-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathpacket_tests.cpp
More file actions
82 lines (64 loc) · 2.25 KB
/
Copy pathpacket_tests.cpp
File metadata and controls
82 lines (64 loc) · 2.25 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
////////////////////////////////////////////////////////////////////////////////
// Distributed under the Boost Software License, Version 1.0. //
// (See accompanying file LICENSE or copy at //
// https://www.boost.org/LICENSE_1_0.txt) //
////////////////////////////////////////////////////////////////////////////////
#include <gtest/gtest.h>
#include "core/exception.h"
#include "networking/packet.h"
#include "networking/packet_type.h"
static const iris::DataBuffer test_data{
static_cast<std::byte>(0x0),
static_cast<std::byte>(0x1),
static_cast<std::byte>(0x2)};
TEST(packet, construct_invalid)
{
iris::Packet p{};
ASSERT_FALSE(p.is_valid());
}
TEST(packet, construct_normal)
{
iris::Packet p{
iris::PacketType::DATA, iris::ChannelType::RELIABLE_ORDERED, test_data};
ASSERT_TRUE(p.is_valid());
ASSERT_EQ(p.type(), iris::PacketType::DATA);
ASSERT_EQ(p.channel(), iris::ChannelType::RELIABLE_ORDERED);
ASSERT_EQ(p.body_buffer(), test_data);
ASSERT_EQ(p.body_size(), test_data.size());
ASSERT_EQ(p.sequence(), 0u);
ASSERT_EQ(iris::DataBuffer(p.body(), p.body() + p.body_size()), test_data);
ASSERT_EQ(std::memcmp(p.data(), &p, p.packet_size()), 0u);
}
TEST(packet, construct_raw_packet)
{
iris::Packet p1{
iris::PacketType::DATA, iris::ChannelType::RELIABLE_ORDERED, test_data};
iris::DataBuffer raw_packet{p1.data(), p1.data() + p1.packet_size()};
iris::Packet p2{raw_packet};
ASSERT_EQ(p1, p2);
}
TEST(packet, sequence)
{
iris::Packet p{
iris::PacketType::DATA, iris::ChannelType::RELIABLE_ORDERED, test_data};
p.set_sequence(10u);
ASSERT_EQ(p.sequence(), 10u);
}
TEST(packet, equality)
{
iris::Packet p1{
iris::PacketType::DATA, iris::ChannelType::RELIABLE_ORDERED, test_data};
iris::Packet p2{
iris::PacketType::DATA, iris::ChannelType::RELIABLE_ORDERED, test_data};
ASSERT_EQ(p1, p2);
}
TEST(packet, inequality)
{
iris::Packet p1{
iris::PacketType::HELLO,
iris::ChannelType::RELIABLE_ORDERED,
test_data};
iris::Packet p2{
iris::PacketType::DATA, iris::ChannelType::RELIABLE_ORDERED, test_data};
ASSERT_NE(p1, p2);
}