Debian Codegraph @

test/unit/common/check_time.c

raw symbols SCIP
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 [email protected]
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 static void setup(void) {
40 reset_sleep();
41 }
42
43 static 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 fail_unless(get_season_name(SEASONS_PER_YEAR+2) == NULL, "getting season name for too high value should bring a NULL");
64 fail_unless(get_season_name(SEASONS_PER_YEAR) != NULL, "getting season name for limit value should bring a '\\n'");
65 fail_unless(strcmp(get_season_name(SEASONS_PER_YEAR), "\n") == 0, "getting season name for limit value should bring a '\n'");
66 fail_unless(get_season_name(0) != NULL, "getting season name for correct value should bring a non NULL season name");
67 }
68 END_TEST
69
70 static Suite *time_suite(void) {
71 Suite *s = suite_create("time");
72 TCase *tc_core = tcase_create("Core");
73
74 /*setup and teardown will be called before each test in testcase 'tc_core' */
75 tcase_add_checked_fixture(tc_core, setup, teardown);
76
77 suite_add_tcase(s, tc_core);
78 tcase_add_test(tc_core, test_get_month_name);
79 tcase_add_test(tc_core, test_get_season_name);
80 tcase_add_test(tc_core, test_get_weekday);
81
82 return s;
83 }
84
85 int main(void) {
86 int nf;
87 Suite *s = time_suite();
88 SRunner *sr = srunner_create(s);
89
90 srunner_set_xml(sr, LOGDIR "/unit/common/time.xml");
91 srunner_set_log(sr, LOGDIR "/unit/common/time.out");
92 srunner_run_all(sr, CK_ENV); /*verbosity from env variable*/
93 nf = srunner_ntests_failed(sr);
94 srunner_free(sr);
95 return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
96 }