]> infiniteadaptability.org Git - seeder/commitdiff
...
authoralex <[email protected]>
Mon, 18 Oct 2021 18:32:02 +0000 (11:32 -0700)
committeralex <[email protected]>
Mon, 18 Oct 2021 18:32:02 +0000 (11:32 -0700)
test/unit/test_utils.c
test/unit/test_utils.h
test/unit/tree.tests.c

index 0b0520c2584ea07eb6f77911b333d88ee689c250..6320b8677e23be5f09a226bb2cbfb6d4926fac45 100644 (file)
@@ -15,6 +15,8 @@ void reset_env() {
 void setup_env() {
        clean_env();
 
+       //srand(time(NULL));
+
        create_test_directory(TEST_DIRECTORY);
        create_test_file(TEST_FILE_1,TEST_FILE_1_CONTENTS);
        create_test_file(TEST_FILE_2,TEST_FILE_2_CONTENTS);
index 9fc057d644d34a64dbf9c9f358b86218610a2994..2d7e4e63e977092ca7e3494e89a1a9d71dc07ba8 100644 (file)
@@ -2,6 +2,8 @@
 #define __TEST_UTILS_H_
 
 #include<assert.h>
+#include<stdlib.h>
+#include<time.h>
 
 #include<default.h>
 #include<setup.h>
index cf530582cc4a775ee7323b7f9f667a4d78a7fb10..b4986337390122c0ade32003d03669f66ad7e13e 100644 (file)
@@ -3,6 +3,7 @@
 #include<tree.h>
 
 int main();
+static char *create_random_path();
 static void tree_add_basic_test();
 static void tree_add_extended_test();
 static void tree_init_basic_test();
@@ -54,28 +55,48 @@ static void tree_add_basic_test() {
        tree_free(tree);
 }
 
-static void tree_add_extended_test() {
-       struct tree *tree;
-       struct file *file;
+static char *create_random_path() {
+       char *str;
+       int len, index;
 
        char valid[] = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
 
+       str = malloc(100);
+       assert(str!=NULL);
+
+       // make sure string is at least 1 character long (not including '\0'
+       len = rand()%98;
+       len+=2;
+
+       index = 0;
+       while(len>1) {
+               for(int i=0;i<rand()%(len-1);i++) {
+                       str[index] = valid[rand()%(sizeof(valid)-1)];
+                       index++;
+                       len--;
+               }
+
+               str[index]='/';
+               index++;
+               len--;
+       }
 
-       char files[7][100] = {
-               "test/test1",
-               "hello/test2",
-               "/notalsdkfj asdfkkl /asdlfkj /asdflkjasdf/klaasdlfjasd",
-               "src/asldfkak/a/aslkdfj//a/lsd/as/alskdf/lasdfjasdfasdlfkajsdfa/sdf",
-               "//./asd//sd/f/sadfasldklfasld///s/d/flskdfkl/asdk",
-               "..",
-               "."
-       };
+       str[index] = '\0';
+
+       return str;
+}
+
+static void tree_add_extended_test() {
+       struct tree *tree;
+       struct file *file;
 
        assert(1==tree_init(&tree,NULL));
        
-       for(int i = 0;i<3;i++) {
-               assert(1==file_init(&file,files[i]));
+       for(int i=0;i<100;i++) {
+               char *path = create_random_path();
+               assert(1==file_init(&file,path));
                assert(1==tree_add(tree,file));
+               free(path);
        }
 
        tree_free(tree);