test/logging_tests.c

Mon, 08 Oct 2012 14:04:52 +0200

author
Mike Becker <universe@uap-core.de>
date
Mon, 08 Oct 2012 14:04:52 +0200
changeset 54
f634f790661a
child 55
180bc6b18fec
permissions
-rw-r--r--

added logging API

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 #ifndef _WIN32
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 #include <unistd.h>
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 #endif /* not _WIN32 */
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 UCX_TEST_IMPLEMENT(test_ucx_logger_log) {
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 char buffer[100];
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 #if defined _USE_GNU || defined _USE_XOPEN2K8
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 FILE *stream = fmemopen(buffer, 100, "w");
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 #else
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 FILE *stream = fopen("test_ucx_logger", "w+");
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 #endif /* _WIN32 */
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 UcxLogger *logger = ucx_logger_new(stream, UCX_LOGGER_INFO);
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 UCX_TEST_BEGIN
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 ucx_logger_info(logger, ST("[INFO:] allright\n"));
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 ucx_logger_trace(logger, ST("[TRACE:] dont log this!\n"));
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 ucx_logger_error(logger, ST("[ERROR:] error!\n"));
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 #if !(defined _USE_GNU || defined _USE_XOPEN2K8)
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 fseek(stream, 0, SEEK_SET);
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 fread(buffer, 1, 100, stream);
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 #endif /* _WIN32 */
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28 UCX_TEST_ASSERT(strncmp(buffer,
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 "[INFO:] allright\n[ERROR:] error!\n", 33) == 0, "incorrect logs");
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31 UCX_TEST_END
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
32
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
33 free(logger);
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34 fclose(stream);
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
35 #if !(defined _USE_GNU || defined _USE_XOPEN2K8)
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36 unlink("test_ucx_logger");
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 #endif
f634f790661a added logging API
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38 }

mercurial