@@ -26,24 +26,58 @@ int main(int argc, char** argv)
2626
2727 //initA
2828
29- ffStrbufInitA (& strbuf , 64 );
29+ ffStrbufInitA (& strbuf , 0 );
3030
31- if (strbuf .allocated != 64 )
32- testFailed (& strbuf , "strbuf.allocated != 64" );
31+ if (strbuf .chars [0 ] != 0 ) //make sure chars[0] is accessable
32+ testFailed (& strbuf , "strbuf.chars[0] != 0" );
33+
34+ if (strbuf .allocated != 0 )
35+ testFailed (& strbuf , "strbuf.allocated != 0" );
3336
3437 if (strbuf .length != 0 )
35- testFailed (& strbuf , "testSrbuf .length != 0" );
38+ testFailed (& strbuf , "strbuf .length != 0" );
3639
3740 //appendS
3841
39- ffStrbufAppendS (& strbuf , "123456789" );
42+ ffStrbufAppendS (& strbuf , "12345" );
43+
44+ if (strbuf .length != 5 )
45+ testFailed (& strbuf , "strbuf.length != 5" );
46+
47+ if (strbuf .allocated < 6 )
48+ testFailed (& strbuf , "strbuf.allocated < 6" );
49+
50+ if (ffStrbufCompS (& strbuf , "12345" ) != 0 )
51+ testFailed (& strbuf , "strbuf.data != \"12345\"" );
52+
53+ //appendNS
54+
55+ ffStrbufAppendNS (& strbuf , 4 , "67890" );
4056
4157 if (strbuf .length != 9 )
4258 testFailed (& strbuf , "strbuf.length != 9" );
4359
44- if (strcmp (strbuf .chars , "123456789" ) != 0 )
60+ if (strbuf .allocated < 10 )
61+ testFailed (& strbuf , "strbuf.allocated < 10" );
62+
63+ if (ffStrbufCompS (& strbuf , "123456789" ) != 0 )
4564 testFailed (& strbuf , "strbuf.data != \"123456789\"" );
4665
66+ //appendS long
67+
68+ ffStrbufAppendS (& strbuf , "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" );
69+
70+ if (strbuf .length != 109 )
71+ testFailed (& strbuf , "strbuf.length != 109" );
72+
73+ if (strbuf .allocated < 110 )
74+ testFailed (& strbuf , "strbuf.allocated < 110" );
75+
76+ if (strbuf .chars [strbuf .length ] != 0 )
77+ testFailed (& strbuf , "strbuf.chars[strbuf.length] != 0" );
78+
79+ strbuf .length = 9 ;
80+
4781 //startsWithS
4882
4983 if (!ffStrbufStartsWithS (& strbuf , "123" ))
@@ -79,6 +113,18 @@ int main(int argc, char** argv)
79113 if (strcmp (strbuf .chars , "12316" ) != 0 )
80114 testFailed (& strbuf , "strbuf.chars != \"12316\"" );
81115
116+ //Destroy
117+
118+ ffStrbufDestroy (& strbuf );
119+ if (strbuf .allocated != 0 )
120+ testFailed (& strbuf , "strbuf.allocated != 0" );
121+
122+ if (strbuf .length != 0 )
123+ testFailed (& strbuf , "strbuf.length != 0" );
124+
125+ if (strbuf .chars != NULL )
126+ testFailed (& strbuf , "strbuf.chars != NULL" );
127+
82128 //Success
83129 puts ("\033[32mAll tests passed!" FASTFETCH_TEXT_MODIFIER_RESET );
84130}
0 commit comments