Crossfire Server, Trunk
check_c_party.cpp
Go to the documentation of this file.
1 /*
2  * static char *rcsid_check_c_party_c =
3  * "$Id$";
4  */
5 
6 /*
7  * CrossFire, A Multiplayer game for X-windows
8  *
9  * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
10  * Copyright (C) 1992 Frank Tore Johansen
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25  *
26  * The authors can be reached via e-mail at crossfire-devel@real-time.com
27  */
28 
29 /*
30  * This is the unit tests file for server/c_party.c
31  */
32 
33 #include <stdlib.h>
34 #include <check.h>
35 #include <global.h>
36 #include <sproto.h>
37 #include "toolkit_common.h"
38 
39 static void setup(void) {
40  /* put any initialisation steps here, they will be run before each testcase */
41 }
42 
43 static void teardown(void) {
44  /* put any cleanup steps here, they will be run after each testcase */
45 }
46 
47 START_TEST(test_party) {
48  partylist *p1, *p2, *p3;
49  object *pl1;
50  object *pl2;
51  object *pl3;
52 
53  FAIL_UNLESS(party_get_first() == NULL, "firstparty should be NULL!");
54 
55  pl1 = static_cast<object *>(calloc(1, sizeof(object)));
56  FAIL_UNLESS(pl1 != NULL, "memory allocation failure");
57  pl1->name = "player1";
58  pl1->contr = static_cast<player *>(calloc(1, sizeof(player)));
59  FAIL_UNLESS(pl1->contr != NULL, "memory allocation failure");
60  first_player = pl1->contr; /* needed because obsolete parties uses this. */
61  pl1->contr->ob = pl1;
62 
63  pl2 = static_cast<object *>(calloc(1, sizeof(object)));
64  FAIL_UNLESS(pl2 != NULL, "memory allocation failure");
65  pl2->name = "player2";
66  pl2->contr = static_cast<player *>(calloc(1, sizeof(player)));
67  FAIL_UNLESS(pl2->contr != NULL, "memory allocation failure");
68  first_player = pl2->contr; /* needed because obsolete parties uses this. */
69  pl2->contr->ob = pl2;
70 
71  pl3 = static_cast<object *>(calloc(1, sizeof(object)));
72  FAIL_UNLESS(pl3 != NULL, "memory allocation failure");
73  pl3->name = "player2";
74  pl3->contr = static_cast<player *>(calloc(1, sizeof(player)));
75  FAIL_UNLESS(pl3->contr != NULL, "memory allocation failure");
76  first_player = pl3->contr; /* needed because obsolete parties uses this. */
77  pl3->contr->ob = pl3;
78 
79  p1 = party_form(pl1, "test1");
80  FAIL_UNLESS(p1 != NULL, "party_form failed.");
81  FAIL_UNLESS(party_get_first() == p1, "firstparty wasn't updated");
82  FAIL_UNLESS(strcmp(p1->partyname, "test1") == 0, "wrong party name");
83  FAIL_UNLESS(p1 == pl1->contr->party, "player wasn't added to party");
84  FAIL_UNLESS(strcmp(party_get_leader(p1), "player1") == 0, "wrong party leader");
85 
86  p2 = party_form(pl2, "test2");
87  FAIL_UNLESS(p2 != NULL, "party_form failed.");
88  FAIL_UNLESS(party_get_next(party_get_first()) == p2, "party incorrectly linked");
89 
90  party_remove(p1);
91 
92  FAIL_UNLESS(party_get_first() == p2, "party incorrectly removed");
93 
94  p3 = party_form(pl3, "test3");
95  FAIL_UNLESS(p3 != NULL, "party_form failed");
96  FAIL_UNLESS(party_get_next(party_get_first()) == p3, "party p3 incorrectly linked");
97  FAIL_UNLESS(pl3->contr->party == p3, "p3 incorrectly assigned to pl3");
98 
100  FAIL_UNLESS(party_get_first() == p3, "party p2 wasn't removed by obsolete_parties(), party %s still there", party_get_first() ? party_get_first()->partyname : "NULL party?");
101 }
102 END_TEST
103 
104 static Suite *c_party_suite(void) {
105  Suite *s = suite_create("c_party");
106  TCase *tc_core = tcase_create("Core");
107 
108  /*setup and teardown will be called before each test in testcase 'tc_core' */
109  tcase_add_checked_fixture(tc_core, setup, teardown);
110 
111  suite_add_tcase(s, tc_core);
112  tcase_add_test(tc_core, test_party);
113 
114  return s;
115 }
116 
117 int main(void) {
118  int nf;
119  Suite *s = c_party_suite();
120  SRunner *sr = srunner_create(s);
121 
122  srunner_set_xml(sr, LOGDIR "/unit/server/c_party.xml");
123  srunner_set_log(sr, LOGDIR "/unit/server/c_party.out");
124  srunner_run_all(sr, CK_ENV); /*verbosity from env variable*/
125  nf = srunner_ntests_failed(sr);
126  srunner_free(sr);
127  return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
128 }
global.h
first_player
player * first_player
Definition: init.cpp:106
party_get_leader
const char * party_get_leader(const partylist *party)
Definition: party.cpp:292
teardown
static void teardown(void)
Definition: check_c_party.cpp:43
player
Definition: player.h:105
party_remove
void party_remove(partylist *party)
Definition: party.cpp:164
main
int main(void)
Definition: check_c_party.cpp:117
player::ob
object * ob
Definition: player.h:177
partylist
Definition: party.h:10
party_obsolete_parties
void party_obsolete_parties(void)
Definition: party.cpp:215
FAIL_UNLESS
#define FAIL_UNLESS(expr,...)
Definition: toolkit_common.h:11
party_get_first
partylist * party_get_first(void)
Definition: party.cpp:196
object::contr
struct player * contr
Definition: object.h:284
toolkit_common.h
setup
static void setup(void)
Definition: check_c_party.cpp:39
sproto.h
partylist::partyname
char * partyname
Definition: party.h:14
party_form
partylist * party_form(object *op, const char *partyname)
Definition: party.cpp:40
party_get_next
partylist * party_get_next(const partylist *party)
Definition: party.cpp:208
object::name
sstring name
Definition: object.h:319
player::party
partylist * party
Definition: player.h:203
c_party_suite
static END_TEST Suite * c_party_suite(void)
Definition: check_c_party.cpp:104
START_TEST
START_TEST(test_party)
Definition: check_c_party.cpp:47