unit_test.c
Go to the documentation of this file.
1 // Unit test for the mongoose web server.
2 // g++ -W -Wall -pedantic -g unit_test.c -lssl && ./a.out
3 // cl unit_test.c /MD
4 
5 #ifndef _WIN32
6 #define NS_ENABLE_IPV6
7 #define NS_ENABLE_SSL
8 #endif
9 #define MONGOOSE_POST_SIZE_LIMIT 999
10 
11 // USE_* definitions must be made before #include "mongoose.c" !
12 #include "../mongoose.c"
13 
14 #define FAIL(str, line) do { \
15  printf("Fail on line %d: [%s]\n", line, str); \
16  return str; \
17 } while (0)
18 
19 #define ASSERT(expr) do { \
20  static_num_tests++; \
21  if (!(expr)) FAIL(#expr, __LINE__); \
22 } while (0)
23 
24 #define RUN_TEST(test) do { const char *msg = test(); \
25  if (msg) return msg; } while (0)
26 
27 #define HTTP_PORT "45772"
28 #define LISTENING_ADDR "127.0.0.1:" HTTP_PORT
29 
30 static int static_num_tests = 0;
31 
32 #if 0
33 // Connects to host:port, and sends formatted request to it. Returns
34 // malloc-ed reply and reply length, or NULL on error. Reply contains
35 // everything including headers, not just the message body.
36 static char *wget(const char *host, int port, int *len, const char *fmt, ...) {
37  char buf[2000], *reply = NULL;
38  int request_len, reply_size = 0, n, sock = -1;
39  struct sockaddr_in sin;
40  struct hostent *he = NULL;
41  va_list ap;
42 
43  if (host != NULL &&
44  (he = gethostbyname(host)) != NULL &&
45  (sock = socket(PF_INET, SOCK_STREAM, 0)) != -1) {
46  sin.sin_family = AF_INET;
47  sin.sin_port = htons((uint16_t) port);
48  sin.sin_addr = * (struct in_addr *) he->h_addr_list[0];
49  if (connect(sock, (struct sockaddr *) &sin, sizeof(sin)) == 0) {
50 
51  // Format and send the request.
52  va_start(ap, fmt);
53  request_len = vsnprintf(buf, sizeof(buf), fmt, ap);
54  va_end(ap);
55  while (request_len > 0 && (n = send(sock, buf, request_len, 0)) > 0) {
56  request_len -= n;
57  }
58  if (request_len == 0) {
59  *len = 0;
60  while ((n = recv(sock, buf, sizeof(buf), 0)) > 0) {
61  if (*len + n > reply_size) {
62  // Leak possible
63  reply = (char *) realloc(reply, reply_size + sizeof(buf));
64  reply_size += sizeof(buf);
65  }
66  if (reply != NULL) {
67  memcpy(reply + *len, buf, n);
68  *len += n;
69  }
70  }
71  }
72  closesocket(sock);
73  }
74  }
75 
76  return reply;
77 }
78 #endif
79 
80 static char *read_file(const char *path, int *size) {
81  FILE *fp;
82  struct stat st;
83  char *data = NULL;
84  if ((fp = fopen(path, "rb")) != NULL && !fstat(fileno(fp), &st)) {
85  *size = (int) st.st_size;
86  data = (char *) malloc(*size);
87  fread(data, 1, *size, fp);
88  fclose(fp);
89  }
90  return data;
91 }
92 
93 static const char *test_parse_http_message() {
94  struct mg_connection ri;
95  char req1[] = "GET / HTTP/1.1\r\n\r\n";
96  char req2[] = "BLAH / HTTP/1.1\r\n\r\n";
97  char req3[] = "GET / HTTP/1.1\r\nBah\r\n";
98  char req4[] = "GET / HTTP/1.1\r\nA: foo bar\r\nB: bar\r\nbaz\r\n\r\n";
99  char req5[] = "GET / HTTP/1.1\r\n\r\n";
100  char req6[] = "G";
101  char req7[] = " blah ";
102  char req8[] = " HTTP/1.1 200 OK \n\n";
103  char req9[] = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n";
104 
105  ASSERT(get_request_len("\r\n", 3) == -1);
106  ASSERT(get_request_len("\r\n", 2) == 0);
107  ASSERT(get_request_len("GET", 3) == 0);
108  ASSERT(get_request_len("\n\n", 2) == 2);
109  ASSERT(get_request_len("\n\r\n", 3) == 3);
110  ASSERT(get_request_len("\xdd\xdd", 2) == 0);
111  ASSERT(get_request_len("\xdd\x03", 2) == -1);
112  ASSERT(get_request_len(req3, sizeof(req3) - 1) == 0);
113  ASSERT(get_request_len(req6, sizeof(req6) - 1) == 0);
114  ASSERT(get_request_len(req7, sizeof(req7) - 1) == 0);
115 
116  ASSERT(parse_http_message(req9, sizeof(req9) - 1, &ri) == sizeof(req9) - 1);
117  ASSERT(ri.num_headers == 1);
118 
119  ASSERT(parse_http_message(req1, sizeof(req1) - 1, &ri) == sizeof(req1) - 1);
120  ASSERT(strcmp(ri.http_version, "1.1") == 0);
121  ASSERT(ri.num_headers == 0);
122 
123  ASSERT(parse_http_message(req2, sizeof(req2) - 1, &ri) == (size_t) ~0);
124  ASSERT(parse_http_message(req6, 0, &ri) == (size_t) ~0);
125  ASSERT(parse_http_message(req8, sizeof(req8) - 1, &ri) == sizeof(req8) - 1);
126 
127  // TODO(lsm): Fix this. Header value may span multiple lines.
128  ASSERT(parse_http_message(req4, sizeof(req4) - 1, &ri) == sizeof(req4) - 1);
129  ASSERT(strcmp(ri.http_version, "1.1") == 0);
130  ASSERT(ri.num_headers == 3);
131  ASSERT(strcmp(ri.http_headers[0].name, "A") == 0);
132  ASSERT(strcmp(ri.http_headers[0].value, "foo bar") == 0);
133  ASSERT(strcmp(ri.http_headers[1].name, "B") == 0);
134  ASSERT(strcmp(ri.http_headers[1].value, "bar") == 0);
135  ASSERT(strcmp(ri.http_headers[2].name, "baz\r\n\r") == 0);
136  ASSERT(strcmp(ri.http_headers[2].value, "") == 0);
137 
138  ASSERT(parse_http_message(req5, sizeof(req5) - 1, &ri) == sizeof(req5) - 1);
139  ASSERT(strcmp(ri.request_method, "GET") == 0);
140  ASSERT(strcmp(ri.http_version, "1.1") == 0);
141 
142  return NULL;
143 }
144 
145 static const char *test_should_keep_alive(void) {
146  struct mg_connection conn;
147  char req1[] = "GET / HTTP/1.1\r\n\r\n";
148  char req2[] = "GET / HTTP/1.0\r\n\r\n";
149  char req3[] = "GET / HTTP/1.1\r\nConnection: close\r\n\r\n";
150  char req4[] = "GET / HTTP/1.1\r\nConnection: keep-alive\r\n\r\n";
151 
152  memset(&conn, 0, sizeof(conn));
153  ASSERT(parse_http_message(req1, sizeof(req1) - 1, &conn) == sizeof(req1) - 1);
154  ASSERT(should_keep_alive(&conn) != 0);
155 
156  parse_http_message(req2, sizeof(req2) - 1, &conn);
157  ASSERT(should_keep_alive(&conn) == 0);
158 
159  parse_http_message(req3, sizeof(req3) - 1, &conn);
160  ASSERT(should_keep_alive(&conn) == 0);
161 
162  parse_http_message(req4, sizeof(req4) - 1, &conn);
163  ASSERT(should_keep_alive(&conn) != 0);
164 
165  return NULL;
166 }
167 
168 static const char *test_match_prefix(void) {
169  ASSERT(mg_match_prefix("/api", 4, "/api") == 4);
170  ASSERT(mg_match_prefix("/a/", 3, "/a/b/c") == 3);
171  ASSERT(mg_match_prefix("/a/", 3, "/ab/c") == -1);
172  ASSERT(mg_match_prefix("/*/", 3, "/ab/c") == 4);
173  ASSERT(mg_match_prefix("**", 2, "/a/b/c") == 6);
174  ASSERT(mg_match_prefix("/*", 2, "/a/b/c") == 2);
175  ASSERT(mg_match_prefix("*/*", 3, "/a/b/c") == 2);
176  ASSERT(mg_match_prefix("**/", 3, "/a/b/c") == 5);
177  ASSERT(mg_match_prefix("**.foo|**.bar", 13, "a.bar") == 5);
178  ASSERT(mg_match_prefix("a|b|cd", 6, "cdef") == 2);
179  ASSERT(mg_match_prefix("a|b|c?", 6, "cdef") == 2);
180  ASSERT(mg_match_prefix("a|?|cd", 6, "cdef") == 1);
181  ASSERT(mg_match_prefix("/a/**.cgi", 9, "/foo/bar/x.cgi") == -1);
182  ASSERT(mg_match_prefix("/a/**.cgi", 9, "/a/bar/x.cgi") == 12);
183  ASSERT(mg_match_prefix("**/", 3, "/a/b/c") == 5);
184  ASSERT(mg_match_prefix("**/$", 4, "/a/b/c") == -1);
185  ASSERT(mg_match_prefix("**/$", 4, "/a/b/") == 5);
186  ASSERT(mg_match_prefix("$", 1, "") == 0);
187  ASSERT(mg_match_prefix("$", 1, "x") == -1);
188  ASSERT(mg_match_prefix("*$", 2, "x") == 1);
189  ASSERT(mg_match_prefix("/$", 2, "/") == 1);
190  ASSERT(mg_match_prefix("**/$", 4, "/a/b/c") == -1);
191  ASSERT(mg_match_prefix("**/$", 4, "/a/b/") == 5);
192  ASSERT(mg_match_prefix("*", 1, "/hello/") == 0);
193  ASSERT(mg_match_prefix("**.a$|**.b$", 11, "/a/b.b/") == -1);
194  ASSERT(mg_match_prefix("**.a$|**.b$", 11, "/a/b.b") == 6);
195  ASSERT(mg_match_prefix("**.a$|**.b$", 11, "/a/B.A") == 6);
196  ASSERT(mg_match_prefix("**o$", 4, "HELLO") == 5);
197  return NULL;
198 }
199 
200 static const char *test_remove_double_dots() {
201  struct { char before[30], after[30]; } data[] = {
202  {"////a", "/a"},
203  {"/.....", "/....."},
204  {"/......", "/......"},
205  {"...", "..."},
206  {"/...///", "/.../"},
207  {"/a...///", "/a.../"},
208  {"/.x", "/.x"},
209  {"/\\", "/"},
210  {"/a\\", "/a\\"},
211  {"/a\\\\...", "/a\\..."},
212  {"foo/x..y/././y/../../..", "foo/x..y/y/"},
213  {"foo/..x", "foo/..x"},
214  };
215  size_t i;
216 
217  for (i = 0; i < ARRAY_SIZE(data); i++) {
219  ASSERT(strcmp(data[i].before, data[i].after) == 0);
220  }
221 
222  return NULL;
223 }
224 
225 static const char *test_get_var(void) {
226  static const char *post[] = {
227  "a=1&&b=2&d&=&c=3%20&e=",
228  "q=&st=2012%2F11%2F13+17%3A05&et=&team_id=",
229  NULL
230  };
231  char buf[20];
232 
233  ASSERT(get_var(post[0], strlen(post[0]), "a", buf, sizeof(buf)) == 1);
234  ASSERT(buf[0] == '1' && buf[1] == '\0');
235  ASSERT(get_var(post[0], strlen(post[0]), "b", buf, sizeof(buf)) == 1);
236  ASSERT(buf[0] == '2' && buf[1] == '\0');
237  ASSERT(get_var(post[0], strlen(post[0]), "c", buf, sizeof(buf)) == 2);
238  ASSERT(buf[0] == '3' && buf[1] == ' ' && buf[2] == '\0');
239  ASSERT(get_var(post[0], strlen(post[0]), "e", buf, sizeof(buf)) == 0);
240  ASSERT(buf[0] == '\0');
241 
242  ASSERT(get_var(post[0], strlen(post[0]), "d", buf, sizeof(buf)) == -1);
243  ASSERT(get_var(post[0], strlen(post[0]), "c", buf, 2) == -2);
244 
245  ASSERT(get_var(post[0], strlen(post[0]), "x", NULL, 10) == -2);
246  ASSERT(get_var(post[0], strlen(post[0]), "x", buf, 0) == -2);
247  ASSERT(get_var(post[1], strlen(post[1]), "st", buf, 16) == -2);
248  ASSERT(get_var(post[1], strlen(post[1]), "st", buf, 17) == 16);
249  return NULL;
250 }
251 
252 static const char *test_url_decode(void) {
253  char buf[100];
254 
255  ASSERT(mg_url_decode("foo", 3, buf, 3, 0) == -1); // No space for \0
256  ASSERT(mg_url_decode("foo", 3, buf, 4, 0) == 3);
257  ASSERT(strcmp(buf, "foo") == 0);
258 
259  ASSERT(mg_url_decode("a+", 2, buf, sizeof(buf), 0) == 2);
260  ASSERT(strcmp(buf, "a+") == 0);
261 
262  ASSERT(mg_url_decode("a+", 2, buf, sizeof(buf), 1) == 2);
263  ASSERT(strcmp(buf, "a ") == 0);
264 
265  ASSERT(mg_url_decode("%61", 1, buf, sizeof(buf), 1) == 1);
266  printf("[%s]\n", buf);
267  ASSERT(strcmp(buf, "%") == 0);
268 
269  ASSERT(mg_url_decode("%61", 2, buf, sizeof(buf), 1) == 2);
270  ASSERT(strcmp(buf, "%6") == 0);
271 
272  ASSERT(mg_url_decode("%61", 3, buf, sizeof(buf), 1) == 1);
273  ASSERT(strcmp(buf, "a") == 0);
274  return NULL;
275 }
276 
277 static const char *test_url_encode(void) {
278  char buf[100];
279  ASSERT(mg_url_encode("", 0, buf, sizeof(buf)) == 0);
280  ASSERT(buf[0] == '\0');
281  ASSERT(mg_url_encode("foo", 3, buf, sizeof(buf)) == 3);
282  ASSERT(strcmp(buf, "foo") == 0);
283  ASSERT(mg_url_encode("f o", 3, buf, sizeof(buf)) == 5);
284  ASSERT(strcmp(buf, "f%20o") == 0);
285  return NULL;
286 }
287 
288 static const char *test_to64(void) {
289  ASSERT(to64("0") == 0);
290  ASSERT(to64("") == 0);
291  ASSERT(to64("123") == 123);
292  ASSERT(to64("-34") == -34);
293  ASSERT(to64("3566626116") == 3566626116);
294  return NULL;
295 }
296 
297 static const char *test_base64_encode(void) {
298  const char *in[] = {"a", "ab", "abc", "abcd", NULL};
299  const char *out[] = {"YQ==", "YWI=", "YWJj", "YWJjZA=="};
300  char buf[100];
301  int i;
302 
303  for (i = 0; in[i] != NULL; i++) {
304  base64_encode((unsigned char *) in[i], strlen(in[i]), buf);
305  ASSERT(!strcmp(buf, out[i]));
306  }
307 
308  return NULL;
309 }
310 
311 static const char *test_mg_parse_header(void) {
312  const char *str = "xx=1 kl yy, ert=234 kl=123, uri=\"/?name=x,y\", "
313  "ii=\"12\\\"34\" zz='aa bb',tt=2,gf=\"xx d=1234";
314  char buf[20];
315  ASSERT(mg_parse_header(str, "yy", buf, sizeof(buf)) == 0);
316  ASSERT(mg_parse_header(str, "ert", buf, sizeof(buf)) == 3);
317  ASSERT(strcmp(buf, "234") == 0);
318  ASSERT(mg_parse_header(str, "ert", buf, 2) == 0);
319  ASSERT(mg_parse_header(str, "ert", buf, 3) == 0);
320  ASSERT(mg_parse_header(str, "ert", buf, 4) == 3);
321  ASSERT(mg_parse_header(str, "gf", buf, sizeof(buf)) == 0);
322  ASSERT(mg_parse_header(str, "zz", buf, sizeof(buf)) == 5);
323  ASSERT(strcmp(buf, "aa bb") == 0);
324  ASSERT(mg_parse_header(str, "d", buf, sizeof(buf)) == 4);
325  ASSERT(strcmp(buf, "1234") == 0);
326  buf[0] = 'x';
327  ASSERT(mg_parse_header(str, "MMM", buf, sizeof(buf)) == 0);
328  ASSERT(buf[0] == '\0');
329  ASSERT(mg_parse_header(str, "kl", buf, sizeof(buf)) == 3);
330  ASSERT(strcmp(buf, "123") == 0);
331  ASSERT(mg_parse_header(str, "xx", buf, sizeof(buf)) == 1);
332  ASSERT(strcmp(buf, "1") == 0);
333  ASSERT(mg_parse_header(str, "ii", buf, sizeof(buf)) == 5);
334  ASSERT(strcmp(buf, "12\"34") == 0);
335  ASSERT(mg_parse_header(str, "tt", buf, sizeof(buf)) == 1);
336  ASSERT(strcmp(buf, "2") == 0);
337  ASSERT(mg_parse_header(str, "uri", buf, sizeof(buf)) == 10);
338  return NULL;
339 }
340 
341 static const char *test_next_option(void) {
342  const char *p, *list = "x/8,/y**=1;2k,z";
343  struct vec a, b;
344  int i;
345 
346  ASSERT(next_option(NULL, &a, &b) == NULL);
347  for (i = 0, p = list; (p = next_option(p, &a, &b)) != NULL; i++) {
348  ASSERT(i != 0 || (a.ptr == list && a.len == 3 && b.len == 0));
349  ASSERT(i != 1 || (a.ptr == list + 4 && a.len == 4 && b.ptr == list + 9 &&
350  b.len == 4));
351 
352  ASSERT(i != 2 || (a.ptr == list + 14 && a.len == 1 && b.len == 0));
353  }
354  return NULL;
355 }
356 
357 static int evh1(struct mg_connection *conn, enum mg_event ev) {
358  char *buf = (char *) conn->connection_param;
359  int result = MG_FALSE;
360 
361  switch (ev) {
362  case MG_CONNECT:
363  mg_printf(conn, "GET %s HTTP/1.0\r\n\r\n",
364  buf[0] == '1' ? "/cb1" : "/non_exist");
365  result = MG_TRUE;
366  break;
367  case MG_HTTP_ERROR:
368  mg_printf(conn, "HTTP/1.0 404 NF\r\n\r\nERR: %d", conn->status_code);
369  result = MG_TRUE;
370  break;
371  case MG_REQUEST:
372  if (!strcmp(conn->uri, "/cb1")) {
373  mg_printf(conn, "HTTP/1.0 200 OK\r\n\r\n%s %s %s",
374  (char *) conn->server_param,
375  buf == NULL ? "?" : "!", conn->remote_ip);
376  result = MG_TRUE;
377  }
378  break;
379  case MG_REPLY:
380  if (buf != NULL) {
381  sprintf(buf + 1, "%.*s", (int) conn->content_len, conn->content);
382  }
383  break;
384  case MG_AUTH:
385  result = MG_TRUE;
386  break;
387  default:
388  break;
389  }
390 
391  return result;
392 }
393 
394 static const char *test_server(void) {
395  char buf1[100] = "1", buf2[100] = "2";
396  struct mg_server *server = mg_create_server((void *) "foo", evh1);
397  struct mg_connection *conn;
398 
399  ASSERT(server != NULL);
400  ASSERT(mg_set_option(server, "listening_port", LISTENING_ADDR) == NULL);
401  ASSERT(mg_set_option(server, "document_root", ".") == NULL);
402 
403  ASSERT((conn = mg_connect(server, "127.0.0.1:" HTTP_PORT)) != NULL);
404  conn->connection_param = buf1;
405  ASSERT((conn = mg_connect(server, "127.0.0.1:" HTTP_PORT)) != NULL);
406  conn->connection_param = buf2;
407 
408  { int i; for (i = 0; i < 50; i++) mg_poll_server(server, 1); }
409  ASSERT(strcmp(buf1, "1foo ? 127.0.0.1") == 0);
410  ASSERT(strcmp(buf2, "2ERR: 404") == 0);
411 
412  ASSERT(strcmp(static_config_options[URL_REWRITES * 2], "url_rewrites") == 0);
413  mg_destroy_server(&server);
414  ASSERT(server == NULL);
415  return NULL;
416 }
417 
418 #define DISP "Content-Disposition: form/data; "
419 #define CRLF "\r\n"
420 #define BOUNDARY "--xyz"
421 static const char *test_parse_multipart(void) {
422  char a[100], b[100];
423  const char *p;
424  static const char f1[] = BOUNDARY CRLF DISP "name=f1" CRLF CRLF
425  "some_content" CRLF BOUNDARY CRLF
426  BOUNDARY CRLF DISP "name=f2; filename=\"foo bar.txt\"" CRLF CRLF
427  "another_content" CRLF BOUNDARY CRLF
428  "--" CRLF;
429  int n, n2, len, f1_len = sizeof(f1) - 1;
430 
431  ASSERT(mg_parse_multipart("", 0, a, sizeof(a), b, sizeof(b), &p, &len) == 0);
432  ASSERT(mg_parse_multipart("a", 1, a, sizeof(a), b, sizeof(b), &p, &len) == 0);
433  ASSERT((n = mg_parse_multipart(f1, f1_len, a, sizeof(a),
434  b, sizeof(b), &p, &len)) > 0);
435  ASSERT(len == 12);
436  ASSERT(memcmp(p, "some_content", len) == 0);
437  ASSERT(strcmp(a, "f1") == 0);
438  ASSERT(b[0] == '\0');
439 
440  ASSERT((n2 = mg_parse_multipart(f1 + n, f1_len - n, a, sizeof(a),
441  b, sizeof(b), &p, &len)) > 0);
442  ASSERT(len == 15);
443  ASSERT(memcmp(p, "another_content", len) == 0);
444  ASSERT(strcmp(a, "f2") == 0);
445  ASSERT(strcmp(b, "foo bar.txt") == 0);
446 
447  ASSERT((n2 = mg_parse_multipart(f1 + n + n2, f1_len - (n + n2), a, sizeof(a),
448  b, sizeof(b), &p, &len)) == 0);
449 
450  return NULL;
451 }
452 
453 static int evh2(struct mg_connection *conn, enum mg_event ev) {
454  char *file_data, *cp = (char *) conn->connection_param;
455  int file_size, result = MG_FALSE;
456 
457  switch (ev) {
458  case MG_AUTH:
459  result = MG_TRUE;
460  break;
461  case MG_CONNECT:
462  mg_printf(conn, "GET /%s HTTP/1.0\r\n\r\n", cp);
463  result = MG_TRUE;
464  break;
465  case MG_REQUEST:
466  break;
467  case MG_REPLY:
468  file_data = read_file("unit_test.c", &file_size);
469  sprintf(cp, "%d %s", (size_t) file_size == conn->content_len &&
470  memcmp(file_data, conn->content, file_size) == 0 ? 1 : 0,
471  conn->query_string == NULL ? "?" : conn->query_string);
472  free(file_data);
473  break;
474  default:
475  break;
476  }
477 
478  return result;
479 }
480 
481 static const char *test_mg_set_option(void) {
482  struct mg_server *server = mg_create_server(NULL, NULL);
483  ASSERT(mg_set_option(server, "listening_port", "0") == NULL);
484  ASSERT(mg_get_option(server, "listening_port")[0] != '\0');
485  mg_destroy_server(&server);
486  return NULL;
487 }
488 
489 static const char *test_rewrites(void) {
490  char buf1[100] = "xx", addr[50];
491  struct mg_server *server = mg_create_server(NULL, evh2);
492  struct mg_connection *conn;
493  const char *port;
494 
495  ASSERT(mg_set_option(server, "listening_port", "0") == NULL);
496  ASSERT(mg_set_option(server, "document_root", ".") == NULL);
497  ASSERT(mg_set_option(server, "url_rewrites", "/xx=unit_test.c") == NULL);
498  ASSERT((port = mg_get_option(server, "listening_port")) != NULL);
499  snprintf(addr, sizeof(addr), "127.0.0.1:%s", port);
500  ASSERT((conn = mg_connect(server, addr)) != NULL);
501  conn->connection_param = buf1;
502 
503  { int i; for (i = 0; i < 50; i++) mg_poll_server(server, 1); }
504 
505  ASSERT(strcmp(buf1, "1 ?") == 0);
506  mg_destroy_server(&server);
507  return NULL;
508 }
509 
510 static const char *run_all_tests(void) {
526  return NULL;
527 }
528 
529 int __cdecl main(void) {
530  const char *fail_msg = run_all_tests();
531  printf("%s, tests run: %d\n", fail_msg ? "FAIL" : "PASS", static_num_tests);
532  return fail_msg == NULL ? EXIT_SUCCESS : EXIT_FAILURE;
533 }
#define free(ptr)
Definition: curl_memory.h:130
static const char * test_get_var(void)
Definition: unit_test.c:225
static const char * test_next_option(void)
Definition: unit_test.c:341
struct mg_connection::mg_header http_headers[30]
struct curl_httppost * post
Definition: unit1308.c:45
static const char * test_to64(void)
Definition: unit_test.c:288
static const char * run_all_tests(void)
Definition: unit_test.c:510
static const char * test_base64_encode(void)
Definition: unit_test.c:297
static void remove_double_dots_and_double_slashes(char *s)
Definition: mongoose.c:2436
void * connection_param
Definition: mongoose.h:56
static const char * test_remove_double_dots()
Definition: unit_test.c:200
int stat(const char *path, struct stat *buffer)
#define LISTENING_ADDR
Definition: unit_test.c:28
#define __cdecl
Definition: web_server.c:58
static const char * test_mg_parse_header(void)
Definition: unit_test.c:311
const char * uri
Definition: mongoose.h:34
const char * ptr
Definition: mongoose.c:1395
static const char * test_url_decode(void)
Definition: unit_test.c:252
static const char * test_server(void)
Definition: unit_test.c:394
static int static_num_tests
Definition: unit_test.c:30
static char * read_file(const char *path, int *size)
Definition: unit_test.c:80
struct mg_server * mg_create_server(void *server_data, mg_handler_t handler)
Definition: mongoose.c:5431
const char * mg_get_option(const struct mg_server *server, const char *name)
Definition: mongoose.c:5425
#define realloc(ptr, size)
Definition: curl_memory.h:128
if(strcmp(arg,"1305")!=0)
Definition: unit1305.c:127
int status_code
Definition: mongoose.h:53
#define malloc(size)
Definition: curl_memory.h:124
#define vsnprintf
Definition: curl_printf.h:45
size_t len
Definition: mongoose.c:1396
UNITTEST_START int result
Definition: unit1304.c:49
const char ** p
Definition: unit1394.c:76
static const char * test_parse_multipart(void)
Definition: unit_test.c:421
unsigned int i
Definition: unit1303.c:79
static int get_request_len(const char *s, size_t buf_len)
Definition: mongoose.c:1760
static int evh2(struct mg_connection *conn, enum mg_event ev)
Definition: unit_test.c:453
size_t len
Definition: curl_sasl.c:55
static int should_keep_alive(const struct mg_connection *conn)
Definition: mongoose.c:2733
static const char * test_parse_http_message()
Definition: unit_test.c:93
time_t mg_poll_server(struct mg_server *server, int milliseconds)
Definition: mongoose.c:4965
int mg_parse_header(const char *s, const char *var_name, char *buf, size_t buf_size)
Definition: mongoose.c:4258
size_t mg_url_encode(const char *src, size_t s_len, char *dst, size_t dst_len)
Definition: mongoose.c:3541
memcpy(filename, filename1, strlen(filename1))
#define sprintf
Definition: curl_printf.h:53
static const char * test_rewrites(void)
Definition: unit_test.c:489
const char * str
Definition: unit1398.c:33
#define ASSERT(expr)
Definition: unit_test.c:19
Definition: mongoose.c:1394
#define DISP
Definition: unit_test.c:418
const char * value
Definition: mongoose.h:46
static const char * next_option(const char *list, struct vec *val, struct vec *eq_val)
Definition: mongoose.c:1699
const char * query_string
Definition: mongoose.h:36
#define printf
Definition: curl_printf.h:40
Definition: unit1323.c:36
UNITTEST_START struct Curl_easy data
Definition: unit1399.c:82
mg_event
Definition: mongoose.h:62
static struct mg_server * server
Definition: web_server.c:72
#define connect
Definition: setup-os400.h:210
const char * name
Definition: mongoose.h:45
int num_headers
Definition: mongoose.h:43
static unsigned short port
Definition: sockfilt.c:137
static const char * test_should_keep_alive(void)
Definition: unit_test.c:145
struct mg_connection * mg_connect(struct mg_server *server, const char *addr)
Definition: mongoose.c:4818
static int evh1(struct mg_connection *conn, enum mg_event ev)
Definition: unit_test.c:357
#define HTTP_PORT
Definition: unit_test.c:27
#define closesocket(x)
Definition: net_skeleton.h:103
int __cdecl main(void)
Definition: unit_test.c:529
char remote_ip[48]
Definition: mongoose.h:38
size_t fread(void *, size_t, size_t, FILE *)
static const char * test_mg_set_option(void)
Definition: unit_test.c:481
static size_t parse_http_message(char *buf, size_t len, struct mg_connection *ri)
Definition: mongoose.c:2492
static CURLcode base64_encode(const char *table64, struct Curl_easy *data, const char *inputbuff, size_t insize, char **outptr, size_t *outlen)
Definition: base64.c:171
char buf[3]
Definition: unit1398.c:32
const char * mg_set_option(struct mg_server *server, const char *name, const char *value)
Definition: mongoose.c:5143
static const char * test_match_prefix(void)
Definition: unit_test.c:168
size_t mg_printf(struct mg_connection *conn, const char *fmt,...)
Definition: mongoose.c:1949
const char * http_version
Definition: mongoose.h:35
const T1 & f1
Definition: gtest-tuple.h:683
int mg_match_prefix(const char *pattern, ssize_t pattern_len, const char *str)
Definition: mongoose.c:2577
size_t size
Definition: unit1302.c:52
static const char * test_url_encode(void)
Definition: unit_test.c:277
#define snprintf
Definition: curl_printf.h:42
int fileno(FILE *stream)
static int get_var(const char *data, size_t data_len, const char *name, char *dst, size_t dst_len)
Definition: mongoose.c:4993
const char * request_method
Definition: mongoose.h:33
#define BOUNDARY
Definition: unit_test.c:420
int mg_parse_multipart(const char *buf, int buf_len, char *var_name, int var_name_len, char *file_name, int file_name_len, const char **data, int *data_len)
Definition: mongoose.c:5056
#define to64(x)
Definition: net_skeleton.h:106
#define ARRAY_SIZE(array)
Definition: net_skeleton.h:119
void mg_destroy_server(struct mg_server **server)
Definition: mongoose.c:4969
#define RUN_TEST(test)
Definition: unit_test.c:24
#define CRLF
Definition: unit_test.c:419
Definition: debug.c:29
size_t content_len
Definition: mongoose.h:50
int mg_url_decode(const char *src, size_t src_len, char *dst, size_t dst_len, int is_form_url_encoded)
Definition: mongoose.c:2455
char * content
Definition: mongoose.h:49
const char * path
Definition: util.c:192
static const char * static_config_options[]
Definition: mongoose.c:1446
void * server_param
Definition: mongoose.h:55


rc_tagdetect_client
Author(s): Monika Florek-Jasinska , Raphael Schaller
autogenerated on Sat Feb 13 2021 03:42:16