00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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
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
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);
00094 nf = srunner_ntests_failed(sr);
00095 srunner_free(sr);
00096 return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
00097 }