summaryrefslogtreecommitdiff
path: root/tests/pke-test-font.cpp
blob: 620715d806c55cd7c3374bc36f13eaf1166bcc18 (plain)
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-font.hpp"

#include "asset-manager.hpp"
#include "ecs.hpp"
#include "font.hpp"
#include "pk.h"
#include "pke-test-stubs.h"
#include "pke-test-types.h"
#include "thread-pool.hpp"

static pk_membucket *bkt;

void pke_test_font_setup() {
	pke_test_stub_init_vulkan();
	bkt = pk_mem_bucket_create("pke_test_font", PK_MEM_DEFAULT_BUCKET_SIZE, PK_MEMBUCKET_FLAG_NONE);
	pk_mem_bucket_set_client_mem_bucket(bkt);
	pk_ev_init(bkt);
	PkeThreads_Init();
	AM_Init();
	ECS_Init();
	FontType_Init();
}

void pke_test_font_teardown() {
	FontType_Teardown();
	ECS_Teardown();
	AM_Teardown();
	PkeThreads_Teardown();
	pk_ev_teardown();
	pk_mem_bucket_destroy(bkt);
	pk_mem_bucket_set_client_mem_bucket(nullptr);
	bkt = nullptr;
	pke_test_stub_teardown_vulkan();
}

/* Ensure the font exists
 */
int pke_test_font_001() {
	int err_index = 0;

	FontType *ft = FontType_Get(FontTypeIndex{0});
	PKE_TEST_ASSERT(ft != nullptr, err_index);
	PKE_TEST_ASSERT(ft->index_ft == FontTypeIndex{0}, err_index);

	return 0;
}

/* Ensure we can have more than one FontRender
 */
int pke_test_font_002() {
	int err_index = 0;
	FontTypeIndex fti{0};
	FontTypeRender handle_001{};
	FontTypeRender handle_002{};
	FontRenderSettings frs{};

	handle_001 = FontType_AddStringRender(fti, std::move(cstring_to_pk_cstr("string one")), &frs);

	PKE_TEST_ASSERT(handle_001.index_ft == FontTypeIndex{0}, err_index);
	PKE_TEST_ASSERT(handle_001.handle_fr.b == 0u, err_index);
	PKE_TEST_ASSERT(handle_001.handle_fr.i == 0u, err_index);

	handle_002 = FontType_AddStringRender(fti, std::move(cstring_to_pk_cstr("string two")), &frs);

	PKE_TEST_ASSERT(handle_002.index_ft == FontTypeIndex{0}, err_index);
	PKE_TEST_ASSERT(handle_002.handle_fr.b == 0u, err_index);
	PKE_TEST_ASSERT(handle_002.handle_fr.i == 1u, err_index);

	return 0;
}

/* Ensure we can have a lot of FontRenders
 */
int pke_test_font_003() {
	unsigned short u;
	const unsigned short count = 96;
	FontTypeIndex fti{0};
	FontTypeRender handles[count];
	FontRenderSettings frs{};

	for (u = 0; u < count; ++u) {
		handles[u].index_ft = FontTypeIndex{0};
		handles[u].handle_fr = {0,0};
	}

	for (u = 0; u < count; ++u) {
		char *s = (char*)malloc(64);
		snprintf(s, 1024, "%s - %u", "test", u);
		handles[u] = FontType_AddStringRender(fti, std::move(cstring_to_pk_cstr(s)), &frs);
		PK_TEST_ASSERT_EQ_RET((FontTypeIndex_T)FontTypeIndex{0}, (FontTypeIndex_T)handles[u].index_ft);
		PK_TEST_ASSERT_EQ_RET(floor(u / (float)PK_BKT_ARR_HANDLE_I_MAX), handles[u].handle_fr.b);
		PK_TEST_ASSERT_EQ_RET(u % PK_BKT_ARR_HANDLE_I_MAX, handles[u].handle_fr.i);
	}

	return 0;
}

struct pk_test_group *pke_test_font_get_group() {
	static const uint64_t test_count = 3;
	static struct pk_test tests[test_count] = {
		{
			.title = "test 001",
			.func = pke_test_font_001,
			.expected_result = 0,
		},
		{
			.title = "test 002",
			.func = pke_test_font_002,
			.expected_result = 0,
		},
		{
			.title = "test 003",
			.func = pke_test_font_003,
			.expected_result = 0,
		},
	};
	static struct pk_test_group group = {};
	group.title = "font test";
	group.test_setup = pke_test_font_setup;
	group.test_teardown = pke_test_font_teardown;
	group.n_tests = test_count;
	group.tests = &tests[0];

	return &group;
}