add defines for each supported BACAPP_TYPES_EXTRA (#543)

* add defines for each supported BACAPP_TYPES_EXTRA

---------

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
Steve Karg
2023-12-01 12:23:44 -06:00
committed by GitHub
parent c34e1a72b2
commit b9a29d8093
25 changed files with 902 additions and 213 deletions
+27 -37
View File
@@ -355,103 +355,95 @@ static void test_bacapp_same_value(void)
value.tag = test_value.tag;
#if defined(BACAPP_BOOLEAN)
zassert_true(bacapp_same_value(&value, &test_value), NULL);
value.type.Boolean = !test_value.type.Boolean;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#else
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#endif
value.type.Boolean = !test_value.type.Boolean;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
memset(&test_value, 0, sizeof(test_value));
test_value.tag = BACNET_APPLICATION_TAG_UNSIGNED_INT;
value = test_value; /* Struct copy */
#if defined(BACAPP_UNSIGNED)
zassert_true(bacapp_same_value(&value, &test_value), NULL);
value.type.Unsigned_Int = ~test_value.type.Unsigned_Int;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#else
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#endif
value.type.Unsigned_Int = ~test_value.type.Unsigned_Int;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
memset(&test_value, 0, sizeof(test_value));
test_value.tag = BACNET_APPLICATION_TAG_SIGNED_INT;
value = test_value; /* Struct copy */
#if defined(BACAPP_SIGNED)
zassert_true(bacapp_same_value(&value, &test_value), NULL);
value.type.Signed_Int = test_value.type.Signed_Int + 1;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#else
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#endif
value.type.Signed_Int = test_value.type.Signed_Int + 1;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
memset(&test_value, 0, sizeof(test_value));
test_value.tag = BACNET_APPLICATION_TAG_REAL;
value = test_value; /* Struct copy */
#if defined(BACAPP_REAL)
zassert_true(bacapp_same_value(&value, &test_value), NULL);
value.type.Real = test_value.type.Real + 1.0f;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#else
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#endif
value.type.Real = test_value.type.Real + 1.0f;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
memset(&test_value, 0, sizeof(test_value));
test_value.tag = BACNET_APPLICATION_TAG_DOUBLE;
value = test_value; /* Struct copy */
#if defined(BACAPP_DOUBLE)
zassert_true(bacapp_same_value(&value, &test_value), NULL);
value.type.Double = test_value.type.Double + 1.0;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#else
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#endif
value.type.Double = test_value.type.Double + 1.0;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
memset(&test_value, 0, sizeof(test_value));
test_value.tag = BACNET_APPLICATION_TAG_ENUMERATED;
value = test_value; /* Struct copy */
#if defined(BACAPP_ENUMERATED)
zassert_true(bacapp_same_value(&value, &test_value), NULL);
value.type.Enumerated = test_value.type.Enumerated + 1;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#else
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#endif
value.type.Enumerated = test_value.type.Enumerated + 1;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
memset(&test_value, 0, sizeof(test_value));
test_value.tag = BACNET_APPLICATION_TAG_DATE;
value = test_value; /* Struct copy */
#if defined(BACAPP_DATE)
zassert_true(bacapp_same_value(&value, &test_value), NULL);
value.type.Date.day = test_value.type.Date.day + 1;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
value = test_value; /* Struct copy */
value.type.Date.month = test_value.type.Date.month + 1;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
value = test_value; /* Struct copy */
value.type.Date.year = test_value.type.Date.year + 1;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#else
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#endif
value = test_value; /* Struct copy */
value.type.Date.day = test_value.type.Date.day + 1;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#if 0 /*REVISIT: wday is not compared! */
value = test_value; /* Struct copy */
value.type.Date.wday = test_value.type.Date.wday + 1;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#endif
value = test_value; /* Struct copy */
value.type.Date.month = test_value.type.Date.month + 1;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
value = test_value; /* Struct copy */
value.type.Date.year = test_value.type.Date.year + 1;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
memset(&test_value, 0, sizeof(test_value));
test_value.tag = BACNET_APPLICATION_TAG_TIME;
value = test_value; /* Struct copy */
#if defined(BACAPP_TIME)
zassert_true(bacapp_same_value(&value, &test_value), NULL);
#else
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#endif
value = test_value; /* Struct copy */
value.type.Time.hour = test_value.type.Time.hour + 1;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
@@ -467,16 +459,15 @@ static void test_bacapp_same_value(void)
value = test_value; /* Struct copy */
value.type.Time.hundredths = test_value.type.Time.hundredths + 1;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#else
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#endif
memset(&test_value, 0, sizeof(test_value));
test_value.tag = BACNET_APPLICATION_TAG_OBJECT_ID;
value = test_value; /* Struct copy */
#if defined(BACAPP_OBJECT_ID)
zassert_true(bacapp_same_value(&value, &test_value), NULL);
#else
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#endif
value = test_value; /* Struct copy */
value.type.Object_Id.type = test_value.type.Object_Id.type + 1;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
@@ -484,6 +475,9 @@ static void test_bacapp_same_value(void)
value = test_value; /* Struct copy */
value.type.Object_Id.instance = test_value.type.Object_Id.instance + 1;
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#else
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#endif
memset(&test_value, 0, sizeof(test_value));
test_value.tag = BACNET_APPLICATION_TAG_CHARACTER_STRING;
@@ -493,7 +487,6 @@ static void test_bacapp_same_value(void)
#else
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#endif
// TODO: Verify .type.Character_String value compared
memset(&test_value, 0, sizeof(test_value));
test_value.tag = BACNET_APPLICATION_TAG_OCTET_STRING;
@@ -503,7 +496,6 @@ static void test_bacapp_same_value(void)
#else
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#endif
// TODO: Verify .type.Octet_String value compared
memset(&test_value, 0, sizeof(test_value));
test_value.tag = BACNET_APPLICATION_TAG_BIT_STRING;
@@ -513,17 +505,15 @@ static void test_bacapp_same_value(void)
#else
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#endif
// TODO: Verify .type.Bit_String value compared
memset(&test_value, 0, sizeof(test_value));
test_value.tag = BACNET_APPLICATION_TAG_LIGHTING_COMMAND;
value = test_value; /* Struct copy */
#if defined(BACAPP_TYPES_EXTRA)
#if defined(BACAPP_LIGHTING_COMMAND)
zassert_true(bacapp_same_value(&value, &test_value), NULL);
#else
zassert_false(bacapp_same_value(&value, &test_value), NULL);
#endif
// TODO: Verify .type.Lighting_Command value compared
}
/**
+6 -4
View File
@@ -49,6 +49,7 @@ static void test_bacnet_tag_codec(uint8_t tag_number,
uint8_t apdu[BACNET_TAG_SIZE] = { 0 };
BACNET_TAG tag = { 0 };
int len = 0, test_len = 0, null_len = 0, tag_len = 0;
uint32_t tag_len_value_type;
bool status;
if (opening) {
@@ -72,9 +73,10 @@ static void test_bacnet_tag_codec(uint8_t tag_number,
zassert_false(tag.closing, NULL);
zassert_false(tag.opening, NULL);
status = bacnet_is_context_tag_number(
apdu, sizeof(apdu), tag_number, &tag_len);
apdu, sizeof(apdu), tag_number, &tag_len, &tag_len_value_type);
zassert_true(status, NULL);
zassert_equal(tag_len, test_len, NULL);
zassert_equal(tag_len_value_type, len_value_type, NULL);
} else if (opening) {
zassert_false(tag.context, NULL);
zassert_false(tag.application, NULL);
@@ -99,7 +101,7 @@ static void test_bacnet_tag_codec(uint8_t tag_number,
zassert_false(tag.closing, NULL);
zassert_false(tag.opening, NULL);
status = bacnet_is_context_tag_number(
apdu, sizeof(apdu), tag_number, &tag_len);
apdu, sizeof(apdu), tag_number, &tag_len, &tag_len_value_type);
zassert_false(status, NULL);
}
while (len) {
@@ -155,7 +157,7 @@ static void testBACDCodeTags(void)
uint8_t apdu[MAX_APDU] = { 0 };
uint8_t tag_number = 0, test_tag_number = 0;
int len = 0, test_len = 0, tag_len = 0;
uint32_t value = 0, test_value = 0;
uint32_t value = 0, test_value = 0, tag_len_value_type = 0;
unsigned i = 0, j = 0;
BACNET_TAG tag = { 0 };
bool status = false;
@@ -212,7 +214,7 @@ static void testBACDCodeTags(void)
zassert_false(tag.context, NULL);
zassert_true(tag.application, NULL);
status = bacnet_is_context_tag_number(
apdu, sizeof(apdu), tag_number, &tag_len);
apdu, sizeof(apdu), tag_number, &tag_len, &tag_len_value_type);
zassert_false(status, NULL);
zassert_false(tag.closing, NULL);
zassert_false(tag.opening, NULL);
+2 -1
View File
@@ -23,7 +23,8 @@ set(ZTST_DIR "${TST_DIR}/ztest/src")
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
BACAPP_ALL
BACAPP_MINIMAL=1
BACAPP_DESTINATION=1
)
include_directories(
+5 -1
View File
@@ -24,7 +24,11 @@ add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
MAX_APDU=50
)
BACAPP_MINIMAL=1
BACAPP_DEVICE_OBJECT_PROPERTY_REFERENCE=1
BACAPP_DEVICE_OBJECT_REFERENCE=1
BACAPP_OBJECT_PROPERTY_REFERENCE=1
)
include_directories(
${SRC_DIR}
+1
View File
@@ -23,6 +23,7 @@ set(ZTST_DIR "${TST_DIR}/ztest/src")
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
BACAPP_PRINT_ENABLED=1
)
include_directories(
+23
View File
@@ -28,7 +28,9 @@ static void testBACnetLightingCommand(BACNET_LIGHTING_COMMAND *data)
BACNET_LIGHTING_COMMAND test_data;
int len, apdu_len;
uint8_t apdu[MAX_APDU] = { 0 };
char command_text[80] = "";
/* copy */
status = lighting_command_copy(&test_data, NULL);
zassert_false(status, NULL);
status = lighting_command_copy(NULL, data);
@@ -37,6 +39,7 @@ static void testBACnetLightingCommand(BACNET_LIGHTING_COMMAND *data)
zassert_true(status, NULL);
status = lighting_command_same(&test_data, data);
zassert_true(status, NULL);
/* encode/decode */
len = lighting_command_encode(apdu, data);
apdu_len = lighting_command_decode(apdu, len, &test_data);
zassert_true(len > 0, "lighting-command[%s] failed to encode!",
@@ -48,6 +51,26 @@ static void testBACnetLightingCommand(BACNET_LIGHTING_COMMAND *data)
len--;
apdu_len = lighting_command_decode(apdu, len, NULL);
}
/* to/from ASCII */
len = lighting_command_to_ascii(NULL, NULL, 0);
zassert_equal(len, 0, NULL);
len = lighting_command_to_ascii(data, NULL, 0);
zassert_true(len > 0, NULL);
len = lighting_command_to_ascii(data, command_text, 0);
zassert_true(len > 0, NULL);
len = lighting_command_to_ascii(data, command_text, sizeof(command_text));
zassert_true(len > 0, NULL);
status = lighting_command_from_ascii(NULL, command_text);
zassert_false(status, NULL);
status = lighting_command_from_ascii(&test_data, NULL);
zassert_false(status, NULL);
status = lighting_command_from_ascii(NULL, NULL);
zassert_false(status, NULL);
status = lighting_command_from_ascii(&test_data, command_text);
zassert_true(status, NULL);
status = lighting_command_same(&test_data, data);
zassert_true(status, "lighting-command[%s] \"%s\" is different!",
bactext_lighting_operation_name(data->operation), command_text);
}
#if defined(CONFIG_ZTEST_NEW_API)