Feature/write property type check refactor (#182)

* refactor write-property tag check

* modify ports objects to use write-property tag check API

* modify example objects to use write-property tag check API

* Fix object unit test builds

* Fix and run unit ztests via CMake

* Enable unit testing on Travis CI

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
Steve Karg
2021-06-23 10:10:12 -05:00
committed by GitHub
parent 31b7fb3c40
commit 810a2f93de
139 changed files with 1142 additions and 4375 deletions
+22 -122
View File
@@ -1134,8 +1134,8 @@ bool Device_Write_Property_Local(BACNET_WRITE_PROPERTY_DATA *wp_data)
/* FIXME: len < application_data_len: more data? */
switch (wp_data->object_property) {
case PROP_OBJECT_IDENTIFIER:
status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_OBJECT_ID,
&wp_data->error_class, &wp_data->error_code);
status = write_property_type_valid(wp_data, &value,
BACNET_APPLICATION_TAG_OBJECT_ID);
if (status) {
if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
(Device_Set_Object_Instance_Number(
@@ -1150,36 +1150,32 @@ bool Device_Write_Property_Local(BACNET_WRITE_PROPERTY_DATA *wp_data)
}
break;
case PROP_NUMBER_OF_APDU_RETRIES:
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT,
&wp_data->error_class, &wp_data->error_code);
status = write_property_type_valid(wp_data, &value,
BACNET_APPLICATION_TAG_UNSIGNED_INT);
if (status) {
/* FIXME: bounds check? */
apdu_retries_set((uint8_t)value.type.Unsigned_Int);
}
break;
case PROP_APDU_TIMEOUT:
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT,
&wp_data->error_class, &wp_data->error_code);
status = write_property_type_valid(wp_data, &value,
BACNET_APPLICATION_TAG_UNSIGNED_INT);
if (status) {
/* FIXME: bounds check? */
apdu_timeout_set((uint16_t)value.type.Unsigned_Int);
}
break;
case PROP_VENDOR_IDENTIFIER:
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT,
&wp_data->error_class, &wp_data->error_code);
status = write_property_type_valid(wp_data, &value,
BACNET_APPLICATION_TAG_UNSIGNED_INT);
if (status) {
/* FIXME: bounds check? */
Device_Set_Vendor_Identifier((uint16_t)value.type.Unsigned_Int);
}
break;
case PROP_SYSTEM_STATUS:
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED,
&wp_data->error_class, &wp_data->error_code);
status = write_property_type_valid(wp_data, &value,
BACNET_APPLICATION_TAG_ENUMERATED);
if (status) {
temp = Device_Set_System_Status(
(BACNET_DEVICE_STATUS)value.type.Enumerated, false);
@@ -1196,9 +1192,8 @@ bool Device_Write_Property_Local(BACNET_WRITE_PROPERTY_DATA *wp_data)
}
break;
case PROP_OBJECT_NAME:
status = WPValidateString(&value,
characterstring_capacity(&My_Object_Name), false,
&wp_data->error_class, &wp_data->error_code);
status = write_property_string_valid(&wp_data, &value,
characterstring_capacity(&My_Object_Name));
if (status) {
/* All the object names in a device must be unique */
if (Device_Valid_Object_Name(&value.type.Character_String,
@@ -1218,8 +1213,8 @@ bool Device_Write_Property_Local(BACNET_WRITE_PROPERTY_DATA *wp_data)
}
break;
case PROP_LOCATION:
status = WPValidateString(&value, MAX_DEV_LOC_LEN, true,
&wp_data->error_class, &wp_data->error_code);
status = write_property_empty_string_valid(&wp_data, &value,
MAX_DEV_LOC_LEN);
if (status) {
Device_Set_Location(
characterstring_value(&value.type.Character_String),
@@ -1228,8 +1223,8 @@ bool Device_Write_Property_Local(BACNET_WRITE_PROPERTY_DATA *wp_data)
break;
case PROP_DESCRIPTION:
status = WPValidateString(&value, MAX_DEV_DESC_LEN, true,
&wp_data->error_class, &wp_data->error_code);
status = write_property_empty_string_valid(&wp_data, &value,
MAX_DEV_DESC_LEN);
if (status) {
Device_Set_Description(
characterstring_value(&value.type.Character_String),
@@ -1237,8 +1232,8 @@ bool Device_Write_Property_Local(BACNET_WRITE_PROPERTY_DATA *wp_data)
}
break;
case PROP_MODEL_NAME:
status = WPValidateString(&value, MAX_DEV_MOD_LEN, true,
&wp_data->error_class, &wp_data->error_code);
status = write_property_empty_string_valid(&wp_data, &value,
MAX_DEV_MOD_LEN);
if (status) {
Device_Set_Model_Name(
characterstring_value(&value.type.Character_String),
@@ -1248,9 +1243,8 @@ bool Device_Write_Property_Local(BACNET_WRITE_PROPERTY_DATA *wp_data)
case PROP_MAX_INFO_FRAMES:
#if defined(BACDL_MSTP)
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT,
&wp_data->error_class, &wp_data->error_code);
status = write_property_type_valid(wp_data, &value,
BACNET_APPLICATION_TAG_UNSIGNED_INT);
if (status) {
if (value.type.Unsigned_Int <= 255) {
dlmstp_set_max_info_frames(
@@ -1265,9 +1259,8 @@ bool Device_Write_Property_Local(BACNET_WRITE_PROPERTY_DATA *wp_data)
#endif
case PROP_MAX_MASTER:
#if defined(BACDL_MSTP)
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT,
&wp_data->error_class, &wp_data->error_code);
status = write_property_type_valid(wp_data, &value,
BACNET_APPLICATION_TAG_UNSIGNED_INT);
if (status) {
if ((value.type.Unsigned_Int > 0) &&
(value.type.Unsigned_Int <= 127)) {
@@ -1585,96 +1578,3 @@ void Routing_Device_Init(uint32_t first_object_instance)
}
#endif /* BAC_ROUTING */
#ifdef BAC_TEST
#include <assert.h>
#include <string.h>
#include "ctest.h"
bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue,
uint8_t ucExpectedTag,
BACNET_ERROR_CLASS *pErrorClass,
BACNET_ERROR_CODE *pErrorCode)
{
pValue = pValue;
ucExpectedTag = ucExpectedTag;
pErrorClass = pErrorClass;
pErrorCode = pErrorCode;
return false;
}
bool WPValidateString(BACNET_APPLICATION_DATA_VALUE *pValue,
int iMaxLen,
bool bEmptyAllowed,
BACNET_ERROR_CLASS *pErrorClass,
BACNET_ERROR_CODE *pErrorCode)
{
pValue = pValue;
iMaxLen = iMaxLen;
bEmptyAllowed = bEmptyAllowed;
pErrorClass = pErrorClass;
pErrorCode = pErrorCode;
return false;
}
int handler_cov_encode_subscriptions(uint8_t *apdu, int max_apdu)
{
apdu = apdu;
max_apdu = max_apdu;
return 0;
}
void testDevice(Test *pTest)
{
bool status = false;
const char *name = "Patricia";
status = Device_Set_Object_Instance_Number(0);
ct_test(pTest, Device_Object_Instance_Number() == 0);
ct_test(pTest, status == true);
status = Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE);
ct_test(pTest, Device_Object_Instance_Number() == BACNET_MAX_INSTANCE);
ct_test(pTest, status == true);
status = Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE / 2);
ct_test(
pTest, Device_Object_Instance_Number() == (BACNET_MAX_INSTANCE / 2));
ct_test(pTest, status == true);
status = Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE + 1);
ct_test(
pTest, Device_Object_Instance_Number() != (BACNET_MAX_INSTANCE + 1));
ct_test(pTest, status == false);
Device_Set_System_Status(STATUS_NON_OPERATIONAL, true);
ct_test(pTest, Device_System_Status() == STATUS_NON_OPERATIONAL);
ct_test(pTest, Device_Vendor_Identifier() == BACNET_VENDOR_ID);
Device_Set_Model_Name(name, strlen(name));
ct_test(pTest, strcmp(Device_Model_Name(), name) == 0);
return;
}
#ifdef TEST_DEVICE
int main(void)
{
Test *pTest;
bool rc;
pTest = ct_create("BACnet Device", NULL);
/* individual tests */
rc = ct_addTestFunction(pTest, testDevice);
assert(rc);
ct_setStream(pTest, stdout);
ct_run(pTest);
(void)ct_report(pTest);
ct_destroy(pTest);
return 0;
}
#endif /* TEST_DEVICE */
#endif /* BAC_TEST */