Skip to content

Commit 89d639b

Browse files
authored
[unittest] Add NotificationBfdSessionStateChange tests (sonic-net#940)
1 parent 40e9c74 commit 89d639b

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

unittest/meta/Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ tests_SOURCES = \
2222
TestNotificationQueuePfcDeadlock.cpp \
2323
TestNotificationSwitchShutdownRequest.cpp \
2424
TestNotificationSwitchStateChange.cpp \
25+
TestNotificationBfdSessionStateChange.cpp \
2526
TestOidRefCounter.cpp \
2627
TestPerformanceIntervalTimer.cpp \
2728
TestPortRelatedSet.cpp \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#include "NotificationBfdSessionStateChange.h"
2+
#include "Meta.h"
3+
#include "MetaTestSaiInterface.h"
4+
5+
#include "sairediscommon.h"
6+
#include "sai_serialize.h"
7+
8+
#include <gtest/gtest.h>
9+
10+
#include <memory>
11+
12+
using namespace sairedis;
13+
using namespace saimeta;
14+
15+
static std::string s = "[{\"bfd_session_id\":\"oid:0x100000000001a\",\"session_state\":\"SAI_BFD_SESSION_STATE_ADMIN_DOWN\"}]";
16+
static std::string null = "[{\"bfd_session_id\":\"oid:0x0\",\"session_state\":\"SAI_BFD_SESSION_STATE_ADMIN_DOWN\"}]";
17+
static std::string fullnull = "[]";
18+
19+
TEST(NotificationBfdSessionStateChange, ctr)
20+
{
21+
NotificationBfdSessionStateChange n(s);
22+
}
23+
24+
TEST(NotificationBfdSessionStateChange, getSwitchId)
25+
{
26+
NotificationBfdSessionStateChange n(s);
27+
28+
EXPECT_EQ(n.getSwitchId(), 0);
29+
30+
NotificationBfdSessionStateChange n2(null);
31+
32+
EXPECT_EQ(n2.getSwitchId(), 0);
33+
}
34+
35+
TEST(NotificationBfdSessionStateChange, getAnyObjectId)
36+
{
37+
NotificationBfdSessionStateChange n(s);
38+
39+
EXPECT_EQ(n.getAnyObjectId(), 0x100000000001a);
40+
41+
NotificationBfdSessionStateChange n2(null);
42+
43+
EXPECT_EQ(n2.getAnyObjectId(), 0);
44+
45+
NotificationBfdSessionStateChange n3(fullnull);
46+
47+
EXPECT_EQ(n3.getSwitchId(), 0);
48+
49+
EXPECT_EQ(n3.getAnyObjectId(), 0);
50+
}
51+
52+
TEST(NotificationBfdSessionStateChange, processMetadata)
53+
{
54+
NotificationBfdSessionStateChange n(s);
55+
56+
auto sai = std::make_shared<MetaTestSaiInterface>();
57+
auto meta = std::make_shared<Meta>(sai);
58+
59+
n.processMetadata(meta);
60+
}
61+
62+
static void on_bfd_session_state_change(
63+
_In_ uint32_t count,
64+
_In_ const sai_bfd_session_state_notification_t *data)
65+
{
66+
SWSS_LOG_ENTER();
67+
}
68+
69+
TEST(NotificationBfdSessionStateChange, executeCallback)
70+
{
71+
NotificationBfdSessionStateChange n(s);
72+
73+
sai_switch_notifications_t ntfs;
74+
75+
ntfs.on_bfd_session_state_change = &on_bfd_session_state_change;
76+
77+
n.executeCallback(ntfs);
78+
}
79+

0 commit comments

Comments
 (0)