From ff7c6c5839b6546afbab11da0473c3fc8037ee58 Mon Sep 17 00:00:00 2001 From: kcudnik Date: Wed, 18 Aug 2021 13:56:39 +0200 Subject: [PATCH] Add CorePortIndexMapContainer tests --- unittest/vslib/Makefile.am | 5 +- .../vslib/TestCorePortIndexMapContainer.cpp | 90 +++++++++++++++++++ 2 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 unittest/vslib/TestCorePortIndexMapContainer.cpp diff --git a/unittest/vslib/Makefile.am b/unittest/vslib/Makefile.am index a888f1a32842..4cf41943e6eb 100644 --- a/unittest/vslib/Makefile.am +++ b/unittest/vslib/Makefile.am @@ -7,7 +7,8 @@ LDADD_GTEST = -L/usr/src/gtest -lgtest -lgtest_main tests_SOURCES = main.cpp \ TestBuffer.cpp \ TestContextConfigContainer.cpp \ - TestCorePortIndexMap.cpp + TestCorePortIndexMap.cpp \ + TestCorePortIndexMapContainer.cpp tests_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) tests_LDADD = $(LDADD_GTEST) $(top_srcdir)/vslib/libSaiVS.a -lhiredis -lswsscommon -lpthread -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq $(CODE_COVERAGE_LIBS) @@ -63,4 +64,4 @@ testslibsaivs_SOURCES = main_libsaivs.cpp \ testslibsaivs_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) testslibsaivs_LDADD = $(LDADD_GTEST) -L$(top_srcdir)/vslib/.libs -lsaivs -lhiredis -lswsscommon -lpthread -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq $(CODE_COVERAGE_LIBS) -TESTS = tests testslibsaivs +TESTS = testslibsaivs tests diff --git a/unittest/vslib/TestCorePortIndexMapContainer.cpp b/unittest/vslib/TestCorePortIndexMapContainer.cpp new file mode 100644 index 000000000000..fe560507933d --- /dev/null +++ b/unittest/vslib/TestCorePortIndexMapContainer.cpp @@ -0,0 +1,90 @@ +#include "CorePortIndexMapContainer.h" + +#include + +using namespace saivs; + +TEST(CorePortIndexMapContainer, remove) +{ + auto cpim = std::make_shared(0); + + CorePortIndexMapContainer cpimc; + + cpimc.insert(cpim); + + EXPECT_EQ(cpimc.size(), 1); + + cpimc.remove(1); + + EXPECT_EQ(cpimc.size(), 1); + + cpimc.remove(0); + + EXPECT_EQ(cpimc.size(), 0); +} + +TEST(CorePortIndexMapContainer, getCorePortIndexMap) +{ + auto cpim = std::make_shared(0); + + CorePortIndexMapContainer cpimc; + + cpimc.insert(cpim); + + EXPECT_EQ(cpimc.getCorePortIndexMap(1), nullptr); + + EXPECT_NE(cpimc.getCorePortIndexMap(0), nullptr); +} + +TEST(CorePortIndexMapContainer, clear) +{ + auto cpim = std::make_shared(0); + + CorePortIndexMapContainer cpimc; + + cpimc.insert(cpim); + + EXPECT_EQ(cpimc.size(), 1); + + cpimc.clear(); + + EXPECT_EQ(cpimc.size(), 0); +} + +TEST(CorePortIndexMapContainer, hasCorePortIndexMap) +{ + auto cpim = std::make_shared(0); + + CorePortIndexMapContainer cpimc; + + cpimc.insert(cpim); + + EXPECT_EQ(cpimc.hasCorePortIndexMap(0), true); + + EXPECT_EQ(cpimc.hasCorePortIndexMap(1), false); +} + +TEST(CorePortIndexMapContainer, removeEmptyCorePortIndexMaps) +{ + auto cpime = std::make_shared(0); + + CorePortIndexMapContainer cpimc; + + cpimc.insert(cpime); + + auto cpim = std::make_shared(1); + + std::vector ok {1,0}; + + EXPECT_EQ(cpim->add("foo", ok), true); + + EXPECT_EQ(cpim->isEmpty(), false); + + cpimc.insert(cpim); + + EXPECT_EQ(cpimc.size(), 2); + + cpimc.removeEmptyCorePortIndexMaps(); + + EXPECT_EQ(cpimc.size(), 1); +}