Crossfire Server, Trunk
check_shop.cpp
Go to the documentation of this file.
1 /*
2  * static char *rcsid_check_shop_c =
3  * "$Id$";
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 }
PLAYER
@ PLAYER
Definition: object.h:112
global.h
get_empty_map
mapstruct * get_empty_map(int sizex, int sizey)
Definition: map.cpp:842
player
Definition: player.h:105
archininventory.arch
arch
DIALOGCHECK MINARGS 1 MAXARGS 1
Definition: archininventory.py:16
cctk_setdatadir
void cctk_setdatadir(const char *datadir)
Definition: toolkit_common.cpp:69
setup
static void setup(void)
Definition: check_shop.cpp:40
teardown
static void teardown(void)
Definition: check_shop.cpp:44
npc_dialog.player
player
Definition: npc_dialog.py:97
START_TEST
START_TEST(test_query_cost)
Definition: check_shop.cpp:48
FAIL_UNLESS
#define FAIL_UNLESS(expr,...)
Definition: toolkit_common.h:11
object_free_drop_inventory
void object_free_drop_inventory(object *ob)
Definition: object.cpp:1560
toolkit_common.h
disinfect.map
map
Definition: disinfect.py:4
sproto.h
mapstruct
Definition: map.h:313
find_archetype
archetype * find_archetype(const char *name)
Definition: assets.cpp:266
shop.h
main
int main(void)
Definition: check_shop.cpp:98
init
void init(int argc, char **argv)
Definition: init.cpp:1087
CLEAR_FLAG
#define CLEAR_FLAG(xyz, p)
Definition: define.h:225
arch_to_object
object * arch_to_object(archetype *at)
Definition: arch.cpp:229
FMT64U
#define FMT64U
Definition: compat.h:17
object::nrof
uint32_t nrof
Definition: object.h:342
diamondslots.cost
int cost
Definition: diamondslots.py:21
shop_suite
static END_TEST Suite * shop_suite(void)
Definition: check_shop.cpp:85
shop_price_sell
uint64_t shop_price_sell(const object *obj, object *who)
Definition: shop.cpp:211
FLAG_IDENTIFIED
#define FLAG_IDENTIFIED
Definition: define.h:261