| 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 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
#include <global.h> |
| 33 |
#include <stdlib.h> |
| 34 |
#include <check.h> |
| 35 |
#include <loader.h> |
| 36 |
#include <toolkit_common.h> |
| 37 |
#include <sproto.h> |
| 38 |
|
| 39 |
|
| 40 |
static void setup(void) { |
| 41 |
} |
| 42 |
|
| 43 |
static void teardown(void) { |
| 44 |
|
| 45 |
} |
| 46 |
|
| 47 |
static object *do_monster_change(object *op, mapstruct *map, short expect, const char *new_name); |
| 48 |
|
| 49 |
START_TEST(test_monster_change) { |
| 50 |
object *monster = NULL, *tmp = NULL; |
| 51 |
object *floor = NULL; |
| 52 |
mapstruct *map = NULL; |
| 53 |
int x, y; |
| 54 |
|
| 55 |
map = get_empty_map(5, 5); |
| 56 |
|
| 57 |
for (x = 0; x < 5; ++x) |
| 58 |
{ |
| 59 |
for (y = 0; y < 5; ++y) |
| 60 |
{ |
| 61 |
floor = create_archetype("battleground"); |
| 62 |
fail_unless(floor != NULL, "cannot find arch battleground"); |
| 63 |
object_insert_in_map_at(floor, map, NULL, 0, x, y); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
monster = create_archetype("kobold"); |
| 68 |
fail_unless(monster != NULL, "failed to find arch kobold"); |
| 69 |
|
| 70 |
monster->other_arch = find_archetype("ogre"); |
| 71 |
|
| 72 |
fail_unless(monster->other_arch != NULL, "Could not find other_arch to transform object %s.", monster->name); |
| 73 |
monster->map = map; |
| 74 |
monster->stats.food = 1; |
| 75 |
object_insert_in_map_at(monster, map, NULL, 0 , 0 , 0); |
| 76 |
tmp = do_monster_change(monster, map, 1, "ogre"); |
| 77 |
fail_unless(monster != tmp, "We got the same object back when we should have gotten a new one!"); |
| 78 |
|
| 79 |
monster = tmp; |
| 80 |
monster->other_arch = find_archetype("angel_knight"); |
| 81 |
|
| 82 |
fail_unless(monster->other_arch != NULL, "Could not find other_arch to transform object %s.", monster->name); |
| 83 |
monster->stats.food = 1; |
| 84 |
tmp = do_monster_change(monster, map, 1, "angel_knight"); |
| 85 |
fail_unless(monster != tmp, "We got the same object back when we should have gotten a new one!"); |
| 86 |
|
| 87 |
monster = tmp; |
| 88 |
monster->other_arch = find_archetype("bear"); |
| 89 |
|
| 90 |
fail_unless(monster->other_arch != NULL, "Could not find other_arch to transform object %s.", monster->name); |
| 91 |
monster->stats.food = 1; |
| 92 |
tmp = do_monster_change(monster, map, 1, "bear"); |
| 93 |
fail_unless(monster != tmp, "We got the same object back when we should have gotten a new one!"); |
| 94 |
|
| 95 |
monster = tmp; |
| 96 |
monster->other_arch = find_archetype("bee"); |
| 97 |
|
| 98 |
fail_unless(monster->other_arch != NULL, "Could not find other_arch to transform object %s.", monster->name); |
| 99 |
monster->stats.food = 1; |
| 100 |
tmp = do_monster_change(monster, map, 1, "bee"); |
| 101 |
fail_unless(monster != tmp, "We got the same object back when we should have gotten a new one!"); |
| 102 |
|
| 103 |
monster = tmp; |
| 104 |
monster->other_arch = find_archetype("Greater_Demon"); |
| 105 |
|
| 106 |
fail_unless(monster->other_arch != NULL, "Could not find other_arch to transform object %s.", monster->name); |
| 107 |
monster->stats.food = 1; |
| 108 |
tmp = do_monster_change(monster, map, 0, "Greater_Demon"); |
| 109 |
fail_unless(monster == tmp, "We expected to get the same monster, but got a different one."); |
| 110 |
} |
| 111 |
END_TEST |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
static object *do_monster_change(object *op, mapstruct *map, short expect, const char *new_name) |
| 129 |
{ |
| 130 |
change_object(op); |
| 131 |
if (expect) |
| 132 |
|
| 133 |
fail_unless(QUERY_FLAG(op, FLAG_FREED) || QUERY_FLAG(op, FLAG_REMOVED), "original object not removed on expected success!"); |
| 134 |
else |
| 135 |
{ |
| 136 |
|
| 137 |
fail_unless(!QUERY_FLAG(op, FLAG_FREED) && !QUERY_FLAG(op, FLAG_FREED), "Expected failure, was successful in change!"); |
| 138 |
return op; |
| 139 |
} |
| 140 |
|
| 141 |
for (int x = 0; x < 5; ++x) |
| 142 |
for (int y = 0; y < 5; ++y) |
| 143 |
{ |
| 144 |
|
| 145 |
op = map_find_by_flag(map, x, y, FLAG_MONSTER); |
| 146 |
if (op != NULL) |
| 147 |
{ |
| 148 |
|
| 149 |
|
| 150 |
goto no_more_looping; |
| 151 |
} |
| 152 |
} |
| 153 |
no_more_looping: |
| 154 |
|
| 155 |
fail_unless(op != NULL, "Could not find new object %s in the map.", new_name); |
| 156 |
return op; |
| 157 |
} |
| 158 |
|
| 159 |
static Suite *change_suite(void) { |
| 160 |
Suite *s = suite_create("change_monster"); |
| 161 |
TCase *tc_core = tcase_create("Core"); |
| 162 |
|
| 163 |
|
| 164 |
tcase_add_checked_fixture(tc_core, setup, teardown); |
| 165 |
|
| 166 |
suite_add_tcase(s, tc_core); |
| 167 |
tcase_add_test(tc_core, test_monster_change); |
| 168 |
|
| 169 |
return s; |
| 170 |
} |
| 171 |
|
| 172 |
int main(void) { |
| 173 |
int nf; |
| 174 |
Suite *s = change_suite(); |
| 175 |
SRunner *sr= srunner_create(s); |
| 176 |
|
| 177 |
|
| 178 |
srunner_set_fork_status (sr, CK_NOFORK); |
| 179 |
|
| 180 |
settings.debug = 0; |
| 181 |
init(0, NULL); |
| 182 |
|
| 183 |
srunner_set_xml(sr, LOGDIR "/unit/server/monster_change.xml"); |
| 184 |
srunner_set_log(sr, LOGDIR "/unit/server/monster_change.out"); |
| 185 |
srunner_run_all(sr, CK_ENV); |
| 186 |
nf = srunner_ntests_failed(sr); |
| 187 |
srunner_free(sr); |
| 188 |
return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; |
| 189 |
} |