Crossfire Server, Trunk
check_time.cpp
Go to the documentation of this file.
1 /*
2  * static char *rcsid_check_time_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/time.c
31  */
32 
33 #include <stdlib.h>
34 #include <check.h>
35 #include <global.h>
36 #include <libproto.h>
37 #include "tod.h"
38 #include <toolkit_common.h>
39 
40 static void setup(void) {
41  cctk_setdatadir(SOURCE_ROOT"lib"); // Somehow it's required to link correctly...
42 // cctk_setlog(LOGDIR"/unit/common/time.out");
43 // cctk_init_std_archetypes();
44  reset_sleep();
45 }
46 
47 static void teardown(void) {
48  /* put any cleanup steps here, they will be run after each testcase */
49 }
50 
51 START_TEST(test_get_month_name) {
52  FAIL_UNLESS(get_month_name(-1) == NULL, "getting month name for negative value should bring a NULL");
53  FAIL_UNLESS(get_month_name(MONTHS_PER_YEAR) == NULL, "getting month name for too high value should bring a NULL");
54  FAIL_UNLESS(get_month_name(0) != NULL, "getting month name for correct value should bring a non NULL season name");
55 }
56 END_TEST
57 
58 START_TEST(test_get_weekday) {
59  FAIL_UNLESS(get_weekday(-1) == NULL, "getting week day name for negative value should bring a NULL");
60  FAIL_UNLESS(get_weekday(DAYS_PER_WEEK) == NULL, "getting weekday name for too high value should bring a NULL");
61  FAIL_UNLESS(get_weekday(0) != NULL, "getting weekday name for correct value should bring a non NULL season name");
62 }
63 END_TEST
64 
65 START_TEST(test_get_season_name) {
66  FAIL_UNLESS(get_season_name(-1) == NULL, "getting season name for negative value should bring a NULL");
67  FAIL_UNLESS(get_season_name(SEASONS_PER_YEAR+2) == NULL, "getting season name for too high value should bring a NULL");
68  FAIL_UNLESS(get_season_name(SEASONS_PER_YEAR) != NULL, "getting season name for limit value should bring a '\\n'");
69  FAIL_UNLESS(strcmp(get_season_name(SEASONS_PER_YEAR), "\n") == 0, "getting season name for limit value should bring a '\n'");
70  FAIL_UNLESS(get_season_name(0) != NULL, "getting season name for correct value should bring a non NULL season name");
71 }
72 END_TEST
73 
74 static Suite *time_suite(void) {
75  Suite *s = suite_create("time");
76  TCase *tc_core = tcase_create("Core");
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_get_month_name);
83  tcase_add_test(tc_core, test_get_season_name);
84  tcase_add_test(tc_core, test_get_weekday);
85 
86  return s;
87 }
88 
89 int main(void) {
90  int nf;
91  Suite *s = time_suite();
92  SRunner *sr = srunner_create(s);
93 
94  srunner_set_xml(sr, LOGDIR "/unit/common/time.xml");
95  srunner_set_log(sr, LOGDIR "/unit/common/time.out");
96  srunner_run_all(sr, CK_ENV); /*verbosity from env variable*/
97  nf = srunner_ntests_failed(sr);
98  srunner_free(sr);
99  return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
100 }
global.h
DAYS_PER_WEEK
#define DAYS_PER_WEEK
Definition: tod.h:16
START_TEST
START_TEST(test_get_month_name)
Definition: check_time.cpp:51
cctk_setdatadir
void cctk_setdatadir(const char *datadir)
Definition: toolkit_common.cpp:69
time_suite
static END_TEST Suite * time_suite(void)
Definition: check_time.cpp:74
teardown
static void teardown(void)
Definition: check_time.cpp:47
main
int main(void)
Definition: check_time.cpp:89
FAIL_UNLESS
#define FAIL_UNLESS(expr,...)
Definition: toolkit_common.h:11
get_season_name
const char * get_season_name(const int index)
Definition: time.cpp:127
toolkit_common.h
get_weekday
const char * get_weekday(const int index)
Definition: time.cpp:120
setup
static void setup(void)
Definition: check_time.cpp:40
SEASONS_PER_YEAR
#define SEASONS_PER_YEAR
Definition: tod.h:19
MONTHS_PER_YEAR
#define MONTHS_PER_YEAR
Definition: tod.h:18
reset_sleep
void reset_sleep(void)
Definition: time.cpp:134
get_month_name
const char * get_month_name(const int index)
Definition: time.cpp:113
tod.h
libproto.h