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
+3
View File
@@ -53,8 +53,10 @@ list(APPEND testdirs
bacnet/bacstr
bacnet/bactimevalue
bacnet/cov
bacnet/create_object
bacnet/datetime
bacnet/dcc
bacnet/delete_object
bacnet/event
bacnet/getalarm
bacnet/getevent
@@ -62,6 +64,7 @@ list(APPEND testdirs
bacnet/ihave
bacnet/indtext
bacnet/lighting
bacnet/list_element
bacnet/lso
bacnet/memcopy
bacnet/npdu
+1 -1
View File
@@ -7,7 +7,6 @@ project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE
"/test/bacnet/[a-zA-Z_/-]*$"
"/src"
@@ -25,6 +24,7 @@ add_compile_definitions(
CONFIG_ZTEST=1
PRINT_ENABLED=1
BACAPP_ALL=1
BACAPP_PRINT_ENABLED=1
)
include_directories(
+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);
}
-171
View File
@@ -27,177 +27,6 @@
* @{
*/
#if 0
/* Mocks */
void bacapp_value_list_init(
BACNET_APPLICATION_DATA_VALUE *value,
size_t count)
{
}
void bacapp_property_value_list_init(
BACNET_PROPERTY_VALUE *value,
size_t count)
{
}
int bacapp_encode_data(
uint8_t * apdu,
BACNET_APPLICATION_DATA_VALUE * value)
{
return -1;
}
int bacapp_decode_data(
uint8_t * apdu,
uint8_t tag_data_type,
uint32_t len_value_type,
BACNET_APPLICATION_DATA_VALUE * value)
{
return -1;
}
int bacapp_decode_application_data(
uint8_t * apdu,
unsigned max_apdu_len,
BACNET_APPLICATION_DATA_VALUE * value)
{
return -1;
}
bool bacapp_decode_application_data_safe(
uint8_t * new_apdu,
uint32_t new_apdu_len,
BACNET_APPLICATION_DATA_VALUE * value)
{
return false;
}
int bacapp_encode_application_data(
uint8_t * apdu,
BACNET_APPLICATION_DATA_VALUE * value)
{
return -1;
}
int bacapp_decode_context_data(
uint8_t * apdu,
unsigned max_apdu_len,
BACNET_APPLICATION_DATA_VALUE * value,
BACNET_PROPERTY_ID property)
{
return -1;
}
int bacapp_encode_context_data(
uint8_t * apdu,
BACNET_APPLICATION_DATA_VALUE * value,
BACNET_PROPERTY_ID property)
{
return -1;
}
int bacapp_encode_context_data_value(
uint8_t * apdu,
uint8_t context_tag_number,
BACNET_APPLICATION_DATA_VALUE * value)
{
return -1;
}
BACNET_APPLICATION_TAG bacapp_context_tag_type(
BACNET_PROPERTY_ID property,
uint8_t tag_number)
{
return MAX_BACNET_APPLICATION_TAG;
}
bool bacapp_copy(
BACNET_APPLICATION_DATA_VALUE * dest_value,
BACNET_APPLICATION_DATA_VALUE * src_value)
{
return false;
}
int bacapp_data_len(
uint8_t * apdu,
unsigned max_apdu_len,
BACNET_PROPERTY_ID property)
{
return -1;
}
int bacapp_decode_data_len(
uint8_t * apdu,
uint8_t tag_data_type,
uint32_t len_value_type)
{
return -1;
}
int bacapp_decode_application_data_len(
uint8_t * apdu,
unsigned max_apdu_len)
{
return -1;
}
int bacapp_decode_context_data_len(
uint8_t * apdu,
unsigned max_apdu_len,
BACNET_PROPERTY_ID property)
{
return -1;
}
int bacapp_snprintf_value(
char *str,
size_t str_len,
BACNET_OBJECT_PROPERTY_VALUE * object_value)
{
return -1;
}
#ifdef BACAPP_PRINT_ENABLED
bool bacapp_parse_application_data(
BACNET_APPLICATION_TAG tag_number,
const char *argv,
BACNET_APPLICATION_DATA_VALUE * value)
{
return false;
}
bool bacapp_print_value(
FILE * stream,
BACNET_OBJECT_PROPERTY_VALUE * value)
{
return false;
}
#endif
bool bacapp_same_value(
BACNET_APPLICATION_DATA_VALUE * value,
BACNET_APPLICATION_DATA_VALUE * test_value)
{
return false;
}
#endif
/**
* @brief Test
*/
+41 -52
View File
@@ -9,7 +9,7 @@
*/
#include <zephyr/ztest.h>
//#include <bacnet/bacapp.h>
// #include <bacnet/bacapp.h>
#include <bacnet/cov.h>
/**
@@ -127,24 +127,19 @@ static int cov_subscribe_property_decode_apdu(uint8_t *apdu,
}
/* dummy function stubs */
static void testCOVNotifyData(
BACNET_COV_DATA *data, BACNET_COV_DATA *test_data)
static void testCOVNotifyData(BACNET_COV_DATA *data, BACNET_COV_DATA *test_data)
{
BACNET_PROPERTY_VALUE *value = NULL;
BACNET_PROPERTY_VALUE *test_value = NULL;
zassert_equal(
test_data->subscriberProcessIdentifier,
data->subscriberProcessIdentifier, NULL);
zassert_equal(
test_data->initiatingDeviceIdentifier,
data->initiatingDeviceIdentifier, NULL);
zassert_equal(
test_data->monitoredObjectIdentifier.type,
data->monitoredObjectIdentifier.type, NULL);
zassert_equal(
test_data->monitoredObjectIdentifier.instance,
data->monitoredObjectIdentifier.instance, NULL);
zassert_equal(test_data->subscriberProcessIdentifier,
data->subscriberProcessIdentifier, NULL);
zassert_equal(test_data->initiatingDeviceIdentifier,
data->initiatingDeviceIdentifier, NULL);
zassert_equal(test_data->monitoredObjectIdentifier.type,
data->monitoredObjectIdentifier.type, NULL);
zassert_equal(test_data->monitoredObjectIdentifier.instance,
data->monitoredObjectIdentifier.instance, NULL);
zassert_equal(test_data->timeRemaining, data->timeRemaining, NULL);
/* test the listOfValues in some clever manner */
value = data->listOfValues;
@@ -152,10 +147,12 @@ static void testCOVNotifyData(
while (value) {
zassert_not_null(test_value, NULL);
if (test_value) {
zassert_equal(
test_value->propertyIdentifier, value->propertyIdentifier, NULL);
zassert_equal(
test_value->propertyArrayIndex, value->propertyArrayIndex, NULL);
zassert_equal(test_value->propertyIdentifier,
value->propertyIdentifier, "property=%u test_property=%u",
(unsigned)value->propertyIdentifier,
(unsigned)test_value->propertyIdentifier);
zassert_equal(test_value->propertyArrayIndex,
value->propertyArrayIndex, NULL);
zassert_equal(test_value->priority, value->priority, NULL);
zassert_true(
bacapp_same_value(&test_value->value, &value->value), NULL);
@@ -170,14 +167,15 @@ static void testUCOVNotifyData(BACNET_COV_DATA *data)
uint8_t apdu[480] = { 0 };
int len = 0;
int apdu_len = 0;
BACNET_COV_DATA test_data;
BACNET_COV_DATA test_data = { 0 };
BACNET_PROPERTY_VALUE value_list[5] = { { 0 } };
len = ucov_notify_encode_apdu(&apdu[0], sizeof(apdu), data);
zassert_true(len > 0, NULL);
apdu_len = len;
cov_data_value_list_link(&test_data, &value_list[0], 5);
cov_data_value_list_link(
&test_data, &value_list[0], ARRAY_SIZE(value_list));
len = ucov_notify_decode_apdu(&apdu[0], apdu_len, &test_data);
zassert_not_equal(len, -1, NULL);
testCOVNotifyData(data, &test_data);
@@ -188,7 +186,7 @@ static void testCCOVNotifyData(uint8_t invoke_id, BACNET_COV_DATA *data)
uint8_t apdu[480] = { 0 };
int len = 0;
int apdu_len = 0;
BACNET_COV_DATA test_data;
BACNET_COV_DATA test_data = { 0 };
BACNET_PROPERTY_VALUE value_list[2] = { { 0 } };
uint8_t test_invoke_id = 0;
@@ -239,42 +237,36 @@ static void testCOVNotify(void)
}
static void testCOVSubscribeData(
BACNET_SUBSCRIBE_COV_DATA *data,
BACNET_SUBSCRIBE_COV_DATA *test_data)
BACNET_SUBSCRIBE_COV_DATA *data, BACNET_SUBSCRIBE_COV_DATA *test_data)
{
zassert_equal(test_data->subscriberProcessIdentifier,
data->subscriberProcessIdentifier, NULL);
zassert_equal(test_data->monitoredObjectIdentifier.type,
data->monitoredObjectIdentifier.type, NULL);
zassert_equal(test_data->monitoredObjectIdentifier.instance,
data->monitoredObjectIdentifier.instance, NULL);
zassert_equal(
test_data->subscriberProcessIdentifier,
data->subscriberProcessIdentifier, NULL);
zassert_equal(
test_data->monitoredObjectIdentifier.type,
data->monitoredObjectIdentifier.type, NULL);
zassert_equal(
test_data->monitoredObjectIdentifier.instance,
data->monitoredObjectIdentifier.instance, NULL);
zassert_equal(test_data->cancellationRequest, data->cancellationRequest, NULL);
test_data->cancellationRequest, data->cancellationRequest, NULL);
if (test_data->cancellationRequest != data->cancellationRequest) {
printf("cancellation request failed!\n");
}
if (!test_data->cancellationRequest) {
zassert_equal(
test_data->issueConfirmedNotifications,
data->issueConfirmedNotifications, NULL);
zassert_equal(test_data->issueConfirmedNotifications,
data->issueConfirmedNotifications, NULL);
zassert_equal(test_data->lifetime, data->lifetime, NULL);
}
}
static void testCOVSubscribePropertyData(
BACNET_SUBSCRIBE_COV_DATA *data,
BACNET_SUBSCRIBE_COV_DATA *test_data)
BACNET_SUBSCRIBE_COV_DATA *data, BACNET_SUBSCRIBE_COV_DATA *test_data)
{
testCOVSubscribeData(data, test_data);
zassert_equal(test_data->monitoredProperty.propertyIdentifier,
data->monitoredProperty.propertyIdentifier, NULL);
zassert_equal(test_data->monitoredProperty.propertyArrayIndex,
data->monitoredProperty.propertyArrayIndex, NULL);
zassert_equal(
test_data->monitoredProperty.propertyIdentifier,
data->monitoredProperty.propertyIdentifier, NULL);
zassert_equal(
test_data->monitoredProperty.propertyArrayIndex,
data->monitoredProperty.propertyArrayIndex, NULL);
zassert_equal(test_data->covIncrementPresent, data->covIncrementPresent, NULL);
test_data->covIncrementPresent, data->covIncrementPresent, NULL);
if (test_data->covIncrementPresent) {
zassert_equal(test_data->covIncrement, data->covIncrement, NULL);
}
@@ -286,7 +278,7 @@ static void testCOVSubscribeEncoding(
uint8_t apdu[480] = { 0 };
int len = 0;
int apdu_len = 0;
BACNET_SUBSCRIBE_COV_DATA test_data;
BACNET_SUBSCRIBE_COV_DATA test_data = { 0 };
uint8_t test_invoke_id = 0;
len = cov_subscribe_encode_apdu(&apdu[0], sizeof(apdu), invoke_id, data);
@@ -328,7 +320,7 @@ static void testCOVSubscribe(void)
#endif
{
uint8_t invoke_id = 12;
BACNET_SUBSCRIBE_COV_DATA data;
BACNET_SUBSCRIBE_COV_DATA data = { 0 };
data.subscriberProcessIdentifier = 1;
data.monitoredObjectIdentifier.type = OBJECT_ANALOG_INPUT;
@@ -375,17 +367,14 @@ static void testCOVSubscribeProperty(void)
* @}
*/
#if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(cov_tests, NULL, NULL, NULL, NULL, NULL);
#else
void test_main(void)
{
ztest_test_suite(cov_tests,
ztest_unit_test(testCOVNotify),
ztest_unit_test(testCOVSubscribe),
ztest_unit_test(testCOVSubscribeProperty)
);
ztest_test_suite(cov_tests, ztest_unit_test(testCOVNotify),
ztest_unit_test(testCOVSubscribe),
ztest_unit_test(testCOVSubscribeProperty));
ztest_run_test_suite(cov_tests);
}
+62
View File
@@ -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/create_object.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
)
+139
View File
@@ -0,0 +1,139 @@
/**
* @file
* @brief Unit test for CreateObject service encode and decode API
* @author Steve Karg <skarg@users.sourceforge.net>
* @date August 2023
* @section LICENSE
*
* SPDX-License-Identifier: MIT
*/
#include <zephyr/ztest.h>
#include <bacnet/bacdest.h>
#include <bacnet/create_object.h>
static void test_CreateObjectCodec(BACNET_CREATE_OBJECT_DATA *data)
{
uint8_t apdu[MAX_APDU] = { 0 };
BACNET_CREATE_OBJECT_DATA test_data = { 0 };
int len = 0, apdu_len = 0, null_len = 0, test_len = 0;
null_len = create_object_encode_service_request(NULL, data);
apdu_len = create_object_encode_service_request(apdu, data);
zassert_equal(apdu_len, null_len, NULL);
zassert_true(apdu_len != BACNET_STATUS_ERROR, NULL);
null_len = create_object_decode_service_request(apdu, apdu_len, NULL);
test_len = create_object_decode_service_request(apdu, apdu_len, &test_data);
zassert_equal(test_len, null_len, NULL);
zassert_equal(
apdu_len, test_len, "apdu_len=%d test_len=%d", apdu_len, test_len);
while (test_len) {
test_len--;
len = create_object_decode_service_request(apdu, test_len, &test_data);
zassert_equal(
len, BACNET_STATUS_REJECT, "len=%d test_len=%d", len, test_len);
}
}
#if defined(CONFIG_ZTEST_NEW_API)
ZTEST(create_object_tests, test_CreateObject)
#else
static void test_CreateObject(void)
#endif
{
BACNET_CREATE_OBJECT_DATA data = { 0 };
int len = 0, apdu_len = 0, null_len = 0, test_len = 0;
test_CreateObjectCodec(&data);
data.object_instance = BACNET_MAX_INSTANCE;
test_CreateObjectCodec(&data);
}
static void test_CreateObjectAckCodec(BACNET_CREATE_OBJECT_DATA *data)
{
uint8_t apdu[MAX_APDU] = { 0 };
BACNET_CREATE_OBJECT_DATA test_data = { 0 };
int len = 0, apdu_len = 0, null_len = 0, test_len = 0;
uint8_t invoke_id = 0;
null_len = create_object_ack_service_encode(NULL, data);
apdu_len = create_object_ack_service_encode(apdu, data);
zassert_equal(apdu_len, null_len, NULL);
zassert_true(apdu_len != BACNET_STATUS_ERROR, NULL);
null_len = create_object_ack_service_decode(apdu, apdu_len, NULL);
test_len = create_object_ack_service_decode(apdu, apdu_len, &test_data);
zassert_equal(test_len, null_len, NULL);
zassert_equal(
apdu_len, test_len, "apdu_len=%d test_len=%d", apdu_len, test_len);
while (test_len) {
test_len--;
len = create_object_ack_service_decode(apdu, test_len, &test_data);
zassert_equal(
len, BACNET_STATUS_ERROR, "len=%d test_len=%d", len, test_len);
}
null_len = create_object_ack_encode(NULL, invoke_id, data);
apdu_len = create_object_ack_encode(apdu, invoke_id, data);
zassert_equal(apdu_len, null_len, NULL);
zassert_true(apdu_len > 0, NULL);
}
#if defined(CONFIG_ZTEST_NEW_API)
ZTEST(create_object_tests, test_CreateObject)
#else
static void test_CreateObjectACK(void)
#endif
{
BACNET_CREATE_OBJECT_DATA data = { 0 };
int len = 0, apdu_len = 0, null_len = 0, test_len = 0;
test_CreateObjectAckCodec(&data);
data.object_instance = BACNET_MAX_INSTANCE;
test_CreateObjectAckCodec(&data);
}
#if defined(CONFIG_ZTEST_NEW_API)
ZTEST(create_object_tests, test_CreateObjectError)
#else
static void test_CreateObjectError(void)
#endif
{
uint8_t apdu[MAX_APDU] = { 0 };
BACNET_CREATE_OBJECT_DATA data = { 0 }, test_data = { 0 };
int len = 0, apdu_len = 0, null_len = 0, test_len = 0;
uint8_t invoke_id = 0;
data.error_class = ERROR_CLASS_SERVICES;
data.error_code = ERROR_CODE_REJECT_PARAMETER_OUT_OF_RANGE;
data.first_failed_element_number = 0;
null_len = create_object_error_ack_service_encode(NULL, &data);
apdu_len = create_object_error_ack_service_encode(apdu, &data);
zassert_equal(apdu_len, null_len, NULL);
test_len = create_object_error_ack_service_decode(apdu, apdu_len, &test_data);
zassert_equal(apdu_len, test_len, NULL);
zassert_equal(test_data.error_class, data.error_class, NULL);
zassert_equal(test_data.error_code, data.error_code, NULL);
zassert_equal(test_data.first_failed_element_number,
data.first_failed_element_number, NULL);
while (test_len) {
test_len--;
len = create_object_error_ack_service_decode(apdu, test_len, &test_data);
zassert_equal(
len, BACNET_STATUS_REJECT, "len=%d test_len=%d", len, test_len);
}
null_len = create_object_error_ack_encode(NULL, invoke_id, &data);
apdu_len = create_object_error_ack_encode(apdu, invoke_id, &data);
zassert_equal(apdu_len, null_len, NULL);
zassert_true(apdu_len > 0, NULL);
}
#if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(create_object_tests, NULL, NULL, NULL, NULL, NULL);
#else
void test_main(void)
{
ztest_test_suite(create_object_tests, ztest_unit_test(test_CreateObject),
ztest_unit_test(test_CreateObjectACK),
ztest_unit_test(test_CreateObjectError));
ztest_run_test_suite(create_object_tests);
}
#endif
+62
View File
@@ -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/delete_object.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
)
+60
View File
@@ -0,0 +1,60 @@
/**
* @file
* @brief Unit test for DeleteObject service encode and decode API
* @author Steve Karg <skarg@users.sourceforge.net>
* @date August 2023
* @section LICENSE
*
* SPDX-License-Identifier: MIT
*/
#include <zephyr/ztest.h>
#include <bacnet/bacdest.h>
#include <bacnet/delete_object.h>
static void test_DeleteObjectCodec(BACNET_DELETE_OBJECT_DATA *data)
{
uint8_t apdu[MAX_APDU] = { 0 };
BACNET_DELETE_OBJECT_DATA test_data = { 0 };
int len = 0, apdu_len = 0, null_len = 0, test_len = 0;
null_len = delete_object_encode_service_request(NULL, data);
apdu_len = delete_object_encode_service_request(apdu, data);
zassert_equal(apdu_len, null_len, NULL);
zassert_true(apdu_len != BACNET_STATUS_ERROR, NULL);
null_len = delete_object_decode_service_request(apdu, apdu_len, NULL);
test_len = delete_object_decode_service_request(apdu, apdu_len, &test_data);
zassert_equal(test_len, null_len, NULL);
zassert_equal(
apdu_len, test_len, "apdu_len=%d test_len=%d", apdu_len, test_len);
while (test_len) {
test_len--;
len = delete_object_decode_service_request(apdu, test_len, &test_data);
zassert_equal(
len, BACNET_STATUS_REJECT, "len=%d test_len=%d", len, test_len);
}
}
#if defined(CONFIG_ZTEST_NEW_API)
ZTEST(delete_object_tests, test_DeleteObject)
#else
static void test_DeleteObject(void)
#endif
{
BACNET_DELETE_OBJECT_DATA data = { 0 };
int len = 0, apdu_len = 0, null_len = 0, test_len = 0;
test_DeleteObjectCodec(&data);
data.object_instance = BACNET_MAX_INSTANCE;
test_DeleteObjectCodec(&data);
}
#if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(delete_object_tests, NULL, NULL, NULL, NULL, NULL);
#else
void test_main(void)
{
ztest_test_suite(delete_object_tests, ztest_unit_test(test_DeleteObject));
ztest_run_test_suite(delete_object_tests);
}
#endif
+1 -1
View File
@@ -6,7 +6,7 @@
*
* SPDX-License-Identifier: MIT
*/
#include <ztest.h>
#include <zephyr/ztest.h>
#include <bacnet/bacdest.h>
#include <bacnet/list_element.h>