Microchip® Advanced Software Framework

common/services/calendar/unit_tests/unit_tests.c File Reference

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...
 

static void run_add_second_to_end_feb_test ( const struct test_case test)
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.

Parameters
testCurrent 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 void run_add_second_to_end_of_day_test ( const struct test_case test)
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.

Parameters
testCurrent 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 void run_add_second_to_end_of_year_test ( const struct test_case test)
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.

Parameters
testCurrent 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 void run_add_second_to_leap_year_feb2_test ( const struct test_case test)
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.

Parameters
testCurrent 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 void run_add_second_to_leap_year_feb_test ( const struct test_case test)
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.

Parameters
testCurrent 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 void run_add_second_to_normal_date_test ( const struct test_case test)
static

Test adding one second to a normal date.

This test checks that incrementing a normal date with one second gives the correct result.

Parameters
testCurrent 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 void run_date_1855_to_timestamp_test ( const struct test_case test)
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.

Parameters
testCurrent test case.

References calendar_date_to_timestamp(), calendar_date::second, and test_assert_true.

Referenced by main().

static void run_date_2107_to_timestamp_test ( const struct test_case test)
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.

Parameters
testCurrent test case.

References calendar_date_to_timestamp(), calendar_date::second, and test_assert_true.

Referenced by main().

static void run_date_to_timestamp_0_test ( const struct test_case test)
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.

Parameters
testCurrent test case.

References calendar_date_to_timestamp(), calendar_date::second, and test_assert_true.

Referenced by main().

static void run_date_to_timestamp_test ( const struct test_case test)
static

Test conversion of a normal date to timestamp.

This test checks that conversion of a normal date results in the correct timestamp.

Parameters
testCurrent test case.

References calendar_date_to_timestamp(), calendar_date::second, and test_assert_true.

Referenced by main().

static void run_erronous_date_to_timestamp_test ( const struct test_case test)
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.

Parameters
testCurrent test case.

References calendar_date_to_timestamp(), calendar_date::second, and test_assert_true.

Referenced by main().

static void run_erronous_time_to_timestamp_test ( const struct test_case test)
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.

Parameters
testCurrent test case.

References calendar_date_to_timestamp(), calendar_date::second, and test_assert_true.

Referenced by main().

static void run_leap_year_date_to_timestamp_test ( const struct test_case test)
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.

Parameters
testCurrent test case.

References calendar_date_to_timestamp(), calendar_date::second, and test_assert_true.

Referenced by main().

static void run_time_between_dates_diff_year_test ( const struct test_case test)
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.

Parameters
testCurrent 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 void run_time_between_dates_exchanged_test ( const struct test_case test)
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.

Parameters
testCurrent 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 void run_time_between_dates_leap_year_test ( const struct test_case test)
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.

Parameters
testCurrent 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 void run_time_between_dates_same_year_test ( const struct test_case test)
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.

Parameters
testCurrent 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 void run_time_between_dates_years2_test ( const struct test_case test)
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.

Parameters
testCurrent 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 void run_time_between_dates_years_test ( const struct test_case test)
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.

Parameters
testCurrent 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 void run_timestamp_0_to_date_test ( const struct test_case test)
static

Test conversion of timestamp 0 to date.

This test checks that conversion of timestamp 0 results in January 1st 1970 00:00:00.

Parameters
testCurrent 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 void run_timestamp_to_leap_year_date2_test ( const struct test_case test)
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.

Parameters
testCurrent 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 void run_timestamp_to_leap_year_date_test ( const struct test_case test)
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.

Parameters
testCurrent 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 void run_timestamp_to_normal_date_test ( const struct test_case test)
static

Test conversion of normal timestamp to date.

This test checks that conversion of a normal timestamp results in the expected date.

Parameters
testCurrent 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().