diff --git a/unit_tests/graph/Test_GraphView.cpp b/unit_tests/graph/Test_GraphView.cpp index a2a348c47093c9fffd841774650fcbeba0508756..d6fcb60c1815ee00643ca4bbc176a19d63aedefd 100644 --- a/unit_tests/graph/Test_GraphView.cpp +++ b/unit_tests/graph/Test_GraphView.cpp @@ -882,29 +882,37 @@ TEST_CASE("[core/graph] AIDGE_TEST_0108000: Replacing a set of nodes, same input Log::setFileLevel(Log::Level::Warn); std::vector<std::string> logs; std::shared_ptr<GraphView> graphTest = std::make_shared<GraphView>("test_graph"); + // Create old graph auto otherInput = GenericOperator("Producer", {}, 1, "other_input"); auto other1 = GenericOperator("Other", {InputCategory::Data}, 1, "other1"); auto myOld1 = GenericOperator("Old", {InputCategory::Data}, 1, "old1"); auto myOld2 = GenericOperator("Old", {InputCategory::Data}, 1, "old2"); auto other2 = GenericOperator("Other", {InputCategory::Data}, 1, "other2"); + // Link old graph otherInput->addChild(other1); other1->addChild(myOld1); myOld1->addChild(myOld2); myOld2->addChild(other2); graphTest->add({other1, myOld1, myOld2, other2}); + // Create and link new graph auto myNew1 = GenericOperator("New", {InputCategory::Data}, 1, "new1"); auto myNew2 = GenericOperator("New", {InputCategory::Data}, 1, "new2"); myNew1->addChild(myNew2); + // Replace bool retValue = GraphView::replace({myOld1, myOld2}, {myNew1, myNew2}); + + // Check outputs CHECK(LoadTextFile("my_log.txt", logs)); CHECK(logs.size() == 0); CHECK(graphTest->getNodes() == std::set<std::shared_ptr<Node>>({other1, myNew1, myNew2, other2})); graphTest->save("myGraph",true,true); CHECK(retValue); + // Check links CHECK(myNew1->input(0).first == other1); CHECK(myNew2->output(0).at(0).first == other2); + // Check graph Nodes CHECK(graphTest->getNode("old1") == nullptr); CHECK(graphTest->getNode("old2") == nullptr); CHECK(graphTest->getNode("new1") == myNew1); @@ -916,6 +924,7 @@ TEST_CASE("[core/graph] AIDGE_TEST_0108000: Replacing a set of nodes, same input Log::setFileLevel(Log::Level::Warn); std::vector<std::string> logs; std::shared_ptr<GraphView> graphTest = std::make_shared<GraphView>("test_graph"); + // Create old graph auto otherInput1 = GenericOperator("Producer", {}, 1, "other_input1"); auto otherInput2 = GenericOperator("Producer", {}, 1, "other_input2"); auto other11 = GenericOperator("Other", {InputCategory::Data}, 1, "other11"); @@ -926,16 +935,18 @@ TEST_CASE("[core/graph] AIDGE_TEST_0108000: Replacing a set of nodes, same input auto myOld22 = GenericOperator("Old", {InputCategory::Data}, 1, "old22"); auto other21 = GenericOperator("Other", {InputCategory::Data}, 1, "other21"); auto other22 = GenericOperator("Other", {InputCategory::Data}, 1, "other22"); + // Link old graph otherInput1->addChild(other11); other11->addChild(myOld11); myOld11->addChild(myOld12); myOld12->addChild(other12); - otherInput2->addChild(other11); + otherInput2->addChild(other21); other21->addChild(myOld21); myOld21->addChild(myOld22); myOld22->addChild(other22); graphTest->add({other11, myOld11, myOld12, other12, other21, myOld21, myOld22, other22}); + // Create and link new graph auto myNew11 = GenericOperator("New", {InputCategory::Data}, 1, "new11"); auto myNew12 = GenericOperator("New", {InputCategory::Data}, 1, "new12"); auto myNew21 = GenericOperator("New", {InputCategory::Data}, 1, "new21"); @@ -943,16 +954,21 @@ TEST_CASE("[core/graph] AIDGE_TEST_0108000: Replacing a set of nodes, same input myNew11->addChild(myNew12); myNew21->addChild(myNew22); + // Replace bool retValue = GraphView::replace({myOld11, myOld12, myOld21, myOld22}, {myNew11, myNew12, myNew21, myNew22}); + + // Check outputs CHECK(LoadTextFile("my_log.txt", logs)); CHECK(logs.size() == 0); CHECK(graphTest->getNodes() == std::set<std::shared_ptr<Node>>({other11, myNew11, myNew12, other12, other21, myNew21, myNew22, other22})); graphTest->save("myGraph",true,true); CHECK(retValue); + // Check links CHECK(myNew11->input(0).first == other11); CHECK(myNew12->output(0).at(0).first == other12); CHECK(myNew21->input(0).first == other21); CHECK(myNew22->output(0).at(0).first == other22); + // Check graph Nodes CHECK(graphTest->getNode("old11") == nullptr); CHECK(graphTest->getNode("old21") == nullptr); CHECK(graphTest->getNode("old21") == nullptr);