Mon, 08 Oct 2012 14:04:52 +0200
added logging API
54 | 1 | /* |
2 | * | |
3 | */ | |
4 | ||
5 | #include "logging_tests.h" | |
6 | #ifndef _WIN32 | |
7 | #include <unistd.h> | |
8 | #endif /* not _WIN32 */ | |
9 | ||
10 | UCX_TEST_IMPLEMENT(test_ucx_logger_log) { | |
11 | char buffer[100]; | |
12 | #if defined _USE_GNU || defined _USE_XOPEN2K8 | |
13 | FILE *stream = fmemopen(buffer, 100, "w"); | |
14 | #else | |
15 | FILE *stream = fopen("test_ucx_logger", "w+"); | |
16 | #endif /* _WIN32 */ | |
17 | UcxLogger *logger = ucx_logger_new(stream, UCX_LOGGER_INFO); | |
18 | ||
19 | UCX_TEST_BEGIN | |
20 | ucx_logger_info(logger, ST("[INFO:] allright\n")); | |
21 | ucx_logger_trace(logger, ST("[TRACE:] dont log this!\n")); | |
22 | ucx_logger_error(logger, ST("[ERROR:] error!\n")); | |
23 | #if !(defined _USE_GNU || defined _USE_XOPEN2K8) | |
24 | fseek(stream, 0, SEEK_SET); | |
25 | fread(buffer, 1, 100, stream); | |
26 | #endif /* _WIN32 */ | |
27 | ||
28 | UCX_TEST_ASSERT(strncmp(buffer, | |
29 | "[INFO:] allright\n[ERROR:] error!\n", 33) == 0, "incorrect logs"); | |
30 | ||
31 | UCX_TEST_END | |
32 | ||
33 | free(logger); | |
34 | fclose(stream); | |
35 | #if !(defined _USE_GNU || defined _USE_XOPEN2K8) | |
36 | unlink("test_ucx_logger"); | |
37 | #endif | |
38 | } |