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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
#include "./pke-test-serialization.h"
#include "pk.h"
#include "serialization-component.hpp"
#include "serialization.hpp"
#include <cstring>
#include <sstream>
pk_membucket *bkt;
const char *const test_001_str = R"VOGON(:PKFB:
:0:
InstPos:00000000!00000000
Position:0.000000;1.000000;2.000000
Rotation:7.000000;8.000000;9.000000;6.000000
Scale:5.000000;4.000000;3.000000
:PKFE:
)VOGON";
int pke_test_serialization_001() {
int64_t err_index = 0, i;
srlztn_serialize_helper *h;
std::stringstream ss;
try {
bkt = pk_bucket_create("pke_test_serialization", PK_DEFAULT_BUCKET_SIZE, false);
h = pke_serialize_init(bkt);
glm::vec3 pos = glm::vec3(0,1,2);
glm::quat rot = glm::quat(6,7,8,9);
glm::vec3 scale = glm::vec3(5,4,3);
pke_serialize_inst_pos(h, pos, rot, scale);
pke_serialize_scene_to_stream(ss, h);
PKE_TEST_ASSERT(h->bkt == bkt, err_index);
PKE_TEST_ASSERT(h->kvp_containers.bkt == bkt, err_index);
PKE_TEST_ASSERT(h->kvp_containers.next == 1, err_index);
PKE_TEST_ASSERT(h->kvp_containers[0].child_handles.next == 0, err_index);
PKE_TEST_ASSERT(h->kvp_containers[0].arr.next == 3, err_index);
for (i = 0; i < 3; ++i) {
// 6,9,12
PKE_TEST_ASSERT(h->kvp_containers[0].arr[i].key != nullptr, err_index);
PKE_TEST_ASSERT(h->kvp_containers[0].arr[i].val != nullptr, err_index);
PKE_TEST_ASSERT(h->kvp_containers[0].arr[i].end != nullptr, err_index);
}
std::string s = ss.str();
// 15
PKE_TEST_ASSERT(strstr(test_001_str, s.c_str()) != nullptr, err_index);
pke_serialize_teardown(h);
} catch (const std::exception &ex) {
pk_bucket_destroy(bkt);
throw;
}
pk_bucket_destroy(bkt);
return 0;
}
int pke_test_deserialization_101() {
int64_t err_index = 0, i;
srlztn_deserialize_helper *h;
std::stringstream ss(test_001_str);
try {
bkt = pk_bucket_create("pke_test_serialization", PK_DEFAULT_BUCKET_SIZE, false);
h = pke_deserialize_init(bkt);
pke_deserialize_scene_from_stream(ss, h);
PKE_TEST_ASSERT(h->bkt == bkt, err_index);
PKE_TEST_ASSERT(h->kvp_containers.bkt == bkt, err_index);
PKE_TEST_ASSERT(h->kvp_containers.next == 1, err_index);
PKE_TEST_ASSERT(h->kvp_containers[0].child_handles.next == 0, err_index);
PKE_TEST_ASSERT(h->kvp_containers[0].arr.next == 3, err_index);
for (i = 0; i < 3; ++i) {
// 6,9,12
PKE_TEST_ASSERT(h->kvp_containers[0].arr[i].key != nullptr, err_index);
PKE_TEST_ASSERT(h->kvp_containers[0].arr[i].val != nullptr, err_index);
PKE_TEST_ASSERT(h->kvp_containers[0].arr[i].end != nullptr, err_index);
}
glm::vec3 pos;
glm::quat rot;
glm::vec3 scale;
pke_deserialize_inst_pos(h, &h->kvp_containers[0], pos, rot, scale);
// 15
PKE_TEST_ASSERT(pos == glm::vec3(0,1,2), err_index);
PKE_TEST_ASSERT(rot == glm::quat(6,7,8,9), err_index);
PKE_TEST_ASSERT(scale == glm::vec3(5,4,3), err_index);
pke_deserialize_teardown(h);
} catch (const std::exception &ex) {
pk_bucket_destroy(bkt);
throw;
}
pk_bucket_destroy(bkt);
return 0;
}
struct pke_test_group *pke_test_serialization_get_group() {
static const uint64_t test_count = 2;
static struct pke_test tests[test_count] = {
{
.title = "test 001",
.func = pke_test_serialization_001,
.expected_result = 0,
},
{
.title = "test 101",
.func = pke_test_deserialization_101,
.expected_result = 0,
},
};
static struct pke_test_group group = {};
group.title = "de/serialization";
group.n_tests = test_count;
group.tests = &tests[0];
return &group;
}
|