Use UnitTest-Cpp library for testing

This commit is contained in:
Ilusha 2024-03-15 16:03:33 +03:00
parent ecaa2bbdfb
commit 00d8fa0886
53 changed files with 1046 additions and 1383 deletions

View file

@ -9,5 +9,5 @@ target_include_directories(${PROJECT_NAME} PUBLIC ./public/)
enable_testing()
file(GLOB SOURCES_TEST "./tests/*.cpp")
add_executable(${PROJECT_NAME}Tests ${SOURCES_TEST})
target_link_libraries(${PROJECT_NAME}Tests ${PROJECT_NAME})
target_link_libraries(${PROJECT_NAME}Tests ${PROJECT_NAME} UnitTest++)
add_test(NAME ${PROJECT_NAME}Tests COMMAND ${PROJECT_NAME}Tests)

View file

@ -1,12 +1,14 @@
#include "Module.hpp"
#include "UnitTest++/UnitTest++.h"
#include "Archiver.hpp"
#include <cstdio>
#include <cstdlib>
using namespace tp;
bool sFailed = false;
struct Undef {
char character1 = 'a';
bool boolean = true;
@ -202,10 +204,7 @@ void test() {
read % res;
if (val != res) {
printf("Test %s Failed\n", typeid(tType).name());
sFailed = true;
}
CHECK(!(val != res));
}
template <typename T, typename A, typename = void>
@ -214,17 +213,32 @@ struct HasArchive : FalseType {};
template <typename T, typename A>
struct HasArchive<T, A, VoidType<decltype(DeclareValue<T>()().archive(DeclareValue<A&>()()))>> : TrueType {};
void testArchiver() {
printf("has archive method - %i\n", HasArchive<SimpleArchive, ArchiverExample<10, false>>::value);
printf("has archive method - %i\n", ArchiverExample<10, false>::HasFunc::Archive<SimpleArchive>::value);
printf("has archive method - %i\n", ArchiverExample<10, false>::HasFunc::Archive<Simple>::value);
test<SimpleArchive>();
test<Simple>();
test<Set<Simple>>();
test<ComplexCart<Simple>>();
SUITE(BaseModule) {
TEST(Basic) {
tp::ModuleManifest* ModuleDependencies[] = { &tp::gModuleBase, nullptr };
tp::ModuleManifest TestModule("Test", nullptr, nullptr, ModuleDependencies);
if (sFailed) {
exit(1);
REQUIRE CHECK(TestModule.initialize());
REQUIRE CHECK(tp::gEnvironment.mWidth == tp::Environment::ArchWidth::X64);
CHECK(tp::max(2, 1) == 2);
CHECK(tp::max(-1, 0) == 0);
CHECK(tp::max(0, -1) == 0);
CHECK(tp::min(0, -1) == -1);
printf("has archive method - %i\n", HasArchive<SimpleArchive, ArchiverExample<10, false>>::value);
printf("has archive method - %i\n", ArchiverExample<10, false>::HasFunc::Archive<SimpleArchive>::value);
printf("has archive method - %i\n", ArchiverExample<10, false>::HasFunc::Archive<Simple>::value);
test<SimpleArchive>();
test<Simple>();
test<Set<Simple>>();
test<ComplexCart<Simple>>();
TestModule.deinitialize();
}
}
int main() { return UnitTest::RunAllTests(); }

View file

@ -1,24 +0,0 @@
#include "Module.hpp"
void testArchiver();
int main() {
tp::ModuleManifest* ModuleDependencies[] = { &tp::gModuleBase, nullptr };
tp::ModuleManifest TestModule("Test", nullptr, nullptr, ModuleDependencies);
if (!TestModule.initialize()) {
return 1;
}
ASSERT(tp::gEnvironment.mWidth == tp::Environment::ArchWidth::X64);
ASSERT(tp::max(2, 1) == 2)
ASSERT(tp::max(-1, 0) == 0)
ASSERT(tp::max(0, -1) == 0)
ASSERT(tp::min(0, -1) == -1)
testArchiver();
TestModule.deinitialize();
}