Crossfire Server, Trunk
check_holy.cpp
Go to the documentation of this file.
1 /*
2  * CrossFire, A Multiplayer game for X-windows
3  *
4  * Copyright (C) 2022 the 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  */
22 
23 /*
24  * This is the unit tests file for common/holy.c
25  */
26 
27 #include <stdlib.h>
28 #include <check.h>
29 #include <global.h>
30 #include <assert.h>
31 #include <toolkit_common.h>
32 
33 void setup(void) {
34  cctk_setdatadir(SOURCE_ROOT "lib");
35  cctk_setlog(LOGDIR "/unit/common/holy.out");
37  init_gods();
38 }
39 
40 void teardown(void) {
41  /* put any cleanup steps here, they will be run after each testcase */
42 }
43 
44 START_TEST(test_get_random_god) {
45  const object *ob = get_rand_god();
46  FAIL_UNLESS(ob != NULL, "There must be at least one god!");
47 }
48 END_TEST
49 
50 START_TEST(test_find_god) {
51  const object *ob = find_god("Valriel");
52  FAIL_UNLESS(ob != NULL, "Valriel must exist");
53 }
54 END_TEST
55 
56 START_TEST(test_find_god_invalid) {
57  const object *ob = find_god("FlyingSpaghettiMonster");
58  FAIL_UNLESS(ob == NULL, "FSM must not be found");
59 }
60 END_TEST
61 
62 START_TEST(test_get_god_for_race) {
63  const char *god = get_god_for_race("undead");
64  FAIL_UNLESS(god != NULL, "Undead must have a race");
65  ck_assert_str_eq(god, "Devourers");
66 }
67 END_TEST
68 
69 START_TEST(test_get_god_for_race_invalid) {
70  const char *god = get_god_for_race("unicorns!!");
71  FAIL_UNLESS(god == NULL, "Must not find a god");
72 }
73 END_TEST
74 
75 Suite *holy_suite(void) {
76  Suite *s = suite_create("holy");
77  TCase *tc_core = tcase_create("Core");
78  tcase_set_timeout(tc_core, 60);
79 
80  /*setup and teardown will be called before each test in testcase 'tc_core' */
81  tcase_add_checked_fixture(tc_core, setup, teardown);
82 
83  suite_add_tcase(s, tc_core);
84  tcase_add_test(tc_core, test_get_random_god);
85  tcase_add_test(tc_core, test_find_god);
86  tcase_add_test(tc_core, test_find_god_invalid);
87  tcase_add_test(tc_core, test_get_god_for_race);
88  tcase_add_test(tc_core, test_get_god_for_race_invalid);
89 
90  return s;
91 }
92 
93 int main(void) {
94  int nf;
95  Suite *s = holy_suite();
96  SRunner *sr = srunner_create(s);
97 
98  srunner_set_xml(sr, LOGDIR "/unit/common/holy.xml");
99  srunner_set_log(sr, LOGDIR "/unit/common/holy.out");
100  srunner_run_all(sr, CK_ENV); /*verbosity from env variable*/
101  nf = srunner_ntests_failed(sr);
102  srunner_free(sr);
103  return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
104 }
START_TEST
START_TEST(test_get_random_god)
Definition: check_holy.cpp:44
global.h
cctk_setdatadir
void cctk_setdatadir(const char *datadir)
Definition: toolkit_common.cpp:69
teardown
void teardown(void)
Definition: check_holy.cpp:40
guildjoin.ob
ob
Definition: guildjoin.py:42
main
int main(void)
Definition: check_holy.cpp:93
holy_suite
END_TEST Suite * holy_suite(void)
Definition: check_holy.cpp:75
FAIL_UNLESS
#define FAIL_UNLESS(expr,...)
Definition: toolkit_common.h:11
find_god
const object * find_god(const char *name)
Definition: holy.cpp:317
init_gods
void init_gods(void)
Definition: holy.cpp:59
toolkit_common.h
get_rand_god
const object * get_rand_god(void)
Definition: holy.cpp:73
cctk_setlog
void cctk_setlog(const char *logfile)
Definition: toolkit_common.cpp:64
get_god_for_race
const char * get_god_for_race(const char *race)
Definition: holy.cpp:90
setup
void setup(void)
Definition: check_holy.cpp:33
cctk_init_std_archetypes
void cctk_init_std_archetypes(void)
Definition: toolkit_common.cpp:83