Skip to content

Commit

Permalink
Add CorePortIndexMapContainer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik committed Aug 23, 2021
1 parent 4598078 commit ff7c6c5
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 2 deletions.
5 changes: 3 additions & 2 deletions unittest/vslib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
90 changes: 90 additions & 0 deletions unittest/vslib/TestCorePortIndexMapContainer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#include "CorePortIndexMapContainer.h"

#include <gtest/gtest.h>

using namespace saivs;

TEST(CorePortIndexMapContainer, remove)
{
auto cpim = std::make_shared<CorePortIndexMap>(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<CorePortIndexMap>(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<CorePortIndexMap>(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<CorePortIndexMap>(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<CorePortIndexMap>(0);

CorePortIndexMapContainer cpimc;

cpimc.insert(cpime);

auto cpim = std::make_shared<CorePortIndexMap>(1);

std::vector<uint32_t> 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);
}

0 comments on commit ff7c6c5

Please sign in to comment.