Restructured tests and matured Logger a lil bit, now LoggerBase
This commit is contained in:
@@ -1,5 +1,16 @@
|
||||
cmake_minimum_required(VERSION 3.26.0)
|
||||
project(gtest_Graphics VERSION 0.1.0 LANGUAGES C CXX)
|
||||
|
||||
add_subdirectory(./ErrorTest)
|
||||
add_subdirectory(./ProcessTest)
|
||||
include(GoogleTest)
|
||||
|
||||
if (NB_BUILD_TESTS)
|
||||
add_executable(TestCore
|
||||
testErrors.cpp
|
||||
testProcesses.cpp
|
||||
)
|
||||
target_link_libraries(TestCore
|
||||
NBCore
|
||||
GTest::gtest_main
|
||||
)
|
||||
gtest_discover_tests(TestCore)
|
||||
endif()
|
||||
@@ -1,5 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.26.0)
|
||||
project(gtest_Graphics VERSION 0.1.0 LANGUAGES C CXX)
|
||||
|
||||
add_executable(ErrorTest main.cpp)
|
||||
target_link_libraries(ErrorTest NBCore)
|
||||
@@ -1,54 +0,0 @@
|
||||
#define CODE_ERROR_LOCATIONS
|
||||
|
||||
#include "Errors.hpp"
|
||||
#include <iostream>
|
||||
#include "Logger.hpp"
|
||||
|
||||
using namespace nb;
|
||||
|
||||
class TestError : public ErrorBase<TestError> {
|
||||
public:
|
||||
using ErrorBase<TestError>::ErrorBase;
|
||||
|
||||
enum ErrorCodes : unsigned int {
|
||||
A, B, C, D
|
||||
};
|
||||
static const std::string type;
|
||||
static const ErrorCodeMap ErrorMessages;
|
||||
};
|
||||
|
||||
const std::string TestError::type="TestError";
|
||||
const ErrorCodeMap TestError::ErrorMessages{
|
||||
{TestError::ErrorCodes::A, "Hey!"},
|
||||
{TestError::ErrorCodes::B, "How"},
|
||||
{TestError::ErrorCodes::C, "You"},
|
||||
{TestError::ErrorCodes::D, "Doin"}
|
||||
};
|
||||
|
||||
int main() {
|
||||
try {
|
||||
try {
|
||||
try {
|
||||
try {
|
||||
THROW(TestError, TestError::ErrorCodes::D);
|
||||
} catch (const std::exception& e){
|
||||
THROW(TestError, TestError::ErrorCodes::C, e);
|
||||
}
|
||||
} catch(const std::exception& e) {
|
||||
THROW(TestError, TestError::ErrorCodes::B, e);
|
||||
}
|
||||
} catch(const std::exception& e) {
|
||||
THROW(TestError, TestError::ErrorCodes::A, e);
|
||||
}
|
||||
} catch(const std::exception& e) {
|
||||
// THROW(Error, Error::ErrorCodes::UNDEFINED, e);
|
||||
BasicLogger log(std::cout);
|
||||
std::cout << "Logger is starting: " << log.run() << std::endl;
|
||||
std::cout << "Logger is running: " << log.isRunning() << std::endl;
|
||||
log.error(e);
|
||||
log.stop();
|
||||
std::cout << "Logger is running: " << log.isRunning() << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.26.0)
|
||||
project(gtest_Graphics VERSION 0.1.0 LANGUAGES C CXX)
|
||||
|
||||
add_executable(ProcessTest main.cpp)
|
||||
target_link_libraries(ProcessTest NBCore)
|
||||
@@ -0,0 +1,45 @@
|
||||
#define CODE_ERROR_LOCATIONS
|
||||
|
||||
#include "Errors.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
#include "Logger.hpp"
|
||||
|
||||
using namespace nb;
|
||||
|
||||
class TestError : public ErrorBase<TestError> {
|
||||
public:
|
||||
using ErrorBase<TestError>::ErrorBase;
|
||||
|
||||
enum ErrorCodes : unsigned int {
|
||||
A, B, C, D
|
||||
};
|
||||
static const std::string type;
|
||||
static const ErrorCodeMap ErrorMessages;
|
||||
};
|
||||
|
||||
const std::string TestError::type="TestError";
|
||||
const ErrorCodeMap TestError::ErrorMessages{
|
||||
{TestError::ErrorCodes::A, "Hey!"},
|
||||
{TestError::ErrorCodes::B, "How"},
|
||||
{TestError::ErrorCodes::C, "You"},
|
||||
{TestError::ErrorCodes::D, "Doin"}
|
||||
};
|
||||
|
||||
class TestLogger : public nb::LoggerBase<TestLogger> {
|
||||
public:
|
||||
using Base = LoggerBase<TestLogger>;
|
||||
using Base::Base;
|
||||
|
||||
virtual void process(const LogEvent& event) {
|
||||
*_ostreams[0] << event.pid << " : " << event.msg << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
TEST(ErrorTest, Test) {
|
||||
EXPECT_EQ(1, 1);
|
||||
|
||||
TestLogger log(std::cout);
|
||||
ASSERT_TRUE(log.run());
|
||||
log.msg("Hey!");
|
||||
}
|
||||
@@ -1,17 +1,22 @@
|
||||
#define CODE_ERROR_LOCATIONS
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <iostream>
|
||||
#include "Processes.hpp"
|
||||
#include <Windows.h>
|
||||
|
||||
int main() {
|
||||
TEST(ProcessesTest, GetPID) {
|
||||
ASSERT_EQ(nb::GetPID(), GetCurrentProcessId());
|
||||
}
|
||||
|
||||
std::cout << "nb::get_pid() -> " << nb::get_pid() << std::endl;
|
||||
/* int main() {
|
||||
|
||||
std::cout << "nb::GetPID() -> " << nb::GetPID() << std::endl;
|
||||
|
||||
#ifdef _TARGET_WINDOWS
|
||||
std::cout << "GetCurrentProcessId() -> " << GetCurrentProcessId() << std::endl;
|
||||
#endif // _TARGET_WINDOWS
|
||||
|
||||
return 0;
|
||||
}
|
||||
} */
|
||||
Reference in New Issue
Block a user