diff --git a/tools/projmgr/src/ProjMgrWorker.cpp b/tools/projmgr/src/ProjMgrWorker.cpp index f4e004de5..ec2068a7b 100644 --- a/tools/projmgr/src/ProjMgrWorker.cpp +++ b/tools/projmgr/src/ProjMgrWorker.cpp @@ -4427,6 +4427,9 @@ bool ProjMgrWorker::IsConnectionSubset(const ConnectionsCollection& connectionSu } bool ProjMgrWorker::IsCollectionSubset(const ConnectionsCollectionVec& collectionSubset, const ConnectionsCollectionVec& collectionSuperset) { + if (collectionSubset.size() != collectionSuperset.size()) { + return false; + } for (const auto& subset : collectionSubset) { bool isSubset = false; for (const auto& superset : collectionSuperset) { @@ -4443,15 +4446,14 @@ bool ProjMgrWorker::IsCollectionSubset(const ConnectionsCollectionVec& collectio } void ProjMgrWorker::RemoveRedundantSubsets(std::vector& validConnections) { - const auto connections = validConnections; auto it = validConnections.begin(); - for (const auto& collection : connections) { + while (it < validConnections.end()) { bool isSubset = false; - for (const auto& otherCollection : connections) { - if (&collection == &otherCollection) { + for (auto it2 = validConnections.begin(); it2 < validConnections.end(); it2++) { + if (it == it2) { continue; } - if (IsCollectionSubset(collection, otherCollection)) { + if (IsCollectionSubset(*it, *it2)) { isSubset = true; break; } diff --git a/tools/projmgr/test/src/ProjMgrWorkerUnitTests.cpp b/tools/projmgr/test/src/ProjMgrWorkerUnitTests.cpp index e9f5a4582..132ceb1ed 100644 --- a/tools/projmgr/test/src/ProjMgrWorkerUnitTests.cpp +++ b/tools/projmgr/test/src/ProjMgrWorkerUnitTests.cpp @@ -1256,18 +1256,19 @@ TEST_F(ProjMgrWorkerUnitTests, CheckDeviceLayer) { }; TEST_F(ProjMgrWorkerUnitTests, RemoveRedundantSubsets) { - const string strA = "A"; - const string strB = "B"; - const string strC = "C"; - ConnectionsCollection A = { strA, RteUtils::EMPTY_STRING }; - ConnectionsCollection B = { strB, RteUtils::EMPTY_STRING }; - ConnectionsCollection C = { strC, RteUtils::EMPTY_STRING }; - ConnectionsCollectionVec vecAB = { A, B }; - ConnectionsCollectionVec vecA = { A }; - ConnectionsCollectionVec vecB = { B }; - ConnectionsCollectionVec vecC = { C }; - vector validConnections = { vecAB, vecA, vecB, vecC }; - vector expected = { vecAB, vecC }; + ConnectItem connect1 = { "connect1" }; + ConnectItem connect2 = { "connect2" }; + ConnectItem connect3 = { "connect3" }; + const ConnectItem* c1 = { &connect1 }; + const ConnectItem* c2 = { &connect2 }; + const ConnectItem* c3 = { &connect3 }; + ConnectionsCollection A = { "filenameA", RteUtils::EMPTY_STRING, {c1, c2, c3} }; + ConnectionsCollection As = { "filenameA", RteUtils::EMPTY_STRING, {c3, c1} }; + ConnectionsCollection B = { "filenameB", RteUtils::EMPTY_STRING, {c1, c2, c3} }; + ConnectionsCollection Bs = { "filenameB", RteUtils::EMPTY_STRING, {c2} }; + ConnectionsCollection C = { "filenameC", RteUtils::EMPTY_STRING }; + vector validConnections = { { Bs }, { A, B }, { A }, { B, A }, { B }, { A, B }, { As }, { C }, { Bs } }; + vector expected = { { A }, { B }, { A, B }, { C } }; RemoveRedundantSubsets(validConnections); auto it = validConnections.begin(); for (const auto& expectedItem : expected) {