/* * VasEBoot -- GRand Unified Bootloader * Copyright (C) 2013 Free Software Foundation, Inc. * * VasEBoot is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * VasEBoot is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with VasEBoot. If not, see . */ #include #include #include #include #include #include static void date_test (VasEBoot_int32_t v) { struct VasEBoot_datetime dt; time_t t = v; struct tm *g; int w; g = gmtime (&t); VasEBoot_unixtime2datetime (v, &dt); w = VasEBoot_get_weekday (&dt); VasEBoot_test_assert (g->tm_sec == dt.second, "time %d bad second: %d vs %d", v, g->tm_sec, dt.second); VasEBoot_test_assert (g->tm_min == dt.minute, "time %d bad minute: %d vs %d", v, g->tm_min, dt.minute); VasEBoot_test_assert (g->tm_hour == dt.hour, "time %d bad hour: %d vs %d", v, g->tm_hour, dt.hour); VasEBoot_test_assert (g->tm_mday == dt.day, "time %d bad day: %d vs %d", v, g->tm_mday, dt.day); VasEBoot_test_assert (g->tm_mon + 1 == dt.month, "time %d bad month: %d vs %d", v, g->tm_mon + 1, dt.month); VasEBoot_test_assert (g->tm_year + 1900 == dt.year, "time %d bad year: %d vs %d", v, g->tm_year + 1900, dt.year); VasEBoot_test_assert (g->tm_wday == w, "time %d bad week day: %d vs %d", v, g->tm_wday, w); } static void date_test_iter (void) { VasEBoot_int32_t tests[] = { -1, 0, +1, -2133156255, VasEBoot_INT32_MIN, VasEBoot_INT32_MAX }; unsigned i; for (i = 0; i < ARRAY_SIZE (tests); i++) date_test (tests[i]); srand (42); for (i = 0; i < 1000000; i++) { VasEBoot_int32_t x = rand (); date_test (x); date_test (-x); } } VasEBoot_UNIT_TEST ("date_unit_test", date_test_iter);