Skip to content

Commit

Permalink
[unittest] Add NotificationBfdSessionStateChange tests (#940)
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored Sep 22, 2021
1 parent 40e9c74 commit 89d639b
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
1 change: 1 addition & 0 deletions unittest/meta/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ tests_SOURCES = \
TestNotificationQueuePfcDeadlock.cpp \
TestNotificationSwitchShutdownRequest.cpp \
TestNotificationSwitchStateChange.cpp \
TestNotificationBfdSessionStateChange.cpp \
TestOidRefCounter.cpp \
TestPerformanceIntervalTimer.cpp \
TestPortRelatedSet.cpp \
Expand Down
79 changes: 79 additions & 0 deletions unittest/meta/TestNotificationBfdSessionStateChange.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include "NotificationBfdSessionStateChange.h"
#include "Meta.h"
#include "MetaTestSaiInterface.h"

#include "sairediscommon.h"
#include "sai_serialize.h"

#include <gtest/gtest.h>

#include <memory>

using namespace sairedis;
using namespace saimeta;

static std::string s = "[{\"bfd_session_id\":\"oid:0x100000000001a\",\"session_state\":\"SAI_BFD_SESSION_STATE_ADMIN_DOWN\"}]";
static std::string null = "[{\"bfd_session_id\":\"oid:0x0\",\"session_state\":\"SAI_BFD_SESSION_STATE_ADMIN_DOWN\"}]";
static std::string fullnull = "[]";

TEST(NotificationBfdSessionStateChange, ctr)
{
NotificationBfdSessionStateChange n(s);
}

TEST(NotificationBfdSessionStateChange, getSwitchId)
{
NotificationBfdSessionStateChange n(s);

EXPECT_EQ(n.getSwitchId(), 0);

NotificationBfdSessionStateChange n2(null);

EXPECT_EQ(n2.getSwitchId(), 0);
}

TEST(NotificationBfdSessionStateChange, getAnyObjectId)
{
NotificationBfdSessionStateChange n(s);

EXPECT_EQ(n.getAnyObjectId(), 0x100000000001a);

NotificationBfdSessionStateChange n2(null);

EXPECT_EQ(n2.getAnyObjectId(), 0);

NotificationBfdSessionStateChange n3(fullnull);

EXPECT_EQ(n3.getSwitchId(), 0);

EXPECT_EQ(n3.getAnyObjectId(), 0);
}

TEST(NotificationBfdSessionStateChange, processMetadata)
{
NotificationBfdSessionStateChange n(s);

auto sai = std::make_shared<MetaTestSaiInterface>();
auto meta = std::make_shared<Meta>(sai);

n.processMetadata(meta);
}

static void on_bfd_session_state_change(
_In_ uint32_t count,
_In_ const sai_bfd_session_state_notification_t *data)
{
SWSS_LOG_ENTER();
}

TEST(NotificationBfdSessionStateChange, executeCallback)
{
NotificationBfdSessionStateChange n(s);

sai_switch_notifications_t ntfs;

ntfs.on_bfd_session_state_change = &on_bfd_session_state_change;

n.executeCallback(ntfs);
}

0 comments on commit 89d639b

Please sign in to comment.