From 67ad1ed2326b7e25c29e111769e4876ad5172ec6 Mon Sep 17 00:00:00 2001 From: Sergey Podobry Date: Tue, 17 Oct 2023 15:23:52 +0300 Subject: [PATCH] Add NullCharPointer test --- test/CMakeLists.txt | 1 + test/NullCharPointer.cpp | 86 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 test/NullCharPointer.cpp 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..9d3a28e --- /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(NULL, NULL); + 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(NULL, NULL); + PLOGI << var; + + THEN("the result is as expected") + { + CHECK_EQ(testAppender.getMessage(), PLOG_NSTR("(null):(null)")); + } + } +#endif + } +}