Skip to content

Commit

Permalink
Add test cases for the logger.
Browse files Browse the repository at this point in the history
  • Loading branch information
xkbeyer committed Jun 15, 2017
1 parent 6ccaeed commit 3fbf1bb
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 3 deletions.
6 changes: 3 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ endif()

# Define all sourcefiles. #
###########################
set(TEST_SRC packet_test.cpp TextFormatting_test.cpp)
set(HDR catch.hpp ../include/packet.h ../include/TextFormatting.h)
set(SRC ../src/packet.cpp )
set(TEST_SRC packet_test.cpp TextFormatting_test.cpp Logger_test.cpp)
set(HDR catch.hpp ../include/packet.h ../include/TextFormatting.h ../include/Logger.h)
set(SRC ../src/packet.cpp ../src/Logger.cpp)

if(MSVC)
source_group( Header FILES ${HDR})
Expand Down
87 changes: 87 additions & 0 deletions test/Logger_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include "catch.hpp"
#include "../include/Logger.h"
#include <sstream>

using namespace FTS;

TEST_CASE("Message Simple String", "[FTSMSG]")
{
std::stringstream logout;
Logger::LogFile(&logout);
Logger::DbgLevel(5);
FTSMSG("Testlog", MsgType::Message);
REQUIRE(logout.str() == "Testlog\n");
}

TEST_CASE("Message one integer parameter", "[FTSMSG]")
{
std::stringstream logout;
Logger::LogFile(&logout);
Logger::DbgLevel(5);
FTSMSG("Testlog {1}", MsgType::Message, toString(123));
REQUIRE(logout.str() == "Testlog 123\n");
}

TEST_CASE("Message three parameter", "[FTSMSG]")
{
std::stringstream logout;
Logger::LogFile(&logout);
Logger::DbgLevel(5);
FTSMSG("Testlog {1} {3} {2}", MsgType::Message, toString(123), toString(123,0,' ',std::ios::hex), "=");
REQUIRE(logout.str() == "Testlog 123 = 7b\n");
}

TEST_CASE("Warning three parameter", "[FTSMSG]")
{
std::stringstream logout;
Logger::LogFile(&logout);
Logger::DbgLevel(5);
FTSMSG("Testlog {1} {3} {2}", MsgType::Warning, toString(123), toString(123, 0, ' ', std::ios::hex), "=");
REQUIRE(logout.str() == "Testlog 123 = 7b\n");
}

TEST_CASE("Error message", "[FTSMSG]")
{
std::stringstream logout;
Logger::LogFile(&logout);
Logger::DbgLevel(5);
FTSMSG("Testlog {1}", MsgType::Error, toString(1));
REQUIRE(logout.str() == "Testlog 1\n");
}


TEST_CASE("Messing missing first parameter placeholder", "[FTSMSG]")
{
std::stringstream logout;
Logger::LogFile(&logout);
Logger::DbgLevel(5);
FTSMSG("Testlog {3} {2}", MsgType::Warning, toString(123), toString(123, 0, ' ', std::ios::hex), "=");
REQUIRE(logout.str() == "Testlog = 7b\n");
}

TEST_CASE("Debug message same level", "[FTSMSGDBG]")
{
std::stringstream logout;
Logger::LogFile(&logout);
Logger::DbgLevel(1);
FTSMSGDBG("Testlog {1} {3} {2}", 1, toString(123), toString(123, 0, ' ', std::ios::hex), "=");
REQUIRE(logout.str() == "Testlog 123 = 7b\n");
}

TEST_CASE("Debug message higher level", "[FTSMSGDBG]")
{
std::stringstream logout;
Logger::LogFile(&logout);
Logger::DbgLevel(1);
FTSMSGDBG("Testlog {1} {3} {2}", 2, toString(123), toString(123, 0, ' ', std::ios::hex), "=");
REQUIRE(logout.str().empty());
}

TEST_CASE("Debug message lower level", "[FTSMSGDBG]")
{
std::stringstream logout;
Logger::LogFile(&logout);
Logger::DbgLevel(2);
FTSMSGDBG("Testlog {1} {3} {2}", 1, toString(123), toString(123, 0, ' ', std::ios::hex), "=");
REQUIRE(logout.str() == "Testlog 123 = 7b\n");
}

0 comments on commit 3fbf1bb

Please sign in to comment.