44 printf(
"set log to %s\n", LOGDIR
"/unit/common/object.out");
114 ob1->nrof = (1UL<<31)-1;
146 FAIL_UNLESS(sum == 45,
"Sum of object's inventory should be 45 ((6*10+7+8)*.6) but was %lu.", sum);
190 FAIL_UNLESS(
result == NULL,
"Getting containing player for ob4(%p) should bring NULL but brought %p while not contained in a player.", ob4,
result);
193 FAIL_UNLESS(
result ==
ob1,
"Getting containing player for ob4(%p) should bring ob1(%p) but brought %p while ob1 is player.", ob4,
ob1,
result);
298 FAIL_UNLESS(
ob2->owner != NULL,
"Prior to testing object_clear_owner, owner of ob2 was wrongly initialized");
300 FAIL_UNLESS(
ob2->owner == NULL,
"After object_clear_owner ob2 still had an owner");
343 FAIL_UNLESS(
ob1->name == NULL,
"Field name of ob1 was not NULLified by object_reset");
344 FAIL_UNLESS(
ob1->name_pl == NULL,
"Field name_pl of ob1 was not NULLified by object_reset");
345 FAIL_UNLESS(
ob1->title == NULL,
"Field title of ob1 was not NULLified by object_reset");
346 FAIL_UNLESS(
ob1->race == NULL,
"Field race of ob1 was not NULLified by object_reset");
347 FAIL_UNLESS(
ob1->slaying == NULL,
"Field slaying of ob1 was not NULLified by object_reset");
348 FAIL_UNLESS(
ob1->skill == NULL,
"Field skill of ob1 was not NULLified by object_reset");
349 FAIL_UNLESS(
ob1->msg == NULL,
"Field msg of ob1 was not NULLified by object_reset");
350 FAIL_UNLESS(
ob1->materialname == NULL,
"Field materialname of ob1 was not NULLified by object_reset");
351 FAIL_UNLESS(
ob1->lore == NULL,
"Field lore of ob1 was not NULLified by object_reset");
360 const char *reference;
364 reference =
add_string(
"This is a test String");
366 FAIL_UNLESS(
ob1->name == NULL,
"Field name of ob1 was not cleaned by object_clear");
367 FAIL_UNLESS(
ob1->name_pl == NULL,
"Field name_pl of ob1 was not cleaned by object_clear");
368 FAIL_UNLESS(
ob1->title == NULL,
"Field title of ob1 was not cleaned by object_clear");
369 FAIL_UNLESS(
ob1->race == NULL,
"Field race of ob1 was not cleaned by object_clear");
370 FAIL_UNLESS(
ob1->slaying == NULL,
"Field slaying of ob1 was not cleaned by object_clear");
371 FAIL_UNLESS(
ob1->skill == NULL,
"Field skill of ob1 was not cleaned by object_clear");
372 FAIL_UNLESS(
ob1->msg == NULL,
"Field msg of ob1 was not cleaned by object_clear");
373 FAIL_UNLESS(
ob1->materialname == NULL,
"Field materialname of ob1 was not cleaned by object_clear");
374 FAIL_UNLESS(
ob1->lore == NULL,
"Field lore of ob1 was not cleaned by object_clear");
385 const char *reference;
399 FAIL_UNLESS(
ob1->name_pl ==
ob2->name_pl,
"Field name_pl of ob1 should match ob2");
402 FAIL_UNLESS(
ob1->slaying ==
ob2->slaying,
"Field slaying of ob1 should match ob2");
405 FAIL_UNLESS(
ob1->materialname ==
ob2->materialname,
"Field materialname of ob1 should match ob2");
409 FAIL_UNLESS(
ob2->key_values,
"Key values should have been copied");
410 kv =
ob2->key_values;
411 FAIL_UNLESS(strcmp(kv->
key,
"some_other_key") == 0,
"Wrong first key %s",
ob2->key_values->key);
412 FAIL_UNLESS(strcmp(kv->
value,
"another_value") == 0,
"Wrong first value %s",
ob2->key_values->value);
415 FAIL_UNLESS(strcmp(kv->
key,
"some_key") == 0,
"Wrong second key %s",
ob2->key_values->key);
416 FAIL_UNLESS(strcmp(kv->
value,
"value") == 0,
"Wrong second value %s",
ob2->key_values->value);
431 FAIL_UNLESS(
ob != NULL,
"Should get an object after calling object_new()");
432 FAIL_UNLESS(
ob->name == NULL,
"Field name has not been nullified by object_new()");
433 FAIL_UNLESS(
ob->name_pl == NULL,
"Field name_pl has not been nullified by object_new()");
434 FAIL_UNLESS(
ob->title == NULL,
"Field title has not been nullified by object_new()");
435 FAIL_UNLESS(
ob->race == NULL,
"Field race has not been nullified by object_new()");
436 FAIL_UNLESS(
ob->slaying == NULL,
"Field slaying has not been nullified by object_new()");
437 FAIL_UNLESS(
ob->skill == NULL,
"Field skill has not been nullified by object_new()");
438 FAIL_UNLESS(
ob->lore == NULL,
"Field lore has not been nullified by object_new()");
439 FAIL_UNLESS(
ob->msg == NULL,
"Field msg has not been nullified by object_new()");
440 FAIL_UNLESS(
ob->materialname == NULL,
"Field materialname has not been nullified by object_new()");
441 FAIL_UNLESS(
ob->prev == NULL,
"Field prev has not been nullified by object_new()");
442 FAIL_UNLESS(
ob->active_next == NULL,
"Field active_next has not been nullified by object_new()");
443 FAIL_UNLESS(
ob->active_prev == NULL,
"Field active_prev has not been nullified by object_new()");
446 for (i = 0; i < 1L<<17; i++) {
448 FAIL_UNLESS(
ob != NULL,
"Should get an object after calling object_new() (iteration %d)",
int(i));
449 if (!(i&((1<<13)-1)))
450 LOG(
llevDebug,
"%ldk items created with object_new\n", i>>10);
470 FAIL_UNLESS(face2 != face1,
"2 opposite direction should provide different faces after object_update_turn_face");
474 #define IS_OBJECT_ACTIVE(op) (op->active_next || op->active_prev || op == active_objects)
534 #undef IS_OBJECT_ACTIVE
574 FAIL_UNLESS(((free2 == 0) && (free1 == 0)),
"after creating an object, the object_count_free() should return 0 (compiled with MEMORY_DEBUG)", free1-1, free2);
576 FAIL_UNLESS((free2 == free1-1),
"after creating an object, the object_count_free() should return one less (%d) but returned %d", free1-1, free2);
591 FAIL_UNLESS((used2 == used1+1),
"after creating an object, the object_count_used() should return one more (%d) but returned %d", used1-1, used2);
600 int active1, active2;
610 FAIL_UNLESS((active2 == active1+1),
"after activating an additional object, object_count_active should return one less %d but returned %d", active1-1, active2);
640 FAIL_UNLESS(sum == 18,
"Sum of object's inventory should be 18 (30*0.6+10) but was %lu.", sum);
642 FAIL_UNLESS(
ob1->carrying == 12,
"after call to object_sub_weight, carrying of ob1 should be 22 but was %d",
ob1->carrying);
689 object *first = NULL;
697 FAIL_UNLESS(first != NULL,
"create barrel failed");
703 FAIL_UNLESS(first != NULL,
"create dragon failed");
720 object *first = NULL;
721 object *second = NULL;
722 object *third = NULL;
723 object *floor = NULL;
731 FAIL_UNLESS(floor != NULL,
"create woodfloor failed");
740 FAIL_UNLESS(first != NULL,
"create barrel failed");
828 object *first = NULL, *second = NULL, *third = NULL;
829 tag_t tag_first, tag_second, tag_third;
837 FAIL_UNLESS(first != NULL,
"create barrel failed");
838 tag_first = first->
count;
844 FAIL_UNLESS(second != NULL,
"create table failed");
848 tag_second = second->count;
851 FAIL_UNLESS(third != NULL,
"create 2nd barrel failed");
853 FAIL_UNLESS(
got == third,
"second barrel shouldn't be destroyed");
854 tag_third = third->count;
870 FAIL_UNLESS(strcmp(
GET_MAP_OB(
map, 0, 0)->
arch->name,
"barrel") == 0,
"item at 0,0 is not a barrel after object_replace_insert_in_map");
878 object *first = NULL;
879 object *second = NULL;
887 FAIL_UNLESS(second != NULL,
"should return an item");
892 FAIL_UNLESS(second != NULL,
"should return an item");
905 object *first = NULL;
906 object *second = NULL;
913 FAIL_UNLESS(second == first,
"gem shouldn't be destroyed");
916 FAIL_UNLESS(second == NULL,
"object_decrease_nrof should return NULL");
933 object *container = NULL;
942 FAIL_UNLESS(container != NULL,
"create bookshelf failed");
953 FAIL_UNLESS(container != NULL,
"create sack failed");
1167 FAIL_UNLESS(o1 != NULL,
"couldn't find cloak archetype");
1174 FAIL_UNLESS(val == 0,
"unidentified cloak matched title with value %d", val);
1176 FAIL_UNLESS(val == 0,
"unidentified cloak matched random value with value %d", val);
1180 FAIL_UNLESS(val != 0,
"identified cloak didn't match title with value %d", val);
1185 FAIL_UNLESS(val == 2,
"unpaid cloak didn't match unpaid");
1187 FAIL_UNLESS(val != 0,
"unpaid cloak didn't match cloak with %d", val);
1189 FAIL_UNLESS(val == 0,
"unpaid cloak matched wrong name %d", val);
1194 Suite *s = suite_create(
"object");
1195 TCase *tc_core = tcase_create(
"Core");
1200 suite_add_tcase(s, tc_core);
1201 tcase_add_test(tc_core, test_object_can_merge);
1202 tcase_add_test(tc_core, test_object_sum_weight);
1203 tcase_add_test(tc_core, test_object_get_env_recursive);
1204 tcase_add_test(tc_core, test_object_get_player_container);
1205 tcase_add_test(tc_core, test_object_dump);
1206 tcase_add_test(tc_core, test_object_dump_all);
1207 tcase_add_test(tc_core, test_object_find_by_tag_global);
1208 tcase_add_test(tc_core, test_object_find_by_name_global);
1209 tcase_add_test(tc_core, test_object_free_all_data);
1210 tcase_add_test(tc_core, test_object_get_owner);
1211 tcase_add_test(tc_core, test_object_clear_owner);
1212 tcase_add_test(tc_core, test_object_set_owner);
1213 tcase_add_test(tc_core, test_object_copy_owner);
1214 tcase_add_test(tc_core, test_object_reset);
1215 tcase_add_test(tc_core, test_object_clear);
1216 tcase_add_test(tc_core, test_object_copy);
1217 tcase_add_test(tc_core, test_object_new);
1218 tcase_add_test(tc_core, test_object_update_turn_face);
1219 tcase_add_test(tc_core, test_object_update_speed);
1220 tcase_add_test(tc_core, test_object_remove_from_active_list);
1221 tcase_add_test(tc_core, test_object_update);
1222 tcase_add_test(tc_core, test_object_free_drop_inventory);
1223 tcase_add_test(tc_core, test_object_count_free);
1224 tcase_add_test(tc_core, test_object_count_used);
1225 tcase_add_test(tc_core, test_object_count_active);
1226 tcase_add_test(tc_core, test_object_sub_weight);
1227 tcase_add_test(tc_core, test_object_remove);
1228 tcase_add_test(tc_core, test_object_merge);
1229 tcase_add_test(tc_core, test_object_insert_in_map_at);
1230 tcase_add_test(tc_core, test_object_insert_in_map);
1231 tcase_add_test(tc_core, test_object_replace_insert_in_map);
1232 tcase_add_test(tc_core, test_object_split);
1233 tcase_add_test(tc_core, test_object_decrease_nrof);
1234 tcase_add_test(tc_core, test_object_add_weight);
1235 tcase_add_test(tc_core, test_object_insert_in_ob);
1236 tcase_add_test(tc_core, test_object_check_move_on);
1237 tcase_add_test(tc_core, test_map_find_by_archetype);
1238 tcase_add_test(tc_core, test_map_find_by_type);
1239 tcase_add_test(tc_core, test_object_present_in_ob);
1240 tcase_add_test(tc_core, test_object_present_in_ob_by_name);
1241 tcase_add_test(tc_core, test_arch_present_in_ob);
1242 tcase_add_test(tc_core, test_object_set_flag_inv);
1243 tcase_add_test(tc_core, test_object_unset_flag_inv);
1244 tcase_add_test(tc_core, test_object_set_cheat);
1245 tcase_add_test(tc_core, test_object_find_free_spot);
1246 tcase_add_test(tc_core, test_object_find_first_free_spot);
1247 tcase_add_test(tc_core, test_get_search_arr);
1248 tcase_add_test(tc_core, test_object_distance);
1249 tcase_add_test(tc_core, test_find_dir_2);
1250 tcase_add_test(tc_core, test_absdir);
1251 tcase_add_test(tc_core, test_dirdiff);
1252 tcase_add_test(tc_core, test_can_see_monsterP);
1253 tcase_add_test(tc_core, test_object_can_pick);
1254 tcase_add_test(tc_core, test_object_create_clone);
1255 tcase_add_test(tc_core, test_object_was_destroyed);
1256 tcase_add_test(tc_core, test_object_find_by_type_subtype);
1257 tcase_add_test(tc_core, test_object_get_key_value);
1258 tcase_add_test(tc_core, test_object_get_value);
1259 tcase_add_test(tc_core, test_object_set_value);
1260 tcase_add_test(tc_core, test_object_matches_string);
1270 sr = srunner_create(s);
1271 srunner_set_xml(sr, LOGDIR
"/unit/common/object.xml");
1275 srunner_run_all(sr, CK_ENV);
1276 nf = srunner_ntests_failed(sr);
1278 return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;