add unit tests to bstr* functions
This commit is contained in:
29
bstr_diff2.c
29
bstr_diff2.c
@@ -28,3 +28,32 @@ int bstr_diff2(const char* a,const char* b,size_t blen) {
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
#ifdef UNITTEST
|
||||
#include <assert.h>
|
||||
|
||||
int main() {
|
||||
assert(bstr_diff2("bar","foo",3) < 0);
|
||||
assert(bstr_diff2("foo","bar",3) > 0);
|
||||
assert(bstr_diff2("foo1","foo",3) > 0);
|
||||
assert(bstr_diff2("foo","foo1",4) < 0);
|
||||
assert(bstr_diff2("foo","foo",3) == 0);
|
||||
|
||||
assert(bstr_diff2("\x00\x03\x00\x00\x00""bar","foo",3) < 0);
|
||||
assert(bstr_diff2("\x00\x03\x00\x00\x00""foo","bar",3) > 0);
|
||||
assert(bstr_diff2("\x00\x04\x00\x00\x00""foo1","foo",3) > 0);
|
||||
assert(bstr_diff2("\x00\x03\x00\x00\x00""foo","foo1",4) < 0);
|
||||
assert(bstr_diff2("\x00\x03\x00\x00\x00""foo","foo",3) == 0);
|
||||
|
||||
assert(bstr_diff2("\x00\x03\x00\x00\x00""bar","foo",3) < 0);
|
||||
assert(bstr_diff2("\x00\x03\x00\x00\x00""foo","bar",3) > 0);
|
||||
assert(bstr_diff2("\x00\x04\x00\x00\x00""foo1","foo",3) > 0);
|
||||
assert(bstr_diff2("\x00\x03\x00\x00\x00""foo","foo1",4) < 0);
|
||||
assert(bstr_diff2("\x00\x03\x00\x00\x00""foo","foo",3) == 0);
|
||||
|
||||
assert(bstr_diff2("\x00\x05\x00\x00\x00""f\x00ord","fnord",5) < 0);
|
||||
assert(bstr_diff2("\x00\x05\x00\x00\x00""f\x00ord","f\x00ort",5) < 0);
|
||||
|
||||
assert(bstr_diff2("\x00\x03\x00\x00\x00""f\xf6o","foo",3) > 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user