add changelog for 1.13
[beanstalkd.git] / testutil.c
blob4d5831fd547fe490f1e6442df55454bc7721b4f9
1 #include "ct/ct.h"
2 #include "dat.h"
3 #include <stdint.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <string.h>
7 #include <sys/time.h>
8 #include <unistd.h>
10 void
11 cttest_allocf()
13 char *got;
15 got = fmtalloc("hello, %s %d", "world", 5);
16 assertf(strcmp("hello, world 5", got) == 0, "got \"%s\"", got);
17 free(got);
20 void
21 cttest_opt_none()
23 char *args[] = {
24 NULL,
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.wantsync == 1);
33 assert(srv.wal.syncrate == DEFAULT_FSYNC_MS*1000000);
34 assert(srv.user == NULL);
35 assert(srv.wal.dir == NULL);
36 assert(srv.wal.use == 0);
37 assert(verbose == 0);
40 static void
41 success(void)
43 _exit(0);
46 void
47 cttest_optminus()
49 char *args[] = {
50 "-",
51 NULL,
54 atexit(success);
55 optparse(&srv, args);
56 assertf(0, "optparse failed to call exit");
59 void
60 cttest_optp()
62 char *args[] = {
63 "-p1234",
64 NULL,
67 optparse(&srv, args);
68 assert(strcmp(srv.port, "1234") == 0);
71 void
72 cttest_optl()
74 char *args[] = {
75 "-llocalhost",
76 NULL,
79 optparse(&srv, args);
80 assert(strcmp(srv.addr, "localhost") == 0);
83 void
84 cttest_optlseparate()
86 char *args[] = {
87 "-l",
88 "localhost",
89 NULL,
92 optparse(&srv, args);
93 assert(strcmp(srv.addr, "localhost") == 0);
96 void
97 cttest_optz()
99 char *args[] = {
100 "-z1234",
101 NULL,
104 optparse(&srv, args);
105 assert(job_data_size_limit == 1234);
108 void
109 cttest_optz_more_than_max()
111 char *args[] = {
112 "-z1073741825",
113 NULL,
116 optparse(&srv, args);
117 assert(job_data_size_limit == 1073741824);
120 void
121 cttest_opts()
123 char *args[] = {
124 "-s1234",
125 NULL,
128 optparse(&srv, args);
129 assert(srv.wal.filesize == 1234);
132 void
133 cttest_optf()
135 char *args[] = {
136 "-f1234",
137 NULL,
140 optparse(&srv, args);
141 assert(srv.wal.syncrate == 1234000000);
142 assert(srv.wal.wantsync == 1);
145 void
146 cttest_optF()
148 char *args[] = {
149 "-f1234",
150 "-F",
151 NULL,
154 optparse(&srv, args);
155 assert(srv.wal.wantsync == 0);
158 void
159 cttest_optu()
161 char *args[] = {
162 "-ukr",
163 NULL,
166 optparse(&srv, args);
167 assert(strcmp(srv.user, "kr") == 0);
170 void
171 cttest_optb()
173 char *args[] = {
174 "-bfoo",
175 NULL,
178 optparse(&srv, args);
179 assert(strcmp(srv.wal.dir, "foo") == 0);
180 assert(srv.wal.use == 1);
183 void
184 cttest_optV()
186 char *args[] = {
187 "-V",
188 NULL,
191 optparse(&srv, args);
192 assert(verbose == 1);
195 void
196 cttest_optV_V()
198 char *args[] = {
199 "-V",
200 "-V",
201 NULL,
204 optparse(&srv, args);
205 assert(verbose == 2);
208 void
209 cttest_optVVV()
211 char *args[] = {
212 "-VVV",
213 NULL,
216 optparse(&srv, args);
217 assert(verbose == 3);
220 void
221 cttest_optVFVu()
223 char *args[] = {
224 "-VFVukr",
225 NULL,
228 optparse(&srv, args);
229 assert(verbose == 2);
230 assert(srv.wal.wantsync == 0);
231 assert(strcmp(srv.user, "kr") == 0);