Atrinik Server  4.0
cursed_treasures.c
Go to the documentation of this file.
1 /*************************************************************************
2  * Atrinik, a Multiplayer Online Role Playing Game *
3  * *
4  * Copyright (C) 2009-2014 Alex Tokar and Atrinik Development Team *
5  * *
6  * Fork from Crossfire (Multiplayer game for X-windows). *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the Free Software *
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
21  * *
22  * The author can be reached at admin@atrinik.org *
23  ************************************************************************/
24 
31 #include <global.h>
32 #include <check.h>
33 #include <checkstd.h>
34 #include <check_proto.h>
35 #include <arch.h>
36 #include <object.h>
37 
38 START_TEST(test_cursed_amulet_shielding)
39 {
40  treasure_list_t *list = treasure_list_find("random_talisman");
41  ck_assert_msg(list != NULL, "Couldn't find 'random_talisman' treasure list "
42  "to start the test.");
43 
44  for (int i = 0; i < 2000; i++) {
45  object *tmp = treasure_generate_single(list, 999, 100);
46  ck_assert_msg(tmp != NULL, "Didn't generate anything: %d", i);
47 
48  if (strcmp(tmp->arch->name, "amulet_shielding") == 0) {
49  if (QUERY_FLAG(tmp, FLAG_CURSED) || QUERY_FLAG(tmp, FLAG_DAMNED)) {
50  ck_abort_msg("Managed to create cursed amulet of minor "
51  "shielding (i: %d).", i);
52  }
53  }
54 
55  object_destroy(tmp);
56  }
57 }
58 END_TEST
59 
60 START_TEST(test_cursed_starting_items)
61 {
62  treasure_list_t *list = treasure_list_find("player_male");
63  ck_assert_msg(list != NULL, "Couldn't find 'player_male' treasure list "
64  "to start the test.");
65 
66  object *inv = object_get();
67 
68  for (int i = 0; i < 2000; i++) {
69  object_destroy_inv(inv);
70  treasure_generate(list, inv, 1, GT_ONLY_GOOD);
71  ck_assert_msg(inv->inv != NULL, "Didn't generate anything: %d", i);
72 
73  for (object *tmp = inv->inv; tmp != NULL; tmp = tmp->below) {
74  if (QUERY_FLAG(tmp, FLAG_CURSED) || QUERY_FLAG(tmp, FLAG_DAMNED)) {
76  char *name = object_get_name_s(tmp, NULL);
77  ck_abort_msg("Managed to create cursed item %s (%s) (i: %d).",
78  name, object_get_str(tmp), i);
79  efree(name);
80  }
81  }
82  }
83 
84  object_destroy(inv);
85 }
86 END_TEST
87 
88 static Suite *suite(void)
89 {
90  Suite *s = suite_create("cursed_treasures");
91  TCase *tc_core = tcase_create("Core");
92 
93  tcase_add_unchecked_fixture(tc_core, check_setup, check_teardown);
94  tcase_add_checked_fixture(tc_core, check_test_setup, check_test_teardown);
95 
96  suite_add_tcase(s, tc_core);
97  tcase_add_test(tc_core, test_cursed_amulet_shielding);
98  tcase_add_test(tc_core, test_cursed_starting_items);
99 
100  return s;
101 }
102 
103 void check_bug_cursed_treasures(void)
104 {
105  check_run_suite(suite(), __FILE__);
106 }
#define GT_ONLY_GOOD
Definition: treasure.h:63
void object_destroy(object *ob)
Definition: object.c:1441
#define FLAG_CURSED
Definition: define.h:1154
object * object_get(void)
Definition: object.c:993
void treasure_generate(treasure_list_t *treasure_list, object *op, int difficulty, int flags)
Definition: treasure.c:1641
#define QUERY_FLAG(xyz, p)
Definition: define.h:761
struct archetype * arch
Definition: object.h:225
char * object_get_name_s(const object *op, const object *caller)
Definition: item.c:398
void object_destroy_inv(object *ob)
Definition: object.c:1414
#define FLAG_DAMNED
Definition: define.h:1158
const char * object_get_str(const object *op)
Definition: object.c:3151
#define SET_FLAG(xyz, p)
Definition: define.h:741
struct obj * below
Definition: object.h:114
object * treasure_generate_single(treasure_list_t *treasure_list, int difficulty, int artifact_chance)
Definition: treasure.c:1672
shstr * name
More definite name, like "kobold".
Definition: arch.h:46
struct obj * inv
Definition: object.h:123
treasure_list_t * treasure_list_find(const char *name)
Definition: treasure.c:789
#define FLAG_IDENTIFIED
Definition: define.h:980