feat(test): add network manager singleton reset
This commit is contained in:
@@ -79,4 +79,5 @@ add_executable(${TestExec}
|
||||
src/Engine/Operator/GeometryOpDef.cpp
|
||||
)
|
||||
target_link_libraries(${TestExec} PRIVATE Catch2::Catch2WithMain Eigen3::Eigen Qt6::Core )
|
||||
target_compile_definitions(${TestExec} PRIVATE UNIT_TEST)
|
||||
target_include_directories(${TestExec} PUBLIC src)
|
||||
|
||||
@@ -100,6 +100,18 @@ std::optional<enzo::nt::OpId> enzo::nt::NetworkManager::getDisplayOp()
|
||||
return displayOp_;
|
||||
}
|
||||
|
||||
#ifdef UNIT_TEST
|
||||
void enzo::nt::NetworkManager::_reset()
|
||||
{
|
||||
delete instancePtr_;
|
||||
instancePtr_ = nullptr;
|
||||
|
||||
gopStore_.clear();
|
||||
maxOpId_=0;
|
||||
displayOp_.reset();
|
||||
}
|
||||
#endif
|
||||
|
||||
enzo::nt::NetworkManager* enzo::nt::NetworkManager::instancePtr_ = nullptr;
|
||||
std::unordered_map<enzo::nt::OpId, std::unique_ptr<enzo::nt::GeometryOperator>> enzo::nt::NetworkManager::gopStore_;
|
||||
|
||||
|
||||
@@ -17,24 +17,31 @@ public:
|
||||
|
||||
static NetworkManager* getInstance();
|
||||
|
||||
// functions
|
||||
static OpId addOperator();
|
||||
void setDisplayOp(OpId opId);
|
||||
static std::optional<OpId> getDisplayOp();
|
||||
static bool isValidOp(nt::OpId opId);
|
||||
static GeometryOperator& getGeoOperator(nt::OpId opId);
|
||||
void setDisplayOp(OpId opId);
|
||||
|
||||
#ifdef UNIT_TEST
|
||||
static void _reset();
|
||||
#endif
|
||||
|
||||
private:
|
||||
static NetworkManager* instancePtr_;
|
||||
NetworkManager() {};
|
||||
|
||||
static std::unordered_map<enzo::nt::OpId, std::unique_ptr<enzo::nt::GeometryOperator>> gopStore_;
|
||||
|
||||
// functions
|
||||
static void cookOp(enzo::nt::OpId opId);
|
||||
static std::vector<enzo::nt::OpId> getDependencyGraph(enzo::nt::OpId opId);
|
||||
|
||||
// variables
|
||||
// store for geometry operators
|
||||
static std::unordered_map<enzo::nt::OpId, std::unique_ptr<enzo::nt::GeometryOperator>> gopStore_;
|
||||
// the highest operator id currently stored
|
||||
inline static enzo::nt::OpId maxOpId_=0;
|
||||
|
||||
// operator selected for displaying in the viewport
|
||||
inline static std::optional<OpId> displayOp_=std::nullopt;
|
||||
signals:
|
||||
void updateDisplay(enzo::geo::Geometry& geometry);
|
||||
|
||||
@@ -3,22 +3,22 @@
|
||||
#include "Engine/Network/NetworkManager.h"
|
||||
#include "Engine/Operator/GeometryOperator.h"
|
||||
#include "Engine/Types.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
TEST_CASE("network")
|
||||
{
|
||||
using namespace enzo;
|
||||
nt::NetworkManager* nm = nt::NetworkManager::getInstance();
|
||||
nt::OpId newOpId = nm->addOperator();
|
||||
nt::OpId newOpId2 = nm->addOperator();
|
||||
nt::NetworkManager::_reset();
|
||||
nt::OpId newOpId = nt::NetworkManager::addOperator();
|
||||
nt::OpId newOpId2 = nt::NetworkManager::addOperator();
|
||||
|
||||
REQUIRE(nm->isValidOp(newOpId));
|
||||
if(nm->isValidOp(newOpId))
|
||||
REQUIRE(nt::NetworkManager::isValidOp(newOpId));
|
||||
if(nt::NetworkManager::isValidOp(newOpId))
|
||||
{
|
||||
auto newConnection = std::make_shared<nt::GeometryConnection>(newOpId, 1, newOpId2, 3);
|
||||
|
||||
auto& inputOp = nm->getGeoOperator(newOpId);
|
||||
auto& outputOp = nm->getGeoOperator(newOpId2);
|
||||
auto& inputOp = nt::NetworkManager::getGeoOperator(newOpId);
|
||||
auto& outputOp = nt::NetworkManager::getGeoOperator(newOpId2);
|
||||
|
||||
// set output on the upper operator
|
||||
outputOp.addOutputConnection(newConnection);
|
||||
@@ -29,3 +29,15 @@ TEST_CASE("network")
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("reset")
|
||||
{
|
||||
using namespace enzo;
|
||||
nt::OpId newOpId = nt::NetworkManager::addOperator();
|
||||
nt::NetworkManager::_reset();
|
||||
nt::OpId newOpId2 = nt::NetworkManager::addOperator();
|
||||
|
||||
|
||||
REQUIRE_FALSE(nt::NetworkManager::isValidOp(newOpId));
|
||||
REQUIRE(nt::NetworkManager::isValidOp(newOpId2));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user