| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
#include <check.h> |
| 29 |
#include <global.h> |
| 30 |
#include <sproto.h> |
| 31 |
#include <stdlib.h> |
| 32 |
#include <string.h> |
| 33 |
|
| 34 |
static object *find_arch_at(mapstruct *map, int x, int y, const char *arch_name) { |
| 35 |
FOR_MAP_PREPARE(map, x, y, op) { |
| 36 |
if (strcmp(op->arch->name, arch_name) == 0) { |
| 37 |
return op; |
| 38 |
} |
| 39 |
} FOR_MAP_FINISH(); |
| 40 |
return NULL; |
| 41 |
} |
| 42 |
|
| 43 |
static void setup(void) { |
| 44 |
} |
| 45 |
|
| 46 |
static void teardown(void) { |
| 47 |
} |
| 48 |
|
| 49 |
START_TEST(test_merge) { |
| 50 |
mapstruct *map1; |
| 51 |
archetype *scroll_arch; |
| 52 |
archetype *food_arch; |
| 53 |
object *scroll1; |
| 54 |
object *scroll2; |
| 55 |
object *food1; |
| 56 |
object *food2; |
| 57 |
|
| 58 |
map1 = ready_map_name("/world/world_103_128", 0); |
| 59 |
fail_unless(map1 != NULL, "cannot load map /world/world_103_128"); |
| 60 |
|
| 61 |
scroll_arch = find_archetype("scroll_new"); |
| 62 |
fail_unless(scroll_arch != NULL, "cannot find archetype scroll_new"); |
| 63 |
|
| 64 |
food_arch = find_archetype("food"); |
| 65 |
fail_unless(food_arch != NULL, "cannot find archetype food"); |
| 66 |
|
| 67 |
scroll1 = object_create_arch(scroll_arch); |
| 68 |
fail_unless(scroll1 != NULL, "cannot create object scroll_new"); |
| 69 |
|
| 70 |
scroll2 = object_create_arch(scroll_arch); |
| 71 |
fail_unless(scroll2 != NULL, "cannot create object scroll_new"); |
| 72 |
|
| 73 |
food1 = object_create_arch(food_arch); |
| 74 |
fail_unless(food1 != NULL, "cannot create object food"); |
| 75 |
|
| 76 |
food2 = object_create_arch(food_arch); |
| 77 |
fail_unless(food2 != NULL, "cannot create object food"); |
| 78 |
|
| 79 |
food1 = object_insert_in_ob(food1, scroll1); |
| 80 |
|
| 81 |
food2 = object_insert_in_ob(food2, scroll2); |
| 82 |
|
| 83 |
fail_unless(find_arch_at(map1, 4, 3, "scroll_new") == NULL, "map initially contains a scroll"); |
| 84 |
fail_unless(find_arch_at(map1, 4, 3, "food") == NULL, "map initially contains a food"); |
| 85 |
|
| 86 |
scroll1 = object_insert_in_map_at(scroll1, map1, NULL, 0, 4, 3); |
| 87 |
fail_unless(scroll1 != NULL, "scroll could not be added to the map"); |
| 88 |
|
| 89 |
fail_unless(find_arch_at(map1, 4, 3, "scroll_new") == scroll1, "scroll disappeared"); |
| 90 |
fail_unless(find_arch_at(map1, 4, 3, "food") == NULL, "map contains a food"); |
| 91 |
|
| 92 |
scroll2 = object_insert_in_map_at(scroll2, map1, NULL, 0, 4, 3); |
| 93 |
fail_unless(scroll2 != NULL, "scroll could not be added to the map"); |
| 94 |
|
| 95 |
fail_unless(find_arch_at(map1, 4, 3, "scroll_new") == scroll2, "scroll disappeared"); |
| 96 |
fail_unless(find_arch_at(map1, 4, 3, "food") == NULL, "map contains a food"); |
| 97 |
|
| 98 |
fail_unless(scroll2->nrof == 2, "scrolls didn't merge"); |
| 99 |
fail_unless(QUERY_FLAG(scroll1, FLAG_FREED), "scroll wasn't freed"); |
| 100 |
} |
| 101 |
END_TEST |
| 102 |
|
| 103 |
static Suite *bug_suite(void) { |
| 104 |
Suite *s = suite_create("bug"); |
| 105 |
TCase *tc_core = tcase_create("Core"); |
| 106 |
|
| 107 |
tcase_add_checked_fixture(tc_core, setup, teardown); |
| 108 |
|
| 109 |
suite_add_tcase(s, tc_core); |
| 110 |
tcase_add_test(tc_core, test_merge); |
| 111 |
tcase_set_timeout(tc_core, 0); |
| 112 |
|
| 113 |
return s; |
| 114 |
} |
| 115 |
|
| 116 |
int main(void) { |
| 117 |
int nf; |
| 118 |
Suite *s = bug_suite(); |
| 119 |
SRunner *sr = srunner_create(s); |
| 120 |
|
| 121 |
srunner_set_fork_status(sr, CK_NOFORK); |
| 122 |
init(0, NULL); |
| 123 |
|
| 124 |
srunner_set_xml(sr, LOGDIR "/bugs/bugtrack/free_objects.xml"); |
| 125 |
srunner_set_log(sr, LOGDIR "/bugs/bugtrack/free_objects.out"); |
| 126 |
srunner_run_all(sr, CK_ENV); |
| 127 |
nf = srunner_ntests_failed(sr); |
| 128 |
srunner_free(sr); |
| 129 |
return nf == 0 ? EXIT_SUCCESS : EXIT_FAILURE; |
| 130 |
} |