Crossfire Server, Trunk
check_player.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 1999-2022 the Crossfire Development Team
5  *
6  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
7  * welcome to redistribute it under certain conditions. For details, please
8  * see COPYING and LICENSE.
9  *
10  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
11  */
12 
13 /*
14  * This is the unit tests file for server/player.c
15  */
16 
17 #include <stdlib.h>
18 #include <global.h>
19 #include <check.h>
20 #include <loader.h>
21 #include <toolkit_common.h>
22 #include <sproto.h>
23 
24 void setup(void) {
26  cctk_setdatadir(SOURCE_ROOT "lib");
27  init(0, NULL);
28 }
29 
30 void teardown(void) {
31  /* put any cleanup steps here, they will be run after each testcase */
32 }
33 
34 START_TEST(test_get_nearest_player) {
35  mapstruct *map = get_empty_map(5, 5);
36 
37  object *monster = create_archetype("kobold");
38  fail_unless(monster != NULL, "failed to find arch kobold");
39  object_insert_in_map_at(monster, map, NULL, 0 , 0 , 0);
40 
41  object *fri = get_nearest_player(monster);
42  fail_unless(fri == NULL, "Shouldn't get any friend");
43 
44  // Add a player, should be found
45  object *ob = create_archetype("angel");
46  fail_unless(QUERY_FLAG(ob, FLAG_MONSTER), "not a monster??");
47  player pl;
48  memset(&pl, 0, sizeof(pl));
49  socket_struct sock;
50  memset(&sock, 0, sizeof(sock));
51  pl.socket = &sock;
52  pl.ob = ob;
53  first_player = &pl;
54  object_insert_in_map_at(ob, map, NULL, 0, 4, 4);
55 
57  fail_unless(fri == ob, "Should get the player");
58 
59  // Add a pet closer, should be found
60  object *pet = create_archetype("vampire");
61  fail_unless(QUERY_FLAG(pet, FLAG_MONSTER), "not a monster??");
62  SET_FLAG(pet, FLAG_FRIENDLY);
64  object_insert_in_map_at(pet, map, NULL, 0, 2, 2);
66  fail_unless(fri == pet, "Should find the pet");
67 }
68 END_TEST
69 
70 Suite *player_suite(void) {
71  Suite *s = suite_create("player");
72  TCase *tc_core = tcase_create("Core");
73  tcase_set_timeout(tc_core, 20);
74 
75  /*setup and teardown will be called before each test in testcase 'tc_core' */
76  tcase_add_checked_fixture(tc_core, setup, teardown);
77 
78  suite_add_tcase(s, tc_core);
79  tcase_add_test(tc_core, test_get_nearest_player);
80 
81  return s;
82 }
83 
84 int main(void) {
85  int nf;
86  Suite *s = player_suite();
87  SRunner *sr = srunner_create(s);
88 // srunner_set_fork_status (sr, CK_NOFORK);
89 
90  srunner_set_xml(sr, LOGDIR "/unit/server/player.xml");
91  srunner_set_log(sr, LOGDIR "/unit/server/player.out");
92  srunner_run_all(sr, CK_ENV); /*verbosity from env variable*/
93  nf = srunner_ntests_failed(sr);
94  srunner_free(sr);
95  return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
96 }
global.h
first_player
player * first_player
Definition: init.cpp:106
settings
struct Settings settings
Definition: init.cpp:139
llevError
@ llevError
Definition: logger.h:11
get_empty_map
mapstruct * get_empty_map(int sizex, int sizey)
Definition: map.cpp:842
SET_FLAG
#define SET_FLAG(xyz, p)
Definition: define.h:224
player
Definition: player.h:105
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
cctk_setdatadir
void cctk_setdatadir(const char *datadir)
Definition: toolkit_common.cpp:69
socket_struct
Definition: newserver.h:89
teardown
void teardown(void)
Definition: check_player.cpp:40
Settings::debug
LogLevel debug
Definition: global.h:243
guildjoin.ob
ob
Definition: guildjoin.py:42
monster
the faster the spell may be cast there are several other common only the caster may be affected by the spell The most common spell range is that of touch This denotes that the caster much touch the recipient of the spell in order to release the spell monster
Definition: spell-info.txt:45
get_nearest_player
object * get_nearest_player(object *mon)
Definition: player.cpp:540
toolkit_common.h
disinfect.map
map
Definition: disinfect.py:4
setup
void setup(void)
Definition: check_player.cpp:36
init
pluglist shows those as well as a short text describing each the list will simply appear empty The keyword for the Python plugin is Python plugout< keyword > Unloads a given identified by its _keyword_ So if you want to unload the Python you need to do plugout Python plugin< libname > Loads a given whose _filename_ is libname So in the case of you d have to do a plugin cfpython so Note that all filenames are relative to the default plugin it tries to load all available files in the SHARE plugins directory as plugin libraries It first displays the Initializing the plugin has the opportunity to signal itself by a message on the console Then the server displays an informative message containing both the plugin content and its keyword For the Python the standard load process thus GreenGoblin When a plugin has been it can request to be warned whenever a global event and are named freely by the developer If the directory doesn t nothing will happen< event name > can be init
Definition: plugins.txt:54
sproto.h
object_insert_in_map_at
object * object_insert_in_map_at(object *op, mapstruct *m, object *originator, int flag, int x, int y)
Definition: object.cpp:2095
FLAG_MONSTER
#define FLAG_MONSTER
Definition: define.h:245
create_archetype
object * create_archetype(const char *name)
Definition: arch.cpp:278
FLAG_FRIENDLY
#define FLAG_FRIENDLY
Definition: define.h:246
add_friendly_object
void add_friendly_object(object *op)
Definition: friend.cpp:32
mapstruct
Definition: map.h:314
START_TEST
START_TEST(test_empty)
Definition: check_player.cpp:44
loader.h
main
int main(void)
Definition: check_player.cpp:62
player_suite
END_TEST Suite * player_suite(void)
Definition: check_player.cpp:49
altar_valkyrie.pl
pl
Definition: altar_valkyrie.py:28