Skip to content

Commit

Permalink
Add CorePortIndexMapFileParser tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik committed Aug 23, 2021
1 parent ff7c6c5 commit 8bf97ed
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
3 changes: 2 additions & 1 deletion unittest/vslib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ tests_SOURCES = main.cpp \
TestBuffer.cpp \
TestContextConfigContainer.cpp \
TestCorePortIndexMap.cpp \
TestCorePortIndexMapContainer.cpp
TestCorePortIndexMapContainer.cpp \
TestCorePortIndexMapFileParser.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
31 changes: 31 additions & 0 deletions unittest/vslib/TestCorePortIndexMapFileParser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "CorePortIndexMapFileParser.h"

#include <gtest/gtest.h>

using namespace saivs;

TEST(CorePortIndexMapFileParser, isInterfaceNameValid)
{
EXPECT_EQ(CorePortIndexMapFileParser::isInterfaceNameValid(""), false);

EXPECT_EQ(CorePortIndexMapFileParser::isInterfaceNameValid("1111111111111111111111111111111111111111111111111111111"), false);

EXPECT_EQ(CorePortIndexMapFileParser::isInterfaceNameValid("rer/;"), false);

EXPECT_EQ(CorePortIndexMapFileParser::isInterfaceNameValid("foo"), true);
}


TEST(CorePortIndexMapFileParser, parseCorePortIndexMapFile)
{
// should load default

EXPECT_NE(CorePortIndexMapFileParser::parseCorePortIndexMapFile(nullptr), nullptr);

EXPECT_NE(CorePortIndexMapFileParser::parseCorePortIndexMapFile("not_existing"), nullptr);

EXPECT_NE(CorePortIndexMapFileParser::parseCorePortIndexMapFile("files/core_port_empty.txt"), nullptr);

EXPECT_NE(CorePortIndexMapFileParser::parseCorePortIndexMapFile("files/core_port_ok.txt"), nullptr);
}

8 changes: 8 additions & 0 deletions unittest/vslib/files/core_port_empty.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
; comment
# comment
error line
0:0
0:0:0
d:d:d
d:x_x:d
1:xx:d,d
4 changes: 4 additions & 0 deletions unittest/vslib/files/core_port_ok.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
; comment
# comment
error line
0:ifname:1,2

0 comments on commit 8bf97ed

Please sign in to comment.