Skip to content

Commit

Permalink
Add SwitchContainer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik committed Aug 23, 2021
1 parent 484beb1 commit 923ab2f
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
74 changes: 74 additions & 0 deletions unittest/vslib/TestSwitchContainer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include "SwitchContainer.h"

#include <gtest/gtest.h>

using namespace saivs;

TEST(SwitchContainer, insert)
{
SwitchContainer sc;

EXPECT_THROW(sc.insert(nullptr), std::runtime_error);

auto s = std::make_shared<Switch>(0x2100000000);

sc.insert(s);

EXPECT_THROW(sc.insert(s), std::runtime_error);
}

TEST(SwitchContainer, removeSwitch)
{
SwitchContainer sc;

EXPECT_THROW(sc.removeSwitch(0), std::runtime_error);

auto s = std::make_shared<Switch>(0x2100000000);

sc.insert(s);

sc.removeSwitch(0x2100000000);

s = std::make_shared<Switch>(0x2100000000);

sc.insert(s);

EXPECT_THROW(sc.removeSwitch(nullptr), std::runtime_error);

EXPECT_THROW(sc.removeSwitch(1), std::runtime_error);

sc.removeSwitch(s);
}

TEST(SwitchContainer, clear)
{
SwitchContainer sc;

sc.clear();
}

TEST(SwitchContainer, contains)
{
SwitchContainer sc;

auto s = std::make_shared<Switch>(0x2100000000);

sc.insert(s);

EXPECT_TRUE(sc.contains(0x2100000000));

EXPECT_FALSE(sc.contains(1));
}

TEST(SwitchContainer, getSwitch)
{
SwitchContainer sc;

auto s = std::make_shared<Switch>(0x2100000000);

sc.insert(s);

EXPECT_NE(sc.getSwitch(0x2100000000), nullptr);

EXPECT_EQ(sc.getSwitch(1), nullptr);
}
10 changes: 10 additions & 0 deletions vslib/SwitchContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ void SwitchContainer::insert(
{
SWSS_LOG_ENTER();

if (sw == nullptr)
{
SWSS_LOG_THROW("switch pointer can't be nullptr");
}

auto switchId = sw->getSwitchId();

if (m_switchMap.find(switchId) != m_switchMap.end())
Expand Down Expand Up @@ -42,6 +47,11 @@ void SwitchContainer::removeSwitch(
{
SWSS_LOG_ENTER();

if (sw == nullptr)
{
SWSS_LOG_THROW("switch pointer can't be nullptr");
}

removeSwitch(sw->getSwitchId());
}

Expand Down

0 comments on commit 923ab2f

Please sign in to comment.