-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserialization_tests.cpp
More file actions
57 lines (44 loc) · 1.39 KB
/
serialization_tests.cpp
File metadata and controls
57 lines (44 loc) · 1.39 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
#include "tcp.hpp"
#include <cassert>
#define BUFFER_SIZE 1024
#define PORT 8080
TcpServer server(PORT, TcpMode::SERVER);
void test_round_trip(const Message &original)
{
char buffer[BUFFER_SIZE] = {0};
bool success = serialize(original, buffer);
Message reconstructed = deserialize(buffer);
assert(reconstructed.type == original.type);
assert(reconstructed.file_name == original.file_name);
assert(reconstructed.data == original.data);
std::cout << "Round-trip test passed for type " << static_cast<int>(original.type) << "\n";
}
void test_client_push_basic() {
Message msg{ MessageType::CLIENT_PUSH, "test.txt", "hello world" };
test_round_trip(msg);
}
void test_server_pull_basic() {
Message msg{ MessageType::SERVER_PULL, "file1.bin", "12345" };
test_round_trip(msg);
}
void test_empty_fields() {
Message msg{ MessageType::CLIENT_PUSH, "", "" };
test_round_trip(msg);
}
void test_client_pull_no_payload() {
Message msg{ MessageType::CLIENT_PULL, "", "" };
test_round_trip(msg);
}
void test_server_push_no_payload() {
Message msg{ MessageType::SERVER_PUSH, "", "" };
test_round_trip(msg);
}
int main() {
test_client_push_basic();
test_server_pull_basic();
test_empty_fields();
test_client_pull_no_payload();
test_server_push_no_payload();
std::cout << "🎉 All round-trip serialization tests passed.\n";
return 0;
}