summaryrefslogtreecommitdiff
path: root/tests/pke-at-test-data-parser.cpp
blob: a6a42cb00d6bfeb7d9fa3c60bbbda922caa648b3 (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
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

#include "pke-at-test-data-parser.h"
#include "../src/pke-at-data-parser.hpp"
#include "../data/service_types_json.h"
#include "../data/upcoming_plans_json.h"
#include "../data/plan_items_json.h"
#include "pke/pk.h"

static pk_membucket *bkt = nullptr;

void parse_test_init() {
	bkt = pk_mem_bucket_create("pke-at-test-data-parser", PK_MEM_DEFAULT_BUCKET_SIZE, PK_MEMBUCKET_FLAG_NONE);
	pk_mem_bucket_set_client_mem_bucket(bkt);
}
void parse_test_teardown() {
	pk_mem_bucket_set_client_mem_bucket(nullptr);
	pk_mem_bucket_destroy(bkt);
	bkt = nullptr;
}

int parse_test_001() {
	pk_arr_t<di_service_type> service_types = pke_at_data_parser_service_types((char*)data_service_types_json);

	PK_TEST_ASSERT_EQ_RET(6, service_types.next);

	PK_TEST_ASSERT_EQ_RET(291481,  service_types[0].details.id.id_long);
	PK_TEST_ASSERT_EQ_RET(291539,  service_types[1].details.id.id_long);
	PK_TEST_ASSERT_EQ_RET(647998,  service_types[2].details.id.id_long);
	PK_TEST_ASSERT_EQ_RET(1164771, service_types[3].details.id.id_long);
	PK_TEST_ASSERT_EQ_RET(1572501, service_types[4].details.id.id_long);
	PK_TEST_ASSERT_EQ_RET(1627193, service_types[5].details.id.id_long);

	PK_TEST_ASSERT_EQ_RET(0, strcmp("Decatur ",           service_types[0].details.name.val));
	PK_TEST_ASSERT_EQ_RET(0, strcmp("Berne",              service_types[1].details.name.val));
	PK_TEST_ASSERT_EQ_RET(0, strcmp("High School",        service_types[2].details.name.val));
	PK_TEST_ASSERT_EQ_RET(0, strcmp("worship night",      service_types[3].details.name.val));
	PK_TEST_ASSERT_EQ_RET(0, strcmp("Security - Decatur", service_types[4].details.name.val));
	PK_TEST_ASSERT_EQ_RET(0, strcmp("Project Worship",    service_types[5].details.name.val));

	return 0;
}

int parse_test_002() {
	pk_arr_t<di_plan> plans = pke_at_data_parser_plans((char*)data_upcoming_plans_json);

	PK_TEST_ASSERT_EQ_RET(12, plans.next);

	PK_TEST_ASSERT_EQ_RET(82934314, plans[0].details.id.id_long);
	PK_TEST_ASSERT_EQ_RET(82934328, plans[1].details.id.id_long);
	PK_TEST_ASSERT_EQ_RET(82934359, plans[2].details.id.id_long);
	PK_TEST_ASSERT_EQ_RET(82934399, plans[3].details.id.id_long);
	PK_TEST_ASSERT_EQ_RET(82934414, plans[4].details.id.id_long);
	PK_TEST_ASSERT_EQ_RET(82934432, plans[5].details.id.id_long);
	PK_TEST_ASSERT_EQ_RET(82934448, plans[6].details.id.id_long);
	PK_TEST_ASSERT_EQ_RET(82934561, plans[7].details.id.id_long);
	PK_TEST_ASSERT_EQ_RET(82934598, plans[8].details.id.id_long);
	PK_TEST_ASSERT_EQ_RET(82934630, plans[9].details.id.id_long);
	PK_TEST_ASSERT_EQ_RET(82934779, plans[10].details.id.id_long);
	PK_TEST_ASSERT_EQ_RET(82934900, plans[11].details.id.id_long);

	// 1760730718
	PK_TEST_ASSERT_NEQ_RET(0, plans[0].details.date);
	PK_TEST_ASSERT_NEQ_RET(0, plans[1].details.date);
	PK_TEST_ASSERT_NEQ_RET(0, plans[2].details.date);
	PK_TEST_ASSERT_NEQ_RET(0, plans[3].details.date);
	PK_TEST_ASSERT_NEQ_RET(0, plans[4].details.date);
	PK_TEST_ASSERT_NEQ_RET(0, plans[5].details.date);
	PK_TEST_ASSERT_NEQ_RET(0, plans[6].details.date);
	PK_TEST_ASSERT_NEQ_RET(0, plans[7].details.date);
	PK_TEST_ASSERT_NEQ_RET(0, plans[8].details.date);
	PK_TEST_ASSERT_NEQ_RET(0, plans[9].details.date);
	PK_TEST_ASSERT_NEQ_RET(0, plans[10].details.date);
	PK_TEST_ASSERT_NEQ_RET(0, plans[11].details.date);
	// after "today"
	PK_TEST_ASSERT_EQ_RET(true, plans[0].details.date > 1760730718);
	PK_TEST_ASSERT_EQ_RET(true, plans[1].details.date > 1760730718);
	PK_TEST_ASSERT_EQ_RET(true, plans[2].details.date > 1760730718);
	PK_TEST_ASSERT_EQ_RET(true, plans[3].details.date > 1760730718);
	PK_TEST_ASSERT_EQ_RET(true, plans[4].details.date > 1760730718);
	PK_TEST_ASSERT_EQ_RET(true, plans[5].details.date > 1760730718);
	PK_TEST_ASSERT_EQ_RET(true, plans[6].details.date > 1760730718);
	PK_TEST_ASSERT_EQ_RET(true, plans[7].details.date > 1760730718);
	PK_TEST_ASSERT_EQ_RET(true, plans[8].details.date > 1760730718);
	PK_TEST_ASSERT_EQ_RET(true, plans[9].details.date > 1760730718);
	PK_TEST_ASSERT_EQ_RET(true, plans[10].details.date > 1760730718);
	PK_TEST_ASSERT_EQ_RET(true, plans[11].details.date > 1760730718);
	// before the new year
	PK_TEST_ASSERT_EQ_RET(true, plans[0].details.date < 1767225600);
	PK_TEST_ASSERT_EQ_RET(true, plans[1].details.date < 1767225600);
	PK_TEST_ASSERT_EQ_RET(true, plans[2].details.date < 1767225600);
	PK_TEST_ASSERT_EQ_RET(true, plans[3].details.date < 1767225600);
	PK_TEST_ASSERT_EQ_RET(true, plans[4].details.date < 1767225600);
	PK_TEST_ASSERT_EQ_RET(true, plans[5].details.date < 1767225600);
	PK_TEST_ASSERT_EQ_RET(true, plans[6].details.date < 1767225600);
	PK_TEST_ASSERT_EQ_RET(true, plans[7].details.date < 1767225600);
	PK_TEST_ASSERT_EQ_RET(true, plans[8].details.date < 1767225600);
	PK_TEST_ASSERT_EQ_RET(true, plans[9].details.date < 1767225600);
	PK_TEST_ASSERT_EQ_RET(true, plans[10].details.date < 1767225600);
	PK_TEST_ASSERT_EQ_RET(true, plans[11].details.date < 1767225600);
	for (int i = 0; i < 10; ++i) {
		PK_TEST_ASSERT_EQ_RET(true, plans[i].details.date < plans[i+1].details.date);
	}

	PK_TEST_ASSERT_EQ_RET(0, strcmp("When Self-Love Is Selfish", plans[0].details.title.val));
	PK_TEST_ASSERT_EQ_RET(0, strcmp("Why Don’t I Feel Like Enough?", plans[1].details.title.val));
	PK_TEST_ASSERT_EQ_RET(0, strcmp("Why Doesn’t God Give Me What I Want?", plans[2].details.title.val));
	PK_TEST_ASSERT_EQ_RET(0, strcmp("The Problem With Perfectionism", plans[3].details.title.val));
	PK_TEST_ASSERT_EQ_RET(0, strcmp("Living for Jesus in a Culture of Compromise", plans[4].details.title.val));
	PK_TEST_ASSERT_EQ_RET(0, strcmp("When You’re Under Attack", plans[5].details.title.val));
	PK_TEST_ASSERT_EQ_RET(0, strcmp("Anxious Hearts, Fearless Faith", plans[6].details.title.val));
	PK_TEST_ASSERT_EQ_RET(0, strcmp("When It’s Hard to Obey", plans[7].details.title.val));
	PK_TEST_ASSERT_EQ_RET(0, strcmp("A Moment of Surrender", plans[8].details.title.val));
	PK_TEST_ASSERT_EQ_RET(0, strcmp("To Hell With Hesitation", plans[9].details.title.val));
	PK_TEST_ASSERT_EQ_RET(0, strcmp("Stand Alone", plans[10].details.title.val));
	PK_TEST_ASSERT_EQ_RET(nullptr, plans[11].details.title.val);

	PK_TEST_ASSERT_EQ_RET(0, strcmp("Almost True", plans[0].details.series_title.val));
	PK_TEST_ASSERT_EQ_RET(0, strcmp("Almost True", plans[1].details.series_title.val));
	PK_TEST_ASSERT_EQ_RET(0, strcmp("Almost True", plans[2].details.series_title.val));
	PK_TEST_ASSERT_EQ_RET(0, strcmp("Almost True", plans[3].details.series_title.val));
	PK_TEST_ASSERT_EQ_RET(0, strcmp("Unshakable", plans[4].details.series_title.val));
	PK_TEST_ASSERT_EQ_RET(0, strcmp("Unshakable", plans[5].details.series_title.val));
	PK_TEST_ASSERT_EQ_RET(0, strcmp("Unshakable", plans[6].details.series_title.val));
	PK_TEST_ASSERT_EQ_RET(0, strcmp("Holy Moments", plans[7].details.series_title.val));
	PK_TEST_ASSERT_EQ_RET(0, strcmp("Holy Moments", plans[8].details.series_title.val));
	PK_TEST_ASSERT_EQ_RET(0, strcmp("Holy Moments", plans[9].details.series_title.val));
	PK_TEST_ASSERT_EQ_RET(nullptr, plans[10].details.series_title.val);
	PK_TEST_ASSERT_EQ_RET(0, strcmp("Christmas Eve", plans[11].details.series_title.val));

	return 0;
}

int parse_test_003() {
	pk_arr_t<di_plan_item> items = pke_at_data_parser_plan_items((char*)data_plan_items_json);

	PK_TEST_ASSERT_EQ_RET(4, items.next);

	PK_TEST_ASSERT_EQ_RET(1116826609, items[0].details.id.id_long);
	PK_TEST_ASSERT_EQ_RET(1116826612, items[1].details.id.id_long);
	PK_TEST_ASSERT_EQ_RET(1116826614, items[2].details.id.id_long);
	PK_TEST_ASSERT_EQ_RET(1131208437, items[3].details.id.id_long);

	PK_TEST_ASSERT_EQ_RET(24030215, items[0].song.details.id.id_long);
	PK_TEST_ASSERT_EQ_RET(27793425, items[0].arrangement.details.id.id_long);
	PK_TEST_ASSERT_EQ_RET(44596256, items[0].key.details.id.id_long);

	PK_TEST_ASSERT_EQ_RET(22058189, items[1].song.details.id.id_long);
	PK_TEST_ASSERT_EQ_RET(25398725, items[1].arrangement.details.id.id_long);
	PK_TEST_ASSERT_EQ_RET(45863343, items[1].key.details.id.id_long);

	PK_TEST_ASSERT_EQ_RET(18743841, items[2].song.details.id.id_long);
	PK_TEST_ASSERT_EQ_RET(21448360, items[2].arrangement.details.id.id_long);
	PK_TEST_ASSERT_EQ_RET(29304181, items[2].key.details.id.id_long);

	PK_TEST_ASSERT_EQ_RET(12327928, items[3].song.details.id.id_long);
	PK_TEST_ASSERT_EQ_RET(13840808, items[3].arrangement.details.id.id_long);
	PK_TEST_ASSERT_EQ_RET(21251195, items[3].key.details.id.id_long);

	PK_TEST_ASSERT_EQ_RET(PKE_AT_KEY_INDEX_G, items[0].details.key);
	PK_TEST_ASSERT_EQ_RET(PKE_AT_KEY_INDEX_G, items[1].details.key);
	PK_TEST_ASSERT_EQ_RET(PKE_AT_KEY_INDEX_G, items[2].details.key);
	PK_TEST_ASSERT_EQ_RET(PKE_AT_KEY_INDEX_D, items[3].details.key);

	PK_TEST_ASSERT_EQ_RET(7, items[0].details.sequence);
	PK_TEST_ASSERT_EQ_RET(8, items[1].details.sequence);
	PK_TEST_ASSERT_EQ_RET(9, items[2].details.sequence);
	PK_TEST_ASSERT_EQ_RET(13, items[3].details.sequence);

	PK_TEST_ASSERT_EQ_RET(0, strcmp("This Is Our God",   items[0].song.details.title.val));
	PK_TEST_ASSERT_EQ_RET(0, strcmp("Egypt",             items[1].song.details.title.val));
	PK_TEST_ASSERT_EQ_RET(0, strcmp("Good Grace",        items[2].song.details.title.val));
	PK_TEST_ASSERT_EQ_RET(0, strcmp("My Heart Is Yours", items[3].song.details.title.val));
	PK_TEST_ASSERT_EQ_RET(7211413, items[0].song.details.ccli);
	PK_TEST_ASSERT_EQ_RET(7133348, items[1].song.details.ccli);
	PK_TEST_ASSERT_EQ_RET(7122177, items[2].song.details.ccli);
	PK_TEST_ASSERT_EQ_RET(7017788, items[3].song.details.ccli);

	PK_TEST_ASSERT_EQ_RET(0, strcmp("Phil Wickham",        items[0].arrangement.details.title.val));
	PK_TEST_ASSERT_EQ_RET(0, strcmp("Cory Asbury ",        items[1].arrangement.details.title.val));
	PK_TEST_ASSERT_EQ_RET(0, strcmp("Hillsong United",     items[2].arrangement.details.title.val));
	PK_TEST_ASSERT_EQ_RET(0, strcmp("Default Arrangement", items[3].arrangement.details.title.val));
	PK_TEST_ASSERT_EQ_RET(0, items[0].arrangement.details.beats_per_minute);
	PK_TEST_ASSERT_EQ_RET(75, items[1].arrangement.details.beats_per_minute);
	PK_TEST_ASSERT_EQ_RET(73, items[2].arrangement.details.beats_per_minute);
	PK_TEST_ASSERT_EQ_RET(0, items[3].arrangement.details.beats_per_minute);
	PK_TEST_ASSERT_EQ_RET(0, items[0].arrangement.details.beats_per_bar);
	PK_TEST_ASSERT_EQ_RET(4, items[1].arrangement.details.beats_per_bar);
	PK_TEST_ASSERT_EQ_RET(4, items[2].arrangement.details.beats_per_bar);
	PK_TEST_ASSERT_EQ_RET(0, items[3].arrangement.details.beats_per_bar);
	PK_TEST_ASSERT_EQ_RET(PKE_AT_KEY_INDEX_C, items[0].arrangement.details.chord_chart_key);
	PK_TEST_ASSERT_EQ_RET(PKE_AT_KEY_INDEX_NONE, items[1].arrangement.details.chord_chart_key);
	PK_TEST_ASSERT_EQ_RET(PKE_AT_KEY_INDEX_G, items[2].arrangement.details.chord_chart_key);
	PK_TEST_ASSERT_EQ_RET(PKE_AT_KEY_INDEX_A, items[3].arrangement.details.chord_chart_key);
	PK_TEST_ASSERT_EQ_RET(0,  items[0].arrangement.details.sequence.next);
	PK_TEST_ASSERT_EQ_RET(0, items[1].arrangement.details.sequence.next);
	PK_TEST_ASSERT_EQ_RET(11, items[2].arrangement.details.sequence.next);
	PK_TEST_ASSERT_EQ_RET(0,  items[3].arrangement.details.sequence.next);
	for (unsigned int i = 0; i < items[2].arrangement.details.sequence.next; ++i) {
		PK_TEST_ASSERT_NEQ_RET(PKE_AT_SECTION_TYPE_INDEX_NONE, items[2].arrangement.details.sequence[i]);
	}

	PK_TEST_ASSERT_EQ_RET(PKE_AT_KEY_INDEX_G, items[0].key.details.key);
	PK_TEST_ASSERT_EQ_RET(PKE_AT_KEY_INDEX_G, items[1].key.details.key);
	PK_TEST_ASSERT_EQ_RET(PKE_AT_KEY_INDEX_G, items[2].key.details.key);
	PK_TEST_ASSERT_EQ_RET(PKE_AT_KEY_INDEX_D, items[3].key.details.key);

	return 0;
}

struct pk_test_group *pke_at_test_get_data_parser() {

	static const unsigned char n_tests = 3;
	static pk_test tests[n_tests] = {
		{
			.title = "parse_test_001",
			.func = parse_test_001,
			.expected_result = 0,
		},
		{
			.title = "parse_test_002",
			.func = parse_test_002,
			.expected_result = 0,
		},
		{
			.title = "parse_test_003",
			.func = parse_test_003,
			.expected_result = 0,
		},
	};

	static pk_test_group g{};
	g.title = "parse-tests";
	g.group_setup = nullptr;
	g.group_teardown = nullptr;
	g.test_setup = parse_test_init;
	g.test_teardown = parse_test_teardown;
	g.tests = tests;
	g.n_tests = n_tests;

	return &g;
}