Commit f3c23332 by Marcus Winter

base_cpp: fixed log test

parent 900bc329
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include <embb/base/c/internal/unused.h> #include <embb/base/c/internal/unused.h>
#include <embb/base/log.h> #include <embb/base/log.h>
#include <cstring> #include <string>
namespace embb { namespace embb {
namespace base { namespace base {
...@@ -38,7 +38,7 @@ LogTest::LogTest() { ...@@ -38,7 +38,7 @@ LogTest::LogTest() {
CreateUnit("Test all").Add(&LogTest::Test, this); CreateUnit("Test all").Add(&LogTest::Test, this);
} }
static char const * logged_message; static std::string logged_message;
static void test_log_function(void * context, char const * msg) { static void test_log_function(void * context, char const * msg) {
EMBB_UNUSED(context); EMBB_UNUSED(context);
...@@ -48,101 +48,90 @@ static void test_log_function(void * context, char const * msg) { ...@@ -48,101 +48,90 @@ static void test_log_function(void * context, char const * msg) {
void LogTest::Test() { void LogTest::Test() {
using embb::base::Log; using embb::base::Log;
char const * test_msg = "hello"; char const * test_msg = "hello";
char const * null = 0;
Log::SetLogFunction(0, test_log_function); Log::SetLogFunction(0, test_log_function);
Log::SetLogLevel(EMBB_LOG_LEVEL_TRACE); Log::SetLogLevel(EMBB_LOG_LEVEL_TRACE);
logged_message = null; logged_message = "none";
Log::Trace("chn", test_msg); Log::Trace("chn", test_msg);
#ifdef EMBB_DEBUG #ifdef EMBB_DEBUG
PT_ASSERT_NE(logged_message, null); PT_EXPECT(logged_message == "[chn] - [TRACE] hello");
PT_EXPECT(0 == strcmp(logged_message, "[chn] - [TRACE] hello"));
#else #else
PT_EXPECT_EQ(null, logged_message); PT_EXPECT(logged_message == "none");
#endif #endif
logged_message = null; logged_message = "none";
Log::Info("chn", test_msg); Log::Info("chn", test_msg);
#ifdef EMBB_DEBUG #ifdef EMBB_DEBUG
PT_ASSERT_NE(logged_message, null); PT_EXPECT(logged_message == "[chn] - [INFO ] hello");
PT_EXPECT(0 == strcmp(logged_message, "[chn] - [INFO ] hello"));
#else #else
PT_EXPECT_EQ(null, logged_message); PT_EXPECT(logged_message == "none");
#endif #endif
logged_message = null; logged_message = "none";
Log::Warning("chn", test_msg); Log::Warning("chn", test_msg);
PT_ASSERT_NE(logged_message, null); PT_EXPECT(logged_message == "[chn] - [WARN ] hello");
PT_EXPECT(0 == strcmp(logged_message, "[chn] - [WARN ] hello")); logged_message = "none";
logged_message = null;
Log::Error("chn", test_msg); Log::Error("chn", test_msg);
PT_ASSERT_NE(logged_message, null); PT_EXPECT(logged_message == "[chn] - [ERROR] hello");
PT_EXPECT(0 == strcmp(logged_message, "[chn] - [ERROR] hello"));
Log::SetLogLevel(EMBB_LOG_LEVEL_INFO); Log::SetLogLevel(EMBB_LOG_LEVEL_INFO);
logged_message = null; logged_message = "none";
Log::Trace("chn", test_msg); Log::Trace("chn", test_msg);
PT_EXPECT_EQ(null, logged_message); PT_EXPECT(logged_message == "none");
logged_message = null; logged_message = "none";
Log::Info("chn", test_msg); Log::Info("chn", test_msg);
#ifdef EMBB_DEBUG #ifdef EMBB_DEBUG
PT_ASSERT_NE(logged_message, null); PT_EXPECT(logged_message == "[chn] - [INFO ] hello");
PT_EXPECT(0 == strcmp(logged_message, "[chn] - [INFO ] hello"));
#else #else
PT_EXPECT_EQ(null, logged_message); PT_EXPECT(logged_message == "none");
#endif #endif
logged_message = null; logged_message = "none";
Log::Warning("chn", test_msg); Log::Warning("chn", test_msg);
PT_ASSERT_NE(logged_message, null); PT_EXPECT(logged_message == "[chn] - [WARN ] hello");
PT_EXPECT(0 == strcmp(logged_message, "[chn] - [WARN ] hello")); logged_message = "none";
logged_message = null;
Log::Error("chn", test_msg); Log::Error("chn", test_msg);
PT_ASSERT_NE(logged_message, null); PT_EXPECT(logged_message == "[chn] - [ERROR] hello");
PT_EXPECT(0 == strcmp(logged_message, "[chn] - [ERROR] hello"));
Log::SetLogLevel(EMBB_LOG_LEVEL_WARNING); Log::SetLogLevel(EMBB_LOG_LEVEL_WARNING);
logged_message = null; logged_message = "none";
Log::Trace("chn", test_msg); Log::Trace("chn", test_msg);
PT_EXPECT_EQ(null, logged_message); PT_EXPECT(logged_message == "none");
logged_message = null; logged_message = "none";
Log::Info("chn", test_msg); Log::Info("chn", test_msg);
PT_EXPECT_EQ(null, logged_message); PT_EXPECT(logged_message == "none");
logged_message = null; logged_message = "none";
Log::Warning("chn", test_msg); Log::Warning("chn", test_msg);
PT_ASSERT_NE(logged_message, null); PT_EXPECT(logged_message == "[chn] - [WARN ] hello");
PT_EXPECT(0 == strcmp(logged_message, "[chn] - [WARN ] hello")); logged_message = "none";
logged_message = null;
Log::Error("chn", test_msg); Log::Error("chn", test_msg);
PT_ASSERT_NE(logged_message, null); PT_EXPECT(logged_message == "[chn] - [ERROR] hello");
PT_EXPECT(0 == strcmp(logged_message, "[chn] - [ERROR] hello"));
Log::SetLogLevel(EMBB_LOG_LEVEL_ERROR); Log::SetLogLevel(EMBB_LOG_LEVEL_ERROR);
logged_message = null; logged_message = "none";
Log::Trace("chn", test_msg); Log::Trace("chn", test_msg);
PT_EXPECT_EQ(null, logged_message); PT_EXPECT(logged_message == "none");
logged_message = null; logged_message = "none";
Log::Info("chn", test_msg); Log::Info("chn", test_msg);
PT_EXPECT_EQ(null, logged_message); PT_EXPECT(logged_message == "none");
logged_message = null; logged_message = "none";
Log::Warning("chn", test_msg); Log::Warning("chn", test_msg);
PT_EXPECT_EQ(null, logged_message); PT_EXPECT(logged_message == "none");
logged_message = null; logged_message = "none";
Log::Error("chn", test_msg); Log::Error("chn", test_msg);
PT_ASSERT_NE(logged_message, null); PT_EXPECT(logged_message == "[chn] - [ERROR] hello");
PT_EXPECT(0 == strcmp(logged_message, "[chn] - [ERROR] hello"));
Log::SetLogLevel(EMBB_LOG_LEVEL_NONE); Log::SetLogLevel(EMBB_LOG_LEVEL_NONE);
logged_message = null; logged_message = "none";
Log::Trace("chn", test_msg); Log::Trace("chn", test_msg);
PT_EXPECT_EQ(null, logged_message); PT_EXPECT(logged_message == "none");
logged_message = null; logged_message = "none";
Log::Info("chn", test_msg); Log::Info("chn", test_msg);
PT_EXPECT_EQ(null, logged_message); PT_EXPECT(logged_message == "none");
logged_message = null; logged_message = "none";
Log::Warning("chn", test_msg); Log::Warning("chn", test_msg);
PT_EXPECT_EQ(null, logged_message); PT_EXPECT(logged_message == "none");
logged_message = null; logged_message = "none";
Log::Error("chn", test_msg); Log::Error("chn", test_msg);
PT_EXPECT_EQ(null, logged_message); PT_EXPECT(logged_message == "none");
} }
} // namespace test } // namespace test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment