| 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 <stdlib.h> |
| 34 |
#include <check.h> |
| 35 |
#include <global.h> |
| 36 |
#include <toolkit_common.h> |
| 37 |
|
| 38 |
static void setup(void) { |
| 39 |
cctk_setdatadir(BUILD_ROOT "lib"); |
| 40 |
cctk_setlog(LOGDIR "/unit/common/object.out"); |
| 41 |
printf("set log to %s\n", LOGDIR"/unit/common/object.out"); |
| 42 |
cctk_init_std_archetypes(); |
| 43 |
} |
| 44 |
|
| 45 |
static void teardown(void) { |
| 46 |
|
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
START_TEST(test_treasurelist_find_matching_type) { |
| 71 |
#define NUM_TREASURE_LISTS 2 |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
const char *treasurelists[NUM_TREASURE_LISTS] = {"monk_class_items", |
| 77 |
"monk_class_items"}; |
| 78 |
const char *items[NUM_TREASURE_LISTS][100] = { { |
| 79 |
#if 0 |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
"skill_missile_weapon_9", |
| 84 |
"skill_sword_9", "skill_axe_9", "skill_blunt_weapon_9", |
| 85 |
"skill_spear_9", "skill_unarmed_combat_3", "skill_armor_3", |
| 86 |
"skill_dodge_3", "skill_air_magic_8", "skill_fire_magic_8", |
| 87 |
"skill_water_magic_8", "skill_earth_magic_8", "skill_divine_power_5", |
| 88 |
"skill_trap_5", "skill_thievery_5", "skill_persuasion_6", |
| 89 |
"skill_acrobatics_3", "skill_literacy_4", "skill_weaponsmith_9", |
| 90 |
"skill_armorer_4", "skill_jeweler_8", "skill_alchemy_8", |
| 91 |
"skill_bowyer_9", "skill_thaumaturgy_8", "skill_woodsman_5", |
| 92 |
#endif |
| 93 |
|
| 94 |
"skill_sense_curse", "skill_sense_magic", "skill_meditation", |
| 95 |
"skill_karate","skill_praying","skill_missile_weapon", |
| 96 |
"skill_punching","skill_literacy","skill_use_magic_item", |
| 97 |
"skill_remove_trap","skill_find_traps","skill_throwing", |
| 98 |
NULL |
| 99 |
}, |
| 100 |
{ NULL } |
| 101 |
}; |
| 102 |
int types[NUM_TREASURE_LISTS] = {SKILL, HOLY_ALTAR }; |
| 103 |
int tr; |
| 104 |
|
| 105 |
for (tr=0; tr < NUM_TREASURE_LISTS; tr++) { |
| 106 |
struct treasureliststruct *randomitems; |
| 107 |
int *results=NULL, list_size; |
| 108 |
objectlink *ol; |
| 109 |
|
| 110 |
randomitems = find_treasurelist(treasurelists[tr]); |
| 111 |
|
| 112 |
fail_unless(randomitems != NULL, "Could not find treasurelist %s", |
| 113 |
treasurelists[tr]); |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
for (list_size=0; items[tr][list_size] != NULL; list_size++) ; |
| 119 |
|
| 120 |
if (list_size) |
| 121 |
results = calloc (list_size, sizeof(*results)); |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
ol = treasurelist_find_matching_type(randomitems, types[tr], TRUE); |
| 128 |
|
| 129 |
fail_if(ol && (list_size == 0), |
| 130 |
"On test %d, should have returned null but did not", tr); |
| 131 |
|
| 132 |
fail_if((ol == NULL) && (list_size != 0), |
| 133 |
"On test %d, should have returned results but returned NULL", |
| 134 |
tr); |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
if ((ol !=NULL) && (list_size != 0)) { |
| 141 |
int i; |
| 142 |
objectlink *oltmp; |
| 143 |
|
| 144 |
for (oltmp = ol; oltmp != NULL; oltmp = oltmp->next) { |
| 145 |
fail_if(oltmp->ob == NULL, |
| 146 |
"On test %d, found NULL object on linked list", tr); |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
for (i=0; i < list_size; i++) { |
| 153 |
if (!strcmp(items[tr][i], oltmp->ob->arch->name)) { |
| 154 |
results[i]++; |
| 155 |
break; |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
fail_if(i == list_size, |
| 161 |
"On test %d, did not find match for %s", tr, |
| 162 |
oltmp->ob->arch->name); |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
for (i=0; i < list_size; i++) { |
| 172 |
fail_if(results[i] == 0, "On test %d, got 0 matches for %s", |
| 173 |
tr, items[tr][i]); |
| 174 |
} |
| 175 |
} |
| 176 |
free(results); |
| 177 |
if (ol) free_objectlink(ol); |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
END_TEST |
| 184 |
|
| 185 |
static Suite *treasure_suite(void) { |
| 186 |
Suite *s = suite_create("treasure"); |
| 187 |
TCase *tc_core = tcase_create("Core"); |
| 188 |
|
| 189 |
|
| 190 |
tcase_add_checked_fixture(tc_core, setup, teardown); |
| 191 |
|
| 192 |
suite_add_tcase(s, tc_core); |
| 193 |
tcase_add_test(tc_core, test_treasurelist_find_matching_type); |
| 194 |
|
| 195 |
return s; |
| 196 |
} |
| 197 |
|
| 198 |
int main(void) { |
| 199 |
int nf; |
| 200 |
Suite *s = treasure_suite(); |
| 201 |
SRunner *sr = srunner_create(s); |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
srunner_set_fork_status(sr, CK_NOFORK); |
| 206 |
|
| 207 |
srunner_set_xml(sr, LOGDIR "/unit/common/treasure.xml"); |
| 208 |
srunner_set_log(sr, LOGDIR "/unit/common/treasure.out"); |
| 209 |
srunner_run_all(sr, CK_ENV); |
| 210 |
nf = srunner_ntests_failed(sr); |
| 211 |
srunner_free(sr); |
| 212 |
return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; |
| 213 |
} |