summaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorGergely Nagy <algernon@balabit.hu>2012-07-19 13:34:49 +0200
committerGergely Nagy <algernon@balabit.hu>2012-07-19 13:34:49 +0200
commit841f531dd0e1a95a9ce08c78b85d388806229394 (patch)
tree66fca2c17e43c02bec5c5c99cfd2b96690d4d8b8 /t
parentcd7703d466b98e9eb45df97b5d91794ef5bdeb90 (diff)
downloadlibumberlog-841f531dd0e1a95a9ce08c78b85d388806229394.tar.gz
libumberlog-841f531dd0e1a95a9ce08c78b85d388806229394.tar.xz
libumberlog-841f531dd0e1a95a9ce08c78b85d388806229394.zip
Leave printf format parsing to glibc if possible.
Call glibc's parse_printf_format() to gather information about argument types. This automatically handles positional parameters and user-defined printf formats for ordinary parameter types; it doesn't handle user-defined printf parameter types (such as defined by libdfp for decimal floating-point). Also add a (non-comprehensive) test. Signed-off-by: Miloslav Trmač <mitr@redhat.com> Signed-off-by: Gergely Nagy <algernon@balabit.hu>
Diffstat (limited to 't')
-rw-r--r--t/test_umberlog.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/t/test_umberlog.c b/t/test_umberlog.c
index 340ea43..69d1a16 100644
--- a/t/test_umberlog.c
+++ b/t/test_umberlog.c
@@ -1,6 +1,7 @@
#define _GNU_SOURCE 1
#include "umberlog.h"
+#include "config.h"
#include <json.h>
#include <assert.h>
#include <string.h>
@@ -262,6 +263,37 @@ START_TEST (test_closelog)
}
END_TEST
+#ifdef HAVE_PARSE_PRINTF_FORMAT
+START_TEST (test_positional_params)
+{
+ char *msg;
+ struct json_object *jo;
+
+ openlog ("umberlog/test_positional_params", LOG_UL_NOTIME, LOG_LOCAL0);
+
+#define COMPLEX_FORMAT \
+ "%3$*5$.*2$hhd , %1$Lf , %4$.3s , %4$s", 1.0L, 5, (char)100, "prefix", -8
+#define COMPLEX_RESULT "00100 , 1.000000 , pre , prefix"
+ msg = ul_format (LOG_DEBUG, COMPLEX_FORMAT,
+ "simple1", "value1",
+ "complex", COMPLEX_FORMAT,
+ "simple2", "value2",
+ NULL);
+ jo = parse_msg (msg);
+ free (msg);
+
+ verify_value (jo, "msg", COMPLEX_RESULT);
+ verify_value (jo, "simple1", "value1");
+ verify_value (jo, "complex", COMPLEX_RESULT);
+ verify_value (jo, "simple2", "value2");
+
+ json_object_put (jo);
+
+ closelog ();
+}
+END_TEST
+#endif
+
int
main (void)
{
@@ -278,6 +310,9 @@ main (void)
tcase_add_test (ft, test_additional_fields);
tcase_add_test (ft, test_discover_priority);
tcase_add_test (ft, test_no_timestamp);
+#ifdef HAVE_PARSE_PRINTF_FORMAT
+ tcase_add_test (ft, test_positional_params);
+#endif
suite_add_tcase (s, ft);
bt = tcase_create ("Bug tests");