static void test_basics(void) { struct stat info1; struct stat info2; test_caseStart("Testing fs"); test_assertInt(mkdir("/newdir",DIR_DEF_MODE),0); fs_createFile("/newdir/file1","foobar"); fs_readFile("/newdir/file1","foobar"); test_assertInt(link("/newdir/file1","/newdir/file2"),0); test_assertInt(stat("/newdir/file1",&info1),0); test_assertInt(stat("/newdir/file2",&info2),0); test_assertInt(memcmp(&info1,&info2,sizeof(struct stat)),0); test_assertUInt(info1.st_nlink,2); test_assertInt(unlink("/newdir/file1"),0); test_assertInt(rmdir("/newdir"),-ENOTEMPTY); test_assertInt(stat("/newdir/file1",&info1),-ENOENT); test_assertInt(stat("/newdir/file2",&info2),0); test_assertUInt(info2.st_nlink,1); test_assertInt(unlink("/newdir/file2"),0); test_assertInt(rmdir("/newdir"),0); int fd = open("/",O_RDONLY); test_assertTrue(fd >= 0); test_assertInt(syncfs(fd),0); close(fd); test_caseSucceeded(); }
static bool test_fileio_checkScan(uint recvRes,uint expRes,const char *fmt,...) { va_list ap; char ch; char *rs,*es; uint ru,eu; int rd,ed; if(!test_assertUInt(recvRes,expRes)) return false; va_start(ap,fmt); while((ch = *fmt++)) { if(ch == '%') ch = *fmt++; switch(ch) { /* signed */ case 'c': case 'd': rd = va_arg(ap,int); ed = va_arg(ap,int); if(!test_assertInt(rd,ed)) { va_end(ap); return false; } break; /* unsigned */ case 'x': case 'b': case 'o': case 'u': ru = va_arg(ap,uint); eu = va_arg(ap,uint); if(!test_assertUInt(ru,eu)) { va_end(ap); return false; } break; /* string */ case 's': rs = va_arg(ap,char*); es = va_arg(ap,char*); if(!test_assertStr(rs,es)) { va_end(ap); return false; } break; } } va_end(ap); return true; }
static void test_canonpath(void) { char path[MAX_PATH_LEN]; size_t count; test_caseStart("Testing canonpath"); setenv("CWD","/"); count = canonpath(path,sizeof(path),"/"); test_assertUInt(count,SSTRLEN("/")); test_assertStr(path,"/"); count = canonpath(path,sizeof(path),"/bin/ls"); test_assertUInt(count,SSTRLEN("/bin/ls")); test_assertStr(path,"/bin/ls"); count = canonpath(path,sizeof(path),"/../bin/../.././home"); test_assertUInt(count,SSTRLEN("/home")); test_assertStr(path,"/home"); count = canonpath(path,sizeof(path),"bin/..///.././home"); test_assertUInt(count,SSTRLEN("/home")); test_assertStr(path,"/home"); count = canonpath(path,sizeof(path),"bin/./ls"); test_assertUInt(count,SSTRLEN("/bin/ls")); test_assertStr(path,"/bin/ls"); setenv("CWD","/home"); count = canonpath(path,sizeof(path),"hrniels/./scripts"); test_assertUInt(count,SSTRLEN("/home/hrniels/scripts")); test_assertStr(path,"/home/hrniels/scripts"); setenv("CWD","/home/"); count = canonpath(path,sizeof(path),"hrniels/./scripts"); test_assertUInt(count,SSTRLEN("/home/hrniels/scripts")); test_assertStr(path,"/home/hrniels/scripts"); count = canonpath(path,sizeof(path),".."); test_assertUInt(count,SSTRLEN("/")); test_assertStr(path,"/"); count = canonpath(path,sizeof(path),"../../."); test_assertUInt(count,SSTRLEN("/")); test_assertStr(path,"/"); count = canonpath(path,sizeof(path),"./../bin"); test_assertUInt(count,SSTRLEN("/bin")); test_assertStr(path,"/bin"); count = canonpath(path,3,"/"); if(count > 3) test_caseFailed("Copied too much"); count = canonpath(path,8,"/bin/ls"); if(count > 8) test_caseFailed("Copied too much"); count = canonpath(path,8,"/bin/../home"); if(count > 8) test_caseFailed("Copied too much"); count = canonpath(path,8,"///../bin/ls"); if(count > 8) test_caseFailed("Copied too much"); test_caseSucceeded(); }
static void test_basics(void) { struct stat info1; struct stat info2; test_caseStart("Testing fs"); test_assertInt(mkdir("/newdir",DIR_DEF_MODE),0); fs_createFile("/newdir/file1","foobar"); fs_readFile("/newdir/file1","foobar"); test_assertInt(link("/newdir/file1","/newdir/file2"),0); test_assertInt(stat("/newdir/file1",&info1),0); test_assertInt(stat("/newdir/file2",&info2),0); // compare elements individually, because the structs might contain uninitialized padding test_assertUInt(info1.st_atime,info2.st_atime); test_assertUInt(info1.st_mtime,info2.st_mtime); test_assertUInt(info1.st_ctime,info2.st_ctime); test_assertUInt(info1.st_blocks,info2.st_blocks); test_assertUInt(info1.st_blksize,info2.st_blksize); test_assertUInt(info1.st_dev,info2.st_dev); test_assertUInt(info1.st_uid,info2.st_uid); test_assertUInt(info1.st_gid,info2.st_gid); test_assertUInt(info1.st_ino,info2.st_ino); test_assertUInt(info1.st_nlink,info2.st_nlink); test_assertUInt(info1.st_mode,info2.st_mode); test_assertUInt(info1.st_size,info2.st_size); test_assertUInt(info1.st_nlink,2); test_assertInt(unlink("/newdir/file1"),0); test_assertInt(rmdir("/newdir"),-ENOTEMPTY); test_assertInt(stat("/newdir/file1",&info1),-ENOENT); test_assertInt(stat("/newdir/file2",&info2),0); test_assertUInt(info2.st_nlink,1); test_assertInt(unlink("/newdir/file2"),0); test_assertInt(rmdir("/newdir"),0); int fd = open("/",O_RDONLY); test_assertTrue(fd >= 0); test_assertInt(syncfs(fd),0); close(fd); test_caseSucceeded(); }
static void test_basics(void) { size_t count,oldFree; test_caseStart("Testing basics"); { sGroup *g; oldFree = heapspace(); g = group_parse("0:root:0",&count); test_assertTrue(g != NULL); test_assertSize(count,1); if(g) { test_assertTrue(g->next == NULL); test_assertUInt(g->gid,0); test_assertStr(g->name,"root"); test_assertSize(g->userCount,1); test_assertUInt(g->users[0],0); } group_free(g); test_assertSize(heapspace(),oldFree); } { sGroup *g; oldFree = heapspace(); g = group_parse("0:root\n",&count); test_assertTrue(g != NULL); test_assertSize(count,1); if(g) { test_assertTrue(g->next == NULL); test_assertUInt(g->gid,0); test_assertStr(g->name,"root"); test_assertSize(g->userCount,0); } group_free(g); test_assertSize(heapspace(),oldFree); } { sGroup *g; oldFree = heapspace(); g = group_parse("0:root:",&count); test_assertTrue(g != NULL); test_assertSize(count,1); if(g) { test_assertTrue(g->next == NULL); test_assertUInt(g->gid,0); test_assertStr(g->name,"root"); test_assertSize(g->userCount,0); } group_free(g); test_assertSize(heapspace(),oldFree); } { sGroup *g; oldFree = heapspace(); g = group_parse("2444:a:100:200",&count); test_assertTrue(g != NULL); test_assertSize(count,1); if(g) { test_assertTrue(g->next == NULL); test_assertUInt(g->gid,2444); test_assertStr(g->name,"a"); test_assertSize(g->userCount,2); test_assertUInt(g->users[0],100); test_assertUInt(g->users[1],200); } group_free(g); test_assertSize(heapspace(),oldFree); } { sGroup *g,*res; oldFree = heapspace(); res = group_parse("1:a:1:2\n\n2:b:4",&count); test_assertSize(count,2); g = res; test_assertTrue(g != NULL); if(g) { test_assertUInt(g->gid,1); test_assertStr(g->name,"a"); test_assertSize(g->userCount,2); test_assertUInt(g->users[0],1); test_assertUInt(g->users[1],2); g = g->next; } test_assertTrue(g != NULL); if(g) { test_assertUInt(g->gid,2); test_assertStr(g->name,"b"); test_assertSize(g->userCount,1); test_assertUInt(g->users[0],4); } group_free(res); test_assertSize(heapspace(),oldFree); } test_caseSucceeded(); }