44 printf(
"set log to %s\n", LOGDIR
"/unit/common/object.out");
108 fail_unless(
can_merge(ob1, ob2),
"Should be able to merge 2 same object");
110 fail_unless(!
can_merge(ob1, ob2),
"Should not be able to merge 2 object with different names");
113 fail_unless(!
can_merge(ob1, ob2),
"Should not be able to merge 2 object with different types");
115 ob1->
nrof = (1UL<<31)-1;
117 fail_unless(!
can_merge(ob1, ob2),
"Should not be able to merge 2 object if result nrof goes to 1<<31 or higher");
147 fail_unless(sum == 45,
"Sum of object's inventory should be 45 ((6*10+7+8)*.6) but was %lu.", sum);
169 fail_unless(result == ob1,
"Getting top level container for ob4(%p) should bring ob1(%p) but brought %p.", ob4, ob1, result);
191 fail_unless(result == NULL,
"Getting containing player for ob4(%p) should bring NULL but brought %p while not contained in a player.", ob4, result);
194 fail_unless(result == ob1,
"Getting containing player for ob4(%p) should bring ob1(%p) but brought %p while ob1 is player.", ob4, ob1, result);
216 fail_unless(strstr(result,
"arch") != NULL,
"The object dump should contain 'arch' but was %s", sb);
247 fail_unless(result == ob1,
"Should find ob1(%p) while search for item %d but got %p", ob1, ob1->
count, result);
265 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);
289 fail_unless(
get_owner(ob2) == ob1,
"Owner of ob2(%p) shoud be ob1(%p) but was %p", ob2, ob1,
get_owner(ob2));
303 fail_unless(ob2->
owner != NULL,
"Prior to testing clear_owner, owner of ob2 was wrongly initialized");
305 fail_unless(ob2->
owner == NULL,
"After clear_owner ob2 still had an owner");
319 fail_unless(ob2->
owner == ob1,
"After set_owner ob2(%p) owner should be ob1(%p) but was (%p)", ob2, ob1, ob2->
owner);
348 fail_unless(ob1->
name == NULL,
"Field name of ob1 was not NULLified by reset_object");
349 fail_unless(ob1->
name_pl == NULL,
"Field name_pl of ob1 was not NULLified by reset_object");
350 fail_unless(ob1->
title == NULL,
"Field title of ob1 was not NULLified by reset_object");
351 fail_unless(ob1->
race == NULL,
"Field race of ob1 was not NULLified by reset_object");
352 fail_unless(ob1->
slaying == NULL,
"Field slaying of ob1 was not NULLified by reset_object");
353 fail_unless(ob1->
skill == NULL,
"Field skill of ob1 was not NULLified by reset_object");
354 fail_unless(ob1->
msg == NULL,
"Field msg of ob1 was not NULLified by reset_object");
355 fail_unless(ob1->
materialname == NULL,
"Field materialname of ob1 was not NULLified by reset_object");
356 fail_unless(ob1->
lore == NULL,
"Field lore of ob1 was not NULLified by reset_object");
365 const char *reference;
369 reference =
add_string(
"This is a test String");
371 fail_unless(ob1->
name == NULL,
"Field name of ob1 was not cleaned by clear_object");
372 fail_unless(ob1->
name_pl == NULL,
"Field name_pl of ob1 was not cleaned by clear_object");
373 fail_unless(ob1->
title == NULL,
"Field title of ob1 was not cleaned by clear_object");
374 fail_unless(ob1->
race == NULL,
"Field race of ob1 was not cleaned by clear_object");
375 fail_unless(ob1->
slaying == NULL,
"Field slaying of ob1 was not cleaned by clear_object");
376 fail_unless(ob1->
skill == NULL,
"Field skill of ob1 was not cleaned by clear_object");
377 fail_unless(ob1->
msg == NULL,
"Field msg of ob1 was not cleaned by clear_object");
378 fail_unless(ob1->
materialname == NULL,
"Field materialname of ob1 was not cleaned by clear_object");
379 fail_unless(ob1->
lore == NULL,
"Field lore of ob1 was not cleaned by clear_object");
380 fail_unless(
query_refcount(reference) == 1,
"The number of references to string should drop back to 1 but was %d",
query_refcount(reference));
390 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");
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));
420 fail_unless(ob != NULL,
"Should get an object after calling get_object()");
421 fail_unless(ob->
name == NULL,
"Field name has not been nullified by get_object()");
422 fail_unless(ob->
name_pl == NULL,
"Field name_pl has not been nullified by get_object()");
423 fail_unless(ob->
title == NULL,
"Field title has not been nullified by get_object()");
424 fail_unless(ob->
race == NULL,
"Field race has not been nullified by get_object()");
425 fail_unless(ob->
slaying == NULL,
"Field slaying has not been nullified by get_object()");
426 fail_unless(ob->
skill == NULL,
"Field skill has not been nullified by get_object()");
427 fail_unless(ob->
lore == NULL,
"Field lore has not been nullified by get_object()");
428 fail_unless(ob->
msg == NULL,
"Field msg has not been nullified by get_object()");
429 fail_unless(ob->
materialname == NULL,
"Field materialname has not been nullified by get_object()");
430 fail_unless(ob->
prev == NULL,
"Field prev has not been nullified by get_object()");
431 fail_unless(ob->
active_next == NULL,
"Field active_next has not been nullified by get_object()");
432 fail_unless(ob->
active_prev == NULL,
"Field active_prev has not been nullified by get_object()");
435 for (i = 0; i < 1U<<17; i++) {
437 fail_unless(ob != NULL,
"Should get an object after calling get_object() (iteration %l)", i);
438 if (!(i&((1<<13)-1)))
439 LOG(
llevDebug,
"%ldk items created with get_object\n", i>>10);
459 fail_unless(face2 != face1,
"2 opposite direction should provide different faces after update_turn_face");
463 #define IS_OBJECT_ACTIVE(op) (op->active_next || op->active_prev || op == active_objects)
502 fail_unless(!
IS_OBJECT_ACTIVE(ob1),
"Object with absolute speed 0.0 should be inactivated", ob1->
speed);
503 fail_unless(!
IS_OBJECT_ACTIVE(ob2),
"Object with absolute speed 0.0 should be inactivated", ob2->
speed);
504 fail_unless(!
IS_OBJECT_ACTIVE(ob3),
"Object with absolute speed 0.0 should be inactivated", ob3->
speed);
505 fail_unless(!
IS_OBJECT_ACTIVE(ob4),
"Object with absolute speed 0.0 should be inactivated", ob4->
speed);
520 fail_unless(!
IS_OBJECT_ACTIVE(ob1),
"After call to remove_from_active_list, object should be made inactive");
523 #undef IS_OBJECT_ACTIVE
564 fail_unless(((free2 == 0) && (free1 == 0)),
"after creating an object, the count_free() should return 0 (compiled with MEMORY_DEBUG)", free1-1, free2);
566 fail_unless((free2 == free1-1),
"after creating an object, the count_free() should return one less (%d) but returned %d", free1-1, free2);
582 fail_unless((used2 == used1+1),
"after creating an object, the count_used() should return one more (%d) but returned %d", used1-1, used2);
591 int active1, active2;
601 fail_unless((active2 == active1+1),
"after activating an additional object, count_active should return one less %d but returned %d", active1-1, active2);
631 fail_unless(sum == 18,
"Sum of object's inventory should be 18 (30*0.6+10) but was %lu.", sum);
633 fail_unless(ob1->
carrying == 12,
"after call to sub_weight, carrying of ob1 should be 22 but was %d", ob1->
carrying);
681 object *first = NULL;
685 fail_unless(map != NULL,
"get_empty_map returned NULL.");
689 fail_unless(first != NULL,
"create barrel failed");
692 fail_unless(got == first,
"item shouldn't be destroyed");
695 fail_unless(first != NULL,
"create dragon failed");
696 fail_unless(first->
more != NULL,
"no other body part");
699 fail_unless(got == first,
"item shouldn't be destroyed");
701 fail_unless(
GET_MAP_OB(map, 1, 1) == first,
"item isn't on 1,1");
702 fail_unless(
GET_MAP_OB(map, 2, 1) != NULL,
"no item on 2,1");
703 fail_unless(
GET_MAP_OB(map, 2, 1)->head == first,
"head of 2,1 isn't 1,1");
712 object *first = NULL;
713 object *second = NULL;
714 object *third = NULL;
715 object *floor = NULL;
719 fail_unless(map != NULL,
"get_empty_map returned NULL.");
723 fail_unless(floor != NULL,
"create woodfloor failed");
728 fail_unless(got == floor,
"woodfloor shouldn't disappear");
729 fail_unless(floor ==
GET_MAP_OB(map, 3, 3),
"woodfloor should be first object");
732 fail_unless(first != NULL,
"create barrel failed");
737 fail_unless(got == first,
"barrel shouldn't disappear");
738 fail_unless(floor ==
GET_MAP_OB(map, 3, 3),
"woodfloor should still be first object");
739 fail_unless(floor->
above == first,
"barrel should be above floor");
742 fail_unless(second != NULL,
"create gem failed");
748 fail_unless(got == second,
"gem shouldn't disappear");
749 fail_unless(floor ==
GET_MAP_OB(map, 3, 3),
"woodfloor should still be first object");
750 fail_unless(floor->
above == second,
"gem should be above floor");
751 fail_unless(second->
above == first,
"barrel should be above gem");
754 fail_unless(third != NULL,
"create bed_1 failed");
760 fail_unless(got == third,
"bed_1 shouldn't disappear");
761 fail_unless(floor ==
GET_MAP_OB(map, 3, 3),
"woodfloor should still be first object");
762 fail_unless(third->
above == first,
"bed should be below barrel");
763 fail_unless(third->
below == second,
"bed should be above gem");
767 fail_unless(third != NULL,
"create gem failed");
773 fail_unless(got == third,
"gem shouldn't disappear");
775 fail_unless(third->
nrof == 2,
"second gem should have nrof 2");
778 fail_unless(second != NULL,
"create gem failed");
785 fail_unless(got == second,
"modified gem shouldn't disappear");
786 fail_unless(second->
nrof == 1,
"modified gem should have nrof 1");
820 object *first = NULL, *second = NULL, *third = NULL;
821 tag_t tag_first, tag_second, tag_third;
825 fail_unless(map != NULL,
"get_empty_map returned NULL.");
829 fail_unless(first != NULL,
"create barrel failed");
830 tag_first = first->
count;
833 fail_unless(got == first,
"item shouldn't be destroyed");
836 fail_unless(second != NULL,
"create table failed");
839 fail_unless(got == second,
"second item shouldn't be destroyed");
840 tag_second = second->count;
843 fail_unless(third != NULL,
"create 2nd barrel failed");
845 fail_unless(got == third,
"second barrel shouldn't be destroyed");
846 tag_third = third->count;
848 fail_unless(
GET_MAP_OB(map, 0, 0) == first,
"item at 0,0 isn't barrel");
849 fail_unless(
GET_MAP_OB(map, 0, 0)->above == second,
"second item at 0,0 isn't table");
850 fail_unless(
GET_MAP_OB(map, 0, 0)->above->above == third,
"third item at 0,0 isn't barrel");
854 fail_unless(
GET_MAP_OB(map, 0, 0) != first,
"item at 0, 0 is still first?");
855 fail_unless(
was_destroyed(first, tag_first),
"1st barrel should be destroyed");
856 fail_unless(!
was_destroyed(second, tag_second),
"table shouldn't be destroyed");
857 fail_unless(
was_destroyed(third, tag_third),
"2nd barrel should be destroyed");
859 fail_unless(
GET_MAP_OB(map, 0, 0) != NULL,
"no item at 0,0 after replace_insert_ob_in_map");
860 fail_unless(
GET_MAP_OB(map, 0, 0) != second,
"second at bottom at 0,0 after replace_insert_ob_in_map");
861 fail_unless(
GET_MAP_OB(map, 0, 0)->above == second,
"table isn't above new barrel");
862 fail_unless(strcmp(
GET_MAP_OB(map, 0, 0)->arch->name,
"barrel") == 0,
"item at 0,0 is not a barrel after replace_insert_ob_in_map");
870 object *first = NULL;
871 object *second = NULL;
875 fail_unless(first != NULL,
"create gem failed");
879 fail_unless(second != NULL,
"should return an item");
880 fail_unless(second->
nrof == 2,
"2 expected to split");
881 fail_unless(first->
nrof == 3,
"3 should be left");
884 fail_unless(second != NULL,
"should return an item");
888 fail_unless(first == NULL,
"should return NULL");
889 fail_unless(second->
nrof == 3,
"3 should be left");
897 object *first = NULL;
898 object *second = NULL;
901 fail_unless(first != NULL,
"create gem failed");
905 fail_unless(second == first,
"gem shouldn't be destroyed");
908 fail_unless(second == NULL,
"decrease_ob_nr should return NULL");
925 object *container = NULL;
929 fail_unless(item != NULL,
"create gem failed");
934 fail_unless(container != NULL,
"create bookshelf failed");
937 fail_unless(container->
inv == item,
"item not inserted");
938 fail_unless(container->
carrying == 50,
"container should carry 50 and not %d", container->
carrying);
941 fail_unless(container->
carrying == 0,
"container should carry 0 and not %d", container->
carrying);
945 fail_unless(container != NULL,
"create sack failed");
948 fail_unless(container->
inv == item,
"item not inserted");
949 fail_unless(container->
carrying == 45,
"container should carry 45 and not %d", container->
carrying);
1163 fail_unless(pl != NULL,
"couldn't create kobold");
1165 fail_unless(pl->
contr != NULL,
"couldn't alloc contr");
1168 fail_unless(o1 != NULL,
"couldn't find cloak archetype");
1173 fail_unless(val == 1,
"all didn't match cloak");
1175 fail_unless(val == 0,
"unidentified cloak matched title with value %d", val);
1177 fail_unless(val == 0,
"unidentified cloak matched random value with value %d", val);
1181 fail_unless(val != 0,
"identified cloak didn't match title with value %d", val);
1186 fail_unless(val == 2,
"unpaid cloak didn't match unpaid");
1188 fail_unless(val != 0,
"unpaid cloak didn't match cloak with %d", val);
1190 fail_unless(val == 0,
"unpaid cloak matched wrong name %d", val);
1195 Suite *s = suite_create(
"object");
1196 TCase *tc_core = tcase_create(
"Core");
1201 suite_add_tcase(s, tc_core);
1202 tcase_add_test(tc_core, test_can_merge);
1203 tcase_add_test(tc_core, test_sum_weight);
1204 tcase_add_test(tc_core, test_object_get_env_recursive);
1205 tcase_add_test(tc_core, test_get_player_container);
1206 tcase_add_test(tc_core, test_dump_object);
1207 tcase_add_test(tc_core, test_dump_all_objects);
1208 tcase_add_test(tc_core, test_find_object);
1209 tcase_add_test(tc_core, test_find_object_name);
1210 tcase_add_test(tc_core, test_free_all_object_data);
1211 tcase_add_test(tc_core, test_get_owner);
1212 tcase_add_test(tc_core, test_clear_owner);
1213 tcase_add_test(tc_core, test_set_owner);
1214 tcase_add_test(tc_core, test_copy_owner);
1215 tcase_add_test(tc_core, test_reset_object);
1216 tcase_add_test(tc_core, test_clear_object);
1217 tcase_add_test(tc_core, test_copy_object);
1218 tcase_add_test(tc_core, test_get_object);
1219 tcase_add_test(tc_core, test_update_turn_face);
1220 tcase_add_test(tc_core, test_update_ob_speed);
1221 tcase_add_test(tc_core, test_remove_from_active_list);
1222 tcase_add_test(tc_core, test_update_object);
1223 tcase_add_test(tc_core, test_free_object);
1224 tcase_add_test(tc_core, test_count_free);
1225 tcase_add_test(tc_core, test_count_used);
1226 tcase_add_test(tc_core, test_count_active);
1227 tcase_add_test(tc_core, test_sub_weight);
1228 tcase_add_test(tc_core, test_remove_ob);
1229 tcase_add_test(tc_core, test_merge_ob);
1230 tcase_add_test(tc_core, test_insert_ob_in_map_at);
1231 tcase_add_test(tc_core, test_insert_ob_in_map);
1232 tcase_add_test(tc_core, test_replace_insert_ob_in_map);
1233 tcase_add_test(tc_core, test_get_split_ob);
1234 tcase_add_test(tc_core, test_decrease_ob_nr);
1235 tcase_add_test(tc_core, test_add_weight);
1236 tcase_add_test(tc_core, test_insert_ob_in_ob);
1237 tcase_add_test(tc_core, test_check_move_on);
1238 tcase_add_test(tc_core, test_present_arch);
1239 tcase_add_test(tc_core, test_present);
1240 tcase_add_test(tc_core, test_present_in_ob);
1241 tcase_add_test(tc_core, test_present_in_ob_by_name);
1242 tcase_add_test(tc_core, test_present_arch_in_ob);
1243 tcase_add_test(tc_core, test_flag_inv);
1244 tcase_add_test(tc_core, test_unflag_inv);
1245 tcase_add_test(tc_core, test_set_cheat);
1246 tcase_add_test(tc_core, test_find_free_spot);
1247 tcase_add_test(tc_core, test_find_first_free_spot);
1248 tcase_add_test(tc_core, test_get_search_arr);
1249 tcase_add_test(tc_core, test_find_dir);
1250 tcase_add_test(tc_core, test_distance);
1251 tcase_add_test(tc_core, test_find_dir_2);
1252 tcase_add_test(tc_core, test_absdir);
1253 tcase_add_test(tc_core, test_dirdiff);
1254 tcase_add_test(tc_core, test_can_see_monsterP);
1255 tcase_add_test(tc_core, test_can_pick);
1256 tcase_add_test(tc_core, test_object_create_clone);
1257 tcase_add_test(tc_core, test_was_destroyed);
1258 tcase_add_test(tc_core, test_find_obj_by_type_subtype);
1259 tcase_add_test(tc_core, test_get_ob_key_link);
1260 tcase_add_test(tc_core, test_get_ob_key_value);
1261 tcase_add_test(tc_core, test_set_ob_key_value);
1262 tcase_add_test(tc_core, test_item_matched_string);
1272 sr = srunner_create(s);
1273 srunner_set_xml(sr, LOGDIR
"/unit/common/object.xml");
1277 srunner_run_all(sr, CK_ENV);
1278 nf = srunner_ntests_failed(sr);
1280 return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
#define INS_BELOW_ORIGINATOR
void set_owner(object *op, object *owner)
mapstruct * get_empty_map(int sizex, int sizey)
object * object_get_env_recursive(object *op)
void remove_from_active_list(object *op)
object * insert_ob_in_map_at(object *op, mapstruct *m, object *originator, int flag, int x, int y)
int query_refcount(sstring str)
StringBuffer * stringbuffer_new(void)
object * find_object_name(const char *str)
int item_matched_string(object *pl, object *op, const char *name)
signed long sum_weight(object *op)
object * find_object(tag_t i)
END_TEST Suite * object_suite(void)
void remove_ob(object *op)
void clear_owner(object *op)
object * get_player_container(object *op)
const char * materialname
void dump_object(object *op, StringBuffer *sb)
int can_merge(object *ob1, object *ob2)
object * get_owner(object *op)
#define QUERY_FLAG(xyz, p)
#define CLEAR_FLAG(xyz, p)
#define INS_ABOVE_FLOOR_ONLY
object * insert_ob_in_ob(object *op, object *where)
object * get_object(void)
object * insert_ob_in_map(object *op, mapstruct *m, object *originator, int flag)
void copy_owner(object *op, object *clone)
void update_turn_face(object *op)
object * decrease_ob_nr(object *op, uint32 i)
void reset_object(object *op)
void dump_all_objects(void)
void update_ob_speed(object *op)
START_TEST(test_can_merge)
sstring add_string(const char *str)
#define GET_MAP_OB(M, X, Y)
void clear_object(object *op)
void LOG(LogLevel logLevel, const char *format,...)
object * get_split_ob(object *orig_ob, uint32 nr, char *err, size_t size)
void sub_weight(object *op, signed long weight)
#define was_destroyed(op, old_tag)
void copy_object(object *op2, object *op)
void free_object(object *ob)
void replace_insert_ob_in_map(const char *arch_string, object *op)
char * stringbuffer_finish(StringBuffer *sb)
#define IS_OBJECT_ACTIVE(op)