-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathserialize_track_status_request_message.cpp
More file actions
70 lines (57 loc) · 2.32 KB
/
Copy pathserialize_track_status_request_message.cpp
File metadata and controls
70 lines (57 loc) · 2.32 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
#include "test_serialization_utils.hpp"
#include "utilities.hpp"
#include <serialization/chunk.hpp>
#include <serialization/deserialization_impl.hpp>
#include <serialization/messages.hpp>
#include <serialization/serialization_impl.hpp>
using namespace rvn;
using namespace rvn::serialization;
void test1()
{
TrackStatusRequestMessage msg;
msg.trackNamespace_ = "h";
msg.trackName_ = "i";
ds::chunk c;
serialization::detail::serialize(c, msg);
// clang-format off
// [ 00001101 ] [ 00000100 ] [ 00000001 01101000 ] [ 00000001 01101001 ]
// (quic_msg_type: 0xD) (msglen = 4) (trackNameSpace) (trackName)
std::string expectedSerializationString = "[00001101][00000100][00000001 01101000][00000001 01101001]";
// clang-format on
auto expectedSerialization = binary_string_to_vector(expectedSerializationString);
utils::ASSERT_LOG_THROW(c.size() == expectedSerialization.size(), "Size mismatch\n",
"Expected size: ", expectedSerialization.size(),
"\n", "Actual size: ", c.size(), "\n");
for (std::size_t i = 0; i < c.size(); i++)
utils::ASSERT_LOG_THROW(c[i] == expectedSerialization[i], "Mismatch at index: ", i,
"\n", "Expected: ", expectedSerialization[i],
"\n", "Actual: ", c[i], "\n");
ds::ChunkSpan span(c);
ControlMessageHeader header;
serialization::detail::deserialize(header, span);
utils::ASSERT_LOG_THROW(header.messageType_ == MoQtMessageType::TRACK_STATUS_REQUEST,
"Message type mismatch\n", "Expected: ",
utils::to_underlying(MoQtMessageType::TRACK_STATUS_REQUEST), "\n",
"Actual: ", utils::to_underlying(header.messageType_), "\n");
TrackStatusRequestMessage deserializedMsg;
serialization::detail::deserialize(deserializedMsg, span);
utils::ASSERT_LOG_THROW(msg == deserializedMsg, "Deserialization failed\n",
"Expected: ", msg, "\n", "Actual: ", deserializedMsg, "\n");
}
void tests()
{
try
{
test1();
}
catch (const std::exception& e)
{
std::cerr << "Test failed\n";
std::cerr << e.what() << std::endl;
}
}
int main()
{
tests();
return 0;
}