diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d69adc0..351c0e8 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -16,6 +16,7 @@ set(SOURCES Conditional.cpp TestAppender.h Main.cpp + NullCharPointer.cpp Path.cpp Printf.cpp SimpleTypes.cpp diff --git a/test/NullCharPointer.cpp b/test/NullCharPointer.cpp new file mode 100644 index 0000000..23b5e14 --- /dev/null +++ b/test/NullCharPointer.cpp @@ -0,0 +1,86 @@ +#include "Common.h" +#include +#include + +SCENARIO("handling null char pointers") +{ + GIVEN("logger is initialised") + { + plog::TestAppender testAppender; + plog::Logger logger(plog::verbose); + logger.addAppender(&testAppender); + + WHEN("type is char* and its value is NULL") + { + char* var = NULL; + PLOGI << var; + + THEN("the result is as expected") + { + CHECK_EQ(testAppender.getMessage(), PLOG_NSTR("(null)")); + } + } + + WHEN("type is std::vector and value of elements is NULL") + { + std::vector var; + var.push_back(NULL); + var.push_back(NULL); + PLOGI << var; + + THEN("the result is as expected") + { + CHECK_EQ(testAppender.getMessage(), PLOG_NSTR("[(null), (null)]")); + } + } + + WHEN("type is std::pair and value of elements is NULL") + { + std::pair var; + PLOGI << var; + + THEN("the result is as expected") + { + CHECK_EQ(testAppender.getMessage(), PLOG_NSTR("(null):(null)")); + } + } + +#if PLOG_ENABLE_WCHAR_INPUT + WHEN("type is wchar_t* and its value is NULL") + { + wchar_t* var = NULL; + PLOGI << var; + + THEN("the result is as expected") + { + CHECK_EQ(testAppender.getMessage(), PLOG_NSTR("(null)")); + } + } + + WHEN("type is std::vector and value of elements is NULL") + { + std::vector var; + var.push_back(NULL); + var.push_back(NULL); + + PLOGI << var; + + THEN("the result is as expected") + { + CHECK_EQ(testAppender.getMessage(), PLOG_NSTR("[(null), (null)]")); + } + } + + WHEN("type is std::pair and value of elements is NULL") + { + std::pair var; + PLOGI << var; + + THEN("the result is as expected") + { + CHECK_EQ(testAppender.getMessage(), PLOG_NSTR("(null):(null)")); + } + } +#endif + } +}