Change Life-Safety-Point object to use Create/Delete-Object (#555)

* Change Life-Safety-Point object to use Create/Delete-Object
This commit is contained in:
Steve Karg
2024-01-12 16:01:50 -06:00
committed by GitHub
parent ebc47571ba
commit c6dcab8f0a
9 changed files with 669 additions and 133 deletions
+11 -6
View File
@@ -4,9 +4,6 @@ cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
# set the project name
project(Unit_Tests)
# add definitions
add_definitions(-fprofile-arcs -ftest-coverage)
option(BACNET_STACK_DEPRECATED_DISABLE "Disable deprecation compile warnings" ON)
if(BACNET_STACK_DEPRECATED_DISABLE)
@@ -14,11 +11,19 @@ if(BACNET_STACK_DEPRECATED_DISABLE)
endif()
# Set the compiler options
if (NOT MSVC)
add_compile_options(-Wall -g -O0 -W -fprofile-arcs -ftest-coverage)
if (CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "GNU")
add_definitions(-fprofile-arcs -ftest-coverage)
add_compile_options(-g -O0 -W -fprofile-arcs -ftest-coverage)
add_compile_options(-Wall -Wextra -pedantic)
add_compile_options(-Wfloat-equal -Wconversion -Wparentheses)
add_compile_options(-Wunused-value -Wreturn-type -Wswitch-default)
add_compile_options(-Wuninitialized -Winit-self)
add_compile_options(-Wno-sign-conversion -Wno-conversion)
add_compile_options(-Wno-sign-compare -Wno-long-long)
add_compile_options(-Wno-implicit-fallthrough -Wno-attributes)
# ignore some warnings that occur during unit testing
add_compile_options(-Wno-unused-variable -Wno-unused-function)
add_compile_options(-Wno-sign-compare -Wno-unused-parameter)
add_compile_options(-Wno-unused-parameter)
add_link_options(-fprofile-arcs -ftest-coverage)
endif()
+2 -2
View File
@@ -7,7 +7,6 @@ project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE
"/test/bacnet/[a-zA-Z_/-]*$"
"/src"
@@ -45,8 +44,9 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/basic/sys/keylist.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c
+96 -13
View File
@@ -9,6 +9,7 @@
*/
#include <zephyr/ztest.h>
#include <bacnet/bactext.h>
#include <bacnet/basic/object/lsp.h>
/**
@@ -25,26 +26,108 @@ ZTEST(lsp_tests, testLifeSafetyPoint)
static void testLifeSafetyPoint(void)
#endif
{
BACNET_OBJECT_TYPE object_type = OBJECT_LIFE_SAFETY_POINT;
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0, test_len = 0;
BACNET_OBJECT_TYPE decoded_type = 0;
uint32_t decoded_instance = 0;
BACNET_READ_PROPERTY_DATA rpdata;
int len = 0;
int test_len = 0;
BACNET_READ_PROPERTY_DATA rpdata = { 0 };
BACNET_APPLICATION_DATA_VALUE value = { 0 };
const int *pRequired = NULL;
const int *pOptional = NULL;
const int *pProprietary = NULL;
const uint32_t instance = 123;
BACNET_WRITE_PROPERTY_DATA wpdata = { 0 };
bool status = false;
unsigned index;
Life_Safety_Point_Init();
Life_Safety_Point_Create(instance);
status = Life_Safety_Point_Valid_Instance(instance);
zassert_true(status, NULL);
index = Life_Safety_Point_Instance_To_Index(instance);
zassert_equal(index, 0, NULL);
rpdata.application_data = &apdu[0];
rpdata.application_data_len = sizeof(apdu);
rpdata.object_type = OBJECT_LIFE_SAFETY_POINT;
rpdata.object_instance = 1;
rpdata.object_type = object_type;
rpdata.object_instance = instance;
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
rpdata.array_index = BACNET_ARRAY_ALL;
Life_Safety_Point_Property_Lists(&pRequired, &pOptional, &pProprietary);
while ((*pRequired) >= 0) {
rpdata.object_property = *pRequired;
rpdata.array_index = BACNET_ARRAY_ALL;
len = Life_Safety_Point_Read_Property(&rpdata);
zassert_not_equal(len, BACNET_STATUS_ERROR,
"property '%s': failed to ReadProperty!\n",
bactext_property_name(rpdata.object_property));
if (len >= 0) {
test_len = bacapp_decode_known_property(rpdata.application_data,
len, &value, rpdata.object_type, rpdata.object_property);
if (len != test_len) {
printf("property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property));
} else {
zassert_equal(len, test_len, NULL);
}
/* check WriteProperty properties */
wpdata.object_type = rpdata.object_type;
wpdata.object_instance = rpdata.object_instance;
wpdata.object_property = rpdata.object_property;
wpdata.array_index = rpdata.array_index;
memcpy(&wpdata.application_data, rpdata.application_data, MAX_APDU);
wpdata.application_data_len = len;
wpdata.error_code = ERROR_CODE_SUCCESS;
status = Life_Safety_Point_Write_Property(&wpdata);
if (!status) {
/* verify WriteProperty property is known */
zassert_not_equal(wpdata.error_code,
ERROR_CODE_UNKNOWN_PROPERTY,
"property '%s': WriteProperty Unknown!\n",
bactext_property_name(rpdata.object_property));
}
}
pRequired++;
}
while ((*pOptional) != -1) {
rpdata.object_property = *pOptional;
rpdata.array_index = BACNET_ARRAY_ALL;
len = Life_Safety_Point_Read_Property(&rpdata);
zassert_not_equal(len, BACNET_STATUS_ERROR,
"property '%s': failed to ReadProperty!\n",
bactext_property_name(rpdata.object_property));
if (len > 0) {
test_len = bacapp_decode_application_data(rpdata.application_data,
(uint8_t)rpdata.application_data_len, &value);
zassert_equal(len, test_len, "property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property));
/* check WriteProperty properties */
wpdata.object_type = rpdata.object_type;
wpdata.object_instance = rpdata.object_instance;
wpdata.object_property = rpdata.object_property;
wpdata.array_index = rpdata.array_index;
memcpy(&wpdata.application_data, rpdata.application_data, MAX_APDU);
wpdata.application_data_len = len;
wpdata.error_code = ERROR_CODE_SUCCESS;
status = Life_Safety_Point_Write_Property(&wpdata);
if (!status) {
/* verify WriteProperty property is known */
zassert_not_equal(wpdata.error_code,
ERROR_CODE_UNKNOWN_PROPERTY,
"property '%s': WriteProperty Unknown!\n",
bactext_property_name(rpdata.object_property));
}
}
pOptional++;
}
rpdata.object_property = PROP_ALL;
len = Life_Safety_Point_Read_Property(&rpdata);
zassert_not_equal(len, 0, NULL);
test_len = bacnet_object_id_application_decode(
apdu, len, &decoded_type, &decoded_instance);
zassert_not_equal(test_len, BACNET_STATUS_ERROR, NULL);
zassert_equal(decoded_type, rpdata.object_type, NULL);
zassert_equal(decoded_instance, rpdata.object_instance, NULL);
zassert_equal(len, BACNET_STATUS_ERROR, NULL);
wpdata.object_property = PROP_ALL;
status = Life_Safety_Point_Write_Property(&wpdata);
zassert_false(status, NULL);
status = Life_Safety_Point_Delete(instance);
zassert_true(status, NULL);
return;
}
+1
View File
@@ -251,6 +251,7 @@ static void handle_signal(int sig)
PRINT(" at %s function\n", phase_str[phase]);
longjmp(test_fail, 1);
case TEST_PHASE_FRAMEWORK:
default:
PRINT("\n");
longjmp(stack_fail, 1);
}