r6586: get rid of a few more compiler warnings
[vlendec/samba-autobuild/.git] / source3 / torture / mangle_test.c
index 6d127a918ebc377a89ce36e640f3d5cbfb3c9bd3..df0855d93d71e8784568dc63dd63323efc71f025 100644 (file)
@@ -20,6 +20,8 @@
 
 #include "includes.h"
 
+extern int torture_numops;
+
 static TDB_CONTEXT *tdb;
 
 #define NAME_LENGTH 20
@@ -54,7 +56,7 @@ static BOOL test_one(struct cli_state *cli, const char *name)
                return False;
        }
 
-       snprintf(name2, sizeof(name2), "\\mangle_test\\%s", shortname);
+       fstr_sprintf(name2, "\\mangle_test\\%s", shortname);
        if (!cli_unlink(cli, name2)) {
                printf("unlink of %s  (%s) failed (%s)\n", 
                       name2, name, cli_errstr(cli));
@@ -82,10 +84,10 @@ static BOOL test_one(struct cli_state *cli, const char *name)
        }
 
        /* see if the short name is already in the tdb */
-       data = tdb_fetch_by_string(tdb, shortname);
+       data = tdb_fetch_bystring(tdb, shortname);
        if (data.dptr) {
                /* maybe its a duplicate long name? */
-               if (strcasecmp(name, data.dptr) != 0) {
+               if (!strequal(name, data.dptr)) {
                        /* we have a collision */
                        collisions++;
                        printf("Collision between %s and %s   ->  %s "
@@ -98,7 +100,7 @@ static BOOL test_one(struct cli_state *cli, const char *name)
                /* store it for later */
                namedata.dptr = name;
                namedata.dsize = strlen(name)+1;
-               tdb_store_by_string(tdb, shortname, namedata, TDB_REPLACE);
+               tdb_store_bystring(tdb, shortname, namedata, TDB_REPLACE);
        }
 
        return True;
@@ -107,7 +109,7 @@ static BOOL test_one(struct cli_state *cli, const char *name)
 
 static void gen_name(char *name)
 {
-       const char *chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._-$~...";
+       const char *chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._-$~... ";
        unsigned max_idx = strlen(chars);
        unsigned len;
        int i;
@@ -135,7 +137,12 @@ static void gen_name(char *name)
 
        /* and a medium probability of a common lead string */
        if (random() % 10 == 0) {
-               strncpy(p, "ABCDE", 5);
+               if (strlen(p) <= 5) {
+                       fstrcpy(p, "ABCDE");
+               } else {
+                       /* try not to kill off the null termination */
+                       memcpy(p, "ABCDE", 5);
+               }
        }
 
        /* and a high probability of a good extension length */
@@ -145,14 +152,18 @@ static void gen_name(char *name)
                        s[4] = 0;
                }
        }
+
+       /* ..... and a 100% proability of a file not ending in "." */
+       if (p[strlen(p)-1] == '.')
+               p[strlen(p)-1] = '_';
 }
 
 
 BOOL torture_mangle(int dummy)
 {
-       extern int torture_numops;
-       static struct cli_state cli;
+       static struct cli_state *cli;
        int i;
+       BOOL ret = True;
 
        printf("starting mangle test\n");
 
@@ -167,20 +178,22 @@ BOOL torture_mangle(int dummy)
                return False;
        }
 
-       cli_unlink(&cli, "\\mangle_test\\*");
-       cli_rmdir(&cli, "\\mangle_test");
+       cli_unlink(cli, "\\mangle_test\\*");
+       cli_rmdir(cli, "\\mangle_test");
 
-       if (!cli_mkdir(&cli, "\\mangle_test")) {
+       if (!cli_mkdir(cli, "\\mangle_test")) {
                printf("ERROR: Failed to make directory\n");
                return False;
        }
 
        for (i=0;i<torture_numops;i++) {
                fstring name;
+               ZERO_STRUCT(name);
 
                gen_name(name);
-
-               if (!test_one(&cli, name)) {
+               
+               if (!test_one(cli, name)) {
+                       ret = False;
                        break;
                }
                if (total && total % 100 == 0) {
@@ -189,8 +202,8 @@ BOOL torture_mangle(int dummy)
                }
        }
 
-       cli_unlink(&cli, "\\mangle_test\\*");
-       if (!cli_rmdir(&cli, "\\mangle_test")) {
+       cli_unlink(cli, "\\mangle_test\\*");
+       if (!cli_rmdir(cli, "\\mangle_test")) {
                printf("ERROR: Failed to remove directory\n");
                return False;
        }
@@ -198,8 +211,8 @@ BOOL torture_mangle(int dummy)
        printf("\nTotal collisions %u/%u  - %.2f%%   (%u failures)\n",
               collisions, total, (100.0*collisions) / total, failures);
 
-       torture_close_connection(&cli);
+       torture_close_connection(cli);
 
        printf("mangle test finished\n");
-       return (failures == 0);
+       return (ret && (failures == 0));
 }