Added AddListElement and RemoveListElement services (#418)
* Added AddListElement and RemoveListElement services Added list-element codec and unit tests. Added BACnetDestination codec and unit tests. Added RecipientList handling to NotificationClass object. Added AddListElement and RemoveListElement client example app. * Fix defects found by scan-build and CPPCHECK * Update ports errors found during CI builds * Update zephy os test build missing files in CMakeLists --------- Co-authored-by: Ondřej Hruška <ondra@ondrovo.com> Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
# 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/list_element.c
|
||||
# Support files and stubs (pathname alphabetical)
|
||||
${SRC_DIR}/bacnet/bacaddr.c
|
||||
${SRC_DIR}/bacnet/bacapp.c
|
||||
${SRC_DIR}/bacnet/bacdcode.c
|
||||
${SRC_DIR}/bacnet/bacdest.c
|
||||
${SRC_DIR}/bacnet/bacdevobjpropref.c
|
||||
${SRC_DIR}/bacnet/bacerror.c
|
||||
${SRC_DIR}/bacnet/bacint.c
|
||||
${SRC_DIR}/bacnet/bacreal.c
|
||||
${SRC_DIR}/bacnet/bacstr.c
|
||||
${SRC_DIR}/bacnet/bactext.c
|
||||
${SRC_DIR}/bacnet/basic/sys/bigend.c
|
||||
${SRC_DIR}/bacnet/datetime.c
|
||||
${SRC_DIR}/bacnet/basic/sys/days.c
|
||||
${SRC_DIR}/bacnet/indtext.c
|
||||
${SRC_DIR}/bacnet/hostnport.c
|
||||
${SRC_DIR}/bacnet/lighting.c
|
||||
${SRC_DIR}/bacnet/timestamp.c
|
||||
${SRC_DIR}/bacnet/memcopy.c
|
||||
${SRC_DIR}/bacnet/weeklyschedule.c
|
||||
${SRC_DIR}/bacnet/bactimevalue.c
|
||||
${SRC_DIR}/bacnet/dailyschedule.c
|
||||
# Test and test library files
|
||||
./src/main.c
|
||||
${ZTST_DIR}/ztest_mock.c
|
||||
${ZTST_DIR}/ztest.c
|
||||
)
|
||||
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* @file
|
||||
* @brief Unit test for list-element services encode and decode
|
||||
* @author Steve Karg <skarg@users.sourceforge.net>
|
||||
* @date December 2022
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#include <ztest.h>
|
||||
#include <bacnet/bacdest.h>
|
||||
#include <bacnet/list_element.h>
|
||||
|
||||
static void test_ListElement(void)
|
||||
{
|
||||
uint8_t apdu[MAX_APDU] = { 0 };
|
||||
BACNET_LIST_ELEMENT_DATA list_element = { 0 }, test_list_element = { 0 };
|
||||
int len = 0, apdu_len = 0, null_len = 0, test_len = 0;
|
||||
uint8_t application_data[MAX_APDU] = { 0 }, *test_application_data = NULL;
|
||||
int application_data_len = 0, test_application_data_len = 0;
|
||||
unsigned i = 0;
|
||||
BACNET_DESTINATION destination[5] = { 0 }, test_destination[5] = { 0 };
|
||||
const int destination_size = sizeof(destination) / sizeof(destination[0]);
|
||||
|
||||
list_element.application_data = NULL;
|
||||
list_element.application_data_len = 0;
|
||||
null_len = list_element_encode_service_request(NULL, &list_element);
|
||||
apdu_len = list_element_encode_service_request(apdu, &list_element);
|
||||
zassert_equal(apdu_len, null_len, NULL);
|
||||
test_len =
|
||||
list_element_decode_service_request(apdu, apdu_len, &test_list_element);
|
||||
zassert_equal(apdu_len, test_len, NULL);
|
||||
/* fill application_data with RecipientList default data */
|
||||
list_element.array_index = BACNET_ARRAY_ALL;
|
||||
for (i = 0; i < destination_size; i++) {
|
||||
bacnet_destination_default_init(&destination[i]);
|
||||
application_data_len += bacnet_destination_encode(
|
||||
&application_data[application_data_len], &destination[i]);
|
||||
}
|
||||
list_element.application_data = application_data;
|
||||
list_element.application_data_len = application_data_len;
|
||||
apdu_len = list_element_encode_service_request(apdu, &list_element);
|
||||
test_len =
|
||||
list_element_decode_service_request(apdu, apdu_len, &test_list_element);
|
||||
zassert_equal(apdu_len, test_len, NULL);
|
||||
zassert_equal(test_list_element.array_index, BACNET_ARRAY_ALL, NULL);
|
||||
test_application_data = list_element.application_data;
|
||||
test_application_data_len = list_element.application_data_len;
|
||||
for (i = 0; i < destination_size; i++) {
|
||||
test_len = bacnet_destination_decode(test_application_data,
|
||||
test_application_data_len, &test_destination[i]);
|
||||
zassert_true(
|
||||
bacnet_destination_same(&destination[i], &test_destination[i]),
|
||||
NULL);
|
||||
zassert_not_equal(test_len, BACNET_STATUS_REJECT, NULL);
|
||||
test_application_data_len -= test_len;
|
||||
test_application_data += test_len;
|
||||
}
|
||||
zassert_equal(test_application_data_len, 0, NULL);
|
||||
}
|
||||
|
||||
static void test_ListElementError(void)
|
||||
{
|
||||
uint8_t apdu[MAX_APDU] = { 0 };
|
||||
BACNET_LIST_ELEMENT_DATA list_element = { 0 }, test_list_element = { 0 };
|
||||
int len = 0, apdu_len = 0, null_len = 0, test_len = 0;
|
||||
|
||||
list_element.error_class = ERROR_CLASS_SERVICES;
|
||||
list_element.error_code = ERROR_CODE_REJECT_PARAMETER_OUT_OF_RANGE;
|
||||
list_element.first_failed_element_number = 0;
|
||||
null_len = list_element_error_ack_encode(NULL, &list_element);
|
||||
apdu_len = list_element_error_ack_encode(apdu, &list_element);
|
||||
zassert_equal(apdu_len, null_len, NULL);
|
||||
test_len =
|
||||
list_element_error_ack_decode(apdu, apdu_len, &test_list_element);
|
||||
zassert_equal(apdu_len, test_len, NULL);
|
||||
zassert_equal(
|
||||
test_list_element.error_class, list_element.error_class, NULL);
|
||||
zassert_equal(test_list_element.error_code, list_element.error_code, NULL);
|
||||
zassert_equal(test_list_element.first_failed_element_number,
|
||||
list_element.first_failed_element_number, NULL);
|
||||
}
|
||||
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(list_element_tests, ztest_unit_test(test_ListElement),
|
||||
ztest_unit_test(test_ListElementError));
|
||||
|
||||
ztest_run_test_suite(list_element_tests);
|
||||
}
|
||||
Reference in New Issue
Block a user