6
6
#include <string.h>
7
7
8
8
#define CHECK_STREQUAL (s1 , s2 ) if (strcmp((s1), (s2))) { \
9
- fprintf(stderr, "[CHECK_STREQUAL] %s != %s\n", s1, s2); \
9
+ fprintf(stderr, "%d [CHECK_STREQUAL] %s != %s\n", __LINE__, s1, s2); \
10
+ exit(-1);\
10
11
}
11
12
12
- #define CHECK_EQUAL (a , b ) if ((a) == (b)) {\
13
- fprintf(stderr, "[CHECK_EQUAL] failed"); \
13
+ #define CHECK_EQUAL (a , b ) if (!((a) == (b))) {\
14
+ fprintf(stderr, "%d [CHECK_EQUAL] failed", __LINE__); \
15
+ fflush(stderr);\
16
+ exit(-1);\
14
17
}
15
18
16
19
void test_dstring1 ()
@@ -26,18 +29,26 @@ void test_dstring2()
26
29
{
27
30
string str ;
28
31
string_malloc (& str );
29
- for (int i = 0 ; i < 1024 ; i ++ ) {
30
- string_append (& str , "a" );
32
+ char fake [2 ];
33
+ fake [1 ] = '\0' ;
34
+ for (char c = 'a' ; c <= 'z' ; c += 1 ) {
35
+ for (int i = 0 ; i < 1024 ; i ++ ) {
36
+ fake [0 ] = c ;
37
+ string_append (& str , fake );
38
+ }
31
39
}
32
- string_append (& str , "b" );
33
- CHECK_EQUAL (string_length (str ), 1025 );
34
- CHECK_EQUAL (string_size (str ), 2048 );
40
+ CHECK_EQUAL (string_length (str ), 26 * 1024 );
41
+ CHECK_EQUAL (string_size (str ), 32 * 1024 );
35
42
CHECK_EQUAL (string_ref (str , string_length (str )),
36
43
'\0' );
37
- for (int i = 0 ; i < 1024 ; i ++ ) {
38
- CHECK_EQUAL (string_ref (str , i ), 'a' );
44
+ for (char c = 'a' ; c <= 'z' ; c += 1 ) {
45
+ for (int i = 0 ; i < 1024 ; i ++ ) {
46
+ int idx = (c - 'a' );
47
+ idx *= 1024 ;
48
+ idx += i ;
49
+ CHECK_EQUAL (string_ref (str , idx ), c );
50
+ }
39
51
}
40
- CHECK_EQUAL (string_ref (str , string_length (str )- 1 ), 'b' );
41
52
string_free (& str );
42
53
}
43
54
0 commit comments