r24569: Add two tests
authorVolker Lendecke <vlendec@samba.org>
Mon, 20 Aug 2007 05:24:19 +0000 (05:24 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 20:02:17 +0000 (15:02 -0500)
A subtest for rename to check if case-changing renames work

A test that exposes the case insensitivity unix_convert bug

source/torture/raw/raw.c
source/torture/raw/rename.c
source/torture/raw/samba3misc.c

index 55e93501448cb0a4208f5ed0710e2f10f5aefa43..67d79ef78c3092eff606baa4c24654718756bdef 100644 (file)
@@ -62,6 +62,8 @@ NTSTATUS torture_raw_init(void)
        torture_suite_add_simple_test(suite, "SAMBA3CLOSEERR", torture_samba3_closeerr);
        torture_suite_add_simple_test(suite, "SAMBA3CHECKFSP", torture_samba3_checkfsp);
        torture_suite_add_simple_test(suite, "SAMBA3BADPATH", torture_samba3_badpath);
+       torture_suite_add_simple_test(suite, "SAMBA3CASEINSENSITIVE",
+                                     torture_samba3_caseinsensitive);
        torture_suite_add_simple_test(suite, "SCAN-EAMAX", torture_max_eas);
 
        suite->description = talloc_strdup(suite, 
index 22e91a44a929687dff2928c8ac0e70d70464327d..9e9977050372b2607c1cb54e6953ff7e71217c7a 100644 (file)
@@ -51,6 +51,8 @@ static BOOL test_mv(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        int fnum = -1;
        const char *fname1 = BASEDIR "\\test1.txt";
        const char *fname2 = BASEDIR "\\test2.txt";
+       const char *Fname1 = BASEDIR "\\Test1.txt";
+       union smb_fileinfo finfo;
        union smb_open op;
 
        printf("Testing SMBmv\n");
@@ -109,6 +111,24 @@ static BOOL test_mv(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        status = smb_raw_rename(cli->tree, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
 
+       printf("Trying case-changing rename\n");
+       io.rename.in.pattern1 = fname1;
+       io.rename.in.pattern2 = Fname1;
+       status = smb_raw_rename(cli->tree, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+       finfo.generic.level = RAW_FILEINFO_ALL_INFO;
+       finfo.all_info.in.file.path = fname1;
+       status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       if (strcmp(finfo.all_info.out.fname.s, Fname1) != 0) {
+               printf("(%s) Incorrect filename [%s] after case-changing "
+                      "rename, should be [%s]\n", __location__,
+                      finfo.all_info.out.fname.s, Fname1);
+               ret = False;
+               goto done;
+       }
+
        io.rename.in.pattern1 = fname1;
        io.rename.in.pattern2 = fname2;
 
index e36be6436a349c330cdf3c95ce5468bcb2cd3fd8..c019c4e2ee663c3a13a1707398124335c51f1992 100644 (file)
@@ -598,3 +598,70 @@ BOOL torture_samba3_badpath(struct torture_context *torture)
 
        return ret;
 }
+
+static void count_fn(struct clilist_file_info *info, const char *name,
+                    void *private_data)
+{
+       int *counter = (int *)private_data;
+       *counter += 1;
+}
+
+BOOL torture_samba3_caseinsensitive(struct torture_context *torture)
+{
+       struct smbcli_state *cli;
+       TALLOC_CTX *mem_ctx;
+       NTSTATUS status;
+       const char *dirname = "insensitive";
+       const char *ucase_dirname = "InSeNsItIvE";
+       const char *fname = "foo";
+       char *fpath;
+       int fnum;
+       int counter = 0;
+       BOOL ret = True;
+
+       if (!(mem_ctx = talloc_init("torture_samba3_caseinsensitive"))) {
+               d_printf("talloc_init failed\n");
+               return False;
+       }
+
+       if (!torture_open_connection(&cli, 0)) {
+               goto done;
+       }
+
+       smbcli_deltree(cli->tree, dirname);
+
+       status = smbcli_mkdir(cli->tree, dirname);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("smbcli_mkdir failed: %s\n", nt_errstr(status));
+               goto done;
+       }
+
+       if (!(fpath = talloc_asprintf(mem_ctx, "%s\\%s", dirname, fname))) {
+               goto done;
+       }
+       fnum = smbcli_open(cli->tree, fpath, O_RDWR | O_CREAT, DENY_NONE);
+       if (fnum == -1) {
+               d_printf("Could not create file %s: %s\n", fpath,
+                        smbcli_errstr(cli->tree));
+               goto done;
+       }
+       smbcli_close(cli->tree, fnum);
+
+       smbcli_list(cli->tree, talloc_asprintf(
+                           mem_ctx, "%s\\*", ucase_dirname),
+                   FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_HIDDEN
+                   |FILE_ATTRIBUTE_SYSTEM,
+                   count_fn, (void *)&counter);
+
+       if (counter == 3) {
+               ret = True;
+       }
+       else {
+               d_fprintf(stderr, "expected 3 entries, got %d\n", counter);
+               ret = False;
+       }
+
+ done:
+       talloc_free(mem_ctx);
+       return ret;
+}