Issue 187 enable skipped ztest suites (#189)
* Fix some ztests that were skipped * Expose bacapp_same_value() * Fix bacapp, ptransfer tests * Fix bugs in Load_Control object & tests * refactor days functions from datetime module * fix legacy ctests * Add bacnet/basic/sys/days.[ch] to Zephyr build * Update ztest to match from Zephyr v2.6.0; update ringbuf, datetime to build * Fixup ztest test for object/acc * Fix bvlc_address_from_ascii; enable/fix bvlc test * Comment cleanup * test/bacnet/basic/object/lc partially enabled * Fix bacapp_decode_data_len return status on erroneous input * fix ztest include fatal error * fix ztest strsignal reference fatal error * fix zassert_mem_equal reference syntax error * fix zassert_mem_equal reference syntax error Co-authored-by: Gregory Shue <gregory.shue@legrand.us> Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
|
||||
|
||||
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
|
||||
project(test_${basename}
|
||||
VERSION 1.0.0
|
||||
LANGUAGES C)
|
||||
|
||||
|
||||
string(REGEX REPLACE
|
||||
"/test/bacnet/[a-zA-Z_/-]*$"
|
||||
"/src"
|
||||
SRC_DIR
|
||||
${CMAKE_CURRENT_SOURCE_DIR})
|
||||
string(REGEX REPLACE
|
||||
"/test/bacnet/[a-zA-Z_/-]*$"
|
||||
"/test"
|
||||
TST_DIR
|
||||
${CMAKE_CURRENT_SOURCE_DIR})
|
||||
set(ZTST_DIR "${TST_DIR}/ztest/src")
|
||||
|
||||
add_compile_definitions(
|
||||
BIG_ENDIAN=0
|
||||
CONFIG_ZTEST=1
|
||||
)
|
||||
|
||||
include_directories(
|
||||
${SRC_DIR}
|
||||
${TST_DIR}/ztest/include
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
# File(s) under test
|
||||
${SRC_DIR}/bacnet/basic/sys/days.c
|
||||
# Support files and stubs (pathname alphabetical)
|
||||
# Test and test library files
|
||||
./src/main.c
|
||||
${ZTST_DIR}/ztest_mock.c
|
||||
${ZTST_DIR}/ztest.c
|
||||
)
|
||||
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Steve Karg <skarg@users.sourceforge.net>
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
/* @file
|
||||
* @brief test BACnet integer encode/decode APIs
|
||||
*/
|
||||
|
||||
#include <ztest.h>
|
||||
#include <bacnet/basic/sys/days.h>
|
||||
|
||||
/**
|
||||
* @addtogroup bacnet_tests
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Unit Test for the days, checking the epoch conversion
|
||||
*/
|
||||
static void test_epoch_conversion_date(
|
||||
uint16_t epoch_year,
|
||||
uint16_t year,
|
||||
uint8_t month,
|
||||
uint8_t day)
|
||||
{
|
||||
uint32_t days;
|
||||
uint16_t test_year;
|
||||
uint8_t test_month;
|
||||
uint8_t test_day;
|
||||
|
||||
/* conversions of day and date */
|
||||
days = days_since_epoch(epoch_year, year, month, day);
|
||||
days_since_epoch_to_date(epoch_year, days, &test_year, &test_month,
|
||||
&test_day);
|
||||
zassert_equal(year, test_year, NULL);
|
||||
zassert_equal(month, test_month, NULL);
|
||||
zassert_equal(day, test_day, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit Test for the epoch
|
||||
*/
|
||||
static void test_days_epoch_conversion(void)
|
||||
{
|
||||
const uint16_t epoch_year = 2000;
|
||||
|
||||
test_epoch_conversion_date(epoch_year, 2000, 1, 1);
|
||||
test_epoch_conversion_date(epoch_year, 2048, 2, 28);
|
||||
test_epoch_conversion_date(epoch_year, 2048, 2, 29);
|
||||
test_epoch_conversion_date(epoch_year, 2038, 6, 15);
|
||||
test_epoch_conversion_date(epoch_year, 9999, 12, 31);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit Test for the days and year to month date year
|
||||
*/
|
||||
static void test_days_of_year_to_month_day_date(
|
||||
uint16_t year,
|
||||
uint16_t days,
|
||||
uint8_t month,
|
||||
uint8_t day)
|
||||
{
|
||||
uint8_t test_month = 0;
|
||||
uint8_t test_day = 0;
|
||||
/* conversions of days and year */
|
||||
days_of_year_to_month_day(days , year, &test_month, &test_day);
|
||||
zassert_equal(month, test_month, NULL);
|
||||
zassert_equal(day, test_day, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit Test for the days and year to month date year
|
||||
*/
|
||||
static void test_days_of_year_to_md(void)
|
||||
{
|
||||
test_days_of_year_to_month_day_date(2029, 145, 5, 25);
|
||||
test_days_of_year_to_month_day_date(2000, 260, 9, 16);
|
||||
test_days_of_year_to_month_day_date(1995, 67, 3, 8);
|
||||
test_days_of_year_to_month_day_date(2092, 366, 12, 31);
|
||||
test_days_of_year_to_month_day_date(2070, 105, 4, 15);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit Test for the days, checking the date to see if it is a valid day
|
||||
*/
|
||||
static void test_date_is_valid_day(
|
||||
uint16_t year,
|
||||
uint8_t month)
|
||||
{
|
||||
uint8_t last_day = days_per_month(year, month);
|
||||
|
||||
zassert_equal(days_date_is_valid(year, month, 0), false, NULL);
|
||||
zassert_equal(days_date_is_valid(year, month, 1), true, NULL);
|
||||
zassert_equal(days_date_is_valid(year, month, 15), true, NULL);
|
||||
zassert_equal(days_date_is_valid(year, month, last_day), true, NULL);
|
||||
zassert_equal(days_date_is_valid(year, month, 32), false, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit Test for the days, checking the date to see if it is a valid date
|
||||
*/
|
||||
static void test_days_date_is_valid(void)
|
||||
{
|
||||
/* first month */
|
||||
test_date_is_valid_day(0, 1);
|
||||
test_date_is_valid_day(2012, 1);
|
||||
test_date_is_valid_day(9999, 1);
|
||||
/* middle month */
|
||||
test_date_is_valid_day(0, 6);
|
||||
test_date_is_valid_day(2012, 6);
|
||||
test_date_is_valid_day(9999, 6);
|
||||
/* last month */
|
||||
test_date_is_valid_day(0, 12);
|
||||
test_date_is_valid_day(2012, 12);
|
||||
test_date_is_valid_day(9999, 12);
|
||||
/* february */
|
||||
test_date_is_valid_day(0, 2);
|
||||
test_date_is_valid_day(2000, 2);
|
||||
test_date_is_valid_day(2001, 2);
|
||||
test_date_is_valid_day(2002, 2);
|
||||
test_date_is_valid_day(2003, 2);
|
||||
test_date_is_valid_day(2004, 2);
|
||||
test_date_is_valid_day(9999, 2);
|
||||
/* invalid months */
|
||||
zassert_equal(days_per_month(0, 0), 0, NULL);
|
||||
zassert_equal(days_per_month(0, 13), 0, NULL);
|
||||
zassert_equal(days_per_month(0, 99), 0, NULL);
|
||||
zassert_equal(days_per_month(0, 0), 0, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit Test for days apart, checking the dates to see how many days apart
|
||||
*/
|
||||
static void test_days_apart(void)
|
||||
{
|
||||
zassert_equal(days_apart(2000, 1, 1, 2000, 1, 1), 0, NULL);
|
||||
zassert_equal(days_apart(2000, 1, 1, 2000, 1, 2), 1, NULL);
|
||||
zassert_equal(days_apart(2000, 1, 1, 2000, 2, 1), 31, NULL);
|
||||
zassert_equal(days_apart(2000, 1, 1, 2000, 12, 31), 365, NULL);
|
||||
zassert_equal(days_apart(2000, 1, 1, 2001, 1, 1), 366, NULL);
|
||||
zassert_equal(days_apart(2001, 1, 1, 2000, 1, 1), 366, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(days_tests,
|
||||
ztest_unit_test(test_days_epoch_conversion),
|
||||
ztest_unit_test(test_days_of_year_to_md),
|
||||
ztest_unit_test(test_days_date_is_valid),
|
||||
ztest_unit_test(test_days_apart)
|
||||
);
|
||||
|
||||
ztest_run_test_suite(days_tests);
|
||||
}
|
||||
@@ -77,7 +77,7 @@ static void testRingAroundBuffer(
|
||||
* @param element_size - size of one data element
|
||||
* @param element_count - number of data elements in the store
|
||||
*/
|
||||
static bool testRingBuf(
|
||||
static void testRingBuf(
|
||||
uint8_t *data_store,
|
||||
uint8_t *data_element,
|
||||
unsigned element_size,
|
||||
@@ -92,7 +92,7 @@ static bool testRingBuf(
|
||||
status =
|
||||
Ringbuf_Init(&test_buffer, data_store, element_size, element_count);
|
||||
if (!status) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
zassert_true(Ringbuf_Empty(&test_buffer), NULL);
|
||||
zassert_equal(Ringbuf_Depth(&test_buffer), 0, NULL);
|
||||
@@ -161,8 +161,6 @@ static bool testRingBuf(
|
||||
|
||||
testRingAroundBuffer(
|
||||
&test_buffer, data_element, element_size, element_count);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -170,13 +168,11 @@ static bool testRingBuf(
|
||||
*/
|
||||
static void testRingBufSizeSmall(void)
|
||||
{
|
||||
bool status;
|
||||
uint8_t data_element[5];
|
||||
uint8_t data_store[sizeof(data_element) * NEXT_POWER_OF_2(16)];
|
||||
|
||||
status = testRingBuf(data_store, data_element, sizeof(data_element),
|
||||
testRingBuf(data_store, data_element, sizeof(data_element),
|
||||
sizeof(data_store) / sizeof(data_element));
|
||||
zassert_true(status, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,13 +180,11 @@ static void testRingBufSizeSmall(void)
|
||||
*/
|
||||
static void testRingBufSizeLarge(void)
|
||||
{
|
||||
bool status;
|
||||
uint8_t data_element[16];
|
||||
uint8_t data_store[sizeof(data_element) * NEXT_POWER_OF_2(99)];
|
||||
|
||||
status = testRingBuf(data_store, data_element, sizeof(data_element),
|
||||
testRingBuf(data_store, data_element, sizeof(data_element),
|
||||
sizeof(data_store) / sizeof(data_element));
|
||||
zassert_true(status, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -198,13 +192,14 @@ static void testRingBufSizeLarge(void)
|
||||
*/
|
||||
static void testRingBufSizeInvalid(void)
|
||||
{
|
||||
bool status;
|
||||
RING_BUFFER test_buffer;
|
||||
uint8_t data_element[16];
|
||||
uint8_t data_store[sizeof(data_element) * 99];
|
||||
|
||||
status = testRingBuf(data_store, data_element, sizeof(data_element),
|
||||
sizeof(data_store) / sizeof(data_element));
|
||||
zassert_false(status, NULL);
|
||||
zassert_false(Ringbuf_Init(&test_buffer,
|
||||
data_store, sizeof(data_element),
|
||||
sizeof(data_store) / sizeof(data_element)),
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void testRingBufPowerOfTwo(void)
|
||||
|
||||
Reference in New Issue
Block a user