-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_shared_memory_endpoint.cpp
More file actions
97 lines (83 loc) · 2.78 KB
/
test_shared_memory_endpoint.cpp
File metadata and controls
97 lines (83 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <gtest/gtest.h>
#include <nprpc/endpoint.hpp>
using namespace nprpc;
TEST(SharedMemoryEndpoint, ParsesCorrectly)
{
// Test shared memory endpoint without port
EndPoint ep1("mem://channel_12345");
EXPECT_EQ(ep1.type(), EndPointType::SharedMemory);
EXPECT_EQ(ep1.memory_channel_id(), "channel_12345");
EXPECT_EQ(ep1.hostname(), "channel_12345");
EXPECT_EQ(ep1.port(), 0);
EXPECT_FALSE(ep1.empty());
}
TEST(SharedMemoryEndpoint, ParsesWithOptionalPort)
{
// Test shared memory endpoint with port (optional, for compatibility)
EndPoint ep2("mem://some_uuid_here:0");
EXPECT_EQ(ep2.type(), EndPointType::SharedMemory);
EXPECT_EQ(ep2.memory_channel_id(), "some_uuid_here");
EXPECT_EQ(ep2.hostname(), "some_uuid_here");
EXPECT_EQ(ep2.port(), 0);
}
TEST(SharedMemoryEndpoint, ToStringFormat)
{
// Test to_string() output
EndPoint ep3("mem://test_channel_abc");
EXPECT_EQ(ep3.to_string(), "mem://test_channel_abc");
// Should not include port separator after channel ID
std::string str = ep3.to_string();
size_t prefix_end = str.find("//") + 2; // Skip the "mem://" prefix
EXPECT_EQ(str.find(':', prefix_end), std::string::npos);
}
TEST(SharedMemoryEndpoint, GetFullReturnsChannelId)
{
// Test get_full() returns just the channel ID for shared memory
EndPoint ep4("mem://my_channel_xyz");
EXPECT_EQ(ep4.get_full(), "my_channel_xyz");
}
TEST(SharedMemoryEndpoint, ComparisonOperators)
{
// Test equality operators
EndPoint ep5("mem://channel_1");
EndPoint ep6("mem://channel_1");
EndPoint ep7("mem://channel_2");
EXPECT_EQ(ep5, ep6);
EXPECT_NE(ep5, ep7);
}
TEST(SharedMemoryEndpoint, ConstructorWithParameters)
{
// Test constructor with explicit parameters
EndPoint ep8(EndPointType::SharedMemory, "explicit_channel", 0);
EXPECT_EQ(ep8.type(), EndPointType::SharedMemory);
EXPECT_EQ(ep8.memory_channel_id(), "explicit_channel");
EXPECT_EQ(ep8.to_string(), "mem://explicit_channel");
}
TEST(SharedMemoryEndpoint, EmptyChannelId)
{
// Test that an endpoint with empty hostname reports empty
EndPoint ep9;
EXPECT_TRUE(ep9.empty());
EXPECT_TRUE(ep9.memory_channel_id().empty());
}
// Test that other endpoint types return empty memory_channel_id
TEST(SharedMemoryEndpoint, OtherTypesReturnEmpty)
{
EndPoint tcp_ep("tcp://localhost:8080");
EXPECT_TRUE(tcp_ep.memory_channel_id().empty());
EndPoint ws_ep("ws://example.com:9090");
EXPECT_TRUE(ws_ep.memory_channel_id().empty());
}
// Test UUID-like channel IDs
TEST(SharedMemoryEndpoint, UuidChannelIds)
{
std::string uuid = "550e8400-e29b-41d4-a716-446655440000";
EndPoint ep10("mem://" + uuid);
EXPECT_EQ(ep10.memory_channel_id(), uuid);
EXPECT_EQ(ep10.to_string(), "mem://" + uuid);
}
int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}