| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#include "global.h" |
| 6 |
|
| 7 |
#include <check.h> |
| 8 |
#include <stdlib.h> |
| 9 |
#include <sys/stat.h> |
| 10 |
|
| 11 |
#include "account_char.h" |
| 12 |
#include "loader.h" |
| 13 |
#include "sproto.h" |
| 14 |
#include "toolkit_common.h" |
| 15 |
#include "toolkit_server.h" |
| 16 |
|
| 17 |
static void setup(void) { |
| 18 |
} |
| 19 |
|
| 20 |
static void teardown(void) { |
| 21 |
|
| 22 |
} |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
START_TEST(test_account_char_add) { |
| 30 |
player *pl; |
| 31 |
Account_Char *chars; |
| 32 |
char path[MAX_BUF]; |
| 33 |
|
| 34 |
pl = calloc(1, sizeof(player)); |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
pl->ob = create_archetype("human_player"); |
| 41 |
pl->ob->level = 1; |
| 42 |
pl->ob->name = add_string("test character"); |
| 43 |
pl->ob->contr = pl; |
| 44 |
strcpy(pl->maplevel, "test map"); |
| 45 |
|
| 46 |
chars = account_char_add(NULL, pl); |
| 47 |
fail_unless(chars != NULL, "account_char_add returned NULL on initial character"); |
| 48 |
|
| 49 |
pl->ob->level = 2; |
| 50 |
chars = account_char_add(chars, pl); |
| 51 |
fail_unless(chars != NULL, "account_char_add returned NULL on update character"); |
| 52 |
fail_unless(chars->next == NULL, "account_char_add added to list, not updated existing entry"); |
| 53 |
|
| 54 |
chars = account_char_remove(chars, pl->ob->name); |
| 55 |
fail_unless(chars == NULL, "account_char_remove returned non NULL on final character removal"); |
| 56 |
|
| 57 |
chars = account_char_add(NULL, pl); |
| 58 |
fail_unless(chars != NULL, "account_char_add returned NULL on initial character"); |
| 59 |
|
| 60 |
pl->ob->name = add_string("char 2"); |
| 61 |
pl->party = party_form(pl->ob, "rockon"); |
| 62 |
|
| 63 |
chars = account_char_add(chars, pl); |
| 64 |
fail_unless(chars != NULL, "account_char_add returned NULL on initial character"); |
| 65 |
fail_unless(chars->next != NULL, "account_char_add did not set next pointer!"); |
| 66 |
|
| 67 |
sprintf(path,"%s/account", settings.localdir); |
| 68 |
mkdir(path, S_IRWXU); |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
account_char_save("testaccount", chars); |
| 74 |
|
| 75 |
|
| 76 |
account_char_free(chars); |
| 77 |
} |
| 78 |
END_TEST |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
START_TEST(test_account_char_load) { |
| 84 |
Account_Char *chars; |
| 85 |
object *ob = create_archetype("human_player"); |
| 86 |
|
| 87 |
chars = account_char_load("testaccount"); |
| 88 |
fail_unless(chars != NULL, "account_char_load returned NULL"); |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
fail_unless(!strcmp(chars->name, "test character"), |
| 93 |
"Name for first character is not test char"); |
| 94 |
|
| 95 |
fail_unless(!strcmp(chars->race, ob->race), |
| 96 |
"Race for first character does not match"); |
| 97 |
|
| 98 |
fail_unless(chars->level == 2, |
| 99 |
"Level for first character is not 2"); |
| 100 |
|
| 101 |
fail_unless(!strcmp(chars->face, ob->face->name), |
| 102 |
"Face for first character does not match"); |
| 103 |
|
| 104 |
fail_unless(chars->party[0] == 0, |
| 105 |
"Party for first character is not blank"); |
| 106 |
|
| 107 |
fail_unless(!strcmp(chars->map, "test map"), |
| 108 |
"Map for first character does not match"); |
| 109 |
|
| 110 |
fail_unless(chars->next != NULL, "account_char_load only loaded one character"); |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
chars = chars->next; |
| 117 |
|
| 118 |
fail_unless(!strcmp(chars->name, "char 2"), |
| 119 |
"Name for second character does not match"); |
| 120 |
|
| 121 |
fail_unless(!strcmp(chars->party, "rockon"), |
| 122 |
"Party for second character does not match"); |
| 123 |
} |
| 124 |
|
| 125 |
END_TEST |
| 126 |
|
| 127 |
static Suite *account_suite(void) { |
| 128 |
Suite *s = suite_create("account_char"); |
| 129 |
TCase *tc_core = tcase_create("Core"); |
| 130 |
|
| 131 |
|
| 132 |
tcase_add_checked_fixture(tc_core, setup, teardown); |
| 133 |
|
| 134 |
suite_add_tcase(s, tc_core); |
| 135 |
tcase_add_test(tc_core, test_account_char_add); |
| 136 |
tcase_add_test(tc_core, test_account_char_load); |
| 137 |
|
| 138 |
return s; |
| 139 |
} |
| 140 |
|
| 141 |
int main(void) { |
| 142 |
int nf; |
| 143 |
Suite *s = account_suite(); |
| 144 |
SRunner *sr = srunner_create(s); |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
settings.debug = 0; |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
settings.localdir = strdup_local("/tmp/"); |
| 156 |
clean_test_account_data(); |
| 157 |
init(0, NULL); |
| 158 |
|
| 159 |
srunner_set_xml(sr, LOGDIR "/unit/server/account_char.xml"); |
| 160 |
srunner_set_log(sr, LOGDIR "/unit/server/account_char.out"); |
| 161 |
srunner_run_all(sr, CK_ENV); |
| 162 |
nf = srunner_ntests_failed(sr); |
| 163 |
srunner_free(sr); |
| 164 |
|
| 165 |
clean_test_account_data(); |
| 166 |
return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; |
| 167 |
} |