44 printf(
"set log to %s\n", LOGDIR
"/unit/common/object.out");
114 ob1->nrof = (1UL<<31)-1;
116 fail_unless(!
object_can_merge(
ob1,
ob2),
"Should not be able to merge 2 object if result nrof goes to 1<<31 or higher");
146 fail_unless(sum == 45,
"Sum of object's inventory should be 45 ((6*10+7+8)*.6) but was %lu.", sum);
168 fail_unless(
result ==
ob1,
"Getting top level container for ob4(%p) should bring ob1(%p) but brought %p.", ob4,
ob1,
result);
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);
215 fail_unless(strstr(
result,
"arch") != NULL,
"The object dump should contain 'arch' but was %s", sb);
242 fail_unless(
result ==
ob1,
"Should find ob1(%p) while search for item %d but got %p",
ob1,
ob1->count,
result);
260 fail_unless(
result ==
ob1,
"Searching for object with name 'This is the key name' returned %p(%s) instead of ob1(%p)",
result,
result ?
result->name :
"null",
ob1);
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");
314 fail_unless(
ob2->owner ==
ob1,
"After object_set_owner ob2(%p) owner should be ob1(%p) but was (%p)",
ob2,
ob1,
ob2->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");
375 fail_unless(
query_refcount(reference) == 1,
"The number of references to string should drop back to 1 but was %d",
query_refcount(reference));
385 const char *reference;
393 fail_unless(
ob1->name ==
ob2->name,
"Field name of ob1 should match ob2");
394 fail_unless(
ob1->name_pl ==
ob2->name_pl,
"Field name_pl of ob1 should match ob2");
395 fail_unless(
ob1->title ==
ob2->title,
"Field title of ob1 should match ob2");
396 fail_unless(
ob1->race ==
ob2->race,
"Field race of ob1 should match ob2");
397 fail_unless(
ob1->slaying ==
ob2->slaying,
"Field slaying of ob1 should match ob2");
398 fail_unless(
ob1->skill ==
ob2->skill,
"Field skill of ob1 should match ob2");
399 fail_unless(
ob1->msg ==
ob2->msg,
"Field msg of ob1 should match ob2");
400 fail_unless(
ob1->materialname ==
ob2->materialname,
"Field materialname of ob1 should match ob2");
401 fail_unless(
ob1->lore ==
ob2->lore,
"Field lore of ob1 should match ob2");
402 fail_unless(
query_refcount(reference) == 1,
"refcount of marker string is not dropped to 1 after copy object, some string field were not cleaned. refcount: %d",
query_refcount(reference));
415 fail_unless(
ob != NULL,
"Should get an object after calling object_new()");
416 fail_unless(
ob->name == NULL,
"Field name has not been nullified by object_new()");
417 fail_unless(
ob->name_pl == NULL,
"Field name_pl has not been nullified by object_new()");
418 fail_unless(
ob->title == NULL,
"Field title has not been nullified by object_new()");
419 fail_unless(
ob->race == NULL,
"Field race has not been nullified by object_new()");
420 fail_unless(
ob->slaying == NULL,
"Field slaying has not been nullified by object_new()");
421 fail_unless(
ob->skill == NULL,
"Field skill has not been nullified by object_new()");
422 fail_unless(
ob->lore == NULL,
"Field lore has not been nullified by object_new()");
423 fail_unless(
ob->msg == NULL,
"Field msg has not been nullified by object_new()");
424 fail_unless(
ob->materialname == NULL,
"Field materialname has not been nullified by object_new()");
425 fail_unless(
ob->prev == NULL,
"Field prev has not been nullified by object_new()");
426 fail_unless(
ob->active_next == NULL,
"Field active_next has not been nullified by object_new()");
427 fail_unless(
ob->active_prev == NULL,
"Field active_prev has not been nullified by object_new()");
430 for (i = 0; i < 1L<<17; i++) {
432 fail_unless(
ob != NULL,
"Should get an object after calling object_new() (iteration %l)", i);
433 if (!(i&((1<<13)-1)))
434 LOG(
llevDebug,
"%ldk items created with object_new\n", i>>10);
454 fail_unless(face2 != face1,
"2 opposite direction should provide different faces after object_update_turn_face");
458 #define IS_OBJECT_ACTIVE(op) (op->active_next || op->active_prev || op == active_objects)
499 fail_unless(!
IS_OBJECT_ACTIVE(ob3),
"Object with absolute speed 0.0 should be inactivated", ob3->
speed);
500 fail_unless(!
IS_OBJECT_ACTIVE(ob4),
"Object with absolute speed 0.0 should be inactivated", ob4->
speed);
515 fail_unless(!
IS_OBJECT_ACTIVE(
ob1),
"After call to object_remove_from_active_list, object should be made inactive");
518 #undef IS_OBJECT_ACTIVE
558 fail_unless(((free2 == 0) && (free1 == 0)),
"after creating an object, the object_count_free() should return 0 (compiled with MEMORY_DEBUG)", free1-1, free2);
560 fail_unless((free2 == free1-1),
"after creating an object, the object_count_free() should return one less (%d) but returned %d", free1-1, free2);
575 fail_unless((used2 == used1+1),
"after creating an object, the object_count_used() should return one more (%d) but returned %d", used1-1, used2);
584 int active1, active2;
594 fail_unless((active2 == active1+1),
"after activating an additional object, object_count_active should return one less %d but returned %d", active1-1, active2);
624 fail_unless(sum == 18,
"Sum of object's inventory should be 18 (30*0.6+10) but was %lu.", sum);
626 fail_unless(
ob1->carrying == 12,
"after call to object_sub_weight, carrying of ob1 should be 22 but was %d",
ob1->carrying);
673 object *first = NULL;
677 fail_unless(
map != NULL,
"get_empty_map returned NULL.");
681 fail_unless(first != NULL,
"create barrel failed");
684 fail_unless(
got == first,
"item shouldn't be destroyed");
687 fail_unless(first != NULL,
"create dragon failed");
688 fail_unless(first->
more != NULL,
"no other body part");
691 fail_unless(
got == first,
"item shouldn't be destroyed");
693 fail_unless(
GET_MAP_OB(
map, 1, 1) == first,
"item isn't on 1,1");
694 fail_unless(
GET_MAP_OB(
map, 2, 1) != NULL,
"no item on 2,1");
695 fail_unless(
GET_MAP_OB(
map, 2, 1)->head == first,
"head of 2,1 isn't 1,1");
704 object *first = NULL;
705 object *second = NULL;
706 object *third = NULL;
707 object *floor = NULL;
711 fail_unless(
map != NULL,
"get_empty_map returned NULL.");
715 fail_unless(floor != NULL,
"create woodfloor failed");
720 fail_unless(
got == floor,
"woodfloor shouldn't disappear");
721 fail_unless(floor ==
GET_MAP_OB(
map, 3, 3),
"woodfloor should be first object");
724 fail_unless(first != NULL,
"create barrel failed");
729 fail_unless(
got == first,
"barrel shouldn't disappear");
730 fail_unless(floor ==
GET_MAP_OB(
map, 3, 3),
"woodfloor should still be first object");
731 fail_unless(floor->
above == first,
"barrel should be above floor");
734 fail_unless(second != NULL,
"create gem failed");
740 fail_unless(
got == second,
"gem shouldn't disappear");
741 fail_unless(floor ==
GET_MAP_OB(
map, 3, 3),
"woodfloor should still be first object");
742 fail_unless(floor->
above == second,
"gem should be above floor");
743 fail_unless(second->
above == first,
"barrel should be above gem");
746 fail_unless(third != NULL,
"create bed_1 failed");
752 fail_unless(
got == third,
"bed_1 shouldn't disappear");
753 fail_unless(floor ==
GET_MAP_OB(
map, 3, 3),
"woodfloor should still be first object");
754 fail_unless(third->
above == first,
"bed should be below barrel");
755 fail_unless(third->
below == second,
"bed should be above gem");
759 fail_unless(third != NULL,
"create gem failed");
765 fail_unless(
got == third,
"gem shouldn't disappear");
767 fail_unless(third->
nrof == 2,
"second gem should have nrof 2");
770 fail_unless(second != NULL,
"create gem failed");
777 fail_unless(
got == second,
"modified gem shouldn't disappear");
778 fail_unless(second->
nrof == 1,
"modified gem should have nrof 1");
812 object *first = NULL, *second = NULL, *third = NULL;
813 tag_t tag_first, tag_second, tag_third;
817 fail_unless(
map != NULL,
"get_empty_map returned NULL.");
821 fail_unless(first != NULL,
"create barrel failed");
822 tag_first = first->
count;
825 fail_unless(
got == first,
"item shouldn't be destroyed");
828 fail_unless(second != NULL,
"create table failed");
831 fail_unless(
got == second,
"second item shouldn't be destroyed");
832 tag_second = second->count;
835 fail_unless(third != NULL,
"create 2nd barrel failed");
837 fail_unless(
got == third,
"second barrel shouldn't be destroyed");
838 tag_third = third->count;
840 fail_unless(
GET_MAP_OB(
map, 0, 0) == first,
"item at 0,0 isn't barrel");
841 fail_unless(
GET_MAP_OB(
map, 0, 0)->above == second,
"second item at 0,0 isn't table");
842 fail_unless(
GET_MAP_OB(
map, 0, 0)->above->above == third,
"third item at 0,0 isn't barrel");
846 fail_unless(
GET_MAP_OB(
map, 0, 0) != first,
"item at 0, 0 is still first?");
851 fail_unless(
GET_MAP_OB(
map, 0, 0) != NULL,
"no item at 0,0 after object_replace_insert_in_map");
852 fail_unless(
GET_MAP_OB(
map, 0, 0) != second,
"second at bottom at 0,0 after object_replace_insert_in_map");
853 fail_unless(
GET_MAP_OB(
map, 0, 0)->above == second,
"table isn't above new barrel");
854 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");
862 object *first = NULL;
863 object *second = NULL;
867 fail_unless(first != NULL,
"create gem failed");
871 fail_unless(second != NULL,
"should return an item");
872 fail_unless(second->
nrof == 2,
"2 expected to split");
873 fail_unless(first->
nrof == 3,
"3 should be left");
876 fail_unless(second != NULL,
"should return an item");
880 fail_unless(first == NULL,
"should return NULL");
881 fail_unless(second->
nrof == 3,
"3 should be left");
889 object *first = NULL;
890 object *second = NULL;
893 fail_unless(first != NULL,
"create gem failed");
897 fail_unless(second == first,
"gem shouldn't be destroyed");
900 fail_unless(second == NULL,
"object_decrease_nrof should return NULL");
917 object *container = NULL;
921 fail_unless(
item != NULL,
"create gem failed");
926 fail_unless(container != NULL,
"create bookshelf failed");
929 fail_unless(container->
inv ==
item,
"item not inserted");
930 fail_unless(container->
carrying == 50,
"container should carry 50 and not %d", container->
carrying);
933 fail_unless(container->
carrying == 0,
"container should carry 0 and not %d", container->
carrying);
937 fail_unless(container != NULL,
"create sack failed");
940 fail_unless(container->
inv ==
item,
"item not inserted");
941 fail_unless(container->
carrying == 45,
"container should carry 45 and not %d", container->
carrying);
1146 fail_unless(
pl != NULL,
"couldn't create kobold");
1148 fail_unless(
pl->contr != NULL,
"couldn't alloc contr");
1151 fail_unless(o1 != NULL,
"couldn't find cloak archetype");
1156 fail_unless(val == 1,
"all didn't match cloak");
1158 fail_unless(val == 0,
"unidentified cloak matched title with value %d", val);
1160 fail_unless(val == 0,
"unidentified cloak matched random value with value %d", val);
1164 fail_unless(val != 0,
"identified cloak didn't match title with value %d", val);
1169 fail_unless(val == 2,
"unpaid cloak didn't match unpaid");
1171 fail_unless(val != 0,
"unpaid cloak didn't match cloak with %d", val);
1173 fail_unless(val == 0,
"unpaid cloak matched wrong name %d", val);
1178 Suite *s = suite_create(
"object");
1179 TCase *tc_core = tcase_create(
"Core");
1184 suite_add_tcase(s, tc_core);
1185 tcase_add_test(tc_core, test_object_can_merge);
1186 tcase_add_test(tc_core, test_object_sum_weight);
1187 tcase_add_test(tc_core, test_object_get_env_recursive);
1188 tcase_add_test(tc_core, test_object_get_player_container);
1189 tcase_add_test(tc_core, test_object_dump);
1190 tcase_add_test(tc_core, test_object_dump_all);
1191 tcase_add_test(tc_core, test_object_find_by_tag_global);
1192 tcase_add_test(tc_core, test_object_find_by_name_global);
1193 tcase_add_test(tc_core, test_object_free_all_data);
1194 tcase_add_test(tc_core, test_object_get_owner);
1195 tcase_add_test(tc_core, test_object_clear_owner);
1196 tcase_add_test(tc_core, test_object_set_owner);
1197 tcase_add_test(tc_core, test_object_copy_owner);
1198 tcase_add_test(tc_core, test_object_reset);
1199 tcase_add_test(tc_core, test_object_clear);
1200 tcase_add_test(tc_core, test_object_copy);
1201 tcase_add_test(tc_core, test_object_new);
1202 tcase_add_test(tc_core, test_object_update_turn_face);
1203 tcase_add_test(tc_core, test_object_update_speed);
1204 tcase_add_test(tc_core, test_object_remove_from_active_list);
1205 tcase_add_test(tc_core, test_object_update);
1206 tcase_add_test(tc_core, test_object_free_drop_inventory);
1207 tcase_add_test(tc_core, test_object_count_free);
1208 tcase_add_test(tc_core, test_object_count_used);
1209 tcase_add_test(tc_core, test_object_count_active);
1210 tcase_add_test(tc_core, test_object_sub_weight);
1211 tcase_add_test(tc_core, test_object_remove);
1212 tcase_add_test(tc_core, test_object_merge);
1213 tcase_add_test(tc_core, test_object_insert_in_map_at);
1214 tcase_add_test(tc_core, test_object_insert_in_map);
1215 tcase_add_test(tc_core, test_object_replace_insert_in_map);
1216 tcase_add_test(tc_core, test_object_split);
1217 tcase_add_test(tc_core, test_object_decrease_nrof);
1218 tcase_add_test(tc_core, test_object_add_weight);
1219 tcase_add_test(tc_core, test_object_insert_in_ob);
1220 tcase_add_test(tc_core, test_object_check_move_on);
1221 tcase_add_test(tc_core, test_map_find_by_archetype);
1222 tcase_add_test(tc_core, test_map_find_by_type);
1223 tcase_add_test(tc_core, test_object_present_in_ob);
1224 tcase_add_test(tc_core, test_object_present_in_ob_by_name);
1225 tcase_add_test(tc_core, test_arch_present_in_ob);
1226 tcase_add_test(tc_core, test_object_set_flag_inv);
1227 tcase_add_test(tc_core, test_object_unset_flag_inv);
1228 tcase_add_test(tc_core, test_object_set_cheat);
1229 tcase_add_test(tc_core, test_object_find_free_spot);
1230 tcase_add_test(tc_core, test_object_find_first_free_spot);
1231 tcase_add_test(tc_core, test_get_search_arr);
1232 tcase_add_test(tc_core, test_object_distance);
1233 tcase_add_test(tc_core, test_find_dir_2);
1234 tcase_add_test(tc_core, test_absdir);
1235 tcase_add_test(tc_core, test_dirdiff);
1236 tcase_add_test(tc_core, test_can_see_monsterP);
1237 tcase_add_test(tc_core, test_object_can_pick);
1238 tcase_add_test(tc_core, test_object_create_clone);
1239 tcase_add_test(tc_core, test_object_was_destroyed);
1240 tcase_add_test(tc_core, test_object_find_by_type_subtype);
1241 tcase_add_test(tc_core, test_object_get_key_value);
1242 tcase_add_test(tc_core, test_object_get_value);
1243 tcase_add_test(tc_core, test_object_set_value);
1244 tcase_add_test(tc_core, test_object_matches_string);
1254 sr = srunner_create(s);
1255 srunner_set_xml(sr, LOGDIR
"/unit/common/object.xml");
1259 srunner_run_all(sr, CK_ENV);
1260 nf = srunner_ntests_failed(sr);
1262 return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;