Skip to content

Commit e33c6e9

Browse files
committed
Add SwitchContainer tests
1 parent bcd1648 commit e33c6e9

File tree

2 files changed

+107
-1
lines changed

2 files changed

+107
-1
lines changed

unittest/lib/Makefile.am

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ tests_SOURCES = \
1515
TestContextConfigContainer.cpp \
1616
TestUtils.cpp \
1717
TestVirtualObjectIdManager.cpp \
18-
TestZeroMQChannel.cpp
18+
TestZeroMQChannel.cpp \
19+
TestSwitchContainer.cpp
1920

2021
tests_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON)
2122
tests_LDADD = $(LDADD_GTEST) $(top_srcdir)/lib/libSaiRedis.a -lhiredis -lswsscommon -lpthread -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq $(CODE_COVERAGE_LIBS)

unittest/lib/TestSwitchContainer.cpp

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#include "SwitchContainer.h"
2+
3+
#include <gtest/gtest.h>
4+
5+
#include <memory>
6+
7+
using namespace sairedis;
8+
9+
TEST(SwitchContainer, insert)
10+
{
11+
auto s = std::make_shared<Switch>(1);
12+
13+
auto sc = std::make_shared<SwitchContainer>();
14+
15+
sc->insert(s);
16+
17+
EXPECT_THROW(sc->insert(s), std::runtime_error);
18+
19+
auto s2 = std::make_shared<Switch>(2);
20+
21+
EXPECT_THROW(sc->insert(s2), std::runtime_error);
22+
}
23+
24+
TEST(SwitchContainer, removeSwitch)
25+
{
26+
auto s = std::make_shared<Switch>(1);
27+
28+
auto sc = std::make_shared<SwitchContainer>();
29+
30+
sc->insert(s);
31+
32+
EXPECT_THROW(sc->removeSwitch(2), std::runtime_error);
33+
34+
sc->removeSwitch(1);
35+
}
36+
37+
TEST(SwitchContainer, removeSwitch_shared)
38+
{
39+
auto s = std::make_shared<Switch>(1);
40+
41+
auto sc = std::make_shared<SwitchContainer>();
42+
43+
sc->insert(s);
44+
45+
auto s2 = std::make_shared<Switch>(2);
46+
47+
EXPECT_THROW(sc->removeSwitch(s2), std::runtime_error);
48+
49+
sc->removeSwitch(s);
50+
}
51+
52+
TEST(SwitchContainer, getSwitch)
53+
{
54+
auto s = std::make_shared<Switch>(1);
55+
56+
auto sc = std::make_shared<SwitchContainer>();
57+
58+
sc->insert(s);
59+
60+
EXPECT_NE(sc->getSwitch(1), nullptr);
61+
62+
EXPECT_EQ(sc->getSwitch(2), nullptr);
63+
}
64+
65+
TEST(SwitchContainer, clear)
66+
{
67+
auto s = std::make_shared<Switch>(1);
68+
69+
auto sc = std::make_shared<SwitchContainer>();
70+
71+
sc->insert(s);
72+
73+
EXPECT_NE(sc->getSwitch(1), nullptr);
74+
75+
sc->clear();
76+
77+
EXPECT_EQ(sc->getSwitch(1), nullptr);
78+
}
79+
80+
TEST(SwitchContainer, contains)
81+
{
82+
auto s = std::make_shared<Switch>(1);
83+
84+
auto sc = std::make_shared<SwitchContainer>();
85+
86+
sc->insert(s);
87+
88+
EXPECT_TRUE(sc->contains(1));
89+
90+
EXPECT_FALSE(sc->contains(2));
91+
}
92+
93+
TEST(SwitchContainer, getSwitchByHardwareInfo)
94+
{
95+
auto s = std::make_shared<Switch>(1);
96+
97+
auto sc = std::make_shared<SwitchContainer>();
98+
99+
sc->insert(s);
100+
101+
EXPECT_EQ(sc->getSwitchByHardwareInfo("foo"), nullptr);
102+
103+
EXPECT_NE(sc->getSwitchByHardwareInfo(""), nullptr);
104+
}
105+

0 commit comments

Comments
 (0)