Crossfire Server, Trunk
check_readable.c
Go to the documentation of this file.
1 /*
2  * static char *rcsid_check_readable_c =
3  * "$Id$";
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 common/readable.c
31  */
32 
33 #include <stdlib.h>
34 #include <check.h>
35 #include <global.h>
36 #include <assert.h>
37 #include <spells.h>
38 #include <toolkit_common.h>
39 
40 static void setup(void) {
41  cctk_setdatadir(SOURCE_ROOT "lib");
42  cctk_setlog(LOGDIR "/unit/common/readable.out");
43 /* printf("set log to %s\n", LOGDIR"/unit/common/readable.out");*/
45  init_gods();
46 }
47 
48 static void teardown(void) {
49  /* put any cleanup steps here, they will be run after each testcase */
50 }
51 
52 START_TEST(test_strtoktolin) {
53  char buf[MAX_BUF];
54 
55 #define C(w, e) \
56  strtoktolin(w, ",", buf, sizeof(buf)); \
57  fail_unless(strcmp(buf, e) == 0, "got %s instead of %s", buf, e);
58 
59  C("single", " single.");
60  C("one, two", " one and two.");
61  C("one, two, three", " one, two and three.");
62 }
63 END_TEST
64 
65 static Suite *readable_suite(void) {
66  Suite *s = suite_create("readable");
67  TCase *tc_core = tcase_create("Core");
68 
69  /*setup and teardown will be called before each test in testcase 'tc_core' */
70  tcase_add_checked_fixture(tc_core, setup, teardown);
71 
72  suite_add_tcase(s, tc_core);
73  tcase_add_test(tc_core, test_strtoktolin);
74 
75  return s;
76 }
77 
78 int main(void) {
79  int nf;
80  Suite *s = readable_suite();
81  SRunner *sr = srunner_create(s);
82 
83  /* to debug, uncomment this line */
84  srunner_set_fork_status(sr, CK_NOFORK);
85  srunner_set_xml(sr, LOGDIR "/unit/common/readable.xml");
86  srunner_set_log(sr, LOGDIR "/unit/common/readable.out");
87  srunner_run_all(sr, CK_ENV); /*verbosity from env variable*/
88  nf = srunner_ntests_failed(sr);
89  srunner_free(sr);
90  return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
91 }
global.h
cctk_setdatadir
void cctk_setdatadir(const char *datadir)
Definition: toolkit_common.c:69
setup
static void setup(void)
Definition: check_readable.c:40
init_gods
void init_gods(void)
Definition: holy.cpp:63
toolkit_common.h
cctk_setlog
void cctk_setlog(const char *logfile)
Definition: toolkit_common.c:64
C
#define C(w, e)
MAX_BUF
#define MAX_BUF
Definition: define.h:35
cctk_init_std_archetypes
void cctk_init_std_archetypes(void)
Definition: toolkit_common.c:83
teardown
static void teardown(void)
Definition: check_readable.c:48
spells.h
readable_suite
static END_TEST Suite * readable_suite(void)
Definition: check_readable.c:65
START_TEST
START_TEST(test_strtoktolin)
Definition: check_readable.c:52
main
int main(void)
Definition: check_readable.c:78
buf
StringBuffer * buf
Definition: readable.c:1610