From 319a1dfd23327e8a38dfbfe7ea3968856068294c Mon Sep 17 00:00:00 2001 From: Steve Karg Date: Mon, 1 Aug 2022 22:17:27 -0500 Subject: [PATCH] remove key.c from any projects. Add unit test from key.c to keylist. (#317) Co-authored-by: Steve Karg --- .../BACnet_Stack_Library.vcxproj | 1 - test/bacnet/basic/object/objects/Makefile | 1 - test/bacnet/basic/sys/keylist/src/main.c | 32 ++++++++++++++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/ports/win32/Microsoft Visual Studio 2019/BACnet_Stack_Library/BACnet_Stack_Library.vcxproj b/ports/win32/Microsoft Visual Studio 2019/BACnet_Stack_Library/BACnet_Stack_Library.vcxproj index 58536e90..ab2ae697 100644 --- a/ports/win32/Microsoft Visual Studio 2019/BACnet_Stack_Library/BACnet_Stack_Library.vcxproj +++ b/ports/win32/Microsoft Visual Studio 2019/BACnet_Stack_Library/BACnet_Stack_Library.vcxproj @@ -196,7 +196,6 @@ - diff --git a/test/bacnet/basic/object/objects/Makefile b/test/bacnet/basic/object/objects/Makefile index bab34bdc..e184763b 100644 --- a/test/bacnet/basic/object/objects/Makefile +++ b/test/bacnet/basic/object/objects/Makefile @@ -10,7 +10,6 @@ CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g SRCS = main.c \ $(SRC_DIR)/bacnet/basic/object/objects.c \ $(SRC_DIR)/bacnet/basic/sys/keylist.c \ - $(SRC_DIR)/bacnet/basic/sys/key.c \ $(TEST_DIR)/ctest.c TARGET_NAME = unittest diff --git a/test/bacnet/basic/sys/keylist/src/main.c b/test/bacnet/basic/sys/keylist/src/main.c index 1f9cd6a7..091aaf29 100644 --- a/test/bacnet/basic/sys/keylist/src/main.c +++ b/test/bacnet/basic/sys/keylist/src/main.c @@ -284,6 +284,35 @@ static void testKeyListLarge(void) return; } + +/* test the encode and decode macros */ +static void testKeySample(void) +{ + int type, id; + int type_list[] = { 0, 1, KEY_TYPE_MAX / 2, KEY_TYPE_MAX - 1, -1 }; + int id_list[] = { 0, 1, KEY_ID_MAX / 2, KEY_ID_MAX - 1, -1 }; + int type_index = 0; + int id_index = 0; + int decoded_type, decoded_id; + KEY key; + + while (type_list[type_index] != -1) { + while (id_list[id_index] != -1) { + type = type_list[type_index]; + id = id_list[id_index]; + key = KEY_ENCODE(type, id); + decoded_type = KEY_DECODE_TYPE(key); + decoded_id = KEY_DECODE_ID(key); + zassert_equal(decoded_type, type, NULL); + zassert_equal(decoded_id, id, NULL); + id_index++; + } + id_index = 0; + type_index++; + } + + return; +} /** * @} */ @@ -296,7 +325,8 @@ void test_main(void) ztest_unit_test(testKeyListFILO), ztest_unit_test(testKeyListDataKey), ztest_unit_test(testKeyListDataIndex), - ztest_unit_test(testKeyListLarge) + ztest_unit_test(testKeyListLarge), + ztest_unit_test(testKeySample) ); ztest_run_test_suite(keylist_tests);