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 
38 static void setup(void) {
39  /* put any initialisation steps here, they will be run before each testcase */
40 }
41 
42 static void teardown(void) {
43  /* put any cleanup steps here, they will be run after each testcase */
44 }
45 
46 START_TEST(test_party) {
47  partylist *p1, *p2, *p3;
48  object *pl1;
49  object *pl2;
50  object *pl3;
51 
52  fail_unless(party_get_first() == NULL, "firstparty should be NULL!");
53 
54  pl1 = static_cast<object *>(calloc(1, sizeof(object)));
55  fail_unless(pl1 != NULL, "memory allocation failure");
56  pl1->name = "player1";
57  pl1->contr = static_cast<player *>(calloc(1, sizeof(player)));
58  fail_unless(pl1->contr != NULL, "memory allocation failure");
59  first_player = pl1->contr; /* needed because obsolete parties uses this. */
60  pl1->contr->ob = pl1;
61 
62  pl2 = static_cast<object *>(calloc(1, sizeof(object)));
63  fail_unless(pl2 != NULL, "memory allocation failure");
64  pl2->name = "player2";
65  pl2->contr = static_cast<player *>(calloc(1, sizeof(player)));
66  fail_unless(pl2->contr != NULL, "memory allocation failure");
67  first_player = pl2->contr; /* needed because obsolete parties uses this. */
68  pl2->contr->ob = pl2;
69 
70  pl3 = static_cast<object *>(calloc(1, sizeof(object)));
71  fail_unless(pl3 != NULL, "memory allocation failure");
72  pl3->name = "player2";
73  pl3->contr = static_cast<player *>(calloc(1, sizeof(player)));
74  fail_unless(pl3->contr != NULL, "memory allocation failure");
75  first_player = pl3->contr; /* needed because obsolete parties uses this. */
76  pl3->contr->ob = pl3;
77 
78  p1 = party_form(pl1, "test1");
79  fail_unless(p1 != NULL, "party_form failed.");
80  fail_unless(party_get_first() == p1, "firstparty wasn't updated");
81  fail_unless(strcmp(p1->partyname, "test1") == 0, "wrong party name");
82  fail_unless(p1 == pl1->contr->party, "player wasn't added to party");
83  fail_unless(strcmp(party_get_leader(p1), "player1") == 0, "wrong party leader");
84 
85  p2 = party_form(pl2, "test2");
86  fail_unless(p2 != NULL, "party_form failed.");
87  fail_unless(party_get_next(party_get_first()) == p2, "party incorrectly linked");
88 
89  party_remove(p1);
90 
91  fail_unless(party_get_first() == p2, "party incorrectly removed");
92 
93  p3 = party_form(pl3, "test3");
94  fail_unless(p3 != NULL, "party_form failed");
95  fail_unless(party_get_next(party_get_first()) == p3, "party p3 incorrectly linked");
96  fail_unless(pl3->contr->party == p3, "p3 incorrectly assigned to pl3");
97 
99  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?");
100 }
101 END_TEST
102 
103 static Suite *c_party_suite(void) {
104  Suite *s = suite_create("c_party");
105  TCase *tc_core = tcase_create("Core");
106 
107  /*setup and teardown will be called before each test in testcase 'tc_core' */
108  tcase_add_checked_fixture(tc_core, setup, teardown);
109 
110  suite_add_tcase(s, tc_core);
111  tcase_add_test(tc_core, test_party);
112 
113  return s;
114 }
115 
116 int main(void) {
117  int nf;
118  Suite *s = c_party_suite();
119  SRunner *sr = srunner_create(s);
120 
121  srunner_set_xml(sr, LOGDIR "/unit/server/c_party.xml");
122  srunner_set_log(sr, LOGDIR "/unit/server/c_party.out");
123  srunner_run_all(sr, CK_ENV); /*verbosity from env variable*/
124  nf = srunner_ntests_failed(sr);
125  srunner_free(sr);
126  return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
127 }
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:42
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:116
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
party_get_first
partylist * party_get_first(void)
Definition: party.cpp:196
object::contr
struct player * contr
Definition: object.h:284
setup
static void setup(void)
Definition: check_c_party.cpp:38
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:103
START_TEST
START_TEST(test_party)
Definition: check_c_party.cpp:46