#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();
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);