Crossfire Server, Trunk  R21524
check_shop.c
Go to the documentation of this file.
1 /*
2  * static char *rcsid_check_shop_c =
3  * "$Id: check_shop.c 21286 2020-08-17 16:34:47Z crowbert $";
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 "shop.h"
38 
39 static void setup(void) {
40  /* put any initialisation steps here, they will be run before each testcase */
41 }
42 
43 static void teardown(void) {
44  /* put any cleanup steps here, they will be run after each testcase */
45 }
46 
47 START_TEST(test_query_cost) {
48  object *tosell, *player;
49  int map_reset_time, player_charisma, arch;
50  mapstruct* map;
51  uint64_t cost;
52  static const char *sell_archs[] = { "fl_corpse", "Pdragon_mail", NULL };
53 
54  player = arch_to_object(find_archetype("dwarf_player"));
55  fail_unless(player != NULL, "can't find player?");
56  fail_unless(player->type == PLAYER, "invalid type for player?");
57  fail_unless(strcmp(player->name, "dwarf") == 0, "wrong name?");
58 
59  map = get_empty_map(5, 5);
60  strncpy(map->path, "test", sizeof(map->path) - 1);
61  player->map = map;
62 
63  for (arch = 0; sell_archs[arch] != NULL; arch++) {
64  tosell = arch_to_object(find_archetype(sell_archs[arch]));
65  fail_unless(tosell != NULL, "can't find %s", sell_archs[arch]);
66  tosell->nrof = 6;
67  CLEAR_FLAG(tosell, FLAG_IDENTIFIED);
68 
69  for (player_charisma = 1; player_charisma <= 30; player_charisma++) {
70  player->stats.Cha = player_charisma;
71  for (map_reset_time = 0; map_reset_time < 1000; map_reset_time++) {
72  map->reset_time = map_reset_time;
73  cost = shop_price_sell(tosell, player);
74  fail_unless(cost < 18446744073710, "mega price %" FMT64U " for charisma %d reset_time %d!", cost, player_charisma, map_reset_time);
75  }
76  }
78  }
79 
81 }
82 END_TEST
83 
84 static Suite *shop_suite(void) {
85  Suite *s = suite_create("shop");
86  TCase *tc_core = tcase_create("Core");
87 
88  /*setup and teardown will be called before each test in testcase 'tc_core' */
89  tcase_add_checked_fixture(tc_core, setup, teardown);
90 
91  suite_add_tcase(s, tc_core);
92  tcase_add_test(tc_core, test_query_cost);
93 
94  return s;
95 }
96 
97 int main(void) {
98  int nf;
99  Suite *s = shop_suite();
100  SRunner *sr = srunner_create(s);
101 
102  srunner_set_fork_status(sr, CK_NOFORK);
103 
104  /* Only want to run this once, so don't put it in setup() */
105  init(0, NULL);
106 
107  srunner_set_xml(sr, LOGDIR "/unit/server/shop.xml");
108  srunner_set_log(sr, LOGDIR "/unit/server/shop.out");
109  srunner_run_all(sr, CK_ENV); /*verbosity from env variable*/
110  nf = srunner_ntests_failed(sr);
111  srunner_free(sr);
112  return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
113 }
char path[HUGE_BUF]
Definition: map.h:365
archetype * find_archetype(const char *name)
Definition: arch.c:696
mapstruct * get_empty_map(int sizex, int sizey)
Definition: map.c:869
#define FMT64U
Definition: compat.h:13
struct pl player
uint32_t reset_time
Definition: map.h:332
static void setup(void)
Definition: check_shop.c:39
START_TEST(test_query_cost)
Definition: check_shop.c:47
void object_free_drop_inventory(object *ob)
Definition: object.c:1325
struct mapdef * map
Definition: object.h:297
static END_TEST Suite * shop_suite(void)
Definition: check_shop.c:84
static void teardown(void)
Definition: check_shop.c:43
#define FLAG_IDENTIFIED
Definition: define.h:261
const char * name
Definition: object.h:311
uint32_t nrof
Definition: object.h:333
int8_t Cha
Definition: living.h:36
unsigned __int64 uint64_t
Definition: win32.h:167
void init(int argc, char **argv)
Definition: init.c:1003
#define CLEAR_FLAG(xyz, p)
Definition: define.h:224
uint64_t shop_price_sell(const object *obj, object *who)
Definition: shop.c:250
Definition: object.h:107
living stats
Definition: object.h:369
uint8_t type
Definition: object.h:339
int main(void)
Definition: check_shop.c:97
Definition: map.h:325
object * arch_to_object(archetype *at)
Definition: arch.c:572