Commit 8034a796 authored by Geoff Simmons's avatar Geoff Simmons

implement and test the %{X}t formatter

parent 58acaecb
......@@ -425,15 +425,15 @@ format_##ltr(tx_t *tx, char *name, enum VSL_tag_e tag, \
{ \
double t; \
(void) tag; \
(extra); \
extra; \
\
t = get_tm(tx); \
AN(scratch); \
size_t n = strfTIMlocal(scratch, config.max_reclen, fmt, t); \
if (n == 0) \
*scratch = '\0'; \
*s = scratch; \
*len = strlen(scratch); \
if (n != 0) { \
*s = scratch; \
*len = strlen(scratch); \
} \
}
FORMAT_tim(t, "[%d/%b/%Y:%T %z]", (void) name)
......@@ -523,10 +523,10 @@ FORMAT_Xio(backend, i, BereqHeader)
FORMAT_Xio(client, o, RespHeader)
FORMAT_Xio(backend, o, BerespHeader)
#if 0
FORMAT_tim(Xt, name, )
#if 0
static void
format_Xttfb_client(logline_t *ll, char *name, enum VSL_tag_e tag,
char **s, size_t *len)
......
......@@ -89,3 +89,5 @@ formatter_f format_Xi_client;
formatter_f format_Xi_backend;
formatter_f format_Xo_client;
formatter_f format_Xo_backend;
formatter_f format_Xt;
......@@ -31,6 +31,7 @@
#include <string.h>
#include <math.h>
#include <time.h>
#include "vre.h"
#include "minunit.h"
......@@ -990,6 +991,54 @@ static const char
return NULL;
}
static const char
*test_format_Xt(void)
{
tx_t tx;
logline_t rec;
chunk_t chunk;
char *str = NULL, strftime_s[BUFSIZ];
size_t len;
char fmt[] =
"%a %A %b %B %c %C %d %D %e %F %g %G %h %H %I %j %m %M %n %p %r %R %S "\
"%t %T %u %U %V %w %W %x %X %y %Y %z %Z %%";
char afmt[] =
"%Ec %EC %Ex %EX %Ey %Ey %Od %Oe %OH %OI %Om %OM %OS %Ou %OU %OV %Ow "\
"%OW %Oy";
char subs[] = "%N";
struct tm *tm;
time_t t = 1427743146;
printf("... testing format_Xt()\n");
init_tx_rec_chunk(&tx, &rec, &chunk);
MAN(chunk.data);
set_record_data(&rec, &chunk, T1, SLT_Timestamp);
tm = localtime(&t);
MAN(strftime(strftime_s, config.max_reclen, fmt, tm));
format_Xt(&tx, fmt, SLT__Bogus, &str, &len);
MAN(str);
VMASSERT(strcmp(str, strftime_s) == 0, "'%s' != '%s'", str, strftime_s);
MASSERT(len == strlen(strftime_s));
/* Alternative strftime formatters */
MAN(strftime(strftime_s, config.max_reclen, afmt, tm));
format_Xt(&tx, afmt, SLT__Bogus, &str, &len);
MAN(str);
VMASSERT(strcmp(str, strftime_s) == 0, "'%s' != '%s'", str, strftime_s);
MASSERT(len == strlen(strftime_s));
/* subsecond formatter */
format_Xt(&tx, subs, SLT__Bogus, &str, &len);
MAN(str);
/* ms accuracy ... */
VMASSERT(strncmp(str, "529306000", 3) == 0, "'%s' != '529306000'", str);
MASSERT(len == 9);
return NULL;
}
static const char
*all_tests(void)
{
......@@ -1016,6 +1065,7 @@ static const char
mu_run_test(test_format_u);
mu_run_test(test_format_Xi);
mu_run_test(test_format_Xo);
mu_run_test(test_format_Xt);
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