| 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 |
#include <check.h> |
| 29 |
#include <global.h> |
| 30 |
#include <sproto.h> |
| 31 |
#include <stdlib.h> |
| 32 |
#include <string.h> |
| 33 |
|
| 34 |
static void setup(void) { |
| 35 |
} |
| 36 |
|
| 37 |
static void teardown(void) { |
| 38 |
} |
| 39 |
|
| 40 |
START_TEST(test_weight_reduction) { |
| 41 |
|
| 42 |
const int reduction[] = { 0, 30, 50, 70, -1 }; |
| 43 |
|
| 44 |
const char *archs[] = { "sack", "luggage", "luggage", "luggage", NULL }; |
| 45 |
|
| 46 |
const char *items[] = { "scroll", "crown", "gem", "tooth", NULL }; |
| 47 |
|
| 48 |
const int add[] = { 2, 5, 7, 3, 3, 9, -5, -7, 11, -8, -9, -11, 0 }; |
| 49 |
int red, a, i, nrof; |
| 50 |
uint32_t sum; |
| 51 |
signed long carrying; |
| 52 |
object *container, *item; |
| 53 |
|
| 54 |
for (red = 0; reduction[red] != -1; red++) { |
| 55 |
for (a = 0; archs[a] != NULL; a++) { |
| 56 |
container = create_archetype(archs[a]); |
| 57 |
fail_unless(container != NULL, "couldn't find container arch %s!", archs[a]); |
| 58 |
fail_unless(container->type == CONTAINER, "%s isn't a container, type %d instead of %d!", archs[a], container->type, CONTAINER); |
| 59 |
fail_unless(container->carrying == 0, "%s has already some carrying?", archs[a]); |
| 60 |
|
| 61 |
container->stats.Str = reduction[red]; |
| 62 |
|
| 63 |
for (i = 0; items[i] != NULL; i++) { |
| 64 |
item = create_archetype(items[i]); |
| 65 |
fail_unless(item != NULL, "couldn't find item %s to put", items[i]); |
| 66 |
fail_unless(item->nrof == 1, "can't test item %s with nrof != 1", items[i]); |
| 67 |
sum = 1; |
| 68 |
|
| 69 |
object_insert_in_ob(item, container); |
| 70 |
carrying = (signed long)(item->weight * (100 - container->stats.Str) / 100); |
| 71 |
fail_unless(container->carrying == carrying, "invalid weight %d instead of %d for %s in %s reduction %d!", container->carrying, carrying, items[i], archs[a], reduction[red]); |
| 72 |
|
| 73 |
for (nrof = 0; add[nrof] != 0; nrof++) { |
| 74 |
sum += add[nrof]; |
| 75 |
if (add[nrof] > 0) { |
| 76 |
item = create_archetype(items[i]); |
| 77 |
item->nrof = add[nrof]; |
| 78 |
item = object_insert_in_ob(item, container); |
| 79 |
} else { |
| 80 |
object_decrease_nrof(item, - add[nrof]); |
| 81 |
} |
| 82 |
fail_unless(item->nrof == sum, "invalid item count %d instead of %d", item->nrof, sum); |
| 83 |
carrying = (signed long)(item->nrof * item->weight * (100 - container->stats.Str) / 100); |
| 84 |
fail_unless(container->carrying == carrying, "invalid weight %d instead of %d for %s in %s reduction %d after adding %d!", container->carrying, carrying, items[i], archs[a], reduction[red], add[nrof]); |
| 85 |
} |
| 86 |
object_remove(item); |
| 87 |
object_free(item, 0); |
| 88 |
fail_unless(container->carrying == 0, "container %s is still carrying %d from %s instead of 0!", archs[a], container->carrying, items[i]); |
| 89 |
} |
| 90 |
object_free(container, 0); |
| 91 |
} |
| 92 |
} |
| 93 |
} |
| 94 |
END_TEST |
| 95 |
|
| 96 |
static Suite *bug_suite(void) { |
| 97 |
Suite *s = suite_create("bug"); |
| 98 |
TCase *tc_core = tcase_create("Core"); |
| 99 |
|
| 100 |
tcase_add_checked_fixture(tc_core, setup, teardown); |
| 101 |
|
| 102 |
suite_add_tcase(s, tc_core); |
| 103 |
tcase_add_test(tc_core, test_weight_reduction); |
| 104 |
tcase_set_timeout(tc_core, 0); |
| 105 |
|
| 106 |
return s; |
| 107 |
} |
| 108 |
|
| 109 |
int main(void) { |
| 110 |
int nf; |
| 111 |
Suite *s = bug_suite(); |
| 112 |
SRunner *sr = srunner_create(s); |
| 113 |
|
| 114 |
srunner_set_fork_status(sr, CK_NOFORK); |
| 115 |
init(0, NULL); |
| 116 |
|
| 117 |
srunner_set_xml(sr, LOGDIR "/bugs/bugtrack/weight_reduction.xml"); |
| 118 |
srunner_set_log(sr, LOGDIR "/bugs/bugtrack/weight_reduction.out"); |
| 119 |
srunner_run_all(sr, CK_ENV); |
| 120 |
nf = srunner_ntests_failed(sr); |
| 121 |
srunner_free(sr); |
| 122 |
return nf == 0 ? EXIT_SUCCESS : EXIT_FAILURE; |
| 123 |
} |
| 124 |
|