fix analog, binary, and multistate output tests
This commit is contained in:
@@ -74,6 +74,8 @@ struct object_data {
|
||||
};
|
||||
/* Key List for storing the object data sorted by instance number */
|
||||
static OS_Keylist Object_List;
|
||||
/* common object type */
|
||||
static const BACNET_OBJECT_TYPE Object_Type = OBJECT_ANALOG_OUTPUT;
|
||||
/* callback for present value writes */
|
||||
static analog_output_write_present_value_callback
|
||||
Analog_Output_Write_Present_Value_Callback;
|
||||
@@ -559,7 +561,7 @@ bool Analog_Output_Name_Set(uint32_t object_instance, char *new_name)
|
||||
characterstring_init_ansi(&object_name, new_name);
|
||||
if (Device_Valid_Object_Name(
|
||||
&object_name, &found_type, &found_instance)) {
|
||||
if ((found_type == OBJECT_ANALOG_OUTPUT) &&
|
||||
if ((found_type == Object_Type) &&
|
||||
(found_instance == object_instance)) {
|
||||
/* writing same name to same object */
|
||||
status = true;
|
||||
@@ -1007,6 +1009,19 @@ int Analog_Output_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
|
||||
|
||||
apdu = rpdata->application_data;
|
||||
switch (rpdata->object_property) {
|
||||
case PROP_OBJECT_IDENTIFIER:
|
||||
apdu_len = encode_application_object_id(
|
||||
&apdu[0], Object_Type, rpdata->object_instance);
|
||||
break;
|
||||
case PROP_OBJECT_NAME:
|
||||
Analog_Output_Object_Name(rpdata->object_instance, &char_string);
|
||||
apdu_len =
|
||||
encode_application_character_string(&apdu[0], &char_string);
|
||||
break;
|
||||
case PROP_OBJECT_TYPE:
|
||||
apdu_len =
|
||||
encode_application_enumerated(&apdu[0], Object_Type);
|
||||
break;
|
||||
case PROP_PRESENT_VALUE:
|
||||
real_value = Analog_Output_Present_Value(rpdata->object_instance);
|
||||
apdu_len = encode_application_real(&apdu[0], real_value);
|
||||
|
||||
@@ -73,6 +73,8 @@ struct object_data {
|
||||
};
|
||||
/* Key List for storing the object data sorted by instance number */
|
||||
static OS_Keylist Object_List;
|
||||
/* common object type */
|
||||
static const BACNET_OBJECT_TYPE Object_Type = OBJECT_BINARY_OUTPUT;
|
||||
/* callback for present value writes */
|
||||
static binary_output_write_present_value_callback
|
||||
Binary_Output_Write_Present_Value_Callback;
|
||||
@@ -563,7 +565,7 @@ bool Binary_Output_Name_Set(uint32_t object_instance, char *new_name)
|
||||
characterstring_init_ansi(&object_name, new_name);
|
||||
if (Device_Valid_Object_Name(
|
||||
&object_name, &found_type, &found_instance)) {
|
||||
if ((found_type == OBJECT_BINARY_OUTPUT) &&
|
||||
if ((found_type == Object_Type) &&
|
||||
(found_instance == object_instance)) {
|
||||
/* writing same name to same object */
|
||||
status = true;
|
||||
@@ -987,6 +989,19 @@ int Binary_Output_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
|
||||
}
|
||||
apdu = rpdata->application_data;
|
||||
switch (rpdata->object_property) {
|
||||
case PROP_OBJECT_IDENTIFIER:
|
||||
apdu_len = encode_application_object_id(
|
||||
&apdu[0], Object_Type, rpdata->object_instance);
|
||||
break;
|
||||
case PROP_OBJECT_NAME:
|
||||
Binary_Output_Object_Name(rpdata->object_instance, &char_string);
|
||||
apdu_len =
|
||||
encode_application_character_string(&apdu[0], &char_string);
|
||||
break;
|
||||
case PROP_OBJECT_TYPE:
|
||||
apdu_len =
|
||||
encode_application_enumerated(&apdu[0], Object_Type);
|
||||
break;
|
||||
case PROP_PRESENT_VALUE:
|
||||
present_value =
|
||||
Binary_Output_Present_Value(rpdata->object_instance);
|
||||
|
||||
@@ -69,6 +69,8 @@ struct object_data {
|
||||
};
|
||||
/* Key List for storing the object data sorted by instance number */
|
||||
static OS_Keylist Object_List;
|
||||
/* common object type */
|
||||
static const BACNET_OBJECT_TYPE Object_Type = OBJECT_MULTI_STATE_OUTPUT;
|
||||
/* callback for present value writes */
|
||||
static multistate_output_write_present_value_callback
|
||||
Multistate_Output_Write_Present_Value_Callback;
|
||||
@@ -650,7 +652,7 @@ bool Multistate_Output_Name_Set(uint32_t object_instance, char *new_name)
|
||||
characterstring_init_ansi(&object_name, new_name);
|
||||
if (Device_Valid_Object_Name(
|
||||
&object_name, &found_type, &found_instance)) {
|
||||
if ((found_type == OBJECT_MULTI_STATE_VALUE) &&
|
||||
if ((found_type == Object_Type) &&
|
||||
(found_instance == object_instance)) {
|
||||
/* writing same name to same object */
|
||||
status = true;
|
||||
@@ -928,6 +930,18 @@ int Multistate_Output_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
|
||||
}
|
||||
apdu = rpdata->application_data;
|
||||
switch (rpdata->object_property) {
|
||||
case PROP_OBJECT_IDENTIFIER:
|
||||
apdu_len = encode_application_object_id(
|
||||
&apdu[0], Object_Type, rpdata->object_instance);
|
||||
break;
|
||||
case PROP_OBJECT_NAME:
|
||||
Multistate_Output_Object_Name(rpdata->object_instance, &char_string);
|
||||
apdu_len =
|
||||
encode_application_character_string(&apdu[0], &char_string);
|
||||
break;
|
||||
case PROP_OBJECT_TYPE:
|
||||
apdu_len = encode_application_enumerated(&apdu[0], Object_Type);
|
||||
break;
|
||||
case PROP_PRESENT_VALUE:
|
||||
present_value =
|
||||
Multistate_Output_Present_Value(rpdata->object_instance);
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ all: test
|
||||
|
||||
BUILD_DIR=build
|
||||
|
||||
CTEST_OPTIONS := --quiet --output-on-failure --parallel 4
|
||||
CTEST_OPTIONS := --quiet --output-on-failure
|
||||
CTEST_OPTIONS += --output-junit test-results.xml
|
||||
|
||||
.PHONY: test
|
||||
|
||||
@@ -42,11 +42,14 @@ add_executable(${PROJECT_NAME}
|
||||
${SRC_DIR}/bacnet/bacstr.c
|
||||
${SRC_DIR}/bacnet/bactext.c
|
||||
${SRC_DIR}/bacnet/basic/sys/bigend.c
|
||||
${SRC_DIR}/bacnet/cov.c
|
||||
${SRC_DIR}/bacnet/datetime.c
|
||||
${SRC_DIR}/bacnet/basic/sys/days.c
|
||||
${SRC_DIR}/bacnet/basic/sys/keylist.c
|
||||
${SRC_DIR}/bacnet/indtext.c
|
||||
${SRC_DIR}/bacnet/hostnport.c
|
||||
${SRC_DIR}/bacnet/lighting.c
|
||||
${SRC_DIR}/bacnet/memcopy.c
|
||||
${SRC_DIR}/bacnet/timestamp.c
|
||||
${SRC_DIR}/bacnet/wp.c
|
||||
${SRC_DIR}/bacnet/weeklyschedule.c
|
||||
@@ -54,6 +57,7 @@ add_executable(${PROJECT_NAME}
|
||||
${SRC_DIR}/bacnet/dailyschedule.c
|
||||
# Test and test library files
|
||||
./src/main.c
|
||||
../mock/device_mock.c
|
||||
${ZTST_DIR}/ztest_mock.c
|
||||
${ZTST_DIR}/ztest.c
|
||||
)
|
||||
|
||||
@@ -29,6 +29,7 @@ static void testAnalogOutput(void)
|
||||
const uint32_t instance = 1;
|
||||
|
||||
Analog_Output_Init();
|
||||
Analog_Output_Create(1);
|
||||
rpdata.application_data = &apdu[0];
|
||||
rpdata.application_data_len = sizeof(apdu);
|
||||
rpdata.object_type = OBJECT_ANALOG_OUTPUT;
|
||||
@@ -39,13 +40,17 @@ static void testAnalogOutput(void)
|
||||
while ((*required_property) >= 0) {
|
||||
rpdata.object_property = *required_property;
|
||||
len = Analog_Output_Read_Property(&rpdata);
|
||||
if (len < 0) {
|
||||
printf("property %u: failed to read!\n",
|
||||
(unsigned)rpdata.object_property);
|
||||
}
|
||||
zassert_true(len >= 0, NULL);
|
||||
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));
|
||||
printf("property %u: failed to decode!\n",
|
||||
(unsigned)rpdata.object_property);
|
||||
}
|
||||
if (rpdata.object_property == PROP_PRIORITY_ARRAY) {
|
||||
/* FIXME: known fail to decode */
|
||||
|
||||
@@ -42,11 +42,14 @@ add_executable(${PROJECT_NAME}
|
||||
${SRC_DIR}/bacnet/bacstr.c
|
||||
${SRC_DIR}/bacnet/bactext.c
|
||||
${SRC_DIR}/bacnet/basic/sys/bigend.c
|
||||
${SRC_DIR}/bacnet/cov.c
|
||||
${SRC_DIR}/bacnet/datetime.c
|
||||
${SRC_DIR}/bacnet/basic/sys/days.c
|
||||
${SRC_DIR}/bacnet/basic/sys/keylist.c
|
||||
${SRC_DIR}/bacnet/indtext.c
|
||||
${SRC_DIR}/bacnet/hostnport.c
|
||||
${SRC_DIR}/bacnet/lighting.c
|
||||
${SRC_DIR}/bacnet/memcopy.c
|
||||
${SRC_DIR}/bacnet/timestamp.c
|
||||
${SRC_DIR}/bacnet/wp.c
|
||||
${SRC_DIR}/bacnet/weeklyschedule.c
|
||||
@@ -54,6 +57,7 @@ add_executable(${PROJECT_NAME}
|
||||
${SRC_DIR}/bacnet/dailyschedule.c
|
||||
# Test and test library files
|
||||
./src/main.c
|
||||
../mock/device_mock.c
|
||||
${ZTST_DIR}/ztest_mock.c
|
||||
${ZTST_DIR}/ztest.c
|
||||
)
|
||||
|
||||
@@ -29,6 +29,7 @@ static void testBinaryOutput(void)
|
||||
const uint32_t instance = 1;
|
||||
|
||||
Binary_Output_Init();
|
||||
Binary_Output_Create(1);
|
||||
rpdata.application_data = &apdu[0];
|
||||
rpdata.application_data_len = sizeof(apdu);
|
||||
rpdata.object_type = OBJECT_BINARY_OUTPUT;
|
||||
@@ -39,13 +40,17 @@ static void testBinaryOutput(void)
|
||||
while ((*required_property) >= 0) {
|
||||
rpdata.object_property = *required_property;
|
||||
len = Binary_Output_Read_Property(&rpdata);
|
||||
if (len < 0) {
|
||||
printf("property %u: failed to read!\n",
|
||||
(unsigned)rpdata.object_property);
|
||||
}
|
||||
zassert_true(len >= 0, NULL);
|
||||
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));
|
||||
printf("property %u: failed to decode!\n",
|
||||
(unsigned)rpdata.object_property);
|
||||
}
|
||||
if (rpdata.object_property == PROP_PRIORITY_ARRAY) {
|
||||
/* FIXME: known fail to decode */
|
||||
|
||||
@@ -42,7 +42,6 @@ add_executable(${PROJECT_NAME}
|
||||
${SRC_DIR}/bacnet/bacreal.c
|
||||
${SRC_DIR}/bacnet/bacstr.c
|
||||
${SRC_DIR}/bacnet/bactext.c
|
||||
${SRC_DIR}/bacnet/basic/object/ao.c
|
||||
${SRC_DIR}/bacnet/basic/sys/bigend.c
|
||||
${SRC_DIR}/bacnet/datetime.c
|
||||
${SRC_DIR}/bacnet/basic/sys/days.c
|
||||
|
||||
@@ -42,11 +42,14 @@ add_executable(${PROJECT_NAME}
|
||||
${SRC_DIR}/bacnet/bacstr.c
|
||||
${SRC_DIR}/bacnet/bactext.c
|
||||
${SRC_DIR}/bacnet/basic/sys/bigend.c
|
||||
${SRC_DIR}/bacnet/cov.c
|
||||
${SRC_DIR}/bacnet/datetime.c
|
||||
${SRC_DIR}/bacnet/basic/sys/days.c
|
||||
${SRC_DIR}/bacnet/basic/sys/keylist.c
|
||||
${SRC_DIR}/bacnet/indtext.c
|
||||
${SRC_DIR}/bacnet/hostnport.c
|
||||
${SRC_DIR}/bacnet/lighting.c
|
||||
${SRC_DIR}/bacnet/memcopy.c
|
||||
${SRC_DIR}/bacnet/timestamp.c
|
||||
${SRC_DIR}/bacnet/wp.c
|
||||
${SRC_DIR}/bacnet/weeklyschedule.c
|
||||
@@ -54,6 +57,7 @@ add_executable(${PROJECT_NAME}
|
||||
${SRC_DIR}/bacnet/dailyschedule.c
|
||||
# Test and test library files
|
||||
./src/main.c
|
||||
../mock/device_mock.c
|
||||
${ZTST_DIR}/ztest_mock.c
|
||||
${ZTST_DIR}/ztest.c
|
||||
)
|
||||
|
||||
@@ -22,27 +22,44 @@
|
||||
static void testMultistateOutput(void)
|
||||
{
|
||||
uint8_t apdu[MAX_APDU] = { 0 };
|
||||
int len = 0;
|
||||
uint32_t len_value = 0;
|
||||
uint8_t tag_number = 0;
|
||||
BACNET_OBJECT_TYPE decoded_type = 0;
|
||||
uint32_t decoded_instance = 0;
|
||||
BACNET_READ_PROPERTY_DATA rpdata;
|
||||
int len = 0, test_len = 0;
|
||||
BACNET_READ_PROPERTY_DATA rpdata = { 0 };
|
||||
BACNET_APPLICATION_DATA_VALUE value = {0};
|
||||
const int *required_property = NULL;
|
||||
const uint32_t instance = 1;
|
||||
|
||||
Multistate_Output_Init();
|
||||
Multistate_Output_Create(1);
|
||||
rpdata.application_data = &apdu[0];
|
||||
rpdata.application_data_len = sizeof(apdu);
|
||||
rpdata.object_type = OBJECT_MULTI_STATE_OUTPUT;
|
||||
rpdata.object_instance = 1;
|
||||
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
|
||||
rpdata.object_instance = instance;
|
||||
rpdata.array_index = BACNET_ARRAY_ALL;
|
||||
len = Multistate_Output_Read_Property(&rpdata);
|
||||
zassert_not_equal(len, 0, NULL);
|
||||
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
|
||||
zassert_equal(tag_number, BACNET_APPLICATION_TAG_OBJECT_ID, NULL);
|
||||
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
|
||||
zassert_equal(decoded_type, rpdata.object_type, NULL);
|
||||
zassert_equal(decoded_instance, rpdata.object_instance, NULL);
|
||||
|
||||
Multistate_Output_Property_Lists(&required_property, NULL, NULL);
|
||||
while ((*required_property) >= 0) {
|
||||
rpdata.object_property = *required_property;
|
||||
len = Multistate_Output_Read_Property(&rpdata);
|
||||
if (len < 0) {
|
||||
printf("property %u: failed to read!\n",
|
||||
(unsigned)rpdata.object_property);
|
||||
}
|
||||
zassert_true(len >= 0, NULL);
|
||||
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 %u: failed to decode!\n",
|
||||
(unsigned)rpdata.object_property);
|
||||
}
|
||||
if (rpdata.object_property == PROP_PRIORITY_ARRAY) {
|
||||
/* FIXME: known fail to decode */
|
||||
len = test_len;
|
||||
}
|
||||
zassert_equal(len, test_len, NULL);
|
||||
}
|
||||
required_property++;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user