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 
56  fri = get_nearest_player(monster);
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);
65  fri = get_nearest_player(monster);
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
guildjoin.ob
ob
Definition: guildjoin.py:42
FAIL_UNLESS
#define FAIL_UNLESS(expr,...)
Definition: toolkit_common.h:11
get_nearest_player
object * get_nearest_player(object *mon)
Definition: player.cpp:540
toolkit_common.h
disinfect.map
map
Definition: disinfect.py:4
Settings::debug
LogLevel debug
Definition: global.h:243
setup
void setup(void)
Definition: check_player.cpp:36
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:2100
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:313
init
void init(int argc, char **argv)
Definition: init.cpp:1087
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