mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-09 22:50:38 +01:00
FFstrbuf: fix bugs in ffStrbufAppendS; add more tests
This commit is contained in:
+52
-6
@@ -26,24 +26,58 @@ int main(int argc, char** argv)
|
||||
|
||||
//initA
|
||||
|
||||
ffStrbufInitA(&strbuf, 64);
|
||||
ffStrbufInitA(&strbuf, 0);
|
||||
|
||||
if(strbuf.allocated != 64)
|
||||
testFailed(&strbuf, "strbuf.allocated != 64");
|
||||
if(strbuf.chars[0] != 0) //make sure chars[0] is accessable
|
||||
testFailed(&strbuf, "strbuf.chars[0] != 0");
|
||||
|
||||
if(strbuf.allocated != 0)
|
||||
testFailed(&strbuf, "strbuf.allocated != 0");
|
||||
|
||||
if(strbuf.length != 0)
|
||||
testFailed(&strbuf, "testSrbuf.length != 0");
|
||||
testFailed(&strbuf, "strbuf.length != 0");
|
||||
|
||||
//appendS
|
||||
|
||||
ffStrbufAppendS(&strbuf, "123456789");
|
||||
ffStrbufAppendS(&strbuf, "12345");
|
||||
|
||||
if(strbuf.length != 5)
|
||||
testFailed(&strbuf, "strbuf.length != 5");
|
||||
|
||||
if(strbuf.allocated < 6)
|
||||
testFailed(&strbuf, "strbuf.allocated < 6");
|
||||
|
||||
if(ffStrbufCompS(&strbuf, "12345") != 0)
|
||||
testFailed(&strbuf, "strbuf.data != \"12345\"");
|
||||
|
||||
//appendNS
|
||||
|
||||
ffStrbufAppendNS(&strbuf, 4, "67890");
|
||||
|
||||
if(strbuf.length != 9)
|
||||
testFailed(&strbuf, "strbuf.length != 9");
|
||||
|
||||
if(strcmp(strbuf.chars, "123456789") != 0)
|
||||
if(strbuf.allocated < 10)
|
||||
testFailed(&strbuf, "strbuf.allocated < 10");
|
||||
|
||||
if(ffStrbufCompS(&strbuf, "123456789") != 0)
|
||||
testFailed(&strbuf, "strbuf.data != \"123456789\"");
|
||||
|
||||
//appendS long
|
||||
|
||||
ffStrbufAppendS(&strbuf, "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890");
|
||||
|
||||
if(strbuf.length != 109)
|
||||
testFailed(&strbuf, "strbuf.length != 109");
|
||||
|
||||
if(strbuf.allocated < 110)
|
||||
testFailed(&strbuf, "strbuf.allocated < 110");
|
||||
|
||||
if(strbuf.chars[strbuf.length] != 0)
|
||||
testFailed(&strbuf, "strbuf.chars[strbuf.length] != 0");
|
||||
|
||||
strbuf.length = 9;
|
||||
|
||||
//startsWithS
|
||||
|
||||
if(!ffStrbufStartsWithS(&strbuf, "123"))
|
||||
@@ -79,6 +113,18 @@ int main(int argc, char** argv)
|
||||
if(strcmp(strbuf.chars, "12316") != 0)
|
||||
testFailed(&strbuf, "strbuf.chars != \"12316\"");
|
||||
|
||||
//Destroy
|
||||
|
||||
ffStrbufDestroy(&strbuf);
|
||||
if(strbuf.allocated != 0)
|
||||
testFailed(&strbuf, "strbuf.allocated != 0");
|
||||
|
||||
if(strbuf.length != 0)
|
||||
testFailed(&strbuf, "strbuf.length != 0");
|
||||
|
||||
if(strbuf.chars != NULL)
|
||||
testFailed(&strbuf, "strbuf.chars != NULL");
|
||||
|
||||
//Success
|
||||
puts("\033[32mAll tests passed!"FASTFETCH_TEXT_MODIFIER_RESET);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user