Skip to content

Commit

Permalink
Add SwitchContainer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik committed Sep 20, 2021
1 parent bcd1648 commit e33c6e9
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 1 deletion.
3 changes: 2 additions & 1 deletion unittest/lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
105 changes: 105 additions & 0 deletions unittest/lib/TestSwitchContainer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#include "SwitchContainer.h"

#include <gtest/gtest.h>

#include <memory>

using namespace sairedis;

TEST(SwitchContainer, insert)
{
auto s = std::make_shared<Switch>(1);

auto sc = std::make_shared<SwitchContainer>();

sc->insert(s);

EXPECT_THROW(sc->insert(s), std::runtime_error);

auto s2 = std::make_shared<Switch>(2);

EXPECT_THROW(sc->insert(s2), std::runtime_error);
}

TEST(SwitchContainer, removeSwitch)
{
auto s = std::make_shared<Switch>(1);

auto sc = std::make_shared<SwitchContainer>();

sc->insert(s);

EXPECT_THROW(sc->removeSwitch(2), std::runtime_error);

sc->removeSwitch(1);
}

TEST(SwitchContainer, removeSwitch_shared)
{
auto s = std::make_shared<Switch>(1);

auto sc = std::make_shared<SwitchContainer>();

sc->insert(s);

auto s2 = std::make_shared<Switch>(2);

EXPECT_THROW(sc->removeSwitch(s2), std::runtime_error);

sc->removeSwitch(s);
}

TEST(SwitchContainer, getSwitch)
{
auto s = std::make_shared<Switch>(1);

auto sc = std::make_shared<SwitchContainer>();

sc->insert(s);

EXPECT_NE(sc->getSwitch(1), nullptr);

EXPECT_EQ(sc->getSwitch(2), nullptr);
}

TEST(SwitchContainer, clear)
{
auto s = std::make_shared<Switch>(1);

auto sc = std::make_shared<SwitchContainer>();

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<Switch>(1);

auto sc = std::make_shared<SwitchContainer>();

sc->insert(s);

EXPECT_TRUE(sc->contains(1));

EXPECT_FALSE(sc->contains(2));
}

TEST(SwitchContainer, getSwitchByHardwareInfo)
{
auto s = std::make_shared<Switch>(1);

auto sc = std::make_shared<SwitchContainer>();

sc->insert(s);

EXPECT_EQ(sc->getSwitchByHardwareInfo("foo"), nullptr);

EXPECT_NE(sc->getSwitchByHardwareInfo(""), nullptr);
}

0 comments on commit e33c6e9

Please sign in to comment.