Added BACnetRecipient and BACnetAddressBinding codecs for EPICS application (#1163)
* Added BACnetRecipient and BACnetAddressBinding encoding, decoding, ASCII conversion, comparison, and copy functions. * Added library specific string manipulation utilities including strcmp, strncmp, stptok, and snprintf with offset functions. * Added test/README about verification and validation testing.
This commit is contained in:
+117
-46
@@ -11,6 +11,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <zephyr/ztest.h>
|
||||
#include <bacnet/bacaddr.h>
|
||||
#include <bacnet/bacdest.h>
|
||||
|
||||
/**
|
||||
@@ -21,49 +22,6 @@
|
||||
/**
|
||||
* @brief Test
|
||||
*/
|
||||
static void
|
||||
testBACnetRecipientData(BACNET_RECIPIENT *data1, BACNET_RECIPIENT *data2)
|
||||
{
|
||||
unsigned i = 0;
|
||||
|
||||
if (data1 && data2) {
|
||||
zassert_equal(data1->tag, data2->tag, NULL);
|
||||
if (data1->tag == BACNET_RECIPIENT_TAG_DEVICE) {
|
||||
zassert_equal(
|
||||
data1->type.device.type, data2->type.device.type, NULL);
|
||||
zassert_equal(
|
||||
data1->type.device.instance, data2->type.device.instance, NULL);
|
||||
} else if (data1->tag == BACNET_RECIPIENT_TAG_ADDRESS) {
|
||||
zassert_equal(
|
||||
data1->type.address.net, data2->type.address.net, NULL);
|
||||
if (data1->type.address.net == BACNET_BROADCAST_NETWORK) {
|
||||
zassert_equal(
|
||||
data1->type.address.mac_len, data2->type.address.mac_len,
|
||||
NULL);
|
||||
} else if (data1->type.address.net) {
|
||||
zassert_equal(
|
||||
data1->type.address.len, data2->type.address.len, NULL);
|
||||
for (i = 0; i < data1->type.address.len; i++) {
|
||||
zassert_equal(
|
||||
data1->type.address.adr[i], data2->type.address.adr[i],
|
||||
NULL);
|
||||
}
|
||||
} else {
|
||||
zassert_equal(
|
||||
data1->type.address.mac_len, data2->type.address.mac_len,
|
||||
NULL);
|
||||
for (i = 0; i < data1->type.address.mac_len; i++) {
|
||||
zassert_equal(
|
||||
data1->type.address.mac[i], data2->type.address.mac[i],
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
zassert_true(data1->tag < BACNET_RECIPIENT_TAG_MAX, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
ZTEST(bacnet_destination_tests, testBACnetDestination)
|
||||
#else
|
||||
@@ -73,6 +31,7 @@ static void testBACnetDestination(void)
|
||||
uint8_t apdu[MAX_APDU] = { 0 };
|
||||
BACNET_DESTINATION destination = { 0 }, test_destination = { 0 };
|
||||
int apdu_len = 0, null_len = 0, test_len = 0;
|
||||
bool status = false;
|
||||
|
||||
destination.Recipient.tag = BACNET_RECIPIENT_TAG_DEVICE;
|
||||
destination.Recipient.type.device.type = OBJECT_DEVICE;
|
||||
@@ -82,8 +41,8 @@ static void testBACnetDestination(void)
|
||||
zassert_equal(apdu_len, null_len, NULL);
|
||||
test_len = bacnet_destination_decode(apdu, apdu_len, &test_destination);
|
||||
zassert_equal(apdu_len, test_len, NULL);
|
||||
testBACnetRecipientData(
|
||||
&destination.Recipient, &test_destination.Recipient);
|
||||
status = bacnet_destination_same(&destination, &test_destination);
|
||||
zassert_true(status, NULL);
|
||||
|
||||
destination.Recipient.tag = BACNET_RECIPIENT_TAG_ADDRESS;
|
||||
destination.Recipient.type.address.net = 1234;
|
||||
@@ -99,6 +58,8 @@ static void testBACnetDestination(void)
|
||||
zassert_equal(apdu_len, null_len, NULL);
|
||||
test_len = bacnet_destination_decode(apdu, apdu_len, &test_destination);
|
||||
zassert_equal(test_len, apdu_len, NULL);
|
||||
status = bacnet_destination_same(&destination, &test_destination);
|
||||
zassert_true(status, NULL);
|
||||
|
||||
null_len = bacnet_destination_encode(NULL, &destination);
|
||||
apdu_len = bacnet_destination_encode(apdu, &destination);
|
||||
@@ -107,12 +68,27 @@ static void testBACnetDestination(void)
|
||||
zassert_equal(test_len, apdu_len, NULL);
|
||||
test_len = bacnet_destination_decode(apdu, apdu_len, NULL);
|
||||
zassert_equal(test_len, apdu_len, NULL);
|
||||
status = bacnet_destination_same(&destination, &test_destination);
|
||||
zassert_true(status, NULL);
|
||||
bacnet_destination_copy(&test_destination, &destination);
|
||||
status = bacnet_destination_same(&destination, &test_destination);
|
||||
zassert_true(status, NULL);
|
||||
|
||||
/* decoding, some negative tests */
|
||||
test_len = bacnet_destination_decode(NULL, apdu_len, &test_destination);
|
||||
zassert_equal(test_len, BACNET_STATUS_REJECT, NULL);
|
||||
test_len = bacnet_destination_decode(apdu, 0, &test_destination);
|
||||
zassert_equal(test_len, BACNET_STATUS_REJECT, NULL);
|
||||
/* context */
|
||||
null_len = bacnet_destination_context_encode(NULL, 4, &destination);
|
||||
apdu_len = bacnet_destination_context_encode(apdu, 4, &destination);
|
||||
zassert_equal(apdu_len, null_len, NULL);
|
||||
test_len =
|
||||
bacnet_destination_context_decode(apdu, apdu_len, 4, &test_destination);
|
||||
zassert_equal(apdu_len, test_len, NULL);
|
||||
/* defaults */
|
||||
status = bacnet_destination_default(&destination);
|
||||
zassert_false(status, NULL);
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
@@ -163,6 +139,99 @@ static void test_BACnetDestination_ASCII(void)
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
ZTEST(bacnet_destination_tests, testBACnetRecipient)
|
||||
#else
|
||||
static void testBACnetRecipient(void)
|
||||
#endif
|
||||
{
|
||||
uint8_t apdu[MAX_APDU] = { 0 };
|
||||
BACNET_RECIPIENT value = { 0 }, test_value = { 0 };
|
||||
BACNET_MAC_ADDRESS mac = { .len = 1, .adr[0] = 0x01 };
|
||||
BACNET_MAC_ADDRESS adr = { .len = 1, .adr[0] = 0x02 };
|
||||
uint16_t snet = 1234;
|
||||
BACNET_ADDRESS address = { 0 };
|
||||
int apdu_len = 0, null_len = 0, test_len = 0;
|
||||
uint8_t tag_number = 4;
|
||||
bool status = false;
|
||||
|
||||
/* device */
|
||||
bacnet_recipient_device_set(&value, OBJECT_DEVICE, 123);
|
||||
status = bacnet_recipient_device_valid(&value);
|
||||
zassert_true(status, NULL);
|
||||
bacnet_recipient_copy(&test_value, &value);
|
||||
status = bacnet_recipient_same(&value, &test_value);
|
||||
zassert_true(status, NULL);
|
||||
null_len = bacnet_recipient_encode(NULL, &value);
|
||||
apdu_len = bacnet_recipient_encode(apdu, &value);
|
||||
zassert_equal(apdu_len, null_len, NULL);
|
||||
test_len = bacnet_recipient_decode(apdu, apdu_len, &test_value);
|
||||
zassert_equal(apdu_len, test_len, NULL);
|
||||
status = bacnet_recipient_same(&value, &test_value);
|
||||
zassert_true(status, NULL);
|
||||
/* address */
|
||||
status = bacnet_address_init(&address, &mac, snet, &adr);
|
||||
zassert_true(status, NULL);
|
||||
bacnet_recipient_address_set(&value, &address);
|
||||
bacnet_recipient_copy(&test_value, &value);
|
||||
status = bacnet_recipient_same(&value, &test_value);
|
||||
zassert_true(status, NULL);
|
||||
null_len = bacnet_recipient_encode(NULL, &value);
|
||||
apdu_len = bacnet_recipient_encode(apdu, &value);
|
||||
zassert_equal(apdu_len, null_len, NULL);
|
||||
test_len = bacnet_recipient_decode(apdu, apdu_len, &test_value);
|
||||
zassert_equal(apdu_len, test_len, NULL);
|
||||
status = bacnet_recipient_same(&value, &test_value);
|
||||
zassert_true(status, NULL);
|
||||
/* context */
|
||||
null_len = bacnet_recipient_context_encode(NULL, tag_number, &value);
|
||||
apdu_len = bacnet_recipient_context_encode(apdu, tag_number, &value);
|
||||
zassert_equal(apdu_len, null_len, NULL);
|
||||
test_len = bacnet_recipient_context_decode(
|
||||
apdu, apdu_len, tag_number, &test_value);
|
||||
zassert_equal(apdu_len, test_len, NULL);
|
||||
status = bacnet_recipient_same(&value, &test_value);
|
||||
zassert_true(status, NULL);
|
||||
|
||||
bacnet_recipient_device_wildcard_set(&value);
|
||||
status = bacnet_recipient_device_wildcard(&value);
|
||||
zassert_true(status, NULL);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
ZTEST(bacnet_destination_tests, test_BACnetRecipient_ASCII)
|
||||
#else
|
||||
static void test_BACnetRecipient_ASCII(void)
|
||||
#endif
|
||||
{
|
||||
bool status = false;
|
||||
BACNET_RECIPIENT value = { 0 }, test_value = { 0 };
|
||||
BACNET_ADDRESS address = { 0 };
|
||||
BACNET_MAC_ADDRESS mac = { .len = 1, .adr[0] = 0x01 };
|
||||
BACNET_MAC_ADDRESS adr = { .len = 1, .adr[0] = 0x02 };
|
||||
uint16_t snet = 1234;
|
||||
int len = 0;
|
||||
char ascii[80] = "";
|
||||
|
||||
bacnet_recipient_device_set(&value, OBJECT_DEVICE, 4194303);
|
||||
len = bacnet_recipient_to_ascii(&value, ascii, sizeof(ascii));
|
||||
zassert_true(len > 0, NULL);
|
||||
status = bacnet_recipient_from_ascii(&test_value, ascii);
|
||||
zassert_true(status, "ascii=%s", ascii);
|
||||
status = bacnet_recipient_same(&value, &test_value);
|
||||
zassert_true(status, NULL);
|
||||
|
||||
status = bacnet_address_init(&address, &mac, snet, &adr);
|
||||
zassert_true(status, NULL);
|
||||
bacnet_recipient_address_set(&value, &address);
|
||||
len = bacnet_recipient_to_ascii(&value, ascii, sizeof(ascii));
|
||||
zassert_true(len > 0, NULL);
|
||||
status = bacnet_recipient_from_ascii(&test_value, ascii);
|
||||
zassert_true(status, "ascii=%s", ascii);
|
||||
status = bacnet_recipient_same(&value, &test_value);
|
||||
zassert_true(status, NULL);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
ZTEST_SUITE(bacnet_destination_tests, NULL, NULL, NULL, NULL, NULL);
|
||||
#else
|
||||
@@ -170,7 +239,9 @@ void test_main(void)
|
||||
{
|
||||
ztest_test_suite(
|
||||
bacnet_destination_tests, ztest_unit_test(testBACnetDestination),
|
||||
ztest_unit_test(test_BACnetDestination_ASCII));
|
||||
ztest_unit_test(test_BACnetDestination_ASCII),
|
||||
ztest_unit_test(testBACnetRecipient),
|
||||
ztest_unit_test(test_BACnetRecipient_ASCII));
|
||||
|
||||
ztest_run_test_suite(bacnet_destination_tests);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user