bool test_doAssertStr(const char *received,const char *expected,const char *func,int line) { char *s1 = (char*)expected; char *s2 = (char*)received; assertCount++; if(s1 == NULL && s2 == NULL) return true; if(s1 == NULL || s2 == NULL) { test_caseFailed("Assert %d in %s line %d: Strings are not equal: Expected '%s', got '%s'", assertCount,func,line,expected,received); return false; } while(*s1 && *s2) { if(*s1 != *s2) { test_caseFailed("Assert %d in %s line %d: Strings are not equal: Expected '%s', got '%s'", assertCount,func,line,expected,received); return false; } s1++; s2++; } if(*s1 != *s2) { test_caseFailed("Assert %d in %s line %d: Strings are not equal: Expected '%s', got '%s'", assertCount,func,line,expected,received); return false; } return true; }
bool test_doAssertFalse(bool received,const char *func,int line) { assertCount++; if(received) { test_caseFailed("Assert %d in %s line %d: Received true, expected false",assertCount,func,line); return false; } return true; }
bool test_doAssertInt(int received,int expected,const char *func,int line) { assertCount++; if(expected != received) { test_caseFailed("Assert %d in %s line %d: Integers are not equal: Expected %d, got %d", assertCount,func,line,expected,received); return false; } return true; }
bool test_doAssertDouble(double received,double expected,const char *func,int line) { assertCount++; if(expected != received) { test_caseFailed("Assert %d in %s line %d: Doubles are not equal: Expected %lf, got %lf", assertCount,func,line,expected,received); return false; } return true; }
bool test_doAssertFloat(float received,float expected,const char *func,int line) { assertCount++; if(expected != received) { test_caseFailed("Assert %d in %s line %d: Floats are not equal: Expected %f, got %f", assertCount,func,line,expected,received); return false; } return true; }
bool test_doAssertPtr(const void *received,const void *expected,const char *func,int line) { assertCount++; if(expected != received) { test_caseFailed("Assert %d in %s line %d: Pointers are not equal: Expected %p, got %p", assertCount,func,line,expected,received); return false; } return true; }
bool test_doAssertULLInt(ullong received,ullong expected,const char *func,int line) { assertCount++; if(expected != received) { test_caseFailed("Assert %d in %s line %d: Integers are not equal: " "Expected 0x%Lx, got 0x%Lx",assertCount,func,line,expected,received); return false; } return true; }
static void test_opendir(void) { DIR *dir; struct dirent e; test_caseStart("Testing opendir, readdir and closedir"); dir = opendir("/bin"); if(dir == NULL) { test_caseFailed("Unable to open '/bin'"); return; } while(readdirto(dir,&e)); closedir(dir); test_caseSucceeded(); }
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(); }