Enable dynamic BACnet POSIX files for example (#374)

* Enable dynamic BACnet POSIX files for example

* Add basic unit test for BACnet File object.

* Use example file pathname in demo app.

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
Steve Karg
2023-01-04 13:11:45 -06:00
committed by GitHub
parent b91735af13
commit c9efd0b84d
8 changed files with 841 additions and 134 deletions
@@ -0,0 +1,75 @@
/**
* @file
* @brief Test for BACnet File object
* @author Steve Karg <skarg@users.sourceforge.net>
* @date January 2023
* @section LICENSE
*
* Copyright (C) 2022 Steve Karg <skarg@users.sourceforge.net>
*
* SPDX-License-Identifier: MIT
*/
#include <ztest.h>
#include <bacnet/basic/object/bacfile.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
static void test_BACnet_File_Object(void)
{
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0, test_len = 0;
BACNET_READ_PROPERTY_DATA rpdata = { 0 };
BACNET_APPLICATION_DATA_VALUE value = {0};
const int *required_property = NULL;
const uint32_t instance = 1;
bacfile_init();
bacfile_create(1);
rpdata.application_data = &apdu[0];
rpdata.application_data_len = sizeof(apdu);
rpdata.object_type = OBJECT_FILE;
rpdata.object_instance = instance;
rpdata.array_index = BACNET_ARRAY_ALL;
BACfile_Property_Lists(&required_property, NULL, NULL);
while ((*required_property) >= 0) {
rpdata.object_property = *required_property;
len = bacfile_read_property(&rpdata);
if (len < 0) {
printf("property %u: failed to read!\n",
(unsigned)rpdata.object_property);
}
zassert_true(len >= 0, NULL);
if (len >= 0) {
test_len = bacapp_decode_known_property(rpdata.application_data,
len, &value, rpdata.object_type, rpdata.object_property);
if (len != test_len) {
printf("property %u: failed to decode!\n",
(unsigned)rpdata.object_property);
}
zassert_equal(len, test_len, NULL);
}
required_property++;
}
return;
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(bacfile_tests,
ztest_unit_test(test_BACnet_File_Object)
);
ztest_run_test_suite(bacfile_tests);
}