fix: tests failing

This commit is contained in:
2025-07-19 00:54:42 +01:00
parent 2d9b9e9c70
commit 67dc55dfb2
8 changed files with 72 additions and 66 deletions

View File

@@ -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)

View File

@@ -24,6 +24,8 @@ Enzo is a 3D animation software application focused on procedural geometry editi
- glm
- catch2
- oneTBB
- TBB
- boost
> [!IMPORTANT]

View File

@@ -1,4 +1,5 @@
#include "Engine/Operator/OperatorTable.h"
#include <boost/dll/import.hpp>
#include <iostream>
@@ -26,5 +27,18 @@ std::vector<enzo::op::OpInfo> enzo::op::OperatorTable::getData()
return opInfoStore_;
}
void enzo::op::OperatorTable::initPlugins()
{
static bool pluginsLoaded=false;
if(pluginsLoaded) return;
auto initPlugin = boost::dll::import_symbol<void(enzo::op::addOperatorPtr)>(
"build/src/OpDefs/libenzoOps1.so", "newSopOperator"
);
initPlugin(enzo::op::OperatorTable::addOperator);
pluginsLoaded = true;
}
std::vector<enzo::op::OpInfo> enzo::op::OperatorTable::opInfoStore_;

View File

@@ -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<OpInfo> getData();
// TODO: move to better spot (maybe engine class)
static void initPlugins();
private:
static std::vector<OpInfo> opInfoStore_;
};

View File

@@ -2,7 +2,6 @@
#include <QPushButton>
#include <QSurfaceFormat>
#include "Engine/Operator/OperatorTable.h"
#include <boost/dll/import.hpp>
#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<void(enzo::op::addOperatorPtr)>(
"build/src/OpDefs/libenzoOps1.so", "newSopOperator"
);
initPlugin(enzo::op::OperatorTable::addOperator);
enzo::op::OperatorTable::initPlugins();
QApplication app (argc, argv);

View File

@@ -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 <iostream>
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<nt::OpId> 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<size(prevOpsBuffer); ++i)
{
prevOps.clear();
nt::OpId newOp = nm.addOperator(GOP_test::ctor);
nt::OpId newOp = nm.addOperator(testOpCtor);
prevOps.push_back(newOp);
nt::connectOperators(newOp, 0, prevOpsBuffer[i], 0);

View File

@@ -3,8 +3,8 @@
#include <memory>
#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 <iostream>
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));

View File

@@ -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<std::string> cpp_var = boost::dll::import_symbol<std::string>(
"build/src/OpDefs/libenzoOps1.so", "myVar"
);
std::cout << "VAR: " << *cpp_var << "\n";
auto cpp11_func = boost::dll::import_symbol<void(enzo::op::addOperatorPtr)>(
"build/src/OpDefs/libenzoOps1.so", "newSopOperator"
);
cpp11_func(enzo::op::OperatorTable::addOperator);
}