| 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 |
|
| 33 |
#include <global.h> |
| 34 |
#include <stdlib.h> |
| 35 |
#include <check.h> |
| 36 |
#include <loader.h> |
| 37 |
#include <toolkit_common.h> |
| 38 |
#include <sproto.h> |
| 39 |
|
| 40 |
static void setup(void) { |
| 41 |
} |
| 42 |
|
| 43 |
static void teardown(void) { |
| 44 |
|
| 45 |
} |
| 46 |
|
| 47 |
START_TEST(test_hit_player) { |
| 48 |
object *victim = NULL; |
| 49 |
object *hitter = NULL; |
| 50 |
object *floor = NULL; |
| 51 |
mapstruct *map = NULL; |
| 52 |
archetype *deplete = NULL; |
| 53 |
int test; |
| 54 |
|
| 55 |
map = get_empty_map(5, 5); |
| 56 |
floor = create_archetype("battleground"); |
| 57 |
fail_unless(floor != NULL, "can't find archetype battleground"); |
| 58 |
object_insert_in_map_at(floor, map, NULL, 0, 0, 0); |
| 59 |
floor = create_archetype("battleground"); |
| 60 |
fail_unless(floor != NULL, "can't find archetype battleground"); |
| 61 |
object_insert_in_map_at(floor, map, NULL, 0, 1, 0); |
| 62 |
|
| 63 |
deplete = find_archetype(ARCH_DEPLETION); |
| 64 |
fail_unless(deplete != NULL, "can't find archetype %s", ARCH_DEPLETION); |
| 65 |
|
| 66 |
victim = create_archetype("kobold"); |
| 67 |
fail_unless(victim != NULL, "couldn't create kobold"); |
| 68 |
fail_unless(victim->inv == NULL, "kobold shouldn't have an inventory"); |
| 69 |
victim->stats.hp = 5000; |
| 70 |
victim->stats.maxhp = 5000; |
| 71 |
victim->resist[ATNR_DEPLETE] = 100; |
| 72 |
victim->resist[ATNR_FIRE] = 100; |
| 73 |
object_insert_in_map_at(victim, map, NULL, 0, 0, 0); |
| 74 |
hitter = create_archetype("sword"); |
| 75 |
fail_unless(hitter != NULL, "couldn't create sword"); |
| 76 |
hitter->attacktype = AT_DEPLETE|AT_FIRE; |
| 77 |
hitter->stats.dam = 100; |
| 78 |
hitter->map = map; |
| 79 |
object_insert_in_map_at(hitter, map, NULL, 0, 1, 0); |
| 80 |
|
| 81 |
fail_unless(arch_present_in_ob(deplete, victim) == NULL, "victim shouldn't be depleted before being attacked"); |
| 82 |
|
| 83 |
for (test = 0; test < 100; test++) { |
| 84 |
hit_player(victim, hitter->stats.dam, hitter, hitter->attacktype, 0); |
| 85 |
fail_unless(victim->stats.hp == victim->stats.maxhp, "victim should have %d hp and not %d.", victim->stats.maxhp, victim->stats.hp); |
| 86 |
} |
| 87 |
fail_unless(victim->inv == NULL, "kobold shouldn't have an inventory after attacked"); |
| 88 |
fail_unless(arch_present_in_ob(deplete, victim) == NULL, "victim shouldn't be depleted when slaying not set"); |
| 89 |
|
| 90 |
hitter->slaying = add_string(victim->race); |
| 91 |
victim->resist[ATNR_FIRE] = 95; |
| 92 |
for (test = 0; test < 100 && arch_present_in_ob(deplete, victim) == NULL; test++) { |
| 93 |
hit_player(victim, hitter->stats.dam, hitter, hitter->attacktype, 0); |
| 94 |
} |
| 95 |
fail_unless(arch_present_in_ob(deplete, victim) != NULL, "victim should be depleted when slaying is set"); |
| 96 |
fail_unless(victim->stats.hp != victim->stats.maxhp, "victim shouldn't have %d hp", victim->stats.hp); |
| 97 |
} |
| 98 |
END_TEST |
| 99 |
|
| 100 |
static Suite *attack_suite(void) { |
| 101 |
Suite *s = suite_create("attack"); |
| 102 |
TCase *tc_core = tcase_create("Core"); |
| 103 |
|
| 104 |
|
| 105 |
tcase_add_checked_fixture(tc_core, setup, teardown); |
| 106 |
|
| 107 |
suite_add_tcase(s, tc_core); |
| 108 |
tcase_add_test(tc_core, test_hit_player); |
| 109 |
|
| 110 |
return s; |
| 111 |
} |
| 112 |
|
| 113 |
int main(void) { |
| 114 |
int nf; |
| 115 |
Suite *s = attack_suite(); |
| 116 |
SRunner *sr = srunner_create(s); |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
settings.debug = 0; |
| 122 |
init(0, NULL); |
| 123 |
|
| 124 |
srunner_set_xml(sr, LOGDIR "/unit/server/attack.xml"); |
| 125 |
srunner_set_log(sr, LOGDIR "/unit/server/attack.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 |
} |