Commit 88a06a5e authored by Geoff Simmons's avatar Geoff Simmons

a smarter test for format_t

parent 8034a796
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
* *
*/ */
/* including source must include varnishevent.h and vre.h */ /* including source must include varnishevent.h */
/* XXX: init as fixed size with length max_reclen + 1 */ /* XXX: init as fixed size with length max_reclen + 1 */
struct vsb *payload; struct vsb *payload;
......
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
#include <math.h> #include <math.h>
#include <time.h> #include <time.h>
#include "vre.h"
#include "minunit.h" #include "minunit.h"
#include "../varnishevent.h" #include "../varnishevent.h"
...@@ -779,31 +778,23 @@ static const char ...@@ -779,31 +778,23 @@ static const char
tx_t tx; tx_t tx;
logline_t rec; logline_t rec;
chunk_t chunk; chunk_t chunk;
char *str; char *str = NULL, strftime_s[BUFSIZ], fmt[] = "[%d/%b/%Y:%T %z]";
const char *error;
size_t len; size_t len;
vre_t *time_re; struct tm *tm;
int n; time_t t = 1427743146;
printf("... testing format_t()\n"); printf("... testing format_t()\n");
#define HTTP_DATA_REGEX \
"^\\[\\d\\d/Mar/2015:\\d\\d:\\d\\d:\\d\\d [+-]\\d{4}\\]$"
time_re = VRE_compile(HTTP_DATA_REGEX, 0, &error, &n);
VMASSERT(time_re != NULL,
"Error compiling '" HTTP_DATA_REGEX "': %s (offset %d)",
error, n);
init_tx_rec_chunk(&tx, &rec, &chunk); init_tx_rec_chunk(&tx, &rec, &chunk);
MAN(chunk.data); MAN(chunk.data);
set_record_data(&rec, &chunk, T1, SLT_Timestamp); set_record_data(&rec, &chunk, T1, SLT_Timestamp);
tm = localtime(&t);
MAN(strftime(strftime_s, config.max_reclen, fmt, tm));
format_t(&tx, NULL, SLT__Bogus, &str, &len); format_t(&tx, NULL, SLT__Bogus, &str, &len);
n = VRE_exec(time_re, str, strlen(str), 0, 0, NULL, 0, NULL); MAN(str);
VMASSERT(n > 0, "'%s' does not match '" HTTP_DATA_REGEX "', " VMASSERT(strcmp(str, strftime_s) == 0, "'%s' != '%s'", str, strftime_s);
"return code = %d", str, n); MASSERT(len == strlen(strftime_s));
MASSERT(len == 28);
return NULL; return NULL;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment