Crossfire Server, Branch 1.12
R12190
|
00001 /* 00002 * static char *rcsid_check_item_c = 00003 * "$Id: check_item.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 common/item.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 00039 void setup(void) { 00040 cctk_setdatadir(BUILD_ROOT "lib"); 00041 cctk_setlog(LOGDIR "/unit/common/item.out"); 00042 cctk_init_std_archetypes(); 00043 init_gods(); 00044 } 00045 00046 void teardown(void) { 00047 /* put any cleanup steps here, they will be run after each testcase */ 00048 } 00049 00050 START_TEST(test_describe_item) { 00051 object *test; 00052 char buf[5000]; 00053 int check; 00054 treasurelist *list; 00055 00056 static const char *archs[] = { 00057 "gem", 00058 "food", 00059 "lantern_1", 00060 "blood", 00061 "ring", 00062 "amulet", 00063 "goblin", 00064 "potion_restoration", 00065 "axe_2", 00066 "elven_bow", 00067 "helmet_of_brilliance", 00068 "holy_avenger", 00069 "scimitar", 00070 "shield", 00071 "fl_corpse", 00072 "booze", 00073 "poison", 00074 "deathshead", 00075 "zombie", 00076 "talisman_evocation", 00077 "talisman_sorcery", 00078 "dragon", 00079 "titan", 00080 "speedboots", 00081 "t_star1", 00082 "girdle_con", 00083 "god_finger", 00084 "shining_finger", 00085 "high_boots_w", 00086 "plate_mail", 00087 "robe", 00088 "scale_mail", 00089 "DShieldms", 00090 "holy_shield", 00091 NULL }; 00092 static const char *arch_results[] = { 00093 "", 00094 "(food+200)", 00095 "(glowing)", 00096 "", 00097 "", 00098 "", 00099 "(slow movement)(wield weapon)(archer)(wear armour)(wear ring)", 00100 "", 00101 "(dam+6)(weapon speed 10)(Attacks: physical)", 00102 "(wc+1)(dam+15)(Attacks: physical)", 00103 "(Int+2)(Pow+2)(ac+2)(item_power +5)(magic+1)(armour +5)", 00104 "(Str+1)(Wis+2)(Cha+2)(dam+15)(item_power +25)(weapon speed 6)(Attacks: weaponmagic, blinding)(resist magic +30)(resist drain +100)", 00105 "(dam+8)(weapon speed 8)(Attacks: physical)", 00106 "(ac+1)(armour +5)", 00107 "(food+600)", 00108 "(food+100)(slay vial_poison:poison)", 00109 "", 00110 "(extremely fast movement)(undead)(spellcaster)(Spell abilities:)(paralyze)(fear ability)(cause black death)(cause red death)(face of death)(meteor swarm)(hellfire)(burning hands)(large fireball)(mass confusion)(negative energy bolt)(negative energy ball)(slow ability)(Attacks: physical, cold)(armour +75)(resist magic +100)(resist fire +100)(resist electricity +90)(resist cold +100)(resist confusion +100)(resist acid +90)(resist drain +100)(resist weaponmagic +80)(resist ghosthit +100)(resist poison +100)(resist slow +100)(resist paralyzation +100)(resist fear +100)(resist cancellation +65)(resist depletion +100)(resist death +100)(resist chaos +100)(resist counterspell +65)(resist god power +80)(resist blindness +100)", 00111 "(slow movement)(undead)(Attacks: physical)(resist cold +50)(resist fear +100)", 00112 "", 00113 "", 00114 "(normal movement)(see invisible)(spellcaster)(Spell abilities:)(burning hands ability)(medium fireball ability)(fear ability)(Attacks: physical)(resist fire +100)(resist cold -100)(resist confusion -100)(resist fear +100)(resist blindness +50)", 00115 "(fast movement)(see invisible)(wield weapon)(archer)(wear armour)(wear ring)(read scroll)(spellcaster)(Spell abilities:)(paralyze)(fear ability)(small lightning)(large lightning)(slow ability)(resist magic +50)(resist electricity +100)(resist fear +100)", 00116 "(speed +6)(item_power +6)(armour +3)", 00117 "(dam+3)(weapon speed 2)(Attacks: physical)", 00118 "(Con+2)(item_power +1)", 00119 "(Str+2)(Dex-1)(dam+3)(item_power +2)(armour +3)", 00120 "(Str+2)(dam+3)(item_power +1)(armour +3)", 00121 "(Cha+1)(ac+1)(Spell regen penalty 4)(armour +4)(resist blindness +1)", 00122 "(ac+5)(Max speed 0.70)(Spell regen penalty 30)(armour +40)", 00123 "(ac+1)(Max speed 1.20)", 00124 "(ac+3)(Max speed 0.90)(Spell regen penalty 10)(armour +20)", 00125 "(Cha-5)(ac+7)(item_power +10)(reflect spells)(reflect missiles)(armour +15)(resist fire +30)(resist drain +100)(resist ghosthit +80)", 00126 "(ac+4)(item_power +6)(armour +10)(resist drain +100)(resist ghosthit +50)", 00127 NULL }; 00128 00129 /* if you change the order, the result will quite certainly change, as the generation depends on the value returned 00130 * by rand() - changing the order changes the item generated... 00131 */ 00132 static const char *treasures[] = { 00133 "random_knowledge", 00134 "missile_weapons", 00135 "random_talisman", 00136 "rare_weapons", 00137 "random_food", 00138 "random_artifact", 00139 "random_read", 00140 "random_amulet", 00141 "random_artifact", 00142 "random_amulet", 00143 "random_artifact", 00144 "standard_old", 00145 NULL 00146 }; 00147 static const char *treasure_results[] = { 00148 "", 00149 "(wc+1)(dam+2)(Attacks: physical)", 00150 "", 00151 "(dam+6)(weapon speed 9)(Attacks: physical)", 00152 "(food+200)", 00153 "(Con+2)(Cha-1)(dam+10)(item_power +15)(weapon speed 5)(regeneration+1)(Attacks: weaponmagic)(resist drain +100)(resist poison +30)", 00154 "", 00155 "", 00156 "(Str+1)(dam+9)(item_power +20)(weapon speed 6)(regeneration+1)(Attacks: electricity, drain)(resist magic +30)(resist electricity +30)(resist drain +100)", 00157 "", 00158 "(Str+1)(armour +3)", 00159 "", 00160 NULL 00161 }; 00162 00163 for (check = 0; archs[check] != NULL; check++) { 00164 test = cctk_create_game_object(archs[check]); 00165 fail_unless(test != NULL, "couldn't create arch %s", archs[check]); 00166 SET_FLAG(test, FLAG_IDENTIFIED); 00167 describe_item(test, NULL, buf, sizeof(buf)); 00168 00169 /* if you're adding items, uncomment that so make finding the good value easier. */ 00170 /* 00171 if (strcmp(buf, arch_results[check])) 00172 printf("describe_item(%s) returned \"%s\" instead of \"%s\"\n", archs[check], buf, arch_results[check]); 00173 */ 00174 00175 fail_unless(strcmp(buf, arch_results[check]) == 0, "describe_item(%s) returned \"%s\" instead of \"%s\"", archs[check], buf, arch_results[check]); 00176 00177 free_object(test); 00178 } 00179 00180 /* we initialize the random generator to always be able to reproduce, and we use rand() in case RANDOM is something else. */ 00181 srand(100); 00182 for (check = 0; treasures[check] != NULL; check++) { 00183 list = find_treasurelist(treasures[check]); 00184 fail_unless(list != NULL, "couldn't find treasure list %s", treasures[check]); 00185 test = generate_treasure(list, 50); 00186 fail_if(test == NULL, "couldn't create item from treasure list %s", treasures[check]); 00187 SET_FLAG(test, FLAG_IDENTIFIED); 00188 describe_item(test, NULL, buf, sizeof(buf)); 00189 00190 /* if you're adding lists, uncomment that so make finding the good value easier. */ 00191 /* 00192 if (strcmp(buf, treasure_results[check])) 00193 printf("Item %d describe_item(treasure %s) returned \"%s\" instead of \"%s\"\n", check, treasures[check], buf, treasure_results[check]); 00194 */ 00195 00196 fail_unless(strcmp(buf, treasure_results[check]) == 0, "describe_item(treasure %s) returned \"%s\" instead of \"%s\"", treasures[check], buf, treasure_results[check]); 00197 00198 free_object(test); 00199 00200 } 00201 } 00202 END_TEST 00203 00204 Suite *item_suite(void) { 00205 Suite *s = suite_create("item"); 00206 TCase *tc_core = tcase_create("Core"); 00207 00208 /*setup and teardown will be called before each test in testcase 'tc_core' */ 00209 tcase_add_checked_fixture(tc_core, setup, teardown); 00210 00211 suite_add_tcase(s, tc_core); 00212 tcase_add_test(tc_core, test_describe_item); 00213 00214 return s; 00215 } 00216 00217 int main(void) { 00218 int nf; 00219 Suite *s = item_suite(); 00220 SRunner *sr = srunner_create(s); 00221 00222 srunner_set_xml(sr, LOGDIR "/unit/common/item.xml"); 00223 srunner_set_log(sr, LOGDIR "/unit/common/item.out"); 00224 srunner_run_all(sr, CK_ENV); /*verbosity from env variable*/ 00225 nf = srunner_ntests_failed(sr); 00226 srunner_free(sr); 00227 return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 00228 }