Atrinik Server  4.0
arch.c
1 /*************************************************************************
2  * Atrinik, a Multiplayer Online Role Playing Game *
3  * *
4  * Copyright (C) 2009-2014 Alex Tokar and Atrinik Development Team *
5  * *
6  * Fork from Crossfire (Multiplayer game for X-windows). *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the Free Software *
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
21  * *
22  * The author can be reached at admin@atrinik.org *
23  ************************************************************************/
24 
25 #include <global.h>
26 #include <check.h>
27 #include <checkstd.h>
28 #include <check_proto.h>
29 #include <arch.h>
30 
31 START_TEST(test_object_matches_string)
32 {
33  mapstruct *map;
34  object *pl, *o1, *o2;
35 
36  check_setup_env_pl(&map, &pl);
37 
38  o1 = arch_get("cloak");
39  ck_assert_ptr_ne(o1, NULL);
40  FREE_AND_COPY_HASH(o1->title, "of Moroch");
42 
43  ck_assert_int_eq(object_matches_string(o1, pl, "all"), 1);
44  ck_assert_int_eq(object_matches_string(o1, pl, "Moroch"), 0);
45  ck_assert_int_eq(object_matches_string(o1, pl, "random"), 0);
46 
48  ck_assert_int_ne(object_matches_string(o1, pl, "Moroch"), 0);
49 
50  o2 = arch_get("cloak");
51  SET_FLAG(o2, FLAG_UNPAID);
52  ck_assert_int_eq(object_matches_string(o2, pl, "unpaid"), 2);
53  ck_assert_int_ne(object_matches_string(o2, pl, "cloak"), 0);
54  ck_assert_int_eq(object_matches_string(o2, pl, "wrong"), 0);
55 
56  object_destroy(o1);
57  object_destroy(o2);
58 }
59 END_TEST
60 
61 START_TEST(test_arch_to_object)
62 {
63  archetype_t *arch;
64  object *obj;
65 
66  arch = arch_find("empty_archetype");
67  obj = arch_to_object(arch);
68  ck_assert_ptr_ne(obj, NULL);
69  object_destroy(obj);
70 }
71 END_TEST
72 
73 START_TEST(test_arch_get)
74 {
75  object *obj;
76 
77  obj = arch_get("empty_archetype");
78  ck_assert_ptr_ne(obj, NULL);
79  object_destroy(obj);
80 
81  obj = arch_get("AA938DFEPQ54FH");
82  ck_assert_ptr_ne(obj, NULL);
83  ck_assert_ptr_ne(obj->name, NULL);
84  ck_assert(strstr(obj->name, "AA938DFEPQ54FH") != NULL);
85  object_destroy(obj);
86 }
87 END_TEST
88 
89 START_TEST(test_arch_find)
90 {
91  ck_assert_ptr_ne(arch_find("empty_archetype"), NULL);
92  ck_assert_ptr_eq(arch_find("AA938DFEPQ54FH"), NULL);
93 }
94 END_TEST
95 
96 static Suite *suite(void)
97 {
98  Suite *s = suite_create("arch");
99  TCase *tc_core = tcase_create("Core");
100 
101  tcase_add_unchecked_fixture(tc_core, check_setup, check_teardown);
102  tcase_add_checked_fixture(tc_core, check_test_setup, check_test_teardown);
103 
104  suite_add_tcase(s, tc_core);
105  tcase_add_test(tc_core, test_object_matches_string);
106  tcase_add_test(tc_core, test_arch_to_object);
107  tcase_add_test(tc_core, test_arch_get);
108  tcase_add_test(tc_core, test_arch_find);
109 
110  return s;
111 }
112 
113 void check_server_arch(void)
114 {
115  check_run_suite(suite(), __FILE__);
116 }
Definition: object.h:94
int object_matches_string(object *op, object *caller, const char *str)
Definition: object.c:2676
#define FREE_AND_COPY_HASH(_sv_, _nv_)
Definition: global.h:100
void object_destroy(object *ob)
Definition: object.c:1441
const char * title
Definition: object.h:171
Definition: arch.h:40
object * arch_get(const char *name)
Definition: arch.c:430
#define FLAG_UNPAID
Definition: define.h:1251
const char * name
Definition: object.h:168
#define SET_FLAG(xyz, p)
Definition: define.h:741
archetype_t * arch_find(const char *name)
Definition: arch.c:407
#define CLEAR_FLAG(xyz, p)
Definition: define.h:751
object * arch_to_object(archetype_t *at)
Definition: arch.c:446
Definition: map.h:536
#define FLAG_IDENTIFIED
Definition: define.h:980