Mercurial > molko
comparison tests/test-character.c @ 281:87b8c7510717
rpg: implement load/save for characters
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sun, 20 Dec 2020 10:55:53 +0100 |
parents | |
children | 196264679079 |
comparison
equal
deleted
inserted
replaced
280:11c824a82e63 | 281:87b8c7510717 |
---|---|
1 /* | |
2 * test-character.c -- test character routines | |
3 * | |
4 * Copyright (c) 2020 David Demelier <markand@malikania.fr> | |
5 * | |
6 * Permission to use, copy, modify, and/or distribute this software for any | |
7 * purpose with or without fee is hereby granted, provided that the above | |
8 * copyright notice and this permission notice appear in all copies. | |
9 * | |
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 */ | |
18 | |
19 #include <stdio.h> | |
20 #include <string.h> | |
21 | |
22 #define GREATEST_USE_ABBREVS 0 | |
23 #include <greatest.h> | |
24 | |
25 #include <rpg/character.h> | |
26 #include <rpg/save.h> | |
27 | |
28 static void | |
29 clean(void *data) | |
30 { | |
31 (void)data; | |
32 | |
33 remove("test.db"); | |
34 } | |
35 | |
36 GREATEST_TEST | |
37 test_save_simple(void) | |
38 { | |
39 struct save db; | |
40 struct character ch = { | |
41 .name = "david", | |
42 .hp = 1989, | |
43 .mp = 1, | |
44 .level = 18, | |
45 .team_order = 1, | |
46 .hpbonus = 500, | |
47 .mpbonus = 50, | |
48 .atkbonus = 1001, | |
49 .defbonus = 1002, | |
50 .agtbonus = 1003, | |
51 .luckbonus = 1004 | |
52 }; | |
53 | |
54 GREATEST_ASSERT(save_open_path(&db, "test.db", SAVE_MODE_WRITE)); | |
55 GREATEST_ASSERT(character_save(&ch, &db)); | |
56 | |
57 /* Restore. */ | |
58 memset(&ch, 0, sizeof (ch)); | |
59 ch.name = "david"; | |
60 | |
61 GREATEST_ASSERT(character_load(&ch, &db)); | |
62 GREATEST_ASSERT_EQ(1989, ch.hp); | |
63 GREATEST_ASSERT_EQ(1, ch.mp); | |
64 GREATEST_ASSERT_EQ(18, ch.level); | |
65 GREATEST_ASSERT_EQ(1, ch.team_order); | |
66 GREATEST_ASSERT_EQ(500, ch.hpbonus); | |
67 GREATEST_ASSERT_EQ(50, ch.mpbonus); | |
68 GREATEST_ASSERT_EQ(1001, ch.atkbonus); | |
69 GREATEST_ASSERT_EQ(1002, ch.defbonus); | |
70 GREATEST_ASSERT_EQ(1003, ch.agtbonus); | |
71 GREATEST_ASSERT_EQ(1004, ch.luckbonus); | |
72 GREATEST_PASS(); | |
73 } | |
74 | |
75 GREATEST_SUITE(suite_save) | |
76 { | |
77 GREATEST_SET_SETUP_CB(clean, NULL); | |
78 GREATEST_SET_TEARDOWN_CB(clean, NULL); | |
79 GREATEST_RUN_TEST(test_save_simple); | |
80 } | |
81 | |
82 GREATEST_MAIN_DEFS(); | |
83 | |
84 int | |
85 main(int argc, char **argv) | |
86 { | |
87 GREATEST_MAIN_BEGIN(); | |
88 GREATEST_RUN_SUITE(suite_save); | |
89 GREATEST_MAIN_END(); | |
90 } |