test/logging_tests.c

Wed, 27 Feb 2013 10:09:23 +0100

author
Mike Becker <universe@uap-core.de>
date
Wed, 27 Feb 2013 10:09:23 +0100
changeset 89
47f7fdbddb62
parent 81
86a23238d8a1
child 95
ecfdc1c4a552
permissions
-rw-r--r--

comparator module

54
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 *
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 */
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 #include "logging_tests.h"
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 UCX_TEST_IMPLEMENT(test_ucx_logger_log) {
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 char buffer[100];
55
180bc6b18fec fixed map tests + used tmpfiles in tests
Mike Becker <universe@uap-core.de>
parents: 54
diff changeset
9 FILE *stream = tmpfile();
180bc6b18fec fixed map tests + used tmpfiles in tests
Mike Becker <universe@uap-core.de>
parents: 54
diff changeset
10
80
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 75
diff changeset
11 UcxLogger *logger = ucx_logger_new(stream,
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 75
diff changeset
12 UCX_LOGGER_INFO, UCX_LOGGER_SOURCE | UCX_LOGGER_LEVEL);
54
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 UCX_TEST_BEGIN
81
86a23238d8a1 changed logger to behave more like printf + added possibility to specify write function
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
15 ucx_logger_info(logger, "allright");
86a23238d8a1 changed logger to behave more like printf + added possibility to specify write function
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
16 ucx_logger_trace(logger, "dont log this!");
86a23238d8a1 changed logger to behave more like printf + added possibility to specify write function
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
17 ucx_logger_error(logger, "error %d!", 42);
54
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 fseek(stream, 0, SEEK_SET);
75
990734f548ef fixed some compiler warnings
Mike Becker <universe@uap-core.de>
parents: 55
diff changeset
19 int r = fread(buffer, 1, 100, stream);
80
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 75
diff changeset
20
81
86a23238d8a1 changed logger to behave more like printf + added possibility to specify write function
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
21 size_t expected_length = 76;
80
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 75
diff changeset
22 UCX_TEST_ASSERT(r == expected_length && strncmp(buffer,
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 75
diff changeset
23 "[INFO] logging_tests.c:15 - allright\n"
81
86a23238d8a1 changed logger to behave more like printf + added possibility to specify write function
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
24 "[ERROR] logging_tests.c:17 - error 42!\n", expected_length) == 0, "incorrect logs");
54
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 UCX_TEST_END
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27
80
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 75
diff changeset
28 ucx_logger_free(logger);
54
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 fclose(stream);
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30 }

mercurial