Crossfire Server, Branches 1.12  R18729
check_c_party.c
Go to the documentation of this file.
1 /*
2  * static char *rcsid_check_c_party_c =
3  * "$Id: check_c_party.c 11578 2009-02-23 22:02:27Z lalo $";
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 void setup(void) {
39  /* put any initialisation steps here, they will be run before each testcase */
40 }
41 
42 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 *pl;
49 
50  fail_unless(get_firstparty() == NULL, "firstparty should be NULL!");
51 
52  pl = calloc(1, sizeof(object));
53  pl->name = "player";
54  fail_unless(pl != NULL, "memory allocation failure");
55  pl->contr = calloc(1, sizeof(player));
56  fail_unless(pl->contr != NULL, "memory allocation failure");
57  first_player = pl->contr; /* needed because obsolete parties uses this. */
58  pl->contr->ob = pl;
59 
60  p1 = form_party(pl, "test1");
61  fail_unless(p1 != NULL, "form_party failed.");
62  fail_unless(get_firstparty() == p1, "firstparty wasn't updated");
63  fail_unless(strcmp(p1->partyname, "test1") == 0, "wrong party name");
64  fail_unless(p1 == pl->contr->party, "player wasn't added to party");
65  fail_unless(strcmp(p1->partyleader, "player") == 0, "wrong party leader");
66 
67  p2 = form_party(pl, "test2");
68  fail_unless(p2 != NULL, "form_party failed.");
69  fail_unless(get_firstparty()->next == p2, "party incorrectly linked");
70 
71  remove_party(p1);
72 
73  fail_unless(get_firstparty() == p2, "party incorrectly removed");
74 
75  p3 = form_party(pl, "test3");
76  fail_unless(p3 != NULL, "form_party failed");
77  fail_unless(get_firstparty()->next == p3, "party p3 incorrectly linked");
78  fail_unless(pl->contr->party == p3, "p3 incorrectly assigned to pl");
79 
81  fail_unless(get_firstparty() == p3, "party p2 wasn't removed by obsolete_parties(), party %s still there", get_firstparty() ? get_firstparty()->partyname : "NULL party?");
82 }
83 END_TEST
84 
85 Suite *c_party_suite(void) {
86  Suite *s = suite_create("c_party");
87  TCase *tc_core = tcase_create("Core");
88 
89  /*setup and teardown will be called before each test in testcase 'tc_core' */
90  tcase_add_checked_fixture(tc_core, setup, teardown);
91 
92  suite_add_tcase(s, tc_core);
93  tcase_add_test(tc_core, test_party);
94 
95  return s;
96 }
97 
98 int main(void) {
99  int nf;
100  Suite *s = c_party_suite();
101  SRunner *sr = srunner_create(s);
102 
103  srunner_set_xml(sr, LOGDIR "/unit/server/c_party.xml");
104  srunner_set_log(sr, LOGDIR "/unit/server/c_party.out");
105  srunner_run_all(sr, CK_ENV); /*verbosity from env variable*/
106  nf = srunner_ntests_failed(sr);
107  srunner_free(sr);
108  return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
109 }
Definition: player.h:146
char * partyname
Definition: player.h:124
partylist * party
Definition: player.h:237
START_TEST(test_party)
Definition: check_c_party.c:46
END_TEST Suite * c_party_suite(void)
Definition: check_c_party.c:85
const char * name
Definition: object.h:167
void remove_party(partylist *target_party)
Definition: c_party.c:106
struct pl * contr
Definition: object.h:134
void obsolete_parties(void)
Definition: c_party.c:165
object * ob
Definition: player.h:207
partylist * get_firstparty(void)
Definition: c_party.c:48
partylist * form_party(object *op, const char *params)
Definition: c_party.c:65
char * partyleader
Definition: player.h:121
void setup(void)
Definition: check_c_party.c:38
EXTERN player * first_player
Definition: global.h:190
int main(void)
Definition: check_c_party.c:98
void teardown(void)
Definition: check_c_party.c:42