Bugfix/issues 1082 AddListElement and RemoveListElement and Notification Class object (#1083)
* Fixed AddListElement and RemoveListElement which were checking the wrong return value from Device object. * Fixed decoding of ListElement Tag 0: Object ID instance. * Fixed Notification_Class_Add_List_Element() and Notification_Class_Remove_List_Element() element counter index, and empty slot detection. * Added bacnet_recipient_device_set() and bacnet_recipient_address_set() API * Added unit test coverage for Notification Class object.
This commit is contained in:
@@ -94,6 +94,36 @@ bool bacnet_recipient_same(
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the BACnetRecipient complex data to a device
|
||||
* @param dest - BACnetRecipient structure
|
||||
* @param object_type - BACnetObjectType enumeration value
|
||||
* @param instance - BACnetObjectInstance value
|
||||
*/
|
||||
void bacnet_recipient_device_set(
|
||||
BACNET_RECIPIENT *dest, BACNET_OBJECT_TYPE object_type, uint32_t instance)
|
||||
{
|
||||
if (dest) {
|
||||
dest->tag = BACNET_RECIPIENT_TAG_DEVICE;
|
||||
dest->type.device.type = object_type;
|
||||
dest->type.device.instance = instance;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the BACnetRecipient complex data to an address
|
||||
* @param dest - BACnetRecipient structure
|
||||
* @param address - BACnetAddress structure
|
||||
*/
|
||||
void bacnet_recipient_address_set(
|
||||
BACNET_RECIPIENT *dest, const BACNET_ADDRESS *address)
|
||||
{
|
||||
if (dest && address) {
|
||||
dest->tag = BACNET_RECIPIENT_TAG_ADDRESS;
|
||||
bacnet_address_copy(&dest->type.address, address);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Copy the BACnetRecipient complex data from src to dest
|
||||
* @param src - BACnetRecipient 1 structure
|
||||
|
||||
@@ -82,6 +82,12 @@ void bacnet_destination_copy(
|
||||
BACNET_DESTINATION *dest, const BACNET_DESTINATION *src);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
void bacnet_recipient_device_set(
|
||||
BACNET_RECIPIENT *dest, BACNET_OBJECT_TYPE object_type, uint32_t instance);
|
||||
BACNET_STACK_EXPORT
|
||||
void bacnet_recipient_address_set(
|
||||
BACNET_RECIPIENT *dest, const BACNET_ADDRESS *address);
|
||||
BACNET_STACK_EXPORT
|
||||
void bacnet_recipient_copy(BACNET_RECIPIENT *dest, const BACNET_RECIPIENT *src);
|
||||
BACNET_STACK_EXPORT
|
||||
bool bacnet_recipient_same(
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
* @file
|
||||
* @author Krzysztof Malorny <malornykrzysztof@gmail.com>
|
||||
* @author Ed Hague <edward@bac-test.com>
|
||||
* @author Steve Karg <skarg@users.sourceforge.net>
|
||||
* @date 2011, 2018
|
||||
* @brief A basic BACnet Notification Class object
|
||||
* @copyright SPDX-License-Identifier: MIT
|
||||
@@ -38,28 +39,28 @@ static NOTIFICATION_CLASS_INFO NC_Info[MAX_NOTIFICATION_CLASSES];
|
||||
static uint8_t Event_Buffer[MAX_APDU];
|
||||
|
||||
/* These three arrays are used by the ReadPropertyMultiple handler */
|
||||
static const int Notification_Properties_Required[] = {
|
||||
static const int Properties_Required[] = {
|
||||
PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME,
|
||||
PROP_OBJECT_TYPE, PROP_NOTIFICATION_CLASS,
|
||||
PROP_PRIORITY, PROP_ACK_REQUIRED,
|
||||
PROP_RECIPIENT_LIST, -1
|
||||
};
|
||||
|
||||
static const int Notification_Properties_Optional[] = { PROP_DESCRIPTION, -1 };
|
||||
static const int Properties_Optional[] = { PROP_DESCRIPTION, -1 };
|
||||
|
||||
static const int Notification_Properties_Proprietary[] = { -1 };
|
||||
static const int Properties_Proprietary[] = { -1 };
|
||||
|
||||
void Notification_Class_Property_Lists(
|
||||
const int **pRequired, const int **pOptional, const int **pProprietary)
|
||||
{
|
||||
if (pRequired) {
|
||||
*pRequired = Notification_Properties_Required;
|
||||
*pRequired = Properties_Required;
|
||||
}
|
||||
if (pOptional) {
|
||||
*pOptional = Notification_Properties_Optional;
|
||||
*pOptional = Properties_Optional;
|
||||
}
|
||||
if (pProprietary) {
|
||||
*pProprietary = Notification_Properties_Proprietary;
|
||||
*pProprietary = Properties_Proprietary;
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -248,6 +249,7 @@ int Notification_Class_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
|
||||
Destination = &CurrentNotify->Recipient_List[idx];
|
||||
Recipient = &Destination->Recipient;
|
||||
if (!bacnet_recipient_device_wildcard(Recipient)) {
|
||||
/* unused slot denoted by wildcard */
|
||||
apdu_len += bacnet_destination_encode(NULL, Destination);
|
||||
}
|
||||
}
|
||||
@@ -266,6 +268,7 @@ int Notification_Class_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
|
||||
Destination = &CurrentNotify->Recipient_List[idx];
|
||||
Recipient = &Destination->Recipient;
|
||||
if (!bacnet_recipient_device_wildcard(Recipient)) {
|
||||
/* unused slot denoted by wildcard */
|
||||
apdu_len +=
|
||||
bacnet_destination_encode(&apdu[apdu_len], Destination);
|
||||
}
|
||||
@@ -428,19 +431,16 @@ bool Notification_Class_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
}
|
||||
status = true;
|
||||
break;
|
||||
|
||||
case PROP_OBJECT_IDENTIFIER:
|
||||
case PROP_OBJECT_NAME:
|
||||
case PROP_OBJECT_TYPE:
|
||||
case PROP_DESCRIPTION:
|
||||
case PROP_NOTIFICATION_CLASS:
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
|
||||
break;
|
||||
|
||||
default:
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data->error_code = ERROR_CODE_UNKNOWN_PROPERTY;
|
||||
if (property_lists_member(
|
||||
Properties_Required, Properties_Optional,
|
||||
Properties_Proprietary, wp_data->object_property)) {
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
|
||||
} else {
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data->error_code = ERROR_CODE_UNKNOWN_PROPERTY;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -673,6 +673,7 @@ void Notification_Class_common_reporting_function(
|
||||
pBacDest = &CurrentNotify->Recipient_List[0];
|
||||
for (index = 0; index < NC_MAX_RECIPIENTS; index++, pBacDest++) {
|
||||
if (bacnet_recipient_device_wildcard(&pBacDest->Recipient)) {
|
||||
/* unused slots denoted by wildcard */
|
||||
continue;
|
||||
}
|
||||
if (IsRecipientActive(pBacDest, event_data->toState)) {
|
||||
@@ -827,6 +828,7 @@ int Notification_Class_Add_List_Element(BACNET_LIST_ELEMENT_DATA *list_element)
|
||||
d1 = ¬ification->Recipient_List[index];
|
||||
r1 = &d1->Recipient;
|
||||
if (!bacnet_recipient_device_wildcard(r1)) {
|
||||
/* unused slots denoted by wildcard */
|
||||
element_count++;
|
||||
}
|
||||
}
|
||||
@@ -836,7 +838,8 @@ int Notification_Class_Add_List_Element(BACNET_LIST_ELEMENT_DATA *list_element)
|
||||
application_data_len = list_element->application_data_len;
|
||||
while (application_data_len > 0) {
|
||||
len = bacnet_destination_decode(
|
||||
application_data, application_data_len, &recipient_list[index]);
|
||||
application_data, application_data_len,
|
||||
&recipient_list[new_element_count]);
|
||||
if (len > 0) {
|
||||
new_element_count++;
|
||||
application_data_len -= len;
|
||||
@@ -907,7 +910,8 @@ int Notification_Class_Add_List_Element(BACNET_LIST_ELEMENT_DATA *list_element)
|
||||
BACNET_RECIPIENT *r2;
|
||||
d2 = ¬ification->Recipient_List[j];
|
||||
r2 = &d2->Recipient;
|
||||
if (!bacnet_recipient_device_wildcard(r2)) {
|
||||
if (bacnet_recipient_device_wildcard(r2)) {
|
||||
/* unused slot denoted by wildcard */
|
||||
bacnet_destination_copy(d2, d1);
|
||||
break;
|
||||
}
|
||||
@@ -984,6 +988,7 @@ int Notification_Class_Remove_List_Element(
|
||||
d1 = ¬ification->Recipient_List[index];
|
||||
r1 = &d1->Recipient;
|
||||
if (!bacnet_recipient_device_wildcard(r1)) {
|
||||
/* unused slot denoted by wildcard */
|
||||
element_count++;
|
||||
}
|
||||
}
|
||||
@@ -992,7 +997,8 @@ int Notification_Class_Remove_List_Element(
|
||||
application_data_len = list_element->application_data_len;
|
||||
while (application_data_len > 0) {
|
||||
len = bacnet_destination_decode(
|
||||
application_data, application_data_len, &recipient_list[index]);
|
||||
application_data, application_data_len,
|
||||
&recipient_list[remove_element_count]);
|
||||
if (len > 0) {
|
||||
remove_element_count++;
|
||||
application_data_len -= len;
|
||||
|
||||
@@ -23,7 +23,9 @@ extern "C" {
|
||||
#define NC_RESCAN_RECIPIENTS_SECS 60
|
||||
|
||||
/* max "length" of recipient_list */
|
||||
#ifndef NC_MAX_RECIPIENTS
|
||||
#define NC_MAX_RECIPIENTS 10
|
||||
#endif
|
||||
|
||||
#if defined(INTRINSIC_REPORTING)
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ void handler_add_list_element(
|
||||
status = false;
|
||||
}
|
||||
if (status) {
|
||||
if (Device_Add_List_Element(&list_element)) {
|
||||
if (Device_Add_List_Element(&list_element) >= 0) {
|
||||
len = encode_simple_ack(
|
||||
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
|
||||
SERVICE_CONFIRMED_ADD_LIST_ELEMENT);
|
||||
@@ -202,7 +202,7 @@ void handler_remove_list_element(
|
||||
status = false;
|
||||
}
|
||||
if (status) {
|
||||
if (Device_Remove_List_Element(&list_element)) {
|
||||
if (Device_Remove_List_Element(&list_element) >= 0) {
|
||||
len = encode_simple_ack(
|
||||
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
|
||||
SERVICE_CONFIRMED_REMOVE_LIST_ELEMENT);
|
||||
|
||||
@@ -143,6 +143,7 @@ int list_element_decode_service_request(
|
||||
len += decode_object_id(&apdu[len], &object_type, &object_instance);
|
||||
if (list_element) {
|
||||
list_element->object_type = object_type;
|
||||
list_element->object_instance = object_instance;
|
||||
}
|
||||
/* Tag 1: Property ID */
|
||||
len +=
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <bacnet/bactext.h>
|
||||
#include <bacnet/rp.h>
|
||||
#include <bacnet/wp.h>
|
||||
#include <bacnet/list_element.h>
|
||||
#include <bacnet/basic/object/nc.h>
|
||||
|
||||
/**
|
||||
@@ -21,9 +22,9 @@
|
||||
* @brief Test
|
||||
*/
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
ZTEST(notification_class_tests, test_Notification_Class)
|
||||
ZTEST(notification_class_tests, test_Notification_Class_Read_Write_Property)
|
||||
#else
|
||||
static void test_Notification_Class(void)
|
||||
static void test_Notification_Class_Read_Write_Property(void)
|
||||
#endif
|
||||
{
|
||||
uint8_t apdu[MAX_APDU] = { 0 };
|
||||
@@ -35,15 +36,23 @@ static void test_Notification_Class(void)
|
||||
const int *pOptional = NULL;
|
||||
const int *pProprietary = NULL;
|
||||
const uint32_t instance = 1;
|
||||
uint32_t test_instance = 0;
|
||||
BACNET_WRITE_PROPERTY_DATA wpdata = { 0 };
|
||||
bool status = false;
|
||||
unsigned index;
|
||||
unsigned count;
|
||||
|
||||
Notification_Class_Init();
|
||||
status = Notification_Class_Valid_Instance(instance);
|
||||
zassert_true(status, NULL);
|
||||
index = Notification_Class_Instance_To_Index(instance);
|
||||
zassert_equal(index, instance, "index=%u", index);
|
||||
test_instance = Notification_Class_Index_To_Instance(index);
|
||||
zassert_equal(test_instance, instance, "test_instance=%u", test_instance);
|
||||
count = Notification_Class_Count();
|
||||
zassert_true(count > 0, NULL);
|
||||
status = Notification_Class_Valid_Instance(BACNET_MAX_INSTANCE);
|
||||
zassert_false(status, NULL);
|
||||
|
||||
rpdata.application_data = &apdu[0];
|
||||
rpdata.application_data_len = sizeof(apdu);
|
||||
@@ -51,6 +60,8 @@ static void test_Notification_Class(void)
|
||||
rpdata.object_instance = instance;
|
||||
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
|
||||
|
||||
len = Notification_Class_Read_Property(NULL);
|
||||
zassert_equal(len, 0, NULL);
|
||||
Notification_Class_Property_Lists(&pRequired, &pOptional, &pProprietary);
|
||||
while ((*pRequired) >= 0) {
|
||||
rpdata.object_property = *pRequired;
|
||||
@@ -123,6 +134,34 @@ static void test_Notification_Class(void)
|
||||
}
|
||||
pOptional++;
|
||||
}
|
||||
/* array property - index 0 = size */
|
||||
rpdata.object_property = PROP_PRIORITY;
|
||||
rpdata.array_index = 0;
|
||||
len = Notification_Class_Read_Property(&rpdata);
|
||||
zassert_not_equal(len, BACNET_STATUS_ERROR, NULL);
|
||||
wpdata.object_type = rpdata.object_type;
|
||||
wpdata.object_property = rpdata.object_property;
|
||||
wpdata.array_index = rpdata.array_index;
|
||||
memcpy(&wpdata.application_data, rpdata.application_data, MAX_APDU);
|
||||
wpdata.error_code = ERROR_CODE_SUCCESS;
|
||||
status = Notification_Class_Write_Property(&wpdata);
|
||||
zassert_false(status, NULL);
|
||||
/* array property - index 1..N */
|
||||
rpdata.array_index = 1;
|
||||
len = Notification_Class_Read_Property(&rpdata);
|
||||
zassert_not_equal(len, BACNET_STATUS_ERROR, NULL);
|
||||
rpdata.array_index = 2;
|
||||
len = Notification_Class_Read_Property(&rpdata);
|
||||
zassert_not_equal(len, BACNET_STATUS_ERROR, NULL);
|
||||
rpdata.array_index = 3;
|
||||
len = Notification_Class_Read_Property(&rpdata);
|
||||
zassert_not_equal(len, BACNET_STATUS_ERROR, NULL);
|
||||
/* array property - index N+1 - non-existing */
|
||||
rpdata.array_index = 4;
|
||||
len = Notification_Class_Read_Property(&rpdata);
|
||||
zassert_equal(len, BACNET_STATUS_ERROR, NULL);
|
||||
/* WriteProperty - priority property */
|
||||
/* non-existing property of the object */
|
||||
rpdata.object_property = PROP_ALL;
|
||||
len = Notification_Class_Read_Property(&rpdata);
|
||||
zassert_equal(len, BACNET_STATUS_ERROR, NULL);
|
||||
@@ -132,6 +171,237 @@ static void test_Notification_Class(void)
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test
|
||||
*/
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
ZTEST(notification_class_tests, test_Notification_Class_Priority)
|
||||
#else
|
||||
static void test_Notification_Class_Priority(void)
|
||||
#endif
|
||||
{
|
||||
const uint32_t instance = 1;
|
||||
bool status = false;
|
||||
uint32_t priority_array[3] = { 0 };
|
||||
|
||||
Notification_Class_Init();
|
||||
status = Notification_Class_Valid_Instance(instance);
|
||||
zassert_true(status, NULL);
|
||||
|
||||
/* API testing */
|
||||
Notification_Class_Get_Priorities(BACNET_MAX_INSTANCE, priority_array);
|
||||
zassert_equal(
|
||||
priority_array[0], 255, "priority_array[0]=%u", priority_array[0]);
|
||||
zassert_equal(
|
||||
priority_array[1], 255, "priority_array[1]=%u", priority_array[1]);
|
||||
zassert_equal(
|
||||
priority_array[2], 255, "priority_array[2]=%u", priority_array[2]);
|
||||
Notification_Class_Get_Priorities(instance, priority_array);
|
||||
zassert_equal(
|
||||
priority_array[0], 255, "priority_array[0]=%u", priority_array[0]);
|
||||
zassert_equal(
|
||||
priority_array[1], 255, "priority_array[1]=%u", priority_array[1]);
|
||||
zassert_equal(
|
||||
priority_array[2], 255, "priority_array[2]=%u", priority_array[2]);
|
||||
|
||||
priority_array[0] = 1;
|
||||
priority_array[1] = 2;
|
||||
priority_array[2] = 3;
|
||||
Notification_Class_Set_Priorities(instance, priority_array);
|
||||
Notification_Class_Get_Priorities(instance, priority_array);
|
||||
zassert_equal(
|
||||
priority_array[0], 1, "priority_array[0]=%u", priority_array[0]);
|
||||
zassert_equal(
|
||||
priority_array[1], 2, "priority_array[1]=%u", priority_array[1]);
|
||||
zassert_equal(
|
||||
priority_array[2], 3, "priority_array[2]=%u", priority_array[2]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test
|
||||
*/
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
ZTEST(notification_class_tests, test_Notification_Class_Ack_Required)
|
||||
#else
|
||||
static void test_Notification_Class_Ack_Required(void)
|
||||
#endif
|
||||
{
|
||||
const uint32_t instance = 1;
|
||||
bool status = false;
|
||||
uint8_t ack_required = 0;
|
||||
|
||||
Notification_Class_Init();
|
||||
status = Notification_Class_Valid_Instance(instance);
|
||||
zassert_true(status, NULL);
|
||||
|
||||
/* API testing */
|
||||
Notification_Class_Get_Ack_Required(BACNET_MAX_INSTANCE, &ack_required);
|
||||
zassert_equal(ack_required, 0, "ack_required=%u", ack_required);
|
||||
Notification_Class_Get_Ack_Required(instance, &ack_required);
|
||||
zassert_equal(ack_required, 0, "ack_required=%u", ack_required);
|
||||
|
||||
Notification_Class_Set_Ack_Required(instance, 1);
|
||||
Notification_Class_Get_Ack_Required(instance, &ack_required);
|
||||
zassert_equal(ack_required, 1, "ack_required=%u", ack_required);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test
|
||||
*/
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
ZTEST(notification_class_tests, test_Notification_Class_Recipient_List)
|
||||
#else
|
||||
static void test_Notification_Class_Recipient_List(void)
|
||||
#endif
|
||||
{
|
||||
const uint32_t instance = 1;
|
||||
bool status = false;
|
||||
BACNET_LIST_ELEMENT_DATA list_element = { 0 };
|
||||
BACNET_DESTINATION destination = { 0 };
|
||||
BACNET_DESTINATION recipient_list[NC_MAX_RECIPIENTS] = { 0 };
|
||||
uint8_t apdu[MAX_APDU] = { 0 };
|
||||
int len = 0;
|
||||
int err = 0;
|
||||
|
||||
Notification_Class_Init();
|
||||
status = Notification_Class_Valid_Instance(instance);
|
||||
zassert_true(status, NULL);
|
||||
|
||||
/* invalid element */
|
||||
err = Notification_Class_Add_List_Element(NULL);
|
||||
zassert_equal(err, BACNET_STATUS_ABORT, NULL);
|
||||
/* valid element, invalid object property type (not a list) */
|
||||
list_element.object_type = OBJECT_NOTIFICATION_CLASS;
|
||||
list_element.object_instance = instance;
|
||||
list_element.object_property = PROP_ALL;
|
||||
list_element.array_index = BACNET_ARRAY_ALL;
|
||||
list_element.application_data = NULL;
|
||||
list_element.application_data_len = 0;
|
||||
list_element.first_failed_element_number = 0;
|
||||
err = Notification_Class_Add_List_Element(&list_element);
|
||||
zassert_equal(err, BACNET_STATUS_ERROR, NULL);
|
||||
zassert_equal(list_element.error_class, ERROR_CLASS_SERVICES, NULL);
|
||||
zassert_equal(
|
||||
list_element.error_code, ERROR_CODE_PROPERTY_IS_NOT_A_LIST, NULL);
|
||||
/* valid element, valid property, array element (object is not an array) */
|
||||
list_element.object_property = PROP_RECIPIENT_LIST;
|
||||
list_element.array_index = 0;
|
||||
err = Notification_Class_Add_List_Element(&list_element);
|
||||
zassert_equal(err, BACNET_STATUS_ERROR, NULL);
|
||||
zassert_equal(list_element.error_class, ERROR_CLASS_PROPERTY, NULL);
|
||||
zassert_equal(
|
||||
list_element.error_code, ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY, NULL);
|
||||
/* valid element, valid property, invalid instance */
|
||||
list_element.object_property = PROP_RECIPIENT_LIST;
|
||||
list_element.object_instance = BACNET_MAX_INSTANCE;
|
||||
list_element.array_index = BACNET_ARRAY_ALL;
|
||||
err = Notification_Class_Add_List_Element(&list_element);
|
||||
zassert_equal(err, BACNET_STATUS_ERROR, NULL);
|
||||
zassert_equal(list_element.error_class, ERROR_CLASS_OBJECT, NULL);
|
||||
zassert_equal(list_element.error_code, ERROR_CODE_UNKNOWN_OBJECT, NULL);
|
||||
/* valid element, valid property, valid instance, no data */
|
||||
list_element.object_property = PROP_RECIPIENT_LIST;
|
||||
list_element.object_instance = instance;
|
||||
list_element.array_index = BACNET_ARRAY_ALL;
|
||||
list_element.application_data = NULL;
|
||||
list_element.application_data_len = 0;
|
||||
err = Notification_Class_Add_List_Element(&list_element);
|
||||
zassert_equal(err, BACNET_STATUS_OK, NULL);
|
||||
/* valid element with application data */
|
||||
for (unsigned i = 0; i < MAX_BACNET_DAYS_OF_WEEK; i++) {
|
||||
bitstring_set_bit(&destination.ValidDays, i, true);
|
||||
}
|
||||
datetime_set_time(&destination.FromTime, 0, 0, 0, 0);
|
||||
datetime_set_time(&destination.ToTime, 23, 59, 59, 99);
|
||||
destination.ProcessIdentifier = 1;
|
||||
destination.ConfirmedNotify = true;
|
||||
bacnet_recipient_device_set(&destination.Recipient, OBJECT_DEVICE, 1);
|
||||
bitstring_set_bit(&destination.Transitions, TRANSITION_TO_OFFNORMAL, true);
|
||||
bitstring_set_bit(&destination.Transitions, TRANSITION_TO_FAULT, true);
|
||||
bitstring_set_bit(&destination.Transitions, TRANSITION_TO_NORMAL, true);
|
||||
len = bacnet_destination_encode(apdu, &destination);
|
||||
list_element.application_data = apdu;
|
||||
list_element.application_data_len = len;
|
||||
err = Notification_Class_Add_List_Element(&list_element);
|
||||
zassert_equal(err, BACNET_STATUS_OK, NULL);
|
||||
/* add a second recipient */
|
||||
bacnet_recipient_device_set(&destination.Recipient, OBJECT_DEVICE, 2);
|
||||
destination.ProcessIdentifier = 2;
|
||||
err = Notification_Class_Add_List_Element(&list_element);
|
||||
zassert_equal(err, BACNET_STATUS_OK, NULL);
|
||||
/* remove a recipient */
|
||||
bacnet_recipient_device_set(&destination.Recipient, OBJECT_DEVICE, 1);
|
||||
destination.ProcessIdentifier = 1;
|
||||
err = Notification_Class_Remove_List_Element(&list_element);
|
||||
zassert_equal(err, BACNET_STATUS_OK, NULL);
|
||||
/* negative tests */
|
||||
err = Notification_Class_Remove_List_Element(NULL);
|
||||
zassert_equal(err, BACNET_STATUS_ABORT, NULL);
|
||||
/* invalid property */
|
||||
list_element.object_property = PROP_ALL;
|
||||
err = Notification_Class_Remove_List_Element(&list_element);
|
||||
zassert_equal(err, BACNET_STATUS_ERROR, NULL);
|
||||
zassert_equal(list_element.error_class, ERROR_CLASS_SERVICES, NULL);
|
||||
zassert_equal(
|
||||
list_element.error_code, ERROR_CODE_PROPERTY_IS_NOT_A_LIST, NULL);
|
||||
/* invalid array */
|
||||
list_element.object_property = PROP_RECIPIENT_LIST;
|
||||
list_element.array_index = 0;
|
||||
err = Notification_Class_Remove_List_Element(&list_element);
|
||||
zassert_equal(err, BACNET_STATUS_ERROR, NULL);
|
||||
zassert_equal(list_element.error_class, ERROR_CLASS_PROPERTY, NULL);
|
||||
zassert_equal(
|
||||
list_element.error_code, ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY, NULL);
|
||||
/* invalid instance */
|
||||
list_element.object_property = PROP_RECIPIENT_LIST;
|
||||
list_element.array_index = BACNET_ARRAY_ALL;
|
||||
list_element.object_instance = BACNET_MAX_INSTANCE;
|
||||
err = Notification_Class_Remove_List_Element(&list_element);
|
||||
zassert_equal(err, BACNET_STATUS_ERROR, NULL);
|
||||
zassert_equal(list_element.error_class, ERROR_CLASS_OBJECT, NULL);
|
||||
zassert_equal(list_element.error_code, ERROR_CODE_UNKNOWN_OBJECT, NULL);
|
||||
|
||||
status =
|
||||
Notification_Class_Get_Recipient_List(instance, &recipient_list[0]);
|
||||
zassert_true(status, NULL);
|
||||
status = Notification_Class_Get_Recipient_List(
|
||||
BACNET_MAX_INSTANCE, &recipient_list[0]);
|
||||
zassert_false(status, NULL);
|
||||
status =
|
||||
Notification_Class_Set_Recipient_List(instance, &recipient_list[0]);
|
||||
zassert_true(status, NULL);
|
||||
status = Notification_Class_Set_Recipient_List(
|
||||
BACNET_MAX_INSTANCE, &recipient_list[0]);
|
||||
zassert_false(status, NULL);
|
||||
|
||||
Notification_Class_find_recipient();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test
|
||||
*/
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
ZTEST(notification_class_tests, test_Notification_Class_Common_Reporting)
|
||||
#else
|
||||
static void test_Notification_Class_Common_Reporting(void)
|
||||
#endif
|
||||
{
|
||||
const uint32_t instance = 1;
|
||||
bool status = false;
|
||||
BACNET_EVENT_NOTIFICATION_DATA event_data = { 0 };
|
||||
|
||||
Notification_Class_Init();
|
||||
status = Notification_Class_Valid_Instance(instance);
|
||||
zassert_true(status, NULL);
|
||||
|
||||
Notification_Class_common_reporting_function(&event_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -142,7 +412,12 @@ ZTEST_SUITE(notification_class_tests, NULL, NULL, NULL, NULL, NULL);
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(
|
||||
notification_class_tests, ztest_unit_test(test_Notification_Class));
|
||||
notification_class_tests,
|
||||
ztest_unit_test(test_Notification_Class_Read_Write_Property),
|
||||
ztest_unit_test(test_Notification_Class_Priority),
|
||||
ztest_unit_test(test_Notification_Class_Ack_Required),
|
||||
ztest_unit_test(test_Notification_Class_Recipient_List),
|
||||
ztest_unit_test(test_Notification_Class_Common_Reporting));
|
||||
|
||||
ztest_run_test_suite(notification_class_tests);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user