Crossfire Server, Trunk  R20513
check_shop.c
Go to the documentation of this file.
1 /*
2  * static char *rcsid_check_shop_c =
3  * "$Id: check_shop.c 19769 2015-02-17 04:44:13Z 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 
38 static void setup(void) {
39  /* put any initialisation steps here, they will be run before each testcase */
40 }
41 
42 static void teardown(void) {
43  /* put any cleanup steps here, they will be run after each testcase */
44 }
45 
46 START_TEST(test_query_cost) {
47  object *tosell, *player;
48  int map_reset_time, player_charisma, arch;
49  mapstruct* map;
50  uint64_t cost;
51  static const char *sell_archs[] = { "fl_corpse", "Pdragon_mail", NULL };
52 
53  player = arch_to_object(find_archetype("dwarf_player"));
54  fail_unless(player != NULL, "can't find player?");
55  fail_unless(player->type == PLAYER, "invalid type for player?");
56  fail_unless(strcmp(player->name, "dwarf") == 0, "wrong name?");
57 
58  map = get_empty_map(5, 5);
59  strncpy(map->path, "test", sizeof(map->path) - 1);
60  player->map = map;
61 
62  for (arch = 0; sell_archs[arch] != NULL; arch++) {
63  tosell = arch_to_object(find_archetype(sell_archs[arch]));
64  fail_unless(tosell != NULL, "can't find %s", sell_archs[arch]);
65  tosell->nrof = 6;
66  CLEAR_FLAG(tosell, FLAG_IDENTIFIED);
67 
68  for (player_charisma = 1; player_charisma <= 30; player_charisma++) {
69  player->stats.Cha = player_charisma;
70  for (map_reset_time = 0; map_reset_time < 1000; map_reset_time++) {
71  map->reset_time = map_reset_time;
72  cost = shop_price_sell(tosell, player);
73  fail_unless(cost < 18446744073710, "mega price %" FMT64U " for charisma %d reset_time %d!", cost, player_charisma, map_reset_time);
74  }
75  }
77  }
78 
80 }
81 END_TEST
82 
83 static Suite *shop_suite(void) {
84  Suite *s = suite_create("shop");
85  TCase *tc_core = tcase_create("Core");
86 
87  /*setup and teardown will be called before each test in testcase 'tc_core' */
88  tcase_add_checked_fixture(tc_core, setup, teardown);
89 
90  suite_add_tcase(s, tc_core);
91  tcase_add_test(tc_core, test_query_cost);
92 
93  return s;
94 }
95 
96 int main(void) {
97  int nf;
98  Suite *s = shop_suite();
99  SRunner *sr = srunner_create(s);
100 
101  srunner_set_fork_status(sr, CK_NOFORK);
102 
103  /* Only want to run this once, so don't put it in setup() */
104  init(0, NULL);
105 
106  srunner_set_xml(sr, LOGDIR "/unit/server/shop.xml");
107  srunner_set_log(sr, LOGDIR "/unit/server/shop.out");
108  srunner_run_all(sr, CK_ENV); /*verbosity from env variable*/
109  nf = srunner_ntests_failed(sr);
110  srunner_free(sr);
111  return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
112 }
char path[HUGE_BUF]
Filename of the map.
Definition: map.h:365
archetype * find_archetype(const char *name)
Finds, using the hashtable, which archetype matches the given name.
Definition: arch.c:695
mapstruct * get_empty_map(int sizex, int sizey)
Creates and returns a map of the specific size.
Definition: map.c:874
#define FMT64U
Definition: compat.h:13
struct pl player
One player.
uint32_t reset_time
When this map should reset.
Definition: map.h:332
Global type definitions and header inclusions.
static void setup(void)
Definition: check_shop.c:38
START_TEST(test_query_cost)
Definition: check_shop.c:46
void object_free_drop_inventory(object *ob)
Frees everything allocated by an object, removes it from the list of used objects, and puts it on the list of free objects.
Definition: object.c:1368
struct mapdef * map
Pointer to the map in which this object is present.
Definition: object.h:297
static END_TEST Suite * shop_suite(void)
Definition: check_shop.c:83
static void teardown(void)
Definition: check_shop.c:42
#define FLAG_IDENTIFIED
Player knows full info about item.
Definition: define.h:261
const char * name
The name of the object, obviously...
Definition: object.h:311
uint32_t nrof
How many of the objects.
Definition: object.h:333
int8_t Cha
Definition: living.h:35
unsigned __int64 uint64_t
Definition: win32.h:167
void init(int argc, char **argv)
This is the main server initialization function.
Definition: init.c:978
#define CLEAR_FLAG(xyz, p)
Definition: define.h:224
uint64_t shop_price_sell(const object *obj, object *who)
Adjust the value of an item to be sold based on the player&#39;s bargaining skill and charisma...
Definition: shop.c:224
See Player.
Definition: object.h:107
living stats
Str, Con, Dex, etc.
Definition: object.h:368
uint8_t type
PLAYER, BULLET, etc.
Definition: object.h:338
int main(void)
Definition: check_shop.c:96
This is a game-map.
Definition: map.h:325
object * arch_to_object(archetype *at)
Creates and returns a new object which is a copy of the given archetype.
Definition: arch.c:571