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;
398 fail_unless(
ob1->name ==
ob2->name,
"Field name of ob1 should match ob2");
399 fail_unless(
ob1->name_pl ==
ob2->name_pl,
"Field name_pl of ob1 should match ob2");
400 fail_unless(
ob1->title ==
ob2->title,
"Field title of ob1 should match ob2");
401 fail_unless(
ob1->race ==
ob2->race,
"Field race of ob1 should match ob2");
402 fail_unless(
ob1->slaying ==
ob2->slaying,
"Field slaying of ob1 should match ob2");
403 fail_unless(
ob1->skill ==
ob2->skill,
"Field skill of ob1 should match ob2");
404 fail_unless(
ob1->msg ==
ob2->msg,
"Field msg of ob1 should match ob2");
405 fail_unless(
ob1->materialname ==
ob2->materialname,
"Field materialname of ob1 should match ob2");
406 fail_unless(
ob1->lore ==
ob2->lore,
"Field lore of ob1 should match ob2");
407 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));
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);
414 fail_unless(kv,
"Missing second key/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);
418 fail_unless(kv == NULL,
"Third key/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 %l)", 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)
515 fail_unless(!
IS_OBJECT_ACTIVE(ob3),
"Object with absolute speed 0.0 should be inactivated", ob3->
speed);
516 fail_unless(!
IS_OBJECT_ACTIVE(ob4),
"Object with absolute speed 0.0 should be inactivated", ob4->
speed);
531 fail_unless(!
IS_OBJECT_ACTIVE(
ob1),
"After call to object_remove_from_active_list, object should be made inactive");
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;
693 fail_unless(
map != NULL,
"get_empty_map returned NULL.");
697 fail_unless(
first != NULL,
"create barrel failed");
700 fail_unless(
got ==
first,
"item shouldn't be destroyed");
703 fail_unless(
first != NULL,
"create dragon failed");
704 fail_unless(
first->more != NULL,
"no other body part");
707 fail_unless(
got ==
first,
"item shouldn't be destroyed");
710 fail_unless(
GET_MAP_OB(
map, 2, 1) != NULL,
"no item on 2,1");
720 object *
first = NULL;
721 object *second = NULL;
722 object *third = NULL;
723 object *
floor = NULL;
727 fail_unless(
map != NULL,
"get_empty_map returned NULL.");
731 fail_unless(
floor != NULL,
"create woodfloor failed");
736 fail_unless(
got ==
floor,
"woodfloor shouldn't disappear");
740 fail_unless(
first != NULL,
"create barrel failed");
745 fail_unless(
got ==
first,
"barrel shouldn't disappear");
746 fail_unless(
floor ==
GET_MAP_OB(
map, 3, 3),
"woodfloor should still be first object");
747 fail_unless(
floor->above ==
first,
"barrel should be above floor");
750 fail_unless(second != NULL,
"create gem failed");
756 fail_unless(
got == second,
"gem shouldn't disappear");
757 fail_unless(
floor ==
GET_MAP_OB(
map, 3, 3),
"woodfloor should still be first object");
758 fail_unless(
floor->above == second,
"gem should be above floor");
759 fail_unless(second->
above ==
first,
"barrel should be above gem");
762 fail_unless(third != NULL,
"create bed_1 failed");
768 fail_unless(
got == third,
"bed_1 shouldn't disappear");
769 fail_unless(
floor ==
GET_MAP_OB(
map, 3, 3),
"woodfloor should still be first object");
770 fail_unless(third->
above ==
first,
"bed should be below barrel");
771 fail_unless(third->
below == second,
"bed should be above gem");
775 fail_unless(third != NULL,
"create gem failed");
781 fail_unless(
got == third,
"gem shouldn't disappear");
783 fail_unless(third->
nrof == 2,
"second gem should have nrof 2");
786 fail_unless(second != NULL,
"create gem failed");
793 fail_unless(
got == second,
"modified gem shouldn't disappear");
794 fail_unless(second->
nrof == 1,
"modified gem should have nrof 1");
828 object *
first = NULL, *second = NULL, *third = NULL;
829 tag_t tag_first, tag_second, tag_third;
833 fail_unless(
map != NULL,
"get_empty_map returned NULL.");
837 fail_unless(
first != NULL,
"create barrel failed");
841 fail_unless(
got ==
first,
"item shouldn't be destroyed");
844 fail_unless(second != NULL,
"create table failed");
847 fail_unless(
got == second,
"second item shouldn't be destroyed");
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;
857 fail_unless(
GET_MAP_OB(
map, 0, 0)->
above == second,
"second item at 0,0 isn't table");
858 fail_unless(
GET_MAP_OB(
map, 0, 0)->
above->above == third,
"third item at 0,0 isn't barrel");
867 fail_unless(
GET_MAP_OB(
map, 0, 0) != NULL,
"no item at 0,0 after object_replace_insert_in_map");
868 fail_unless(
GET_MAP_OB(
map, 0, 0) != second,
"second at bottom at 0,0 after object_replace_insert_in_map");
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;
883 fail_unless(
first != NULL,
"create gem failed");
887 fail_unless(second != NULL,
"should return an item");
888 fail_unless(second->
nrof == 2,
"2 expected to split");
889 fail_unless(
first->nrof == 3,
"3 should be left");
892 fail_unless(second != NULL,
"should return an item");
896 fail_unless(
first == NULL,
"should return NULL");
897 fail_unless(second->
nrof == 3,
"3 should be left");
905 object *
first = NULL;
906 object *second = NULL;
909 fail_unless(
first != NULL,
"create gem failed");
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;
937 fail_unless(
item != NULL,
"create gem failed");
942 fail_unless(container != NULL,
"create bookshelf failed");
945 fail_unless(container->
inv ==
item,
"item not inserted");
946 fail_unless(container->
carrying == 50,
"container should carry 50 and not %d", container->
carrying);
949 fail_unless(container->
carrying == 0,
"container should carry 0 and not %d", container->
carrying);
953 fail_unless(container != NULL,
"create sack failed");
956 fail_unless(container->
inv ==
item,
"item not inserted");
957 fail_unless(container->
carrying == 45,
"container should carry 45 and not %d", container->
carrying);
1162 fail_unless(
pl != NULL,
"couldn't create kobold");
1164 fail_unless(
pl->contr != NULL,
"couldn't alloc contr");
1167 fail_unless(o1 != NULL,
"couldn't find cloak archetype");
1172 fail_unless(val == 1,
"all didn't match cloak");
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;