Crossfire Server, Branch 1.12
R12190
|
00001 /* 00002 * static char *rcsid_check_time_c = 00003 * "$Id: check_time.c 11578 2009-02-23 22:02:27Z lalo $"; 00004 */ 00005 00006 /* 00007 * CrossFire, A Multiplayer game for X-windows 00008 * 00009 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team 00010 * Copyright (C) 1992 Frank Tore Johansen 00011 * 00012 * This program is free software; you can redistribute it and/or modify 00013 * it under the terms of the GNU General Public License as published by 00014 * the Free Software Foundation; either version 2 of the License, or 00015 * (at your option) any later version. 00016 * 00017 * This program is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU General Public License for more details. 00021 * 00022 * You should have received a copy of the GNU General Public License 00023 * along with this program; if not, write to the Free Software 00024 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00025 * 00026 * The authors can be reached via e-mail at crossfire-devel@real-time.com 00027 */ 00028 00029 /* 00030 * This is the unit tests file for common/time.c 00031 */ 00032 00033 #include <stdlib.h> 00034 #include <check.h> 00035 #include <global.h> 00036 #include <libproto.h> 00037 #include "tod.h" 00038 00039 void setup(void) { 00040 reset_sleep(); 00041 } 00042 00043 void teardown(void) { 00044 /* put any cleanup steps here, they will be run after each testcase */ 00045 } 00046 00047 START_TEST(test_get_month_name) { 00048 fail_unless(get_month_name(-1) == NULL, "getting month name for negative value should bring a NULL"); 00049 fail_unless(get_month_name(MONTHS_PER_YEAR) == NULL, "getting month name for too high value should bring a NULL"); 00050 fail_unless(get_month_name(0) != NULL, "getting month name for correct value should bring a non NULL season name"); 00051 } 00052 END_TEST 00053 00054 START_TEST(test_get_weekday) { 00055 fail_unless(get_weekday(-1) == NULL, "getting week day name for negative value should bring a NULL"); 00056 fail_unless(get_weekday(DAYS_PER_WEEK) == NULL, "getting weekday name for too high value should bring a NULL"); 00057 fail_unless(get_weekday(0) != NULL, "getting weekday name for correct value should bring a non NULL season name"); 00058 } 00059 END_TEST 00060 00061 START_TEST(test_get_season_name) { 00062 fail_unless(get_season_name(-1) == NULL, "getting season name for negative value should bring a NULL"); 00063 printf("got at season +2: %s\n", get_season_name(SEASONS_PER_YEAR+2)); 00064 fail_unless(get_season_name(SEASONS_PER_YEAR+2) == NULL, "getting season name for too high value should bring a NULL"); 00065 fail_unless(get_season_name(SEASONS_PER_YEAR) != NULL, "getting season name for limit value should bring a '\\n'"); 00066 fail_unless(strcmp(get_season_name(SEASONS_PER_YEAR), "\n") == 0, "getting season name for limit value should bring a '\n'"); 00067 fail_unless(get_season_name(0) != NULL, "getting season name for correct value should bring a non NULL season name"); 00068 } 00069 END_TEST 00070 00071 Suite *time_suite(void) { 00072 Suite *s = suite_create("time"); 00073 TCase *tc_core = tcase_create("Core"); 00074 00075 /*setup and teardown will be called before each test in testcase 'tc_core' */ 00076 tcase_add_checked_fixture(tc_core, setup, teardown); 00077 00078 suite_add_tcase(s, tc_core); 00079 tcase_add_test(tc_core, test_get_month_name); 00080 tcase_add_test(tc_core, test_get_season_name); 00081 tcase_add_test(tc_core, test_get_weekday); 00082 00083 return s; 00084 } 00085 00086 int main(void) { 00087 int nf; 00088 Suite *s = time_suite(); 00089 SRunner *sr = srunner_create(s); 00090 00091 srunner_set_xml(sr, LOGDIR "/unit/common/time.xml"); 00092 srunner_set_log(sr, LOGDIR "/unit/common/time.out"); 00093 srunner_run_all(sr, CK_ENV); /*verbosity from env variable*/ 00094 nf = srunner_ntests_failed(sr); 00095 srunner_free(sr); 00096 return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 00097 }