awtk/tests/log_test.cc
2023-11-28 17:47:26 +08:00

30 lines
647 B
C++

#include "tkc/str.h"
#include "tkc/log.h"
#include "gtest/gtest.h"
static ret_t debugger_log(void* ctx, log_level_t level, const char* msg) {
str_t* str = (str_t*)ctx;
str_append_more(str, msg, ";", NULL);
return RET_OK;
}
TEST(Log, basic) {
str_t str;
str_init(&str, 100);
log_set_hook(debugger_log, &str);
log_set_hook(debugger_log, &str);
log_debug("%d:%s\n", 1, "debug");
log_info("%d:%s\n", 2, "info");
log_warn("%d:%s\n", 3, "warn");
log_error("%d:%s\n", 4, "error");
ASSERT_STREQ(str.str, "1:debug\n;2:info\n;3:warn\n;4:error\n;");
log_set_hook(NULL, NULL);
log_set_hook(NULL, NULL);
str_reset(&str);
}