Crossfire Server, Trunk  R22047
check_shop.c
Go to the documentation of this file.
1 /*
2  * static char *rcsid_check_shop_c =
3  * "$Id: check_shop.c 22047 2021-03-28 18:08:02Z partmedia $";
4  */
5 
6 /*
7  * CrossFire, A Multiplayer game for X-windows
8  *
9  * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
10  * Copyright (C) 1992 Frank Tore Johansen
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25  *
26  * The authors can be reached via e-mail at crossfire-devel@real-time.com
27  */
28 
29 /*
30  * This is the unit tests file for server/shop.c
31  */
32 
33 #include <stdlib.h>
34 #include <check.h>
35 #include <global.h>
36 #include <sproto.h>
37 #include <toolkit_common.h>
38 #include "shop.h"
39 
40 static void setup(void) {
41  /* put any initialisation steps here, they will be run before each testcase */
42 }
43 
44 static void teardown(void) {
45  /* put any cleanup steps here, they will be run after each testcase */
46 }
47 
48 START_TEST(test_query_cost) {
49  object *tosell, *player;
50  int map_reset_time, player_charisma, arch;
51  mapstruct* map;
52  uint64_t cost;
53  static const char *sell_archs[] = { "fl_corpse", "Pdragon_mail", NULL };
54 
55  player = arch_to_object(find_archetype("dwarf_player"));
56  fail_unless(player != NULL, "can't find player?");
57  fail_unless(player->type == PLAYER, "invalid type for player?");
58  fail_unless(strcmp(player->name, "dwarf") == 0, "wrong name?");
59 
60  map = get_empty_map(5, 5);
61  strncpy(map->path, "test", sizeof(map->path) - 1);
62  player->map = map;
63 
64  for (arch = 0; sell_archs[arch] != NULL; arch++) {
65  tosell = arch_to_object(find_archetype(sell_archs[arch]));
66  fail_unless(tosell != NULL, "can't find %s", sell_archs[arch]);
67  tosell->nrof = 6;
68  CLEAR_FLAG(tosell, FLAG_IDENTIFIED);
69 
70  for (player_charisma = 1; player_charisma <= 30; player_charisma++) {
71  player->stats.Cha = player_charisma;
72  for (map_reset_time = 0; map_reset_time < 1000; map_reset_time++) {
73  map->reset_time = map_reset_time;
74  cost = shop_price_sell(tosell, player);
75  fail_unless(cost < 18446744073710, "mega price %" FMT64U " for charisma %d reset_time %d!", cost, player_charisma, map_reset_time);
76  }
77  }
79  }
80 
82 }
83 END_TEST
84 
85 static Suite *shop_suite(void) {
86  Suite *s = suite_create("shop");
87  TCase *tc_core = tcase_create("Core");
88 
89  /*setup and teardown will be called before each test in testcase 'tc_core' */
90  tcase_add_checked_fixture(tc_core, setup, teardown);
91 
92  suite_add_tcase(s, tc_core);
93  tcase_add_test(tc_core, test_query_cost);
94 
95  return s;
96 }
97 
98 int main(void) {
99  int nf;
100  Suite *s = shop_suite();
101  SRunner *sr = srunner_create(s);
102 
103  srunner_set_fork_status(sr, CK_NOFORK);
104 
105  /* Only want to run this once, so don't put it in setup() */
106  cctk_setdatadir(SOURCE_ROOT "lib");
107  init(0, NULL);
108 
109  srunner_set_xml(sr, LOGDIR "/unit/server/shop.xml");
110  srunner_set_log(sr, LOGDIR "/unit/server/shop.out");
111  srunner_run_all(sr, CK_ENV); /*verbosity from env variable*/
112  nf = srunner_ntests_failed(sr);
113  srunner_free(sr);
114  return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
115 }
char path[HUGE_BUF]
Definition: map.h:366
mapstruct * get_empty_map(int sizex, int sizey)
Definition: map.c:870
void cctk_setdatadir(const char *datadir)
archetype * find_archetype(const char *name)
Definition: assets.cpp:253
#define FMT64U
Definition: compat.h:13
struct pl player
uint32_t reset_time
Definition: map.h:333
static void setup(void)
Definition: check_shop.c:40
START_TEST(test_query_cost)
Definition: check_shop.c:48
void object_free_drop_inventory(object *ob)
Definition: object.c:1316
object * arch_to_object(archetype *at)
Definition: arch.cpp:232
static END_TEST Suite * shop_suite(void)
Definition: check_shop.c:85
static void teardown(void)
Definition: check_shop.c:44
#define FLAG_IDENTIFIED
Definition: define.h:261
unsigned __int64 uint64_t
Definition: win32.h:167
void init(int argc, char **argv)
Definition: init.c:1033
#define CLEAR_FLAG(xyz, p)
Definition: define.h:224
uint64_t shop_price_sell(const object *obj, object *who)
Definition: shop.c:243
int main(void)
Definition: check_shop.c:98
Definition: map.h:326