Unit tests for calendar service.
Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <asf.h>
#include <string.h>
#include <unit_test/suite.h>
#include <stdio_serial.h>
#include <conf_test.h>
#include <calendar.h>
Functions | |
int | main (void) |
Run calendar service unit tests. More... | |
Calendar unit test functions | |
static void | run_timestamp_to_normal_date_test (const struct test_case *test) |
Test conversion of normal timestamp to date. More... | |
static void | run_timestamp_0_to_date_test (const struct test_case *test) |
Test conversion of timestamp 0 to date. More... | |
static void | run_timestamp_to_leap_year_date_test (const struct test_case *test) |
Test conversion of timestamp to end of February in leap year date. More... | |
static void | run_timestamp_to_leap_year_date2_test (const struct test_case *test) |
Test conversion of timestamp to March in leap year date. More... | |
static void | run_date_to_timestamp_0_test (const struct test_case *test) |
Test conversion of first date to timestamp. More... | |
static void | run_erronous_time_to_timestamp_test (const struct test_case *test) |
Test conversion of a date with invalid time to timestamp. More... | |
static void | run_erronous_date_to_timestamp_test (const struct test_case *test) |
Test conversion of a date with invalid day to timestamp. More... | |
static void | run_leap_year_date_to_timestamp_test (const struct test_case *test) |
Test conversion of a date in a leap year to timestamp. More... | |
static void | run_date_to_timestamp_test (const struct test_case *test) |
Test conversion of a normal date to timestamp. More... | |
static void | run_date_1855_to_timestamp_test (const struct test_case *test) |
Test conversion of a date before 1970 to timestamp 0. More... | |
static void | run_date_2107_to_timestamp_test (const struct test_case *test) |
Test conversion of a date after 2106 to timestamp 0. More... | |
static void | run_time_between_dates_same_year_test (const struct test_case *test) |
Test computation of time between dates in the same year. More... | |
static void | run_time_between_dates_diff_year_test (const struct test_case *test) |
Test computation of time between dates in the different years. More... | |
static void | run_time_between_dates_leap_year_test (const struct test_case *test) |
Test computation of time between dates in the same leap year. More... | |
static void | run_time_between_dates_years_test (const struct test_case *test) |
Test computation of time between dates several years apart. More... | |
static void | run_time_between_dates_years2_test (const struct test_case *test) |
Test computation of time between dates several years apart. More... | |
static void | run_time_between_dates_exchanged_test (const struct test_case *test) |
Test computation of time between dates with end before start. More... | |
static void | run_add_second_to_normal_date_test (const struct test_case *test) |
Test adding one second to a normal date. More... | |
static void | run_add_second_to_end_of_day_test (const struct test_case *test) |
Test adding one second to the end of a day. More... | |
static void | run_add_second_to_end_feb_test (const struct test_case *test) |
Test adding one second to the 28th of February, normal year. More... | |
static void | run_add_second_to_leap_year_feb_test (const struct test_case *test) |
Test adding one second to the 28th of February, leap year. More... | |
static void | run_add_second_to_leap_year_feb2_test (const struct test_case *test) |
Test adding one second to the end of February, leap year. More... | |
static void | run_add_second_to_end_of_year_test (const struct test_case *test) |
Test adding one second to the end of a year. More... | |
int main | ( | void | ) |
Run calendar service unit tests.
Initializes the clock system, board and serial output, then sets up the calendar unit test suite and runs it.
References usart_rs232_options::baudrate, board_init(), DEFINE_TEST_ARRAY, DEFINE_TEST_CASE, DEFINE_TEST_SUITE, run_add_second_to_end_feb_test(), run_add_second_to_end_of_day_test(), run_add_second_to_end_of_year_test(), run_add_second_to_leap_year_feb2_test(), run_add_second_to_leap_year_feb_test(), run_add_second_to_normal_date_test(), run_date_1855_to_timestamp_test(), run_date_2107_to_timestamp_test(), run_date_to_timestamp_0_test(), run_date_to_timestamp_test(), run_erronous_date_to_timestamp_test(), run_erronous_time_to_timestamp_test(), run_leap_year_date_to_timestamp_test(), run_time_between_dates_diff_year_test(), run_time_between_dates_exchanged_test(), run_time_between_dates_leap_year_test(), run_time_between_dates_same_year_test(), run_time_between_dates_years2_test(), run_time_between_dates_years_test(), run_timestamp_0_to_date_test(), run_timestamp_to_leap_year_date2_test(), run_timestamp_to_leap_year_date_test(), run_timestamp_to_normal_date_test(), stdio_serial_init(), sysclk_init(), test_suite_run(), and usart_serial_options.
|
static |
Test adding one second to the 28th of February, normal year.
This test checks that incrementing the end of February 28th in a year that is not a leap year with one second results in March 1st.
test | Current test case. |
References calendar_add_second_to_date(), calendar_date::date, calendar_date::hour, calendar_date::minute, calendar_date::month, calendar_date::second, test_assert_true, and calendar_date::year.
Referenced by main().
|
static |
Test adding one second to the end of a day.
This test checks that incrementing the end of a day with one second gives the correct result.
test | Current test case. |
References calendar_add_second_to_date(), calendar_date::date, calendar_date::hour, calendar_date::minute, calendar_date::month, calendar_date::second, test_assert_true, and calendar_date::year.
Referenced by main().
|
static |
Test adding one second to the end of a year.
This test checks that incrementing the end of a day year results in start of a new year.
test | Current test case. |
References calendar_add_second_to_date(), calendar_date::date, calendar_date::hour, calendar_date::minute, calendar_date::month, calendar_date::second, test_assert_true, and calendar_date::year.
Referenced by main().
|
static |
Test adding one second to the end of February, leap year.
This test checks that incrementing the end of February 29th in a year that is a leap year with one second results in March 1st.
test | Current test case. |
References calendar_add_second_to_date(), calendar_date::date, calendar_date::hour, calendar_date::minute, calendar_date::month, calendar_date::second, test_assert_true, and calendar_date::year.
Referenced by main().
|
static |
Test adding one second to the 28th of February, leap year.
This test checks that incrementing the end of February 28th in a year that is not a leap year with one second results in February 29th.
test | Current test case. |
References calendar_add_second_to_date(), calendar_date::date, calendar_date::hour, calendar_date::minute, calendar_date::month, calendar_date::second, test_assert_true, and calendar_date::year.
Referenced by main().
|
static |
Test adding one second to a normal date.
This test checks that incrementing a normal date with one second gives the correct result.
test | Current test case. |
References calendar_add_second_to_date(), calendar_date::date, calendar_date::hour, calendar_date::minute, calendar_date::month, calendar_date::second, test_assert_true, and calendar_date::year.
Referenced by main().
|
static |
Test conversion of a date before 1970 to timestamp 0.
This test checks that conversion of a date before epoch year 1970 results in timestamp 0.
test | Current test case. |
References calendar_date_to_timestamp(), calendar_date::second, and test_assert_true.
Referenced by main().
|
static |
Test conversion of a date after 2106 to timestamp 0.
This test checks that conversion of a date after overflow year 2106 results in timestamp 0.
test | Current test case. |
References calendar_date_to_timestamp(), calendar_date::second, and test_assert_true.
Referenced by main().
|
static |
Test conversion of first date to timestamp.
This test checks that conversion of the first date in UNIX time date results in timestamp 0.
test | Current test case. |
References calendar_date_to_timestamp(), calendar_date::second, and test_assert_true.
Referenced by main().
|
static |
Test conversion of a normal date to timestamp.
This test checks that conversion of a normal date results in the correct timestamp.
test | Current test case. |
References calendar_date_to_timestamp(), calendar_date::second, and test_assert_true.
Referenced by main().
|
static |
Test conversion of a date with invalid day to timestamp.
This test checks that conversion of February 29th in a year that is not a leap year results in timestamp 0.
test | Current test case. |
References calendar_date_to_timestamp(), calendar_date::second, and test_assert_true.
Referenced by main().
|
static |
Test conversion of a date with invalid time to timestamp.
This test checks that conversion of a date with 83 seconds results in timestamp 0.
test | Current test case. |
References calendar_date_to_timestamp(), calendar_date::second, and test_assert_true.
Referenced by main().
|
static |
Test conversion of a date in a leap year to timestamp.
This test checks that conversion of February 29th in a year that is a leap year results in the correct timestamp.
test | Current test case. |
References calendar_date_to_timestamp(), calendar_date::second, and test_assert_true.
Referenced by main().
|
static |
Test computation of time between dates in the different years.
This test checks that computing time between dates in the different years, but less than one year apart results in the expected duration.
test | Current test case. |
References calendar_time_between_dates(), calendar_timestamp_to_date(), calendar_date::date, calendar_date::hour, calendar_date::minute, calendar_date::month, calendar_date::second, test_assert_true, and calendar_date::year.
Referenced by main().
|
static |
Test computation of time between dates with end before start.
This test checks that computing time between dates several years apart where end date is earlier than start date results in the expected duration.
test | Current test case. |
References calendar_time_between_dates(), calendar_timestamp_to_date(), calendar_date::date, calendar_date::hour, calendar_date::minute, calendar_date::month, calendar_date::second, test_assert_true, and calendar_date::year.
Referenced by main().
|
static |
Test computation of time between dates in the same leap year.
This test checks that computing time between dates in the same leap year results the expected duration.
test | Current test case. |
References calendar_time_between_dates(), calendar_timestamp_to_date(), calendar_date::date, calendar_date::hour, calendar_date::minute, calendar_date::month, calendar_date::second, test_assert_true, and calendar_date::year.
Referenced by main().
|
static |
Test computation of time between dates in the same year.
This test checks that computing time between dates in the same year returns the expected duration.
test | Current test case. |
References calendar_time_between_dates(), calendar_timestamp_to_date(), calendar_date::date, calendar_date::hour, calendar_date::minute, calendar_date::month, calendar_date::second, test_assert_true, and calendar_date::year.
Referenced by main().
|
static |
Test computation of time between dates several years apart.
This test checks that computing time between dates several years apart results in the expected duration.
test | Current test case. |
References calendar_time_between_dates(), calendar_timestamp_to_date(), calendar_date::date, calendar_date::hour, calendar_date::minute, calendar_date::month, calendar_date::second, test_assert_true, and calendar_date::year.
Referenced by main().
|
static |
Test computation of time between dates several years apart.
This test checks that computing time between dates several years apart results in the expected duration.
test | Current test case. |
References calendar_time_between_dates(), calendar_timestamp_to_date(), calendar_date::date, calendar_date::hour, calendar_date::minute, calendar_date::month, calendar_date::second, test_assert_true, and calendar_date::year.
Referenced by main().
|
static |
Test conversion of timestamp 0 to date.
This test checks that conversion of timestamp 0 results in January 1st 1970 00:00:00.
test | Current test case. |
References calendar_timestamp_to_date(), calendar_date::date, calendar_date::hour, calendar_date::minute, calendar_date::month, calendar_date::second, test_assert_true, and calendar_date::year.
Referenced by main().
|
static |
Test conversion of timestamp to March in leap year date.
This test checks that conversion of a timestamp results in March 3rd 1992 15:30:11.
test | Current test case. |
References calendar_timestamp_to_date(), calendar_date::date, calendar_date::hour, calendar_date::minute, calendar_date::month, calendar_date::second, test_assert_true, and calendar_date::year.
Referenced by main().
|
static |
Test conversion of timestamp to end of February in leap year date.
This test checks that conversion of a timestamp results in February 29th 2008 06:05:50.
test | Current test case. |
References calendar_timestamp_to_date(), calendar_date::date, calendar_date::hour, calendar_date::minute, calendar_date::month, calendar_date::second, test_assert_true, and calendar_date::year.
Referenced by main().
|
static |
Test conversion of normal timestamp to date.
This test checks that conversion of a normal timestamp results in the expected date.
test | Current test case. |
References calendar_timestamp_to_date(), calendar_date::date, calendar_date::hour, calendar_date::minute, calendar_date::month, calendar_date::second, test_assert_true, and calendar_date::year.
Referenced by main().