1 | #include <gtest/gtest.h> |
2 | |
3 | #include <base/system.h> |
4 | #include <engine/shared/snapshot.h> |
5 | #include <game/generated/protocol.h> |
6 | |
7 | TEST(Snapshot, CrcOneInt) |
8 | { |
9 | CSnapshotBuilder Builder; |
10 | Builder.Init(); |
11 | |
12 | CNetObj_Flag Flag; |
13 | void *pItem = Builder.NewItem(Type: CNetObj_Flag::ms_MsgId, Id: 0, Size: sizeof(Flag)); |
14 | ASSERT_FALSE(pItem == nullptr); |
15 | Flag.m_X = 4; |
16 | Flag.m_Y = 0; |
17 | Flag.m_Team = 0; |
18 | mem_copy(dest: pItem, source: &Flag, size: sizeof(Flag)); |
19 | |
20 | char aData[CSnapshot::MAX_SIZE]; |
21 | CSnapshot *pSnapshot = (CSnapshot *)aData; |
22 | Builder.Finish(pSnapdata: pSnapshot); |
23 | |
24 | ASSERT_EQ(pSnapshot->Crc(), 4); |
25 | } |
26 | |
27 | TEST(Snapshot, CrcTwoInts) |
28 | { |
29 | CSnapshotBuilder Builder; |
30 | Builder.Init(); |
31 | |
32 | CNetObj_Flag Flag; |
33 | void *pItem = Builder.NewItem(Type: CNetObj_Flag::ms_MsgId, Id: 0, Size: sizeof(Flag)); |
34 | ASSERT_FALSE(pItem == nullptr); |
35 | Flag.m_X = 1; |
36 | Flag.m_Y = 1; |
37 | Flag.m_Team = 0; |
38 | mem_copy(dest: pItem, source: &Flag, size: sizeof(Flag)); |
39 | |
40 | char aData[CSnapshot::MAX_SIZE]; |
41 | CSnapshot *pSnapshot = (CSnapshot *)aData; |
42 | Builder.Finish(pSnapdata: pSnapshot); |
43 | |
44 | ASSERT_EQ(pSnapshot->Crc(), 2); |
45 | } |
46 | |
47 | TEST(Snapshot, CrcBiggerInts) |
48 | { |
49 | CSnapshotBuilder Builder; |
50 | Builder.Init(); |
51 | |
52 | CNetObj_Flag Flag; |
53 | void *pItem = Builder.NewItem(Type: CNetObj_Flag::ms_MsgId, Id: 0, Size: sizeof(Flag)); |
54 | ASSERT_FALSE(pItem == nullptr); |
55 | Flag.m_X = 99999999; |
56 | Flag.m_Y = 1; |
57 | Flag.m_Team = 1; |
58 | mem_copy(dest: pItem, source: &Flag, size: sizeof(Flag)); |
59 | |
60 | char aData[CSnapshot::MAX_SIZE]; |
61 | CSnapshot *pSnapshot = (CSnapshot *)aData; |
62 | Builder.Finish(pSnapdata: pSnapshot); |
63 | |
64 | ASSERT_EQ(pSnapshot->Crc(), 100000001); |
65 | } |
66 | |
67 | TEST(Snapshot, CrcOverflow) |
68 | { |
69 | CSnapshotBuilder Builder; |
70 | Builder.Init(); |
71 | |
72 | CNetObj_Flag Flag; |
73 | void *pItem = Builder.NewItem(Type: CNetObj_Flag::ms_MsgId, Id: 0, Size: sizeof(Flag)); |
74 | ASSERT_FALSE(pItem == nullptr); |
75 | Flag.m_X = 0xFFFFFFFF; |
76 | Flag.m_Y = 1; |
77 | Flag.m_Team = 1; |
78 | mem_copy(dest: pItem, source: &Flag, size: sizeof(Flag)); |
79 | |
80 | char aData[CSnapshot::MAX_SIZE]; |
81 | CSnapshot *pSnapshot = (CSnapshot *)aData; |
82 | Builder.Finish(pSnapdata: pSnapshot); |
83 | |
84 | ASSERT_EQ(pSnapshot->Crc(), 1); |
85 | } |
86 | |