1 #include <stdint.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include <sys/time.h>
6 #include <unistd.h>
7 #include "ct/ct.h"
8 #include "dat.h"
9
10 void
cttestallocf()11 cttestallocf()
12 {
13 char *got;
14
15 got = fmtalloc("hello, %s %d", "world", 5);
16 assertf(strcmp("hello, world 5", got) == 0, "got \"%s\"", got);
17 }
18
19
20 void
cttestoptnone()21 cttestoptnone()
22 {
23 char *args[] = {
24 NULL,
25 };
26
27 optparse(&srv, args);
28 assert(strcmp(srv.port, Portdef) == 0);
29 assert(srv.addr == NULL);
30 assert(job_data_size_limit == JOB_DATA_SIZE_LIMIT_DEFAULT);
31 assert(srv.wal.filesize == Filesizedef);
32 assert(srv.wal.nocomp == 0);
33 assert(srv.wal.wantsync == 0);
34 assert(srv.user == NULL);
35 assert(srv.wal.dir == NULL);
36 assert(srv.wal.use == 0);
37 assert(verbose == 0);
38 }
39
40
41 static void
success(void)42 success(void)
43 {
44 _exit(0);
45 }
46
47
48 void
cttestoptminus()49 cttestoptminus()
50 {
51 char *args[] = {
52 "-",
53 NULL,
54 };
55
56 atexit(success);
57 optparse(&srv, args);
58 assertf(0, "optparse failed to call exit");
59 }
60
61
62 void
cttestoptp()63 cttestoptp()
64 {
65 char *args[] = {
66 "-p1234",
67 NULL,
68 };
69
70 optparse(&srv, args);
71 assert(strcmp(srv.port, "1234") == 0);
72 }
73
74
75 void
cttestoptl()76 cttestoptl()
77 {
78 char *args[] = {
79 "-llocalhost",
80 NULL,
81 };
82
83 optparse(&srv, args);
84 assert(strcmp(srv.addr, "localhost") == 0);
85 }
86
87
88 void
cttestoptlseparate()89 cttestoptlseparate()
90 {
91 char *args[] = {
92 "-l",
93 "localhost",
94 NULL,
95 };
96
97 optparse(&srv, args);
98 assert(strcmp(srv.addr, "localhost") == 0);
99 }
100
101
102 void
cttestoptz()103 cttestoptz()
104 {
105 char *args[] = {
106 "-z1234",
107 NULL,
108 };
109
110 optparse(&srv, args);
111 assert(job_data_size_limit == 1234);
112 }
113
114
115 void
cttestopts()116 cttestopts()
117 {
118 char *args[] = {
119 "-s1234",
120 NULL,
121 };
122
123 optparse(&srv, args);
124 assert(srv.wal.filesize == 1234);
125 }
126
127
128 void
cttestoptc()129 cttestoptc()
130 {
131 char *args[] = {
132 "-n",
133 "-c",
134 NULL,
135 };
136
137 optparse(&srv, args);
138 assert(srv.wal.nocomp == 0);
139 }
140
141
142 void
cttestoptn()143 cttestoptn()
144 {
145 char *args[] = {
146 "-n",
147 NULL,
148 };
149
150 optparse(&srv, args);
151 assert(srv.wal.nocomp == 1);
152 }
153
154
155 void
cttestoptf()156 cttestoptf()
157 {
158 char *args[] = {
159 "-f1234",
160 NULL,
161 };
162
163 optparse(&srv, args);
164 assert(srv.wal.syncrate == 1234000000);
165 assert(srv.wal.wantsync == 1);
166 }
167
168
169 void
cttestoptF()170 cttestoptF()
171 {
172 char *args[] = {
173 "-f1234",
174 "-F",
175 NULL,
176 };
177
178 optparse(&srv, args);
179 assert(srv.wal.wantsync == 0);
180 }
181
182
183 void
cttestoptu()184 cttestoptu()
185 {
186 char *args[] = {
187 "-ukr",
188 NULL,
189 };
190
191 optparse(&srv, args);
192 assert(strcmp(srv.user, "kr") == 0);
193 }
194
195
196 void
cttestoptb()197 cttestoptb()
198 {
199 char *args[] = {
200 "-bfoo",
201 NULL,
202 };
203
204 optparse(&srv, args);
205 assert(strcmp(srv.wal.dir, "foo") == 0);
206 assert(srv.wal.use == 1);
207 }
208
209
210 void
cttestoptV()211 cttestoptV()
212 {
213 char *args[] = {
214 "-V",
215 NULL,
216 };
217
218 optparse(&srv, args);
219 assert(verbose == 1);
220 }
221
222
223 void
cttestoptV_V()224 cttestoptV_V()
225 {
226 char *args[] = {
227 "-V",
228 "-V",
229 NULL,
230 };
231
232 optparse(&srv, args);
233 assert(verbose == 2);
234 }
235
236
237 void
cttestoptVVV()238 cttestoptVVV()
239 {
240 char *args[] = {
241 "-VVV",
242 NULL,
243 };
244
245 optparse(&srv, args);
246 assert(verbose == 3);
247 }
248
249
250 void
cttestoptVnVu()251 cttestoptVnVu()
252 {
253 char *args[] = {
254 "-VnVukr",
255 NULL,
256 };
257
258 optparse(&srv, args);
259 assert(verbose == 2);
260 assert(srv.wal.nocomp == 1);
261 assert(strcmp(srv.user, "kr") == 0);
262 }
263