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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
|
#include "./pke-test-serialization.h"
#include "asset-manager.hpp"
#include "font.hpp"
#include "game-settings.hpp"
#include "camera.hpp"
#include "ecs.hpp"
#include "physics.hpp"
#include "pk.h"
#include "scene.hpp"
#include "serialization-camera.hpp"
#include "serialization-component.hpp"
#include "serialization.hpp"
#include "static-ui.hpp"
#include "thread-pool.hpp"
#include <cstring>
#include <sstream>
pk_membucket *bkt = nullptr;
const char *test_scene_name = "srlztn_test_scene";
pke_scene *test_scene = nullptr;
FontType *ft;
#define FAKE_UUID_GEN(oct) { .uuid = { oct,oct,oct,oct,oct,oct,oct,oct,oct,oct,oct,oct,oct,oct,oct,oct } }
const pk_uuid uuid_n[] = {
FAKE_UUID_GEN(0x00),
FAKE_UUID_GEN(0x01),
FAKE_UUID_GEN(0x02),
FAKE_UUID_GEN(0x03),
FAKE_UUID_GEN(0x04),
FAKE_UUID_GEN(0x05),
FAKE_UUID_GEN(0x06),
FAKE_UUID_GEN(0x07),
FAKE_UUID_GEN(0x08),
FAKE_UUID_GEN(0x09),
FAKE_UUID_GEN(0x0a),
FAKE_UUID_GEN(0x0b),
FAKE_UUID_GEN(0x0c),
FAKE_UUID_GEN(0x0d),
FAKE_UUID_GEN(0x0e),
FAKE_UUID_GEN(0x0f),
};
const pk_uuid uuid_17 = FAKE_UUID_GEN(0x11);
// const pk_uuid uuid_34 = FAKE_UUID_GEN(0x22);
void pke_test_serialization_spinup() {
pkeSettings.isSimulationPaused = true;
Physics_Init();
PkeThreads_Init();
AM_Init();
ECS_Init();
pke_ui_init();
PkeCamera_Init();
FontType_Init();
pke_scene_master_init();
test_scene = pke_scene_create(test_scene_name);
FontTypeIndex fti;
FontType *ft = FontType_GetFonts(fti);
assert(fti > FontTypeIndex{0});
ft->uuid = uuid_17;
};
void pke_test_serialization_teardown() {
// pke_scene_remove(test_scene->scene_handle); // TODO this doesn't work?
test_scene = nullptr;
pke_scene_master_teardown();
FontType_Teardown();
PkeCamera_Teardown();
pke_ui_teardown();
ECS_Teardown();
AM_Teardown();
PkeThreads_Teardown();
Physics_Teardown();
pk_memory_teardown_all();
bkt = nullptr;
};
int pke_test_serialization_999() {
int64_t err_index = 0;
pke_kve_container kvec{};
pke_kve kve{};
const pk_handle zed_handle = {0,0};
PKE_TEST_ASSERT(kvec.srlztn_handle == zed_handle, err_index);
PKE_TEST_ASSERT(kvec.type_code.length == 0, err_index);
PKE_TEST_ASSERT(kvec.type_code.reserved == 0, err_index);
PKE_TEST_ASSERT(kvec.type_code.val == nullptr, err_index);
PKE_TEST_ASSERT(kvec.bkt == nullptr, err_index);
// 6
PKE_TEST_ASSERT(kvec.child_handles.next == 0, err_index);
PKE_TEST_ASSERT(kvec.child_handles.reserved == 0, err_index);
PKE_TEST_ASSERT(kvec.child_handles.stride == sizeof(pk_handle), err_index);
PKE_TEST_ASSERT(kvec.child_handles.alignment == alignof(pk_handle), err_index);
PKE_TEST_ASSERT(kvec.child_handles.bkt == nullptr, err_index);
PKE_TEST_ASSERT(kvec.child_handles.data == nullptr, err_index);
// 12
PKE_TEST_ASSERT(kvec.children.next == 0, err_index);
PKE_TEST_ASSERT(kvec.children.reserved == 0, err_index);
PKE_TEST_ASSERT(kvec.children.stride == sizeof(pke_kve_container*), err_index);
PKE_TEST_ASSERT(kvec.children.alignment == alignof(pke_kve_container*), err_index);
PKE_TEST_ASSERT(kvec.children.bkt == nullptr, err_index);
PKE_TEST_ASSERT(kvec.children.data == nullptr, err_index);
// 18
PKE_TEST_ASSERT(kvec.arr.next == 0, err_index);
PKE_TEST_ASSERT(kvec.arr.reserved == 0, err_index);
PKE_TEST_ASSERT(kvec.arr.stride == sizeof(pke_kve), err_index);
PKE_TEST_ASSERT(kvec.arr.alignment == alignof(pke_kve), err_index);
PKE_TEST_ASSERT(kvec.arr.bkt == nullptr, err_index);
PKE_TEST_ASSERT(kvec.arr.data == nullptr, err_index);
// 24
PKE_TEST_ASSERT(kve.key == nullptr, err_index);
PKE_TEST_ASSERT(kve.val == nullptr, err_index);
PKE_TEST_ASSERT(kve.end == nullptr, err_index);
return 0;
}
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;
}
const char *const test_002_str = R"VOGON(:PKFB:
:0:
InstPos:00000000!00000000
Rotation:0.000000;0.000000;0.000000;1.000000
Instance:00000000!00000001
ChildId:00000000!00000000
UUID:01010101-0101-0101-0101-010101010101
Mass:1.000000
CollisionLayer:0x0000000000000001
CollisionMask:0x0000000000000001
InstPos:00000000!00000002
Position:0.000000;-10.000000;-10.000000
Rotation:0.000000;0.000000;0.000000;1.000000
Scale:5.000000;4.000000;3.000000
Camera:00000000!00000003
ChildId:00000000!00000002
UUID:02020202-0202-0202-0202-020202020202
Type:0x01
Orientation:0x01
TargetUUID:01010101-0101-0101-0101-010101010101
IsPrimary:1
:PKFE:)VOGON";
int pke_test_serialization_002() {
int64_t err_index = 0;
uint32_t i, k;
srlztn_serialize_helper *h = nullptr;
pke_kve *kve = nullptr;
std::stringstream ss;
try {
bkt = pk_bucket_create("pke_test_serialization", PK_DEFAULT_BUCKET_SIZE, false);
h = pke_serialize_init(bkt);
// reminder that 'targeting' moves and rotates the camera, so we shouldn't see these values in the output
InstPos cam_inst_pos{};
cam_inst_pos.posRot.setIdentity();
cam_inst_pos.posRot.setOrigin(btVector3(0,0,0));
cam_inst_pos.posRot.setRotation(btQuaternion(0.f,0.f,0.f,1));
cam_inst_pos.scale = btVector3(1,1,1);
cam_inst_pos.mass = 1.f;
Entity_Base *target_ent = ECS_CreateGenericEntity();
CompInstance *target_ent_comp_inst = ECS_CreateInstance(target_ent, uuid_n[1], nullptr, &cam_inst_pos);
cam_inst_pos.scale = btVector3(5,4,3);
PkeCamera &cam = PkeCamera_Register(uuid_n[2], cam_inst_pos);
cam.type = PKE_CAMERA_TYPE_PERSPECTIVE;
cam.view = PKE_CAMERA_VIEW_TARGET;
PkeCamera_SetPrimary(cam.camHandle);
PkeCamera_TargetInstance(cam.camHandle, target_ent_comp_inst);
pke_serialize_scene(h);
pke_serialize_scene_to_stream(ss, h);
std::string s = ss.str();
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 == 4, err_index);
// instpos
PKE_TEST_ASSERT(h->kvp_containers[0].child_handles.next == 0, err_index);
PKE_TEST_ASSERT(h->kvp_containers[0].arr.next == 1, err_index);
// instance
PKE_TEST_ASSERT(h->kvp_containers[1].child_handles.next == 1, err_index);
PKE_TEST_ASSERT(h->kvp_containers[1].arr.next == 4, err_index);
// instpos
PKE_TEST_ASSERT(h->kvp_containers[2].child_handles.next == 0, err_index);
PKE_TEST_ASSERT(h->kvp_containers[2].arr.next == 3, err_index);
// camera
PKE_TEST_ASSERT(h->kvp_containers[3].child_handles.next == 1, err_index);
PKE_TEST_ASSERT(h->kvp_containers[3].arr.next == 5, err_index);
// 12
for (k = 0; k < h->kvp_containers.next; ++k) {
for (i = 0; i < h->kvp_containers[k].arr.next; ++i) {
// 12 + (3 * (1 + 4 + 3 + 5))
kve = &h->kvp_containers[k].arr[i];
PKE_TEST_ASSERT(kve->key != nullptr, err_index);
PKE_TEST_ASSERT(kve->val != nullptr, err_index);
PKE_TEST_ASSERT(kve->end != nullptr, err_index);
}
}
// 51
PKE_TEST_ASSERT(strstr(test_002_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_102() {
int64_t err_index = 0;
uint32_t i, k;
pke_kve *kve;
srlztn_deserialize_helper *h;
std::stringstream ss(test_002_str);
try {
bkt = pk_bucket_create("pke_test_serialization", PK_DEFAULT_BUCKET_SIZE, false);
h = pke_deserialize_init(bkt);
h->scene = test_scene;
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 == 4, err_index);
PKE_TEST_ASSERT(h->kvp_containers[0].child_handles.next == 0, err_index);
PKE_TEST_ASSERT(h->kvp_containers[1].child_handles.next == 1, err_index);
PKE_TEST_ASSERT(h->kvp_containers[2].child_handles.next == 0, err_index);
PKE_TEST_ASSERT(h->kvp_containers[3].child_handles.next == 1, err_index);
PKE_TEST_ASSERT(h->kvp_containers[0].arr.next == 1, err_index);
PKE_TEST_ASSERT(h->kvp_containers[1].arr.next == 4, err_index);
PKE_TEST_ASSERT(h->kvp_containers[2].arr.next == 3, err_index);
PKE_TEST_ASSERT(h->kvp_containers[3].arr.next == 5, err_index);
// 12
for (k = 0; k < h->kvp_containers.next; ++k) {
for (i = 0; i < h->kvp_containers[k].arr.next; ++i) {
// 12 + (3 * (1 + 4 + 3 + 5))
kve = &h->kvp_containers[k].arr[i];
PKE_TEST_ASSERT(kve->key != nullptr, err_index);
PKE_TEST_ASSERT(kve->val != nullptr, err_index);
PKE_TEST_ASSERT(kve->end != nullptr, err_index);
}
}
glm::vec3 pos = glm::vec3(0,0,0);
glm::quat rot = glm::quat(1,0,0,0);
glm::vec3 scale = glm::vec3(1,1,1);
pke_deserialize_inst_pos(h, &h->kvp_containers[0], pos, rot, scale);
// 51
PKE_TEST_ASSERT(pos == glm::vec3(0,0,0), err_index);
PKE_TEST_ASSERT(rot == glm::quat(1,0,0,0), err_index);
PKE_TEST_ASSERT(scale == glm::vec3(1,1,1), err_index);
pke_deserialize_inst_pos(h, &h->kvp_containers[2], pos, rot, scale);
// 54
PKE_TEST_ASSERT(pos == glm::vec3(0,-10,-10), err_index);
PKE_TEST_ASSERT(rot == glm::quat(1,0,0,0), err_index);
PKE_TEST_ASSERT(scale == glm::vec3(5,4,3), err_index);
pke_deserialize_scene(h);
pk_handle_item_index_T item_index;
PkeCamera *des_cam = &PkeCamera_GetCameras(0, item_index)[0];
// 57
PKE_TEST_ASSERT(des_cam != nullptr, err_index);
PKE_TEST_ASSERT(des_cam->uuid == uuid_n[2], err_index);
PKE_TEST_ASSERT(des_cam->type == PKE_CAMERA_TYPE_PERSPECTIVE, err_index);
PKE_TEST_ASSERT(des_cam->view == PKE_CAMERA_VIEW_TARGET, err_index);
PKE_TEST_ASSERT(des_cam->phys.target_inst_uuid == uuid_n[1], err_index);
PKE_TEST_ASSERT(des_cam->isPrimary == true, err_index);
pke_deserialize_teardown(h);
} catch (const std::exception &ex) {
pk_bucket_destroy(bkt);
throw;
}
pk_bucket_destroy(bkt);
return 0;
}
const char *const test_003_str = R"VOGON(:PKFB:
:0:
FontRenderSettings:00000000!00000000
CharScale:1.000000
LineHeightScale:1.000000
CharSpacingScale:1.000000
SurfaceAreaSize:250;250
SurfaceAreaPos:0;0
SurfaceAreaFlags:0x03
FontRender:00000000!00000001
ChildId:00000000!00000000
UUID:01010101-0101-0101-0101-010101010101
FontTypeUUID:11111111-1111-1111-1111-111111111111
TextBegin::
asdf
:MULTILINE_END:
UIBoxTypeData:00000000!00000002
FontRenderUUID:01010101-0101-0101-0101-010101010101
UIBox:00000000!00000003
ChildId:00000000!00000002
UUID:02020202-0202-0202-0202-020202020202
Flags:0x84
PosTopLeft:0.100000;0.100000
MaxSize:0.800000;0.800000
Type:0x28
Layer:0x00
:PKFE:)VOGON";
int pke_test_serialization_003() {
int64_t err_index = 0;
uint32_t i, k;
srlztn_serialize_helper *h = nullptr;
pke_kve *kve = nullptr;
std::stringstream ss;
try {
bkt = pk_bucket_create("pke_test_serialization", PK_DEFAULT_BUCKET_SIZE, false);
h = pke_serialize_init(bkt);
FontTypeIndex fti;
FontRenderSettings frs;
frs.char_scale = 1.0;
frs.char_spacing_scale = 1.0;
frs.line_height_scale = 1.0;
frs.surface_area_size = glm::ivec2(250, 250);
frs.surface_area_pos = glm::ivec2(0, 0);
frs.surface_area_type_flags = FONT_RENDER_SURFACE_AREA_TYPE_FLAGS_FLUID;
FontRenderHandle fr_handle = FontType_AddStringRender(FontType_GetFonts(fti)[0].index_ft, std::move(cstring_to_pk_cstr("asdf")), &frs, nullptr, uuid_n[1]);
pke_ui_box *ui_box = pke_ui_box_new_root(PKE_UI_BOX_TYPE_TEXT, uuid_n[2]);
ui_box->flags |= PKE_UI_BOX_FLAG_POSITION_TYPE_DYNAMIC;
ui_box->pos_top_left.x = 0.1;
ui_box->pos_top_left.y = 0.1;
ui_box->max_size.x = 0.8;
ui_box->max_size.y = 0.8;
ui_box->type_data->text.font_render_handle = fr_handle;
pke_serialize_scene(h);
pke_serialize_scene_to_stream(ss, h);
std::string s = ss.str();
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 == 4, err_index);
// FontRenderSettings
PKE_TEST_ASSERT(h->kvp_containers[0].child_handles.next == 0, err_index);
PKE_TEST_ASSERT(h->kvp_containers[0].arr.next == 6, err_index);
// FontRender
PKE_TEST_ASSERT(h->kvp_containers[1].child_handles.next == 1, err_index);
PKE_TEST_ASSERT(h->kvp_containers[1].arr.next == 3, err_index);
// ui box type text
PKE_TEST_ASSERT(h->kvp_containers[2].child_handles.next == 0, err_index);
PKE_TEST_ASSERT(h->kvp_containers[2].arr.next == 1, err_index);
// ui box
PKE_TEST_ASSERT(h->kvp_containers[3].child_handles.next == 1, err_index);
PKE_TEST_ASSERT(h->kvp_containers[3].arr.next == 6, err_index);
// 12
for (k = 0; k < h->kvp_containers.next; ++k) {
for (i = 0; i < h->kvp_containers[k].arr.next; ++i) {
// 12 + (3 * (6 + 3 + 1 + 6))
kve = &h->kvp_containers[k].arr[i];
PKE_TEST_ASSERT(kve->key != nullptr, err_index);
PKE_TEST_ASSERT(kve->val != nullptr, err_index);
PKE_TEST_ASSERT(kve->end != nullptr, err_index);
}
}
// 60
PKE_TEST_ASSERT(strstr(test_003_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_103() {
int64_t err_index = 0;
uint32_t i, k;
pke_kve *kve;
srlztn_deserialize_helper *h;
std::stringstream ss(test_003_str);
try {
bkt = pk_bucket_create("pke_test_serialization", PK_DEFAULT_BUCKET_SIZE, false);
h = pke_deserialize_init(bkt);
h->scene = test_scene;
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 == 4, err_index);
// FontRenderSettings
PKE_TEST_ASSERT(h->kvp_containers[0].child_handles.next == 0, err_index);
PKE_TEST_ASSERT(h->kvp_containers[0].arr.next == 6, err_index);
// FontRender
PKE_TEST_ASSERT(h->kvp_containers[1].child_handles.next == 1, err_index);
PKE_TEST_ASSERT(h->kvp_containers[1].arr.next == 3, err_index);
// ui box type text
PKE_TEST_ASSERT(h->kvp_containers[2].child_handles.next == 0, err_index);
PKE_TEST_ASSERT(h->kvp_containers[2].arr.next == 1, err_index);
// ui box
PKE_TEST_ASSERT(h->kvp_containers[3].child_handles.next == 1, err_index);
PKE_TEST_ASSERT(h->kvp_containers[3].arr.next == 6, err_index);
// 12
for (k = 0; k < h->kvp_containers.next; ++k) {
for (i = 0; i < h->kvp_containers[k].arr.next; ++i) {
// 12 + (3 * (6 + 3 + 1 + 6))
kve = &h->kvp_containers[k].arr[i];
PKE_TEST_ASSERT(kve->key != nullptr, err_index);
PKE_TEST_ASSERT(kve->val != nullptr, err_index);
PKE_TEST_ASSERT(kve->end != nullptr, err_index);
}
}
pke_deserialize_scene(h);
FontTypeIndex fti = FontTypeIndex{0};
FontType *fonts = FontType_GetFonts(fti);
// 60
PKE_TEST_ASSERT(fti > FontTypeIndex{0}, err_index);
PKE_TEST_ASSERT(fonts != nullptr, err_index);
PKE_TEST_ASSERT(fonts->h_render > FontRenderIndex{0}, err_index);
PKE_TEST_ASSERT(fonts->n_render > FontRenderIndex{0}, err_index);
FontRender *fr = &fonts[0].renders[0];
// 64
PKE_TEST_ASSERT(fr->settings.char_scale == 1.f, err_index);
PKE_TEST_ASSERT(fr->settings.line_height_scale == 1.f, err_index);
PKE_TEST_ASSERT(fr->settings.char_spacing_scale == 1.f, err_index);
PKE_TEST_ASSERT(fr->settings.surface_area_size == glm::ivec2(250,250), err_index);
PKE_TEST_ASSERT(fr->settings.surface_area_pos == glm::ivec2(0,0), err_index);
PKE_TEST_ASSERT(fr->settings.surface_area_type_flags == FONT_RENDER_SURFACE_AREA_TYPE_FLAGS_FLUID, err_index);
// 70
PKE_TEST_ASSERT(fr->uuid == uuid_n[1], err_index);
PKE_TEST_ASSERT(fr->text.val != nullptr, err_index);
PKE_TEST_ASSERT(fr->text.val[0] == 'a', err_index);
PKE_TEST_ASSERT(fr->text.val[1] == 's', err_index);
PKE_TEST_ASSERT(fr->text.val[2] == 'd', err_index);
PKE_TEST_ASSERT(fr->text.val[3] == 'f', err_index);
PKE_TEST_ASSERT(fr->text.val[4] == '\0', 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 = 7;
static struct pke_test tests[test_count] = {
{
.title = "test 999",
.func = pke_test_serialization_999,
.expected_result = 0,
},
{
.title = "test 001",
.func = pke_test_serialization_001,
.expected_result = 0,
},
{
.title = "test 101",
.func = pke_test_deserialization_101,
.expected_result = 0,
},
{
.title = "test 002",
.func = pke_test_serialization_002,
.expected_result = 0,
},
{
.title = "test 102",
.func = pke_test_deserialization_102,
.expected_result = 0,
},
{
.title = "test 003",
.func = pke_test_serialization_003,
.expected_result = 0,
},
{
.title = "test 103",
.func = pke_test_deserialization_103,
.expected_result = 0,
},
};
static struct pke_test_group group = {};
group.title = "de/serialization";
group.group_setup = nullptr;
group.group_teardown = nullptr;
group.test_setup = pke_test_serialization_spinup;
group.test_teardown = pke_test_serialization_teardown;
group.n_tests = test_count;
group.tests = &tests[0];
return &group;
}
|