926bc17801
* 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
180 lines
6.8 KiB
C
180 lines
6.8 KiB
C
/**
|
|
* @file
|
|
* @brief Unit test for object
|
|
* @author Steve Karg <skarg@users.sourceforge.net>
|
|
* @date May 2024
|
|
*
|
|
* @copyright SPDX-License-Identifier: MIT
|
|
*/
|
|
#include <zephyr/ztest.h>
|
|
#include <bacnet/basic/object/structured_view.h>
|
|
#include <property_test.h>
|
|
|
|
/**
|
|
* @addtogroup bacnet_tests
|
|
* @{
|
|
*/
|
|
|
|
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
|
|
*/
|
|
#if defined(CONFIG_ZTEST_NEW_API)
|
|
ZTEST(tests_object_structured_view, test_object_structured_view)
|
|
#else
|
|
static void test_object_structured_view(void)
|
|
#endif
|
|
{
|
|
bool status = false;
|
|
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[] = {
|
|
{ 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();
|
|
Structured_View_Create(instance);
|
|
status = Structured_View_Valid_Instance(instance);
|
|
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, 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 */
|
|
status = Structured_View_Name_Set(instance, test_name);
|
|
zassert_true(status, NULL);
|
|
diff = strcmp(Structured_View_Name_ASCII(instance), test_name);
|
|
zassert_equal(diff, 0, NULL);
|
|
|
|
status = Structured_View_Description_Set(instance, test_description);
|
|
zassert_true(status, NULL);
|
|
diff = strcmp(Structured_View_Description(instance), test_description);
|
|
zassert_equal(diff, 0, NULL);
|
|
|
|
status = Structured_View_Node_Subtype_Set(instance, test_node_subtype);
|
|
zassert_true(status, NULL);
|
|
diff = strcmp(Structured_View_Node_Subtype(instance), test_node_subtype);
|
|
zassert_equal(diff, 0, NULL);
|
|
|
|
status = Structured_View_Node_Type_Set(instance, test_node_type);
|
|
zassert_true(status, NULL);
|
|
zassert_equal(Structured_View_Node_Type(instance), test_node_type, NULL);
|
|
|
|
status = Structured_View_Default_Subordinate_Relationship_Set(
|
|
instance, test_relationship);
|
|
zassert_true(status, NULL);
|
|
zassert_equal(
|
|
Structured_View_Default_Subordinate_Relationship(instance),
|
|
test_relationship, NULL);
|
|
|
|
status = Structured_View_Represents_Set(instance, &test_represents);
|
|
zassert_true(status, NULL);
|
|
diff = memcmp(
|
|
Structured_View_Represents(instance), &test_represents,
|
|
sizeof(test_represents));
|
|
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();
|
|
}
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
#if defined(CONFIG_ZTEST_NEW_API)
|
|
ZTEST_SUITE(tests_object_structured_view, NULL, NULL, NULL, NULL, NULL);
|
|
#else
|
|
void test_main(void)
|
|
{
|
|
ztest_test_suite(
|
|
tests_object_structured_view,
|
|
ztest_unit_test(test_object_structured_view));
|
|
|
|
ztest_run_test_suite(tests_object_structured_view);
|
|
}
|
|
#endif
|