lib/util/charset rename iconv_convenience to iconv_handle
[nivanova/samba-autobuild/.git] / source4 / torture / basic / charset.c
index 7becdcd8e5c7f94766dd32dc39938815c61384cf..e4974892c385029c7fcca82bb70c83e1ccbf88b5 100644 (file)
@@ -7,7 +7,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
-#include "torture/torture.h"
-#include "libcli/raw/libcliraw.h"
+#include "libcli/libcli.h"
+#include "torture/util.h"
+#include "param/param.h"
+#include "torture/basic/proto.h"
 
 #define BASEDIR "\\chartest\\"
 
@@ -31,7 +32,8 @@
 
    the prefix BASEDIR is added before the name
 */
-static NTSTATUS unicode_open(struct smbcli_tree *tree,
+static NTSTATUS unicode_open(struct torture_context *tctx,
+                            struct smbcli_tree *tree,
                             TALLOC_CTX *mem_ctx,
                             uint32_t open_disposition, 
                             const uint32_t *u_name, 
@@ -39,7 +41,7 @@ static NTSTATUS unicode_open(struct smbcli_tree *tree,
 {
        union smb_open io;
        char *fname, *fname2=NULL, *ucs_name;
-       int i;
+       size_t i;
        NTSTATUS status;
 
        ucs_name = talloc_size(mem_ctx, (1+u_name_len)*2);
@@ -53,9 +55,8 @@ static NTSTATUS unicode_open(struct smbcli_tree *tree,
        }
        SSVAL(ucs_name, i*2, 0);
 
-       i = convert_string_talloc(ucs_name, CH_UTF16, CH_UNIX, ucs_name, (1+u_name_len)*2, (void **)&fname);
-       if (i == -1) {
-               printf("Failed to convert UCS2 Name into unix - convert_string_talloc() failure\n");
+       if (!convert_string_talloc_handle(ucs_name, lpcfg_iconv_handle(tctx->lp_ctx), CH_UTF16, CH_UNIX, ucs_name, (1+u_name_len)*2, (void **)&fname, &i)) {
+               torture_comment(tctx, "Failed to convert UCS2 Name into unix - convert_string_talloc() failure\n");
                talloc_free(ucs_name);
                return NT_STATUS_NO_MEMORY;
        }
@@ -68,7 +69,7 @@ static NTSTATUS unicode_open(struct smbcli_tree *tree,
 
        io.generic.level = RAW_OPEN_NTCREATEX;
        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
-       io.ntcreatex.in.root_fid = 0;
+       io.ntcreatex.in.root_fid.fnum = 0;
        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
        io.ntcreatex.in.alloc_size = 0;
        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
@@ -80,7 +81,7 @@ static NTSTATUS unicode_open(struct smbcli_tree *tree,
        io.ntcreatex.in.fname = fname2;
        io.ntcreatex.in.open_disposition = open_disposition;
 
-       status = smb_raw_open(tree, mem_ctx, &io);
+       status = smb_raw_open(tree, tctx, &io);
 
        talloc_free(ucs_name);
 
@@ -91,175 +92,118 @@ static NTSTATUS unicode_open(struct smbcli_tree *tree,
 /*
   see if the server recognises composed characters
 */
-static BOOL test_composed(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+static bool test_composed(struct torture_context *tctx, 
+                         struct smbcli_state *cli)
 {
        const uint32_t name1[] = {0x61, 0x308};
        const uint32_t name2[] = {0xe4};
        NTSTATUS status1, status2;
 
-       printf("Testing composite character (a umlaut)\n");
-       
-       status1 = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name1, 2);
-       if (!NT_STATUS_IS_OK(status1)) {
-               printf("Failed to create composed name - %s\n",
-                      nt_errstr(status1));
-               return False;
-       }
+       torture_assert(tctx, torture_setup_dir(cli, BASEDIR), 
+                      "setting up basedir");
 
-       status2 = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name2, 1);
+       status1 = unicode_open(tctx, cli->tree, tctx, NTCREATEX_DISP_CREATE, name1, 2);
+       torture_assert_ntstatus_ok(tctx, status1, "Failed to create composed name");
 
-       if (!NT_STATUS_IS_OK(status2)) {
-               printf("Failed to create accented character - %s\n",
-                      nt_errstr(status2));
-               return False;
-       }
+       status2 = unicode_open(tctx, cli->tree, tctx, NTCREATEX_DISP_CREATE, name2, 1);
 
-       return True;
+       torture_assert_ntstatus_ok(tctx, status2, "Failed to create accented character");
+
+       return true;
 }
 
 /*
   see if the server recognises a naked diacritical
 */
-static BOOL test_diacritical(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+static bool test_diacritical(struct torture_context *tctx, 
+                            struct smbcli_state *cli)
 {
        const uint32_t name1[] = {0x308};
        const uint32_t name2[] = {0x308, 0x308};
        NTSTATUS status1, status2;
 
-       printf("Testing naked diacritical (umlaut)\n");
-       
-       status1 = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name1, 1);
+       torture_assert(tctx, torture_setup_dir(cli, BASEDIR), 
+                      "setting up basedir");
 
-       if (!NT_STATUS_IS_OK(status1)) {
-               printf("Failed to create naked diacritical - %s\n",
-                      nt_errstr(status1));
-               return False;
-       }
+       status1 = unicode_open(tctx, cli->tree, tctx, NTCREATEX_DISP_CREATE, name1, 1);
+
+       torture_assert_ntstatus_ok(tctx, status1, "Failed to create naked diacritical");
 
        /* try a double diacritical */
-       status2 = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name2, 2);
+       status2 = unicode_open(tctx, cli->tree, tctx, NTCREATEX_DISP_CREATE, name2, 2);
 
-       if (!NT_STATUS_IS_OK(status2)) {
-               printf("Failed to create double naked diacritical - %s\n",
-                      nt_errstr(status2));
-               return False;
-       }
+       torture_assert_ntstatus_ok(tctx, status2, "Failed to create double naked diacritical");
 
-       return True;
+       return true;
 }
 
 /*
   see if the server recognises a partial surrogate pair
 */
-static BOOL test_surrogate(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+static bool test_surrogate(struct torture_context *tctx, 
+                          struct smbcli_state *cli)
 {
        const uint32_t name1[] = {0xd800};
        const uint32_t name2[] = {0xdc00};
        const uint32_t name3[] = {0xd800, 0xdc00};
        NTSTATUS status;
 
-       printf("Testing partial surrogate\n");
+       torture_assert(tctx, torture_setup_dir(cli, BASEDIR), 
+                      "setting up basedir");
 
-       status = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name1, 1);
+       status = unicode_open(tctx, cli->tree, tctx, NTCREATEX_DISP_CREATE, name1, 1);
 
-       if (!NT_STATUS_IS_OK(status)) {
-               printf("Failed to create partial surrogate 1 - %s\n",
-                      nt_errstr(status));
-               return False;
-       }
+       torture_assert_ntstatus_ok(tctx, status, "Failed to create partial surrogate 1");
 
-       status = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name2, 1);
+       status = unicode_open(tctx, cli->tree, tctx, NTCREATEX_DISP_CREATE, name2, 1);
 
-       if (!NT_STATUS_IS_OK(status)) {
-               printf("Failed to create partial surrogate 2 - %s\n",
-                      nt_errstr(status));
-               return False;
-       }
+       torture_assert_ntstatus_ok(tctx, status, "Failed to create partial surrogate 2");
 
-       status = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name3, 2);
+       status = unicode_open(tctx, cli->tree, tctx, NTCREATEX_DISP_CREATE, name3, 2);
 
-       if (!NT_STATUS_IS_OK(status)) {
-               printf("Failed to create full surrogate - %s\n",
-                      nt_errstr(status));
-               return False;
-       }
+       torture_assert_ntstatus_ok(tctx, status, "Failed to create full surrogate");
 
-       return True;
+       return true;
 }
 
 /*
   see if the server recognises wide-a characters
 */
-static BOOL test_widea(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+static bool test_widea(struct torture_context *tctx, 
+                      struct smbcli_state *cli)
 {
        const uint32_t name1[] = {'a'};
        const uint32_t name2[] = {0xff41};
        const uint32_t name3[] = {0xff21};
        NTSTATUS status;
 
-       printf("Testing wide-a\n");
-       
-       status = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name1, 1);
+       torture_assert(tctx, torture_setup_dir(cli, BASEDIR), 
+                      "setting up basedir");
 
-       if (!NT_STATUS_IS_OK(status)) {
-               printf("Failed to create 'a' - %s\n",
-                      nt_errstr(status));
-               return False;
-       }
+       status = unicode_open(tctx, cli->tree, tctx, NTCREATEX_DISP_CREATE, name1, 1);
 
-       status = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name2, 1);
+       torture_assert_ntstatus_ok(tctx, status, "Failed to create 'a'");
 
-       if (!NT_STATUS_IS_OK(status)) {
-               printf("Failed to create wide-a - %s\n",
-                      nt_errstr(status));
-               return False;
-       }
+       status = unicode_open(tctx, cli->tree, tctx, NTCREATEX_DISP_CREATE, name2, 1);
 
-       status = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name3, 1);
+       torture_assert_ntstatus_ok(tctx, status, "Failed to create wide-a");
 
-       if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
-               printf("Expected %s creating wide-A - %s\n",
-                      nt_errstr(NT_STATUS_OBJECT_NAME_COLLISION),
-                      nt_errstr(status));
-               return False;
-       }
+       status = unicode_open(tctx, cli->tree, tctx, NTCREATEX_DISP_CREATE, name3, 1);
+
+       torture_assert_ntstatus_equal(tctx, status, NT_STATUS_OBJECT_NAME_COLLISION, 
+               "Failed to create wide-A");
 
-       return True;
+       return true;
 }
 
-BOOL torture_charset(void)
+struct torture_suite *torture_charset(TALLOC_CTX *mem_ctx)
 {
-       static struct smbcli_state *cli;
-       BOOL ret = True;
-       TALLOC_CTX *mem_ctx;
+       struct torture_suite *suite = torture_suite_create(mem_ctx, "charset");
 
-       mem_ctx = talloc_init("torture_charset");
-
-       if (!torture_open_connection(&cli)) {
-               return False;
-       }
-
-       printf("Starting charset tests\n");
-
-       if (!torture_setup_dir(cli, BASEDIR)) {
-               return False;
-       }
-
-       if (!test_composed(cli, mem_ctx)) {
-               ret = False;
-       }
-
-       if (!test_diacritical(cli, mem_ctx)) {
-               ret = False;
-       }
-
-       if (!test_surrogate(cli, mem_ctx)) {
-               ret = False;
-       }
-
-       if (!test_widea(cli, mem_ctx)) {
-               ret = False;
-       }
+       torture_suite_add_1smb_test(suite, "Testing composite character (a umlaut)", test_composed); 
+       torture_suite_add_1smb_test(suite, "Testing naked diacritical (umlaut)", test_diacritical);
+       torture_suite_add_1smb_test(suite, "Testing partial surrogate", test_surrogate);
+       torture_suite_add_1smb_test(suite, "Testing wide-a", test_widea);
 
-       return ret;
+       return suite;
 }