Added object-name c-string getter function to basic objects so they can be referenced to free if dynamically created. (#754)

* Added basic object-name get for ASCII names to enable free if they were dynamically created. Added unit testing to validate the basic object ASCII object-name API.

* Removed static scope on character array used for name since the array gets copied into characterstring array and static is not needed.
This commit is contained in:
Steve Karg
2024-08-28 16:21:58 -05:00
committed by GitHub
parent b3c8c10c03
commit 3d3e192ae9
86 changed files with 872 additions and 87 deletions
+4
View File
@@ -40,6 +40,10 @@ static void testAnalogInput(void)
OBJECT_ANALOG_INPUT, object_instance, Analog_Input_Property_Lists,
Analog_Input_Read_Property, Analog_Input_Write_Property,
skip_fail_property_list);
bacnet_object_name_ascii_test(
object_instance,
Analog_Input_Name_Set,
Analog_Input_Name_ASCII);
status = Analog_Input_Delete(object_instance);
zassert_true(status, NULL);
}
+5 -1
View File
@@ -28,7 +28,7 @@ static void testAnalogOutput(void)
bool status = false;
unsigned count = 0;
uint32_t object_instance = BACNET_MAX_INSTANCE, test_object_instance = 0;
const int skip_fail_property_list[] = { PROP_PRIORITY_ARRAY, -1 };
const int skip_fail_property_list[] = { -1 };
Analog_Output_Init();
object_instance = Analog_Output_Create(object_instance);
@@ -40,6 +40,10 @@ static void testAnalogOutput(void)
OBJECT_ANALOG_OUTPUT, object_instance, Analog_Output_Property_Lists,
Analog_Output_Read_Property, Analog_Output_Write_Property,
skip_fail_property_list);
bacnet_object_name_ascii_test(
object_instance,
Analog_Output_Name_Set,
Analog_Output_Name_ASCII);
status = Analog_Output_Delete(object_instance);
zassert_true(status, NULL);
}
+4
View File
@@ -40,6 +40,10 @@ static void testAnalog_Value(void)
OBJECT_ANALOG_VALUE, object_instance, Analog_Value_Property_Lists,
Analog_Value_Read_Property, Analog_Value_Write_Property,
skip_fail_property_list);
bacnet_object_name_ascii_test(
object_instance,
Analog_Value_Name_Set,
Analog_Value_Name_ASCII);
status = Analog_Value_Delete(object_instance);
zassert_true(status, NULL);
}
+4
View File
@@ -41,6 +41,10 @@ static void testBinaryInput(void)
OBJECT_BINARY_INPUT, object_instance, Binary_Input_Property_Lists,
Binary_Input_Read_Property, Binary_Input_Write_Property,
skip_fail_property_list);
bacnet_object_name_ascii_test(
object_instance,
Binary_Input_Name_Set,
Binary_Input_Name_ASCII);
status = Binary_Input_Delete(object_instance);
zassert_true(status, NULL);
}
@@ -52,6 +52,10 @@ static void test_BitString_Value_Object(void)
OBJECT_BINARY_INPUT, instance, BitString_Value_Property_Lists,
BitString_Value_Read_Property, BitString_Value_Write_Property,
skip_fail_property_list);
bacnet_object_name_ascii_test(
instance,
BitString_Value_Name_Set,
BitString_Value_Name_ASCII);
/* test specific WriteProperty values */
BitString_Value_Write_Disable(instance);
status = BitString_Value_Write_Enabled(instance);
+11
View File
@@ -36,6 +36,8 @@ static void testBinaryLightingOutput(void)
uint32_t test_instance = 0;
bool status = false;
unsigned index;
const char *test_name = NULL;
char *sample_name = "sample";
Binary_Lighting_Output_Init();
test_instance = Binary_Lighting_Output_Create(instance);
@@ -129,6 +131,15 @@ static void testBinaryLightingOutput(void)
zassert_equal(len, BACNET_STATUS_ERROR, NULL);
status = Binary_Lighting_Output_Write_Property(&wpdata);
zassert_false(status, NULL);
/* test the ASCII name get/set */
status = Binary_Lighting_Output_Name_Set(instance, sample_name);
zassert_true(status, NULL);
test_name = Binary_Lighting_Output_Name_ASCII(instance);
zassert_equal(test_name, sample_name, NULL);
status = Binary_Lighting_Output_Name_Set(instance, NULL);
zassert_true(status, NULL);
test_name = Binary_Lighting_Output_Name_ASCII(instance);
zassert_equal(test_name, NULL, NULL);
/* check the delete function */
status = Binary_Lighting_Output_Delete(instance);
zassert_true(status, NULL);
+4
View File
@@ -40,6 +40,10 @@ static void testBinaryOutput(void)
OBJECT_BINARY_OUTPUT, object_instance, Binary_Output_Property_Lists,
Binary_Output_Read_Property, Binary_Output_Write_Property,
skip_fail_property_list);
bacnet_object_name_ascii_test(
object_instance,
Binary_Output_Name_Set,
Binary_Output_Name_ASCII);
status = Binary_Output_Delete(object_instance);
zassert_true(status, NULL);
}
+4
View File
@@ -42,6 +42,10 @@ static void testBinary_Value(void)
OBJECT_BINARY_VALUE, object_instance, Binary_Value_Property_Lists,
Binary_Value_Read_Property, Binary_Value_Write_Property,
skip_fail_property_list);
bacnet_object_name_ascii_test(
object_instance,
Binary_Value_Name_Set,
Binary_Value_Name_ASCII);
status = Binary_Value_Delete(object_instance);
zassert_true(status, NULL);
}
@@ -37,6 +37,8 @@ static void testCalendar(void)
uint32_t test_instance = 0;
bool status = false;
unsigned index;
const char *test_name = NULL;
char *sample_name = "sample";
Calendar_Init();
test_instance = Calendar_Create(instance);
@@ -127,6 +129,15 @@ static void testCalendar(void)
zassert_equal(len, BACNET_STATUS_ERROR, NULL);
status = Calendar_Write_Property(&wpdata);
zassert_false(status, NULL);
/* test the ASCII name get/set */
status = Calendar_Name_Set(instance, sample_name);
zassert_true(status, NULL);
test_name = Calendar_Name_ASCII(instance);
zassert_equal(test_name, sample_name, NULL);
status = Calendar_Name_Set(instance, NULL);
zassert_true(status, NULL);
test_name = Calendar_Name_ASCII(instance);
zassert_equal(test_name, NULL, NULL);
/* check the delete function */
status = Calendar_Delete(instance);
zassert_true(status, NULL);
@@ -34,6 +34,8 @@ static void test_Channel_ReadProperty(void)
unsigned count = 0;
bool status = false;
unsigned index;
const char *test_name = NULL;
char *sample_name = "sample";
Channel_Init();
Channel_Create(instance);
@@ -126,12 +128,23 @@ static void test_Channel_ReadProperty(void)
}
pOptional++;
}
/* check for unsupported property - use ALL */
rpdata.object_property = PROP_ALL;
len = Channel_Read_Property(&rpdata);
zassert_equal(len, BACNET_STATUS_ERROR, NULL);
wpdata.object_property = PROP_ALL;
status = Channel_Write_Property(&wpdata);
zassert_false(status, NULL);
/* test the ASCII name get/set */
status = Channel_Name_Set(instance, sample_name);
zassert_true(status, NULL);
test_name = Channel_Name_ASCII(instance);
zassert_equal(test_name, sample_name, NULL);
status = Channel_Name_Set(instance, NULL);
zassert_true(status, NULL);
test_name = Channel_Name_ASCII(instance);
zassert_equal(test_name, NULL, NULL);
/* cleanup */
status = Channel_Delete(instance);
zassert_true(status, NULL);
}
@@ -36,6 +36,8 @@ static void testColorObject(void)
BACNET_WRITE_PROPERTY_DATA wpdata = { 0 };
bool status = false;
unsigned index;
const char *test_name = NULL;
char *sample_name = "sample";
Color_Init();
Color_Create(instance);
@@ -119,12 +121,23 @@ static void testColorObject(void)
}
pOptional++;
}
/* check for unsupported property - use ALL */
rpdata.object_property = PROP_ALL;
len = Color_Read_Property(&rpdata);
zassert_equal(len, BACNET_STATUS_ERROR, NULL);
wpdata.object_property = PROP_ALL;
status = Color_Write_Property(&wpdata);
zassert_false(status, NULL);
/* test the ASCII name get/set */
status = Color_Name_Set(instance, sample_name);
zassert_true(status, NULL);
test_name = Color_Name_ASCII(instance);
zassert_equal(test_name, sample_name, NULL);
status = Color_Name_Set(instance, NULL);
zassert_true(status, NULL);
test_name = Color_Name_ASCII(instance);
zassert_equal(test_name, NULL, NULL);
/* cleanup */
status = Color_Delete(instance);
zassert_true(status, NULL);
@@ -35,6 +35,8 @@ static void testColorTemperature(void)
const uint32_t instance = 123;
BACNET_WRITE_PROPERTY_DATA wpdata = { 0 };
bool status = false;
const char *test_name = NULL;
char *sample_name = "sample";
Color_Temperature_Init();
Color_Temperature_Create(instance);
@@ -114,12 +116,23 @@ static void testColorTemperature(void)
}
pOptional++;
}
/* check for unsupported property - use ALL */
rpdata.object_property = PROP_ALL;
len = Color_Temperature_Read_Property(&rpdata);
zassert_equal(len, BACNET_STATUS_ERROR, NULL);
wpdata.object_property = PROP_ALL;
status = Color_Temperature_Write_Property(&wpdata);
zassert_false(status, NULL);
/* test the ASCII name get/set */
status = Color_Temperature_Name_Set(instance, sample_name);
zassert_true(status, NULL);
test_name = Color_Temperature_Name_ASCII(instance);
zassert_equal(test_name, sample_name, NULL);
status = Color_Temperature_Name_Set(instance, NULL);
zassert_true(status, NULL);
test_name = Color_Temperature_Name_ASCII(instance);
zassert_equal(test_name, NULL, NULL);
/* cleanup */
status = Color_Temperature_Delete(instance);
zassert_true(status, NULL);
+12
View File
@@ -26,6 +26,8 @@ static void testInteger_Value(void)
unsigned count = 0;
uint32_t object_instance = BACNET_MAX_INSTANCE, test_object_instance = 0;
const int skip_fail_property_list[] = { -1 };
const char *test_name = NULL;
char *sample_name = "sample";
Integer_Value_Init();
object_instance = Integer_Value_Create(object_instance);
@@ -37,6 +39,16 @@ static void testInteger_Value(void)
OBJECT_INTEGER_VALUE, object_instance, Integer_Value_Property_Lists,
Integer_Value_Read_Property, Integer_Value_Write_Property,
skip_fail_property_list);
/* test the ASCII name get/set */
status = Integer_Value_Name_Set(object_instance, sample_name);
zassert_true(status, NULL);
test_name = Integer_Value_Name_ASCII(object_instance);
zassert_equal(test_name, sample_name, NULL);
status = Integer_Value_Name_Set(object_instance, NULL);
zassert_true(status, NULL);
test_name = Integer_Value_Name_ASCII(object_instance);
zassert_equal(test_name, NULL, NULL);
/* cleanup */
status = Integer_Value_Delete(object_instance);
zassert_true(status, NULL);
}
+4
View File
@@ -657,6 +657,10 @@ static void test_Load_Control_Read_Write_Property(void)
OBJECT_LOAD_CONTROL, object_instance, Load_Control_Property_Lists,
Load_Control_Read_Property, Load_Control_Write_Property,
skip_fail_property_list);
bacnet_object_name_ascii_test(
object_instance,
Load_Control_Name_Set,
Load_Control_Name_ASCII);
test_teardown(object_instance);
}
+11
View File
@@ -38,6 +38,8 @@ static void testLightingOutput(void)
bool status = false;
unsigned index;
uint16_t milliseconds = 10;
const char *test_name = NULL;
char *sample_name = "sample";
Lighting_Output_Init();
Lighting_Output_Create(instance);
@@ -131,6 +133,15 @@ static void testLightingOutput(void)
zassert_false(status, NULL);
/* check the dimming/ramping/stepping engine*/
Lighting_Output_Timer(instance, milliseconds);
/* test the ASCII name get/set */
status = Lighting_Output_Name_Set(instance, sample_name);
zassert_true(status, NULL);
test_name = Lighting_Output_Name_ASCII(instance);
zassert_equal(test_name, sample_name, NULL);
status = Lighting_Output_Name_Set(instance, NULL);
zassert_true(status, NULL);
test_name = Lighting_Output_Name_ASCII(instance);
zassert_equal(test_name, NULL, NULL);
/* check the delete function */
status = Lighting_Output_Delete(instance);
zassert_true(status, NULL);
+13
View File
@@ -39,6 +39,8 @@ static void testLifeSafetyPoint(void)
BACNET_WRITE_PROPERTY_DATA wpdata = { 0 };
bool status = false;
unsigned index;
const char *test_name = NULL;
char *sample_name = "sample";
Life_Safety_Point_Init();
Life_Safety_Point_Create(instance);
@@ -126,12 +128,23 @@ static void testLifeSafetyPoint(void)
}
pOptional++;
}
/* check for unsupported property - use ALL */
rpdata.object_property = PROP_ALL;
len = Life_Safety_Point_Read_Property(&rpdata);
zassert_equal(len, BACNET_STATUS_ERROR, NULL);
wpdata.object_property = PROP_ALL;
status = Life_Safety_Point_Write_Property(&wpdata);
zassert_false(status, NULL);
/* test the ASCII name get/set */
status = Life_Safety_Point_Name_Set(instance, sample_name);
zassert_true(status, NULL);
test_name = Life_Safety_Point_Name_ASCII(instance);
zassert_equal(test_name, sample_name, NULL);
status = Life_Safety_Point_Name_Set(instance, NULL);
zassert_true(status, NULL);
test_name = Life_Safety_Point_Name_ASCII(instance);
zassert_equal(test_name, NULL, NULL);
/* cleanup */
status = Life_Safety_Point_Delete(instance);
zassert_true(status, NULL);
+15
View File
@@ -27,9 +27,12 @@ ZTEST(testsLifeSafetyZone, testLifeSafetyZone)
static void testLifeSafetyZone(void)
#endif
{
bool status;
unsigned count = 0;
uint32_t object_instance = 0, test_object_instance = 0;
const int skip_fail_property_list[] = { -1 };
const char *test_name = NULL;
char *sample_name = "sample";
Life_Safety_Zone_Init();
object_instance = Life_Safety_Zone_Create(BACNET_MAX_INSTANCE);
@@ -41,6 +44,18 @@ static void testLifeSafetyZone(void)
OBJECT_LIFE_SAFETY_ZONE, object_instance,
Life_Safety_Zone_Property_Lists, Life_Safety_Zone_Read_Property,
Life_Safety_Zone_Write_Property, skip_fail_property_list);
/* test the ASCII name get/set */
status = Life_Safety_Zone_Name_Set(object_instance, sample_name);
zassert_true(status, NULL);
test_name = Life_Safety_Zone_Name_ASCII(object_instance);
zassert_equal(test_name, sample_name, NULL);
status = Life_Safety_Zone_Name_Set(object_instance, NULL);
zassert_true(status, NULL);
test_name = Life_Safety_Zone_Name_ASCII(object_instance);
zassert_equal(test_name, NULL, NULL);
/* cleanup */
status = Life_Safety_Zone_Delete(object_instance);
}
/**
* @}
@@ -41,6 +41,10 @@ static void testMultistateInput(void)
OBJECT_MULTI_STATE_INPUT, object_instance,
Multistate_Input_Property_Lists, Multistate_Input_Read_Property,
Multistate_Input_Write_Property, skip_fail_property_list);
bacnet_object_name_ascii_test(
object_instance,
Multistate_Input_Name_Set,
Multistate_Input_Name_ASCII);
status = Multistate_Input_Delete(object_instance);
zassert_true(status, NULL);
}
+4
View File
@@ -40,6 +40,10 @@ static void testMultistateOutput(void)
OBJECT_MULTI_STATE_OUTPUT, object_instance,
Multistate_Output_Property_Lists, Multistate_Output_Read_Property,
Multistate_Output_Write_Property, skip_fail_property_list);
bacnet_object_name_ascii_test(
object_instance,
Multistate_Output_Name_Set,
Multistate_Output_Name_ASCII);
status = Multistate_Output_Delete(object_instance);
zassert_true(status, NULL);
}
+4
View File
@@ -41,6 +41,10 @@ static void testMultistateValue(void)
OBJECT_MULTI_STATE_VALUE, object_instance,
Multistate_Value_Property_Lists, Multistate_Value_Read_Property,
Multistate_Value_Write_Property, skip_fail_property_list);
bacnet_object_name_ascii_test(
object_instance,
Multistate_Value_Name_Set,
Multistate_Value_Name_ASCII);
status = Multistate_Value_Delete(object_instance);
zassert_true(status, NULL);
}
@@ -57,6 +57,10 @@ static void test_network_port(void)
OBJECT_NETWORK_PORT, object_instance, Network_Port_Property_Lists,
Network_Port_Read_Property, Network_Port_Write_Property,
known_fail_property_list);
bacnet_object_name_ascii_test(
object_instance,
Network_Port_Name_Set,
Network_Port_Object_Name_ASCII);
port++;
}
@@ -40,6 +40,10 @@ static void test_object_structured_view(void)
bacnet_object_properties_read_write_test(
OBJECT_STRUCTURED_VIEW, instance, Structured_View_Property_Lists,
Structured_View_Read_Property, NULL, skip_fail_property_list);
bacnet_object_name_ascii_test(
instance,
Structured_View_Name_Set,
Structured_View_Name_ASCII);
}
/**
* @}
@@ -11,6 +11,7 @@
#include <bacnet/rp.h>
#include <bacnet/rpm.h>
#include <bacnet/wp.h>
#include "property_test.h"
/**
* @brief Perform a read/write test on a property
@@ -221,3 +222,28 @@ void bacnet_object_properties_read_write_test(
zassert_false(status, NULL);
}
}
/**
* @brief Perform a test on the ASCII name of an object
* @param object_instance The instance number of the object to test
* @param ascii_set The function to set the ASCII name
* @param ascii_get The function to get the ASCII name
*/
void bacnet_object_name_ascii_test(
uint32_t object_instance,
object_name_ascii_set_function ascii_set,
object_name_ascii_function ascii_get)
{
bool status = false;
const char *test_name = NULL;
char *sample_name = "sample";
status = ascii_set(object_instance, sample_name);
zassert_true(status, NULL);
test_name = ascii_get(object_instance);
zassert_equal(test_name, sample_name, NULL);
status = ascii_set(object_instance, NULL);
zassert_true(status, NULL);
test_name = ascii_get(object_instance);
zassert_equal(test_name, NULL, NULL);
}
@@ -13,6 +13,17 @@
#include <bacnet/rpm.h>
#include <bacnet/wp.h>
/* function API pattern for testing ASCII name get/set */
typedef bool (*object_name_ascii_set_function) (uint32_t object_instance,
char *new_name);
typedef const char * (*object_name_ascii_function) (
uint32_t object_instance);
void bacnet_object_name_ascii_test(
uint32_t object_instance,
object_name_ascii_set_function ascii_set,
object_name_ascii_function ascii_get);
void bacnet_object_properties_read_write_test(
BACNET_OBJECT_TYPE object_type,
uint32_t object_instance,
@@ -40,6 +40,10 @@ static void testTimeValue(void)
OBJECT_TIME_VALUE, object_instance, Time_Value_Property_Lists,
Time_Value_Read_Property, Time_Value_Write_Property,
skip_fail_property_list);
bacnet_object_name_ascii_test(
object_instance,
Time_Value_Name_Set,
Time_Value_Name_ASCII);
/* check the delete function */
status = Time_Value_Delete(object_instance);
zassert_true(status, NULL);