Feature/writable structured view object lists (#1256)
* Added WriteProperty handler in the Structured View object with handling for object-name, description, node-subtype, node-type, default-subordinate-relationship, represents, subordinate-list, subordinate-annotations, subordinate-node-types, and subordinate-relationships in the basic Structured View object. * Changed Structured View character strings for object-name, description, and node-subtype to use dynamic strings to support WriteProperty. * Added characterstring_utf8_valid(), characterstring_utf8_strdup() and write_property_characterstring_utf8_strdup() for UTF-8 string duplication. * Added write property tests for array handling and validation of array index values
This commit is contained in:
@@ -15,6 +15,22 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
static void Structured_View_Subordinate_List_Member_Same(
|
||||
BACNET_SUBORDINATE_DATA *list_member_a,
|
||||
BACNET_SUBORDINATE_DATA *list_member_b)
|
||||
{
|
||||
zassert_equal(
|
||||
list_member_a->Device_Instance, list_member_b->Device_Instance, NULL);
|
||||
zassert_equal(list_member_a->Object_Type, list_member_b->Object_Type, NULL);
|
||||
zassert_equal(
|
||||
list_member_a->Object_Instance, list_member_b->Object_Instance, NULL);
|
||||
zassert_equal(list_member_a->Node_Type, list_member_b->Node_Type, NULL);
|
||||
zassert_equal(
|
||||
list_member_a->Relationship, list_member_b->Relationship, NULL);
|
||||
zassert_equal(
|
||||
strcmp(list_member_a->Annotation, list_member_b->Annotation), 0, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test
|
||||
*/
|
||||
@@ -28,23 +44,35 @@ static void test_object_structured_view(void)
|
||||
int diff = 0;
|
||||
unsigned count = 0, index = 0;
|
||||
const uint32_t instance = 123;
|
||||
uint32_t test_instance = 0;
|
||||
const int32_t skip_fail_property_list[] = { -1 };
|
||||
const int32_t *writable_properties;
|
||||
size_t test_size = 0;
|
||||
const char *test_name = "name-1234";
|
||||
const char *test_description = "description-1234";
|
||||
const char *test_node_subtype = "node-subtype-1234";
|
||||
char *sample_context = "context";
|
||||
BACNET_NODE_TYPE test_node_type = BACNET_NODE_UNKNOWN;
|
||||
BACNET_RELATIONSHIP test_relationship = BACNET_RELATIONSHIP_DEFAULT;
|
||||
BACNET_SUBORDINATE_DATA *test_list_member = NULL;
|
||||
BACNET_DEVICE_OBJECT_REFERENCE test_represents = {
|
||||
{ OBJECT_DEVICE, 1234 }, { OBJECT_DEVICE, 1234 }
|
||||
};
|
||||
BACNET_SUBORDINATE_DATA test_subordinate_data = {
|
||||
1234,
|
||||
OBJECT_DEVICE,
|
||||
1234,
|
||||
"annotations-1234",
|
||||
BACNET_NODE_UNKNOWN,
|
||||
BACNET_RELATIONSHIP_DEFAULT,
|
||||
NULL
|
||||
BACNET_SUBORDINATE_DATA test_subordinate_data[] = {
|
||||
{ 0, OBJECT_ACCUMULATOR, 1, "watt-hours", BACNET_NODE_COLLECTION,
|
||||
BACNET_RELATIONSHIP_CONTAINS, NULL },
|
||||
{ 0, OBJECT_LOAD_CONTROL, 1, "demand-response", BACNET_NODE_COLLECTION,
|
||||
BACNET_RELATIONSHIP_CONTAINS, NULL },
|
||||
{ 0, OBJECT_CHANNEL, 1, "scene", BACNET_NODE_COLLECTION,
|
||||
BACNET_RELATIONSHIP_CONTAINS, NULL },
|
||||
{ 0, OBJECT_LIGHTING_OUTPUT, 1, "light", BACNET_NODE_COLLECTION,
|
||||
BACNET_RELATIONSHIP_CONTAINS, NULL },
|
||||
{ 0, OBJECT_BINARY_LIGHTING_OUTPUT, 1, "relay", BACNET_NODE_COLLECTION,
|
||||
BACNET_RELATIONSHIP_CONTAINS, NULL },
|
||||
{ 0, OBJECT_COLOR, 1, "color", BACNET_NODE_COLLECTION,
|
||||
BACNET_RELATIONSHIP_CONTAINS, NULL },
|
||||
{ 0, OBJECT_COLOR_TEMPERATURE, 1, "color-temperature",
|
||||
BACNET_NODE_COLLECTION, BACNET_RELATIONSHIP_CONTAINS, NULL },
|
||||
};
|
||||
|
||||
Structured_View_Init();
|
||||
@@ -53,11 +81,26 @@ static void test_object_structured_view(void)
|
||||
zassert_true(status, NULL);
|
||||
index = Structured_View_Instance_To_Index(instance);
|
||||
zassert_equal(index, 0, NULL);
|
||||
test_instance = Structured_View_Index_To_Instance(index);
|
||||
zassert_equal(test_instance, instance, NULL);
|
||||
count = Structured_View_Count();
|
||||
zassert_true(count > 0, NULL);
|
||||
Structured_View_Subordinate_List_Link_Array(
|
||||
test_subordinate_data, ARRAY_SIZE(test_subordinate_data));
|
||||
Structured_View_Subordinate_List_Set(instance, &test_subordinate_data[0]);
|
||||
count = Structured_View_Subordinate_List_Count(instance);
|
||||
zassert_equal(count, ARRAY_SIZE(test_subordinate_data), NULL);
|
||||
for (index = 0; index < count; index++) {
|
||||
test_list_member =
|
||||
Structured_View_Subordinate_List_Member(instance, index);
|
||||
zassert_not_null(test_list_member, NULL);
|
||||
Structured_View_Subordinate_List_Member_Same(
|
||||
test_list_member, &test_subordinate_data[index]);
|
||||
}
|
||||
bacnet_object_properties_read_write_test(
|
||||
OBJECT_STRUCTURED_VIEW, instance, Structured_View_Property_Lists,
|
||||
Structured_View_Read_Property, NULL, skip_fail_property_list);
|
||||
Structured_View_Read_Property, Structured_View_Write_Property,
|
||||
skip_fail_property_list);
|
||||
bacnet_object_name_ascii_test(
|
||||
instance, Structured_View_Name_Set, Structured_View_Name_ASCII);
|
||||
/* there is no WriteProperty test for structured view - use get/set */
|
||||
@@ -94,11 +137,29 @@ static void test_object_structured_view(void)
|
||||
sizeof(test_represents));
|
||||
zassert_equal(diff, 0, NULL);
|
||||
|
||||
Structured_View_Subordinate_List_Set(instance, &test_subordinate_data);
|
||||
diff = memcmp(
|
||||
Structured_View_Subordinate_List(instance), &test_subordinate_data,
|
||||
sizeof(test_subordinate_data));
|
||||
zassert_equal(diff, 0, NULL);
|
||||
/* WriteProperty test */
|
||||
Structured_View_Writable_Property_List(instance, &writable_properties);
|
||||
zassert_not_null(writable_properties, NULL);
|
||||
|
||||
/* property specific API */
|
||||
test_list_member = Structured_View_Subordinate_List_Member(instance, 0);
|
||||
Structured_View_Subordinate_List_Member_Same(
|
||||
test_list_member, &test_subordinate_data[0]);
|
||||
|
||||
/* context API */
|
||||
Structured_View_Context_Set(instance, sample_context);
|
||||
zassert_true(sample_context == Structured_View_Context_Get(instance), NULL);
|
||||
zassert_true(NULL == Structured_View_Context_Get(instance + 1), NULL);
|
||||
|
||||
test_size = Structured_View_Size();
|
||||
zassert_true(test_size > 0, NULL);
|
||||
printf("Structured_View_Size: %zu bytes\n", test_size);
|
||||
|
||||
Structured_View_Delete(instance);
|
||||
status = Structured_View_Valid_Instance(instance);
|
||||
zassert_false(status, NULL);
|
||||
|
||||
Structured_View_Cleanup();
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
|
||||
Reference in New Issue
Block a user