Crossfire Server, Branch 1.12
R12190
|
00001 /* 00002 * static char *rcsid_check_c_party_c = 00003 * "$Id: check_c_party.c 11578 2009-02-23 22:02:27Z lalo $"; 00004 */ 00005 00006 /* 00007 * CrossFire, A Multiplayer game for X-windows 00008 * 00009 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team 00010 * Copyright (C) 1992 Frank Tore Johansen 00011 * 00012 * This program is free software; you can redistribute it and/or modify 00013 * it under the terms of the GNU General Public License as published by 00014 * the Free Software Foundation; either version 2 of the License, or 00015 * (at your option) any later version. 00016 * 00017 * This program is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU General Public License for more details. 00021 * 00022 * You should have received a copy of the GNU General Public License 00023 * along with this program; if not, write to the Free Software 00024 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00025 * 00026 * The authors can be reached via e-mail at crossfire-devel@real-time.com 00027 */ 00028 00029 /* 00030 * This is the unit tests file for server/c_party.c 00031 */ 00032 00033 #include <stdlib.h> 00034 #include <check.h> 00035 #include <global.h> 00036 #include <sproto.h> 00037 00038 void setup(void) { 00039 /* put any initialisation steps here, they will be run before each testcase */ 00040 } 00041 00042 void teardown(void) { 00043 /* put any cleanup steps here, they will be run after each testcase */ 00044 } 00045 00046 START_TEST(test_party) { 00047 partylist *p1, *p2, *p3; 00048 object *pl; 00049 00050 fail_unless(get_firstparty() == NULL, "firstparty should be NULL!"); 00051 00052 pl = calloc(1, sizeof(object)); 00053 pl->name = "player"; 00054 fail_unless(pl != NULL, "memory allocation failure"); 00055 pl->contr = calloc(1, sizeof(player)); 00056 fail_unless(pl->contr != NULL, "memory allocation failure"); 00057 first_player = pl->contr; /* needed because obsolete parties uses this. */ 00058 pl->contr->ob = pl; 00059 00060 p1 = form_party(pl, "test1"); 00061 fail_unless(p1 != NULL, "form_party failed."); 00062 fail_unless(get_firstparty() == p1, "firstparty wasn't updated"); 00063 fail_unless(strcmp(p1->partyname, "test1") == 0, "wrong party name"); 00064 fail_unless(p1 == pl->contr->party, "player wasn't added to party"); 00065 fail_unless(strcmp(p1->partyleader, "player") == 0, "wrong party leader"); 00066 00067 p2 = form_party(pl, "test2"); 00068 fail_unless(p2 != NULL, "form_party failed."); 00069 fail_unless(get_firstparty()->next == p2, "party incorrectly linked"); 00070 00071 remove_party(p1); 00072 00073 fail_unless(get_firstparty() == p2, "party incorrectly removed"); 00074 00075 p3 = form_party(pl, "test3"); 00076 fail_unless(p3 != NULL, "form_party failed"); 00077 fail_unless(get_firstparty()->next == p3, "party p3 incorrectly linked"); 00078 fail_unless(pl->contr->party == p3, "p3 incorrectly assigned to pl"); 00079 00080 obsolete_parties(); 00081 fail_unless(get_firstparty() == p3, "party p2 wasn't removed by obsolete_parties(), party %s still there", get_firstparty() ? get_firstparty()->partyname : "NULL party?"); 00082 } 00083 END_TEST 00084 00085 Suite *c_party_suite(void) { 00086 Suite *s = suite_create("c_party"); 00087 TCase *tc_core = tcase_create("Core"); 00088 00089 /*setup and teardown will be called before each test in testcase 'tc_core' */ 00090 tcase_add_checked_fixture(tc_core, setup, teardown); 00091 00092 suite_add_tcase(s, tc_core); 00093 tcase_add_test(tc_core, test_party); 00094 00095 return s; 00096 } 00097 00098 int main(void) { 00099 int nf; 00100 Suite *s = c_party_suite(); 00101 SRunner *sr = srunner_create(s); 00102 00103 srunner_set_xml(sr, LOGDIR "/unit/server/c_party.xml"); 00104 srunner_set_log(sr, LOGDIR "/unit/server/c_party.out"); 00105 srunner_run_all(sr, CK_ENV); /*verbosity from env variable*/ 00106 nf = srunner_ntests_failed(sr); 00107 srunner_free(sr); 00108 return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 00109 }