Complete migration of framework and unit tests to CMake.
Test results are more consistent and accurate now. Work #144
This commit is contained in:
parent
08bb8f364a
commit
c05bffe83e
@ -9,7 +9,6 @@ AccessModifierOffset: -4
|
||||
BinPackParameters: true
|
||||
AlwaysBreakAfterDefinitionReturnType: TopLevel
|
||||
AlwaysBreakAfterReturnType: None
|
||||
ConstructorInitializerIndentWidth: 2
|
||||
ContinuationIndentWidth: 4
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
|
@ -60,27 +60,34 @@ include(FetchContent)
|
||||
include(CheckIncludeFile)
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(CATCH2 "catch2-with-main >= 2.13.7")
|
||||
#pkg_check_modules(CATCH2 "catch2-with-main >= 2.13.7")
|
||||
pkg_check_modules(SDL2 "sdl >= 2")
|
||||
pkg_check_modules(SDL2_IMG "SDL2_image >= 0.29.0")
|
||||
pkg_check_modules(SDL2_GFX "SDL2_gfx >= 1.0.2")
|
||||
pkg_check_modules(NLOHMANN_JSON "nlohmann_json >= 3.11.10")
|
||||
|
||||
find_package(Catch2 3 REQUIRED)
|
||||
|
||||
if (CATCH2_FOUND)
|
||||
set(USE_SYSTEM_CATCH2 ON)
|
||||
endif()
|
||||
|
||||
if (SDL2_FOUND)
|
||||
include_directories(${SDL2_INCLUDE_DIRS})
|
||||
link_directories(AFTER ${SDL2_IMG_LIBRARY_DIRS})
|
||||
endif()
|
||||
if (SDL2_IMG_FOUND)
|
||||
include_directories(${SDL2_IMG_INCLUDE_DIRS})
|
||||
link_directories(AFTER ${SDL2_LIBRARY_DIRS})
|
||||
endif()
|
||||
if (SDL2_GFX_FOUND)
|
||||
include_directories(${SDL2_GFX_INCLUDE_DIRS})
|
||||
link_directories(AFTER ${SDL2_GFX_LIBRARY_DIRS})
|
||||
endif()
|
||||
if (NLOHMANN_JSON_FOUND)
|
||||
include_directories(${NLOHMANN_JSON_INCLUDE_DIRS})
|
||||
|
||||
#add_link_options(${NKLOHMANN_JSON_LDFLAGS})
|
||||
endif()
|
||||
|
||||
# @{ Download and build unit test engine only if needed
|
||||
@ -123,11 +130,11 @@ if(USE_BOOST_STACKTRACE)
|
||||
set(Boost_USE_STATIC_RUNTIME OFF) # Do not require static C++ runtime
|
||||
set(Boost_USE_MULTITHREADED ON)
|
||||
find_package(Boost 1.82.0 COMPONENTS system filesystem REQUIRED)
|
||||
endif()
|
||||
|
||||
if (Boost_FOUND)
|
||||
add_definitions(-DBOOST_STACKTRACE_USE_ADDR2LINE=1)
|
||||
include_directories(${Boost_INCLUDE_DIRS})
|
||||
if (Boost_FOUND)
|
||||
add_definitions(-DBOOST_STACKTRACE_USE_ADDR2LINE=1)
|
||||
include_directories(${Boost_INCLUDE_DIRS})
|
||||
endif()
|
||||
endif()
|
||||
#@}
|
||||
#@{ QT5 Dependency detection & tool setup
|
||||
@ -161,6 +168,7 @@ if (USE_EXECINFO_STACKTRACE)
|
||||
endif()
|
||||
|
||||
include_directories(
|
||||
${CMAKE_SOURCE_DIR}
|
||||
${CMAKE_SOURCE_DIR}/src
|
||||
#${CMAKE_SOURCE_DIR}/include
|
||||
#${CMAKE_SOURCE_DIR}/include/private
|
||||
@ -189,6 +197,4 @@ endif()
|
||||
add_subdirectory(src)
|
||||
#add_subdirectory(apps)
|
||||
|
||||
|
||||
|
||||
# vim:set noet sts=0 sw=8 ts=8 foldmethod=marker foldmarker=@{,@}:
|
||||
|
@ -7,7 +7,13 @@ set(FRAMEWORK_SOURCES
|
||||
core/components/PositionAttribute.cpp
|
||||
core/input/EventDispatcher.cpp)
|
||||
|
||||
set(FRAMEWORK_LINK_LIBS ${STACKTRACE_DEP_LIBS} )
|
||||
set(FRAMEWORK_LINK_LIBS
|
||||
${STACKTRACE_DEP_LIBS}
|
||||
${SDL2_LIBRARIES}
|
||||
${SDL2_IMG_LIBRARIES}
|
||||
${SDL2_GFX_LIBRARIES}
|
||||
)
|
||||
list(REMOVE_DUPLICATES FRAMEWORK_LINK_LIBS)
|
||||
|
||||
add_library(framework-core SHARED ${FRAMEWORK_SOURCES})
|
||||
add_library(framework-core_static STATIC ${FRAMEWORK_SOURCES})
|
||||
@ -17,6 +23,8 @@ target_compile_options(framework-core PRIVATE ${CMAKE_CXX_FLAGS})
|
||||
target_compile_options(framework-core_static PRIVATE ${CMAKE_CXX_FLAGS})
|
||||
target_compile_options(framework-core_test PRIVATE ${CMAKE_CXX_FLAGS})
|
||||
|
||||
target_compile_definitions(framework-core_test PUBLIC -DUNIT_TEST=1)
|
||||
|
||||
# Check if the system is Linux
|
||||
set_target_properties(framework-core_static PROPERTIES
|
||||
CMAKE_POSITION_INDEPENDENT_CODE OFF # This forces all linkages to be static (?)
|
||||
|
@ -1,4 +1,18 @@
|
||||
/Users/sdavid/Developer/Personal/C++/quartz-warriors/.clang-format:15:1: error: duplicated mapping key 'ConstructorInitializerIndentWidth'
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Error reading /Users/sdavid/Developer/Personal/C++/quartz-warriors/.clang-format: Invalid argument
|
||||
/* requirements.h
|
||||
* Copyright © 2019-2022 Saul D. Beniquez
|
||||
* License: Mozilla Public License v. 2.0
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public License,
|
||||
* v.2.0. If a copy of the MPL was not distributed with this file, You can
|
||||
* obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
// #include <config.h>
|
||||
|
||||
#if __cplusplus < 202002L
|
||||
#error This framework requires C++20, at least
|
||||
#endif
|
||||
|
||||
// clang-format off
|
||||
// vim: set foldmethod=marker foldmarker=#region,#endregion textwidth=80 ts=8 sts=0 sw=8 noexpandtab ft=cpp.doxygen :
|
||||
|
@ -1,4 +1,75 @@
|
||||
/Users/sdavid/Developer/Personal/C++/quartz-warriors/.clang-format:15:1: error: duplicated mapping key 'ConstructorInitializerIndentWidth'
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Error reading /Users/sdavid/Developer/Personal/C++/quartz-warriors/.clang-format: Invalid argument
|
||||
/* debuginfo.h
|
||||
* Copyright © 2020-2023 Saul D. Beniquez
|
||||
* License: Mozilla Public License v. 2.0
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
// #include "config.h"
|
||||
#include "framework/core/types.hpp"
|
||||
|
||||
#ifdef HAVE_EXECINFO_H
|
||||
#include <execinfo.h>
|
||||
#else
|
||||
#include <boost/stacktrace.hpp>
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
using namespace QW::Core::Types;
|
||||
|
||||
#ifdef QW_DEBUG // #region
|
||||
#include <iostream>
|
||||
#define debugprint(msg) std::cout << "#*!* " << msg << std::endl
|
||||
#else
|
||||
#define debugprint(msg) ;
|
||||
#endif // #endregion
|
||||
|
||||
inline std::string
|
||||
generate_stacktrace()
|
||||
{
|
||||
std::stringstream buffer;
|
||||
#ifdef HAVE_EXECINFO_H
|
||||
void* callstack[128];
|
||||
|
||||
int i, frames = backtrace(callstack, 128);
|
||||
char** strs = backtrace_symbols(callstack, frames);
|
||||
for (i = 0; i < frames; ++i) {
|
||||
buffer << strs[i] << std::endl;
|
||||
}
|
||||
free(strs);
|
||||
#else
|
||||
buffer << boost::stacktrace::stacktrace() << std::flush;
|
||||
#endif
|
||||
return buffer.str();
|
||||
}
|
||||
inline void
|
||||
print_backtrace()
|
||||
{
|
||||
std::cout << generate_stacktrace() << std::endl;
|
||||
}
|
||||
|
||||
inline void
|
||||
print_backtrace(std::exception& ex)
|
||||
{
|
||||
std::cout << "caught: " << ex.what() << std::endl;
|
||||
print_backtrace();
|
||||
}
|
||||
|
||||
inline void
|
||||
print_cmdline(int argc, const c_string argv[])
|
||||
{
|
||||
int i;
|
||||
|
||||
std::cout << "Command-line received" << std::endl;
|
||||
for (i = 0; i < argc; ++i)
|
||||
std::cout << argv[i] << " ";
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
// vim: set foldmethod=marker foldmarker=#region,#endregion textwidth=80 ts=8 sts=0 sw=8 noexpandtab ft=cpp.doxygen :
|
||||
|
@ -14,16 +14,20 @@ add_executable(framework-tests
|
||||
)
|
||||
|
||||
set_target_properties(framework-tests PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/artifacts/tests"
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/build/tests"
|
||||
)
|
||||
|
||||
target_compile_definitions(framework-tests PUBLIC -DTESTING)
|
||||
target_include_directories(framework-tests PRIVATE ${Catch2_INCLUDE_DIRS})
|
||||
target_compile_definitions(framework-tests PUBLIC -DUNIT_TEST=1)
|
||||
target_include_directories(framework-tests PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/src/tests
|
||||
${CMAKE_SOURCE_DIR}/src/tests/common
|
||||
${Catch2_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
# Link the test executable with libframework_static source code and Catch2
|
||||
target_link_libraries(framework-tests PRIVATE
|
||||
framework-core_test
|
||||
catch2-with-main
|
||||
Catch2::Catch2WithMain
|
||||
FakeIt::FakeIt-catch
|
||||
)
|
||||
|
||||
|
@ -42,46 +42,49 @@ TEST_CASE("EntityManager::GetInstance", TEST_SUITE_NAME)
|
||||
REQUIRE_NOTHROW([]() { EntityManager::GetInstance(); });
|
||||
}
|
||||
|
||||
TEST_CASE("EntityManager::RegisterPool", TEST_SUITE_NAME)
|
||||
TEST_CASE("Pool registration and deregistration", TEST_SUITE_NAME)
|
||||
{
|
||||
ComponentDictionary<SomeComponent> test_table;
|
||||
ComponentDictionary<SomeOtherComponent> test_table2;
|
||||
EntityManager& registry = EntityManager::GetInstance();
|
||||
SECTION("EntityManager::RegisterPool()")
|
||||
{
|
||||
ComponentDictionary<SomeComponent> test_table;
|
||||
ComponentDictionary<SomeOtherComponent> test_table2;
|
||||
EntityManager& registry = EntityManager::GetInstance();
|
||||
|
||||
test_table.emplace(0, 0);
|
||||
test_table.emplace(0, 0);
|
||||
|
||||
using DictionaryPtr = ComponentDictionary<SomeComponent>*;
|
||||
using DictionaryPtr = ComponentDictionary<SomeComponent>*;
|
||||
|
||||
auto& pools = registry.getPools();
|
||||
auto& typeInfo = SomeComponent::GetType();
|
||||
auto& pools = registry.getPools();
|
||||
auto& typeInfo = SomeComponent::GetType();
|
||||
|
||||
void* voidPtr = nullptr;
|
||||
registry.RegisterPool(test_table);
|
||||
registry.RegisterPool(test_table2);
|
||||
void* voidPtr = nullptr;
|
||||
registry.RegisterPool(test_table);
|
||||
registry.RegisterPool(test_table2);
|
||||
|
||||
voidPtr = pools.at(typeInfo);
|
||||
auto poolPtr = reinterpret_cast<DictionaryPtr>(voidPtr);
|
||||
voidPtr = pools.at(typeInfo);
|
||||
auto poolPtr = reinterpret_cast<DictionaryPtr>(voidPtr);
|
||||
|
||||
// Verify that the object returned from the registry is the same
|
||||
// original object that was passed in.
|
||||
REQUIRE(poolPtr == &test_table);
|
||||
}
|
||||
// Verify that the object returned from the registry is the same
|
||||
// original object that was passed in.
|
||||
REQUIRE(poolPtr == &test_table);
|
||||
}
|
||||
|
||||
TEST_CASE("EntityManager::DeregisterPool", TEST_SUITE_NAME)
|
||||
{
|
||||
EntityManager& registry = EntityManager::GetInstance();
|
||||
SECTION("EntityManager::DeregisterPool")
|
||||
{
|
||||
EntityManager& registry = EntityManager::GetInstance();
|
||||
|
||||
auto& pools = registry.getPools();
|
||||
auto& typeInfo = SomeComponent::GetType();
|
||||
auto oldSize = pools.size();
|
||||
auto& pools = registry.getPools();
|
||||
auto& typeInfo = SomeComponent::GetType();
|
||||
auto oldSize = pools.size();
|
||||
|
||||
REQUIRE(pools.size() > 0);
|
||||
registry.DeregisterPool(typeInfo);
|
||||
REQUIRE(pools.size() < oldSize);
|
||||
CHECK(pools.size() > 0);
|
||||
registry.DeregisterPool(typeInfo);
|
||||
REQUIRE(pools.size() < oldSize);
|
||||
|
||||
oldSize = pools.size();
|
||||
registry.DeregisterPool(SomeOtherComponent::GetType());
|
||||
REQUIRE(pools.size() < oldSize);
|
||||
oldSize = pools.size();
|
||||
registry.DeregisterPool(SomeOtherComponent::GetType());
|
||||
REQUIRE(pools.size() < oldSize);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(TestFixture, "EntityManager::GetIterable", TEST_SUITE_NAME)
|
||||
|
@ -54,7 +54,7 @@ BEGIN_TEST_SUITE("class:EventDispatcher")
|
||||
{
|
||||
}
|
||||
|
||||
const std::queue<SDL_Event>& GetEventQueue() const
|
||||
inline const std::queue<SDL_Event>& GetEventQueue() const
|
||||
{
|
||||
return this->getEventBuffer();
|
||||
}
|
||||
|
@ -22,12 +22,12 @@
|
||||
static const char* TEST_SUITE_NAME = "[" name "]"; \
|
||||
namespace
|
||||
|
||||
#define SUITE_TEST(testname) TEST_CASE(#testname, TEST_SUITE_NAME)
|
||||
#define SUITE_TEST(testname) TEST_CASE(testname, TEST_SUITE_NAME)
|
||||
|
||||
#define FIXTURE_CASE(FixtureName, testname) \
|
||||
TEST_CASE_METHOD(FixtureName, #testname, TEST_SUITE_NAME)
|
||||
TEST_CASE_METHOD(FixtureName, testname, TEST_SUITE_NAME)
|
||||
|
||||
#define TEST_SUITE_CASE(testname) FIXTURE_CASE(TestFixture, #testname)
|
||||
#define TEST_SUITE_CASE(testname) FIXTURE_CASE(TestFixture, testname)
|
||||
|
||||
#ifdef VIM_COMPLETION
|
||||
#define UNIT_TEST 1
|
||||
|
Loading…
Reference in New Issue
Block a user