From e33c6e921b08e8fb0762c5e3bae78122a171c32f Mon Sep 17 00:00:00 2001 From: kcudnik Date: Mon, 6 Sep 2021 20:34:07 +0200 Subject: [PATCH] Add SwitchContainer tests --- unittest/lib/Makefile.am | 3 +- unittest/lib/TestSwitchContainer.cpp | 105 +++++++++++++++++++++++++++ 2 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 unittest/lib/TestSwitchContainer.cpp diff --git a/unittest/lib/Makefile.am b/unittest/lib/Makefile.am index 067158618..46fad44a7 100644 --- a/unittest/lib/Makefile.am +++ b/unittest/lib/Makefile.am @@ -15,7 +15,8 @@ tests_SOURCES = \ TestContextConfigContainer.cpp \ TestUtils.cpp \ TestVirtualObjectIdManager.cpp \ - TestZeroMQChannel.cpp + TestZeroMQChannel.cpp \ + TestSwitchContainer.cpp tests_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) tests_LDADD = $(LDADD_GTEST) $(top_srcdir)/lib/libSaiRedis.a -lhiredis -lswsscommon -lpthread -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq $(CODE_COVERAGE_LIBS) diff --git a/unittest/lib/TestSwitchContainer.cpp b/unittest/lib/TestSwitchContainer.cpp new file mode 100644 index 000000000..5674d58fe --- /dev/null +++ b/unittest/lib/TestSwitchContainer.cpp @@ -0,0 +1,105 @@ +#include "SwitchContainer.h" + +#include + +#include + +using namespace sairedis; + +TEST(SwitchContainer, insert) +{ + auto s = std::make_shared(1); + + auto sc = std::make_shared(); + + sc->insert(s); + + EXPECT_THROW(sc->insert(s), std::runtime_error); + + auto s2 = std::make_shared(2); + + EXPECT_THROW(sc->insert(s2), std::runtime_error); +} + +TEST(SwitchContainer, removeSwitch) +{ + auto s = std::make_shared(1); + + auto sc = std::make_shared(); + + sc->insert(s); + + EXPECT_THROW(sc->removeSwitch(2), std::runtime_error); + + sc->removeSwitch(1); +} + +TEST(SwitchContainer, removeSwitch_shared) +{ + auto s = std::make_shared(1); + + auto sc = std::make_shared(); + + sc->insert(s); + + auto s2 = std::make_shared(2); + + EXPECT_THROW(sc->removeSwitch(s2), std::runtime_error); + + sc->removeSwitch(s); +} + +TEST(SwitchContainer, getSwitch) +{ + auto s = std::make_shared(1); + + auto sc = std::make_shared(); + + sc->insert(s); + + EXPECT_NE(sc->getSwitch(1), nullptr); + + EXPECT_EQ(sc->getSwitch(2), nullptr); +} + +TEST(SwitchContainer, clear) +{ + auto s = std::make_shared(1); + + auto sc = std::make_shared(); + + sc->insert(s); + + EXPECT_NE(sc->getSwitch(1), nullptr); + + sc->clear(); + + EXPECT_EQ(sc->getSwitch(1), nullptr); +} + +TEST(SwitchContainer, contains) +{ + auto s = std::make_shared(1); + + auto sc = std::make_shared(); + + sc->insert(s); + + EXPECT_TRUE(sc->contains(1)); + + EXPECT_FALSE(sc->contains(2)); +} + +TEST(SwitchContainer, getSwitchByHardwareInfo) +{ + auto s = std::make_shared(1); + + auto sc = std::make_shared(); + + sc->insert(s); + + EXPECT_EQ(sc->getSwitchByHardwareInfo("foo"), nullptr); + + EXPECT_NE(sc->getSwitchByHardwareInfo(""), nullptr); +} +