Crossfire Server, Trunk
check_living.cpp
Go to the documentation of this file.
1 /*
2  * This is the unit tests file for common/living.c
3  */
4 
5 #include "global.h"
6 
7 #include <check.h>
8 #include <stdlib.h>
9 
10 #include "toolkit_common.h"
11 
12 static void setup(void) {
13  cctk_setdatadir(SOURCE_ROOT "lib");
14  cctk_setlog(LOGDIR "/unit/common/living.out");
17 }
18 
19 static void teardown(void) {
20  /* put any cleanup steps here, they will be run after each testcase */
21 }
22 
31 START_TEST(test_fix_object) {
32 #define TESTS 50
33 #define ARCHS 3
34  static const char *archs[ARCHS] = { "pl_dragon", "pl_half_orc", "human_player" };
35 
36  object *ob, *grace, *mana;
37  player *pl;
38  int test,i;
39 
46  int wc[3][50] = {
47  { 21, 3, 3, 22, 2, 10, 18, 10, 20, 14, 1, 14, 15, 9, 19, 4, 2, 3, 16, 17, 9, 2, 11, 14, 4, 11, 14, 12, 8, 20, 16, 21, 19, 3, 12, 6, 14, 8, 10, 14, 15, 17, 6, 21, 16, 9, 3, 19, 2, 20},
48  { 6, 23, 1, 2, 6, 14, 7, 6, 23, 13, 17, 9, 9, 19, 11, 18, 5, 15, 2, 3, 15, 9, 13, 13, 6, 19, 5, 21, 2, 12, 15, 6, 23, 19, 7, 20, 19, 3, 22, 7, 7, 12, 14, 15, 7, 15, 8, 10, 23, 11},
49  { 1, 8, 5, 16, 16, 15, 9, 21, 4, 16, 20, 17, 12, 19, 1, 3, 23, 4, 2, 10, 17, 3, 20, 6, 19, 21, 1, 7, 12, 20, 8, 2, 23, 17, 17, 18, 22, 17, 6, 3, 17, 3, 18, 13, 6, 3, 5, 17, 23, 1}
50  };
51 
52  int maxgr[3][50] = {
53  { 333, 236, 182, 225, 160, 36, 53, 78, 221, 130, 204, 246, 242, 256, 38, 67, 419, 145, 282, 245, 315, 208, 340, 81, 120, 232, 176, 260, 354, 111, 332, 251, 249, 90, 215, 62, 42, 372, 241, 196, 216, 46, 94, 47, 264, 102, 86, 126, 289, 107},
54  { 62, 119, 164, 309, 223, 236, 124, 98, 38, 302, 209, 155, 148, 134, 90, 220, 96, 262, 111, 126, 92, 236, 206, 131, 269, 255, 222, 88, 58, 102, 126, 111, 215, 170, 132, 156, 46, 153, 203, 88, 236, 43, 69, 167, 123, 36, 56, 168, 359, 52},
55  { 42, 192, 232, 110, 164, 287, 90, 238, 160, 242, 225, 258, 66, 226, 165, 114, 189, 208, 88, 255, 97, 83, 40, 254, 130, 88, 109, 238, 238, 226, 46, 231, 172, 206, 42, 148, 126, 82, 97, 162, 161, 232, 108, 152, 205, 190, 212, 80, 54, 152}
56  };
57 
58  int maxsp[3][50] = {
59  { 64, 403, 72, 106, 156, 234, 214, 194, 183, 432, 219, 70, 208, 108, 140, 224, 263, 218, 211, 178, 194, 160, 48, 106, 165, 100, 349, 245, 218, 239, 336, 247, 323, 243, 148, 37, 160, 148, 132, 362, 156, 238, 286, 217, 229, 166, 156, 178, 245, 220},
60  { 159, 218, 84, 115, 154, 159, 70, 78, 46, 243, 167, 142, 70, 130, 158, 164, 66, 180, 297, 252, 188, 142, 284, 80, 251, 61, 78, 207, 188, 210, 228, 236, 124, 32, 224, 228, 39, 246, 69, 188, 200, 210, 242, 158, 112, 184, 278, 229, 346, 220},
61  { 74, 64, 156, 240, 217, 297, 114, 276, 82, 265, 273, 212, 207, 253, 172, 146, 110, 88, 72, 68, 220, 251, 224, 94, 135, 53, 151, 181, 150, 214, 92, 218, 184, 126, 172, 170, 58, 224, 90, 50, 152, 181, 208, 79, 79, 163, 106, 31, 62, 231}
62  };
63 
64  int maxhp[3][50] = {
65  { 79, 466, 246, 36, 238, 170, 80, 218, 196, 358, 279, 112, 110, 164, 62, 300, 380, 224, 119, 117, 358, 300, 218, 162, 212, 153, 306, 136, 178, 90, 186, 73, 304, 226, 188, 260, 114, 293, 267, 352, 106, 90, 244, 150, 164, 182, 228, 90, 476, 132},
66  { 210, 34, 246, 351, 198, 254, 211, 196, 34, 188, 162, 196, 162, 140, 146, 72, 210, 158, 349, 264, 138, 164, 154, 136, 192, 91, 258, 82, 256, 278, 102, 238, 93, 64, 188, 171, 64, 420, 39, 184, 303, 202, 258, 104, 206, 121, 274, 346, 130, 142},
67  { 259, 176, 219, 100, 92, 344, 164, 100, 218, 152, 248, 90, 182, 64, 242, 226, 110, 214, 239, 152, 150, 364, 54, 194, 112, 50, 250, 268, 138, 85, 174, 240, 32, 90, 82, 74, 45, 82, 284, 226, 109, 246, 78, 154, 222, 254, 202, 82, 33, 248}
68  };
69 
70  int ac[3][50] = {
71  { 4, -7, -7, 6, -7, -7, -2, -7, 2, -7, -7, -7, -7, -7, 1, -7, -7, -7, -4, -2, -7, -7, -7, -7, -7, -7, -7, -7, -7, 2, -4, 4, 1, -7, -7, -7, -7, -7, -7, -7, -6, -3, -7, 3, -4, -7, -7, 0, -7, 3},
72  { 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13},
73  { 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13}
74  };
75 
76 
81  int wis[ARCHS][TESTS] = {
82  {
83  28, 26, 25, 25, 5, 16, 21, 7, 11, 25, 12, 16, 22, 23, 20, 7, 30, 20, 30, 28,
84  26, 16, 29, 24, 27, 19, 12, 26, 29, 23, 30, 14, 15, 2, 21, 13, 9, 30, 17, 19,
85  2, 13, 9, 24, 26, 21, 8, 28, 28, 7
86  },{
87  15, 19, 16, 26, 24, 19, 2, 16, 1, 27, 19, 15, 28, 21, 20, 3, 11, 23, 8, 4, 22,
88  12, 7, 17, 27, 21, 6, 9, 12, 7, 9, 28, 9, 4, 12, 1, 15, 2, 27, 2, 13, 20, 1, 24, 15, 7,
89  3, 11, 27, 1
90 
91  }, {
92  3, 11, 14, 13, 7, 11, 3, 5, 6, 13, 15, 23, 4, 13, 29, 10, 15, 10, 7, 19, 19,
93  14, 9, 25, 9, 11, 23, 29, 27, 30, 23, 30, 7, 16, 10, 9, 18, 26, 9, 11, 28, 8, 14, 25,
94  17, 5, 19, 14, 21, 12
95  }
96  };
97 
98  int intelligence[ARCHS][TESTS] = {
99  {
100  2, 7, 21, 10, 22, 2, 21, 16, 23, 27, 8, 24, 11, 27, 3, 26, 28, 1, 11, 3, 11, 27,
101  3, 15, 25, 13, 8, 25, 14, 12, 29, 11, 30, 30, 24, 5, 23, 3, 8, 10, 22, 21, 29,
102  5, 26, 11, 7, 4, 24, 30
103  },{
104  20, 18, 16, 15, 27, 2, 3, 9, 19, 21, 10, 4, 19, 8, 14, 13, 26, 7, 28, 26, 30, 27,
105  30, 2, 27, 16, 13, 22, 5, 5, 24, 20, 19, 18, 3, 17, 23, 11, 26, 11, 19, 3, 22, 29,
106  5, 10, 22, 12, 26, 8
107  },{
108  2, 20, 17, 5, 30, 9, 28, 30, 16, 19, 4, 6, 12, 28, 2, 2, 30, 24, 13, 10, 1, 15, 27,
109  16, 3, 23, 28, 10, 27, 4, 26, 4, 13, 9, 19, 23, 19, 19, 18, 13, 1, 24, 7, 12, 22,
110  18, 14, 11, 6, 26
111  }
112  };
113  int pow[ARCHS][TESTS] = {
114  {
115  19, 30, 16, 11, 5, 14, 6, 22, 28, 30, 19, 4, 11, 1, 4, 24, 28, 5, 17, 19, 29, 22,
116  23, 21, 6, 13, 29, 6, 5, 18, 25, 17, 30, 2, 21, 22, 1, 27, 27, 30, 9, 2, 21, 26,
117  23, 16, 11, 16, 30, 24
118  }, {
119  14, 7, 12, 27, 1, 28, 17, 12, 5, 22, 24, 18, 12, 23, 3, 3, 1, 21, 27, 20, 18, 2, 18,
120  14, 7, 17, 21, 20, 16, 28, 8, 20, 27, 3, 8, 27, 9, 29, 13, 12, 27, 23, 28, 7, 16, 15,
121  26, 29, 30, 8
122  }, {
123  15, 8, 15, 12, 12, 30, 7, 21, 2, 22, 29, 5, 21, 1, 1, 12, 29, 1, 13, 12, 22, 28, 11,
124  1, 21, 12, 11, 24, 10, 17, 6, 9, 10, 8, 6, 8, 15, 4, 25, 3, 17, 16, 7, 18, 18, 18, 2,
125  11, 9, 12
126  }
127  };
128  int con[ARCHS][TESTS] = {
129  {
130  19, 30, 16, 11, 5, 14, 6, 22, 28, 30, 19, 4, 11, 1, 4, 24, 28, 5, 17, 19, 29, 22,
131  23, 21, 6, 13, 29, 6, 5, 18, 25, 17, 30, 2, 21, 22, 1, 27, 27, 30, 9, 2, 21, 26,
132  23, 16, 11, 16, 30, 24
133  }, {
134  14, 7, 12, 27, 1, 28, 17, 12, 5, 22, 24, 18, 12, 23, 3, 3, 1, 21, 27, 20, 18, 2, 18,
135  14, 7, 17, 21, 20, 16, 28, 8, 20, 27, 3, 8, 27, 9, 29, 13, 12, 27, 23, 28, 7, 16, 15,
136  26, 29, 30, 8
137  }, {
138  15, 8, 15, 12, 12, 30, 7, 21, 2, 22, 29, 5, 21, 1, 1, 12, 29, 1, 13, 12, 22, 28, 11,
139  1, 21, 12, 11, 24, 10, 17, 6, 9, 10, 8, 6, 8, 15, 4, 25, 3, 17, 16, 7, 18, 18, 18, 2,
140  11, 9, 12
141  }
142  };
143  int ob_level[ARCHS][TESTS] = {
144  {
145  12, 103, 103, 6, 109, 70, 30, 69, 18, 49, 112, 46, 45, 72, 21, 100, 110, 102,
146  37, 31, 74, 110, 64, 46, 96, 64, 48, 58, 79, 20, 38, 14, 22, 103, 59, 90, 47,
147  79, 66, 46, 43, 35, 87, 15, 37, 71, 104, 25, 108, 16
148  }, {
149  90, 4, 113, 108, 89, 47, 83, 88, 4, 54, 31, 73, 71, 25, 63, 26, 95, 44, 107,
150  102, 44, 72, 52, 53, 86, 23, 94, 11, 108, 59, 41, 89, 5, 22, 84, 18, 22,
151  105, 6, 82, 84, 56, 49, 42, 83, 43, 77, 68, 4, 61
152  }, {
153  112, 78, 92, 40, 36, 42, 72, 15, 99, 36, 19, 35, 56, 22, 111, 103, 4,
154  97, 107, 66, 35, 102, 17, 87, 21, 15, 115, 84, 59, 20, 77,
155  110, 2, 35, 31, 27, 6, 31, 87, 103, 32, 103, 29, 52, 86, 102, 91, 31, 3, 114
156  }
157  };
158  int grace_level[ARCHS][TESTS] = {
159  {
160  112, 40, 61, 85, 70, 5, 15, 29, 83, 7, 92, 113, 105, 114, 8, 23, 90, 62, 42, 68, 93, 89, 94,
161  13, 21, 103, 50, 100, 111, 34, 58, 115, 70, 35, 89, 19, 11, 71, 92, 40, 98, 13, 37, 2, 93,
162  35, 33, 10, 48, 43
163  }, {
164  21, 49, 72, 104, 93, 83, 52, 39, 8, 104, 83, 66, 23, 46, 35, 100, 38, 108,
165  35, 53, 27, 108, 93, 54, 95, 111, 101, 34, 19, 27, 53, 8, 86, 75, 56, 64, 13, 48,
166  59, 34, 93, 4, 16, 62, 51, 6, 17, 47, 92, 16
167  }, {
168  11, 86, 106, 45, 72, 93, 35, 109, 70, 109, 72, 113, 23, 103, 18, 47, 54,
169  94, 34, 115, 31, 11, 10, 104, 55, 34, 36, 41, 78, 14, 7, 20, 76, 93, 11, 64, 50,
170  12, 34, 71, 27, 106, 44, 45, 89, 85, 96, 30, 14, 66
171  }
172  };
173 
174  int mana_level[ARCHS][TESTS] = {
175  {
176  22, 107, 22, 43, 68, 107, 97, 79, 34, 101, 99, 25, 94, 40, 60, 75, 58, 99, 95, 79, 28, 46, 9,
177  37, 71, 40, 107, 111, 99, 108, 108, 113, 19, 79, 51, 4, 70, 36, 26, 85, 68, 109, 97, 79, 82,
178  73, 68, 79, 17, 41
179  }, {
180  68, 99, 32, 14, 63, 33, 25, 29, 13, 101, 61, 61, 25, 48, 69, 72, 23, 78, 84,
181  99, 37, 56, 85, 30, 106, 18, 24, 85, 84, 57, 103, 101, 17, 2, 102, 70, 9, 54, 14, 84, 55, 90,
182  65, 46, 46, 82, 101, 45, 63, 100
183  }, {
184  27, 22, 67, 110, 57, 53, 33, 78, 31, 113, 71, 96, 89, 108, 76, 63, 3, 34,
185  26, 24, 99, 73, 89, 37, 57, 14, 48, 68, 53, 97, 32, 99, 82, 53, 76, 75, 17, 102, 14, 15, 66,
186  72, 94, 28, 23, 67, 43, 1, 21, 96
187  }
188  };
189 
190 
192 #define GENERATE 0
193 
194 #if GENERATE
196  StringBuffer *smaxgr = stringbuffer_new();
197  StringBuffer *smaxsp = stringbuffer_new();
198  StringBuffer *smaxhp = stringbuffer_new();
200  const char *sep = "";
201 
202  stringbuffer_append_printf(swc, "\tint wc[%d][%d] = {\n\t", ARCHS, TESTS);
203  stringbuffer_append_printf(smaxgr, "\tint maxgr[%d][%d] = {\n\t", ARCHS, TESTS);
204  stringbuffer_append_printf(smaxsp, "\tint maxsp[%d][%d] = {\n\t", ARCHS, TESTS);
205  stringbuffer_append_printf(smaxhp, "\tint maxhp[%d][%d] = {\n\t", ARCHS, TESTS);
206  stringbuffer_append_printf(sac, "\tint ac[%d][%d] = {\n\t", ARCHS, TESTS);
207 #endif
208 
209  pl = static_cast<player *>(calloc(1, sizeof(player)));
210 
211  for (i = 0; i < ARCHS; i++)
212  {
213 #if GENERATE
214  stringbuffer_append_printf(swc, "%s{ ", sep);
215  stringbuffer_append_printf(smaxgr, "%s{ ", sep);
216  stringbuffer_append_printf(smaxsp, "%s{ ", sep);
217  stringbuffer_append_printf(smaxhp, "%s{ ", sep);
218  stringbuffer_append_printf(sac, "%s{ ", sep);
219  sep = "";
220 #endif
221 
222  ob = create_archetype(archs[i]);
223  FAIL_UNLESS(ob != NULL, "invalid archetype %s", archs[i]);
224  if (ob->type == PLAYER)
225  ob->contr = pl;
226 
227  grace = create_archetype("skill_praying");
228  object_insert_in_ob(grace, ob);
229  mana = create_archetype("skill_pyromancy");
230  object_insert_in_ob(mana, ob);
231 
232  for (test = 0; test < TESTS; test++)
233  {
234 
235  ob->contr->orig_stats.Wis = wis[i][test];
236  ob->contr->orig_stats.Int = intelligence[i][test];
237  ob->contr->orig_stats.Pow = pow[i][test];
238  ob->contr->orig_stats.Con = con[i][test];
239 
240  ob->level = ob_level[i][test];
241  grace->level = grace_level[i][test];
242  mana->level = mana_level[i][test];
243 
244  fix_object(ob);
245 
246 #if GENERATE
247  stringbuffer_append_printf(swc, "%s%d", sep, ob->stats.wc);
248  stringbuffer_append_printf(smaxgr, "%s%d", sep, ob->stats.maxgrace);
249  stringbuffer_append_printf(smaxsp, "%s%d", sep, ob->stats.maxsp);
250  stringbuffer_append_printf(smaxhp, "%s%d", sep, ob->stats.maxhp);
251  stringbuffer_append_printf(sac, "%s%d", sep, ob->stats.ac);
252  sep = ", ";
253 #else
254  FAIL_UNLESS(ob->stats.wc == wc[i][test], "wc [test %d, arch %d]: got %d instead of %d", test, i, ob->stats.wc, wc[i][test]);
255  FAIL_UNLESS(ob->stats.maxgrace == maxgr[i][test], "gr: got %d instead of %d", ob->stats.maxgrace, maxgr[i][test]);
256  FAIL_UNLESS(ob->stats.maxsp == maxsp[i][test], "sp: got %d instead of %d", ob->stats.maxsp, maxsp[i][test]);
257  FAIL_UNLESS(ob->stats.maxhp == maxhp[i][test], "hp: [test %d, arch %d] [con %d level %d] got %d instead of %d", test, i, con[i][test], ob->level, ob->stats.maxhp, maxhp[i][test]);
258  FAIL_UNLESS(ob->stats.ac == ac[i][test], "ac: got %d instead of %d", ob->stats.ac, ac[i][test]);
259 #endif
260  }
262 
263 #if GENERATE
264  stringbuffer_append_string(swc, "}\n\t");
265  stringbuffer_append_string(smaxgr, "}\n\t");
266  stringbuffer_append_string(smaxsp, "}\n\t");
267  stringbuffer_append_string(smaxhp, "}\n\t");
268  stringbuffer_append_string(sac, "}\n\t");
269 #endif
270  }
271 
272  free(pl);
273 
274 #if GENERATE
275  stringbuffer_append_string(swc, "\n}; \n");
276  stringbuffer_append_string(smaxgr, "\n}; \n");
277  stringbuffer_append_string(smaxsp, "\n}; \n");
278  stringbuffer_append_string(smaxhp, "\n}; \n");
279  stringbuffer_append_string(sac, "\n}; \n");
280  {
281  char *pwc = stringbuffer_finish(swc);
282  char *pmaxgr = stringbuffer_finish(smaxgr);
283  char *pmaxsp = stringbuffer_finish(smaxsp);
284  char *pmaxhp = stringbuffer_finish(smaxhp);
285  char *pac = stringbuffer_finish(sac);
286  printf("%s\n", pwc);
287  printf("%s\n", pmaxgr);
288  printf("%s\n", pmaxsp);
289  printf("%s\n", pmaxhp);
290  printf("%s\n", pac);
291  free(pwc);
292  free(pmaxgr);
293  free(pmaxsp);
294  free(pmaxhp);
295  free(pac);
296  }
297  fail("Here are the results.");
298 #endif
299 }
300 END_TEST
301 
302 static Suite *living_suite(void) {
303  Suite *s = suite_create("living");
304  TCase *tc_core = tcase_create("Core");
305  tcase_set_timeout(tc_core, 60);
306 
307  /*setup and teardown will be called before each test in testcase 'tc_core' */
308  tcase_add_checked_fixture(tc_core, setup, teardown);
309 
310  suite_add_tcase(s, tc_core);
311  tcase_add_test(tc_core, test_fix_object);
312 
313  return s;
314 }
315 
316 int main(void) {
317  int nf;
318  Suite *s = living_suite();
319  SRunner *sr = srunner_create(s);
320 
321  /* to debug, uncomment this line */
322  /*srunner_set_fork_status(sr, CK_NOFORK);*/
323 
324  srunner_set_xml(sr, LOGDIR "/unit/common/living.xml");
325  srunner_set_log(sr, LOGDIR "/unit/common/living.out");
326  srunner_run_all(sr, CK_ENV); /*verbosity from env variable*/
327  nf = srunner_ntests_failed(sr);
328  srunner_free(sr);
329  return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
330 }
PLAYER
@ PLAYER
Definition: object.h:112
global.h
main
int main(void)
Definition: check_living.cpp:316
player
Definition: player.h:105
setup
static void setup(void)
Definition: check_living.cpp:12
cctk_setdatadir
void cctk_setdatadir(const char *datadir)
Definition: toolkit_common.cpp:69
stringbuffer_append_printf
void stringbuffer_append_printf(StringBuffer *sb, const char *format,...)
Definition: stringbuffer.cpp:138
stringbuffer_new
StringBuffer * stringbuffer_new(void)
Definition: stringbuffer.cpp:57
guildjoin.ob
ob
Definition: guildjoin.py:42
fix_object
void fix_object(object *op)
Definition: living.cpp:1132
curse_on_apply.ac
ac
Definition: curse_on_apply.py:4
object::level
int16_t level
Definition: object.h:361
object_insert_in_ob
object * object_insert_in_ob(object *op, object *where)
Definition: object.cpp:2857
FAIL_UNLESS
#define FAIL_UNLESS(expr,...)
Definition: toolkit_common.h:11
TESTS
#define TESTS
stringbuffer_finish
char * stringbuffer_finish(StringBuffer *sb)
Definition: stringbuffer.cpp:76
toolkit_common.h
cctk_setlog
void cctk_setlog(const char *logfile)
Definition: toolkit_common.cpp:64
living_suite
static END_TEST Suite * living_suite(void)
Definition: check_living.cpp:302
object_free
void object_free(object *ob, int flags)
Definition: object.cpp:1592
stringbuffer_append_string
void stringbuffer_append_string(StringBuffer *sb, const char *str)
Definition: stringbuffer.cpp:95
ARCHS
#define ARCHS
create_archetype
object * create_archetype(const char *name)
Definition: arch.cpp:278
teardown
static void teardown(void)
Definition: check_living.cpp:19
StringBuffer
Definition: stringbuffer.cpp:25
cctk_init_std_archetypes
void cctk_init_std_archetypes(void)
Definition: toolkit_common.cpp:83
init_experience
void init_experience(void)
Definition: exp.cpp:167
START_TEST
START_TEST(test_fix_object)
Definition: check_living.cpp:31
FREE_OBJ_FREE_INVENTORY
#define FREE_OBJ_FREE_INVENTORY
Definition: object.h:544
altar_valkyrie.pl
pl
Definition: altar_valkyrie.py:28