Feature/add create object service (#476)

Added BACnet CreateObject and DeleteObject services

* refactored codec for BACnetPropertyValue into bacapp module
* added unit tests for BACnetPropertyValue
* refactored COV and Events to use BACnetPropertyValue codec API
* added unit tests for COV
* added overrun safe decoders for tag numbers and boolean context
* added unit tests and codecs for CreateObject and DeleteObject services
* added APDU service handers and senders for CreateObject and DeleteObject services
* added command line apps bacco and bacdo for CreateObject and DeleteObject services
* added CreateObject and DeleteObject service handling in example server app and device object
* added new BACnetRejectReason, Error Class, and BACnetAbortReason enumerations and conversions

---------

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
Steve Karg
2023-08-28 13:02:35 -05:00
committed by GitHub
parent 8184afea12
commit f61f4300be
60 changed files with 3946 additions and 942 deletions
+192 -137
View File
@@ -17,46 +17,46 @@
static const BACNET_APPLICATION_TAG tag_list[] = {
BACNET_APPLICATION_TAG_NULL,
#if defined(BACAPP_BOOLEAN)
#if defined(BACAPP_BOOLEAN)
BACNET_APPLICATION_TAG_BOOLEAN,
#endif
#if defined(BACAPP_UNSIGNED)
#endif
#if defined(BACAPP_UNSIGNED)
BACNET_APPLICATION_TAG_UNSIGNED_INT,
#endif
#if defined(BACAPP_SIGNED)
#endif
#if defined(BACAPP_SIGNED)
BACNET_APPLICATION_TAG_SIGNED_INT,
#endif
#if defined(BACAPP_REAL)
#endif
#if defined(BACAPP_REAL)
BACNET_APPLICATION_TAG_REAL,
#endif
#if defined(BACAPP_DOUBLE)
#endif
#if defined(BACAPP_DOUBLE)
BACNET_APPLICATION_TAG_DOUBLE,
#endif
#if defined(BACAPP_OCTET_STRING)
#endif
#if defined(BACAPP_OCTET_STRING)
BACNET_APPLICATION_TAG_OCTET_STRING,
#endif
#if defined(BACAPP_CHARACTER_STRING)
#endif
#if defined(BACAPP_CHARACTER_STRING)
BACNET_APPLICATION_TAG_CHARACTER_STRING,
#endif
#if defined(BACAPP_BIT_STRING)
#endif
#if defined(BACAPP_BIT_STRING)
BACNET_APPLICATION_TAG_BIT_STRING,
#endif
#if defined(BACAPP_ENUMERATED)
#endif
#if defined(BACAPP_ENUMERATED)
BACNET_APPLICATION_TAG_ENUMERATED,
#endif
#if defined(BACAPP_DATE)
#endif
#if defined(BACAPP_DATE)
BACNET_APPLICATION_TAG_DATE,
#endif
#if defined(BACAPP_TIME)
#endif
#if defined(BACAPP_TIME)
BACNET_APPLICATION_TAG_TIME,
#endif
#if defined(BACAPP_OBJECT_ID)
#endif
#if defined(BACAPP_OBJECT_ID)
BACNET_APPLICATION_TAG_OBJECT_ID,
#endif
#if defined(BACAPP_TYPES_EXTRA)
#endif
#if defined(BACAPP_TYPES_EXTRA)
BACNET_APPLICATION_TAG_LIGHTING_COMMAND,
BACNET_APPLICATION_TAG_HOST_N_PORT,
#endif
#endif
};
/**
@@ -71,15 +71,16 @@ static void test_bacapp_decode_application_data(void)
#endif
{
uint8_t apdu[128] = { 0 };
//unsigned max_apdu_len = sizeof(apdu);
// unsigned max_apdu_len = sizeof(apdu);
BACNET_APPLICATION_DATA_VALUE value = { 0 };
zassert_equal(bacapp_decode_application_data(NULL, sizeof(apdu), &value), 0, NULL);
zassert_equal(
bacapp_decode_application_data(NULL, sizeof(apdu), &value), 0, NULL);
zassert_equal(bacapp_decode_application_data(apdu, 0, &value), 0, NULL);
zassert_equal(bacapp_decode_application_data(apdu, sizeof(apdu), NULL), 0, NULL);
zassert_equal(
bacapp_decode_application_data(apdu, sizeof(apdu), NULL), 0, NULL);
}
#if defined(CONFIG_ZTEST_NEW_API)
ZTEST(bacapp_tests, test_bacapp_decode_data_len)
#else
@@ -90,58 +91,89 @@ static void test_bacapp_decode_data_len(void)
uint32_t len_value_type = 0;
int expected_value = 0;
zassert_equal(bacapp_decode_data_len(NULL, BACNET_APPLICATION_TAG_NULL, sizeof(apdu)), 0, NULL);
zassert_equal(bacapp_decode_data_len(apdu, UINT8_MAX, sizeof(apdu)), 0, NULL);
zassert_equal(
bacapp_decode_data_len(NULL, BACNET_APPLICATION_TAG_NULL, sizeof(apdu)),
0, NULL);
zassert_equal(
bacapp_decode_data_len(apdu, UINT8_MAX, sizeof(apdu)), 0, NULL);
expected_value = (int) (~0U >> 1); /* INT_MAX is not universally defined */
zassert_equal(bacapp_decode_data_len(apdu, BACNET_APPLICATION_TAG_UNSIGNED_INT, UINT32_MAX), expected_value, NULL);
expected_value = (int)(~0U >> 1); /* INT_MAX is not universally defined */
zassert_equal(bacapp_decode_data_len(
apdu, BACNET_APPLICATION_TAG_UNSIGNED_INT, UINT32_MAX),
expected_value, NULL);
zassert_equal(bacapp_decode_data_len(apdu, BACNET_APPLICATION_TAG_NULL, sizeof(apdu)), 0, NULL);
zassert_equal(bacapp_decode_data_len(apdu, BACNET_APPLICATION_TAG_BOOLEAN, sizeof(apdu)), 0, NULL);
zassert_equal(
bacapp_decode_data_len(apdu, BACNET_APPLICATION_TAG_NULL, sizeof(apdu)),
0, NULL);
zassert_equal(bacapp_decode_data_len(
apdu, BACNET_APPLICATION_TAG_BOOLEAN, sizeof(apdu)),
0, NULL);
len_value_type = INT32_MAX - 1;
expected_value = (int) len_value_type;
zassert_equal(bacapp_decode_data_len(apdu, BACNET_APPLICATION_TAG_UNSIGNED_INT, len_value_type), expected_value, NULL);
expected_value = (int)len_value_type;
zassert_equal(bacapp_decode_data_len(apdu,
BACNET_APPLICATION_TAG_UNSIGNED_INT, len_value_type),
expected_value, NULL);
len_value_type = INT32_MAX - 2;
expected_value = (int) len_value_type;
zassert_equal(bacapp_decode_data_len(apdu, BACNET_APPLICATION_TAG_SIGNED_INT, len_value_type), expected_value, NULL);
expected_value = (int)len_value_type;
zassert_equal(bacapp_decode_data_len(
apdu, BACNET_APPLICATION_TAG_SIGNED_INT, len_value_type),
expected_value, NULL);
len_value_type = INT32_MAX - 5;
expected_value = (int) len_value_type;
zassert_equal(bacapp_decode_data_len(apdu, BACNET_APPLICATION_TAG_REAL, len_value_type), expected_value, NULL);
expected_value = (int)len_value_type;
zassert_equal(bacapp_decode_data_len(
apdu, BACNET_APPLICATION_TAG_REAL, len_value_type),
expected_value, NULL);
len_value_type = INT32_MAX - 9;
expected_value = (int) len_value_type;
zassert_equal(bacapp_decode_data_len(apdu, BACNET_APPLICATION_TAG_DOUBLE, len_value_type), expected_value, NULL);
expected_value = (int)len_value_type;
zassert_equal(bacapp_decode_data_len(
apdu, BACNET_APPLICATION_TAG_DOUBLE, len_value_type),
expected_value, NULL);
len_value_type = INT32_MAX - 13;
expected_value = (int) len_value_type;
zassert_equal(bacapp_decode_data_len(apdu, BACNET_APPLICATION_TAG_OCTET_STRING, len_value_type), expected_value, NULL);
expected_value = (int)len_value_type;
zassert_equal(bacapp_decode_data_len(apdu,
BACNET_APPLICATION_TAG_OCTET_STRING, len_value_type),
expected_value, NULL);
len_value_type = INT32_MAX - 17;
expected_value = (int) len_value_type;
zassert_equal(bacapp_decode_data_len(apdu, BACNET_APPLICATION_TAG_CHARACTER_STRING, len_value_type), expected_value, NULL);
expected_value = (int)len_value_type;
zassert_equal(bacapp_decode_data_len(apdu,
BACNET_APPLICATION_TAG_CHARACTER_STRING, len_value_type),
expected_value, NULL);
len_value_type = INT32_MAX - 19;
expected_value = (int) len_value_type;
zassert_equal(bacapp_decode_data_len(apdu, BACNET_APPLICATION_TAG_BIT_STRING, len_value_type), expected_value, NULL);
expected_value = (int)len_value_type;
zassert_equal(bacapp_decode_data_len(
apdu, BACNET_APPLICATION_TAG_BIT_STRING, len_value_type),
expected_value, NULL);
len_value_type = INT32_MAX - 23;
expected_value = (int) len_value_type;
zassert_equal(bacapp_decode_data_len(apdu, BACNET_APPLICATION_TAG_ENUMERATED, len_value_type), expected_value, NULL);
expected_value = (int)len_value_type;
zassert_equal(bacapp_decode_data_len(
apdu, BACNET_APPLICATION_TAG_ENUMERATED, len_value_type),
expected_value, NULL);
len_value_type = INT32_MAX - 29;
expected_value = (int) len_value_type;
zassert_equal(bacapp_decode_data_len(apdu, BACNET_APPLICATION_TAG_DATE, len_value_type), expected_value, NULL);
expected_value = (int)len_value_type;
zassert_equal(bacapp_decode_data_len(
apdu, BACNET_APPLICATION_TAG_DATE, len_value_type),
expected_value, NULL);
len_value_type = INT32_MAX - 31;
expected_value = (int) len_value_type;
zassert_equal(bacapp_decode_data_len(apdu, BACNET_APPLICATION_TAG_TIME, len_value_type), expected_value, NULL);
expected_value = (int)len_value_type;
zassert_equal(bacapp_decode_data_len(
apdu, BACNET_APPLICATION_TAG_TIME, len_value_type),
expected_value, NULL);
len_value_type = INT32_MAX - 37;
expected_value = (int) len_value_type;
zassert_equal(bacapp_decode_data_len(apdu, BACNET_APPLICATION_TAG_OBJECT_ID, len_value_type), expected_value, NULL);
expected_value = (int)len_value_type;
zassert_equal(bacapp_decode_data_len(
apdu, BACNET_APPLICATION_TAG_OBJECT_ID, len_value_type),
expected_value, NULL);
}
#if defined(CONFIG_ZTEST_NEW_API)
@@ -164,16 +196,16 @@ static void test_bacapp_copy(void)
zassert_equal(dest_value.tag, src_value.tag, NULL);
zassert_equal(dest_value.next, src_value.next, NULL);
for (i = 0; i < sizeof(tag_list)/sizeof(tag_list[0]); ++i) {
for (i = 0; i < sizeof(tag_list) / sizeof(tag_list[0]); ++i) {
BACNET_APPLICATION_TAG tag = tag_list[i];
bool result;
bool expected_result = true;
#if ! defined(BACAPP_NULL)
#if !defined(BACAPP_NULL)
if (tag == BACNET_APPLICATION_TAG_NULL) {
expected_result = false;
}
#endif
#endif
memset(&src_value, 0, sizeof(src_value));
src_value.next = NULL;
@@ -210,7 +242,8 @@ static void test_bacapp_value_list_init(void)
bacapp_value_list_init(&value[0], 0);
zassert_equal(memcmp(&value[0], &value[1], sizeof(value[1])), 0, NULL);
/* Verify one structure is initialized correctly */
for (max_count = 1; max_count < sizeof(value)/sizeof(value[0]); ++max_count) {
for (max_count = 1; max_count < sizeof(value) / sizeof(value[0]);
++max_count) {
memset(value, 0, sizeof(value));
max_count = 1;
bacapp_value_list_init(&value[0], max_count);
@@ -219,20 +252,24 @@ static void test_bacapp_value_list_init(void)
zassert_equal(value[count].tag, BACNET_APPLICATION_TAG_NULL, NULL);
zassert_equal(value[count].context_specific, 0, NULL);
zassert_equal(value[count].context_tag, 0, NULL);
zassert_equal(value[count].next, ((count + 1 >= max_count) ? NULL : &value[count + 1]), NULL);
zassert_equal(value[count].next,
((count + 1 >= max_count) ? NULL : &value[count + 1]), NULL);
}
}
}
#if defined(CONFIG_ZTEST_NEW_API)
ZTEST(bacapp_tests, test_bacapp_property_value_list_init)
ZTEST(bacapp_tests, test_bacapp_property_value_list)
#else
static void test_bacapp_property_value_list_init(void)
static void test_bacapp_property_value_list(void)
#endif
{
BACNET_PROPERTY_VALUE value[2] = { { 0 } };
size_t max_count = 0;
size_t count = 0;
int len, test_len;
uint8_t apdu[480];
bool status;
/* Verify NULL ptr is properly handled */
bacapp_property_value_list_init(NULL, 1);
@@ -243,16 +280,50 @@ static void test_bacapp_property_value_list_init(void)
zassert_equal(memcmp(&value[0], &value[1], sizeof(value[1])), 0, NULL);
/* Verify one structure is initialized correctly */
for (max_count = 1; max_count < sizeof(value)/sizeof(value[0]); ++max_count) {
for (max_count = 1; max_count < ARRAY_SIZE(value); ++max_count) {
memset(value, 0, sizeof(value));
max_count = 1;
bacapp_property_value_list_init(&value[0], max_count);
for (count = 0; count < max_count; ++count) {
zassert_equal(value[count].propertyIdentifier, MAX_BACNET_PROPERTY_ID, NULL);
zassert_equal(value[count].propertyArrayIndex, BACNET_ARRAY_ALL, NULL);
zassert_equal(
value[count].propertyIdentifier, MAX_BACNET_PROPERTY_ID, NULL);
zassert_equal(
value[count].propertyArrayIndex, BACNET_ARRAY_ALL, NULL);
zassert_equal(value[count].priority, BACNET_NO_PRIORITY, NULL);
zassert_equal(value[count].next, ((count + 1 >= max_count) ? NULL : &value[count + 1]), NULL);
zassert_equal(value[count].next,
((count + 1 >= max_count) ? NULL : &value[count + 1]), NULL);
}
}
bacapp_property_value_list_link(value, ARRAY_SIZE(value));
value[0].propertyIdentifier = 1;
value[0].propertyArrayIndex = 1;
value[0].priority = 1;
status = bacapp_parse_application_data(
BACNET_APPLICATION_TAG_UNSIGNED_INT, "1", &value[0].value);
zassert_true(status, NULL);
test_len = bacapp_property_value_encode(NULL, &value[0]);
zassert_true(test_len > 0, NULL);
len = bacapp_property_value_encode(apdu, &value[0]);
zassert_true(len > 0, NULL);
test_len = bacapp_property_value_decode(apdu, sizeof(apdu), &value[1]);
zassert_equal(len, test_len, "len=%d test_len=%d", len, test_len);
test_len = bacapp_property_value_decode(apdu, sizeof(apdu), NULL);
zassert_equal(len, test_len, "len=%d test_len=%d", len, test_len);
while (len) {
len--;
test_len = bacapp_property_value_decode(apdu, len, &value[1]);
if (test_len != BACNET_STATUS_ERROR) {
/* shorter packet leaves off the OPTIONAL priority */
zassert_equal(len, test_len, "len=%d test_len=%d", len, test_len);
zassert_equal(value[1].priority, BACNET_NO_PRIORITY, "priority=%u",
(unsigned)value[1].priority);
} else {
zassert_equal(test_len, BACNET_STATUS_ERROR, "len=%d test_len=%d",
len, test_len);
test_len = bacapp_property_value_decode(apdu, len, NULL);
zassert_equal(test_len, BACNET_STATUS_ERROR, "len=%d test_len=%d",
len, test_len);
}
}
}
@@ -280,7 +351,6 @@ static void test_bacapp_same_value(void)
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#endif
test_value.tag = BACNET_APPLICATION_TAG_BOOLEAN;
value.tag = test_value.tag;
#if defined(BACAPP_BOOLEAN)
@@ -291,10 +361,9 @@ static void test_bacapp_same_value(void)
value.type.Boolean = !test_value.type.Boolean;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
memset(&test_value, 0, sizeof(test_value));
test_value.tag = BACNET_APPLICATION_TAG_UNSIGNED_INT;
value = test_value; /* Struct copy */
value = test_value; /* Struct copy */
#if defined(BACAPP_UNSIGNED)
zassert_true(bacapp_same_value(&value, &test_value), NULL);
#else
@@ -303,10 +372,9 @@ static void test_bacapp_same_value(void)
value.type.Unsigned_Int = ~test_value.type.Unsigned_Int;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
memset(&test_value, 0, sizeof(test_value));
test_value.tag = BACNET_APPLICATION_TAG_SIGNED_INT;
value = test_value; /* Struct copy */
value = test_value; /* Struct copy */
#if defined(BACAPP_SIGNED)
zassert_true(bacapp_same_value(&value, &test_value), NULL);
#else
@@ -315,10 +383,9 @@ static void test_bacapp_same_value(void)
value.type.Signed_Int = test_value.type.Signed_Int + 1;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
memset(&test_value, 0, sizeof(test_value));
test_value.tag = BACNET_APPLICATION_TAG_REAL;
value = test_value; /* Struct copy */
value = test_value; /* Struct copy */
#if defined(BACAPP_REAL)
zassert_true(bacapp_same_value(&value, &test_value), NULL);
#else
@@ -327,10 +394,9 @@ static void test_bacapp_same_value(void)
value.type.Real = test_value.type.Real + 1.0f;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
memset(&test_value, 0, sizeof(test_value));
test_value.tag = BACNET_APPLICATION_TAG_DOUBLE;
value = test_value; /* Struct copy */
value = test_value; /* Struct copy */
#if defined(BACAPP_DOUBLE)
zassert_true(bacapp_same_value(&value, &test_value), NULL);
#else
@@ -339,10 +405,9 @@ static void test_bacapp_same_value(void)
value.type.Double = test_value.type.Double + 1.0;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
memset(&test_value, 0, sizeof(test_value));
test_value.tag = BACNET_APPLICATION_TAG_ENUMERATED;
value = test_value; /* Struct copy */
value = test_value; /* Struct copy */
#if defined(BACAPP_ENUMERATED)
zassert_true(bacapp_same_value(&value, &test_value), NULL);
#else
@@ -351,17 +416,16 @@ static void test_bacapp_same_value(void)
value.type.Enumerated = test_value.type.Enumerated + 1;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
memset(&test_value, 0, sizeof(test_value));
test_value.tag = BACNET_APPLICATION_TAG_DATE;
value = test_value; /* Struct copy */
value = test_value; /* Struct copy */
#if defined(BACAPP_DATE)
zassert_true(bacapp_same_value(&value, &test_value), NULL);
#else
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#endif
value = test_value; /* Struct copy */
value = test_value; /* Struct copy */
value.type.Date.day = test_value.type.Date.day + 1;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
@@ -371,104 +435,97 @@ static void test_bacapp_same_value(void)
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#endif
value = test_value; /* Struct copy */
value = test_value; /* Struct copy */
value.type.Date.month = test_value.type.Date.month + 1;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
value = test_value; /* Struct copy */
value = test_value; /* Struct copy */
value.type.Date.year = test_value.type.Date.year + 1;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
memset(&test_value, 0, sizeof(test_value));
test_value.tag = BACNET_APPLICATION_TAG_TIME;
value = test_value; /* Struct copy */
value = test_value; /* Struct copy */
#if defined(BACAPP_TIME)
zassert_true(bacapp_same_value(&value, &test_value), NULL);
#else
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#endif
value = test_value; /* Struct copy */
value = test_value; /* Struct copy */
value.type.Time.hour = test_value.type.Time.hour + 1;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
value = test_value; /* Struct copy */
value = test_value; /* Struct copy */
value.type.Time.min = test_value.type.Time.min + 1;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
value = test_value; /* Struct copy */
value = test_value; /* Struct copy */
value.type.Time.sec = test_value.type.Time.sec + 1;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
value = test_value; /* Struct copy */
value = test_value; /* Struct copy */
value.type.Time.hundredths = test_value.type.Time.hundredths + 1;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
memset(&test_value, 0, sizeof(test_value));
test_value.tag = BACNET_APPLICATION_TAG_OBJECT_ID;
value = test_value; /* Struct copy */
value = test_value; /* Struct copy */
#if defined(BACAPP_OBJECT_ID)
zassert_true(bacapp_same_value(&value, &test_value), NULL);
#else
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#endif
value = test_value; /* Struct copy */
value = test_value; /* Struct copy */
value.type.Object_Id.type = test_value.type.Object_Id.type + 1;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
value = test_value; /* Struct copy */
value = test_value; /* Struct copy */
value.type.Object_Id.instance = test_value.type.Object_Id.instance + 1;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
memset(&test_value, 0, sizeof(test_value));
test_value.tag = BACNET_APPLICATION_TAG_CHARACTER_STRING;
value = test_value; /* Struct copy */
value = test_value; /* Struct copy */
#if defined(BACAPP_CHARACTER_STRING)
zassert_true(bacapp_same_value(&value, &test_value), NULL);
#else
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#endif
//TODO: Verify .type.Character_String value compared
// TODO: Verify .type.Character_String value compared
memset(&test_value, 0, sizeof(test_value));
test_value.tag = BACNET_APPLICATION_TAG_OCTET_STRING;
value = test_value; /* Struct copy */
value = test_value; /* Struct copy */
#if defined(BACAPP_OCTET_STRING)
zassert_true(bacapp_same_value(&value, &test_value), NULL);
#else
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#endif
//TODO: Verify .type.Octet_String value compared
// TODO: Verify .type.Octet_String value compared
memset(&test_value, 0, sizeof(test_value));
test_value.tag = BACNET_APPLICATION_TAG_BIT_STRING;
value = test_value; /* Struct copy */
value = test_value; /* Struct copy */
#if defined(BACAPP_BIT_STRING)
zassert_true(bacapp_same_value(&value, &test_value), NULL);
#else
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#endif
//TODO: Verify .type.Bit_String value compared
// TODO: Verify .type.Bit_String value compared
memset(&test_value, 0, sizeof(test_value));
test_value.tag = BACNET_APPLICATION_TAG_LIGHTING_COMMAND;
value = test_value; /* Struct copy */
value = test_value; /* Struct copy */
#if defined(BACAPP_TYPES_EXTRA)
zassert_true(bacapp_same_value(&value, &test_value), NULL);
#else
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#endif
//TODO: Verify .type.Lighting_Command value compared
// TODO: Verify .type.Lighting_Command value compared
}
/**
* @brief Test
*/
@@ -759,7 +816,8 @@ static void testBACnetApplicationDataLength(void)
/**
* @brief Test
*/
static bool verifyBACnetApplicationDataValue(BACNET_APPLICATION_DATA_VALUE *value)
static bool verifyBACnetApplicationDataValue(
BACNET_APPLICATION_DATA_VALUE *value)
{
uint8_t apdu[480] = { 0 };
int apdu_len = 0;
@@ -780,8 +838,7 @@ static bool verifyBACnetApplicationDataValue(BACNET_APPLICATION_DATA_VALUE *valu
* @brief Test
*/
static bool verifyBACnetComplexDataValue(
BACNET_APPLICATION_DATA_VALUE *value,
BACNET_PROPERTY_ID prop)
BACNET_APPLICATION_DATA_VALUE *value, BACNET_PROPERTY_ID prop)
{
uint8_t apdu[480] = { 0 };
int apdu_len = 0;
@@ -792,8 +849,8 @@ static bool verifyBACnetComplexDataValue(
zassert_true(apdu_len > 0, NULL);
null_len = bacapp_encode_application_data(NULL, value);
zassert_equal(apdu_len, null_len, NULL);
apdu_len = bacapp_decode_generic_property(&apdu[0], apdu_len,
&test_value, prop);
apdu_len =
bacapp_decode_generic_property(&apdu[0], apdu_len, &test_value, prop);
zassert_true(apdu_len != BACNET_STATUS_ERROR, NULL);
return bacapp_same_value(value, &test_value);
@@ -1053,8 +1110,8 @@ static void testBACnetApplicationData(void)
BACNET_APPLICATION_TAG_HOST_N_PORT, "192.168.1.1:47808", &value);
zassert_true(status, NULL);
status = verifyBACnetComplexDataValue(&value, PROP_FD_BBMD_ADDRESS);
status = verifyBACnetComplexDataValue(&value,
PROP_BACNET_IP_GLOBAL_ADDRESS);
status =
verifyBACnetComplexDataValue(&value, PROP_BACNET_IP_GLOBAL_ADDRESS);
return;
}
@@ -1074,16 +1131,16 @@ static void test_bacapp_context_data(void)
int apdu_len, null_len;
unsigned i = 0;
for (i = 0; i < sizeof(tag_list)/sizeof(tag_list[0]); i++) {
for (i = 0; i < sizeof(tag_list) / sizeof(tag_list[0]); i++) {
BACNET_APPLICATION_TAG tag = tag_list[i];
value.tag = tag;
null_len = bacapp_encode_context_data_value(NULL,
context_tag_number, &value);
apdu_len = bacapp_encode_context_data_value(apdu,
context_tag_number, &value);
null_len =
bacapp_encode_context_data_value(NULL, context_tag_number, &value);
apdu_len =
bacapp_encode_context_data_value(apdu, context_tag_number, &value);
if (apdu_len != null_len) {
printf("bacapp: NULL len=%d != APDU len=%d for tag=%s",
null_len, apdu_len, bactext_application_tag_name(tag));
printf("bacapp: NULL len=%d != APDU len=%d for tag=%s", null_len,
apdu_len, bactext_application_tag_name(tag));
}
zassert_equal(apdu_len, null_len, NULL);
}
@@ -1114,8 +1171,8 @@ static void test_bacapp_sprintf_data(void)
zassert_true(status, NULL);
str_len = bacapp_snprintf_value(NULL, 0, &object_value);
if (str_len > 0) {
char str[str_len+1];
bacapp_snprintf_value(str, str_len+1, &object_value);
char str[str_len + 1];
bacapp_snprintf_value(str, str_len + 1, &object_value);
zassert_mem_equal(str, "Null", str_len, NULL);
}
}
@@ -1124,25 +1181,23 @@ static void test_bacapp_sprintf_data(void)
* @}
*/
#if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(bacapp_tests, NULL, NULL, NULL, NULL, NULL);
#else
void test_main(void)
{
ztest_test_suite(bacapp_tests,
ztest_unit_test(test_bacapp_decode_application_data),
ztest_unit_test(test_bacapp_decode_data_len),
ztest_unit_test(test_bacapp_copy),
ztest_unit_test(test_bacapp_value_list_init),
ztest_unit_test(test_bacapp_property_value_list_init),
ztest_unit_test(test_bacapp_same_value),
ztest_unit_test(testBACnetApplicationData),
ztest_unit_test(testBACnetApplicationDataLength),
ztest_unit_test(testBACnetApplicationData_Safe),
ztest_unit_test(test_bacapp_context_data),
ztest_unit_test(test_bacapp_sprintf_data)
);
ztest_unit_test(test_bacapp_decode_application_data),
ztest_unit_test(test_bacapp_decode_data_len),
ztest_unit_test(test_bacapp_copy),
ztest_unit_test(test_bacapp_value_list_init),
ztest_unit_test(test_bacapp_property_value_list),
ztest_unit_test(test_bacapp_same_value),
ztest_unit_test(testBACnetApplicationData),
ztest_unit_test(testBACnetApplicationDataLength),
ztest_unit_test(testBACnetApplicationData_Safe),
ztest_unit_test(test_bacapp_context_data),
ztest_unit_test(test_bacapp_sprintf_data));
ztest_run_test_suite(bacapp_tests);
}