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