32 size_t len =
rndm(5,
MIN(max_length,
sizeof(
buf) - 1));
34 for (
size_t c = 0;
c < len;
c++) {
44 writer.
write(asset, sb);
50 loader.
load(br,
"dummy");
69 if (
rndm(0, 5 - depth) != 0) {
72 if (!single &&
rndm(0, 2) == 0) {
75 if (!single &&
rndm(0, 2) == 0) {
84 bool single =
rndm(0, 1) == 0;
89 list->total_chance += i->chance;
97 if (left ==
nullptr) {
98 FAIL_UNLESS(right ==
nullptr,
"left treasure == null but right treasure != null");
101 FAIL_UNLESS(right !=
nullptr,
"left treasure != null but right treasure == null");
114 if (left ==
nullptr) {
115 FAIL_UNLESS(right ==
nullptr,
"left list == null but right list != null");
118 FAIL_UNLESS(right !=
nullptr,
"left list != null but right list == null");
135 auto loaded = trs.
find(generated->name);
136 FAIL_UNLESS(loaded,
"Treasurelist should have been loaded!");
137 FAIL_UNLESS(
equal(generated, loaded),
"loaded treasurelist isn't the same as generated one");
139 trs.
define(generated->name, generated);
150 anim->faces =
static_cast<const Face **
>(calloc(
anim->num_animations,
sizeof(
const Face *)));
151 for (uint8_t f = 0; f <
anim->num_animations; f++) {
168 FAIL_UNLESS(loaded,
"face should have been loaded");
169 ck_assert_str_eq(
anim->name, loaded->name);
170 ck_assert_int_eq(
anim->num_animations, loaded->num_animations);
171 for (uint8_t f = 0; f <
anim->num_animations; f++) {
172 ck_assert_str_eq(
anim->faces[f]->name, loaded->faces[f]->name);
174 ck_assert_int_eq(
anim->facings, loaded->facings);
183 Face *face =
static_cast<Face *
>(calloc(1,
sizeof(
Face)));
185 if (
rndm(0, 10) == 0) {
191 if (
rndm(0, 3) == 0) {
195 if (
rndm(0, 3) == 0) {
211 ck_assert_int_eq(face->
magicmap, loaded->magicmap);
212 ck_assert_int_eq(face->
visibility, loaded->visibility);
214 ck_assert(loaded->smoothface);
215 ck_assert_str_eq(face->
smoothface->
name, loaded->smoothface->name);
217 ck_assert(loaded->smoothface ==
nullptr);
229 if (
rndm(0, 3) == 0) {
232 }
else if (
rndm(0, 2) == 0) {
233 c->minstep =
rndm(4, 15);
234 c->maxstep =
c->minstep;
235 }
else if (
rndm(0, 1)) {
236 c->maxstep =
rndm(4, 15);
238 c->minstep =
rndm(0, 14);
239 c->maxstep =
c->minstep +
rndm(1, 10);
247 s->step =
rndm(1, 50);
249 for (
int i =
rndm(0, 2); i != 0; i--) {
251 s->conditions.push_back(
c);
260 q->quest_is_system =
rndm(0, 1);
261 q->quest_restart =
rndm(0, 1);
270 q->face =
faces.get(
"quest_generic.111");
272 for (
int i =
rndm(0, 5); i != 0; i--) {
280 ck_assert(rc ==
nullptr);
291 ck_assert(rs ==
nullptr);
300 ck_assert_int_eq(ls->
step, rs->
step);
311 void check_steps(
const std::vector<quest_step_definition *> &ls,
const std::vector<quest_step_definition *> &rs) {
312 ck_assert(ls.size() == rs.size());
313 for (
size_t i = 0; i < ls.size(); i++) {
328 ck_assert_str_eq(
quest->quest_description, loaded->quest_description);
329 ck_assert_str_eq(
quest->quest_title, loaded->quest_title);
330 if (
quest->quest_comment)
331 ck_assert_str_eq(
quest->quest_comment, loaded->quest_comment);
333 ck_assert(loaded->quest_comment ==
nullptr);
334 ck_assert_int_eq(
quest->quest_restart, loaded->quest_restart);
335 ck_assert_int_eq(
quest->quest_is_system, loaded->quest_is_system);
336 ck_assert(
quest->face == loaded->face);
337 ck_assert(
quest->parent == loaded->parent);
347 Suite *s = suite_create(
"asset_load_write");
348 TCase *tc_core = tcase_create(
"Core");
353 suite_add_tcase(s, tc_core);
354 tcase_add_loop_test(tc_core, test_treasure, 0, 25);
355 tcase_add_loop_test(tc_core, test_animation, 0, 25);
356 tcase_add_loop_test(tc_core, test_face, 0, 25);
357 tcase_add_loop_test(tc_core, test_quest, 0, 25);
365 SRunner *sr = srunner_create(s);
367 srunner_set_xml(sr, LOGDIR
"/unit/common/asset_load_write.xml");
368 srunner_set_log(sr, LOGDIR
"/unit/common/asset_load_write.out");
369 srunner_set_fork_status(sr, CK_NOFORK);
370 srunner_run_all(sr, CK_ENV);
371 nf = srunner_ntests_failed(sr);
373 return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;