48 |
48 |
49 UCX_TEST_ASSERT(logger->levels->count == 4, |
49 UCX_TEST_ASSERT(logger->levels->count == 4, |
50 "incorrect number of registered log levels"); |
50 "incorrect number of registered log levels"); |
51 |
51 |
52 int level = UCX_LOGGER_ERROR; |
52 int level = UCX_LOGGER_ERROR; |
53 UCX_TEST_ASSERT(strcmp(ucx_map_int_get(logger->levels, level), |
53 UCX_TEST_ASSERT(strcmp((char*)ucx_map_int_get(logger->levels, level), |
54 "[ERROR]") == 0, "invalid error level"); |
54 "[ERROR]") == 0, "invalid error level"); |
55 level = UCX_LOGGER_WARN; |
55 level = UCX_LOGGER_WARN; |
56 UCX_TEST_ASSERT(strcmp(ucx_map_int_get(logger->levels, level), |
56 UCX_TEST_ASSERT(strcmp((char*)ucx_map_int_get(logger->levels, level), |
57 "[WARNING]") == 0, "invalid warning level"); |
57 "[WARNING]") == 0, "invalid warning level"); |
58 level = UCX_LOGGER_INFO; |
58 level = UCX_LOGGER_INFO; |
59 UCX_TEST_ASSERT(strcmp(ucx_map_int_get(logger->levels, level), |
59 UCX_TEST_ASSERT(strcmp((char*)ucx_map_int_get(logger->levels, level), |
60 "[INFO]") == 0, "invalid info level"); |
60 "[INFO]") == 0, "invalid info level"); |
61 level = UCX_LOGGER_TRACE; |
61 level = UCX_LOGGER_TRACE; |
62 UCX_TEST_ASSERT(strcmp(ucx_map_int_get(logger->levels, level), |
62 UCX_TEST_ASSERT(strcmp((char*)ucx_map_int_get(logger->levels, level), |
63 "[TRACE]") == 0, "invalid trace level"); |
63 "[TRACE]") == 0, "invalid trace level"); |
64 |
64 |
65 UCX_TEST_END |
65 UCX_TEST_END |
66 |
66 |
67 fclose(stream); |
67 fclose(stream); |
73 |
73 |
74 FILE *stream = tmpfile(); |
74 FILE *stream = tmpfile(); |
75 |
75 |
76 UcxLogger *logger = ucx_logger_new(stream, |
76 UcxLogger *logger = ucx_logger_new(stream, |
77 UCX_LOGGER_INFO, UCX_LOGGER_SOURCE | UCX_LOGGER_LEVEL); |
77 UCX_LOGGER_INFO, UCX_LOGGER_SOURCE | UCX_LOGGER_LEVEL); |
78 logger->dateformat = "%F:"; |
78 logger->dateformat = (char*) "%F:"; |
79 |
79 |
80 UCX_TEST_BEGIN |
80 UCX_TEST_BEGIN |
81 const uint line1 = __LINE__; ucx_logger_info(logger, "allright"); |
81 const uint line1 = __LINE__; ucx_logger_info(logger, "allright"); |
82 |
82 |
83 ucx_logger_trace(logger, "dont log this!"); |
83 ucx_logger_trace(logger, "dont log this!"); |
90 |
90 |
91 fseek(stream, 0, SEEK_SET); |
91 fseek(stream, 0, SEEK_SET); |
92 size_t r = fread(buffer, 1, 100, stream); |
92 size_t r = fread(buffer, 1, 100, stream); |
93 |
93 |
94 const size_t expected_length = 87; |
94 const size_t expected_length = 87; |
95 char expected[expected_length+1]; |
95 char expected[88]; |
96 snprintf(expected, expected_length+1, |
96 snprintf(expected, expected_length+1, |
97 "[INFO] logging_tests.c:%u - allright\n" |
97 "[INFO] logging_tests.c:%u - allright\n" |
98 "[ERROR] %slogging_tests.c:%u - error 42!\n", line1, timestr, line2); |
98 "[ERROR] %slogging_tests.c:%u - error 42!\n", line1, timestr, line2); |
99 |
99 |
100 UCX_TEST_ASSERT(r == expected_length, "incorrect log length"); |
100 UCX_TEST_ASSERT(r == expected_length, "incorrect log length"); |