File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -29,7 +29,8 @@ tests_SOURCES = main.cpp \
2929 TestResourceLimiterParser.cpp \
3030 TestSaiUnittests.cpp \
3131 TestSelectableFd.cpp \
32- TestSignal.cpp
32+ TestSignal.cpp \
33+ TestSwitchConfigContainer.cpp
3334
3435tests_CXXFLAGS = $(DBGFLAGS ) $(AM_CXXFLAGS ) $(CXXFLAGS_COMMON )
3536tests_LDADD = $(LDADD_GTEST ) $(top_srcdir ) /vslib/libSaiVS.a -lhiredis -lswsscommon -lnl-genl-3 -lnl-nf-3 -lnl-route-3 -lnl-3 \
Original file line number Diff line number Diff line change 1+ #include " SwitchConfigContainer.h"
2+
3+ #include < gtest/gtest.h>
4+
5+ using namespace saivs ;
6+
7+ TEST (SwitchConfigContainer, insert)
8+ {
9+ SwitchConfigContainer scc;
10+
11+ EXPECT_THROW (scc.insert (nullptr ), std::runtime_error);
12+
13+ auto sc0 = std::make_shared<SwitchConfig>(0 ," foo" );
14+ auto sc1 = std::make_shared<SwitchConfig>(0 ," bar" );
15+ auto sc2 = std::make_shared<SwitchConfig>(1 ," bar" );
16+
17+ scc.insert (sc1);
18+
19+ EXPECT_THROW (scc.insert (sc0), std::runtime_error);
20+
21+ EXPECT_THROW (scc.insert (sc2), std::runtime_error);
22+ }
23+
24+ TEST (SwitchConfigContainer, getConfig)
25+ {
26+ SwitchConfigContainer scc;
27+
28+ auto sc0 = std::make_shared<SwitchConfig>(0 ," foo" );
29+ auto sc1 = std::make_shared<SwitchConfig>(1 ," bar" );
30+
31+ scc.insert (sc0);
32+ scc.insert (sc1);
33+
34+ EXPECT_EQ (scc.getConfig (2 ), nullptr );
35+ EXPECT_NE (scc.getConfig (0 ), nullptr );
36+ EXPECT_NE (scc.getConfig (1 ), nullptr );
37+ }
Original file line number Diff line number Diff line change @@ -9,6 +9,11 @@ void SwitchConfigContainer::insert(
99{
1010 SWSS_LOG_ENTER ();
1111
12+ if (config == nullptr )
13+ {
14+ SWSS_LOG_THROW (" switch config pointer can't be nullptr" );
15+ }
16+
1217 auto it = m_indexToConfig.find (config->m_switchIndex );
1318
1419 if (it != m_indexToConfig.end ())
You can’t perform that action at this time.
0 commit comments