|
@@ -15,8 +15,10 @@ START_TEST(test_logger_init)
|
15
|
15
|
pyfcgi_logger_init();
|
16
|
16
|
ck_assert_ptr_eq(conf->syslog_ident, NULL);
|
17
|
17
|
ck_assert_ptr_eq(conf->ident, NULL);
|
18
|
|
- ck_assert_ptr_eq(conf->format, NULL);
|
|
18
|
+ /*
|
|
19
|
+ ck_assert_ptr_eq(conf->formats, NULL);
|
19
|
20
|
ck_assert_ptr_eq(conf->loggers, NULL);
|
|
21
|
+ */
|
20
|
22
|
ck_assert_int_eq(conf->logger_sz, 0);
|
21
|
23
|
ck_assert_int_eq(conf->format_sz, 0);
|
22
|
24
|
ck_assert_int_eq(conf->flags, 0);
|
|
@@ -24,19 +26,20 @@ START_TEST(test_logger_init)
|
24
|
26
|
}
|
25
|
27
|
END_TEST
|
26
|
28
|
|
27
|
|
-/*
|
28
|
29
|
START_TEST(test_logger_format_add)
|
29
|
30
|
{
|
30
|
31
|
int ret;
|
31
|
32
|
size_t s;
|
32
|
33
|
pyfcgi_logger_init();
|
|
34
|
+ const char *fmt = "{datetime} {level} {ident}[{pid}] {msg}";
|
33
|
35
|
|
34
|
|
- ret = pyfcgi_logger_format_add("TEST", NULL);
|
|
36
|
+ ret = pyfcgi_logger_format_add(fmt, &s);
|
35
|
37
|
ck_assert_int_eq(conf->format_sz, 1);
|
36
|
|
- ck_assert_str_eq(conf->format[0], "TEST");
|
|
38
|
+ ck_assert_int_eq(s, 0);
|
|
39
|
+ ck_assert_str_eq(conf->formats[s].fmt, fmt);
|
|
40
|
+
|
37
|
41
|
}
|
38
|
42
|
END_TEST
|
39
|
|
-*/
|
40
|
43
|
|
41
|
44
|
/*
|
42
|
45
|
TC logger default values
|
|
@@ -54,7 +57,7 @@ START_TEST(test_logger_parse_field_dtfmt_default)
|
54
|
57
|
ret = pyfcgi_logger_parse_field_dtfmt((const char**)&ptr, &fmt);
|
55
|
58
|
ck_assert_int_eq(ret, 0);
|
56
|
59
|
ck_assert_str_eq(fmt, PYFCGI_LOGGER_TIME_FMT_DEFAULT);
|
57
|
|
- ck_assert_ptr_eq(ptr, orig+1);
|
|
60
|
+ ck_assert_ptr_eq(ptr, orig);
|
58
|
61
|
free(fmt);
|
59
|
62
|
}
|
60
|
63
|
END_TEST
|
|
@@ -74,7 +77,7 @@ START_TEST(test_logger_parse_field_sz_default)
|
74
|
77
|
ret = pyfcgi_logger_parse_field_sz((const char**)&ptr, &val);
|
75
|
78
|
ck_assert_int_eq(ret, 0);
|
76
|
79
|
ck_assert_int_eq(val, 0);
|
77
|
|
- ck_assert_ptr_eq(ptr, (*orig)+1);
|
|
80
|
+ ck_assert_ptr_eq(ptr, (*orig));
|
78
|
81
|
orig++;
|
79
|
82
|
}
|
80
|
83
|
}
|
|
@@ -122,11 +125,13 @@ START_TEST(test_logger_parse_field_sz)
|
122
|
125
|
{
|
123
|
126
|
int ret, *res;
|
124
|
127
|
size_t val;
|
125
|
|
- char *ptr, **orig;
|
126
|
|
- char *vals[] = {"42:%F}", "1337:}", "0}", NULL};
|
127
|
|
- int _res[] = {42,1337,0};
|
|
128
|
+ char *ptr, **orig, **eptr;
|
|
129
|
+ char *vals[] = {"42:%F}", "1337:}", "0}", ":}", NULL};
|
|
130
|
+ int _res[] = {42,1337,0, 0};
|
|
131
|
+ char *_eptr[] = {vals[0]+2, vals[1]+4, vals[2]+1, vals[3]};
|
128
|
132
|
|
129
|
133
|
orig = vals;
|
|
134
|
+ eptr = _eptr;
|
130
|
135
|
res = _res;
|
131
|
136
|
while(*orig)
|
132
|
137
|
{
|
|
@@ -134,9 +139,10 @@ START_TEST(test_logger_parse_field_sz)
|
134
|
139
|
|
135
|
140
|
ret = pyfcgi_logger_parse_field_sz((const char**)&ptr, &val);
|
136
|
141
|
ck_assert_int_eq(val, *res);
|
137
|
|
- ck_assert_ptr_eq(ptr, (*orig)+snprintf(NULL, 0, "%d", *res));
|
|
142
|
+ ck_assert_ptr_eq(ptr, *eptr);
|
138
|
143
|
orig++;
|
139
|
144
|
res++;
|
|
145
|
+ eptr++;
|
140
|
146
|
}
|
141
|
147
|
}
|
142
|
148
|
END_TEST
|
|
@@ -174,10 +180,16 @@ START_TEST(test_logger_parse_field_datetime)
|
174
|
180
|
pyfcgi_logger_fmt_field_t field;
|
175
|
181
|
char *vals[] = {"datetime:42}", "datetime::%s%F}",
|
176
|
182
|
"datetime:42:COUCOU}",
|
177
|
|
- "dat:32:FOO}", "d::BAR}", NULL};
|
178
|
|
- int _len[] = {42, PYFCGI_LOG_DTM_LEN, 42, 32, PYFCGI_LOG_DTM_LEN};
|
|
183
|
+ "dat:32:FOO}", "d::BAR}",
|
|
184
|
+ "datetime}{level}", "datetime} {level}",
|
|
185
|
+ "datetime}:{level}",
|
|
186
|
+ NULL};
|
|
187
|
+ int _len[] = {42, PYFCGI_LOG_DTM_LEN, 42, 32, PYFCGI_LOG_DTM_LEN,
|
|
188
|
+ PYFCGI_LOG_DTM_LEN, PYFCGI_LOG_DTM_LEN, PYFCGI_LOG_DTM_LEN};
|
179
|
189
|
char *_fmt[] = {PYFCGI_LOGGER_TIME_FMT_DEFAULT, "%s%F", "COUCOU", "FOO",
|
180
|
|
- "BAR"};
|
|
190
|
+ "BAR", PYFCGI_LOGGER_TIME_FMT_DEFAULT,
|
|
191
|
+ PYFCGI_LOGGER_TIME_FMT_DEFAULT,
|
|
192
|
+ PYFCGI_LOGGER_TIME_FMT_DEFAULT};
|
181
|
193
|
|
182
|
194
|
memset(&field, 0, sizeof(pyfcgi_logger_fmt_field_t));
|
183
|
195
|
|
|
@@ -339,8 +351,9 @@ START_TEST(test_logger_parse_field_msg)
|
339
|
351
|
int ret;
|
340
|
352
|
char **val, **ptr;
|
341
|
353
|
char err[PYFCGI_LOGGER_FMT_PARSE_ERRSZ];
|
342
|
|
- char *vals[] = {"msg}", "m}", "ms}", NULL};
|
343
|
354
|
pyfcgi_logger_fmt_field_t field;
|
|
355
|
+ char *vals[] = {"msg}", "m}", "ms}", NULL};
|
|
356
|
+
|
344
|
357
|
|
345
|
358
|
val = vals;
|
346
|
359
|
memset(&field, 0, sizeof(pyfcgi_logger_fmt_field_t));
|
|
@@ -365,6 +378,35 @@ START_TEST(test_logger_parse_field_msg)
|
365
|
378
|
}
|
366
|
379
|
END_TEST
|
367
|
380
|
|
|
381
|
+START_TEST(test_logger_format_parse1)
|
|
382
|
+{
|
|
383
|
+ int ret, i;
|
|
384
|
+ size_t s;
|
|
385
|
+ pyfcgi_logger_init();
|
|
386
|
+ const char *fmt = "{datetime} {level} {ident}[{pid}] {msg}";
|
|
387
|
+ pyfcgi_logger_field_type_e types[] = {
|
|
388
|
+ pyfcgi_logger_field_datetime, pyfcgi_logger_field_const,
|
|
389
|
+ pyfcgi_logger_field_level, pyfcgi_logger_field_const,
|
|
390
|
+ pyfcgi_logger_field_ident, pyfcgi_logger_field_const,
|
|
391
|
+ pyfcgi_logger_field_pid, pyfcgi_logger_field_const,
|
|
392
|
+ pyfcgi_logger_field_msg};
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+ ret = pyfcgi_logger_format_add(fmt, &s);
|
|
396
|
+ ck_assert_int_eq(ret, 0);
|
|
397
|
+ ck_assert_int_eq(conf->format_sz, 1);
|
|
398
|
+ ck_assert_int_eq(s, 0);
|
|
399
|
+ ck_assert_str_eq(conf->formats[s].fmt, fmt);
|
|
400
|
+ for(i=0; i<9; i++)
|
|
401
|
+ {
|
|
402
|
+dprintf(2, "I=%d\n", i);
|
|
403
|
+ ck_assert_int_eq(conf->formats[s].fields[i].type, types[i]);
|
|
404
|
+ }
|
|
405
|
+ ck_assert_int_eq(conf->formats[s].nfield, 9);
|
|
406
|
+
|
|
407
|
+}
|
|
408
|
+END_TEST
|
|
409
|
+
|
368
|
410
|
/*
|
369
|
411
|
TC logger format parsing error
|
370
|
412
|
*/
|
|
@@ -425,11 +467,6 @@ Suite * logger_suite(void)
|
425
|
467
|
|
426
|
468
|
s = suite_create("Logger");
|
427
|
469
|
|
428
|
|
- tc_init = tcase_create("Initialisation");
|
429
|
|
- tcase_add_test(tc_init, test_logger_init);
|
430
|
|
- //tcase_add_test(tc_init, test_logger_format_add);
|
431
|
|
- suite_add_tcase(s, tc_init);
|
432
|
|
-
|
433
|
470
|
tc_field_default = tcase_create("Logger format parsing default values");
|
434
|
471
|
tcase_add_test(tc_field_default, test_logger_parse_field_dtfmt_default);
|
435
|
472
|
tcase_add_test(tc_field_default, test_logger_parse_field_sz_default);
|
|
@@ -444,6 +481,7 @@ Suite * logger_suite(void)
|
444
|
481
|
tcase_add_test(tc_field, test_logger_parse_field_pid);
|
445
|
482
|
tcase_add_test(tc_field, test_logger_parse_field_ident);
|
446
|
483
|
tcase_add_test(tc_field, test_logger_parse_field_msg);
|
|
484
|
+ tcase_add_test(tc_field, test_logger_format_parse1);
|
447
|
485
|
suite_add_tcase(s, tc_field);
|
448
|
486
|
|
449
|
487
|
tc_parse_err = tcase_create("Logger format parsing errors handling");
|
|
@@ -451,6 +489,11 @@ Suite * logger_suite(void)
|
451
|
489
|
tcase_add_test(tc_parse_err, test_logger_parse_field_parse_err);
|
452
|
490
|
suite_add_tcase(s, tc_parse_err);
|
453
|
491
|
|
|
492
|
+ tc_init = tcase_create("Initialisation");
|
|
493
|
+ tcase_add_test(tc_init, test_logger_init);
|
|
494
|
+ tcase_add_test(tc_init, test_logger_format_add);
|
|
495
|
+ suite_add_tcase(s, tc_init);
|
|
496
|
+
|
454
|
497
|
|
455
|
498
|
return s;
|
456
|
499
|
}
|