f641aacddb
* added or updated secure the BACnet primitive value decoders - the core codecs - named bacnet_x_decode(), bacnet_x_application_decode() and bacnet_x_context_decode where x is one of the 13 BACnet primitive value names. The updated API includes an APDU size to prevent over-reading of an APDU buffer while decoding. Improved or added unit test code coverage for the BACnet primitive value decoders. * marked the insecure decoding API as 'deprecated' which is defined in src/bacnet/basic/sys/platform.h and can be disabled during a build. * added secure decoders for BACnetTimeValue, BACnetHostNPort, BACnetTimeStamp, BACnetAddress, and Weekly_Schedule and improved unit test code coverage. * improved test code coverage for BACnet objects and properties. * secured AtomicReadFile and AtomicWriteFile service decoders and improved unit test code coverage. * secured BACnet Error service decoder and improved unit test code coverage. --------- Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
90 lines
2.5 KiB
C
90 lines
2.5 KiB
C
/*
|
|
* Copyright (c) 2020 Legrand North America, LLC.
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
/* @file
|
|
* @brief test BACnet integer encode/decode APIs
|
|
*/
|
|
|
|
#include <zephyr/ztest.h>
|
|
#include <bacnet/basic/object/access_credential.h>
|
|
|
|
/**
|
|
* @addtogroup bacnet_tests
|
|
* @{
|
|
*/
|
|
|
|
/**
|
|
* @brief Test
|
|
*/
|
|
#if defined(CONFIG_ZTEST_NEW_API)
|
|
ZTEST(access_credential_tests, testAccessCredential)
|
|
#else
|
|
static void testAccessCredential(void)
|
|
#endif
|
|
{
|
|
uint8_t apdu[MAX_APDU] = { 0 };
|
|
int len = 0;
|
|
int test_len = 0;
|
|
BACNET_READ_PROPERTY_DATA rpdata = { 0 };
|
|
BACNET_APPLICATION_DATA_VALUE value = { 0 };
|
|
BACNET_APPLICATION_DATA_VALUE value2 = { 0 };
|
|
const int *required_property = NULL;
|
|
bool status = false;
|
|
|
|
Access_Credential_Init();
|
|
rpdata.application_data = &apdu[0];
|
|
rpdata.application_data_len = sizeof(apdu);
|
|
rpdata.object_type = OBJECT_ACCESS_CREDENTIAL;
|
|
rpdata.object_instance = Access_Credential_Index_To_Instance(0);
|
|
status = Access_Credential_Valid_Instance(rpdata.object_instance);
|
|
zassert_true(status, NULL);
|
|
Access_Credential_Property_Lists(&required_property, NULL, NULL);
|
|
while ((*required_property) >= 0) {
|
|
rpdata.object_property = *required_property;
|
|
rpdata.array_index = BACNET_ARRAY_ALL;
|
|
len = Access_Credential_Read_Property(&rpdata);
|
|
zassert_true(len >= 0, NULL);
|
|
if (len >= 0) {
|
|
if (IS_CONTEXT_SPECIFIC(rpdata.application_data[0])) {
|
|
test_len = bacapp_decode_context_data(rpdata.application_data,
|
|
len, &value, rpdata.object_property);
|
|
} else {
|
|
test_len = bacapp_decode_application_data(
|
|
rpdata.application_data, len, &value);
|
|
if (test_len < len) {
|
|
test_len += bacapp_decode_application_data(
|
|
rpdata.application_data + test_len, len - test_len,
|
|
&value2);
|
|
}
|
|
}
|
|
if (len != test_len) {
|
|
fprintf(stderr, "property '%d': failed to decode!\n",
|
|
rpdata.object_property);
|
|
}
|
|
zassert_true(len == test_len, NULL);
|
|
}
|
|
required_property++;
|
|
}
|
|
|
|
return;
|
|
}
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
|
|
#if defined(CONFIG_ZTEST_NEW_API)
|
|
ZTEST_SUITE(access_credential_tests, NULL, NULL, NULL, NULL, NULL);
|
|
#else
|
|
void test_main(void)
|
|
{
|
|
ztest_test_suite(
|
|
access_credential_tests, ztest_unit_test(testAccessCredential));
|
|
|
|
ztest_run_test_suite(access_credential_tests);
|
|
}
|
|
#endif
|