| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 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 |
|
| 40 |
} |
| 41 |
|
| 42 |
static void teardown(void) { |
| 43 |
|
| 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 = calloc(1, sizeof(object)); |
| 55 |
pl1->name = "player1"; |
| 56 |
fail_unless(pl1 != NULL, "memory allocation failure"); |
| 57 |
pl1->contr = calloc(1, sizeof(player)); |
| 58 |
fail_unless(pl1->contr != NULL, "memory allocation failure"); |
| 59 |
first_player = pl1->contr; |
| 60 |
pl1->contr->ob = pl1; |
| 61 |
|
| 62 |
pl2 = calloc(1, sizeof(object)); |
| 63 |
pl2->name = "player2"; |
| 64 |
fail_unless(pl2 != NULL, "memory allocation failure"); |
| 65 |
pl2->contr = calloc(1, sizeof(player)); |
| 66 |
fail_unless(pl2->contr != NULL, "memory allocation failure"); |
| 67 |
first_player = pl2->contr; |
| 68 |
pl2->contr->ob = pl2; |
| 69 |
|
| 70 |
pl3 = calloc(1, sizeof(object)); |
| 71 |
pl3->name = "player2"; |
| 72 |
fail_unless(pl3 != NULL, "memory allocation failure"); |
| 73 |
pl3->contr = calloc(1, sizeof(player)); |
| 74 |
fail_unless(pl3->contr != NULL, "memory allocation failure"); |
| 75 |
first_player = pl3->contr; |
| 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 |
|
| 98 |
party_obsolete_parties(); |
| 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 |
|
| 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); |
| 124 |
nf = srunner_ntests_failed(sr); |
| 125 |
srunner_free(sr); |
| 126 |
return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; |
| 127 |
} |