Crossfire Server, Trunk
check_treasure.c
Go to the documentation of this file.
1 /*
2  * static char *rcsid_check_treasure_c =
3  * "$Id$";
4  */
5 
6 /*
7  * CrossFire, A Multiplayer game for X-windows
8  *
9  * Copyright (C) 2002,2011 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 common/treasure.c
31  */
32 
33 #include <stdlib.h>
34 #include <check.h>
35 #include <global.h>
36 #include <toolkit_common.h>
37 
38 static void setup(void) {
39  cctk_setdatadir(SOURCE_ROOT "lib");
40  cctk_setlog(LOGDIR "/unit/common/object.out");
41  printf("set log to %s\n", LOGDIR"/unit/common/object.out");
42  //cctk_init_std_archetypes();
43 }
44 
45 static void teardown(void) {
46  /* put any cleanup steps here, they will be run after each testcase */
47 }
48 
49 START_TEST(test_add_treasure_in_list) {
51  list.items = NULL;
52  treasure *first = treasure_insert(&list, 10);
53  fail_unless(list.items == first, "First not inserted in first place");
54 
55  treasure *new_first = treasure_insert(&list, -1);
56  fail_unless(list.items == new_first, "First not replaced");
57  fail_unless(new_first->next == first, "List not correctly linked");
58 
59  treasure *second = treasure_insert(&list, 11);
60  fail_unless(first->next == second, "Second not inserted at end");
61  fail_unless(second->next == NULL, "Second should be the last");
62 
63  treasure *between = treasure_insert(&list, 2);
64  fail_unless(first->next == between, "Between should be after first");
65  fail_unless(between->next == second, "Between should be before second");
66 
67  treasure *other_first = treasure_insert(&list, 0);
68  fail_unless(list.items == other_first, "Other first should be first item");
69  fail_unless(other_first->next == new_first, "Other first should be before new first");
70 }
71 END_TEST
72 
73 START_TEST(test_treasure_remove_item) {
75  memset(&list, 0, sizeof(list));
76  /*treasure *first =*/ treasure_insert(&list, 0);
77  treasure *second = treasure_insert(&list, 1);
78  /*treasure *third =*/ treasure_insert(&list, 2);
79  treasure *fourth = treasure_insert(&list, 3);
80  /*treasure *fifth =*/ treasure_insert(&list, 4);
81 
83  fail_unless(list.items == second, "first not removed");
85  fail_unless(second->next == fourth, "third not removed");
87  fail_unless(fourth->next == NULL, "fifth not removed");
88 }
89 END_TEST
90 
91 static Suite *treasure_suite(void) {
92  Suite *s = suite_create("treasure");
93  TCase *tc_core = tcase_create("Core");
94 
95  /*setup and teardown will be called before each test in testcase 'tc_core' */
96  tcase_add_checked_fixture(tc_core, setup, teardown);
97 
98  suite_add_tcase(s, tc_core);
99  tcase_add_test(tc_core, test_add_treasure_in_list);
100  tcase_add_test(tc_core, test_treasure_remove_item);
101 
102  return s;
103 }
104 
105 int main(void) {
106  int nf;
107  Suite *s = treasure_suite();
108  SRunner *sr = srunner_create(s);
109 
110 
111  /* to debug, uncomment this line */
112  srunner_set_fork_status(sr, CK_NOFORK);
113 
114  srunner_set_xml(sr, LOGDIR "/unit/common/treasure.xml");
115  srunner_set_log(sr, LOGDIR "/unit/common/treasure.out");
116  srunner_run_all(sr, CK_ENV); /*verbosity from env variable*/
117  nf = srunner_ntests_failed(sr);
118  srunner_free(sr);
119  return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
120 }
global.h
cctk_setdatadir
void cctk_setdatadir(const char *datadir)
Definition: toolkit_common.c:69
guildoracle.list
list
Definition: guildoracle.py:87
treasure_suite
static END_TEST Suite * treasure_suite(void)
Definition: check_treasure.c:91
treasure_remove_item
void treasure_remove_item(treasurelist *list, int position)
Definition: treasure.c:1414
treasurestruct
Definition: treasure.h:63
teardown
static void teardown(void)
Definition: check_treasure.c:45
toolkit_common.h
cctk_setlog
void cctk_setlog(const char *logfile)
Definition: toolkit_common.c:64
START_TEST
START_TEST(test_add_treasure_in_list)
Definition: check_treasure.c:49
treasure_insert
treasure * treasure_insert(treasurelist *list, int position)
Definition: treasure.c:1391
setup
static void setup(void)
Definition: check_treasure.c:38
main
int main(void)
Definition: check_treasure.c:105
treasurestruct::next
struct treasurestruct * next
Definition: treasure.h:66
treasureliststruct
Definition: treasure.h:82