Bugfix/bacapp deprecation fixes (#578)

* Secured bacapp_decode_application_data_safe(), bacapp_decode_application_data_len(), bacapp_decode_context_data(), bacapp_decode_known_property() for timestamp, bacapp_decode_context_data_len(), and bacapp_data_len() functions.

* Fixed Command, Credential Data Input, and Schedule objects unit test
This commit is contained in:
Steve Karg
2024-02-27 14:03:14 -06:00
committed by GitHub
parent 33c7df249a
commit dfef5208d1
21 changed files with 698 additions and 548 deletions
@@ -27,6 +27,7 @@ add_compile_definitions(
include_directories(
${SRC_DIR}
${TST_DIR}/bacnet/basic/object
${TST_DIR}/ztest/include
)
@@ -52,6 +53,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/proplist.c
${SRC_DIR}/bacnet/timestamp.c
${SRC_DIR}/bacnet/wp.c
${SRC_DIR}/bacnet/weeklyschedule.c
@@ -61,6 +63,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/special_event.c
# Test and test library files
./src/main.c
${TST_DIR}/bacnet/basic/object/property_test.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
@@ -1,16 +1,15 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
/**
* @file
* @brief Unit test for object
* @author Steve Karg <skarg@users.sourceforge.net>
* @date February 2024
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <zephyr/ztest.h>
#include <bacnet/basic/object/credential_data_input.h>
#include <bacnet/bactext.h>
#include <property_test.h>
/**
* @addtogroup bacnet_tests
@@ -26,65 +25,25 @@ ZTEST(credential_data_input_tests, testCredentialDataInput)
static void testCredentialDataInput(void)
#endif
{
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0;
int test_len = 0;
BACNET_READ_PROPERTY_DATA rpdata;
/* for decode value data */
BACNET_APPLICATION_DATA_VALUE value;
const int *pRequired = NULL;
const int *pOptional = NULL;
const int *pProprietary = NULL;
unsigned count = 0;
uint32_t object_instance = 0;
const int skip_fail_property_list[] = {
PROP_PRESENT_VALUE,
PROP_UPDATE_TIME,
PROP_SUPPORTED_FORMATS,
-1 };
Credential_Data_Input_Init();
count = Credential_Data_Input_Count();
zassert_true(count > 0, NULL);
object_instance = Credential_Data_Input_Index_To_Instance(0);
rpdata.application_data = &apdu[0];
rpdata.application_data_len = sizeof(apdu);
rpdata.object_type = OBJECT_CREDENTIAL_DATA_INPUT;
rpdata.object_instance = object_instance;
Credential_Data_Input_Property_Lists(&pRequired, &pOptional, &pProprietary);
while ((*pRequired) != -1) {
rpdata.object_property = *pRequired;
rpdata.array_index = BACNET_ARRAY_ALL;
len = Credential_Data_Input_Read_Property(&rpdata);
zassert_not_equal(len, BACNET_STATUS_ERROR, NULL);
if (len > 0) {
test_len = bacapp_decode_application_data(rpdata.application_data,
(uint8_t)rpdata.application_data_len, &value);
if (len != test_len) {
printf("property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property));
}
if (rpdata.object_property == PROP_PRIORITY_ARRAY) {
/* FIXME: known fail to decode */
len = test_len;
}
zassert_true(test_len >= 0, NULL);
} else {
printf("property '%s': failed to read!\n",
bactext_property_name(rpdata.object_property));
}
pRequired++;
}
while ((*pOptional) != -1) {
rpdata.object_property = *pOptional;
rpdata.array_index = BACNET_ARRAY_ALL;
len = Credential_Data_Input_Read_Property(&rpdata);
zassert_not_equal(len, BACNET_STATUS_ERROR, NULL);
if (len > 0) {
test_len = bacapp_decode_application_data(rpdata.application_data,
(uint8_t)rpdata.application_data_len, &value);
zassert_true(test_len >= 0, NULL);
} else {
printf("property '%s': failed to read!\n",
bactext_property_name(rpdata.object_property));
}
pOptional++;
}
bacnet_object_properties_read_write_test(
OBJECT_CREDENTIAL_DATA_INPUT,
object_instance,
Credential_Data_Input_Property_Lists,
Credential_Data_Input_Read_Property,
Credential_Data_Input_Write_Property,
skip_fail_property_list);
}
/**
* @}