Crossfire Server, Branches 1.12  R18729
check_time.c
Go to the documentation of this file.
1 /*
2  * static char *rcsid_check_time_c =
3  * "$Id: check_time.c 11578 2009-02-23 22:02:27Z lalo $";
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 
39 void setup(void) {
40  reset_sleep();
41 }
42 
43 void teardown(void) {
44  /* put any cleanup steps here, they will be run after each testcase */
45 }
46 
47 START_TEST(test_get_month_name) {
48  fail_unless(get_month_name(-1) == NULL, "getting month name for negative value should bring a NULL");
49  fail_unless(get_month_name(MONTHS_PER_YEAR) == NULL, "getting month name for too high value should bring a NULL");
50  fail_unless(get_month_name(0) != NULL, "getting month name for correct value should bring a non NULL season name");
51 }
52 END_TEST
53 
54 START_TEST(test_get_weekday) {
55  fail_unless(get_weekday(-1) == NULL, "getting week day name for negative value should bring a NULL");
56  fail_unless(get_weekday(DAYS_PER_WEEK) == NULL, "getting weekday name for too high value should bring a NULL");
57  fail_unless(get_weekday(0) != NULL, "getting weekday name for correct value should bring a non NULL season name");
58 }
59 END_TEST
60 
61 START_TEST(test_get_season_name) {
62  fail_unless(get_season_name(-1) == NULL, "getting season name for negative value should bring a NULL");
63 printf("got at season +2: %s\n", get_season_name(SEASONS_PER_YEAR+2));
64  fail_unless(get_season_name(SEASONS_PER_YEAR+2) == NULL, "getting season name for too high value should bring a NULL");
65  fail_unless(get_season_name(SEASONS_PER_YEAR) != NULL, "getting season name for limit value should bring a '\\n'");
66  fail_unless(strcmp(get_season_name(SEASONS_PER_YEAR), "\n") == 0, "getting season name for limit value should bring a '\n'");
67  fail_unless(get_season_name(0) != NULL, "getting season name for correct value should bring a non NULL season name");
68 }
69 END_TEST
70 
71 Suite *time_suite(void) {
72  Suite *s = suite_create("time");
73  TCase *tc_core = tcase_create("Core");
74 
75  /*setup and teardown will be called before each test in testcase 'tc_core' */
76  tcase_add_checked_fixture(tc_core, setup, teardown);
77 
78  suite_add_tcase(s, tc_core);
79  tcase_add_test(tc_core, test_get_month_name);
80  tcase_add_test(tc_core, test_get_season_name);
81  tcase_add_test(tc_core, test_get_weekday);
82 
83  return s;
84 }
85 
86 int main(void) {
87  int nf;
88  Suite *s = time_suite();
89  SRunner *sr = srunner_create(s);
90 
91  srunner_set_xml(sr, LOGDIR "/unit/common/time.xml");
92  srunner_set_log(sr, LOGDIR "/unit/common/time.out");
93  srunner_run_all(sr, CK_ENV); /*verbosity from env variable*/
94  nf = srunner_ntests_failed(sr);
95  srunner_free(sr);
96  return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
97 }
#define DAYS_PER_WEEK
Definition: tod.h:42
const char * get_season_name(const int index)
Definition: time.c:134
const char * get_weekday(const int index)
Definition: time.c:127
START_TEST(test_get_month_name)
Definition: check_time.c:47
const char * get_month_name(const int index)
Definition: time.c:120
void teardown(void)
Definition: check_time.c:43
void reset_sleep(void)
Definition: time.c:141
void setup(void)
Definition: check_time.c:39
#define MONTHS_PER_YEAR
Definition: tod.h:44
#define SEASONS_PER_YEAR
Definition: tod.h:45
END_TEST Suite * time_suite(void)
Definition: check_time.c:71
int main(void)
Definition: check_time.c:86