Crossfire Server, Trunk
check_artifact.cpp
Go to the documentation of this file.
1 /*
2  * CrossFire, A Multiplayer game for X-windows
3  *
4  * Copyright (C) 2022 the Crossfire Development Team
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  * The authors can be reached via e-mail at crossfire-devel@real-time.com
21  */
22 
23 /*
24  * This is the unit tests file for common/artifact.c
25  */
26 
27 #include <global.h>
28 #include <stdlib.h>
29 #include <check.h>
30 #include <loader.h>
31 #include <toolkit_common.h>
32 
33 static void setup(void) {
34  cctk_setdatadir(SOURCE_ROOT"lib");
35  cctk_setlog(LOGDIR"/unit/common/artifact.out");
37 }
38 
39 static void teardown(void) {
40  /* put any cleanup steps here, they will be run after each testcase */
41 }
42 
44 START_TEST(test_face_for_each_artifact) {
45  const artifactlist *al;
46  al = first_artifactlist;
47  while (al) {
48  for (auto art : al->items) {
49  FAIL_UNLESS(artifact_get_face(art) != (uint16_t)-1, "failed to find a face for %s", art->item->name);
50  }
51  al = al->next;
52  }
53 }
54 END_TEST
55 
57 START_TEST(test_artifact_key_value) {
58  object *initial = object_new(), *arti = object_new();
59 
60 #define KEY "check_artifact"
61 #define VALUE "all is right!"
62  object_set_value(arti, KEY, VALUE, 1);
63  add_abilities(initial, arti);
64  sstring value = object_get_value(initial, KEY);
65  FAIL_UNLESS(value, "failed to get the key back");
66  FAIL_UNLESS(strcmp(value, VALUE) == 0, "wrong value '%s' instead of '%s'", value, VALUE);
67 
70 }
71 END_TEST
72 
73 static Suite *artifact_suite(void) {
74  Suite *s = suite_create("artifact");
75  TCase *tc_core = tcase_create("Core");
76  tcase_set_timeout(tc_core, 60);
77 
78  /*setup and teardown will be called before each test in testcase 'tc_core' */
79  tcase_add_checked_fixture(tc_core, setup, teardown);
80 
81  suite_add_tcase(s, tc_core);
82  tcase_add_test(tc_core, test_face_for_each_artifact);
83  tcase_add_test(tc_core, test_artifact_key_value);
84 
85  return s;
86 }
87 
88 int main(void) {
89  int nf;
90  Suite *s = artifact_suite();
91  SRunner *sr = srunner_create(s);
92 
93  srunner_set_xml(sr, LOGDIR "/unit/common/artifact.xml");
94  srunner_set_log(sr, LOGDIR "/unit/common/artifact.out");
95  srunner_run_all(sr, CK_ENV); /*verbosity from env variable*/
96  nf = srunner_ntests_failed(sr);
97  srunner_free(sr);
98  return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
99 }
global.h
FREE_OBJ_NO_DESTROY_CALLBACK
#define FREE_OBJ_NO_DESTROY_CALLBACK
Definition: object.h:545
VALUE
#define VALUE
cctk_setdatadir
void cctk_setdatadir(const char *datadir)
Definition: toolkit_common.cpp:69
artifactlist::items
std::vector< artifact * > items
Definition: artifact.h:28
add_abilities
void add_abilities(object *op, const object *change)
Definition: artifact.cpp:320
artifactlist::next
artifactlist * next
Definition: artifact.h:27
object_get_value
const char * object_get_value(const object *op, const char *const key)
Definition: object.cpp:4346
START_TEST
START_TEST(test_face_for_each_artifact)
Definition: check_artifact.cpp:44
FAIL_UNLESS
#define FAIL_UNLESS(expr,...)
Definition: toolkit_common.h:11
toolkit_common.h
cctk_setlog
void cctk_setlog(const char *logfile)
Definition: toolkit_common.cpp:64
artifact_suite
static END_TEST Suite * artifact_suite(void)
Definition: check_artifact.cpp:73
main
int main(void)
Definition: check_artifact.cpp:88
object_free
void object_free(object *ob, int flags)
Definition: object.cpp:1592
artifactlist
Definition: artifact.h:24
object_new
object * object_new(void)
Definition: object.cpp:1273
cctk_init_std_archetypes
void cctk_init_std_archetypes(void)
Definition: toolkit_common.cpp:83
KEY
#define KEY
sstring
const typedef char * sstring
Definition: sstring.h:2
autojail.value
value
Definition: autojail.py:6
artifact_get_face
uint16_t artifact_get_face(const artifact *art)
Definition: artifact.cpp:638
first_artifactlist
artifactlist * first_artifactlist
Definition: init.cpp:109
loader.h
teardown
static void teardown(void)
Definition: check_artifact.cpp:39
setup
static void setup(void)
Definition: check_artifact.cpp:33
object_set_value
int object_set_value(object *op, const char *key, const char *value, int add_key)
Definition: object.cpp:4499