From 67dc55dfb235ba9f196db3f0c4230be30d56b7cf Mon Sep 17 00:00:00 2001 From: parker Date: Sat, 19 Jul 2025 00:54:42 +0100 Subject: [PATCH] fix: tests failing --- CMakeLists.txt | 54 +++++++++++++-------------- README.md | 2 + src/Engine/Operator/OperatorTable.cpp | 14 +++++++ src/Engine/Operator/OperatorTable.h | 2 + src/Gui/main.cpp | 8 +--- tests/Benchmarks.cpp | 16 ++++++-- tests/NetworkTests.cpp | 20 +++++++--- tests/main-tests.cpp | 22 ----------- 8 files changed, 72 insertions(+), 66 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 228e3f2..d86c9ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,37 +73,37 @@ target_link_libraries(${AppExec} PRIVATE Qt6::Core Qt6::Widgets Qt6::SvgWidgets target_include_directories(${AppExec} PUBLIC src) # tests -# Include(FetchContent) +Include(FetchContent) -# FetchContent_Declare( -# Catch2 -# GIT_REPOSITORY https://github.com/catchorg/Catch2.git -# GIT_TAG v3.8.1 # or a later release -# ) +FetchContent_Declare( + Catch2 + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG v3.8.1 # or a later release +) -# FetchContent_MakeAvailable(Catch2) +FetchContent_MakeAvailable(Catch2) -# add_executable(${TestExec} -# ${ENGINE_SOURCES} -# tests/main-tests.cpp -# tests/OperatorTests.cpp -# tests/NetworkTests.cpp -# ) -# target_link_libraries(${TestExec} PRIVATE Catch2::Catch2WithMain Eigen3::Eigen Qt6::Core TBB::tbb Boost::filesystem Boost::system) -# target_compile_definitions(${TestExec} PRIVATE UNIT_TEST) -# target_include_directories(${TestExec} PUBLIC -# src -# ${BOOST_INCLUDE_DIRS} -# ) +add_executable(${TestExec} + ${ENGINE_SOURCES} + tests/main-tests.cpp + tests/OperatorTests.cpp + tests/NetworkTests.cpp +) +target_link_libraries(${TestExec} PRIVATE Catch2::Catch2WithMain Eigen3::Eigen Qt6::Core TBB::tbb Boost::filesystem Boost::system) +target_compile_definitions(${TestExec} PRIVATE UNIT_TEST) +target_include_directories(${TestExec} PUBLIC + src + ${BOOST_INCLUDE_DIRS} +) -# # benchmarks -# add_executable(${BenchExec} -# ${ENGINE_SOURCES} +# benchmarks +add_executable(${BenchExec} + ${ENGINE_SOURCES} -# tests/Benchmarks.cpp -# ) -# target_link_libraries(${BenchExec} PRIVATE Catch2::Catch2WithMain Eigen3::Eigen Qt6::Core TBB::tbb) -# target_compile_definitions(${BenchExec} PRIVATE UNIT_TEST) -# target_include_directories(${BenchExec} PUBLIC src) + tests/Benchmarks.cpp +) +target_link_libraries(${BenchExec} PRIVATE Catch2::Catch2WithMain Eigen3::Eigen Qt6::Core TBB::tbb Boost::filesystem Boost::system) +target_compile_definitions(${BenchExec} PRIVATE UNIT_TEST) +target_include_directories(${BenchExec} PUBLIC src) add_subdirectory(src/OpDefs) diff --git a/README.md b/README.md index c9c5e64..23d6948 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,8 @@ Enzo is a 3D animation software application focused on procedural geometry editi - glm - catch2 - oneTBB +- TBB +- boost > [!IMPORTANT] diff --git a/src/Engine/Operator/OperatorTable.cpp b/src/Engine/Operator/OperatorTable.cpp index 906c5c5..999b952 100644 --- a/src/Engine/Operator/OperatorTable.cpp +++ b/src/Engine/Operator/OperatorTable.cpp @@ -1,4 +1,5 @@ #include "Engine/Operator/OperatorTable.h" +#include #include @@ -26,5 +27,18 @@ std::vector enzo::op::OperatorTable::getData() return opInfoStore_; } +void enzo::op::OperatorTable::initPlugins() +{ + static bool pluginsLoaded=false; + if(pluginsLoaded) return; + + auto initPlugin = boost::dll::import_symbol( + "build/src/OpDefs/libenzoOps1.so", "newSopOperator" + ); + + initPlugin(enzo::op::OperatorTable::addOperator); + + pluginsLoaded = true; +} std::vector enzo::op::OperatorTable::opInfoStore_; diff --git a/src/Engine/Operator/OperatorTable.h b/src/Engine/Operator/OperatorTable.h index a385db0..106196a 100644 --- a/src/Engine/Operator/OperatorTable.h +++ b/src/Engine/Operator/OperatorTable.h @@ -20,6 +20,8 @@ public: static void addOperator(const char* internalName, const char* displayName, nt::opConstructor ctorFunc); static nt::opConstructor getOpConstructor(std::string name); static std::vector getData(); + // TODO: move to better spot (maybe engine class) + static void initPlugins(); private: static std::vector opInfoStore_; }; diff --git a/src/Gui/main.cpp b/src/Gui/main.cpp index 86d6b12..48f0933 100644 --- a/src/Gui/main.cpp +++ b/src/Gui/main.cpp @@ -2,7 +2,6 @@ #include #include #include "Engine/Operator/OperatorTable.h" -#include #include "Interface.h" @@ -16,12 +15,7 @@ int main(int argc, char **argv) format.setSamples(4); QSurfaceFormat::setDefaultFormat(format); - // setup table - auto initPlugin = boost::dll::import_symbol( - "build/src/OpDefs/libenzoOps1.so", "newSopOperator" - ); - - initPlugin(enzo::op::OperatorTable::addOperator); + enzo::op::OperatorTable::initPlugins(); QApplication app (argc, argv); diff --git a/tests/Benchmarks.cpp b/tests/Benchmarks.cpp index 4cfff6a..3562a66 100644 --- a/tests/Benchmarks.cpp +++ b/tests/Benchmarks.cpp @@ -4,7 +4,7 @@ #include "Engine/Network/NetworkManager.h" #include "Engine/Operator/GeometryOperator.h" #include "Engine/Types.h" -#include "Engine/Operator/GOP_test.h" +#include "Engine/Operator/OperatorTable.h" #include struct NMReset @@ -20,13 +20,21 @@ struct NMReset }; +// TODO: fix this init monstrosity +struct OperatorTableInit +{ + OperatorTableInit() { enzo::op::OperatorTable::initPlugins(); } +}; +static OperatorTableInit _operatorTableInit; +auto testOpCtor = enzo::op::OperatorTable::getOpConstructor("house"); + TEST_CASE_METHOD(NMReset, "Network Manager") { using namespace enzo; auto& nm = nt::nm(); - nt::OpId startOp = nm.addOperator(&GOP_test::ctor); + nt::OpId startOp = nm.addOperator(testOpCtor); nt::OpId prevOp = startOp; std::vector prevOps; @@ -34,7 +42,7 @@ TEST_CASE_METHOD(NMReset, "Network Manager") { for(int i=0; i<4; ++i) { - nt::OpId newOp = nm.addOperator(&GOP_test::ctor); + nt::OpId newOp = nm.addOperator(testOpCtor); prevOps.push_back(newOp); nt::connectOperators(newOp, i, prevOp, 0); } @@ -44,7 +52,7 @@ TEST_CASE_METHOD(NMReset, "Network Manager") for(int i=0; i #include "Engine/Network/NetworkManager.h" #include "Engine/Operator/GeometryOperator.h" +#include "Engine/Operator/OperatorTable.h" #include "Engine/Types.h" -#include "Engine/Operator/GOP_test.h" #include struct NMReset @@ -20,12 +20,20 @@ struct NMReset }; +// TODO: fix this init monstrosity +struct OperatorTableInit +{ + OperatorTableInit() { enzo::op::OperatorTable::initPlugins(); } +}; +static OperatorTableInit _operatorTableInit; +auto testOpCtor = enzo::op::OperatorTable::getOpConstructor("house"); + TEST_CASE_METHOD(NMReset, "network fixture separation start") { using namespace enzo; auto& nm = nt::nm(); - nt::OpId newOpId = nm.addOperator(GOP_test::ctor); + nt::OpId newOpId = nm.addOperator(testOpCtor); REQUIRE(newOpId==1); REQUIRE(nm.isValidOp(1)); @@ -45,8 +53,8 @@ TEST_CASE_METHOD(NMReset, "network") using namespace enzo; auto& nm = nt::nm(); - nt::OpId newOpId = nm.addOperator(GOP_test::ctor); - nt::OpId newOpId2 = nm.addOperator(GOP_test::ctor); + nt::OpId newOpId = nm.addOperator(testOpCtor); + nt::OpId newOpId2 = nm.addOperator(testOpCtor); REQUIRE(nm.isValidOp(newOpId)); if(nm.isValidOp(newOpId)) @@ -70,13 +78,13 @@ TEST_CASE_METHOD(NMReset, "reset") using namespace enzo; auto& nm = nt::nm(); - nt::OpId newOpId = nm.addOperator(GOP_test::ctor); + nt::OpId newOpId = nm.addOperator(testOpCtor); nm._reset(); REQUIRE_FALSE(nm.isValidOp(newOpId)); - nt::OpId newOpId2 = nm.addOperator(GOP_test::ctor); + nt::OpId newOpId2 = nm.addOperator(testOpCtor); REQUIRE(nm.isValidOp(newOpId2)); diff --git a/tests/main-tests.cpp b/tests/main-tests.cpp index e005d19..7279cbf 100644 --- a/tests/main-tests.cpp +++ b/tests/main-tests.cpp @@ -20,25 +20,3 @@ TEST_CASE("tbb") << std::this_thread::get_id() << std::endl; }); } - -TEST_CASE("boost dll") -{ - std::cout << "Using Boost " - << BOOST_VERSION / 100000 << "." // major version - << BOOST_VERSION / 100 % 1000 << "." // minor version - << BOOST_VERSION % 100 // patch level - << std::endl; - - - boost::shared_ptr cpp_var = boost::dll::import_symbol( - "build/src/OpDefs/libenzoOps1.so", "myVar" - ); - std::cout << "VAR: " << *cpp_var << "\n"; - - auto cpp11_func = boost::dll::import_symbol( - "build/src/OpDefs/libenzoOps1.so", "newSopOperator" - ); - - cpp11_func(enzo::op::OperatorTable::addOperator); - -}