Skip to content

Commit 2cb5d7e

Browse files
committed
test(agnocastlib): add unit test for EpollEventType
Signed-off-by: Takumi Jin <primenumber_2_3_5@yahoo.co.jp>
1 parent 02fc532 commit 2cb5d7e

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

src/agnocastlib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ if(BUILD_TESTING)
130130
test/unit/test_agnocast_subscription.cpp
131131
test/unit/test_mocked_agnocast.cpp
132132
test/unit/test_agnocast_executors.cpp
133+
test/unit/test_agnocast_epoll_event.cpp
133134
test/unit/test_agnocast_epoll_update.cpp
134135
test/unit/test_node_topics.cpp
135136
test/unit/test_cie_client_utils.cpp)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include "agnocast/agnocast_callback_info.hpp"
2+
#include "agnocast/agnocast_epoll_event.hpp"
3+
4+
#include <gtest/gtest.h>
5+
6+
#include <array>
7+
8+
namespace agnocast
9+
{
10+
11+
TEST(EpollEventDataTest, PackAndUnpackRoundTripForAllKnownTypes)
12+
{
13+
constexpr EpollEventLocalID id = 0x12345678;
14+
15+
const std::array<EpollEventType, static_cast<size_t>(EpollEventType::NrEventType)> types = {
16+
EpollEventType::Subscription, EpollEventType::Timer, EpollEventType::Clock,
17+
EpollEventType::Shutdown};
18+
19+
for (auto type : types) {
20+
const auto packed = pack_epoll_data(type, id);
21+
const auto [unpacked_type, unpacked_id] = unpack_epoll_data(packed);
22+
23+
EXPECT_EQ(unpacked_type, type);
24+
EXPECT_EQ(unpacked_id, id);
25+
}
26+
}
27+
28+
TEST(EpollEventDataTest, PackPlacesTypeInUpperBitsAndIdInLowerBits)
29+
{
30+
constexpr auto type = EpollEventType::Shutdown;
31+
constexpr EpollEventLocalID id = 0x89ABCDEF;
32+
33+
const auto packed = pack_epoll_data(type, id);
34+
35+
EXPECT_EQ(packed >> EPOLL_DATA_TYPE_SHIFT, static_cast<uint64_t>(type));
36+
EXPECT_EQ(packed & static_cast<uint64_t>(EPOLL_DATA_ID_BITMASK), static_cast<uint64_t>(id));
37+
}
38+
39+
TEST(EpollEventDataTest, PackAndUnpackWithMaxID)
40+
{
41+
constexpr auto type = EpollEventType::Subscription;
42+
constexpr EpollEventLocalID id = MAX_CALLBACK_INFO_ID - 1;
43+
44+
const auto packed = pack_epoll_data(type, id);
45+
const auto [unpacked_type, unpacked_id] = unpack_epoll_data(packed);
46+
47+
EXPECT_EQ(unpacked_type, type);
48+
EXPECT_EQ(unpacked_id, id);
49+
}
50+
51+
} // namespace agnocast

0 commit comments

Comments
 (0)