-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.c
121 lines (84 loc) · 2.84 KB
/
test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mstring.h"
//void testmstring() {
int main() {
mstring M;
// expected output: none
mstringNew(&M,126);
// expected output: dirty
mstringNew(&M,17);
// expected output: invalid
char invalid[sizeof(mstring)];
memset(invalid, 24, sizeof(mstring));
//mstringDuplicate((mstring*)&invalid, &M); // fatal
//mstringSet((mstring*)&invalid, "abcd",4); // fatal
mstringDelete((mstring*)&invalid);
mstring Z;
// expected output: none
mstringDelete(&M);
mstringNew(&M,12);
mstringSet(&M,"abcd",3);
// expected output: abc
printf("Contents of M: %s\n", M.buf);
//mstringSet(&M,"abcdefghijklmnop",14); // fatal
// expected output: none
mstringDuplicate(&M, &Z);
// expected output: abc
printf("Contents of Z: %s\n", Z.buf);
// expected output: none
mstringDelete(&M);
mstringNew(&M, 0);
//mstringSet(&M, "1",1); // fatal
mstringDelete(&M);
mstringNew(&M, 12);
mstringSet(&M, "abcd", 0);
printf("-+-+-+-+-+ %d\n", (int)strlen(M.buf));
mstringAppend(&M, "efghij", strlen("efgh"), strlen(M.buf));
//mstringAppend(&M, "ijklmnop", 8, strlen(M.buf)); // fatal
// expected output: abcdefgh
printf("Contents of M: %s\n", M.buf);
mstringDebug(&M);
mstringDelete(&M);
//printf("Allocating will fail...");
//mstringNew(&M,0xFFFFFFFFFFFFFFFF-32); // fatal
mstringNew(&M, 16);
mstringNew(&Z, 16);
mstringSet(&M, "abcdefg", 7);
mstringSet(&Z, "hijklmn", 7);
if(mstringCompare(&M, &Z) < 0) printf("~~ mstringCompare 1 of 3: working\n");
mstringSet(&M, "opwrstu", 7);
if(mstringCompare(&M, &Z) > 0) printf("~~ mstringCompare 2 of 3: working\n");
mstringSet(&M, "hijklmn", 7);
if(mstringCompare(&M, &Z) == 0) printf("~~ mstringCompare 3 of 3: working\n");
if(mstringLength(&M) == M.len) printf("~~ mstringLength: working\n");
mstringNew(&M, 32);
mstringPrintf(&M, "%s %x", "Here we come a wassailing", 0xbadc0d35);
printf("Printf test: %s\n", M.buf);
mstringPrintf(&M, "%s", "short string");
printf("Printf test: %s\n", M.buf);
mstringPrintf(&M, "%s", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
printf("Printf test: %s\n", M.buf);
mstringClear(&M);
if(M.buf[0] == 0 && M.buf[31] == 0) printf("~~ mstringClear: probably working\n");
mstringNew(&M, 16);
mstringSet(&M, "0123456789ABCDE", 0);
printf("Auto-strlen: %s\n", M.buf);
//mstringSet(&M, "0123456789ABCDEF", 0); // fatal
//printf("Auto-strlen: %s\n", M.buf);
mstringGrow(&M, 32);
mstringSet(&M, "0123456789ABCDEFGHIJKLMNOP", 0);
printf("Growing: %s - %d\n", M.buf, (int)M.len);
//mstringGrow(&M, 8); // fatal
printf("Sizeof ulong: %ld\n", sizeof(unsigned long));
mstringDebug(&M);
mstringHexdump(&M);
printf("Awkward size:\n");
mstringDelete(&M);
mstringNew(&M, 17);
mstringSet(&M, "abcdefghijklmnop", 0);
mstringDebug(&M);
mstringHexdump(&M);
return 0;
}