Skip to content

Commit

Permalink
Add NullCharPointer test
Browse files Browse the repository at this point in the history
  • Loading branch information
SergiusTheBest committed Oct 17, 2023
1 parent a2b6113 commit be7c5a2
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set(SOURCES
Conditional.cpp
TestAppender.h
Main.cpp
NullCharPointer.cpp
Path.cpp
Printf.cpp
SimpleTypes.cpp
Expand Down
86 changes: 86 additions & 0 deletions test/NullCharPointer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include "Common.h"
#include <vector>
#include <utility>

SCENARIO("handling null char pointers")
{
GIVEN("logger is initialised")
{
plog::TestAppender testAppender;
plog::Logger<PLOG_DEFAULT_INSTANCE_ID> 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<char*> and value of elements is NULL")
{
std::vector<char*> 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<char*, char*> and value of elements is NULL")
{
std::pair<char*, char*> 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<wchar_t*> and value of elements is NULL")
{
std::vector<wchar_t*> 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<wchar_t*, wchar_t*> and value of elements is NULL")
{
std::pair<wchar_t*, wchar_t*> var;
PLOGI << var;

THEN("the result is as expected")
{
CHECK_EQ(testAppender.getMessage(), PLOG_NSTR("(null):(null)"));
}
}
#endif
}
}

0 comments on commit be7c5a2

Please sign in to comment.