Crossfire Server, Branch 1.12
R12190
|
00001 /* 00002 * static char *rcsid_check_attack_c = 00003 * "$Id: check_attack.c 11578 2009-02-23 22:02:27Z lalo $"; 00004 */ 00005 00006 /* 00007 * CrossFire, A Multiplayer game for X-windows 00008 * 00009 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team 00010 * Copyright (C) 1992 Frank Tore Johansen 00011 * 00012 * This program is free software; you can redistribute it and/or modify 00013 * it under the terms of the GNU General Public License as published by 00014 * the Free Software Foundation; either version 2 of the License, or 00015 * (at your option) any later version. 00016 * 00017 * This program is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU General Public License for more details. 00021 * 00022 * You should have received a copy of the GNU General Public License 00023 * along with this program; if not, write to the Free Software 00024 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00025 * 00026 * The authors can be reached via e-mail at crossfire-devel@real-time.com 00027 */ 00028 00029 /* 00030 * This is the unit tests file for server/attack.c 00031 */ 00032 00033 #include <global.h> 00034 #include <stdlib.h> 00035 #include <check.h> 00036 #include <loader.h> 00037 #include <toolkit_common.h> 00038 #include <sproto.h> 00039 00040 void setup(void) { 00041 } 00042 00043 void teardown(void) { 00044 /* put any cleanup steps here, they will be run after each testcase */ 00045 } 00046 00047 START_TEST(test_hit_player) { 00048 object *victim = NULL; 00049 object *hitter = NULL; 00050 object *floor = NULL; 00051 mapstruct *map = NULL; 00052 archetype *deplete = NULL; 00053 int test; 00054 00055 map = get_empty_map(5, 5); 00056 floor = create_archetype("battleground"); 00057 fail_unless(floor != NULL, "can't find archetype battleground"); 00058 insert_ob_in_map_at(floor, map, NULL, 0, 0, 0); 00059 floor = create_archetype("battleground"); 00060 fail_unless(floor != NULL, "can't find archetype battleground"); 00061 insert_ob_in_map_at(floor, map, NULL, 0, 1, 0); 00062 00063 deplete = find_archetype(ARCH_DEPLETION); 00064 fail_unless(deplete != NULL, "can't find archetype %s", ARCH_DEPLETION); 00065 00066 victim = create_archetype("kobold"); 00067 fail_unless(victim != NULL, "couldn't create kobold"); 00068 fail_unless(victim->inv == NULL, "kobold shouldn't have an inventory"); 00069 victim->stats.hp = 5000; 00070 victim->stats.maxhp = 5000; 00071 victim->resist[ATNR_DEPLETE] = 100; 00072 victim->resist[ATNR_FIRE] = 100; 00073 insert_ob_in_map_at(victim, map, NULL, 0, 0, 0); 00074 hitter = create_archetype("sword"); 00075 fail_unless(hitter != NULL, "couldn't create sword"); 00076 hitter->attacktype = AT_DEPLETE|AT_FIRE; 00077 hitter->stats.dam = 100; 00078 hitter->map = map; 00079 insert_ob_in_map_at(hitter, map, NULL, 0, 1, 0); 00080 00081 fail_unless(present_arch_in_ob(deplete, victim) == NULL, "victim shouldn't be depleted before being attacked"); 00082 00083 for (test = 0; test < 100; test++) { 00084 hit_player(victim, hitter->stats.dam, hitter, hitter->attacktype, 0); 00085 fail_unless(victim->stats.hp == victim->stats.maxhp, "victim should have %d hp and not %d.", victim->stats.maxhp, victim->stats.hp); 00086 } 00087 fail_unless(victim->inv == NULL, "kobold shouldn't have an inventory after attacked"); 00088 fail_unless(present_arch_in_ob(deplete, victim) == NULL, "victim shouldn't be depleted when slaying not set"); 00089 00090 hitter->slaying = add_string(victim->race); 00091 victim->resist[ATNR_FIRE] = 95; 00092 for (test = 0; test < 100 && present_arch_in_ob(deplete, victim) == NULL; test++) { 00093 hit_player(victim, hitter->stats.dam, hitter, hitter->attacktype, 0); 00094 } 00095 fail_unless(present_arch_in_ob(deplete, victim) != NULL, "victim should be depleted when slaying is set"); 00096 fail_unless(victim->stats.hp != victim->stats.maxhp, "victim shouldn't have %d hp", victim->stats.hp); 00097 } 00098 END_TEST 00099 00100 Suite *attack_suite(void) { 00101 Suite *s = suite_create("attack"); 00102 TCase *tc_core = tcase_create("Core"); 00103 00104 /*setup and teardown will be called before each test in testcase 'tc_core' */ 00105 tcase_add_checked_fixture(tc_core, setup, teardown); 00106 00107 suite_add_tcase(s, tc_core); 00108 tcase_add_test(tc_core, test_hit_player); 00109 00110 return s; 00111 } 00112 00113 int main(void) { 00114 int nf; 00115 Suite *s = attack_suite(); 00116 SRunner *sr = srunner_create(s); 00117 00118 /* If you wish to debug the program, uncomment this line. */ 00119 /*srunner_set_fork_status (sr, CK_NOFORK); */ 00120 00121 settings.debug = 0; 00122 init(0, NULL); 00123 00124 srunner_set_xml(sr, LOGDIR "/unit/server/attack.xml"); 00125 srunner_set_log(sr, LOGDIR "/unit/server/attack.out"); 00126 srunner_run_all(sr, CK_ENV); /*verbosity from env variable*/ 00127 nf = srunner_ntests_failed(sr); 00128 srunner_free(sr); 00129 return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 00130 }