Crossfire Server, Trunk
check_duplicate_skills.c
Go to the documentation of this file.
1 /*
2  * CrossFire, A Multiplayer game for X-windows
3  *
4  * Copyright (C) 2021 Crossfire Development Team
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  * The authors can be reached via e-mail at crossfire-devel@real-time.com
21  */
30 #include <stdlib.h>
31 #include <check.h>
32 #include <global.h>
33 #include <sproto.h>
34 #include <toolkit_common.h>
35 
36 static void setup(void) {
37 }
38 
39 static void teardown(void) {
40 }
41 
42 START_TEST(test_skills) {
43  // We will be using the halfling thief as our example, since both get stealing.
44  player *pl;
45  archetype *race_arch, *class_arch;
46  living stats;
47  int result, num_stealing = 0;
48  object *ob_inv;
49  socket_struct ns;
50 
51  race_arch = find_archetype("halfling_player");
52  fail_unless(race_arch != NULL, "Cannot find halfing arch to test on.");
53 
54  class_arch = find_archetype("thief_class");
55  fail_unless(class_arch != NULL, "Cannot find thief class to test on.");
56 
57  // Pretend we sent faces
58  ns.faces_sent = calloc(sizeof(uint8_t), get_faces_count());
59  fail_unless(ns.faces_sent != NULL, "Could not allocate socket space to remember what faces are sent.");
60 
62  fail_unless(pl != NULL, "Could not create a player to handle.");
63 
64  // This should ensure we don't get negative stats no matter what we choose.
65  stats.Str = stats.Dex = stats.Con = stats.Int = stats.Wis = stats.Pow = stats.Cha = 20;
66 
67  result = apply_race_and_class(pl->ob, race_arch, class_arch, &stats);
68  fail_unless(result == 0, "Could not apply race and class to player.");
69 
70  // Now we loop through the inventory of the object and look for the number of times we find stealing as a skill.
71  // We should find it exactly once.
72  ob_inv = pl->ob->inv;
73  while (ob_inv) {
74  if (ob_inv->type == SKILL && strcmp(ob_inv->arch->name, "skill_stealing") == 0) {
75  ++num_stealing;
76  }
77  ob_inv = ob_inv->below;
78  }
79 
80  fail_unless(num_stealing < 2, "Found duplicate stealing skills in player inventory.");
81  fail_unless(num_stealing > 0, "Failed to find any stealing skills in player inventory.");
82 
83  // Cleanup
84  free(ns.faces_sent);
85 }
86 END_TEST
87 
88 static Suite *bug_suite(void) {
89  Suite *s = suite_create("bug");
90  TCase *tc_core = tcase_create("Core");
91 
92  tcase_add_checked_fixture(tc_core, setup, teardown);
93 
94  suite_add_tcase(s, tc_core);
95  tcase_add_test(tc_core, test_skills);
96  tcase_set_timeout(tc_core, 0);
97 
98  return s;
99 }
100 
101 int main(void) {
102  int nf;
103  Suite *s = bug_suite();
104  SRunner *sr = srunner_create(s);
105 
106  srunner_set_fork_status(sr, CK_NOFORK);
107  cctk_setdatadir(SOURCE_ROOT "lib");
108  init(0, NULL);
109 
110  srunner_set_xml(sr, LOGDIR "/bugs/bugtrack/duplicate_skills.xml");
111  srunner_set_log(sr, LOGDIR "/bugs/bugtrack/duplicate_skills.out");
112  srunner_run_all(sr, CK_ENV); /*verbosity from env variable*/
113  nf = srunner_ntests_failed(sr);
114  srunner_free(sr);
115  return nf == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
116 }
ADD_PLAYER_NO_STATS_ROLL
#define ADD_PLAYER_NO_STATS_ROLL
Definition: player.h:232
bug_suite
static END_TEST Suite * bug_suite(void)
Definition: check_duplicate_skills.c:88
global.h
teardown
static void teardown(void)
Definition: check_duplicate_skills.c:39
cctk_setdatadir
void cctk_setdatadir(const char *datadir)
Definition: toolkit_common.c:69
socket_struct
Definition: newserver.h:89
liv::Str
int8_t Str
Definition: living.h:36
setup
static void setup(void)
Definition: check_duplicate_skills.c:36
pl
Definition: player.h:92
pl::ob
object * ob
Definition: player.h:162
SKILL
@ SKILL
Definition: object.h:143
add_player
player * add_player(socket_struct *ns, int flags)
Definition: player.c:455
archt
Definition: object.h:468
toolkit_common.h
ADD_PLAYER_NO_MAP
#define ADD_PLAYER_NO_MAP
Definition: player.h:231
liv::Cha
int8_t Cha
Definition: living.h:36
liv::Con
int8_t Con
Definition: living.h:36
obj::below
struct obj * below
Definition: object.h:288
sproto.h
liv::Int
int8_t Int
Definition: living.h:36
liv
Definition: living.h:35
ADD_PLAYER_NEW
#define ADD_PLAYER_NEW
Definition: player.h:230
obj::arch
struct archt * arch
Definition: object.h:416
apply_race_and_class
int apply_race_and_class(object *op, archetype *race, archetype *opclass, living *stats)
Definition: player.c:1455
obj::type
uint8_t type
Definition: object.h:341
liv::Dex
int8_t Dex
Definition: living.h:36
liv::Wis
int8_t Wis
Definition: living.h:36
START_TEST
START_TEST(test_skills)
Definition: check_duplicate_skills.c:42
find_archetype
archetype * find_archetype(const char *name)
Definition: assets.cpp:278
init
void init(int argc, char **argv)
Definition: init.c:1108
socket_struct::faces_sent
uint8_t * faces_sent
Definition: newserver.h:96
main
int main(void)
Definition: check_duplicate_skills.c:101
archt::name
sstring name
Definition: object.h:469
get_faces_count
size_t get_faces_count()
Definition: assets.cpp:313
altar_valkyrie.pl
pl
Definition: altar_valkyrie.py:28
liv::Pow
int8_t Pow
Definition: living.h:36
obj::inv
struct obj * inv
Definition: object.h:291