diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 2a81fc14..521d1730 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,11 +1,11 @@ -name: Lint +name: Quality on: push: branches: - master pull_request: - branches: + branches: - '*' jobs: @@ -29,8 +29,11 @@ jobs: sudo apt-get update -qq sudo apt-get install -qq cppcheck - name: cppcheck - run: make clean cppcheck - + run: | + cppcheck --version + make clean + make cppcheck + codespell: runs-on: ubuntu-latest steps: @@ -42,3 +45,13 @@ jobs: - name: codespell run: make spell + unittest: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Create Build Environment + run: | + sudo apt-get update -qq + sudo apt-get install -qq lcov + - name: Run Unit Test + run: make test diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b1ff96bd..b1ee8710 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,7 +5,7 @@ on: branches: - master pull_request: - branches: + branches: - '*' env: @@ -33,8 +33,8 @@ jobs: # access regardless of the host operating system shell: bash working-directory: ${{runner.workspace}}/build - # Note the current convention is to use the -S and -B options here to specify source - # and build directories, but this is only available with CMake 3.13 and higher. + # Note the current convention is to use the -S and -B options here to specify source + # and build directories, but this is only available with CMake 3.13 and higher. # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE @@ -43,11 +43,3 @@ jobs: shell: bash # Execute the build. You can specify a specific target with "--target " run: cmake --build . --config $BUILD_TYPE - - - name: Test - # Use a bash shell to execute tests in the pipeline - working-directory: ${{runner.workspace}}/build - shell: bash - # Execute tests defined by the CMake configuration. - # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - run: make test diff --git a/CMakeLists.txt b/CMakeLists.txt index 0cfb42c3..61a2420d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.7 FATAL_ERROR) project( bacnet-stack - VERSION 0.8.6 + VERSION 1.1.0 LANGUAGES C) # @@ -313,7 +313,6 @@ add_library(${PROJECT_NAME} src/bacnet/basic/sys/fifo.h src/bacnet/basic/sys/filename.c src/bacnet/basic/sys/filename.h - src/bacnet/basic/sys/key.c src/bacnet/basic/sys/key.h src/bacnet/basic/sys/keylist.c src/bacnet/basic/sys/keylist.h @@ -444,112 +443,6 @@ add_library( ALIAS ${PROJECT_NAME}) -# -# add tests -# - -list(APPEND testdirs - test/bacnet/abort - test/bacnet/alarm_ack - test/bacnet/arf - test/bacnet/awf - test/bacnet/bacapp - test/bacnet/bacdcode - test/bacnet/bacdevobjpropref - test/bacnet/bacerror - test/bacnet/bacint - test/bacnet/bacpropstates - test/bacnet/bacreal - test/bacnet/bacstr - test/bacnet/cov - test/bacnet/datetime - test/bacnet/dcc - test/bacnet/event - test/bacnet/getevent - test/bacnet/iam - test/bacnet/ihave - test/bacnet/indtext - test/bacnet/lighting - test/bacnet/lso - test/bacnet/memcopy - test/bacnet/npdu - test/bacnet/property - test/bacnet/ptransfer - test/bacnet/rd - test/bacnet/reject - test/bacnet/rp - test/bacnet/rpm - test/bacnet/timestamp - test/bacnet/timesync - test/bacnet/whohas - test/bacnet/whois - test/bacnet/wp - ) - -# bacnet/basic/* -list(APPEND testdirs - # basic/object/binding - test/bacnet/basic/binding/address - # basic/object - test/bacnet/basic/object/acc - test/bacnet/basic/object/access_credential - test/bacnet/basic/object/access_door - test/bacnet/basic/object/access_point - test/bacnet/basic/object/access_rights - test/bacnet/basic/object/access_user - test/bacnet/basic/object/access_zone - test/bacnet/basic/object/ai - test/bacnet/basic/object/ao - test/bacnet/basic/object/av - test/bacnet/basic/object/bi - test/bacnet/basic/object/bo - test/bacnet/basic/object/bv - test/bacnet/basic/object/command - test/bacnet/basic/object/credential_data_input - test/bacnet/basic/object/device - #test/bacnet/basic/object/lc #Tests skipped, redesign to use only API - test/bacnet/basic/object/lo - test/bacnet/basic/object/lsp - test/bacnet/basic/object/ms-input - test/bacnet/basic/object/mso - test/bacnet/basic/object/msv - test/bacnet/basic/object/netport - test/bacnet/basic/object/objects - test/bacnet/basic/object/osv - test/bacnet/basic/object/piv - test/bacnet/basic/object/schedule - # basic/sys - test/bacnet/basic/sys/days - test/bacnet/basic/sys/fifo - test/bacnet/basic/sys/filename - test/bacnet/basic/sys/key - test/bacnet/basic/sys/keylist - test/bacnet/basic/sys/ringbuf - test/bacnet/basic/sys/sbuf - ) - -# bacnet/datalink/* -list(APPEND testdirs - test/bacnet/datalink/cobs - test/bacnet/datalink/crc - test/bacnet/datalink/bvlc - ) - -enable_testing() -foreach(testdir IN ITEMS ${testdirs}) - get_filename_component(basename ${testdir} NAME) - add_subdirectory(${testdir}) - add_test(build_${basename} - "${CMAKE_COMMAND}" - --build "${CMAKE_BINARY_DIR}" - --config "$" - --target test_${basename} - ) - add_test(test_${basename} ${testdir}/test_${basename}) - set_tests_properties(test_${basename} PROPERTIES FIXTURES_REQUIRED test_fixture) - set_tests_properties(build_${basename} PROPERTIES FIXTURES_SETUP test_fixture) -endforeach() - # # add ports # diff --git a/Makefile b/Makefile index d04ca267..4d836e45 100644 --- a/Makefile +++ b/Makefile @@ -51,10 +51,6 @@ cmake: [ -d $(CMAKE_BUILD_DIR) ] || mkdir -p $(CMAKE_BUILD_DIR) [ -d $(CMAKE_BUILD_DIR) ] && cd $(CMAKE_BUILD_DIR) && cmake .. -DBUILD_SHARED_LIBS=ON && cmake --build . --clean-first -.PHONY: cmake-test -cmake-test: - [ -d $(CMAKE_BUILD_DIR) ] && $(MAKE) -s -C build test - .PHONY: abort abort: $(MAKE) -s -C apps $@ @@ -226,7 +222,6 @@ lint: CPPCHECK_OPTIONS = --enable=warning,portability CPPCHECK_OPTIONS += --template=gcc CPPCHECK_OPTIONS += --suppress=selfAssignment - .PHONY: cppcheck cppcheck: cppcheck $(CPPCHECK_OPTIONS) --quiet --force ./src/ @@ -257,6 +252,4 @@ clean: ports-clean .PHONY: test test: $(MAKE) -s -C test clean - $(MAKE) -s -C test all - $(MAKE) -s -C test report - + $(MAKE) -s -j -C test all diff --git a/README.md b/README.md index c58caa6f..5434f728 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ and unit testing to produce robust C code and BACnet functionality. [![Actions Status](https://github.com/bacnet-stack/bacnet-stack/workflows/GCC/badge.svg)](https://github.com/bacnet-stack/bacnet-stack/actions) GitHub Workflow -[![Actions Status](https://github.com/bacnet-stack/bacnet-stack/workflows/Lint/badge.svg)](https://github.com/bacnet-stack/bacnet-stack/actions) GitHub Workflow +[![Actions Status](https://github.com/bacnet-stack/bacnet-stack/workflows/Quality/badge.svg)](https://github.com/bacnet-stack/bacnet-stack/actions) GitHub Workflow [![Actions Status](https://github.com/bacnet-stack/bacnet-stack/workflows/CodeQL/badge.svg)](https://github.com/bacnet-stack/bacnet-stack/actions) GitHub Workflow diff --git a/ports/arduino_uno/av.c b/ports/arduino_uno/av.c index 77607880..1b180db2 100644 --- a/ports/arduino_uno/av.c +++ b/ports/arduino_uno/av.c @@ -197,53 +197,3 @@ bool Analog_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data, return status; } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -void testAnalog_Value(Test *pTest) -{ - uint8_t apdu[MAX_APDU] = { 0 }; - int len = 0; - uint32_t len_value = 0; - uint8_t tag_number = 0; - BACNET_OBJECT_TYPE decoded_type = OBJECT_ANALOG_VALUE; - uint32_t decoded_instance = 0; - uint32_t instance = 123; - BACNET_ERROR_CLASS error_class; - BACNET_ERROR_CODE error_code; - - len = Analog_Value_Encode_Property_APDU(&apdu[0], instance, - PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code); - ct_test(pTest, len != 0); - len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); - ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); - len = decode_object_id(&apdu[len], (int *)&decoded_type, &decoded_instance); - ct_test(pTest, decoded_type == OBJECT_ANALOG_VALUE); - ct_test(pTest, decoded_instance == instance); - - return; -} - -#ifdef TEST_ANALOG_VALUE -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet Analog Value", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testAnalog_Value); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_ANALOG_VALUE */ -#endif /* BAC_TEST */ diff --git a/ports/arduino_uno/av.h b/ports/arduino_uno/av.h index 2b4f2eff..06f6deda 100644 --- a/ports/arduino_uno/av.h +++ b/ports/arduino_uno/av.h @@ -64,11 +64,6 @@ extern "C" { void Analog_Value_Init(void); -#ifdef BAC_TEST -#include "ctest.h" - void testAnalog_Value(Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/ports/arduino_uno/bv.c b/ports/arduino_uno/bv.c index 0d9189bf..770962e2 100644 --- a/ports/arduino_uno/bv.c +++ b/ports/arduino_uno/bv.c @@ -244,53 +244,3 @@ bool Binary_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data, return status; } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -void testBinary_Value(Test *pTest) -{ - uint8_t apdu[MAX_APDU] = { 0 }; - int len = 0; - uint32_t len_value = 0; - uint8_t tag_number = 0; - BACNET_OBJECT_TYPE decoded_type = OBJECT_BINARY_VALUE; - uint32_t decoded_instance = 0; - uint32_t instance = 123; - BACNET_ERROR_CLASS error_class; - BACNET_ERROR_CODE error_code; - - len = Binary_Value_Encode_Property_APDU(&apdu[0], instance, - PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code); - ct_test(pTest, len != 0); - len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); - ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); - len = decode_object_id(&apdu[len], (int *)&decoded_type, &decoded_instance); - ct_test(pTest, decoded_type == OBJECT_BINARY_VALUE); - ct_test(pTest, decoded_instance == instance); - - return; -} - -#ifdef TEST_BINARY_VALUE -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet Binary_Value", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testBinary_Value); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_BINARY_VALUE */ -#endif /* BAC_TEST */ diff --git a/ports/arduino_uno/bv.h b/ports/arduino_uno/bv.h index 090612bb..e85dc1f1 100644 --- a/ports/arduino_uno/bv.h +++ b/ports/arduino_uno/bv.h @@ -61,11 +61,6 @@ extern "C" { BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code); -#ifdef BAC_TEST -#include "ctest.h" - void testBinary_Value(Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/ports/atmega168/ai.h b/ports/atmega168/ai.h index 6f6d5f19..992a09d3 100644 --- a/ports/atmega168/ai.h +++ b/ports/atmega168/ai.h @@ -82,12 +82,6 @@ extern "C" { void Analog_Input_Init( void); -#ifdef BAC_TEST -#include "ctest.h" - void testAnalogInput( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/ports/atmega168/av.c b/ports/atmega168/av.c index ac2396d1..3fa4627b 100644 --- a/ports/atmega168/av.c +++ b/ports/atmega168/av.c @@ -216,53 +216,3 @@ bool Analog_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) return status; } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -void testAnalog_Value(Test *pTest) -{ - uint8_t apdu[MAX_APDU] = { 0 }; - int len = 0; - uint32_t len_value = 0; - uint8_t tag_number = 0; - BACNET_OBJECT_TYPE decoded_type = OBJECT_ANALOG_VALUE; - uint32_t decoded_instance = 0; - uint32_t instance = 123; - BACNET_ERROR_CLASS error_class; - BACNET_ERROR_CODE error_code; - - len = Analog_Value_Encode_Property_APDU(&apdu[0], instance, - PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code); - ct_test(pTest, len != 0); - len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); - ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); - len = decode_object_id(&apdu[len], (int *)&decoded_type, &decoded_instance); - ct_test(pTest, decoded_type == OBJECT_ANALOG_VALUE); - ct_test(pTest, decoded_instance == instance); - - return; -} - -#ifdef TEST_ANALOG_VALUE -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet Analog Value", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testAnalog_Value); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_ANALOG_VALUE */ -#endif /* BAC_TEST */ diff --git a/ports/atmega168/av.h b/ports/atmega168/av.h index 3aabf0bf..10eb23ac 100644 --- a/ports/atmega168/av.h +++ b/ports/atmega168/av.h @@ -74,12 +74,6 @@ extern "C" { void Analog_Value_Init( void); -#ifdef BAC_TEST -#include "ctest.h" - void testAnalog_Value( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/ports/atmega168/bv.c b/ports/atmega168/bv.c index 79168009..cf846a9f 100644 --- a/ports/atmega168/bv.c +++ b/ports/atmega168/bv.c @@ -260,53 +260,3 @@ bool Binary_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) return status; } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -void testBinary_Value(Test *pTest) -{ - uint8_t apdu[MAX_APDU] = { 0 }; - int len = 0; - uint32_t len_value = 0; - uint8_t tag_number = 0; - BACNET_OBJECT_TYPE decoded_type = OBJECT_BINARY_VALUE; - uint32_t decoded_instance = 0; - uint32_t instance = 123; - BACNET_ERROR_CLASS error_class; - BACNET_ERROR_CODE error_code; - - len = Binary_Value_Encode_Property_APDU(&apdu[0], instance, - PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code); - ct_test(pTest, len != 0); - len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); - ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); - len = decode_object_id(&apdu[len], (int *)&decoded_type, &decoded_instance); - ct_test(pTest, decoded_type == OBJECT_BINARY_VALUE); - ct_test(pTest, decoded_instance == instance); - - return; -} - -#ifdef TEST_BINARY_VALUE -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet Binary_Value", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testBinary_Value); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_BINARY_VALUE */ -#endif /* BAC_TEST */ diff --git a/ports/atmega168/bv.h b/ports/atmega168/bv.h index 2107ac1e..e891b87a 100644 --- a/ports/atmega168/bv.h +++ b/ports/atmega168/bv.h @@ -69,12 +69,6 @@ extern "C" { BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code); -#ifdef BAC_TEST -#include "ctest.h" - void testBinary_Value( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/ports/esp32/src/ai.h b/ports/esp32/src/ai.h index 63e9e074..bfec0f2e 100644 --- a/ports/esp32/src/ai.h +++ b/ports/esp32/src/ai.h @@ -162,12 +162,6 @@ extern "C" { void Analog_Input_Init( void); -#ifdef BAC_TEST -#include "ctest.h" - void testAnalogInput( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/ports/esp32/src/bo.h b/ports/esp32/src/bo.h index 83115acf..6645db43 100644 --- a/ports/esp32/src/bo.h +++ b/ports/esp32/src/bo.h @@ -129,12 +129,6 @@ extern "C" { void Binary_Output_Cleanup( void); -#ifdef BAC_TEST -#include "ctest.h" - void testBinaryOutput( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/ports/zephyr/event.c b/ports/zephyr/event.c index 170a9bdb..cfb9352f 100644 --- a/ports/zephyr/event.c +++ b/ports/zephyr/event.c @@ -1137,944 +1137,3 @@ int event_notify_decode_service_request( return len; } - -#ifdef BAC_TEST - -#include -#include -#include "ctest.h" - -BACNET_EVENT_NOTIFICATION_DATA data; -BACNET_EVENT_NOTIFICATION_DATA data2; - -void testBaseEventState(Test *pTest) -{ - ct_test(pTest, data.processIdentifier == data2.processIdentifier); - ct_test(pTest, - data.initiatingObjectIdentifier.instance == - data2.initiatingObjectIdentifier.instance); - ct_test(pTest, - data.initiatingObjectIdentifier.type == - data2.initiatingObjectIdentifier.type); - ct_test(pTest, - data.eventObjectIdentifier.instance == - data2.eventObjectIdentifier.instance); - ct_test(pTest, - data.eventObjectIdentifier.type == data2.eventObjectIdentifier.type); - ct_test(pTest, data.notificationClass == data2.notificationClass); - ct_test(pTest, data.priority == data2.priority); - ct_test(pTest, data.notifyType == data2.notifyType); - ct_test(pTest, data.fromState == data2.fromState); - ct_test(pTest, data.toState == data2.toState); - ct_test(pTest, data.toState == data2.toState); - - if (data.messageText != NULL && data2.messageText != NULL) { - ct_test( - pTest, data.messageText->encoding == data2.messageText->encoding); - ct_test(pTest, data.messageText->length == data2.messageText->length); - ct_test(pTest, - strcmp(data.messageText->value, data2.messageText->value) == 0); - } - - ct_test(pTest, data.timeStamp.tag == data2.timeStamp.tag); - - switch (data.timeStamp.tag) { - case TIME_STAMP_SEQUENCE: - ct_test(pTest, - data.timeStamp.value.sequenceNum == - data2.timeStamp.value.sequenceNum); - break; - - case TIME_STAMP_DATETIME: - ct_test(pTest, - data.timeStamp.value.dateTime.time.hour == - data2.timeStamp.value.dateTime.time.hour); - ct_test(pTest, - data.timeStamp.value.dateTime.time.min == - data2.timeStamp.value.dateTime.time.min); - ct_test(pTest, - data.timeStamp.value.dateTime.time.sec == - data2.timeStamp.value.dateTime.time.sec); - ct_test(pTest, - data.timeStamp.value.dateTime.time.hundredths == - data2.timeStamp.value.dateTime.time.hundredths); - - ct_test(pTest, - data.timeStamp.value.dateTime.date.day == - data2.timeStamp.value.dateTime.date.day); - ct_test(pTest, - data.timeStamp.value.dateTime.date.month == - data2.timeStamp.value.dateTime.date.month); - ct_test(pTest, - data.timeStamp.value.dateTime.date.wday == - data2.timeStamp.value.dateTime.date.wday); - ct_test(pTest, - data.timeStamp.value.dateTime.date.year == - data2.timeStamp.value.dateTime.date.year); - break; - - case TIME_STAMP_TIME: - ct_test(pTest, - data.timeStamp.value.time.hour == - data2.timeStamp.value.time.hour); - ct_test(pTest, - data.timeStamp.value.time.min == - data2.timeStamp.value.time.min); - ct_test(pTest, - data.timeStamp.value.time.sec == - data2.timeStamp.value.time.sec); - ct_test(pTest, - data.timeStamp.value.time.hundredths == - data2.timeStamp.value.time.hundredths); - break; - - default: - ct_fail(pTest, "Unknown type"); - break; - } -} - -void testEventEventState(Test *pTest) -{ - uint8_t buffer[MAX_APDU]; - int inLen; - int outLen; - BACNET_CHARACTER_STRING messageText; - BACNET_CHARACTER_STRING messageText2; - characterstring_init_ansi( - &messageText, "This is a test of the message text\n"); - - data.messageText = &messageText; - data2.messageText = &messageText2; - - data.processIdentifier = 1234; - data.initiatingObjectIdentifier.type = OBJECT_ANALOG_INPUT; - data.initiatingObjectIdentifier.instance = 100; - data.eventObjectIdentifier.type = OBJECT_ANALOG_INPUT; - data.eventObjectIdentifier.instance = 200; - data.timeStamp.value.sequenceNum = 1234; - data.timeStamp.tag = TIME_STAMP_SEQUENCE; - data.notificationClass = 50; - data.priority = 50; - data.notifyType = NOTIFY_ALARM; - data.fromState = EVENT_STATE_NORMAL; - data.toState = EVENT_STATE_OFFNORMAL; - - data.eventType = EVENT_CHANGE_OF_STATE; - data.notificationParams.changeOfState.newState.tag = UNITS; - data.notificationParams.changeOfState.newState.state.units = - UNITS_SQUARE_METERS; - - bitstring_init(&data.notificationParams.changeOfState.statusFlags); - bitstring_set_bit(&data.notificationParams.changeOfState.statusFlags, - STATUS_FLAG_IN_ALARM, true); - bitstring_set_bit(&data.notificationParams.changeOfState.statusFlags, - STATUS_FLAG_FAULT, false); - bitstring_set_bit(&data.notificationParams.changeOfState.statusFlags, - STATUS_FLAG_OVERRIDDEN, false); - bitstring_set_bit(&data.notificationParams.changeOfState.statusFlags, - STATUS_FLAG_OUT_OF_SERVICE, false); - - inLen = event_notify_encode_service_request(&buffer[0], &data); - - outLen = event_notify_decode_service_request(&buffer[0], inLen, &data2); - - ct_test(pTest, inLen == outLen); - testBaseEventState(pTest); - - ct_test(pTest, - data.notificationParams.changeOfState.newState.tag == - data2.notificationParams.changeOfState.newState.tag); - ct_test(pTest, - data.notificationParams.changeOfState.newState.state.units == - data2.notificationParams.changeOfState.newState.state.units); - - ct_test(pTest, - bitstring_same(&data.notificationParams.changeOfState.statusFlags, - &data2.notificationParams.changeOfState.statusFlags)); - - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - - /* - ** Same, but timestamp of - */ - data.timeStamp.tag = TIME_STAMP_DATETIME; - data.timeStamp.value.dateTime.time.hour = 1; - data.timeStamp.value.dateTime.time.min = 2; - data.timeStamp.value.dateTime.time.sec = 3; - data.timeStamp.value.dateTime.time.hundredths = 4; - - data.timeStamp.value.dateTime.date.day = 1; - data.timeStamp.value.dateTime.date.month = 1; - data.timeStamp.value.dateTime.date.wday = 1; - data.timeStamp.value.dateTime.date.year = 1945; - - memset(buffer, 0, MAX_APDU); - inLen = event_notify_encode_service_request(&buffer[0], &data); - - memset(&data2, 0, sizeof(data2)); - data2.messageText = &messageText2; - outLen = event_notify_decode_service_request(&buffer[0], inLen, &data2); - - ct_test(pTest, inLen == outLen); - testBaseEventState(pTest); - ct_test(pTest, - data.notificationParams.changeOfState.newState.tag == - data2.notificationParams.changeOfState.newState.tag); - ct_test(pTest, - data.notificationParams.changeOfState.newState.state.units == - data2.notificationParams.changeOfState.newState.state.units); - - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - - /* - ** Event Type = EVENT_CHANGE_OF_BITSTRING - */ - data.timeStamp.value.sequenceNum = 1234; - data.timeStamp.tag = TIME_STAMP_SEQUENCE; - - data.eventType = EVENT_CHANGE_OF_BITSTRING; - - bitstring_init( - &data.notificationParams.changeOfBitstring.referencedBitString); - bitstring_set_bit( - &data.notificationParams.changeOfBitstring.referencedBitString, 0, - true); - bitstring_set_bit( - &data.notificationParams.changeOfBitstring.referencedBitString, 1, - false); - bitstring_set_bit( - &data.notificationParams.changeOfBitstring.referencedBitString, 2, - true); - bitstring_set_bit( - &data.notificationParams.changeOfBitstring.referencedBitString, 2, - false); - - bitstring_init(&data.notificationParams.changeOfBitstring.statusFlags); - - bitstring_set_bit(&data.notificationParams.changeOfBitstring.statusFlags, - STATUS_FLAG_IN_ALARM, true); - bitstring_set_bit(&data.notificationParams.changeOfBitstring.statusFlags, - STATUS_FLAG_FAULT, false); - bitstring_set_bit(&data.notificationParams.changeOfBitstring.statusFlags, - STATUS_FLAG_OVERRIDDEN, false); - bitstring_set_bit(&data.notificationParams.changeOfBitstring.statusFlags, - STATUS_FLAG_OUT_OF_SERVICE, false); - - memset(buffer, 0, MAX_APDU); - inLen = event_notify_encode_service_request(&buffer[0], &data); - - memset(&data2, 0, sizeof(data2)); - data2.messageText = &messageText2; - outLen = event_notify_decode_service_request(&buffer[0], inLen, &data2); - - ct_test(pTest, inLen == outLen); - testBaseEventState(pTest); - - ct_test(pTest, - bitstring_same( - &data.notificationParams.changeOfBitstring.referencedBitString, - &data2.notificationParams.changeOfBitstring.referencedBitString)); - - ct_test(pTest, - bitstring_same(&data.notificationParams.changeOfBitstring.statusFlags, - &data2.notificationParams.changeOfBitstring.statusFlags)); - - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /* - ** Event Type = EVENT_CHANGE_OF_VALUE - float value - */ - - data.eventType = EVENT_CHANGE_OF_VALUE; - data.notificationParams.changeOfValue.tag = CHANGE_OF_VALUE_REAL; - data.notificationParams.changeOfValue.newValue.changeValue = 1.23f; - - bitstring_init(&data.notificationParams.changeOfValue.statusFlags); - - bitstring_set_bit(&data.notificationParams.changeOfValue.statusFlags, - STATUS_FLAG_IN_ALARM, true); - bitstring_set_bit(&data.notificationParams.changeOfValue.statusFlags, - STATUS_FLAG_FAULT, false); - bitstring_set_bit(&data.notificationParams.changeOfValue.statusFlags, - STATUS_FLAG_OVERRIDDEN, false); - bitstring_set_bit(&data.notificationParams.changeOfValue.statusFlags, - STATUS_FLAG_OUT_OF_SERVICE, false); - - memset(buffer, 0, MAX_APDU); - inLen = event_notify_encode_service_request(&buffer[0], &data); - - memset(&data2, 0, sizeof(data2)); - data2.messageText = &messageText2; - outLen = event_notify_decode_service_request(&buffer[0], inLen, &data2); - - ct_test(pTest, inLen == outLen); - testBaseEventState(pTest); - - ct_test(pTest, - bitstring_same(&data.notificationParams.changeOfValue.statusFlags, - &data2.notificationParams.changeOfValue.statusFlags)); - - ct_test(pTest, - data.notificationParams.changeOfValue.tag == - data2.notificationParams.changeOfValue.tag); - - ct_test(pTest, - data.notificationParams.changeOfValue.newValue.changeValue == - data2.notificationParams.changeOfValue.newValue.changeValue); - - /* - ** Event Type = EVENT_CHANGE_OF_VALUE - bitstring value - */ - - data.notificationParams.changeOfValue.tag = CHANGE_OF_VALUE_BITS; - - bitstring_init(&data.notificationParams.changeOfValue.newValue.changedBits); - bitstring_set_bit( - &data.notificationParams.changeOfValue.newValue.changedBits, 0, true); - bitstring_set_bit( - &data.notificationParams.changeOfValue.newValue.changedBits, 1, false); - bitstring_set_bit( - &data.notificationParams.changeOfValue.newValue.changedBits, 2, false); - bitstring_set_bit( - &data.notificationParams.changeOfValue.newValue.changedBits, 3, false); - - memset(buffer, 0, MAX_APDU); - inLen = event_notify_encode_service_request(&buffer[0], &data); - - memset(&data2, 0, sizeof(data2)); - data2.messageText = &messageText2; - outLen = event_notify_decode_service_request(&buffer[0], inLen, &data2); - - ct_test(pTest, inLen == outLen); - testBaseEventState(pTest); - - ct_test(pTest, - bitstring_same(&data.notificationParams.changeOfValue.statusFlags, - &data2.notificationParams.changeOfValue.statusFlags)); - - ct_test(pTest, - data.notificationParams.changeOfValue.tag == - data2.notificationParams.changeOfValue.tag); - - ct_test(pTest, - bitstring_same( - &data.notificationParams.changeOfValue.newValue.changedBits, - &data2.notificationParams.changeOfValue.newValue.changedBits)); - - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /* - ** Event Type = EVENT_COMMAND_FAILURE - */ - - - /* - ** commandValue = enumerated - */ - data.eventType = EVENT_COMMAND_FAILURE; - data.notificationParams.commandFailure.tag = COMMAND_FAILURE_BINARY_PV; - data.notificationParams.commandFailure.commandValue.binaryValue = - BINARY_INACTIVE; - data.notificationParams.commandFailure.feedbackValue.binaryValue = - BINARY_ACTIVE; - - bitstring_init(&data.notificationParams.commandFailure.statusFlags); - - bitstring_set_bit(&data.notificationParams.commandFailure.statusFlags, - STATUS_FLAG_IN_ALARM, true); - bitstring_set_bit(&data.notificationParams.commandFailure.statusFlags, - STATUS_FLAG_FAULT, false); - bitstring_set_bit(&data.notificationParams.commandFailure.statusFlags, - STATUS_FLAG_OVERRIDDEN, false); - bitstring_set_bit(&data.notificationParams.commandFailure.statusFlags, - STATUS_FLAG_OUT_OF_SERVICE, false); - - memset(buffer, 0, MAX_APDU); - inLen = event_notify_encode_service_request(&buffer[0], &data); - - memset(&data2, 0, sizeof(data2)); - data2.messageText = &messageText2; - outLen = event_notify_decode_service_request(&buffer[0], inLen, &data2); - - ct_test(pTest, inLen == outLen); - testBaseEventState(pTest); - - ct_test(pTest, - data.notificationParams.commandFailure.commandValue.binaryValue == - data2.notificationParams.commandFailure.commandValue.binaryValue); - - ct_test(pTest, - data.notificationParams.commandFailure.feedbackValue.binaryValue == - data2.notificationParams.commandFailure.feedbackValue.binaryValue); - - ct_test(pTest, - bitstring_same(&data.notificationParams.commandFailure.statusFlags, - &data2.notificationParams.commandFailure.statusFlags)); - - /* - ** commandValue = unsigned - */ - data.eventType = EVENT_COMMAND_FAILURE; - data.notificationParams.commandFailure.tag = COMMAND_FAILURE_UNSIGNED; - data.notificationParams.commandFailure.commandValue.unsignedValue = 10; - data.notificationParams.commandFailure.feedbackValue.unsignedValue = 2; - - bitstring_init(&data.notificationParams.commandFailure.statusFlags); - - bitstring_set_bit(&data.notificationParams.commandFailure.statusFlags, - STATUS_FLAG_IN_ALARM, true); - bitstring_set_bit(&data.notificationParams.commandFailure.statusFlags, - STATUS_FLAG_FAULT, false); - bitstring_set_bit(&data.notificationParams.commandFailure.statusFlags, - STATUS_FLAG_OVERRIDDEN, false); - bitstring_set_bit(&data.notificationParams.commandFailure.statusFlags, - STATUS_FLAG_OUT_OF_SERVICE, false); - - memset(buffer, 0, MAX_APDU); - inLen = event_notify_encode_service_request(&buffer[0], &data); - - memset(&data2, 0, sizeof(data2)); - data2.messageText = &messageText2; - outLen = event_notify_decode_service_request(&buffer[0], inLen, &data2); - - ct_test(pTest, inLen == outLen); - testBaseEventState(pTest); - - ct_test(pTest, - data.notificationParams.commandFailure.commandValue.unsignedValue == - data2.notificationParams.commandFailure.commandValue.unsignedValue); - - ct_test(pTest, - data.notificationParams.commandFailure.feedbackValue.unsignedValue == - data2.notificationParams.commandFailure.feedbackValue.unsignedValue); - - ct_test(pTest, - bitstring_same(&data.notificationParams.commandFailure.statusFlags, - &data2.notificationParams.commandFailure.statusFlags)); - - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /* - ** Event Type = EVENT_FLOATING_LIMIT - */ - data.eventType = EVENT_FLOATING_LIMIT; - data.notificationParams.floatingLimit.referenceValue = 1.23f; - data.notificationParams.floatingLimit.setPointValue = 2.34f; - data.notificationParams.floatingLimit.errorLimit = 3.45f; - - bitstring_init(&data.notificationParams.floatingLimit.statusFlags); - - bitstring_set_bit(&data.notificationParams.floatingLimit.statusFlags, - STATUS_FLAG_IN_ALARM, true); - bitstring_set_bit(&data.notificationParams.floatingLimit.statusFlags, - STATUS_FLAG_FAULT, false); - bitstring_set_bit(&data.notificationParams.floatingLimit.statusFlags, - STATUS_FLAG_OVERRIDDEN, false); - bitstring_set_bit(&data.notificationParams.floatingLimit.statusFlags, - STATUS_FLAG_OUT_OF_SERVICE, false); - - memset(buffer, 0, MAX_APDU); - inLen = event_notify_encode_service_request(&buffer[0], &data); - - memset(&data2, 0, sizeof(data2)); - data2.messageText = &messageText2; - outLen = event_notify_decode_service_request(&buffer[0], inLen, &data2); - - ct_test(pTest, inLen == outLen); - testBaseEventState(pTest); - - ct_test(pTest, - data.notificationParams.floatingLimit.referenceValue == - data2.notificationParams.floatingLimit.referenceValue); - - ct_test(pTest, - data.notificationParams.floatingLimit.setPointValue == - data2.notificationParams.floatingLimit.setPointValue); - - ct_test(pTest, - data.notificationParams.floatingLimit.errorLimit == - data2.notificationParams.floatingLimit.errorLimit); - ct_test(pTest, - bitstring_same(&data.notificationParams.floatingLimit.statusFlags, - &data2.notificationParams.floatingLimit.statusFlags)); - - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /* - ** Event Type = EVENT_OUT_OF_RANGE - */ - data.eventType = EVENT_OUT_OF_RANGE; - data.notificationParams.outOfRange.exceedingValue = 3.45f; - data.notificationParams.outOfRange.deadband = 2.34f; - data.notificationParams.outOfRange.exceededLimit = 1.23f; - - bitstring_init(&data.notificationParams.outOfRange.statusFlags); - - bitstring_set_bit(&data.notificationParams.outOfRange.statusFlags, - STATUS_FLAG_IN_ALARM, true); - bitstring_set_bit(&data.notificationParams.outOfRange.statusFlags, - STATUS_FLAG_FAULT, false); - bitstring_set_bit(&data.notificationParams.outOfRange.statusFlags, - STATUS_FLAG_OVERRIDDEN, false); - bitstring_set_bit(&data.notificationParams.outOfRange.statusFlags, - STATUS_FLAG_OUT_OF_SERVICE, false); - - memset(buffer, 0, MAX_APDU); - inLen = event_notify_encode_service_request(&buffer[0], &data); - - memset(&data2, 0, sizeof(data2)); - data2.messageText = &messageText2; - outLen = event_notify_decode_service_request(&buffer[0], inLen, &data2); - - ct_test(pTest, inLen == outLen); - testBaseEventState(pTest); - - ct_test(pTest, - data.notificationParams.outOfRange.deadband == - data2.notificationParams.outOfRange.deadband); - - ct_test(pTest, - data.notificationParams.outOfRange.exceededLimit == - data2.notificationParams.outOfRange.exceededLimit); - - ct_test(pTest, - data.notificationParams.outOfRange.exceedingValue == - data2.notificationParams.outOfRange.exceedingValue); - ct_test(pTest, - bitstring_same(&data.notificationParams.outOfRange.statusFlags, - &data2.notificationParams.outOfRange.statusFlags)); - - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /* - ** Event Type = EVENT_CHANGE_OF_LIFE_SAFETY - */ - data.eventType = EVENT_CHANGE_OF_LIFE_SAFETY; - data.notificationParams.changeOfLifeSafety.newState = - LIFE_SAFETY_STATE_ALARM; - data.notificationParams.changeOfLifeSafety.newMode = LIFE_SAFETY_MODE_ARMED; - data.notificationParams.changeOfLifeSafety.operationExpected = - LIFE_SAFETY_OP_RESET; - - bitstring_init(&data.notificationParams.changeOfLifeSafety.statusFlags); - - bitstring_set_bit(&data.notificationParams.changeOfLifeSafety.statusFlags, - STATUS_FLAG_IN_ALARM, true); - bitstring_set_bit(&data.notificationParams.changeOfLifeSafety.statusFlags, - STATUS_FLAG_FAULT, false); - bitstring_set_bit(&data.notificationParams.changeOfLifeSafety.statusFlags, - STATUS_FLAG_OVERRIDDEN, false); - bitstring_set_bit(&data.notificationParams.changeOfLifeSafety.statusFlags, - STATUS_FLAG_OUT_OF_SERVICE, false); - - memset(buffer, 0, MAX_APDU); - inLen = event_notify_encode_service_request(&buffer[0], &data); - - memset(&data2, 0, sizeof(data2)); - data2.messageText = &messageText2; - outLen = event_notify_decode_service_request(&buffer[0], inLen, &data2); - - ct_test(pTest, inLen == outLen); - testBaseEventState(pTest); - - ct_test(pTest, - data.notificationParams.changeOfLifeSafety.newMode == - data2.notificationParams.changeOfLifeSafety.newMode); - - ct_test(pTest, - data.notificationParams.changeOfLifeSafety.newState == - data2.notificationParams.changeOfLifeSafety.newState); - - ct_test(pTest, - data.notificationParams.changeOfLifeSafety.operationExpected == - data2.notificationParams.changeOfLifeSafety.operationExpected); - - ct_test(pTest, - bitstring_same(&data.notificationParams.changeOfLifeSafety.statusFlags, - &data2.notificationParams.changeOfLifeSafety.statusFlags)); - - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /* - ** Event Type = EVENT_UNSIGNED_RANGE - */ - data.eventType = EVENT_UNSIGNED_RANGE; - data.notificationParams.unsignedRange.exceedingValue = 1234; - data.notificationParams.unsignedRange.exceededLimit = 2345; - - bitstring_init(&data.notificationParams.unsignedRange.statusFlags); - - bitstring_set_bit(&data.notificationParams.unsignedRange.statusFlags, - STATUS_FLAG_IN_ALARM, true); - bitstring_set_bit(&data.notificationParams.unsignedRange.statusFlags, - STATUS_FLAG_FAULT, false); - bitstring_set_bit(&data.notificationParams.unsignedRange.statusFlags, - STATUS_FLAG_OVERRIDDEN, false); - bitstring_set_bit(&data.notificationParams.unsignedRange.statusFlags, - STATUS_FLAG_OUT_OF_SERVICE, false); - - memset(buffer, 0, MAX_APDU); - inLen = event_notify_encode_service_request(&buffer[0], &data); - - memset(&data2, 0, sizeof(data2)); - data2.messageText = &messageText2; - outLen = event_notify_decode_service_request(&buffer[0], inLen, &data2); - - ct_test(pTest, inLen == outLen); - testBaseEventState(pTest); - - ct_test(pTest, - data.notificationParams.unsignedRange.exceedingValue == - data2.notificationParams.unsignedRange.exceedingValue); - - ct_test(pTest, - data.notificationParams.unsignedRange.exceededLimit == - data2.notificationParams.unsignedRange.exceededLimit); - - ct_test(pTest, - bitstring_same(&data.notificationParams.unsignedRange.statusFlags, - &data2.notificationParams.unsignedRange.statusFlags)); - - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /* - ** Event Type = EVENT_BUFFER_READY - */ - data.eventType = EVENT_BUFFER_READY; - data.notificationParams.bufferReady.previousNotification = 1234; - data.notificationParams.bufferReady.currentNotification = 2345; - data.notificationParams.bufferReady.bufferProperty.deviceIdentifier.type = - OBJECT_DEVICE; - data.notificationParams.bufferReady.bufferProperty.deviceIdentifier - .instance = 500; - data.notificationParams.bufferReady.bufferProperty.objectIdentifier.type = - OBJECT_ANALOG_INPUT; - data.notificationParams.bufferReady.bufferProperty.objectIdentifier - .instance = 100; - data.notificationParams.bufferReady.bufferProperty.propertyIdentifier = - PROP_PRESENT_VALUE; - data.notificationParams.bufferReady.bufferProperty.arrayIndex = 0; - - memset(buffer, 0, MAX_APDU); - inLen = event_notify_encode_service_request(&buffer[0], &data); - - memset(&data2, 0, sizeof(data2)); - data2.messageText = &messageText2; - outLen = event_notify_decode_service_request(&buffer[0], inLen, &data2); - - ct_test(pTest, inLen == outLen); - testBaseEventState(pTest); - - ct_test(pTest, - data.notificationParams.bufferReady.previousNotification == - data2.notificationParams.bufferReady.previousNotification); - - ct_test(pTest, - data.notificationParams.bufferReady.currentNotification == - data2.notificationParams.bufferReady.currentNotification); - - ct_test(pTest, - data.notificationParams.bufferReady.bufferProperty.deviceIdentifier - .type == - data2.notificationParams.bufferReady.bufferProperty.deviceIdentifier - .type); - - ct_test(pTest, - data.notificationParams.bufferReady.bufferProperty.deviceIdentifier - .instance == - data2.notificationParams.bufferReady.bufferProperty.deviceIdentifier - .instance); - - ct_test(pTest, - data.notificationParams.bufferReady.bufferProperty.objectIdentifier - .instance == - data2.notificationParams.bufferReady.bufferProperty.objectIdentifier - .instance); - - ct_test(pTest, - data.notificationParams.bufferReady.bufferProperty.objectIdentifier - .type == - data2.notificationParams.bufferReady.bufferProperty.objectIdentifier - .type); - - ct_test(pTest, - data.notificationParams.bufferReady.bufferProperty.propertyIdentifier == - data2.notificationParams.bufferReady.bufferProperty - .propertyIdentifier); - - ct_test(pTest, - data.notificationParams.bufferReady.bufferProperty.arrayIndex == - data2.notificationParams.bufferReady.bufferProperty.arrayIndex); - - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /* - ** Event Type = EVENT_ACCESS_EVENT - */ - - // OPTIONAL authenticationFactor omitted - data.eventType = EVENT_ACCESS_EVENT; - data.notificationParams.accessEvent.accessEvent = - ACCESS_EVENT_LOCKED_BY_HIGHER_AUTHORITY; - data.notificationParams.accessEvent.accessEventTag = 7; - data.notificationParams.accessEvent.accessEventTime.tag = - TIME_STAMP_SEQUENCE; - data.notificationParams.accessEvent.accessEventTime.value.sequenceNum = 17; - data.notificationParams.accessEvent.accessCredential. - deviceIdentifier.instance = 1234; - data.notificationParams.accessEvent.accessCredential. - deviceIdentifier.type = OBJECT_DEVICE; - data.notificationParams.accessEvent.accessCredential. - objectIdentifier.instance = 17; - data.notificationParams.accessEvent.accessCredential. - objectIdentifier.type = OBJECT_ACCESS_POINT; - data.notificationParams.accessEvent.authenticationFactor.format_type = AUTHENTICATION_FACTOR_MAX; // omit authenticationFactor - - bitstring_init(&data.notificationParams.accessEvent.statusFlags); - bitstring_set_bit(&data.notificationParams.accessEvent.statusFlags, - STATUS_FLAG_IN_ALARM, true); - bitstring_set_bit(&data.notificationParams.accessEvent.statusFlags, - STATUS_FLAG_FAULT, false); - bitstring_set_bit(&data.notificationParams.accessEvent.statusFlags, - STATUS_FLAG_OVERRIDDEN, false); - bitstring_set_bit(&data.notificationParams.accessEvent.statusFlags, - STATUS_FLAG_OUT_OF_SERVICE, false); - - memset(buffer, 0, MAX_APDU); - inLen = event_notify_encode_service_request(&buffer[0], &data); - - memset(&data2, 0, sizeof(data2)); - data2.messageText = &messageText2; - outLen = event_notify_decode_service_request(&buffer[0], inLen, &data2); - - ct_test(pTest, inLen == outLen); - testBaseEventState(pTest); - - ct_test(pTest, - data.notificationParams.accessEvent.accessEvent == - data2.notificationParams.accessEvent.accessEvent); - - ct_test(pTest, - bitstring_same(&data.notificationParams.accessEvent.statusFlags, - &data2.notificationParams.accessEvent.statusFlags)); - - ct_test(pTest, - data.notificationParams.accessEvent.accessEventTag == - data2.notificationParams.accessEvent.accessEventTag); - - ct_test(pTest, - data.notificationParams.accessEvent.accessEventTime.tag == - data2.notificationParams.accessEvent.accessEventTime.tag); - - ct_test(pTest, - data.notificationParams.accessEvent.accessEventTime. - value.sequenceNum == - data2.notificationParams.accessEvent.accessEventTime. - value.sequenceNum); - - ct_test(pTest, - data.notificationParams.accessEvent.accessCredential. - deviceIdentifier.instance == - data2.notificationParams.accessEvent.accessCredential. - deviceIdentifier.instance); - - ct_test(pTest, - data.notificationParams.accessEvent.accessCredential. - deviceIdentifier.type == - data2.notificationParams.accessEvent.accessCredential. - deviceIdentifier.type); - - ct_test(pTest, - data.notificationParams.accessEvent.accessCredential. - objectIdentifier.instance == - data2.notificationParams.accessEvent.accessCredential. - objectIdentifier.instance); - - ct_test(pTest, - data.notificationParams.accessEvent.accessCredential. - objectIdentifier.type == - data2.notificationParams.accessEvent.accessCredential. - objectIdentifier.type); - - // OPTIONAL authenticationFactor included - data.eventType = EVENT_ACCESS_EVENT; - data.notificationParams.accessEvent.accessEvent = - ACCESS_EVENT_LOCKED_BY_HIGHER_AUTHORITY; - data.notificationParams.accessEvent.accessEventTag = 7; - data.notificationParams.accessEvent.accessEventTime.tag = - TIME_STAMP_SEQUENCE; - data.notificationParams.accessEvent.accessEventTime.value.sequenceNum = 17; - data.notificationParams.accessEvent.accessCredential. - deviceIdentifier.instance = 1234; - data.notificationParams.accessEvent.accessCredential. - deviceIdentifier.type = OBJECT_DEVICE; - data.notificationParams.accessEvent.accessCredential. - objectIdentifier.instance = 17; - data.notificationParams.accessEvent.accessCredential. - objectIdentifier.type = OBJECT_ACCESS_POINT; - data.notificationParams.accessEvent.authenticationFactor.format_type = - AUTHENTICATION_FACTOR_SIMPLE_NUMBER16; - data.notificationParams.accessEvent.authenticationFactor.format_class = - 215; - uint8_t octetstringValue[2] = { 0x00, 0x10 }; - - octetstring_init(&data.notificationParams.accessEvent. - authenticationFactor.value, octetstringValue, 2); - - bitstring_init(&data.notificationParams.accessEvent.statusFlags); - bitstring_set_bit(&data.notificationParams.accessEvent.statusFlags, - STATUS_FLAG_IN_ALARM, true); - bitstring_set_bit(&data.notificationParams.accessEvent.statusFlags, - STATUS_FLAG_FAULT, false); - bitstring_set_bit(&data.notificationParams.accessEvent.statusFlags, - STATUS_FLAG_OVERRIDDEN, false); - bitstring_set_bit(&data.notificationParams.accessEvent.statusFlags, - STATUS_FLAG_OUT_OF_SERVICE, false); - - memset(buffer, 0, MAX_APDU); - inLen = event_notify_encode_service_request(&buffer[0], &data); - - memset(&data2, 0, sizeof(data2)); - data2.messageText = &messageText2; - outLen = event_notify_decode_service_request(&buffer[0], inLen, &data2); - - ct_test(pTest, inLen == outLen); - testBaseEventState(pTest); - - ct_test(pTest, - data.notificationParams.accessEvent.accessEvent == - data2.notificationParams.accessEvent.accessEvent); - - ct_test(pTest, - bitstring_same(&data.notificationParams.accessEvent.statusFlags, - &data2.notificationParams.accessEvent.statusFlags)); - - ct_test(pTest, - data.notificationParams.accessEvent.accessEventTag == - data2.notificationParams.accessEvent.accessEventTag); - - ct_test(pTest, - data.notificationParams.accessEvent.accessEventTime.tag == - data2.notificationParams.accessEvent.accessEventTime.tag); - - ct_test(pTest, - data.notificationParams.accessEvent.accessEventTime. - value.sequenceNum == - data2.notificationParams.accessEvent.accessEventTime. - value.sequenceNum); - - ct_test(pTest, - data.notificationParams.accessEvent.accessCredential. - deviceIdentifier.instance == - data2.notificationParams.accessEvent.accessCredential. - deviceIdentifier.instance); - - ct_test(pTest, - data.notificationParams.accessEvent.accessCredential. - deviceIdentifier.type == - data2.notificationParams.accessEvent.accessCredential. - deviceIdentifier.type); - - ct_test(pTest, - data.notificationParams.accessEvent.accessCredential. - objectIdentifier.instance == - data2.notificationParams.accessEvent.accessCredential. - objectIdentifier.instance); - - ct_test(pTest, - data.notificationParams.accessEvent.accessCredential. - objectIdentifier.type == - data2.notificationParams.accessEvent.accessCredential. - objectIdentifier.type); - - ct_test(pTest, - data.notificationParams.accessEvent.authenticationFactor.format_type == - data2.notificationParams.accessEvent.authenticationFactor.format_type); - - ct_test(pTest, - data.notificationParams.accessEvent. - authenticationFactor.format_class == - data2.notificationParams.accessEvent. - authenticationFactor.format_class); - - ct_test(pTest, - octetstring_value_same(&data.notificationParams. - accessEvent.authenticationFactor.value, - &data2.notificationParams.accessEvent.authenticationFactor.value)); -} - -#ifdef TEST_EVENT - -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet Event", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testEventEventState); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} - -#endif /* TEST_EVENT */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/abort.c b/src/bacnet/abort.c index d0151c7f..bb52e0c2 100644 --- a/src/bacnet/abort.c +++ b/src/bacnet/abort.c @@ -200,152 +200,3 @@ int abort_decode_service_request( return len; } #endif - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -/* decode the whole APDU - mainly used for unit testing */ -static int abort_decode_apdu(uint8_t *apdu, - unsigned apdu_len, - uint8_t *invoke_id, - uint8_t *abort_reason, - bool *server) -{ - int len = 0; - - if (!apdu) - return -1; - /* optional checking - most likely was already done prior to this call */ - if (apdu_len > 0) { - if ((apdu[0] & 0xF0) != PDU_TYPE_ABORT) - return -1; - if (apdu[0] & 1) - *server = true; - else - *server = false; - if (apdu_len > 1) { - len = abort_decode_service_request( - &apdu[1], apdu_len - 1, invoke_id, abort_reason); - } - } - - return len; -} - -static void testAbortAPDU( - Test *pTest, uint8_t invoke_id, uint8_t abort_reason, bool server) -{ - uint8_t apdu[480] = { 0 }; - int len = 0; - int apdu_len = 0; - uint8_t test_invoke_id = 0; - uint8_t test_abort_reason = 0; - bool test_server = false; - - len = abort_encode_apdu(&apdu[0], invoke_id, abort_reason, server); - apdu_len = len; - ct_test(pTest, len != 0); - len = abort_decode_apdu( - &apdu[0], apdu_len, &test_invoke_id, &test_abort_reason, &test_server); - ct_test(pTest, len != -1); - ct_test(pTest, test_invoke_id == invoke_id); - ct_test(pTest, test_abort_reason == abort_reason); - ct_test(pTest, test_server == server); - - return; -} - -static void testAbortEncodeDecode(Test *pTest) -{ - uint8_t apdu[480] = { 0 }; - int len = 0; - int apdu_len = 0; - uint8_t invoke_id = 0; - uint8_t test_invoke_id = 0; - uint8_t abort_reason = 0; - uint8_t test_abort_reason = 0; - bool server = false; - bool test_server = false; - - len = abort_encode_apdu(&apdu[0], invoke_id, abort_reason, server); - ct_test(pTest, len != 0); - apdu_len = len; - len = abort_decode_apdu( - &apdu[0], apdu_len, &test_invoke_id, &test_abort_reason, &test_server); - ct_test(pTest, len != -1); - ct_test(pTest, test_invoke_id == invoke_id); - ct_test(pTest, test_abort_reason == abort_reason); - ct_test(pTest, test_server == server); - - /* change type to get negative response */ - apdu[0] = PDU_TYPE_REJECT; - len = abort_decode_apdu( - &apdu[0], apdu_len, &test_invoke_id, &test_abort_reason, &test_server); - ct_test(pTest, len == -1); - - /* test NULL APDU */ - len = abort_decode_apdu( - NULL, apdu_len, &test_invoke_id, &test_abort_reason, &test_server); - ct_test(pTest, len == -1); - - /* force a zero length */ - len = abort_decode_apdu( - &apdu[0], 0, &test_invoke_id, &test_abort_reason, &test_server); - ct_test(pTest, len == 0); - - /* check them all... */ - for (invoke_id = 0; invoke_id < 255; invoke_id++) { - for (abort_reason = 0; abort_reason < 255; abort_reason++) { - testAbortAPDU(pTest, invoke_id, abort_reason, false); - testAbortAPDU(pTest, invoke_id, abort_reason, true); - } - } -} - -static void testAbortError(Test *pTest) -{ - int i; - BACNET_ERROR_CODE error_code; - BACNET_ABORT_REASON abort_code; - BACNET_ABORT_REASON test_abort_code; - - for (i = 0; i < MAX_BACNET_ABORT_REASON; i++) { - abort_code = (BACNET_ABORT_REASON)i; - error_code = abort_convert_to_error_code(abort_code); - test_abort_code = abort_convert_error_code(error_code); - if (test_abort_code != abort_code) { - printf("Abort: result=%u abort-code=%u\n", test_abort_code, - abort_code); - } - ct_test(pTest, test_abort_code == abort_code); - } -} - -void testAbort(Test *pTest) -{ - testAbortEncodeDecode(pTest); - testAbortError(pTest); -} - -#ifdef TEST_ABORT -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet Abort", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testAbort); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_ABORT */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/abort.h b/src/bacnet/abort.h index a7550d07..2c9c411d 100644 --- a/src/bacnet/abort.h +++ b/src/bacnet/abort.h @@ -54,13 +54,6 @@ extern "C" { uint8_t * invoke_id, uint8_t * abort_reason); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void testAbort( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/alarm_ack.c b/src/bacnet/alarm_ack.c index bf76a8ca..b5eed9dd 100644 --- a/src/bacnet/alarm_ack.c +++ b/src/bacnet/alarm_ack.c @@ -173,101 +173,3 @@ int alarm_ack_decode_service_request( return len; } - -#ifdef BAC_TEST - -#include -#include -#include "ctest.h" - -void testAlarmAck(Test *pTest) -{ - BACNET_ALARM_ACK_DATA testAlarmAckIn; - BACNET_ALARM_ACK_DATA testAlarmAckOut; - - uint8_t buffer[MAX_APDU]; - int inLen; - int outLen; - - testAlarmAckIn.ackProcessIdentifier = 0x1234; - characterstring_init_ansi(&testAlarmAckIn.ackSource, "This is a test"); - testAlarmAckIn.ackTimeStamp.tag = TIME_STAMP_SEQUENCE; - testAlarmAckIn.ackTimeStamp.value.sequenceNum = 0x4331; - testAlarmAckIn.eventObjectIdentifier.instance = 567; - testAlarmAckIn.eventObjectIdentifier.type = OBJECT_DEVICE; - testAlarmAckIn.eventTimeStamp.tag = TIME_STAMP_TIME; - testAlarmAckIn.eventTimeStamp.value.time.hour = 10; - testAlarmAckIn.eventTimeStamp.value.time.min = 11; - testAlarmAckIn.eventTimeStamp.value.time.sec = 12; - testAlarmAckIn.eventTimeStamp.value.time.hundredths = 14; - testAlarmAckIn.eventStateAcked = EVENT_STATE_OFFNORMAL; - - memset(&testAlarmAckOut, 0, sizeof(testAlarmAckOut)); - - inLen = alarm_ack_encode_service_request(buffer, &testAlarmAckIn); - outLen = alarm_ack_decode_service_request(buffer, inLen, &testAlarmAckOut); - - ct_test(pTest, inLen == outLen); - - ct_test(pTest, - testAlarmAckIn.ackProcessIdentifier == - testAlarmAckOut.ackProcessIdentifier); - - ct_test(pTest, - testAlarmAckIn.ackTimeStamp.tag == testAlarmAckOut.ackTimeStamp.tag); - ct_test(pTest, - testAlarmAckIn.ackTimeStamp.value.sequenceNum == - testAlarmAckOut.ackTimeStamp.value.sequenceNum); - - ct_test(pTest, - testAlarmAckIn.ackProcessIdentifier == - testAlarmAckOut.ackProcessIdentifier); - - ct_test(pTest, - testAlarmAckIn.eventObjectIdentifier.instance == - testAlarmAckOut.eventObjectIdentifier.instance); - ct_test(pTest, - testAlarmAckIn.eventObjectIdentifier.type == - testAlarmAckOut.eventObjectIdentifier.type); - - ct_test(pTest, - testAlarmAckIn.eventTimeStamp.tag == - testAlarmAckOut.eventTimeStamp.tag); - ct_test(pTest, - testAlarmAckIn.eventTimeStamp.value.time.hour == - testAlarmAckOut.eventTimeStamp.value.time.hour); - ct_test(pTest, - testAlarmAckIn.eventTimeStamp.value.time.min == - testAlarmAckOut.eventTimeStamp.value.time.min); - ct_test(pTest, - testAlarmAckIn.eventTimeStamp.value.time.sec == - testAlarmAckOut.eventTimeStamp.value.time.sec); - ct_test(pTest, - testAlarmAckIn.eventTimeStamp.value.time.hundredths == - testAlarmAckOut.eventTimeStamp.value.time.hundredths); - - ct_test(pTest, - testAlarmAckIn.eventStateAcked == testAlarmAckOut.eventStateAcked); -} - -#ifdef TEST_ALARM_ACK -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet Alarm Ack", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testAlarmAck); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} - -#endif /* TEST_ALARM_ACK */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/arf.c b/src/bacnet/arf.c index ccf1c5b0..f06411b8 100644 --- a/src/bacnet/arf.c +++ b/src/bacnet/arf.c @@ -377,193 +377,3 @@ int arf_ack_decode_apdu(uint8_t *apdu, return len; } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -void testAtomicReadFileAckAccess( - Test *pTest, BACNET_ATOMIC_READ_FILE_DATA *data) -{ - BACNET_ATOMIC_READ_FILE_DATA test_data = { 0 }; - uint8_t apdu[480] = { 0 }; - int len = 0; - int apdu_len = 0; - uint8_t invoke_id = 128; - uint8_t test_invoke_id = 0; - unsigned int i = 0; - - len = arf_ack_encode_apdu(&apdu[0], invoke_id, data); - ct_test(pTest, len != 0); - apdu_len = len; - - len = arf_ack_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &test_data); - ct_test(pTest, len != -1); - ct_test(pTest, test_data.endOfFile == data->endOfFile); - ct_test(pTest, test_data.access == data->access); - if (test_data.access == FILE_STREAM_ACCESS) { - ct_test(pTest, - test_data.type.stream.fileStartPosition == - data->type.stream.fileStartPosition); - ct_test(pTest, - octetstring_length(&test_data.fileData[0]) == - octetstring_length(&data->fileData[0])); - ct_test(pTest, - memcmp(octetstring_value(&test_data.fileData[0]), - octetstring_value(&data->fileData[0]), - octetstring_length(&test_data.fileData[0])) == 0); - } else if (test_data.access == FILE_RECORD_ACCESS) { - ct_test(pTest, - test_data.type.record.fileStartRecord == - data->type.record.fileStartRecord); - ct_test(pTest, - test_data.type.record.RecordCount == data->type.record.RecordCount); - for (i = 0; i < data->type.record.RecordCount; i++) { - ct_test(pTest, - octetstring_length(&test_data.fileData[i]) == - octetstring_length(&data->fileData[i])); - ct_test(pTest, - memcmp(octetstring_value(&test_data.fileData[i]), - octetstring_value(&data->fileData[i]), - octetstring_length(&test_data.fileData[i])) == 0); - } - } -} - -void testAtomicReadFileAck(Test *pTest) -{ - BACNET_ATOMIC_READ_FILE_DATA data = { 0 }; - uint8_t test_octet_string[32] = "Joshua-Mary-Anna-Christopher"; - unsigned int i = 0; - - data.endOfFile = true; - data.access = FILE_STREAM_ACCESS; - data.type.stream.fileStartPosition = 0; - octetstring_init( - &data.fileData[0], test_octet_string, sizeof(test_octet_string)); - testAtomicReadFileAckAccess(pTest, &data); - - data.endOfFile = false; - data.access = FILE_RECORD_ACCESS; - data.type.record.fileStartRecord = 1; - data.type.record.RecordCount = BACNET_READ_FILE_RECORD_COUNT; - for (i = 0; i < data.type.record.RecordCount; i++) { - octetstring_init( - &data.fileData[i], test_octet_string, sizeof(test_octet_string)); - } - testAtomicReadFileAckAccess(pTest, &data); - - return; -} - -void testAtomicReadFileAccess(Test *pTest, BACNET_ATOMIC_READ_FILE_DATA *data) -{ - BACNET_ATOMIC_READ_FILE_DATA test_data = { 0 }; - uint8_t apdu[480] = { 0 }; - int len = 0; - int apdu_len = 0; - uint8_t invoke_id = 128; - uint8_t test_invoke_id = 0; - - len = arf_encode_apdu(&apdu[0], invoke_id, data); - ct_test(pTest, len != 0); - apdu_len = len; - - len = arf_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &test_data); - ct_test(pTest, len != -1); - ct_test(pTest, test_data.object_type == data->object_type); - ct_test(pTest, test_data.object_instance == data->object_instance); - ct_test(pTest, test_data.access == data->access); - if (test_data.access == FILE_STREAM_ACCESS) { - ct_test(pTest, - test_data.type.stream.fileStartPosition == - data->type.stream.fileStartPosition); - ct_test(pTest, - test_data.type.stream.requestedOctetCount == - data->type.stream.requestedOctetCount); - } else if (test_data.access == FILE_RECORD_ACCESS) { - ct_test(pTest, - test_data.type.record.fileStartRecord == - data->type.record.fileStartRecord); - ct_test(pTest, - test_data.type.record.RecordCount == data->type.record.RecordCount); - } -} - -void testAtomicReadFile(Test *pTest) -{ - BACNET_ATOMIC_READ_FILE_DATA data = { 0 }; - - data.object_type = OBJECT_FILE; - data.object_instance = 1; - data.access = FILE_STREAM_ACCESS; - data.type.stream.fileStartPosition = 0; - data.type.stream.requestedOctetCount = 128; - testAtomicReadFileAccess(pTest, &data); - - data.object_type = OBJECT_FILE; - data.object_instance = 2; - data.access = FILE_RECORD_ACCESS; - data.type.record.fileStartRecord = 1; - data.type.record.RecordCount = 2; - testAtomicReadFileAccess(pTest, &data); - - return; -} - -void testAtomicReadFileMalformed(Test *pTest) -{ - uint8_t apdu[480] = { 0 }; - /* payloads with malformation */ - uint8_t payload_1[] = { 0xc4, 0x02, 0x80, 0x00, 0x00, 0x0e, 0x35, 0xff, - 0xdf, 0x62, 0xee, 0x00, 0x00, 0x22, 0x05, 0x84, 0x0f }; - uint8_t payload_2[] = { 0xc4, 0x02, 0x80, 0x00, 0x00, 0x0e, 0x31, 0x00, - 0x25, 0xff, 0xd4, 0x9e, 0xbf, 0x79, 0x05, 0x84 }; - BACNET_ATOMIC_READ_FILE_DATA data = { 0 }; - int len = 0; - uint8_t test_invoke_id = 0; - - len = arf_decode_apdu(NULL, sizeof(apdu), &test_invoke_id, &data); - ct_test(pTest, len == BACNET_STATUS_ERROR); - len = arf_decode_apdu(apdu, sizeof(apdu), &test_invoke_id, &data); - ct_test(pTest, len == BACNET_STATUS_ERROR); - apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST; - apdu[1] = 0; - apdu[2] = 1; - len = arf_decode_apdu(apdu, sizeof(apdu), &test_invoke_id, &data); - ct_test(pTest, len == BACNET_STATUS_ERROR); - apdu[2] = SERVICE_CONFIRMED_ATOMIC_READ_FILE; - len = arf_decode_apdu(apdu, sizeof(apdu), &test_invoke_id, &data); - ct_test(pTest, len == BACNET_STATUS_ERROR); - /* malformed payload testing */ - len = arf_decode_service_request(payload_1, sizeof(payload_1), &data); - ct_test(pTest, len == BACNET_STATUS_ERROR); - len = arf_decode_service_request(payload_2, sizeof(payload_2), &data); - ct_test(pTest, len == BACNET_STATUS_ERROR); -} - -#ifdef TEST_ATOMIC_READ_FILE -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet AtomicReadFile", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testAtomicReadFile); - assert(rc); - rc = ct_addTestFunction(pTest, testAtomicReadFileAck); - assert(rc); - rc = ct_addTestFunction(pTest, testAtomicReadFileMalformed); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_xxx */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/arf.h b/src/bacnet/arf.h index d9d42ac4..9655fc50 100644 --- a/src/bacnet/arf.h +++ b/src/bacnet/arf.h @@ -103,17 +103,6 @@ extern "C" { uint8_t * invoke_id, BACNET_ATOMIC_READ_FILE_DATA * data); -#ifdef BAC_TEST -#include "ctest.h" - - BACNET_STACK_EXPORT - void test_AtomicReadFile( - Test * pTest); - BACNET_STACK_EXPORT - void test_AtomicReadFileAck( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/awf.c b/src/bacnet/awf.c index f281c3a8..fcf809d3 100644 --- a/src/bacnet/awf.c +++ b/src/bacnet/awf.c @@ -311,180 +311,3 @@ int awf_ack_decode_apdu(uint8_t *apdu, return len; } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -void testAtomicWriteFileAccess(Test *pTest, BACNET_ATOMIC_WRITE_FILE_DATA *data) -{ - BACNET_ATOMIC_WRITE_FILE_DATA test_data = { 0 }; - uint8_t apdu[480] = { 0 }; - int len = 0; - int apdu_len = 0; - uint8_t invoke_id = 128; - uint8_t test_invoke_id = 0; - - len = awf_encode_apdu(&apdu[0], invoke_id, data); - ct_test(pTest, len != 0); - apdu_len = len; - - len = awf_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &test_data); - ct_test(pTest, len != BACNET_STATUS_ERROR); - ct_test(pTest, test_data.object_type == data->object_type); - ct_test(pTest, test_data.object_instance == data->object_instance); - ct_test(pTest, test_data.access == data->access); - if (test_data.access == FILE_STREAM_ACCESS) { - ct_test(pTest, - test_data.type.stream.fileStartPosition == - data->type.stream.fileStartPosition); - } else if (test_data.access == FILE_RECORD_ACCESS) { - ct_test(pTest, - test_data.type.record.fileStartRecord == - data->type.record.fileStartRecord); - ct_test(pTest, - test_data.type.record.returnedRecordCount == - data->type.record.returnedRecordCount); - } - ct_test(pTest, - octetstring_length(&test_data.fileData[0]) == - octetstring_length(&data->fileData[0])); - ct_test(pTest, - memcmp(octetstring_value(&test_data.fileData[0]), - octetstring_value(&data->fileData[0]), - octetstring_length(&test_data.fileData[0])) == 0); -} - -void testAtomicWriteFile(Test *pTest) -{ - BACNET_ATOMIC_WRITE_FILE_DATA data = { 0 }; - uint8_t test_octet_string[32] = "Joshua-Mary-Anna-Christopher"; - - data.object_type = OBJECT_FILE; - data.object_instance = 1; - data.access = FILE_STREAM_ACCESS; - data.type.stream.fileStartPosition = 0; - octetstring_init( - &data.fileData[0], test_octet_string, sizeof(test_octet_string)); - testAtomicWriteFileAccess(pTest, &data); - - data.object_type = OBJECT_FILE; - data.object_instance = 1; - data.access = FILE_RECORD_ACCESS; - data.type.record.fileStartRecord = 1; - data.type.record.returnedRecordCount = 1; - octetstring_init( - &data.fileData[0], test_octet_string, sizeof(test_octet_string)); - testAtomicWriteFileAccess(pTest, &data); - - return; -} - -void testAtomicWriteFileAckAccess( - Test *pTest, BACNET_ATOMIC_WRITE_FILE_DATA *data) -{ - BACNET_ATOMIC_WRITE_FILE_DATA test_data = { 0 }; - uint8_t apdu[480] = { 0 }; - int len = 0; - int apdu_len = 0; - uint8_t invoke_id = 128; - uint8_t test_invoke_id = 0; - - len = awf_encode_apdu(&apdu[0], invoke_id, data); - ct_test(pTest, len != 0); - apdu_len = len; - - len = awf_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &test_data); - if (len == BACNET_STATUS_ERROR) { - if (data->access == FILE_STREAM_ACCESS) { - printf("testing FILE_STREAM_ACCESS failed decode\n"); - } else if (data->access == FILE_RECORD_ACCESS) { - printf("testing FILE_RECORD_ACCESS failed decode\n"); - } - } - ct_test(pTest, len != BACNET_STATUS_ERROR); - ct_test(pTest, test_data.access == data->access); - if (test_data.access == FILE_STREAM_ACCESS) { - ct_test(pTest, - test_data.type.stream.fileStartPosition == - data->type.stream.fileStartPosition); - } else if (test_data.access == FILE_RECORD_ACCESS) { - ct_test(pTest, - test_data.type.record.fileStartRecord == - data->type.record.fileStartRecord); - } -} - -void testAtomicWriteFileAck(Test *pTest) -{ - BACNET_ATOMIC_WRITE_FILE_DATA data = { 0 }; - - data.access = FILE_STREAM_ACCESS; - data.type.stream.fileStartPosition = 42; - testAtomicWriteFileAckAccess(pTest, &data); - - data.access = FILE_RECORD_ACCESS; - data.type.record.fileStartRecord = 54; - testAtomicWriteFileAckAccess(pTest, &data); - - return; -} - -void testAtomicWriteFileMalformed(Test *pTest) -{ - uint8_t apdu[480] = { 0 }; - /* payloads with malformation */ - uint8_t payload_1[] = { 0xc4, 0x02, 0x80, 0x00, 0x00, 0x0e, 0x35, 0xff, - 0x5e, 0xd5, 0xc0, 0x85, 0x0a, 0x62, 0x64, 0x0a, 0x0f }; - uint8_t payload_2[] = { 0xc4, 0x02, 0x80, 0x00, 0x00, 0x0e, 0x35, 0xff, - 0xc4, 0x4d, 0x92, 0xd9, 0x0a, 0x62, 0x64, 0x0a, 0x0f, 0x0f, 0x0f, 0x0f, - 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, - 0x0f }; - BACNET_ATOMIC_WRITE_FILE_DATA data = { 0 }; - int len = 0; - uint8_t test_invoke_id = 0; - - len = awf_decode_apdu(NULL, sizeof(apdu), &test_invoke_id, &data); - ct_test(pTest, len == BACNET_STATUS_ERROR); - len = awf_decode_apdu(apdu, sizeof(apdu), &test_invoke_id, &data); - ct_test(pTest, len == BACNET_STATUS_ERROR); - apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST; - apdu[1] = 0; - apdu[2] = 1; - len = awf_decode_apdu(apdu, sizeof(apdu), &test_invoke_id, &data); - ct_test(pTest, len == BACNET_STATUS_ERROR); - apdu[2] = SERVICE_CONFIRMED_ATOMIC_WRITE_FILE; - len = awf_decode_apdu(apdu, sizeof(apdu), &test_invoke_id, &data); - ct_test(pTest, len == BACNET_STATUS_ERROR); - /* malformed payload testing */ - len = awf_decode_service_request(payload_1, sizeof(payload_1), &data); - ct_test(pTest, len == BACNET_STATUS_ERROR); - len = awf_decode_service_request(payload_2, sizeof(payload_2), &data); - ct_test(pTest, len == BACNET_STATUS_ERROR); -} - -#ifdef TEST_ATOMIC_WRITE_FILE -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet AtomicWriteFile", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testAtomicWriteFile); - assert(rc); - rc = ct_addTestFunction(pTest, testAtomicWriteFileAck); - assert(rc); - rc = ct_addTestFunction(pTest, testAtomicWriteFileMalformed); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_WRITE_PROPERTY */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/awf.h b/src/bacnet/awf.h index b2a10cf1..82048746 100644 --- a/src/bacnet/awf.h +++ b/src/bacnet/awf.h @@ -97,17 +97,6 @@ extern "C" { uint8_t * invoke_id, BACNET_ATOMIC_WRITE_FILE_DATA * data); -#ifdef BAC_TEST -#include "ctest.h" - - BACNET_STACK_EXPORT - void test_AtomicWriteFile( - Test * pTest); - BACNET_STACK_EXPORT - void test_AtomicWriteFileAck( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/bacapp.h b/src/bacnet/bacapp.h index 86f3330c..56282a62 100644 --- a/src/bacnet/bacapp.h +++ b/src/bacnet/bacapp.h @@ -229,7 +229,7 @@ extern "C" { BACNET_PROPERTY_ID property); #ifndef BACAPP_PRINT_ENABLED -#if PRINT_ENABLED || defined BAC_TEST +#if PRINT_ENABLED #define BACAPP_PRINT_ENABLED #endif #endif diff --git a/src/bacnet/bacdcode.c b/src/bacnet/bacdcode.c index d4a620e9..a1476780 100644 --- a/src/bacnet/bacdcode.c +++ b/src/bacnet/bacdcode.c @@ -2749,1312 +2749,3 @@ int decode_context_bacnet_address( } return len; } - -/* end of decoding_encoding.c */ -#ifdef BAC_TEST -#include -#include -#include -#include "ctest.h" - -static int get_apdu_len(bool extended_tag, uint32_t value) -{ - int test_len = 1; - - if (extended_tag) { - test_len++; - } - if (value <= 4) { - test_len += 0; /* do nothing... */ - } else if (value <= 253) { - test_len += 1; - } else if (value <= 65535) { - test_len += 3; - } else { - test_len += 5; - } - - return test_len; -} - -static void print_apdu(uint8_t *pBlock, uint32_t num) -{ - size_t lines = 0; /* number of lines to print */ - size_t line = 0; /* line of text counter */ - size_t last_line = 0; /* line on which the last text resided */ - unsigned long count = 0; /* address to print */ - unsigned int i = 0; /* counter */ - - if (pBlock && num) { - /* how many lines to print? */ - num--; /* adjust */ - lines = (num / 16) + 1; - last_line = num % 16; - - /* create the line */ - for (line = 0; line < lines; line++) { - /* start with the address */ - printf("%08lX: ", count); - /* hex representation */ - for (i = 0; i < 16; i++) { - if (((line == (lines - 1)) && (i <= last_line)) || - (line != (lines - 1))) { - printf("%02X ", (unsigned)(0x00FF & pBlock[i])); - } else { - printf("-- "); - } - } - printf(" "); - /* print the characters if valid */ - for (i = 0; i < 16; i++) { - if (((line == (lines - 1)) && (i <= last_line)) || - (line != (lines - 1))) { - if (isprint(pBlock[i])) { - printf("%c", pBlock[i]); - } else { - printf("."); - } - } else { - printf("."); - } - } - printf("\r\n"); - pBlock += 16; - count += 16; - } - } - - return; -} - -static void testBACDCodeTags(Test *pTest) -{ - uint8_t apdu[MAX_APDU] = { 0 }; - uint8_t tag_number = 0, test_tag_number = 0; - int len = 0, test_len = 0; - uint32_t value = 0, test_value = 0; - - for (tag_number = 0;; tag_number++) { - len = encode_opening_tag(&apdu[0], tag_number); - test_len = get_apdu_len(IS_EXTENDED_TAG_NUMBER(apdu[0]), 0); - ct_test(pTest, len == test_len); - len = decode_tag_number_and_value(&apdu[0], &test_tag_number, &value); - ct_test(pTest, value == 0); - ct_test(pTest, len == test_len); - ct_test(pTest, tag_number == test_tag_number); - ct_test(pTest, IS_OPENING_TAG(apdu[0]) == true); - ct_test(pTest, IS_CLOSING_TAG(apdu[0]) == false); - len = encode_closing_tag(&apdu[0], tag_number); - ct_test(pTest, len == test_len); - len = decode_tag_number_and_value(&apdu[0], &test_tag_number, &value); - ct_test(pTest, len == test_len); - ct_test(pTest, value == 0); - ct_test(pTest, tag_number == test_tag_number); - ct_test(pTest, IS_OPENING_TAG(apdu[0]) == false); - ct_test(pTest, IS_CLOSING_TAG(apdu[0]) == true); - /* test the len-value-type portion */ - for (value = 1;; value = value << 1) { - len = encode_tag(&apdu[0], tag_number, false, value); - len = decode_tag_number_and_value( - &apdu[0], &test_tag_number, &test_value); - ct_test(pTest, tag_number == test_tag_number); - ct_test(pTest, value == test_value); - test_len = get_apdu_len(IS_EXTENDED_TAG_NUMBER(apdu[0]), value); - ct_test(pTest, len == test_len); - /* stop at the the last value */ - if (value & BIT(31L)) { - break; - } - } - /* stop after the last tag number */ - if (tag_number == 255) { - break; - } - } - - return; -} - -static void testBACDCodeEnumerated(Test *pTest) -{ - uint8_t array[5] = { 0 }; - uint8_t encoded_array[5] = { 0 }; - uint32_t value = 1; - uint32_t decoded_value = 0; - int i = 0, apdu_len = 0; - int len = 0; - uint8_t apdu[MAX_APDU] = { 0 }; - uint8_t tag_number = 0; - uint32_t len_value = 0; - - for (i = 0; i < 31; i++) { - apdu_len = encode_application_enumerated(&array[0], value); - len = decode_tag_number_and_value(&array[0], &tag_number, &len_value); - len += decode_enumerated(&array[len], len_value, &decoded_value); - ct_test(pTest, decoded_value == value); - ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_ENUMERATED); - ct_test(pTest, len == apdu_len); - /* encode back the value */ - encode_application_enumerated(&encoded_array[0], decoded_value); - ct_test( - pTest, memcmp(&array[0], &encoded_array[0], sizeof(array)) == 0); - /* an enumerated will take up to 4 octects */ - /* plus a one octet for the tag */ - apdu_len = encode_application_enumerated(&apdu[0], value); - len = decode_tag_number_and_value(&apdu[0], &tag_number, NULL); - ct_test(pTest, len == 1); - ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_ENUMERATED); - ct_test(pTest, IS_CONTEXT_SPECIFIC(apdu[0]) == false); - /* context specific encoding */ - apdu_len = encode_context_enumerated(&apdu[0], 3, value); - ct_test(pTest, IS_CONTEXT_SPECIFIC(apdu[0]) == true); - len = decode_tag_number_and_value(&apdu[0], &tag_number, NULL); - ct_test(pTest, len == 1); - ct_test(pTest, tag_number == 3); - /* test the interesting values */ - value = value << 1; - } - - return; -} - -static void testBACDCodeReal(Test *pTest) -{ - uint8_t real_array[4] = { 0 }; - uint8_t encoded_array[4] = { 0 }; - float value = 42.123F; - float decoded_value = 0.0F; - uint8_t apdu[MAX_APDU] = { 0 }; - int len = 0, apdu_len = 0; - uint8_t tag_number = 0; - uint32_t long_value = 0; - - encode_bacnet_real(value, &real_array[0]); - decode_real(&real_array[0], &decoded_value); - ct_test(pTest, decoded_value == value); - encode_bacnet_real(value, &encoded_array[0]); - ct_test( - pTest, memcmp(&real_array, &encoded_array, sizeof(real_array)) == 0); - - /* a real will take up 4 octects plus a one octet tag */ - apdu_len = encode_application_real(&apdu[0], value); - ct_test(pTest, apdu_len == 5); - /* len tells us how many octets were used for encoding the value */ - len = decode_tag_number_and_value(&apdu[0], &tag_number, &long_value); - ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_REAL); - ct_test(pTest, IS_CONTEXT_SPECIFIC(apdu[0]) == false); - ct_test(pTest, len == 1); - ct_test(pTest, long_value == 4); - decode_real(&apdu[len], &decoded_value); - ct_test(pTest, decoded_value == value); - - return; -} - -static void testBACDCodeDouble(Test *pTest) -{ - uint8_t double_array[8] = { 0 }; - uint8_t encoded_array[8] = { 0 }; - double value = 42.123; - double decoded_value = 0.0; - uint8_t apdu[MAX_APDU] = { 0 }; - int len = 0, apdu_len = 0; - uint8_t tag_number = 0; - uint32_t long_value = 0; - - encode_bacnet_double(value, &double_array[0]); - decode_double(&double_array[0], &decoded_value); - ct_test(pTest, decoded_value == value); - encode_bacnet_double(value, &encoded_array[0]); - ct_test(pTest, - memcmp(&double_array, &encoded_array, sizeof(double_array)) == 0); - - /* a real will take up 4 octects plus a one octet tag */ - apdu_len = encode_application_double(&apdu[0], value); - ct_test(pTest, apdu_len == 10); - /* len tells us how many octets were used for encoding the value */ - len = decode_tag_number_and_value(&apdu[0], &tag_number, &long_value); - ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_DOUBLE); - ct_test(pTest, IS_CONTEXT_SPECIFIC(apdu[0]) == false); - ct_test(pTest, len == 2); - ct_test(pTest, long_value == 8); - decode_double(&apdu[len], &decoded_value); - ct_test(pTest, decoded_value == value); - - return; -} - -static void testBACDCodeUnsignedValue( - Test *pTest, BACNET_UNSIGNED_INTEGER value) -{ - uint8_t array[5] = { 0 }; - uint8_t encoded_array[5] = { 0 }; - BACNET_UNSIGNED_INTEGER decoded_value = 0; - int len; - uint8_t apdu[MAX_APDU] = { 0 }; - uint8_t tag_number = 0; - uint32_t len_value = 0; - - len_value = encode_application_unsigned(&array[0], value); - len = decode_tag_number_and_value(&array[0], &tag_number, &len_value); - len = decode_unsigned(&array[len], len_value, &decoded_value); - ct_test(pTest, decoded_value == value); - if (decoded_value != value) { - printf("value=%lu decoded_value=%lu\n", (unsigned long)value, - (unsigned long)decoded_value); - print_apdu(&array[0], sizeof(array)); - } - encode_application_unsigned(&encoded_array[0], decoded_value); - ct_test(pTest, memcmp(&array[0], &encoded_array[0], sizeof(array)) == 0); - /* an unsigned will take up to 4 octects */ - /* plus a one octet for the tag */ - encode_application_unsigned(&apdu[0], value); - /* apdu_len varies... */ - len = decode_tag_number_and_value(&apdu[0], &tag_number, NULL); - ct_test(pTest, len == 1); - ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_UNSIGNED_INT); - ct_test(pTest, IS_CONTEXT_SPECIFIC(apdu[0]) == false); -} - -static void testBACDCodeUnsigned(Test *pTest) -{ -#ifdef UINT64_MAX - const unsigned max_bits = 64; -#else - const unsigned max_bits = 32; -#endif - uint32_t value = 1; - int i; - - for (i = 0; i < max_bits; i++) { - testBACDCodeUnsignedValue(pTest, value - 1); - testBACDCodeUnsignedValue(pTest, value); - testBACDCodeUnsignedValue(pTest, value + 1); - value |= (value << 1); - } - - return; -} - -static void testBACnetUnsigned(Test *pTest) -{ - uint8_t apdu[32] = { 0 }; - BACNET_UNSIGNED_INTEGER value = 0, test_value = 0; - int len = 0, test_len = 0; - - for (value = 0; value == BACNET_UNSIGNED_INTEGER_MAX; - value = (value << 8) | 0xff) { - len = encode_bacnet_unsigned(&apdu[0], value); - test_len = decode_unsigned(&apdu[0], len, &test_value); - ct_test(pTest, len == test_len); - ct_test(pTest, value == test_value); - } -} - -static void testBACDCodeSignedValue(Test *pTest, int32_t value) -{ - uint8_t array[5] = { 0 }; - uint8_t encoded_array[5] = { 0 }; - int32_t decoded_value = 0; - int len = 0; - uint8_t apdu[MAX_APDU] = { 0 }; - uint8_t tag_number = 0; - uint32_t len_value = 0; - int diff = 0; - - len = encode_application_signed(&array[0], value); - len = decode_tag_number_and_value(&array[0], &tag_number, &len_value); - len = decode_signed(&array[len], len_value, &decoded_value); - ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_SIGNED_INT); - ct_test(pTest, decoded_value == value); - if (decoded_value != value) { - printf( - "value=%ld decoded_value=%ld\n", (long)value, (long)decoded_value); - print_apdu(&array[0], sizeof(array)); - } - encode_application_signed(&encoded_array[0], decoded_value); - diff = memcmp(&array[0], &encoded_array[0], sizeof(array)); - ct_test(pTest, diff == 0); - if (diff) { - printf( - "value=%ld decoded_value=%ld\n", (long)value, (long)decoded_value); - print_apdu(&array[0], sizeof(array)); - print_apdu(&encoded_array[0], sizeof(array)); - } - /* a signed int will take up to 4 octects */ - /* plus a one octet for the tag */ - encode_application_signed(&apdu[0], value); - len = decode_tag_number_and_value(&apdu[0], &tag_number, NULL); - ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_SIGNED_INT); - ct_test(pTest, IS_CONTEXT_SPECIFIC(apdu[0]) == false); - - return; -} - -static void testBACDCodeSigned(Test *pTest) -{ - int value = 1; - int i = 0; - - for (i = 0; i < 32; i++) { - testBACDCodeSignedValue(pTest, value - 1); - testBACDCodeSignedValue(pTest, value); - testBACDCodeSignedValue(pTest, value + 1); - value = value << 1; - } - - testBACDCodeSignedValue(pTest, -1); - value = -2; - for (i = 0; i < 32; i++) { - testBACDCodeSignedValue(pTest, value - 1); - testBACDCodeSignedValue(pTest, value); - testBACDCodeSignedValue(pTest, value + 1); - value = value << 1; - } - - return; -} - -static void testBACnetSigned(Test *pTest) -{ - uint8_t apdu[32] = { 0 }; - int32_t value = 0, test_value = 0; - int len = 0, test_len = 0; - - for (value = -2147483647; value < 0; value += 127) { - len = encode_bacnet_signed(&apdu[0], value); - test_len = decode_signed(&apdu[0], len, &test_value); - ct_test(pTest, len == test_len); - ct_test(pTest, value == test_value); - } - for (value = 2147483647; value > 0; value -= 127) { - len = encode_bacnet_signed(&apdu[0], value); - test_len = decode_signed(&apdu[0], len, &test_value); - ct_test(pTest, len == test_len); - ct_test(pTest, value == test_value); - } -} - -static void testBACDCodeOctetString(Test *pTest) -{ - uint8_t array[MAX_APDU] = { 0 }; - uint8_t encoded_array[MAX_APDU] = { 0 }; - BACNET_OCTET_STRING octet_string; - BACNET_OCTET_STRING test_octet_string; - uint8_t test_value[MAX_APDU] = { "" }; - int i; /* for loop counter */ - int apdu_len; - int len; - uint8_t tag_number = 0; - uint32_t len_value = 0; - bool status = false; - int diff = 0; /* for memcmp */ - - status = octetstring_init(&octet_string, NULL, 0); - ct_test(pTest, status == true); - apdu_len = encode_application_octet_string(&array[0], &octet_string); - len = decode_tag_number_and_value(&array[0], &tag_number, &len_value); - ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OCTET_STRING); - len += decode_octet_string(&array[len], len_value, &test_octet_string); - ct_test(pTest, apdu_len == len); - diff = memcmp(octetstring_value(&octet_string), &test_value[0], - octetstring_length(&octet_string)); - ct_test(pTest, diff == 0); - - for (i = 0; i < (MAX_APDU - 6); i++) { - test_value[i] = '0' + (i % 10); - status = octetstring_init(&octet_string, test_value, i); - ct_test(pTest, status == true); - apdu_len = - encode_application_octet_string(&encoded_array[0], &octet_string); - len = decode_tag_number_and_value( - &encoded_array[0], &tag_number, &len_value); - ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OCTET_STRING); - len += decode_octet_string( - &encoded_array[len], len_value, &test_octet_string); - if (apdu_len != len) { - printf("test octet string=#%d\n", i); - } - ct_test(pTest, apdu_len == len); - diff = memcmp(octetstring_value(&octet_string), &test_value[0], - octetstring_length(&octet_string)); - if (diff) { - printf("test octet string=#%d\n", i); - } - ct_test(pTest, diff == 0); - } - - return; -} - -static void testBACDCodeCharacterString(Test *pTest) -{ - uint8_t array[MAX_APDU] = { 0 }; - uint8_t encoded_array[MAX_APDU] = { 0 }; - BACNET_CHARACTER_STRING char_string; - BACNET_CHARACTER_STRING test_char_string; - char test_value[MAX_APDU] = { "" }; - int i; /* for loop counter */ - int apdu_len; - int len; - uint8_t tag_number = 0; - uint32_t len_value = 0; - int diff = 0; /* for comparison */ - bool status = false; - - status = characterstring_init(&char_string, CHARACTER_ANSI_X34, NULL, 0); - ct_test(pTest, status == true); - apdu_len = encode_application_character_string(&array[0], &char_string); - len = decode_tag_number_and_value(&array[0], &tag_number, &len_value); - ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_CHARACTER_STRING); - len += decode_character_string(&array[len], len_value, &test_char_string); - ct_test(pTest, apdu_len == len); - diff = memcmp(characterstring_value(&char_string), &test_value[0], - characterstring_length(&char_string)); - ct_test(pTest, diff == 0); - for (i = 0; i < MAX_CHARACTER_STRING_BYTES - 1; i++) { - test_value[i] = 'S'; - test_value[i + 1] = '\0'; - status = characterstring_init_ansi(&char_string, test_value); - ct_test(pTest, status == true); - apdu_len = encode_application_character_string( - &encoded_array[0], &char_string); - len = decode_tag_number_and_value( - &encoded_array[0], &tag_number, &len_value); - ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_CHARACTER_STRING); - len += decode_character_string( - &encoded_array[len], len_value, &test_char_string); - if (apdu_len != len) { - printf("test string=#%d apdu_len=%d len=%d\n", i, apdu_len, len); - } - ct_test(pTest, apdu_len == len); - diff = memcmp(characterstring_value(&char_string), &test_value[0], - characterstring_length(&char_string)); - if (diff) { - printf("test string=#%d\n", i); - } - ct_test(pTest, diff == 0); - } - - return; -} - -static void testBACDCodeObject(Test *pTest) -{ - uint8_t object_array[32] = { 0 }; - uint8_t encoded_array[32] = { 0 }; - BACNET_OBJECT_TYPE type = OBJECT_BINARY_INPUT; - BACNET_OBJECT_TYPE decoded_type = OBJECT_ANALOG_OUTPUT; - uint32_t instance = 123; - uint32_t decoded_instance = 0; - int len = 0; - uint8_t tag_number = 0; - - encode_bacnet_object_id(&encoded_array[0], type, instance); - decode_object_id(&encoded_array[0], &decoded_type, &decoded_instance); - ct_test(pTest, decoded_type == type); - ct_test(pTest, decoded_instance == instance); - encode_bacnet_object_id(&object_array[0], type, instance); - ct_test(pTest, - memcmp(&object_array[0], &encoded_array[0], sizeof(object_array)) == 0); - for (type = 0; type < 1024; type++) { - for (instance = 0; instance <= BACNET_MAX_INSTANCE; instance += 1024) { - /* test application encoded */ - len = - encode_application_object_id(&encoded_array[0], type, instance); - ct_test(pTest, len > 0); - bacnet_object_id_application_decode( - &encoded_array[0], len, &decoded_type, &decoded_instance); - ct_test(pTest, decoded_type == type); - ct_test(pTest, decoded_instance == instance); - /* test context encoded */ - tag_number = 99; - len = encode_context_object_id( - &encoded_array[0], tag_number, type, instance); - ct_test(pTest, len > 0); - len = decode_context_object_id(&encoded_array[0], tag_number, - &decoded_type, &decoded_instance); - ct_test(pTest, len > 0); - ct_test(pTest, decoded_type == type); - ct_test(pTest, decoded_instance == instance); - tag_number = 100; - len = decode_context_object_id(&encoded_array[0], tag_number, - &decoded_type, &decoded_instance); - ct_test(pTest, len == BACNET_STATUS_ERROR); - } - } - /* test context encoded */ - tag_number = 1; - type = OBJECT_BINARY_INPUT; - instance = 123; - for (tag_number = 0; tag_number < 254; tag_number++) { - len = encode_context_object_id( - &encoded_array[0], tag_number, type, instance); - ct_test(pTest, len > 0); - len = decode_context_object_id( - &encoded_array[0], tag_number, &decoded_type, &decoded_instance); - ct_test(pTest, len > 0); - ct_test(pTest, decoded_type == type); - ct_test(pTest, decoded_instance == instance); - len = decode_context_object_id( - &encoded_array[0], 254, &decoded_type, &decoded_instance); - ct_test(pTest, len == BACNET_STATUS_ERROR); - } - - return; -} - -static void testBACDCodeMaxSegsApdu(Test *pTest) -{ - int max_segs[8] = { 0, 2, 4, 8, 16, 32, 64, 65 }; - int max_apdu[6] = { 50, 128, 206, 480, 1024, 1476 }; - int i = 0; - int j = 0; - uint8_t octet = 0; - - /* test */ - for (i = 0; i < 8; i++) { - for (j = 0; j < 6; j++) { - octet = encode_max_segs_max_apdu(max_segs[i], max_apdu[j]); - ct_test(pTest, max_segs[i] == decode_max_segs(octet)); - ct_test(pTest, max_apdu[j] == decode_max_apdu(octet)); - } - } -} - -static void testBACDCodeBitString(Test *pTest) -{ - uint8_t bit = 0; - BACNET_BIT_STRING bit_string; - BACNET_BIT_STRING decoded_bit_string; - uint8_t apdu[MAX_APDU] = { 0 }; - uint32_t len_value = 0; - uint8_t tag_number = 0; - int len = 0; - - bitstring_init(&bit_string); - /* verify initialization */ - ct_test(pTest, bitstring_bits_used(&bit_string) == 0); - for (bit = 0; bit < (MAX_BITSTRING_BYTES * 8); bit++) { - ct_test(pTest, bitstring_bit(&bit_string, bit) == false); - } - /* test encode/decode -- true */ - for (bit = 0; bit < (MAX_BITSTRING_BYTES * 8); bit++) { - bitstring_set_bit(&bit_string, bit, true); - ct_test(pTest, bitstring_bits_used(&bit_string) == (bit + 1)); - ct_test(pTest, bitstring_bit(&bit_string, bit) == true); - /* encode */ - len = encode_application_bitstring(&apdu[0], &bit_string); - /* decode */ - len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); - ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_BIT_STRING); - len += decode_bitstring(&apdu[len], len_value, &decoded_bit_string); - ct_test(pTest, bitstring_bits_used(&decoded_bit_string) == (bit + 1)); - ct_test(pTest, bitstring_bit(&decoded_bit_string, bit) == true); - } - /* test encode/decode -- false */ - bitstring_init(&bit_string); - for (bit = 0; bit < (MAX_BITSTRING_BYTES * 8); bit++) { - bitstring_set_bit(&bit_string, bit, false); - ct_test(pTest, bitstring_bits_used(&bit_string) == (bit + 1)); - ct_test(pTest, bitstring_bit(&bit_string, bit) == false); - /* encode */ - len = encode_application_bitstring(&apdu[0], &bit_string); - /* decode */ - len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); - ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_BIT_STRING); - len += decode_bitstring(&apdu[len], len_value, &decoded_bit_string); - ct_test(pTest, bitstring_bits_used(&decoded_bit_string) == (bit + 1)); - ct_test(pTest, bitstring_bit(&decoded_bit_string, bit) == false); - } -} - -static void testUnsignedContextDecodes(Test *pTest) -{ - uint8_t apdu[MAX_APDU] = { 0 }; - int inLen = 0; - int outLen = 0; - int outLen2 = 0; - uint8_t large_context_tag = 0xfe; - BACNET_UNSIGNED_INTEGER in = 0xdeadbeef; - BACNET_UNSIGNED_INTEGER out = 0; - - /* error, stack-overflow check */ - outLen2 = decode_context_unsigned(apdu, 9, &out); - -#ifdef UINT64_MAX - /* 64 bit number */ - in = 0xdeadbeefdeadbeef; - inLen = encode_context_unsigned(apdu, 10, in); - outLen = decode_context_unsigned(apdu, 10, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - - inLen = encode_context_unsigned(apdu, large_context_tag, in); - outLen = decode_context_unsigned(apdu, large_context_tag, &out); - outLen2 = decode_context_unsigned(apdu, large_context_tag - 1, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); -#endif - - /* 32 bit number */ - in = 0xdeadbeef; - inLen = encode_context_unsigned(apdu, 10, in); - outLen = decode_context_unsigned(apdu, 10, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - - inLen = encode_context_unsigned(apdu, large_context_tag, in); - outLen = decode_context_unsigned(apdu, large_context_tag, &out); - outLen2 = decode_context_unsigned(apdu, large_context_tag - 1, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - - /* 16 bit number */ - in = 0xdead; - inLen = encode_context_unsigned(apdu, 10, in); - outLen = decode_context_unsigned(apdu, 10, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - - inLen = encode_context_unsigned(apdu, large_context_tag, in); - outLen = decode_context_unsigned(apdu, large_context_tag, &out); - outLen2 = decode_context_unsigned(apdu, large_context_tag - 1, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - /* 8 bit number */ - in = 0xde; - inLen = encode_context_unsigned(apdu, 10, in); - outLen = decode_context_unsigned(apdu, 10, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - - inLen = encode_context_unsigned(apdu, large_context_tag, in); - outLen = decode_context_unsigned(apdu, large_context_tag, &out); - outLen2 = decode_context_unsigned(apdu, large_context_tag - 1, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - /* 4 bit number */ - in = 0xd; - inLen = encode_context_unsigned(apdu, 10, in); - outLen = decode_context_unsigned(apdu, 10, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - - inLen = encode_context_unsigned(apdu, large_context_tag, in); - outLen = decode_context_unsigned(apdu, large_context_tag, &out); - outLen2 = decode_context_unsigned(apdu, large_context_tag - 1, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - /* 2 bit number */ - in = 0x2; - inLen = encode_context_unsigned(apdu, 10, in); - outLen = decode_context_unsigned(apdu, 10, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - - inLen = encode_context_unsigned(apdu, large_context_tag, in); - outLen = decode_context_unsigned(apdu, large_context_tag, &out); - outLen2 = decode_context_unsigned(apdu, large_context_tag - 1, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); -} - -static void testSignedContextDecodes(Test *pTest) -{ - uint8_t apdu[MAX_APDU]; - int inLen; - int outLen; - int outLen2; - uint8_t large_context_tag = 0xfe; - - /* 32 bit number */ - int32_t in = 0xdeadbeef; - int32_t out; - - outLen2 = decode_context_signed(apdu, 9, &out); - - in = 0xdeadbeef; - inLen = encode_context_signed(apdu, 10, in); - outLen = decode_context_signed(apdu, 10, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - - inLen = encode_context_signed(apdu, large_context_tag, in); - outLen = decode_context_signed(apdu, large_context_tag, &out); - outLen2 = decode_context_signed(apdu, large_context_tag - 1, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - - /* 16 bit number */ - in = 0xdead; - inLen = encode_context_signed(apdu, 10, in); - outLen = decode_context_signed(apdu, 10, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - - inLen = encode_context_signed(apdu, large_context_tag, in); - outLen = decode_context_signed(apdu, large_context_tag, &out); - outLen2 = decode_context_signed(apdu, large_context_tag - 1, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - - /* 8 bit number */ - in = 0xde; - inLen = encode_context_signed(apdu, 10, in); - outLen = decode_context_signed(apdu, 10, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - - inLen = encode_context_signed(apdu, large_context_tag, in); - outLen = decode_context_signed(apdu, large_context_tag, &out); - outLen2 = decode_context_signed(apdu, large_context_tag - 1, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - - /* 4 bit number */ - in = 0xd; - inLen = encode_context_signed(apdu, 10, in); - outLen = decode_context_signed(apdu, 10, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - - inLen = encode_context_signed(apdu, large_context_tag, in); - outLen = decode_context_signed(apdu, large_context_tag, &out); - outLen2 = decode_context_signed(apdu, large_context_tag - 1, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - - /* 2 bit number */ - in = 0x2; - inLen = encode_context_signed(apdu, 10, in); - outLen = decode_context_signed(apdu, 10, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - - inLen = encode_context_signed(apdu, large_context_tag, in); - outLen = decode_context_signed(apdu, large_context_tag, &out); - outLen2 = decode_context_signed(apdu, large_context_tag - 1, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); -} - -static void testEnumeratedContextDecodes(Test *pTest) -{ - uint8_t apdu[MAX_APDU] = { 0 }; - int inLen = 0; - int outLen = 0; - int outLen2 = 0; - uint8_t large_context_tag = 0xfe; - - /* 32 bit number */ - uint32_t in = 0xdeadbeef; - uint32_t out = 0; - - outLen2 = decode_context_enumerated(apdu, 9, &out); - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - - in = 0xdeadbeef; - inLen = encode_context_enumerated(apdu, 10, in); - outLen = decode_context_enumerated(apdu, 10, &out); - outLen2 = decode_context_enumerated(apdu, 9, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - - inLen = encode_context_enumerated(apdu, large_context_tag, in); - outLen = decode_context_enumerated(apdu, large_context_tag, &out); - outLen2 = decode_context_enumerated(apdu, large_context_tag - 1, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - - /* 16 bit number */ - in = 0xdead; - inLen = encode_context_enumerated(apdu, 10, in); - outLen = decode_context_enumerated(apdu, 10, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - - inLen = encode_context_enumerated(apdu, large_context_tag, in); - outLen = decode_context_enumerated(apdu, large_context_tag, &out); - outLen2 = decode_context_enumerated(apdu, large_context_tag - 1, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - /* 8 bit number */ - in = 0xde; - inLen = encode_context_enumerated(apdu, 10, in); - outLen = decode_context_enumerated(apdu, 10, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - - inLen = encode_context_enumerated(apdu, large_context_tag, in); - outLen = decode_context_enumerated(apdu, large_context_tag, &out); - outLen2 = decode_context_enumerated(apdu, large_context_tag - 1, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - /* 4 bit number */ - in = 0xd; - inLen = encode_context_enumerated(apdu, 10, in); - outLen = decode_context_enumerated(apdu, 10, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - - inLen = encode_context_enumerated(apdu, large_context_tag, in); - outLen = decode_context_enumerated(apdu, large_context_tag, &out); - outLen2 = decode_context_enumerated(apdu, large_context_tag - 1, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - /* 2 bit number */ - in = 0x2; - inLen = encode_context_enumerated(apdu, 10, in); - outLen = decode_context_enumerated(apdu, 10, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - - inLen = encode_context_enumerated(apdu, large_context_tag, in); - outLen = decode_context_enumerated(apdu, large_context_tag, &out); - outLen2 = decode_context_enumerated(apdu, large_context_tag - 1, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); -} - -static void testFloatContextDecodes(Test *pTest) -{ - uint8_t apdu[MAX_APDU]; - int inLen; - int outLen; - int outLen2; - uint8_t large_context_tag = 0xfe; - - /* 32 bit number */ - float in; - float out; - - in = 0.1234f; - inLen = encode_context_real(apdu, 10, in); - outLen = decode_context_real(apdu, 10, &out); - outLen2 = decode_context_real(apdu, 9, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - - inLen = encode_context_real(apdu, large_context_tag, in); - outLen = decode_context_real(apdu, large_context_tag, &out); - outLen2 = decode_context_real(apdu, large_context_tag - 1, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - - in = 0.0f; - inLen = encode_context_real(apdu, 10, in); - outLen = decode_context_real(apdu, 10, &out); - outLen2 = decode_context_real(apdu, 9, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - - inLen = encode_context_real(apdu, large_context_tag, in); - outLen = decode_context_real(apdu, large_context_tag, &out); - outLen2 = decode_context_real(apdu, large_context_tag - 1, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); -} - -static void testDoubleContextDecodes(Test *pTest) -{ - uint8_t apdu[MAX_APDU]; - int inLen; - int outLen; - int outLen2; - uint8_t large_context_tag = 0xfe; - - /* 64 bit number */ - double in; - double out; - - in = 0.1234; - inLen = encode_context_double(apdu, 10, in); - outLen = decode_context_double(apdu, 10, &out); - outLen2 = decode_context_double(apdu, 9, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - - inLen = encode_context_double(apdu, large_context_tag, in); - outLen = decode_context_double(apdu, large_context_tag, &out); - outLen2 = decode_context_double(apdu, large_context_tag - 1, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - - in = 0.0; - inLen = encode_context_double(apdu, 10, in); - outLen = decode_context_double(apdu, 10, &out); - outLen2 = decode_context_double(apdu, 9, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - - inLen = encode_context_double(apdu, large_context_tag, in); - outLen = decode_context_double(apdu, large_context_tag, &out); - outLen2 = decode_context_double(apdu, large_context_tag - 1, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in == out); - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); -} - -static void testObjectIDContextDecodes(Test *pTest) -{ - uint8_t apdu[MAX_APDU]; - int inLen; - int outLen; - int outLen2; - uint8_t large_context_tag = 0xfe; - - /* 32 bit number */ - BACNET_OBJECT_TYPE in_type; - uint32_t in_id; - - BACNET_OBJECT_TYPE out_type; - uint32_t out_id; - - in_type = 0xde; - in_id = 0xbeef; - - inLen = encode_context_object_id(apdu, 10, in_type, in_id); - outLen = decode_context_object_id(apdu, 10, &out_type, &out_id); - outLen2 = decode_context_object_id(apdu, 9, &out_type, &out_id); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in_type == out_type); - ct_test(pTest, in_id == out_id); - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - - inLen = encode_context_object_id(apdu, large_context_tag, in_type, in_id); - outLen = - decode_context_object_id(apdu, large_context_tag, &out_type, &out_id); - outLen2 = decode_context_object_id( - apdu, large_context_tag - 1, &out_type, &out_id); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in_type == out_type); - ct_test(pTest, in_id == out_id); - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); -} - -static void testCharacterStringContextDecodes(Test *pTest) -{ - uint8_t apdu[MAX_APDU]; - int inLen; - int outLen; - int outLen2; - uint8_t large_context_tag = 0xfe; - - BACNET_CHARACTER_STRING in; - BACNET_CHARACTER_STRING out; - - characterstring_init_ansi(&in, "This is a test"); - - inLen = encode_context_character_string(apdu, 10, &in); - outLen = decode_context_character_string(apdu, 10, &out); - outLen2 = decode_context_character_string(apdu, 9, &out); - - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - ct_test(pTest, inLen == outLen); - ct_test(pTest, in.length == out.length); - ct_test(pTest, in.encoding == out.encoding); - ct_test(pTest, strcmp(in.value, out.value) == 0); - - inLen = encode_context_character_string(apdu, large_context_tag, &in); - outLen = decode_context_character_string(apdu, large_context_tag, &out); - outLen2 = - decode_context_character_string(apdu, large_context_tag - 1, &out); - - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - ct_test(pTest, inLen == outLen); - ct_test(pTest, in.length == out.length); - ct_test(pTest, in.encoding == out.encoding); - ct_test(pTest, strcmp(in.value, out.value) == 0); -} - -static void testBitStringContextDecodes(Test *pTest) -{ - uint8_t apdu[MAX_APDU]; - int inLen; - int outLen; - int outLen2; - uint8_t large_context_tag = 0xfe; - - BACNET_BIT_STRING in; - BACNET_BIT_STRING out; - - bitstring_init(&in); - bitstring_set_bit(&in, 1, true); - bitstring_set_bit(&in, 3, true); - bitstring_set_bit(&in, 6, true); - bitstring_set_bit(&in, 10, false); - bitstring_set_bit(&in, 11, true); - bitstring_set_bit(&in, 12, false); - - inLen = encode_context_bitstring(apdu, 10, &in); - outLen = decode_context_bitstring(apdu, 10, &out); - outLen2 = decode_context_bitstring(apdu, 9, &out); - - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - ct_test(pTest, inLen == outLen); - ct_test(pTest, in.bits_used == out.bits_used); - ct_test(pTest, memcmp(in.value, out.value, MAX_BITSTRING_BYTES) == 0); - - inLen = encode_context_bitstring(apdu, large_context_tag, &in); - outLen = decode_context_bitstring(apdu, large_context_tag, &out); - outLen2 = decode_context_bitstring(apdu, large_context_tag - 1, &out); - - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - ct_test(pTest, inLen == outLen); - ct_test(pTest, in.bits_used == out.bits_used); - ct_test(pTest, memcmp(in.value, out.value, MAX_BITSTRING_BYTES) == 0); -} - -static void testOctetStringContextDecodes(Test *pTest) -{ - uint8_t apdu[MAX_APDU]; - int inLen; - int outLen; - int outLen2; - uint8_t large_context_tag = 0xfe; - - BACNET_OCTET_STRING in; - BACNET_OCTET_STRING out; - - uint8_t initData[] = { 0xde, 0xad, 0xbe, 0xef }; - - octetstring_init(&in, initData, sizeof(initData)); - - inLen = encode_context_octet_string(apdu, 10, &in); - outLen = decode_context_octet_string(apdu, 10, &out); - outLen2 = decode_context_octet_string(apdu, 9, &out); - - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - ct_test(pTest, inLen == outLen); - ct_test(pTest, in.length == out.length); - ct_test(pTest, octetstring_value_same(&in, &out)); - - inLen = encode_context_octet_string(apdu, large_context_tag, &in); - outLen = decode_context_octet_string(apdu, large_context_tag, &out); - outLen2 = decode_context_octet_string(apdu, large_context_tag - 1, &out); - - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - ct_test(pTest, inLen == outLen); - ct_test(pTest, in.length == out.length); - ct_test(pTest, octetstring_value_same(&in, &out)); -} - -static void testTimeContextDecodes(Test *pTest) -{ - uint8_t apdu[MAX_APDU]; - int inLen; - int outLen; - int outLen2; - uint8_t large_context_tag = 0xfe; - - BACNET_TIME in; - BACNET_TIME out; - - in.hour = 10; - in.hundredths = 20; - in.min = 30; - in.sec = 40; - - inLen = encode_context_time(apdu, 10, &in); - outLen = decode_context_bacnet_time(apdu, 10, &out); - outLen2 = decode_context_bacnet_time(apdu, 9, &out); - - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - ct_test(pTest, inLen == outLen); - ct_test(pTest, in.hour == out.hour); - ct_test(pTest, in.hundredths == out.hundredths); - ct_test(pTest, in.min == out.min); - ct_test(pTest, in.sec == out.sec); - - inLen = encode_context_time(apdu, large_context_tag, &in); - outLen = decode_context_bacnet_time(apdu, large_context_tag, &out); - outLen2 = decode_context_bacnet_time(apdu, large_context_tag - 1, &out); - - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - ct_test(pTest, inLen == outLen); - ct_test(pTest, in.hour == out.hour); - ct_test(pTest, in.hundredths == out.hundredths); - ct_test(pTest, in.min == out.min); - ct_test(pTest, in.sec == out.sec); -} - -static void testDateContextDecodes(Test *pTest) -{ - uint8_t apdu[MAX_APDU]; - int inLen; - int outLen; - int outLen2; - uint8_t large_context_tag = 0xfe; - - BACNET_DATE in; - BACNET_DATE out; - - in.day = 3; - in.month = 10; - in.wday = 5; - in.year = 1945; - - inLen = encode_context_date(apdu, 10, &in); - outLen = decode_context_date(apdu, 10, &out); - outLen2 = decode_context_date(apdu, 9, &out); - - ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - ct_test(pTest, inLen == outLen); - ct_test(pTest, in.day == out.day); - ct_test(pTest, in.month == out.month); - ct_test(pTest, in.wday == out.wday); - ct_test(pTest, in.year == out.year); - - /* Test large tags */ - inLen = encode_context_date(apdu, large_context_tag, &in); - outLen = decode_context_date(apdu, large_context_tag, &out); - outLen2 = decode_context_date(apdu, large_context_tag - 1, &out); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, in.day == out.day); - ct_test(pTest, in.month == out.month); - ct_test(pTest, in.wday == out.wday); - ct_test(pTest, in.year == out.year); -} - -void test_BACDCode(Test *pTest) -{ - bool rc; - - /* add individual tests */ - rc = ct_addTestFunction(pTest, testBACDCodeTags); - assert(rc); - rc = ct_addTestFunction(pTest, testBACDCodeReal); - assert(rc); - rc = ct_addTestFunction(pTest, testBACDCodeUnsigned); - assert(rc); - rc = ct_addTestFunction(pTest, testBACnetUnsigned); - assert(rc); - rc = ct_addTestFunction(pTest, testBACDCodeSigned); - assert(rc); - rc = ct_addTestFunction(pTest, testBACnetSigned); - assert(rc); - rc = ct_addTestFunction(pTest, testBACDCodeEnumerated); - assert(rc); - rc = ct_addTestFunction(pTest, testBACDCodeOctetString); - assert(rc); - rc = ct_addTestFunction(pTest, testBACDCodeCharacterString); - assert(rc); - rc = ct_addTestFunction(pTest, testBACDCodeObject); - assert(rc); - rc = ct_addTestFunction(pTest, testBACDCodeMaxSegsApdu); - assert(rc); - rc = ct_addTestFunction(pTest, testBACDCodeBitString); - assert(rc); - rc = ct_addTestFunction(pTest, testUnsignedContextDecodes); - assert(rc); - rc = ct_addTestFunction(pTest, testSignedContextDecodes); - assert(rc); - rc = ct_addTestFunction(pTest, testEnumeratedContextDecodes); - assert(rc); - rc = ct_addTestFunction(pTest, testCharacterStringContextDecodes); - assert(rc); - rc = ct_addTestFunction(pTest, testFloatContextDecodes); - assert(rc); - rc = ct_addTestFunction(pTest, testDoubleContextDecodes); - assert(rc); - rc = ct_addTestFunction(pTest, testObjectIDContextDecodes); - assert(rc); - rc = ct_addTestFunction(pTest, testBitStringContextDecodes); - assert(rc); - rc = ct_addTestFunction(pTest, testTimeContextDecodes); - assert(rc); - rc = ct_addTestFunction(pTest, testDateContextDecodes); - assert(rc); - rc = ct_addTestFunction(pTest, testOctetStringContextDecodes); - assert(rc); - rc = ct_addTestFunction(pTest, testBACDCodeDouble); - assert(rc); -} - -#ifdef TEST_DECODE -int main(void) -{ - Test *pTest; - - pTest = ct_create("BACDCode", NULL); - test_BACDCode(pTest); - - /* configure output */ - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_DECODE */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/bacdcode.h b/src/bacnet/bacdcode.h index 24769cc1..0149897f 100644 --- a/src/bacnet/bacdcode.h +++ b/src/bacnet/bacdcode.h @@ -629,13 +629,6 @@ extern "C" { /* true if the tag is a closing tag */ #define IS_CLOSING_TAG(x) ((x & 0x07) == 7) -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void test_BACDCode( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/bacdevobjpropref.c b/src/bacnet/bacdevobjpropref.c index d023dca4..493e5e52 100644 --- a/src/bacnet/bacdevobjpropref.c +++ b/src/bacnet/bacdevobjpropref.c @@ -400,133 +400,3 @@ int bacapp_decode_context_device_obj_ref( } return len; } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" -static void testDevObjPropRef( - Test *pTest, BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE *inData) -{ - BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE outData; - uint8_t buffer[MAX_APDU] = { 0 }; - int inLen = 0; - int outLen = 0; - - /* encode */ - inLen = bacapp_encode_device_obj_property_ref(buffer, inData); - /* add a closing tag at the end of the buffer to verify proper handling - when that is encountered in real packets */ - encode_closing_tag(&buffer[inLen], 3); - /* decode */ - outLen = bacapp_decode_device_obj_property_ref(buffer, &outData); - ct_test(pTest, outLen == inLen); - ct_test(pTest, - inData->objectIdentifier.instance == outData.objectIdentifier.instance); - ct_test( - pTest, inData->objectIdentifier.type == outData.objectIdentifier.type); - ct_test(pTest, inData->propertyIdentifier == outData.propertyIdentifier); - if (inData->arrayIndex != BACNET_ARRAY_ALL) { - ct_test(pTest, inData->arrayIndex == outData.arrayIndex); - } else { - ct_test(pTest, outData.arrayIndex == BACNET_ARRAY_ALL); - } - if (inData->deviceIdentifier.type == OBJECT_DEVICE) { - ct_test(pTest, - inData->deviceIdentifier.instance == - outData.deviceIdentifier.instance); - ct_test(pTest, - inData->deviceIdentifier.type == outData.deviceIdentifier.type); - } else { - ct_test(pTest, outData.deviceIdentifier.instance == BACNET_NO_DEV_ID); - ct_test(pTest, outData.deviceIdentifier.type == BACNET_NO_DEV_TYPE); - } -} - -static void testDevIdPropRef(Test *pTest) -{ - BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE inData; - - /* everything encoded */ - inData.objectIdentifier.instance = 0x1234; - inData.objectIdentifier.type = 15; - inData.propertyIdentifier = 25; - inData.arrayIndex = 0x5678; - inData.deviceIdentifier.instance = 0x4343; - inData.deviceIdentifier.type = OBJECT_DEVICE; - testDevObjPropRef(pTest, &inData); - /* optional array */ - inData.objectIdentifier.instance = 0x1234; - inData.objectIdentifier.type = 15; - inData.propertyIdentifier = 25; - inData.arrayIndex = BACNET_ARRAY_ALL; - inData.deviceIdentifier.instance = 0x4343; - inData.deviceIdentifier.type = OBJECT_DEVICE; - testDevObjPropRef(pTest, &inData); - /* optional device ID */ - inData.objectIdentifier.instance = 0x1234; - inData.objectIdentifier.type = 15; - inData.propertyIdentifier = 25; - inData.arrayIndex = 1; - inData.deviceIdentifier.instance = 0; - inData.deviceIdentifier.type = BACNET_NO_DEV_TYPE; - testDevObjPropRef(pTest, &inData); - /* optional array + optional device ID */ - inData.objectIdentifier.instance = 0x1234; - inData.objectIdentifier.type = 15; - inData.propertyIdentifier = 25; - inData.arrayIndex = BACNET_ARRAY_ALL; - inData.deviceIdentifier.instance = 0; - inData.deviceIdentifier.type = BACNET_NO_DEV_TYPE; - testDevObjPropRef(pTest, &inData); -} - -static void testDevIdRef(Test *pTest) -{ - BACNET_DEVICE_OBJECT_REFERENCE inData; - BACNET_DEVICE_OBJECT_REFERENCE outData; - uint8_t buffer[MAX_APDU]; - int inLen; - int outLen; - - inData.deviceIdentifier.instance = 0x4343; - inData.deviceIdentifier.type = OBJECT_DEVICE; - inLen = bacapp_encode_device_obj_ref(buffer, &inData); - outLen = bacapp_decode_device_obj_ref(buffer, &outData); - ct_test(pTest, outLen == inLen); - ct_test(pTest, - inData.deviceIdentifier.instance == outData.deviceIdentifier.instance); - ct_test( - pTest, inData.deviceIdentifier.type == outData.deviceIdentifier.type); -} - -void testBACnetDeviceObjectPropertyReference(Test *pTest) -{ - bool rc; - - /* individual tests */ - rc = ct_addTestFunction(pTest, testDevIdPropRef); - assert(rc); - rc = ct_addTestFunction(pTest, testDevIdRef); - assert(rc); -} - -#ifdef TEST_DEV_ID_PROP_REF -#include -int main(void) -{ - Test *pTest; - - pTest = ct_create("BACnet Prop Ref", NULL); - testBACnetDeviceObjectPropertyReference(pTest); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} - -#endif /* TEST_DEV_ID_PROP_REF */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/bacdevobjpropref.h b/src/bacnet/bacdevobjpropref.h index 954c4176..24816db2 100644 --- a/src/bacnet/bacdevobjpropref.h +++ b/src/bacnet/bacdevobjpropref.h @@ -100,13 +100,6 @@ extern "C" { uint8_t tag_number, BACNET_DEVICE_OBJECT_REFERENCE * value); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void testBACnetDeviceObjectPropertyReference( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/bacerror.c b/src/bacnet/bacerror.c index 896eaa78..fe43fd6c 100644 --- a/src/bacnet/bacerror.c +++ b/src/bacnet/bacerror.c @@ -124,135 +124,3 @@ int bacerror_decode_service_request(uint8_t *apdu, return len; } #endif - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -/* decode the whole APDU - mainly used for unit testing */ -int bacerror_decode_apdu(uint8_t *apdu, - unsigned apdu_len, - uint8_t *invoke_id, - BACNET_CONFIRMED_SERVICE *service, - BACNET_ERROR_CLASS *error_class, - BACNET_ERROR_CODE *error_code) -{ - int len = 0; - - if (!apdu) - return -1; - /* optional checking - most likely was already done prior to this call */ - if (apdu_len) { - if (apdu[0] != PDU_TYPE_ERROR) - return -1; - if (apdu_len > 1) { - len = bacerror_decode_service_request(&apdu[1], apdu_len - 1, - invoke_id, service, error_class, error_code); - } - } - - return len; -} - -void testBACError(Test *pTest) -{ - uint8_t apdu[480] = { 0 }; - int len = 0; - int apdu_len = 0; - uint8_t invoke_id = 0; - BACNET_CONFIRMED_SERVICE service = 0; - BACNET_ERROR_CLASS error_class = 0; - BACNET_ERROR_CODE error_code = 0; - uint8_t test_invoke_id = 0; - BACNET_CONFIRMED_SERVICE test_service = 0; - BACNET_ERROR_CLASS test_error_class = 0; - BACNET_ERROR_CODE test_error_code = 0; - - len = bacerror_encode_apdu( - &apdu[0], invoke_id, service, error_class, error_code); - ct_test(pTest, len != 0); - apdu_len = len; - - len = bacerror_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, - &test_service, &test_error_class, &test_error_code); - ct_test(pTest, len != -1); - ct_test(pTest, test_invoke_id == invoke_id); - ct_test(pTest, test_service == service); - ct_test(pTest, test_error_class == error_class); - ct_test(pTest, test_error_code == error_code); - - /* change type to get negative response */ - apdu[0] = PDU_TYPE_ABORT; - len = bacerror_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, - &test_service, &test_error_class, &test_error_code); - ct_test(pTest, len == -1); - - /* test NULL APDU */ - len = bacerror_decode_apdu(NULL, apdu_len, &test_invoke_id, &test_service, - &test_error_class, &test_error_code); - ct_test(pTest, len == -1); - - /* force a zero length */ - len = bacerror_decode_apdu(&apdu[0], 0, &test_invoke_id, &test_service, - &test_error_class, &test_error_code); - ct_test(pTest, len == 0); - - /* check them all... */ - for (service = 0; service < MAX_BACNET_CONFIRMED_SERVICE; service++) { - for (error_class = 0; error_class < ERROR_CLASS_PROPRIETARY_FIRST; - error_class++) { - for (error_code = 0; error_code < ERROR_CODE_PROPRIETARY_FIRST; - error_code++) { - len = bacerror_encode_apdu( - &apdu[0], invoke_id, service, error_class, error_code); - apdu_len = len; - ct_test(pTest, len != 0); - len = bacerror_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, - &test_service, &test_error_class, &test_error_code); - ct_test(pTest, len != -1); - ct_test(pTest, test_invoke_id == invoke_id); - ct_test(pTest, test_service == service); - ct_test(pTest, test_error_class == error_class); - ct_test(pTest, test_error_code == error_code); - } - } - } - - /* max boundaries */ - service = 255; - error_class = ERROR_CLASS_PROPRIETARY_LAST; - error_code = ERROR_CODE_PROPRIETARY_LAST; - len = bacerror_encode_apdu( - &apdu[0], invoke_id, service, error_class, error_code); - apdu_len = len; - ct_test(pTest, len != 0); - len = bacerror_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, - &test_service, &test_error_class, &test_error_code); - ct_test(pTest, len != -1); - ct_test(pTest, test_invoke_id == invoke_id); - ct_test(pTest, test_service == service); - ct_test(pTest, test_error_class == error_class); - ct_test(pTest, test_error_code == error_code); -} - -#ifdef TEST_BACERROR -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet Error", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testBACError); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_ERROR */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/bacerror.h b/src/bacnet/bacerror.h index 9bd6342d..d2af3b3e 100644 --- a/src/bacnet/bacerror.h +++ b/src/bacnet/bacerror.h @@ -57,22 +57,6 @@ extern "C" { BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - int bacerror_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - uint8_t * invoke_id, - BACNET_CONFIRMED_SERVICE * service, - BACNET_ERROR_CLASS * error_class, - BACNET_ERROR_CODE * error_code); - - BACNET_STACK_EXPORT - void testBACError( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/bacint.c b/src/bacnet/bacint.c index f9b41575..0efae52c 100644 --- a/src/bacnet/bacint.c +++ b/src/bacnet/bacint.c @@ -412,243 +412,3 @@ int decode_signed32(uint8_t *apdu, int32_t *value) return 4; } #endif -/* end of decoding_encoding.c */ -#ifdef BAC_TEST -#include -#include -#include -#include "ctest.h" - -static void testBACnetUnsigned16(Test *pTest) -{ - uint8_t apdu[32] = { 0 }; - uint16_t value = 0, test_value = 0; - int len = 0; - - for (value = 0;; value++) { - len = encode_unsigned16(&apdu[0], value); - ct_test(pTest, len == 2); - len = decode_unsigned16(&apdu[0], &test_value); - ct_test(pTest, value == test_value); - if (value == 0xFFFF) - break; - } -} - -static void testBACnetUnsigned24(Test *pTest) -{ - uint8_t apdu[32] = { 0 }; - uint32_t value = 0, test_value = 0; - int len = 0; - - for (value = 0; value == 0xffffff; value += 0xf) { - len = encode_unsigned24(&apdu[0], value); - ct_test(pTest, len == 3); - len = decode_unsigned24(&apdu[0], &test_value); - ct_test(pTest, value == test_value); - } -} - -static void testBACnetUnsigned32(Test *pTest) -{ - uint8_t apdu[32] = { 0 }; - uint32_t value = 0, test_value = 0; - int len = 0; - - for (value = 0; value == 0xffffffff; value = (value << 8) | 0xff) { - len = encode_unsigned32(&apdu[0], value); - ct_test(pTest, len == 4); - len = decode_unsigned32(&apdu[0], &test_value); - ct_test(pTest, value == test_value); - } -} - -static void testBACnetUnsigned40(Test *pTest) -{ -#ifdef UINT64_MAX - uint8_t apdu[64] = { 0 }; - uint64_t value = 0, test_value = 0; - int len = 0; - - for (value = 0; value == 0xffffffffff; value = (value << 8) | 0xff) { - len = encode_unsigned40(&apdu[0], value); - ct_test(pTest, len == 5); - len = decode_unsigned40(&apdu[0], &test_value); - ct_test(pTest, len == 5); - ct_test(pTest, value == test_value); - } -#else -#warning "UINT64_MAX not supported!" -#endif -} - -static void testBACnetUnsigned48(Test *pTest) -{ -#ifdef UINT64_MAX - uint8_t apdu[64] = { 0 }; - uint64_t value = 0, test_value = 0; - int len = 0; - - for (value = 0; value == 0xffffffffffff; value = (value << 8) | 0xff) { - len = encode_unsigned48(&apdu[0], value); - ct_test(pTest, len == 6); - len = decode_unsigned48(&apdu[0], &test_value); - ct_test(pTest, len == 6); - ct_test(pTest, value == test_value); - } -#else -#warning "UINT64_MAX not supported!" -#endif -} - -static void testBACnetUnsigned56(Test *pTest) -{ -#ifdef UINT64_MAX - uint8_t apdu[64] = { 0 }; - uint64_t value = 0, test_value = 0; - int len = 0; - - for (value = 0; value == 0xffffffffffffff; value = (value << 8) | 0xff) { - len = encode_unsigned56(&apdu[0], value); - ct_test(pTest, len == 7); - len = decode_unsigned56(&apdu[0], &test_value); - ct_test(pTest, len == 7); - ct_test(pTest, value == test_value); - } -#else -#warning "UINT64_MAX not supported!" -#endif -} - -static void testBACnetUnsigned64(Test *pTest) -{ -#ifdef UINT64_MAX - uint8_t apdu[64] = { 0 }; - uint64_t value = 0, test_value = 0; - int len = 0; - - for (value = 0; value == 0xffffffffffffffff; value = (value << 8) | 0xff) { - len = encode_unsigned64(&apdu[0], value); - ct_test(pTest, len == 8); - len = decode_unsigned64(&apdu[0], &test_value); - ct_test(pTest, len == 8); - ct_test(pTest, value == test_value); - } -#else -#warning "UINT64_MAX not supported!" -#endif -} - -static void testBACnetSigned8(Test *pTest) -{ - uint8_t apdu[32] = { 0 }; - int32_t value = 0, test_value = 0; - int len = 0; - - for (value = -127;; value++) { - len = encode_signed8(&apdu[0], value); - ct_test(pTest, len == 1); - len = decode_signed8(&apdu[0], &test_value); - ct_test(pTest, value == test_value); - if (value == 127) - break; - } -} - -static void testBACnetSigned16(Test *pTest) -{ - uint8_t apdu[32] = { 0 }; - int32_t value = 0, test_value = 0; - int len = 0; - - for (value = -32767;; value++) { - len = encode_signed16(&apdu[0], value); - ct_test(pTest, len == 2); - len = decode_signed16(&apdu[0], &test_value); - ct_test(pTest, value == test_value); - if (value == 32767) - break; - } -} - -static void testBACnetSigned24(Test *pTest) -{ - uint8_t apdu[32] = { 0 }; - int32_t value = 0, test_value = 0; - int len = 0; - - for (value = -8388607; value <= 8388607; value += 15) { - len = encode_signed24(&apdu[0], value); - ct_test(pTest, len == 3); - len = decode_signed24(&apdu[0], &test_value); - ct_test(pTest, value == test_value); - } -} - -static void testBACnetSigned32(Test *pTest) -{ - uint8_t apdu[32] = { 0 }; - int32_t value = 0, test_value = 0; - int len = 0; - - for (value = -2147483647; value < 0; value += 127) { - len = encode_signed32(&apdu[0], value); - ct_test(pTest, len == 4); - len = decode_signed32(&apdu[0], &test_value); - ct_test(pTest, value == test_value); - } - for (value = 2147483647; value > 0; value -= 127) { - len = encode_signed32(&apdu[0], value); - ct_test(pTest, len == 4); - len = decode_signed32(&apdu[0], &test_value); - ct_test(pTest, value == test_value); - } -} - -void testBACnetIntegers(Test *pTest) -{ - bool rc; - - assert(pTest); - /* individual tests */ - rc = ct_addTestFunction(pTest, testBACnetUnsigned16); - assert(rc); - rc = ct_addTestFunction(pTest, testBACnetUnsigned24); - assert(rc); - rc = ct_addTestFunction(pTest, testBACnetUnsigned32); - assert(rc); - rc = ct_addTestFunction(pTest, testBACnetUnsigned40); - assert(rc); - rc = ct_addTestFunction(pTest, testBACnetUnsigned48); - assert(rc); - rc = ct_addTestFunction(pTest, testBACnetUnsigned56); - assert(rc); - rc = ct_addTestFunction(pTest, testBACnetUnsigned64); - assert(rc); - rc = ct_addTestFunction(pTest, testBACnetSigned8); - assert(rc); - rc = ct_addTestFunction(pTest, testBACnetSigned16); - assert(rc); - rc = ct_addTestFunction(pTest, testBACnetSigned24); - assert(rc); - rc = ct_addTestFunction(pTest, testBACnetSigned32); - assert(rc); -} - -#ifdef TEST_BACINT -int main(void) -{ - Test *pTest; - - pTest = ct_create("BACint", NULL); - testBACnetIntegers(pTest); - /* configure output */ - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_BACINT */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/bacint.h b/src/bacnet/bacint.h index 281070c6..95e4df9e 100644 --- a/src/bacnet/bacint.h +++ b/src/bacnet/bacint.h @@ -137,13 +137,6 @@ extern "C" { uint8_t * apdu, int32_t * value); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void testBACnetIntegers( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/bacpropstates.c b/src/bacnet/bacpropstates.c index e8088d0f..8625d7e7 100644 --- a/src/bacnet/bacpropstates.c +++ b/src/bacnet/bacpropstates.c @@ -292,131 +292,3 @@ int bacapp_encode_property_state(uint8_t *apdu, BACNET_PROPERTY_STATE *value) } return len; } - -#ifdef BAC_TEST -#include /* for memset */ - -void testPropStates(Test *pTest) -{ - BACNET_PROPERTY_STATE inData; - BACNET_PROPERTY_STATE outData; - uint8_t appMsg[MAX_APDU]; - int inLen; - int outLen; - - inData.tag = BOOLEAN_VALUE; - inData.state.booleanValue = true; - - inLen = bacapp_encode_property_state(appMsg, &inData); - - memset(&outData, 0, sizeof(outData)); - - outLen = bacapp_decode_property_state(appMsg, &outData); - - ct_test(pTest, outLen == inLen); - ct_test(pTest, inData.tag == outData.tag); - ct_test(pTest, inData.state.booleanValue == outData.state.booleanValue); - - /**************** - ***************** - ****************/ - inData.tag = BINARY_VALUE; - inData.state.binaryValue = BINARY_ACTIVE; - - inLen = bacapp_encode_property_state(appMsg, &inData); - - memset(&outData, 0, sizeof(outData)); - - outLen = bacapp_decode_property_state(appMsg, &outData); - - ct_test(pTest, outLen == inLen); - ct_test(pTest, inData.tag == outData.tag); - ct_test(pTest, inData.state.binaryValue == outData.state.binaryValue); - - /**************** - ***************** - ****************/ - inData.tag = EVENT_TYPE; - inData.state.eventType = EVENT_BUFFER_READY; - - inLen = bacapp_encode_property_state(appMsg, &inData); - - memset(&outData, 0, sizeof(outData)); - - outLen = bacapp_decode_property_state(appMsg, &outData); - - ct_test(pTest, outLen == inLen); - ct_test(pTest, inData.tag == outData.tag); - ct_test(pTest, inData.state.eventType == outData.state.eventType); - - /**************** - ***************** - ****************/ - inData.tag = POLARITY; - inData.state.polarity = POLARITY_REVERSE; - - inLen = bacapp_encode_property_state(appMsg, &inData); - - memset(&outData, 0, sizeof(outData)); - - outLen = bacapp_decode_property_state(appMsg, &outData); - - ct_test(pTest, outLen == inLen); - ct_test(pTest, inData.tag == outData.tag); - ct_test(pTest, inData.state.polarity == outData.state.polarity); - - /**************** - ***************** - ****************/ - inData.tag = PROGRAM_CHANGE; - inData.state.programChange = PROGRAM_REQUEST_RESTART; - - inLen = bacapp_encode_property_state(appMsg, &inData); - - memset(&outData, 0, sizeof(outData)); - - outLen = bacapp_decode_property_state(appMsg, &outData); - - ct_test(pTest, outLen == inLen); - ct_test(pTest, inData.tag == outData.tag); - ct_test(pTest, inData.state.programChange == outData.state.programChange); - - /**************** - ***************** - ****************/ - inData.tag = UNSIGNED_VALUE; - inData.state.unsignedValue = 0xdeadbeef; - - inLen = bacapp_encode_property_state(appMsg, &inData); - - memset(&outData, 0, sizeof(outData)); - - outLen = bacapp_decode_property_state(appMsg, &outData); - - ct_test(pTest, outLen == inLen); - ct_test(pTest, inData.tag == outData.tag); - ct_test(pTest, inData.state.unsignedValue == outData.state.unsignedValue); -} - -#ifdef TEST_PROP_STATES -#include -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet Event", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testPropStates); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} - -#endif /* TEST_PROP_STATES */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/bacstr.c b/src/bacnet/bacstr.c index c80bbe38..7a45675a 100644 --- a/src/bacnet/bacstr.c +++ b/src/bacnet/bacstr.c @@ -1223,216 +1223,3 @@ bool octetstring_value_same( return false; } #endif - -#ifdef BAC_TEST -#include -#include -#include -#include -#include "ctest.h" - -static void testBitString(Test *pTest) -{ - uint8_t bit = 0; - int max_bit; - BACNET_BIT_STRING bit_string; - BACNET_BIT_STRING bit_string2; - BACNET_BIT_STRING bit_string3; - - bitstring_init(&bit_string); - /* verify initialization */ - ct_test(pTest, bitstring_bits_used(&bit_string) == 0); - for (bit = 0; bit < (MAX_BITSTRING_BYTES * 8); bit++) { - ct_test(pTest, bitstring_bit(&bit_string, bit) == false); - } - - /* test for true */ - for (bit = 0; bit < (MAX_BITSTRING_BYTES * 8); bit++) { - bitstring_set_bit(&bit_string, bit, true); - ct_test(pTest, bitstring_bits_used(&bit_string) == (bit + 1)); - ct_test(pTest, bitstring_bit(&bit_string, bit) == true); - } - /* test for false */ - bitstring_init(&bit_string); - for (bit = 0; bit < (MAX_BITSTRING_BYTES * 8); bit++) { - bitstring_set_bit(&bit_string, bit, false); - ct_test(pTest, bitstring_bits_used(&bit_string) == (bit + 1)); - ct_test(pTest, bitstring_bit(&bit_string, bit) == false); - } - - /* test for compare equals */ - srand(time(NULL)); - for (max_bit = 0; max_bit < (MAX_BITSTRING_BYTES * 8); max_bit++) { - bitstring_init(&bit_string); - bitstring_init(&bit_string2); - for (bit = 0; bit < max_bit; bit++) { - bool bit_value = rand() % 2; - bitstring_set_bit(&bit_string, bit, bit_value); - bitstring_set_bit(&bit_string2, bit, bit_value); - } - ct_test(pTest, bitstring_same(&bit_string, &bit_string2)); - } - /* test for compare not equals */ - for (max_bit = 1; max_bit < (MAX_BITSTRING_BYTES * 8); max_bit++) { - bitstring_init(&bit_string); - bitstring_init(&bit_string2); - bitstring_init(&bit_string3); - for (bit = 0; bit < max_bit; bit++) { - bool bit_value = rand() % 2; - bitstring_set_bit(&bit_string, bit, bit_value); - bitstring_set_bit(&bit_string2, bit, bit_value); - bitstring_set_bit(&bit_string3, bit, bit_value); - } - /* Set the first bit of bit_string2 and the last bit of bit_string3 to - * be different */ - bitstring_set_bit(&bit_string2, 0, !bitstring_bit(&bit_string, 0)); - bitstring_set_bit(&bit_string3, max_bit - 1, - !bitstring_bit(&bit_string, max_bit - 1)); - ct_test(pTest, !bitstring_same(&bit_string, &bit_string2)); - ct_test(pTest, !bitstring_same(&bit_string, &bit_string3)); - } -} - -static void testCharacterString(Test *pTest) -{ - BACNET_CHARACTER_STRING bacnet_string; - char *value = "Joshua,Mary,Anna,Christopher"; - char test_value[MAX_APDU] = "Patricia"; - char test_append_value[MAX_APDU] = " and the Kids"; - char test_append_string[MAX_APDU] = ""; - bool status = false; - size_t length = 0; - size_t test_length = 0; - size_t i = 0; - - /* verify initialization */ - status = characterstring_init(&bacnet_string, CHARACTER_ANSI_X34, NULL, 0); - ct_test(pTest, status == true); - ct_test(pTest, characterstring_length(&bacnet_string) == 0); - ct_test( - pTest, characterstring_encoding(&bacnet_string) == CHARACTER_ANSI_X34); - /* bounds check */ - status = characterstring_init(&bacnet_string, CHARACTER_ANSI_X34, NULL, - characterstring_capacity(&bacnet_string) + 1); - ct_test(pTest, status == false); - status = characterstring_truncate( - &bacnet_string, characterstring_capacity(&bacnet_string) + 1); - ct_test(pTest, status == false); - status = characterstring_truncate( - &bacnet_string, characterstring_capacity(&bacnet_string)); - ct_test(pTest, status == true); - - test_length = strlen(test_value); - status = characterstring_init( - &bacnet_string, CHARACTER_ANSI_X34, &test_value[0], test_length); - ct_test(pTest, status == true); - value = characterstring_value(&bacnet_string); - length = characterstring_length(&bacnet_string); - ct_test(pTest, length == test_length); - for (i = 0; i < test_length; i++) { - ct_test(pTest, value[i] == test_value[i]); - } - test_length = strlen(test_append_value); - status = characterstring_append( - &bacnet_string, &test_append_value[0], test_length); - strcat(test_append_string, test_value); - strcat(test_append_string, test_append_value); - test_length = strlen(test_append_string); - ct_test(pTest, status == true); - length = characterstring_length(&bacnet_string); - value = characterstring_value(&bacnet_string); - ct_test(pTest, length == test_length); - for (i = 0; i < test_length; i++) { - ct_test(pTest, value[i] == test_append_string[i]); - } -} - -static void testOctetString(Test *pTest) -{ - BACNET_OCTET_STRING bacnet_string; - uint8_t *value = NULL; - uint8_t test_value[MAX_APDU] = "Patricia"; - uint8_t test_append_value[MAX_APDU] = " and the Kids"; - uint8_t test_append_string[MAX_APDU] = ""; - bool status = false; - size_t length = 0; - size_t test_length = 0; - size_t i = 0; - - /* verify initialization */ - status = octetstring_init(&bacnet_string, NULL, 0); - ct_test(pTest, status == true); - ct_test(pTest, octetstring_length(&bacnet_string) == 0); - value = octetstring_value(&bacnet_string); - for (i = 0; i < octetstring_capacity(&bacnet_string); i++) { - ct_test(pTest, value[i] == 0); - } - /* bounds check */ - status = octetstring_init( - &bacnet_string, NULL, octetstring_capacity(&bacnet_string) + 1); - ct_test(pTest, status == false); - status = octetstring_init( - &bacnet_string, NULL, octetstring_capacity(&bacnet_string)); - ct_test(pTest, status == true); - status = octetstring_truncate( - &bacnet_string, octetstring_capacity(&bacnet_string) + 1); - ct_test(pTest, status == false); - status = octetstring_truncate( - &bacnet_string, octetstring_capacity(&bacnet_string)); - ct_test(pTest, status == true); - - test_length = strlen((char *)test_value); - status = octetstring_init(&bacnet_string, &test_value[0], test_length); - ct_test(pTest, status == true); - length = octetstring_length(&bacnet_string); - value = octetstring_value(&bacnet_string); - ct_test(pTest, length == test_length); - for (i = 0; i < test_length; i++) { - ct_test(pTest, value[i] == test_value[i]); - } - - test_length = strlen((char *)test_append_value); - status = - octetstring_append(&bacnet_string, &test_append_value[0], test_length); - strcat((char *)test_append_string, (char *)test_value); - strcat((char *)test_append_string, (char *)test_append_value); - test_length = strlen((char *)test_append_string); - ct_test(pTest, status == true); - length = octetstring_length(&bacnet_string); - value = octetstring_value(&bacnet_string); - ct_test(pTest, length == test_length); - for (i = 0; i < test_length; i++) { - ct_test(pTest, value[i] == test_append_string[i]); - } -} - -void testBACnetStrings(Test *pTest) -{ - bool rc; - - /* add individual tests */ - rc = ct_addTestFunction(pTest, testBitString); - assert(rc); - rc = ct_addTestFunction(pTest, testCharacterString); - assert(rc); - rc = ct_addTestFunction(pTest, testOctetString); - assert(rc); -} - -#ifdef TEST_BACSTR -int main(void) -{ - Test *pTest; - - pTest = ct_create("BACnet Strings", NULL); - testBACnetStrings(pTest); - /* configure output */ - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_BACSTR */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/bacstr.h b/src/bacnet/bacstr.h index 01e1bb60..464c2bdd 100644 --- a/src/bacnet/bacstr.h +++ b/src/bacnet/bacstr.h @@ -235,13 +235,6 @@ extern "C" { BACNET_OCTET_STRING * octet_string1, BACNET_OCTET_STRING * octet_string2); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void testBACnetStrings( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/bactext.h b/src/bacnet/bactext.h index f33882df..69ad6db3 100644 --- a/src/bacnet/bactext.h +++ b/src/bacnet/bactext.h @@ -27,10 +27,6 @@ /* tiny implementations have no need to print */ #if PRINT_ENABLED #define BACTEXT_PRINT_ENABLED -#else -#ifdef BAC_TEST -#define BACTEXT_PRINT_ENABLED -#endif #endif #include diff --git a/src/bacnet/basic/bbmd6/vmac.c b/src/bacnet/basic/bbmd6/vmac.c index 4389a81f..8fd1f92a 100644 --- a/src/bacnet/basic/bbmd6/vmac.c +++ b/src/bacnet/basic/bbmd6/vmac.c @@ -289,63 +289,3 @@ void VMAC_Init(void) PRINTF("VMAC List initialized.\n"); } } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -void testVMAC(Test *pTest) -{ - uint32_t device_id = 123; - uint32_t test_device_id = 0; - struct vmac_data test_vmac_data; - struct vmac_data *pVMAC; - unsigned int i = 0; - bool status = false; - - VMAC_Init(); - for (i = 0; i < VMAC_MAC_MAX; i++) { - test_vmac_data.mac[i] = 1 + i; - } - test_vmac_data.mac_len = VMAC_MAC_MAX; - status = VMAC_Add(device_id, &test_vmac_data); - ct_test(pTest, status); - pVMAC = VMAC_Find_By_Key(0); - ct_test(pTest, pVMAC == NULL); - pVMAC = VMAC_Find_By_Key(device_id); - ct_test(pTest, pVMAC); - status = VMAC_Different(pVMAC, &test_vmac_data); - ct_test(pTest, !status); - status = VMAC_Match(pVMAC, &test_vmac_data); - ct_test(pTest, status); - status = VMAC_Find_By_Data(&test_vmac_data, &test_device_id); - ct_test(pTest, status); - ct_test(pTest, test_device_id == device_id); - status = VMAC_Delete(device_id); - ct_test(pTest, status); - pVMAC = VMAC_Find_By_Key(device_id); - ct_test(pTest, pVMAC == NULL); - VMAC_Cleanup(); -} - -#ifdef TEST_VMAC -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet VMAC", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testVMAC); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif -#endif diff --git a/src/bacnet/basic/bbmd6/vmac.h b/src/bacnet/basic/bbmd6/vmac.h index 0e6f9337..11868059 100644 --- a/src/bacnet/basic/bbmd6/vmac.h +++ b/src/bacnet/basic/bbmd6/vmac.h @@ -52,13 +52,6 @@ extern "C" { BACNET_STACK_EXPORT void VMAC_Debug_Enable(void); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void testVMAC( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/basic/binding/address.c b/src/bacnet/basic/binding/address.c index d19ee8d9..719cf5b4 100644 --- a/src/bacnet/basic/binding/address.c +++ b/src/bacnet/basic/binding/address.c @@ -229,7 +229,7 @@ static struct Address_Cache_Entry *address_remove_oldest(void) if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ | BAC_ADDR_STATIC)) == BAC_ADDR_IN_USE) { - if (pMatch->TimeToLive <= ulTime) { + if (pMatch->TimeToLive <= ulTime) { /* Shorter lived entry found */ ulTime = pMatch->TimeToLive; pCandidate = pMatch; @@ -237,11 +237,11 @@ static struct Address_Cache_Entry *address_remove_oldest(void) } } - if (pCandidate != NULL) { + if (pCandidate != NULL) { /* Found something to free up */ pCandidate->Flags = BAC_ADDR_RESERVED; /* only reserve it for a short while */ - pCandidate->TimeToLive = BAC_ADDR_SHORT_TIME; + pCandidate->TimeToLive = BAC_ADDR_SHORT_TIME; return (pCandidate); } @@ -258,7 +258,7 @@ static struct Address_Cache_Entry *address_remove_oldest(void) } } - if (pCandidate != NULL) { + if (pCandidate != NULL) { /* Found something to free up */ pCandidate->Flags = BAC_ADDR_RESERVED; /* only reserve it for a short while */ @@ -442,7 +442,7 @@ void address_init_partial(void) for (index = 0; index < MAX_ADDRESS_CACHE; index++) { pMatch = &Address_Cache[index]; - if ((pMatch->Flags & BAC_ADDR_IN_USE) != 0) { + if ((pMatch->Flags & BAC_ADDR_IN_USE) != 0) { /* It's in use so let's check further */ if (((pMatch->Flags & BAC_ADDR_BIND_REQ) != 0) || (pMatch->TimeToLive == 0)) { @@ -450,7 +450,7 @@ void address_init_partial(void) } } - if ((pMatch->Flags & BAC_ADDR_RESERVED) != 0) { + if ((pMatch->Flags & BAC_ADDR_RESERVED) != 0) { /* Reserved entries should be cleared */ pMatch->Flags = 0; } @@ -482,7 +482,7 @@ void address_set_device_TTL( pMatch = &Address_Cache[index]; if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) && (pMatch->device_id == device_id)) { - if ((pMatch->Flags & BAC_ADDR_BIND_REQ) == 0) { + if ((pMatch->Flags & BAC_ADDR_BIND_REQ) == 0) { /* If bound then we have either static or normaal */ if (StaticFlag) { pMatch->Flags |= BAC_ADDR_STATIC; @@ -493,7 +493,7 @@ void address_set_device_TTL( } } else { /* For unbound we can only set the time to live */ - pMatch->TimeToLive = TimeOut; + pMatch->TimeToLive = TimeOut; } break; /* Exit now if found at all - bound or unbound */ } @@ -518,15 +518,15 @@ bool address_get_by_device( pMatch = &Address_Cache[index]; if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) && (pMatch->device_id == device_id)) { - if ((pMatch->Flags & BAC_ADDR_BIND_REQ) == 0) { + if ((pMatch->Flags & BAC_ADDR_BIND_REQ) == 0) { /* If bound then fetch data */ bacnet_address_copy(src, &pMatch->address); *max_apdu = pMatch->max_apdu; /* Prove we found it */ - found = true; + found = true; } /* Exit now if found at all - bound or unbound */ - break; + break; } } @@ -549,8 +549,8 @@ bool address_get_device_id(BACNET_ADDRESS *src, uint32_t *device_id) for (index = 0; index < MAX_ADDRESS_CACHE; index++) { pMatch = &Address_Cache[index]; - if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) == - BAC_ADDR_IN_USE) { + if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) == + BAC_ADDR_IN_USE) { /* If bound */ if (bacnet_address_same(&pMatch->address, src)) { if (device_id) { @@ -597,21 +597,21 @@ void address_add(uint32_t device_id, unsigned max_apdu, BACNET_ADDRESS *src) bacnet_address_copy(&pMatch->address, src); pMatch->max_apdu = max_apdu; /* Pick the right time to live */ - if ((pMatch->Flags & BAC_ADDR_BIND_REQ) != 0) { + if ((pMatch->Flags & BAC_ADDR_BIND_REQ) != 0) { /* Bind requested so long time */ pMatch->TimeToLive = BAC_ADDR_LONG_TIME; - } else if ((pMatch->Flags & BAC_ADDR_STATIC) != 0) { + } else if ((pMatch->Flags & BAC_ADDR_STATIC) != 0) { /* Static already so make sure it never expires */ pMatch->TimeToLive = BAC_ADDR_FOREVER; - } else if ((pMatch->Flags & BAC_ADDR_SHORT_TTL) != 0) { + } else if ((pMatch->Flags & BAC_ADDR_SHORT_TTL) != 0) { /* Opportunistic entry so leave on short fuse */ pMatch->TimeToLive = BAC_ADDR_SHORT_TIME; } else { /* Renewing existing entry */ - pMatch->TimeToLive = BAC_ADDR_LONG_TIME; + pMatch->TimeToLive = BAC_ADDR_LONG_TIME; } /* Clear bind request flag just in case */ - pMatch->Flags &= ~BAC_ADDR_BIND_REQ; + pMatch->Flags &= ~BAC_ADDR_BIND_REQ; found = true; break; } @@ -626,7 +626,7 @@ void address_add(uint32_t device_id, unsigned max_apdu, BACNET_ADDRESS *src) pMatch->max_apdu = max_apdu; bacnet_address_copy(&pMatch->address, src); /* Opportunistic entry so leave on short fuse */ - pMatch->TimeToLive = BAC_ADDR_SHORT_TIME; + pMatch->TimeToLive = BAC_ADDR_SHORT_TIME; found = true; break; } @@ -642,7 +642,7 @@ void address_add(uint32_t device_id, unsigned max_apdu, BACNET_ADDRESS *src) pMatch->max_apdu = max_apdu; bacnet_address_copy(&pMatch->address, src); /* Opportunistic entry so leave on short fuse */ - pMatch->TimeToLive = BAC_ADDR_SHORT_TIME; + pMatch->TimeToLive = BAC_ADDR_SHORT_TIME; } } return; @@ -675,7 +675,7 @@ bool address_device_bind_request(uint32_t device_id, pMatch = &Address_Cache[index]; if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) && (pMatch->device_id == device_id)) { - if ((pMatch->Flags & BAC_ADDR_BIND_REQ) == 0) { + if ((pMatch->Flags & BAC_ADDR_BIND_REQ) == 0) { /* Already bound */ found = true; if (src) { @@ -687,7 +687,7 @@ bool address_device_bind_request(uint32_t device_id, if (device_ttl) { *device_ttl = pMatch->TimeToLive; } - if ((pMatch->Flags & BAC_ADDR_SHORT_TTL) != 0) { + if ((pMatch->Flags & BAC_ADDR_SHORT_TTL) != 0) { /* Was picked up opportunistacilly */ /* Convert to normal entry */ pMatch->Flags &= ~BAC_ADDR_SHORT_TTL; @@ -696,7 +696,7 @@ bool address_device_bind_request(uint32_t device_id, } } /* True if bound, false if bind request outstanding */ - return (found); + return (found); } } @@ -1025,12 +1025,12 @@ int rr_address_list_encode(uint8_t *apdu, BACNET_READ_RANGE_DATA *pRequest) /* From here on in we only have a starting point and a positive count */ - if (pRequest->Range.RefIndex > uiTotal) { + if (pRequest->Range.RefIndex > uiTotal) { /* Nothing to return as we are past the end of the list */ return (0); } /* Index of last required entry */ - uiTarget = pRequest->Range.RefIndex + pRequest->Count - 1; + uiTarget = pRequest->Range.RefIndex + pRequest->Count - 1; if (uiTarget > uiTotal) { /* Capped at end of list if necessary */ uiTarget = uiTotal; } @@ -1043,14 +1043,14 @@ int rr_address_list_encode(uint8_t *apdu, BACNET_READ_RANGE_DATA *pRequest) /* Shall not happen as the count has been checked first. */ if (pMatch > &Address_Cache[MAX_ADDRESS_CACHE - 1]) { /* Issue with the table. */ - return (0); + return (0); } } /* Seek to start position */ while (uiIndex != pRequest->Range.RefIndex) { if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) == - BAC_ADDR_IN_USE) { + BAC_ADDR_IN_USE) { /* Only count bound entries */ pMatch++; uiIndex++; @@ -1060,7 +1060,7 @@ int rr_address_list_encode(uint8_t *apdu, BACNET_READ_RANGE_DATA *pRequest) /* Shall not happen as the count has been checked first. */ if (pMatch > &Address_Cache[MAX_ADDRESS_CACHE - 1]) { /* Issue with the table. */ - return (0); + return (0); } } @@ -1093,25 +1093,25 @@ int rr_address_list_encode(uint8_t *apdu, BACNET_READ_RANGE_DATA *pRequest) &apdu[iLen + iTemp], &MAC_Address); } /* Reduce the remaining space */ - uiRemaining -= iTemp; + uiRemaining -= iTemp; /* and increase the length consumed */ - iLen += iTemp; + iLen += iTemp; /* Record the last entry encoded */ - uiLast = uiIndex; + uiLast = uiIndex; /* and get ready for next one */ - uiIndex++; + uiIndex++; pMatch++; /* Chalk up another one for the response count */ - pRequest->ItemCount++; + pRequest->ItemCount++; while ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) != - BAC_ADDR_IN_USE) { + BAC_ADDR_IN_USE) { /* Find next bound entry */ pMatch++; /* Can normally not happen. */ if (pMatch > &Address_Cache[MAX_ADDRESS_CACHE - 1]) { /* Issue with the table. */ - return (0); + return (0); } } } @@ -1140,7 +1140,7 @@ void address_cache_timer(uint16_t uSeconds) { struct Address_Cache_Entry *pMatch; unsigned index; - + for (index = 0; index < MAX_ADDRESS_CACHE; index++) { pMatch = &Address_Cache[index]; if (((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_RESERVED)) != 0) && @@ -1155,178 +1155,3 @@ void address_cache_timer(uint16_t uSeconds) } } } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -static void set_address(unsigned index, BACNET_ADDRESS *dest) -{ - unsigned i; - - for (i = 0; i < MAX_MAC_LEN; i++) { - dest->mac[i] = index; - } - dest->mac_len = MAX_MAC_LEN; - dest->net = 7; - dest->len = MAX_MAC_LEN; - for (i = 0; i < MAX_MAC_LEN; i++) { - dest->adr[i] = index; - } -} - -static void set_file_address(const char *pFilename, - uint32_t device_id, - BACNET_ADDRESS *dest, - uint16_t max_apdu) -{ - unsigned i; - FILE *pFile = NULL; - - pFile = fopen(pFilename, "w"); - - if (pFile) { - fprintf(pFile, "%lu ", (long unsigned int)device_id); - for (i = 0; i < dest->mac_len; i++) { - fprintf(pFile, "%02x", dest->mac[i]); - if ((i + 1) < dest->mac_len) { - fprintf(pFile, ":"); - } - } - fprintf(pFile, " %hu ", dest->net); - if (dest->net) { - for (i = 0; i < dest->len; i++) { - fprintf(pFile, "%02x", dest->adr[i]); - if ((i + 1) < dest->len) { - fprintf(pFile, ":"); - } - } - } else { - fprintf(pFile, "0"); - } - fprintf(pFile, " %hu\n", max_apdu); - fclose(pFile); - } -} - -#ifdef BACNET_ADDRESS_CACHE_FILE -void testAddressFile(Test *pTest) -{ - BACNET_ADDRESS src = { 0 }; - uint32_t device_id = 0; - unsigned max_apdu = 480; - BACNET_ADDRESS test_address = { 0 }; - unsigned test_max_apdu = 0; - - /* create a fake address */ - device_id = 55555; - src.mac_len = 1; - src.mac[0] = 25; - src.net = 0; - src.adr[0] = 0; - max_apdu = 50; - set_file_address(Address_Cache_Filename, device_id, &src, max_apdu); - /* retrieve it from the file, and see if we can find it */ - address_file_init(Address_Cache_Filename); - ct_test( - pTest, address_get_by_device(device_id, &test_max_apdu, &test_address)); - ct_test(pTest, test_max_apdu == max_apdu); - ct_test(pTest, bacnet_address_same(&test_address, &src)); - - /* create a fake address */ - device_id = 55555; - src.mac_len = 6; - src.mac[0] = 0xC0; - src.mac[1] = 0xA8; - src.mac[2] = 0x00; - src.mac[3] = 0x18; - src.mac[4] = 0xBA; - src.mac[5] = 0xC0; - src.net = 26001; - src.len = 1; - src.adr[0] = 25; - max_apdu = 50; - set_file_address(Address_Cache_Filename, device_id, &src, max_apdu); - /* retrieve it from the file, and see if we can find it */ - address_file_init(Address_Cache_Filename); - ct_test( - pTest, address_get_by_device(device_id, &test_max_apdu, &test_address)); - ct_test(pTest, test_max_apdu == max_apdu); - ct_test(pTest, bacnet_address_same(&test_address, &src)); -} -#endif - -void testAddress(Test *pTest) -{ - unsigned i, count; - BACNET_ADDRESS src; - uint32_t device_id = 0; - unsigned max_apdu = 480; - BACNET_ADDRESS test_address; - uint32_t test_device_id = 0; - unsigned test_max_apdu = 0; - - /* create a fake address database */ - for (i = 0; i < MAX_ADDRESS_CACHE; i++) { - set_address(i, &src); - device_id = i * 255; - address_add(device_id, max_apdu, &src); - count = address_count(); - ct_test(pTest, count == (i + 1)); - } - - for (i = 0; i < MAX_ADDRESS_CACHE; i++) { - device_id = i * 255; - set_address(i, &src); - /* test the lookup by device id */ - ct_test(pTest, - address_get_by_device(device_id, &test_max_apdu, &test_address)); - ct_test(pTest, test_max_apdu == max_apdu); - ct_test(pTest, bacnet_address_same(&test_address, &src)); - ct_test(pTest, - address_get_by_index( - i, &test_device_id, &test_max_apdu, &test_address)); - ct_test(pTest, test_device_id == device_id); - ct_test(pTest, test_max_apdu == max_apdu); - ct_test(pTest, bacnet_address_same(&test_address, &src)); - ct_test(pTest, address_count() == MAX_ADDRESS_CACHE); - /* test the lookup by MAC */ - ct_test(pTest, address_get_device_id(&src, &test_device_id)); - ct_test(pTest, test_device_id == device_id); - } - - for (i = 0; i < MAX_ADDRESS_CACHE; i++) { - device_id = i * 255; - address_remove_device(device_id); - ct_test(pTest, - !address_get_by_device(device_id, &test_max_apdu, &test_address)); - count = address_count(); - ct_test(pTest, count == (MAX_ADDRESS_CACHE - i - 1)); - } -} - -#ifdef TEST_ADDRESS -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet Address", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testAddress); - assert(rc); -#ifdef BACNET_ADDRESS_CACHE_FILE - rc = ct_addTestFunction(pTest, testAddressFile); - assert(rc); -#endif - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_ADDRESS */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/basic/object/access_credential.h b/src/bacnet/basic/object/access_credential.h index 768487d0..ec72d2f9 100644 --- a/src/bacnet/basic/object/access_credential.h +++ b/src/bacnet/basic/object/access_credential.h @@ -127,13 +127,6 @@ extern "C" { void Access_Credential_Init( void); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void testAccessCredential( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/basic/object/bo.h b/src/bacnet/basic/object/bo.h index cf960afd..d2207cc9 100644 --- a/src/bacnet/basic/object/bo.h +++ b/src/bacnet/basic/object/bo.h @@ -163,13 +163,6 @@ extern "C" { void Binary_Output_Cleanup( void); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void testBinaryOutput( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/basic/object/bv.c b/src/bacnet/basic/object/bv.c index 0ce31332..cb30ffcb 100644 --- a/src/bacnet/basic/object/bv.c +++ b/src/bacnet/basic/object/bv.c @@ -538,57 +538,3 @@ bool Binary_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) return status; } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -void testBinary_Value(Test *pTest) -{ - uint8_t apdu[MAX_APDU] = { 0 }; - int len = 0; - uint32_t len_value = 0; - uint8_t tag_number = 0; - uint16_t decoded_type = 0; - uint32_t decoded_instance = 0; - BACNET_READ_PROPERTY_DATA rpdata; - - Binary_Value_Init(); - rpdata.application_data = &apdu[0]; - rpdata.application_data_len = sizeof(apdu); - rpdata.object_type = OBJECT_BINARY_VALUE; - rpdata.object_instance = 1; - rpdata.object_property = PROP_OBJECT_IDENTIFIER; - rpdata.array_index = BACNET_ARRAY_ALL; - len = Binary_Value_Read_Property(&rpdata); - ct_test(pTest, len != 0); - len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); - ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); - len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance); - ct_test(pTest, decoded_type == rpdata.object_type); - ct_test(pTest, decoded_instance == rpdata.object_instance); - - return; -} - -#ifdef TEST_BINARY_VALUE -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet Binary_Value", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testBinary_Value); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_BINARY_VALUE */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/basic/object/bv.h b/src/bacnet/basic/object/bv.h index f654ef69..bf706000 100644 --- a/src/bacnet/basic/object/bv.h +++ b/src/bacnet/basic/object/bv.h @@ -181,13 +181,6 @@ extern "C" { void Binary_Value_Cleanup( void); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void testBinary_Value( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/basic/object/channel.h b/src/bacnet/basic/object/channel.h index 61c5b837..fad67f30 100644 --- a/src/bacnet/basic/object/channel.h +++ b/src/bacnet/basic/object/channel.h @@ -222,12 +222,6 @@ extern "C" { BACNET_STACK_EXPORT void Channel_Init(void); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void testChannelObject(Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/basic/object/command.c b/src/bacnet/basic/object/command.c index 4417cf1e..b0dbbd28 100644 --- a/src/bacnet/basic/object/command.c +++ b/src/bacnet/basic/object/command.c @@ -820,88 +820,3 @@ bool Command_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) void Command_Intrinsic_Reporting(uint32_t object_instance) { } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -void testCommand(Test *pTest) -{ - uint8_t apdu[MAX_APDU] = { 0 }; - int len = 0; - uint32_t len_value = 0; - uint8_t tag_number = 0; - uint32_t decoded_instance = 0; - uint16_t decoded_type = 0; - BACNET_READ_PROPERTY_DATA rpdata; - BACNET_ACTION_LIST clist, clist_test; - Command_Init(); - rpdata.application_data = &apdu[0]; - rpdata.application_data_len = sizeof(apdu); - rpdata.object_type = OBJECT_COMMAND; - rpdata.object_instance = 1; - rpdata.object_property = PROP_OBJECT_IDENTIFIER; - rpdata.array_index = BACNET_ARRAY_ALL; - len = Command_Read_Property(&rpdata); - ct_test(pTest, len != 0); - len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); - ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); - len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance); - ct_test(pTest, decoded_type == rpdata.object_type); - ct_test(pTest, decoded_instance == rpdata.object_instance); - memset(&clist, 0, sizeof(BACNET_ACTION_LIST)); - memset(&clist_test, 0, sizeof(BACNET_ACTION_LIST)); - clist.Device_Id.type = OBJECT_DEVICE; - clist.Device_Id.instance = 3389; - clist.Object_Id.type = OBJECT_ANALOG_VALUE; - clist.Object_Id.instance = 42; - clist.Property_Identifier = PROP_PRESENT_VALUE; - clist.Property_Array_Index = BACNET_ARRAY_ALL; - clist.Value.tag = BACNET_APPLICATION_TAG_REAL; - clist.Value.type.Real = 39.0f; - clist.Priority = 4; - clist.Post_Delay = 0xFFFFFFFFU; - clist.Quit_On_Failure = true; - clist.Write_Successful = false; - clist.next = NULL; - len = cl_encode_apdu(apdu, &clist); - ct_test(pTest, len > 0); - len = cl_decode_apdu(apdu, len, BACNET_APPLICATION_TAG_REAL, &clist_test); - ct_test(pTest, len > 0); - ct_test(pTest, clist.Device_Id.type == clist_test.Device_Id.type); - ct_test(pTest, clist.Device_Id.instance == clist_test.Device_Id.instance); - ct_test(pTest, clist.Object_Id.type == clist_test.Object_Id.type); - ct_test(pTest, clist.Object_Id.instance == clist_test.Object_Id.instance); - ct_test(pTest, clist.Property_Identifier == clist_test.Property_Identifier); - ct_test( - pTest, clist.Property_Array_Index == clist_test.Property_Array_Index); - ct_test(pTest, clist.Value.tag == clist_test.Value.tag); - ct_test(pTest, clist.Value.type.Real == clist_test.Value.type.Real); - ct_test(pTest, clist.Priority == clist_test.Priority); - ct_test(pTest, clist.Post_Delay == clist_test.Post_Delay); - ct_test(pTest, clist.Quit_On_Failure == clist_test.Quit_On_Failure); - ct_test(pTest, clist.Write_Successful == clist_test.Write_Successful); - return; -} - -#ifdef TEST_COMMAND -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet Command", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testCommand); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_COMMAND */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/basic/object/command.h b/src/bacnet/basic/object/command.h index ddc7836f..8e66d286 100644 --- a/src/bacnet/basic/object/command.h +++ b/src/bacnet/basic/object/command.h @@ -188,13 +188,6 @@ extern "C" { void Command_Init( void); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void testCommand( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/basic/object/credential_data_input.c b/src/bacnet/basic/object/credential_data_input.c index 87a0ca54..3ba3c28d 100644 --- a/src/bacnet/basic/object/credential_data_input.c +++ b/src/bacnet/basic/object/credential_data_input.c @@ -362,57 +362,3 @@ bool Credential_Data_Input_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) return status; } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -void testCredentialDataInput(Test *pTest) -{ - uint8_t apdu[MAX_APDU] = { 0 }; - int len = 0; - uint32_t len_value = 0; - uint8_t tag_number = 0; - uint32_t decoded_instance = 0; - uint16_t decoded_type = 0; - BACNET_READ_PROPERTY_DATA rpdata; - - Credential_Data_Input_Init(); - rpdata.application_data = &apdu[0]; - rpdata.application_data_len = sizeof(apdu); - rpdata.object_type = OBJECT_CREDENTIAL_DATA_INPUT; - rpdata.object_instance = 1; - rpdata.object_property = PROP_OBJECT_IDENTIFIER; - rpdata.array_index = BACNET_ARRAY_ALL; - len = Credential_Data_Input_Read_Property(&rpdata); - ct_test(pTest, len != 0); - len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); - ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); - len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance); - ct_test(pTest, decoded_type == rpdata.object_type); - ct_test(pTest, decoded_instance == rpdata.object_instance); - - return; -} - -#ifdef TEST_CREDENTIAL_DATA_INPUT -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet Credential Data Input", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testCredentialDataInput); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_CREDENTIAL_DATA_INPUT */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/basic/object/credential_data_input.h b/src/bacnet/basic/object/credential_data_input.h index cfc5fdcb..eb178365 100644 --- a/src/bacnet/basic/object/credential_data_input.h +++ b/src/bacnet/basic/object/credential_data_input.h @@ -121,13 +121,6 @@ extern "C" { void Credential_Data_Input_Init( void); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void testCredentialDataInput( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/basic/object/csv.c b/src/bacnet/basic/object/csv.c index 0e7e5ead..1605e362 100644 --- a/src/bacnet/basic/object/csv.c +++ b/src/bacnet/basic/object/csv.c @@ -625,57 +625,3 @@ bool CharacterString_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) return status; } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -void testCharacterStringValue(Test *pTest) -{ - uint8_t apdu[MAX_APDU] = { 0 }; - int len = 0; - uint32_t len_value = 0; - uint8_t tag_number = 0; - uint16_t decoded_type = 0; - uint32_t decoded_instance = 0; - BACNET_READ_PROPERTY_DATA rpdata; - - CharacterString_Value_Init(); - rpdata.application_data = &apdu[0]; - rpdata.application_data_len = sizeof(apdu); - rpdata.object_type = OBJECT_CHARACTERSTRING_VALUE; - rpdata.object_instance = 1; - rpdata.object_property = PROP_OBJECT_IDENTIFIER; - rpdata.array_index = BACNET_ARRAY_ALL; - len = CharacterString_Value_Read_Property(&rpdata); - ct_test(pTest, len != 0); - len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); - ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); - len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance); - ct_test(pTest, decoded_type == rpdata.object_type); - ct_test(pTest, decoded_instance == rpdata.object_instance); - - return; -} - -#ifdef TEST_CHARACTERSTRING_VALUE -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet CharacterString Value", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testCharacterStringValue); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif -#endif /* BAC_TEST */ diff --git a/src/bacnet/basic/object/csv.h b/src/bacnet/basic/object/csv.h index 8f0744c5..cf720777 100644 --- a/src/bacnet/basic/object/csv.h +++ b/src/bacnet/basic/object/csv.h @@ -109,14 +109,6 @@ extern "C" { void CharacterString_Value_Init( void); - -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void testCharacterStringValue( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/basic/object/device.c b/src/bacnet/basic/object/device.c index 32b01710..810d4d21 100644 --- a/src/bacnet/basic/object/device.c +++ b/src/bacnet/basic/object/device.c @@ -1890,104 +1890,3 @@ void Routing_Device_Init(uint32_t first_object_instance) } #endif /* BAC_ROUTING */ - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -bool write_property_type_valid( - BACNET_WRITE_PROPERTY_DATA * wp_data, - BACNET_APPLICATION_DATA_VALUE * value, - uint8_t expected_tag) -{ - (void)wp_data; - (void)value; - (void)expected_tag; - - return false; -} - -bool write_property_string_valid( - BACNET_WRITE_PROPERTY_DATA * wp_data, - BACNET_APPLICATION_DATA_VALUE * value, - int len_max) -{ - (void)wp_data; - (void)value; - (void)len_max; - - return false; -} - -bool write_property_empty_string_valid( - BACNET_WRITE_PROPERTY_DATA * wp_data, - BACNET_APPLICATION_DATA_VALUE * value, - int len_max) -{ - (void)wp_data; - (void)value; - (void)len_max; - - return false; -} - -int handler_cov_encode_subscriptions(uint8_t *apdu, int max_apdu) -{ - apdu = apdu; - max_apdu = max_apdu; - - return 0; -} - -void testDevice(Test *pTest) -{ - bool status = false; - const char *name = "Patricia"; - - status = Device_Set_Object_Instance_Number(0); - ct_test(pTest, Device_Object_Instance_Number() == 0); - ct_test(pTest, status == true); - status = Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE); - ct_test(pTest, Device_Object_Instance_Number() == BACNET_MAX_INSTANCE); - ct_test(pTest, status == true); - status = Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE / 2); - ct_test( - pTest, Device_Object_Instance_Number() == (BACNET_MAX_INSTANCE / 2)); - ct_test(pTest, status == true); - status = Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE + 1); - ct_test( - pTest, Device_Object_Instance_Number() != (BACNET_MAX_INSTANCE + 1)); - ct_test(pTest, status == false); - - Device_Set_System_Status(STATUS_NON_OPERATIONAL, true); - ct_test(pTest, Device_System_Status() == STATUS_NON_OPERATIONAL); - - ct_test(pTest, Device_Vendor_Identifier() == BACNET_VENDOR_ID); - - Device_Set_Model_Name(name, strlen(name)); - ct_test(pTest, strcmp(Device_Model_Name(), name) == 0); - - return; -} - -#ifdef TEST_DEVICE -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet Device", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testDevice); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_DEVICE */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/basic/object/iv.h b/src/bacnet/basic/object/iv.h index 8ab4394f..3a454d67 100644 --- a/src/bacnet/basic/object/iv.h +++ b/src/bacnet/basic/object/iv.h @@ -131,13 +131,6 @@ extern "C" { void Integer_Value_Init( void); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void testInteger_Value( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/basic/object/lc.c b/src/bacnet/basic/object/lc.c index 8d8d7365..587afa0b 100644 --- a/src/bacnet/basic/object/lc.c +++ b/src/bacnet/basic/object/lc.c @@ -868,7 +868,7 @@ bool Load_Control_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) int len = 0; BACNET_APPLICATION_DATA_VALUE value; /* build here in case of error in time half of datetime */ - BACNET_DATE start_date; + BACNET_DATE start_date; PRINTF("Load_Control_Write_Property(wp_data=%p)\n", wp_data); if (wp_data == NULL) { @@ -1036,417 +1036,3 @@ bool Load_Control_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) PRINTF("Load_Control_Write_Property() returning status=%d\n", status); return status; } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -#if 0 -static void Load_Control_WriteProperty_Request_Shed_Percent( - Test * pTest, - int instance, - unsigned percent) -{ - bool status = false; - BACNET_APPLICATION_DATA_VALUE value; - BACNET_WRITE_PROPERTY_DATA wp_data; - - wp_data.object_type = OBJECT_LOAD_CONTROL; - wp_data.object_instance = instance; - wp_data.array_index = BACNET_ARRAY_ALL; - wp_data.priority = BACNET_NO_PRIORITY; - wp_data.object_property = PROP_REQUESTED_SHED_LEVEL; - wp_data.error_class = ERROR_CLASS_PROPERTY; - wp_data.error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; - value.context_specific = true; - value.context_tag = 0; - value.tag = BACNET_APPLICATION_TAG_UNSIGNED_INT; - value.type.Unsigned_Int = percent; - wp_data.application_data_len = - bacapp_encode_data(&wp_data.application_data[0], &value); - ct_test(pTest, wp_data.application_data_len > 0); - status = Load_Control_Write_Property(&wp_data); - ct_test(pTest, status == true); -} -#endif - -static void Load_Control_WriteProperty_Request_Shed_Level( - Test *pTest, int instance, unsigned level) -{ - bool status = false; - BACNET_APPLICATION_DATA_VALUE value; - BACNET_WRITE_PROPERTY_DATA wp_data; - - wp_data.object_type = OBJECT_LOAD_CONTROL; - wp_data.object_instance = instance; - wp_data.array_index = BACNET_ARRAY_ALL; - wp_data.priority = BACNET_NO_PRIORITY; - wp_data.object_property = PROP_REQUESTED_SHED_LEVEL; - value.context_specific = true; - value.context_tag = 1; - value.tag = BACNET_APPLICATION_TAG_UNSIGNED_INT; - value.type.Unsigned_Int = level; - wp_data.application_data_len = - bacapp_encode_data(&wp_data.application_data[0], &value); - ct_test(pTest, wp_data.application_data_len > 0); - status = Load_Control_Write_Property(&wp_data); - ct_test(pTest, status == true); -} - -#if 0 -static void Load_Control_WriteProperty_Request_Shed_Amount( - Test * pTest, - int instance, - float amount) -{ - bool status = false; - BACNET_APPLICATION_DATA_VALUE value; - BACNET_WRITE_PROPERTY_DATA wp_data; - - wp_data.object_type = OBJECT_LOAD_CONTROL; - wp_data.object_instance = instance; - wp_data.array_index = BACNET_ARRAY_ALL; - wp_data.priority = BACNET_NO_PRIORITY; - wp_data.object_property = PROP_REQUESTED_SHED_LEVEL; - value.context_specific = true; - value.context_tag = 2; - value.tag = BACNET_APPLICATION_TAG_REAL; - value.type.Real = amount; - wp_data.application_data_len = - bacapp_encode_data(&wp_data.application_data[0], &value); - ct_test(pTest, wp_data.application_data_len > 0); - status = Load_Control_Write_Property(&wp_data); - ct_test(pTest, status == true); -} -#endif - -static void Load_Control_WriteProperty_Enable( - Test *pTest, int instance, bool enable) -{ - bool status = false; - BACNET_APPLICATION_DATA_VALUE value; - BACNET_WRITE_PROPERTY_DATA wp_data; - - wp_data.object_type = OBJECT_LOAD_CONTROL; - wp_data.object_instance = instance; - wp_data.array_index = BACNET_ARRAY_ALL; - wp_data.priority = BACNET_NO_PRIORITY; - /* Set Enable=TRUE */ - wp_data.object_property = PROP_ENABLE; - value.context_specific = false; - value.context_tag = 0; - value.tag = BACNET_APPLICATION_TAG_BOOLEAN; - value.type.Boolean = enable; - wp_data.application_data_len = - bacapp_encode_data(&wp_data.application_data[0], &value); - ct_test(pTest, wp_data.application_data_len > 0); - status = Load_Control_Write_Property(&wp_data); - ct_test(pTest, status == true); -} - -static void Load_Control_WriteProperty_Shed_Duration( - Test *pTest, int instance, unsigned duration) -{ - bool status = false; - BACNET_APPLICATION_DATA_VALUE value; - BACNET_WRITE_PROPERTY_DATA wp_data; - - wp_data.object_type = OBJECT_LOAD_CONTROL; - wp_data.object_instance = instance; - wp_data.array_index = BACNET_ARRAY_ALL; - wp_data.priority = BACNET_NO_PRIORITY; - wp_data.object_property = PROP_SHED_DURATION; - value.context_specific = false; - value.context_tag = 0; - value.tag = BACNET_APPLICATION_TAG_UNSIGNED_INT; - value.type.Unsigned_Int = duration; - wp_data.application_data_len = - bacapp_encode_data(&wp_data.application_data[0], &value); - ct_test(pTest, wp_data.application_data_len > 0); - status = Load_Control_Write_Property(&wp_data); - ct_test(pTest, status == true); -} - -static void Load_Control_WriteProperty_Duty_Window( - Test *pTest, int instance, unsigned duration) -{ - bool status = false; - BACNET_APPLICATION_DATA_VALUE value; - BACNET_WRITE_PROPERTY_DATA wp_data; - - wp_data.object_type = OBJECT_LOAD_CONTROL; - wp_data.object_instance = instance; - wp_data.array_index = BACNET_ARRAY_ALL; - wp_data.priority = BACNET_NO_PRIORITY; - wp_data.object_property = PROP_DUTY_WINDOW; - value.context_specific = false; - value.context_tag = 0; - value.tag = BACNET_APPLICATION_TAG_UNSIGNED_INT; - value.type.Unsigned_Int = duration; - wp_data.application_data_len = - bacapp_encode_data(&wp_data.application_data[0], &value); - ct_test(pTest, wp_data.application_data_len > 0); - status = Load_Control_Write_Property(&wp_data); - ct_test(pTest, status == true); -} - -static void Load_Control_WriteProperty_Start_Time_Wildcards( - Test *pTest, int instance) -{ - int len = 0; - bool status = false; - BACNET_APPLICATION_DATA_VALUE value; - BACNET_WRITE_PROPERTY_DATA wp_data; - - wp_data.object_type = OBJECT_LOAD_CONTROL; - wp_data.object_instance = instance; - wp_data.array_index = BACNET_ARRAY_ALL; - wp_data.priority = BACNET_NO_PRIORITY; - wp_data.object_property = PROP_START_TIME; - value.context_specific = false; - value.context_tag = 0; - value.tag = BACNET_APPLICATION_TAG_DATE; - datetime_date_wildcard_set(&value.type.Date); - wp_data.application_data_len = - bacapp_encode_data(&wp_data.application_data[0], &value); - ct_test(pTest, wp_data.application_data_len > 0); - len = wp_data.application_data_len; - value.tag = BACNET_APPLICATION_TAG_TIME; - datetime_time_wildcard_set(&value.type.Time); - wp_data.application_data_len = - bacapp_encode_data(&wp_data.application_data[len], &value); - ct_test(pTest, wp_data.application_data_len > 0); - wp_data.application_data_len += len; - status = Load_Control_Write_Property(&wp_data); - ct_test(pTest, status == true); -} - -static void Load_Control_WriteProperty_Start_Time(Test *pTest, - int instance, - uint16_t year, - uint8_t month, - uint8_t day, - uint8_t hour, - uint8_t minute, - uint8_t seconds, - uint8_t hundredths) -{ - int len = 0; - bool status = false; - BACNET_APPLICATION_DATA_VALUE value; - BACNET_WRITE_PROPERTY_DATA wp_data; - - wp_data.object_type = OBJECT_LOAD_CONTROL; - wp_data.object_instance = instance; - wp_data.array_index = BACNET_ARRAY_ALL; - wp_data.priority = BACNET_NO_PRIORITY; - wp_data.object_property = PROP_START_TIME; - value.context_specific = false; - value.context_tag = 0; - value.tag = BACNET_APPLICATION_TAG_DATE; - datetime_set_date(&value.type.Date, year, month, day); - wp_data.application_data_len = - bacapp_encode_data(&wp_data.application_data[0], &value); - ct_test(pTest, wp_data.application_data_len > 0); - len = wp_data.application_data_len; - value.tag = BACNET_APPLICATION_TAG_TIME; - datetime_set_time(&value.type.Time, hour, minute, seconds, hundredths); - wp_data.application_data_len = - bacapp_encode_data(&wp_data.application_data[len], &value); - ct_test(pTest, wp_data.application_data_len > 0); - wp_data.application_data_len += len; - status = Load_Control_Write_Property(&wp_data); - ct_test(pTest, status == true); -} - -void testLoadControlStateMachine(Test *pTest) -{ - unsigned i = 0, j = 0; - uint8_t level = 0; - - Load_Control_Init(); - /* validate the triggers for each state change */ - for (j = 0; j < 20; j++) { - Load_Control_State_Machine(0); - for (i = 0; i < MAX_LOAD_CONTROLS; i++) { - ct_test(pTest, Load_Control_State[i] == SHED_INACTIVE); - } - } - /* SHED_REQUEST_PENDING */ - /* CancelShed - Start time has wildcards */ - Load_Control_WriteProperty_Enable(pTest, 0, true); - Load_Control_WriteProperty_Shed_Duration(pTest, 0, 60); - Load_Control_WriteProperty_Start_Time_Wildcards(pTest, 0); - Load_Control_State_Machine(0); - ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING); - Load_Control_State_Machine(0); - ct_test(pTest, Load_Control_State[0] == SHED_INACTIVE); - - /* CancelShed - Requested_Shed_Level equal to default value */ - Load_Control_Init(); - Load_Control_WriteProperty_Request_Shed_Level(pTest, 0, 0); - Load_Control_WriteProperty_Start_Time(pTest, 0, 2007, 2, 27, 15, 0, 0, 0); - Load_Control_WriteProperty_Shed_Duration(pTest, 0, 5); - datetime_set_values(&Current_Time, 2007, 2, 27, 15, 0, 0, 0); - Load_Control_State_Machine(0); - ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING); - Load_Control_State_Machine(0); - ct_test(pTest, Load_Control_State[0] == SHED_INACTIVE); - - /* CancelShed - Non-default values, but Start time is passed */ - Load_Control_Init(); - Load_Control_WriteProperty_Enable(pTest, 0, true); - Load_Control_WriteProperty_Request_Shed_Level(pTest, 0, 1); - Load_Control_WriteProperty_Shed_Duration(pTest, 0, 5); - Load_Control_WriteProperty_Start_Time(pTest, 0, 2007, 2, 27, 15, 0, 0, 0); - datetime_set_values(&Current_Time, 2007, 2, 28, 15, 0, 0, 0); - Load_Control_State_Machine(0); - ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING); - Load_Control_State_Machine(0); - ct_test(pTest, Load_Control_State[0] == SHED_INACTIVE); - - /* ReconfigurePending - new write received while pending */ - Load_Control_Init(); - Load_Control_WriteProperty_Enable(pTest, 0, true); - Load_Control_WriteProperty_Request_Shed_Level(pTest, 0, 1); - Load_Control_WriteProperty_Shed_Duration(pTest, 0, 5); - Load_Control_WriteProperty_Start_Time(pTest, 0, 2007, 2, 27, 15, 0, 0, 0); - datetime_set_values(&Current_Time, 2007, 2, 27, 5, 0, 0, 0); - Load_Control_State_Machine(0); - ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING); - Load_Control_State_Machine(0); - ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING); - Load_Control_WriteProperty_Request_Shed_Level(pTest, 0, 2); - Load_Control_State_Machine(0); - ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING); - Load_Control_WriteProperty_Shed_Duration(pTest, 0, 6); - Load_Control_State_Machine(0); - ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING); - Load_Control_WriteProperty_Duty_Window(pTest, 0, 60); - Load_Control_State_Machine(0); - ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING); - Load_Control_WriteProperty_Start_Time(pTest, 0, 2007, 2, 27, 15, 0, 0, 1); - Load_Control_State_Machine(0); - ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING); - Load_Control_State_Machine(0); - ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING); - Load_Control_State_Machine(0); - ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING); - - /* CannotMeetShed -> FinishedUnsuccessfulShed */ - Load_Control_Init(); - Load_Control_WriteProperty_Enable(pTest, 0, true); - Load_Control_WriteProperty_Request_Shed_Level(pTest, 0, 1); - Load_Control_WriteProperty_Shed_Duration(pTest, 0, 120); - Load_Control_WriteProperty_Start_Time(pTest, 0, 2007, 2, 27, 15, 0, 0, 0); - datetime_set_values(&Current_Time, 2007, 2, 27, 5, 0, 0, 0); - Load_Control_State_Machine(0); - ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING); - Load_Control_State_Machine(0); - ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING); - /* set to lowest value so we cannot meet the shed level */ - datetime_set_values(&Current_Time, 2007, 2, 27, 16, 0, 0, 0); - Analog_Output_Present_Value_Set(0, 0, 16); - Load_Control_State_Machine(0); - ct_test(pTest, Load_Control_State[0] == SHED_NON_COMPLIANT); - Load_Control_State_Machine(0); - ct_test(pTest, Load_Control_State[0] == SHED_NON_COMPLIANT); - /* FinishedUnsuccessfulShed */ - datetime_set_values(&Current_Time, 2007, 2, 27, 23, 0, 0, 0); - Load_Control_State_Machine(0); - ct_test(pTest, Load_Control_State[0] == SHED_INACTIVE); - - /* CannotMeetShed -> UnsuccessfulShedReconfigured */ - Load_Control_Init(); - Load_Control_WriteProperty_Enable(pTest, 0, true); - Load_Control_WriteProperty_Request_Shed_Level(pTest, 0, 1); - Load_Control_WriteProperty_Shed_Duration(pTest, 0, 120); - Load_Control_WriteProperty_Start_Time(pTest, 0, 2007, 2, 27, 15, 0, 0, 0); - datetime_set_values(&Current_Time, 2007, 2, 27, 5, 0, 0, 0); - Load_Control_State_Machine(0); - ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING); - Load_Control_State_Machine(0); - ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING); - /* set to lowest value so we cannot meet the shed level */ - datetime_set_values(&Current_Time, 2007, 2, 27, 16, 0, 0, 0); - Analog_Output_Present_Value_Set(0, 0, 16); - Load_Control_State_Machine(0); - ct_test(pTest, Load_Control_State[0] == SHED_NON_COMPLIANT); - Load_Control_State_Machine(0); - ct_test(pTest, Load_Control_State[0] == SHED_NON_COMPLIANT); - /* FinishedUnsuccessfulShed */ - Load_Control_WriteProperty_Start_Time(pTest, 0, 2007, 2, 27, 16, 0, 0, 0); - Load_Control_State_Machine(0); - ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING); - Load_Control_State_Machine(0); - ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING); - datetime_set_values(&Current_Time, 2007, 2, 27, 16, 0, 1, 0); - Load_Control_State_Machine(0); - ct_test(pTest, Load_Control_State[0] == SHED_NON_COMPLIANT); - /* CanNowComplyWithShed */ - Analog_Output_Present_Value_Set(0, 100, 16); - datetime_set_values(&Current_Time, 2007, 2, 27, 16, 0, 2, 0); - Load_Control_State_Machine(0); - ct_test(pTest, Load_Control_State[0] == SHED_COMPLIANT); - level = Analog_Output_Present_Value(0); - ct_test(pTest, level == 90); - /* FinishedSuccessfulShed */ - datetime_set_values(&Current_Time, 2007, 2, 27, 23, 0, 0, 0); - Load_Control_State_Machine(0); - ct_test(pTest, Load_Control_State[0] == SHED_INACTIVE); - level = Analog_Output_Present_Value(0); - ct_test(pTest, level == 100); -} - -void testLoadControl(Test *pTest) -{ - uint8_t apdu[MAX_APDU] = { 0 }; - int len = 0; - uint32_t len_value = 0; - uint8_t tag_number = 0; - uint16_t decoded_type = 0; - uint32_t decoded_instance = 0; - BACNET_READ_PROPERTY_DATA rpdata; - - Analog_Output_Init(); - Load_Control_Init(); - rpdata.application_data = &apdu[0]; - rpdata.application_data_len = sizeof(apdu); - rpdata.object_type = OBJECT_LOAD_CONTROL; - rpdata.object_instance = 1; - rpdata.object_property = PROP_OBJECT_IDENTIFIER; - rpdata.array_index = BACNET_ARRAY_ALL; - len = Load_Control_Read_Property(&rpdata); - ct_test(pTest, len != 0); - len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); - ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); - len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance); - ct_test(pTest, decoded_type == rpdata.object_type); - ct_test(pTest, decoded_instance == rpdata.object_instance); - - return; -} - -#ifdef TEST_LOAD_CONTROL -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet Load Control", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testLoadControl); - assert(rc); - rc = ct_addTestFunction(pTest, testLoadControlStateMachine); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_LOAD_CONTROL */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/basic/object/lc.h b/src/bacnet/basic/object/lc.h index 2de02c57..270adfa3 100644 --- a/src/bacnet/basic/object/lc.h +++ b/src/bacnet/basic/object/lc.h @@ -79,13 +79,6 @@ extern "C" { bool Load_Control_Write_Property( BACNET_WRITE_PROPERTY_DATA * wp_data); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void testLoadControl( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/basic/object/lo.c b/src/bacnet/basic/object/lo.c index 19e23baf..73d242fe 100644 --- a/src/bacnet/basic/object/lo.c +++ b/src/bacnet/basic/object/lo.c @@ -1331,57 +1331,3 @@ void Lighting_Output_Init(void) return; } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -void testLightingOutput(Test *pTest) -{ - uint8_t apdu[MAX_APDU] = { 0 }; - int len = 0; - uint32_t len_value = 0; - uint8_t tag_number = 0; - uint16_t decoded_type = 0; - uint32_t decoded_instance = 0; - BACNET_READ_PROPERTY_DATA rpdata; - - Lighting_Output_Init(); - rpdata.application_data = &apdu[0]; - rpdata.application_data_len = sizeof(apdu); - rpdata.object_type = OBJECT_LIGHTING_OUTPUT; - rpdata.object_instance = 1; - rpdata.object_property = PROP_OBJECT_IDENTIFIER; - rpdata.array_index = BACNET_ARRAY_ALL; - len = Lighting_Output_Read_Property(&rpdata); - ct_test(pTest, len != 0); - len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); - ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); - len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance); - ct_test(pTest, decoded_type == rpdata.object_type); - ct_test(pTest, decoded_instance == rpdata.object_instance); - - return; -} - -#ifdef TEST_LIGHTING_OUTPUT -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet Lighting Output", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testLightingOutput); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_LIGHTING_INPUT */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/basic/object/lo.h b/src/bacnet/basic/object/lo.h index 1de879dc..af8751e5 100644 --- a/src/bacnet/basic/object/lo.h +++ b/src/bacnet/basic/object/lo.h @@ -216,13 +216,6 @@ extern "C" { bool Lighting_Output_Write_Property( BACNET_WRITE_PROPERTY_DATA * wp_data); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void testLightingOutput( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/basic/object/lsp.c b/src/bacnet/basic/object/lsp.c index f013799e..390f86ee 100644 --- a/src/bacnet/basic/object/lsp.c +++ b/src/bacnet/basic/object/lsp.c @@ -371,57 +371,3 @@ bool Life_Safety_Point_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) return status; } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -void testLifeSafetyPoint(Test *pTest) -{ - uint8_t apdu[MAX_APDU] = { 0 }; - int len = 0; - uint32_t len_value = 0; - uint8_t tag_number = 0; - uint16_t decoded_type = 0; - uint32_t decoded_instance = 0; - BACNET_READ_PROPERTY_DATA rpdata; - - Life_Safety_Point_Init(); - rpdata.application_data = &apdu[0]; - rpdata.application_data_len = sizeof(apdu); - rpdata.object_type = OBJECT_LIFE_SAFETY_POINT; - rpdata.object_instance = 1; - rpdata.object_property = PROP_OBJECT_IDENTIFIER; - rpdata.array_index = BACNET_ARRAY_ALL; - len = Life_Safety_Point_Read_Property(&rpdata); - ct_test(pTest, len != 0); - len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); - ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); - len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance); - ct_test(pTest, decoded_type == rpdata.object_type); - ct_test(pTest, decoded_instance == rpdata.object_instance); - - return; -} - -#ifdef TEST_LIFE_SAFETY_POINT -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet Life Safety Point", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testLifeSafetyPoint); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_LIFE_SAFETY_POINT */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/basic/object/lsp.h b/src/bacnet/basic/object/lsp.h index f54ef9a7..4a721323 100644 --- a/src/bacnet/basic/object/lsp.h +++ b/src/bacnet/basic/object/lsp.h @@ -70,13 +70,6 @@ extern "C" { bool Life_Safety_Point_Write_Property( BACNET_WRITE_PROPERTY_DATA * wp_data); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void testLifeSafetyPoint( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/basic/object/ms-input.c b/src/bacnet/basic/object/ms-input.c index f87deb53..75c0e3a3 100644 --- a/src/bacnet/basic/object/ms-input.c +++ b/src/bacnet/basic/object/ms-input.c @@ -727,64 +727,3 @@ bool Multistate_Input_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) return status; } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -bool Device_Valid_Object_Name(BACNET_CHARACTER_STRING *object_name, - int *object_type, - uint32_t *object_instance) -{ - return true; -} - -void testMultistateInput(Test *pTest) -{ - uint8_t apdu[MAX_APDU] = { 0 }; - int len = 0; - uint32_t len_value = 0; - uint8_t tag_number = 0; - uint16_t decoded_type = 0; - uint32_t decoded_instance = 0; - BACNET_READ_PROPERTY_DATA rpdata; - - Multistate_Input_Init(); - rpdata.application_data = &apdu[0]; - rpdata.application_data_len = sizeof(apdu); - rpdata.object_type = OBJECT_MULTI_STATE_INPUT; - rpdata.object_instance = 1; - rpdata.object_property = PROP_OBJECT_IDENTIFIER; - rpdata.array_index = BACNET_ARRAY_ALL; - len = Multistate_Input_Read_Property(&rpdata); - ct_test(pTest, len != 0); - len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); - ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); - len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance); - ct_test(pTest, decoded_type == rpdata.object_type); - ct_test(pTest, decoded_instance == rpdata.object_instance); - - return; -} - -#ifdef TEST_MULTISTATE_INPUT -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet Multi-state Input", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testMultistateInput); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif -#endif /* BAC_TEST */ diff --git a/src/bacnet/basic/object/ms-input.h b/src/bacnet/basic/object/ms-input.h index 608db7ac..0316e107 100644 --- a/src/bacnet/basic/object/ms-input.h +++ b/src/bacnet/basic/object/ms-input.h @@ -149,14 +149,6 @@ extern "C" { void Multistate_Input_Init( void); - -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void testMultistateInput( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/basic/object/mso.c b/src/bacnet/basic/object/mso.c index 4c130526..83c97ff1 100644 --- a/src/bacnet/basic/object/mso.c +++ b/src/bacnet/basic/object/mso.c @@ -464,57 +464,3 @@ bool Multistate_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) return status; } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -void testMultistateOutput(Test *pTest) -{ - uint8_t apdu[MAX_APDU] = { 0 }; - int len = 0; - uint32_t len_value = 0; - uint8_t tag_number = 0; - uint16_t decoded_type = 0; - uint32_t decoded_instance = 0; - BACNET_READ_PROPERTY_DATA rpdata; - - Multistate_Output_Init(); - 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.array_index = BACNET_ARRAY_ALL; - len = Multistate_Output_Read_Property(&rpdata); - ct_test(pTest, len != 0); - len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); - ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); - len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance); - ct_test(pTest, decoded_type == rpdata.object_type); - ct_test(pTest, decoded_instance == rpdata.object_instance); - - return; -} - -#ifdef TEST_MULTISTATE_OUTPUT -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet Multi-state Output", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testMultistateOutput); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_BINARY_INPUT */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/basic/object/mso.h b/src/bacnet/basic/object/mso.h index 53036f93..0d436504 100644 --- a/src/bacnet/basic/object/mso.h +++ b/src/bacnet/basic/object/mso.h @@ -126,14 +126,6 @@ extern "C" { uint32_t object_instance, uint32_t state_index); - -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void testMultistateOutput( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/basic/object/msv.c b/src/bacnet/basic/object/msv.c index 9d4a092f..a5de79e5 100644 --- a/src/bacnet/basic/object/msv.c +++ b/src/bacnet/basic/object/msv.c @@ -576,57 +576,3 @@ bool Multistate_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) return status; } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -void testMultistateInput(Test *pTest) -{ - uint8_t apdu[MAX_APDU] = { 0 }; - int len = 0; - uint32_t len_value = 0; - uint8_t tag_number = 0; - uint16_t decoded_type = 0; - uint32_t decoded_instance = 0; - BACNET_READ_PROPERTY_DATA rpdata; - - Multistate_Value_Init(); - rpdata.application_data = &apdu[0]; - rpdata.application_data_len = sizeof(apdu); - rpdata.object_type = OBJECT_MULTI_STATE_VALUE; - rpdata.object_instance = 1; - rpdata.object_property = PROP_OBJECT_IDENTIFIER; - rpdata.array_index = BACNET_ARRAY_ALL; - len = Multistate_Value_Read_Property(&rpdata); - ct_test(pTest, len != 0); - len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); - ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); - len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance); - ct_test(pTest, decoded_type == rpdata.object_type); - ct_test(pTest, decoded_instance == rpdata.object_instance); - - return; -} - -#ifdef TEST_MULTISTATE_VALUE -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet Multi-state Input", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testMultistateInput); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif -#endif /* BAC_TEST */ diff --git a/src/bacnet/basic/object/msv.h b/src/bacnet/basic/object/msv.h index 0d95924f..e35b06da 100644 --- a/src/bacnet/basic/object/msv.h +++ b/src/bacnet/basic/object/msv.h @@ -140,14 +140,6 @@ extern "C" { void Multistate_Value_Init( void); - -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void testMultistateValue( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/basic/object/netport.c b/src/bacnet/basic/object/netport.c index fdad2808..88f45cb5 100644 --- a/src/bacnet/basic/object/netport.c +++ b/src/bacnet/basic/object/netport.c @@ -2427,95 +2427,3 @@ void Network_Port_Init(void) { /* do something interesting */ } - -#ifdef BACNET_UNIT_TEST -#include -#include -#include "ctest.h" - -void test_network_port(Test *pTest) -{ - uint8_t apdu[MAX_APDU] = { 0 }; - int len = 0; - int test_len = 0; - BACNET_READ_PROPERTY_DATA rpdata; - /* for decode value data */ - BACNET_APPLICATION_DATA_VALUE value; - const int *pRequired = NULL; - const int *pOptional = NULL; - const int *pProprietary = NULL; - unsigned port = 0; - unsigned count = 0; - uint32_t object_instance = 0; - bool status = false; - uint8_t port_type[] = { PORT_TYPE_ETHERNET, PORT_TYPE_ARCNET, - PORT_TYPE_MSTP, PORT_TYPE_PTP, PORT_TYPE_LONTALK, PORT_TYPE_BIP, - PORT_TYPE_ZIGBEE, PORT_TYPE_VIRTUAL, PORT_TYPE_NON_BACNET, - PORT_TYPE_BIP6, PORT_TYPE_MAX }; - - while (port_type[port] != PORT_TYPE_MAX) { - object_instance = 1234; - status = Network_Port_Object_Instance_Number_Set(0, object_instance); - ct_test(pTest, status); - status = Network_Port_Type_Set(object_instance, port_type[port]); - ct_test(pTest, status); - Network_Port_Init(); - count = Network_Port_Count(); - ct_test(pTest, count > 0); - rpdata.application_data = &apdu[0]; - rpdata.application_data_len = sizeof(apdu); - rpdata.object_type = OBJECT_NETWORK_PORT; - rpdata.object_instance = object_instance; - Network_Port_Property_Lists(&pRequired, &pOptional, &pProprietary); - while ((*pRequired) != -1) { - rpdata.object_property = *pRequired; - rpdata.array_index = BACNET_ARRAY_ALL; - len = Network_Port_Read_Property(&rpdata); - ct_test(pTest, len != 0); - test_len = bacapp_decode_application_data(rpdata.application_data, - (uint8_t)rpdata.application_data_len, &value); - ct_test(pTest, test_len >= 0); - if (test_len < 0) { - printf("\n"); - } - pRequired++; - } - while ((*pOptional) != -1) { - rpdata.object_property = *pOptional; - rpdata.array_index = BACNET_ARRAY_ALL; - len = Network_Port_Read_Property(&rpdata); - ct_test(pTest, len != 0); - test_len = bacapp_decode_application_data(rpdata.application_data, - (uint8_t)rpdata.application_data_len, &value); - ct_test(pTest, test_len >= 0); - if (test_len < 0) { - printf("\n"); - } - pOptional++; - } - port++; - } - - return; -} - -#ifdef TEST_NETWORK_PORT -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet Network Port", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, test_network_port); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif -#endif /* BAC_TEST */ diff --git a/src/bacnet/basic/object/osv.c b/src/bacnet/basic/object/osv.c index 1cb7579b..31225fca 100644 --- a/src/bacnet/basic/object/osv.c +++ b/src/bacnet/basic/object/osv.c @@ -355,57 +355,3 @@ bool OctetString_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) void OctetString_Value_Intrinsic_Reporting(uint32_t object_instance) { } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -void testOctetString_Value(Test *pTest) -{ - BACNET_READ_PROPERTY_DATA rpdata; - uint8_t apdu[MAX_APDU] = { 0 }; - int len = 0; - uint32_t len_value = 0; - uint8_t tag_number = 0; - uint16_t decoded_type = 0; - uint32_t decoded_instance = 0; - - OctetString_Value_Init(); - rpdata.application_data = &apdu[0]; - rpdata.application_data_len = sizeof(apdu); - rpdata.object_type = OBJECT_OCTETSTRING_VALUE; - rpdata.object_instance = 1; - rpdata.object_property = PROP_OBJECT_IDENTIFIER; - rpdata.array_index = BACNET_ARRAY_ALL; - len = OctetString_Value_Read_Property(&rpdata); - ct_test(pTest, len != 0); - len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); - ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); - len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance); - ct_test(pTest, decoded_type == rpdata.object_type); - ct_test(pTest, decoded_instance == rpdata.object_instance); - - return; -} - -#ifdef TEST_OCTETSTRING_VALUE -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet OctetString Value", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testOctetString_Value); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_OCTETSTRING_VALUE */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/basic/object/osv.h b/src/bacnet/basic/object/osv.h index da088a37..7c478783 100644 --- a/src/bacnet/basic/object/osv.h +++ b/src/bacnet/basic/object/osv.h @@ -104,12 +104,6 @@ extern "C" { BACNET_STACK_EXPORT void OctetString_Value_Init(void); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void testOctetString_Value(Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/basic/object/piv.c b/src/bacnet/basic/object/piv.c index 97dc6934..10916a77 100644 --- a/src/bacnet/basic/object/piv.c +++ b/src/bacnet/basic/object/piv.c @@ -360,57 +360,3 @@ bool PositiveInteger_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) void PositiveInteger_Value_Intrinsic_Reporting(uint32_t object_instance) { } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -void testPositiveInteger_Value(Test *pTest) -{ - BACNET_READ_PROPERTY_DATA rpdata; - uint8_t apdu[MAX_APDU] = { 0 }; - int len = 0; - uint32_t len_value = 0; - uint8_t tag_number = 0; - uint16_t decoded_type = 0; - uint32_t decoded_instance = 0; - - PositiveInteger_Value_Init(); - rpdata.application_data = &apdu[0]; - rpdata.application_data_len = sizeof(apdu); - rpdata.object_type = OBJECT_POSITIVE_INTEGER_VALUE; - rpdata.object_instance = 1; - rpdata.object_property = PROP_OBJECT_IDENTIFIER; - rpdata.array_index = BACNET_ARRAY_ALL; - len = PositiveInteger_Value_Read_Property(&rpdata); - ct_test(pTest, len != 0); - len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); - ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); - len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance); - ct_test(pTest, decoded_type == rpdata.object_type); - ct_test(pTest, decoded_instance == rpdata.object_instance); - - return; -} - -#ifdef TEST_POSITIVEINTEGER_VALUE -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet PositiveInteger Value", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testPositiveInteger_Value); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_POSITIVEINTEGER_VALUE */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/basic/object/piv.h b/src/bacnet/basic/object/piv.h index 492f7e1f..5d647861 100644 --- a/src/bacnet/basic/object/piv.h +++ b/src/bacnet/basic/object/piv.h @@ -103,12 +103,6 @@ extern "C" { BACNET_STACK_EXPORT void PositiveInteger_Value_Init(void); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void testPositiveInteger_Value(Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/basic/object/schedule.c b/src/bacnet/basic/object/schedule.c index e6427cf4..214371a2 100644 --- a/src/bacnet/basic/object/schedule.c +++ b/src/bacnet/basic/object/schedule.c @@ -424,59 +424,3 @@ void Schedule_Recalculate_PV( desc->Present_Value = &desc->Schedule_Default; } } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -void testSchedule(Test *pTest) -{ - BACNET_READ_PROPERTY_DATA rpdata; - uint8_t apdu[MAX_APDU] = { 0 }; - int len = 0; - uint32_t len_value = 0; - uint8_t tag_number = 0; - uint16_t decoded_type = 0; - uint32_t decoded_instance = 0; - - Schedule_Init(); - rpdata.application_data = &apdu[0]; - rpdata.application_data_len = sizeof(apdu); - rpdata.object_type = OBJECT_SCHEDULE; - rpdata.object_instance = 1; - rpdata.object_property = PROP_OBJECT_IDENTIFIER; - rpdata.array_index = BACNET_ARRAY_ALL; - len = Schedule_Read_Property(&rpdata); - ct_test(pTest, len != 0); - len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); - ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); - len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance); - ct_test(pTest, decoded_type == rpdata.object_type); - ct_test(pTest, decoded_instance == rpdata.object_instance); - - return; -} - -#ifdef TEST_SCHEDULE - -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet Schedule", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testSchedule); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} - -#endif /* TEST_SCHEDULE */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/basic/sys/fifo.c b/src/bacnet/basic/sys/fifo.c index 566875a9..89f1f7ca 100644 --- a/src/bacnet/basic/sys/fifo.c +++ b/src/bacnet/basic/sys/fifo.c @@ -327,155 +327,3 @@ void FIFO_Init(FIFO_BUFFER *b, volatile uint8_t *buffer, unsigned buffer_len) return; } - -#ifdef BAC_TEST -#include -#include -#include -#include "ctest.h" - -/** - * Unit Test for the FIFO buffer - * - * @param pTest - test tracking pointer - */ -void testFIFOBuffer(Test *pTest) -{ - /* FIFO data structure */ - FIFO_BUFFER test_buffer = { 0 }; - volatile FIFO_DATA_STORE(data_store, 60) = { 0 }; - uint8_t add_data[40] = { "RoseSteveLouPatRachelJessicaDaniAmyHerb" }; - uint8_t test_add_data[40] = { 0 }; - uint8_t test_data = 0; - unsigned index = 0; - unsigned count = 0; - bool status = 0; - - ct_test(pTest, sizeof(data_store) == 64); - FIFO_Init(&test_buffer, data_store, sizeof(data_store)); - ct_test(pTest, FIFO_Empty(&test_buffer)); - - /* load the buffer */ - for (test_data = 0; test_data < sizeof(data_store); test_data++) { - ct_test(pTest, !FIFO_Full(&test_buffer)); - ct_test(pTest, FIFO_Available(&test_buffer, 1)); - status = FIFO_Put(&test_buffer, test_data); - ct_test(pTest, status == true); - ct_test(pTest, !FIFO_Empty(&test_buffer)); - } - /* not able to put any more */ - ct_test(pTest, FIFO_Full(&test_buffer)); - ct_test(pTest, !FIFO_Available(&test_buffer, 1)); - status = FIFO_Put(&test_buffer, 42); - ct_test(pTest, status == false); - /* unload the buffer */ - for (index = 0; index < sizeof(data_store); index++) { - ct_test(pTest, !FIFO_Empty(&test_buffer)); - test_data = FIFO_Peek(&test_buffer); - ct_test(pTest, test_data == index); - test_data = FIFO_Get(&test_buffer); - ct_test(pTest, test_data == index); - ct_test(pTest, FIFO_Available(&test_buffer, 1)); - ct_test(pTest, !FIFO_Full(&test_buffer)); - } - ct_test(pTest, FIFO_Empty(&test_buffer)); - test_data = FIFO_Get(&test_buffer); - ct_test(pTest, test_data == 0); - test_data = FIFO_Peek(&test_buffer); - ct_test(pTest, test_data == 0); - ct_test(pTest, FIFO_Empty(&test_buffer)); - /* test the ring around the buffer */ - for (index = 0; index < sizeof(data_store); index++) { - ct_test(pTest, FIFO_Empty(&test_buffer)); - ct_test(pTest, FIFO_Available(&test_buffer, 4)); - for (count = 1; count < 4; count++) { - test_data = count; - status = FIFO_Put(&test_buffer, test_data); - ct_test(pTest, status == true); - ct_test(pTest, !FIFO_Empty(&test_buffer)); - } - for (count = 1; count < 4; count++) { - ct_test(pTest, !FIFO_Empty(&test_buffer)); - test_data = FIFO_Peek(&test_buffer); - ct_test(pTest, test_data == count); - test_data = FIFO_Get(&test_buffer); - ct_test(pTest, test_data == count); - } - } - ct_test(pTest, FIFO_Empty(&test_buffer)); - /* test Add */ - ct_test(pTest, FIFO_Available(&test_buffer, sizeof(add_data))); - status = FIFO_Add(&test_buffer, add_data, sizeof(add_data)); - ct_test(pTest, status == true); - count = FIFO_Count(&test_buffer); - ct_test(pTest, count == sizeof(add_data)); - ct_test(pTest, !FIFO_Empty(&test_buffer)); - for (index = 0; index < sizeof(add_data); index++) { - /* unload the buffer */ - ct_test(pTest, !FIFO_Empty(&test_buffer)); - test_data = FIFO_Peek(&test_buffer); - ct_test(pTest, test_data == add_data[index]); - test_data = FIFO_Get(&test_buffer); - ct_test(pTest, test_data == add_data[index]); - } - ct_test(pTest, FIFO_Empty(&test_buffer)); - /* test Pull */ - ct_test(pTest, FIFO_Available(&test_buffer, sizeof(add_data))); - status = FIFO_Add(&test_buffer, add_data, sizeof(add_data)); - ct_test(pTest, status == true); - count = FIFO_Count(&test_buffer); - ct_test(pTest, count == sizeof(add_data)); - ct_test(pTest, !FIFO_Empty(&test_buffer)); - count = FIFO_Pull(&test_buffer, &test_add_data[0], sizeof(test_add_data)); - ct_test(pTest, FIFO_Empty(&test_buffer)); - ct_test(pTest, count == sizeof(test_add_data)); - for (index = 0; index < sizeof(add_data); index++) { - ct_test(pTest, test_add_data[index] == add_data[index]); - } - ct_test(pTest, FIFO_Available(&test_buffer, sizeof(add_data))); - status = FIFO_Add(&test_buffer, test_add_data, sizeof(add_data)); - ct_test(pTest, status == true); - ct_test(pTest, !FIFO_Empty(&test_buffer)); - for (index = 0; index < sizeof(add_data); index++) { - count = FIFO_Pull(&test_buffer, &test_add_data[0], 1); - ct_test(pTest, count == 1); - ct_test(pTest, test_add_data[0] == add_data[index]); - } - ct_test(pTest, FIFO_Empty(&test_buffer)); - /* test flush */ - status = FIFO_Add(&test_buffer, test_add_data, sizeof(test_add_data)); - ct_test(pTest, status == true); - ct_test(pTest, !FIFO_Empty(&test_buffer)); - FIFO_Flush(&test_buffer); - ct_test(pTest, FIFO_Empty(&test_buffer)); - - return; -} - -#ifdef TEST_FIFO_BUFFER -/** - * Main program entry for Unit Test - * - * @return returns 0 on success, and non-zero on fail. - */ -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("FIFO Buffer", NULL); - - /* individual tests */ - rc = ct_addTestFunction(pTest, testFIFOBuffer); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - - ct_destroy(pTest); - - return 0; -} -#endif -#endif diff --git a/src/bacnet/basic/sys/fifo.h b/src/bacnet/basic/sys/fifo.h index 1a147468..ae3547e8 100644 --- a/src/bacnet/basic/sys/fifo.h +++ b/src/bacnet/basic/sys/fifo.h @@ -108,13 +108,6 @@ extern "C" { volatile uint8_t * buffer, unsigned buffer_len); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void testFIFOBuffer( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/basic/sys/filename.c b/src/bacnet/basic/sys/filename.c index 4de98e4b..7a6e71f9 100644 --- a/src/bacnet/basic/sys/filename.c +++ b/src/bacnet/basic/sys/filename.c @@ -58,55 +58,3 @@ char *filename_remove_path(const char *filename_in) return filename_out; } - -#ifdef BAC_TEST -#include -#include - -#include "ctest.h" - -void testFilename(Test *pTest) -{ - char *data1 = "c:\\Joshua\\run"; - char *data2 = "/home/Anna/run"; - char *data3 = "c:\\Program Files\\Christopher\\run.exe"; - char *data4 = "//Mary/data/run"; - char *data5 = "bin\\run"; - char *filename = NULL; - - filename = filename_remove_path(data1); - ct_test(pTest, strcmp("run", filename) == 0); - filename = filename_remove_path(data2); - ct_test(pTest, strcmp("run", filename) == 0); - filename = filename_remove_path(data3); - ct_test(pTest, strcmp("run.exe", filename) == 0); - filename = filename_remove_path(data4); - ct_test(pTest, strcmp("run", filename) == 0); - filename = filename_remove_path(data5); - ct_test(pTest, strcmp("run", filename) == 0); - - return; -} - -#ifdef TEST_FILENAME -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("filename remove path", NULL); - - /* individual tests */ - rc = ct_addTestFunction(pTest, testFilename); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_FILENAME */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/basic/sys/key.c b/src/bacnet/basic/sys/key.c deleted file mode 100644 index f1d5e217..00000000 --- a/src/bacnet/basic/sys/key.c +++ /dev/null @@ -1,118 +0,0 @@ -/*####COPYRIGHTBEGIN#### - ------------------------------------------- - Copyright (C) 2003 Steve Karg - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to - The Free Software Foundation, Inc. - 59 Temple Place - Suite 330 - Boston, MA 02111-1307, USA. - - As a special exception, if other files instantiate templates or - use macros or inline functions from this file, or you compile - this file and link it with other works to produce a work based - on this file, this file does not by itself cause the resulting - work to be covered by the GNU General Public License. However - the source code for this file must still be made available in - accordance with section (3) of the GNU General Public License. - - This exception does not invalidate any other reasons why a work - based on this file might be covered by the GNU General Public - License. - ------------------------------------------- -####COPYRIGHTEND####*/ -/*#define BAC_TEST */ -/*#define TEST_KEY */ -#include "key.h" - -/** @file key.c Tests (only) of key encoding/decoding. */ - -#ifdef BAC_TEST -#include -#include - -#include "ctest.h" - -/* test the encode and decode macros */ -void testKeys(Test *pTest) -{ - int type, id; - int decoded_type, decoded_id; - KEY key; - - for (type = 0; type < KEY_TYPE_MAX; type++) { - for (id = 0; id < KEY_ID_MAX; id++) { - key = KEY_ENCODE(type, id); - decoded_type = KEY_DECODE_TYPE(key); - decoded_id = KEY_DECODE_ID(key); - ct_test(pTest, decoded_type == type); - ct_test(pTest, decoded_id == id); - } - } - - return; -} - -/* test the encode and decode macros */ -void testKeySample(Test *pTest) -{ - 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); - ct_test(pTest, decoded_type == type); - ct_test(pTest, decoded_id == id); - - id_index++; - } - id_index = 0; - type_index++; - } - - return; -} - -#ifdef TEST_KEY -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("key", NULL); - /* add the individual tests */ - /* rc = ct_addTestFunction(pTest, testKeys); */ - /* assert(rc); */ - rc = ct_addTestFunction(pTest, testKeySample); - assert(rc); - /* run all the tests */ - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - /* completed testing - cleanup */ - ct_destroy(pTest); - - return 0; -} -#endif /* LOCAL_TEST */ -#endif diff --git a/src/bacnet/basic/sys/keylist.c b/src/bacnet/basic/sys/keylist.c index 0e7dd8c9..5df6c2fc 100644 --- a/src/bacnet/basic/sys/keylist.c +++ b/src/bacnet/basic/sys/keylist.c @@ -497,312 +497,3 @@ void Keylist_Delete(OS_Keylist list) return; } - -#ifdef BAC_TEST -#include -#include - -#include "ctest.h" - -/* test the FIFO */ -static void testKeyListFIFO(Test *pTest) -{ - OS_Keylist list; - KEY key; - int index; - char *data1 = "Joshua"; - char *data2 = "Anna"; - char *data3 = "Mary"; - char *data; - - list = Keylist_Create(); - ct_test(pTest, list != NULL); - - key = 0; - index = Keylist_Data_Add(list, key, data1); - ct_test(pTest, index == 0); - index = Keylist_Data_Add(list, key, data2); - ct_test(pTest, index == 0); - index = Keylist_Data_Add(list, key, data3); - ct_test(pTest, index == 0); - - ct_test(pTest, Keylist_Count(list) == 3); - - data = Keylist_Data_Pop(list); - ct_test(pTest, data != NULL); - ct_test(pTest, strcmp(data, data1) == 0); - data = Keylist_Data_Pop(list); - ct_test(pTest, data != NULL); - ct_test(pTest, strcmp(data, data2) == 0); - data = Keylist_Data_Pop(list); - ct_test(pTest, data != NULL); - ct_test(pTest, strcmp(data, data3) == 0); - data = Keylist_Data_Pop(list); - ct_test(pTest, data == NULL); - data = Keylist_Data_Pop(list); - ct_test(pTest, data == NULL); - - Keylist_Delete(list); - - return; -} - -/* test the FILO */ -static void testKeyListFILO(Test *pTest) -{ - OS_Keylist list; - KEY key; - int index; - char *data1 = "Joshua"; - char *data2 = "Anna"; - char *data3 = "Mary"; - char *data; - - list = Keylist_Create(); - ct_test(pTest, list != NULL); - - key = 0; - index = Keylist_Data_Add(list, key, data1); - ct_test(pTest, index == 0); - index = Keylist_Data_Add(list, key, data2); - ct_test(pTest, index == 0); - index = Keylist_Data_Add(list, key, data3); - ct_test(pTest, index == 0); - - ct_test(pTest, Keylist_Count(list) == 3); - - data = Keylist_Data_Delete_By_Index(list, 0); - ct_test(pTest, data != NULL); - ct_test(pTest, strcmp(data, data3) == 0); - - data = Keylist_Data_Delete_By_Index(list, 0); - ct_test(pTest, data != NULL); - ct_test(pTest, strcmp(data, data2) == 0); - - data = Keylist_Data_Delete_By_Index(list, 0); - ct_test(pTest, data != NULL); - ct_test(pTest, strcmp(data, data1) == 0); - - data = Keylist_Data_Delete_By_Index(list, 0); - ct_test(pTest, data == NULL); - - data = Keylist_Data_Delete_By_Index(list, 0); - ct_test(pTest, data == NULL); - - Keylist_Delete(list); - - return; -} - -static void testKeyListDataKey(Test *pTest) -{ - OS_Keylist list; - KEY key; - KEY test_key; - int index; - char *data1 = "Joshua"; - char *data2 = "Anna"; - char *data3 = "Mary"; - char *data; - - list = Keylist_Create(); - ct_test(pTest, list != NULL); - - key = 1; - index = Keylist_Data_Add(list, key, data1); - ct_test(pTest, index == 0); - test_key = Keylist_Key(list, index); - ct_test(pTest, test_key == key); - - key = 2; - index = Keylist_Data_Add(list, key, data2); - ct_test(pTest, index == 1); - test_key = Keylist_Key(list, index); - ct_test(pTest, test_key == key); - - key = 3; - index = Keylist_Data_Add(list, key, data3); - ct_test(pTest, index == 2); - test_key = Keylist_Key(list, index); - ct_test(pTest, test_key == key); - - ct_test(pTest, Keylist_Count(list) == 3); - - /* look at the data */ - key = 2; - data = Keylist_Data(list, key); - ct_test(pTest, data != NULL); - ct_test(pTest, strcmp(data, data2) == 0); - - key = 1; - data = Keylist_Data(list, key); - ct_test(pTest, data != NULL); - ct_test(pTest, strcmp(data, data1) == 0); - - key = 3; - data = Keylist_Data(list, key); - ct_test(pTest, data != NULL); - ct_test(pTest, strcmp(data, data3) == 0); - - /* work the data */ - key = 2; - data = Keylist_Data_Delete(list, key); - ct_test(pTest, data != NULL); - ct_test(pTest, strcmp(data, data2) == 0); - data = Keylist_Data_Delete(list, key); - ct_test(pTest, data == NULL); - ct_test(pTest, Keylist_Count(list) == 2); - - key = 1; - data = Keylist_Data(list, key); - ct_test(pTest, data != NULL); - ct_test(pTest, strcmp(data, data1) == 0); - - key = 3; - data = Keylist_Data(list, key); - ct_test(pTest, data != NULL); - ct_test(pTest, strcmp(data, data3) == 0); - - /* cleanup */ - do { - data = Keylist_Data_Pop(list); - } while (data); - - Keylist_Delete(list); - - return; -} - -static void testKeyListDataIndex(Test *pTest) -{ - OS_Keylist list; - KEY key; - int index; - char *data1 = "Joshua"; - char *data2 = "Anna"; - char *data3 = "Mary"; - char *data; - - list = Keylist_Create(); - ct_test(pTest, list != NULL); - - key = 0; - index = Keylist_Data_Add(list, key, data1); - ct_test(pTest, index == 0); - index = Keylist_Data_Add(list, key, data2); - ct_test(pTest, index == 0); - index = Keylist_Data_Add(list, key, data3); - ct_test(pTest, index == 0); - - ct_test(pTest, Keylist_Count(list) == 3); - - /* look at the data */ - data = Keylist_Data_Index(list, 0); - ct_test(pTest, data != NULL); - ct_test(pTest, strcmp(data, data3) == 0); - - data = Keylist_Data_Index(list, 1); - ct_test(pTest, data != NULL); - ct_test(pTest, strcmp(data, data2) == 0); - - data = Keylist_Data_Index(list, 2); - ct_test(pTest, data != NULL); - ct_test(pTest, strcmp(data, data1) == 0); - - /* work the data */ - data = Keylist_Data_Delete_By_Index(list, 1); - ct_test(pTest, data != NULL); - ct_test(pTest, strcmp(data, data2) == 0); - - ct_test(pTest, Keylist_Count(list) == 2); - - data = Keylist_Data_Index(list, 0); - ct_test(pTest, data != NULL); - ct_test(pTest, strcmp(data, data3) == 0); - - data = Keylist_Data_Index(list, 1); - ct_test(pTest, data != NULL); - ct_test(pTest, strcmp(data, data1) == 0); - - data = Keylist_Data_Delete_By_Index(list, 1); - ct_test(pTest, data != NULL); - ct_test(pTest, strcmp(data, data1) == 0); - - data = Keylist_Data_Delete_By_Index(list, 1); - ct_test(pTest, data == NULL); - - /* cleanup */ - do { - data = Keylist_Data_Pop(list); - } while (data); - - Keylist_Delete(list); - - return; -} - -/* test access of a lot of entries */ -static void testKeyListLarge(Test *pTest) -{ - int data1 = 42; - int *data; - OS_Keylist list; - KEY key; - int index; - const unsigned num_keys = 1024 * 16; - - list = Keylist_Create(); - if (!list) - return; - - for (key = 0; key < num_keys; key++) { - index = Keylist_Data_Add(list, key, &data1); - } - for (key = 0; key < num_keys; key++) { - data = Keylist_Data(list, key); - ct_test(pTest, *data == data1); - } - for (index = 0; index < num_keys; index++) { - data = Keylist_Data_Index(list, index); - ct_test(pTest, *data == data1); - } - Keylist_Delete(list); - - return; -} - -/* test access of a lot of entries */ -void testKeyList(Test *pTest) -{ - bool rc; - - /* individual tests */ - rc = ct_addTestFunction(pTest, testKeyListFIFO); - assert(rc); - rc = ct_addTestFunction(pTest, testKeyListFILO); - assert(rc); - rc = ct_addTestFunction(pTest, testKeyListDataKey); - assert(rc); - rc = ct_addTestFunction(pTest, testKeyListDataIndex); - assert(rc); - rc = ct_addTestFunction(pTest, testKeyListLarge); - assert(rc); -} - -#ifdef TEST_KEYLIST -int main(void) -{ - Test *pTest; - - pTest = ct_create("keylist", NULL); - testKeyList(pTest); - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_KEYLIST */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/basic/sys/keylist.h b/src/bacnet/basic/sys/keylist.h index e764e741..d832949d 100644 --- a/src/bacnet/basic/sys/keylist.h +++ b/src/bacnet/basic/sys/keylist.h @@ -121,13 +121,6 @@ extern "C" { int Keylist_Count( OS_Keylist list); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void testKeyList( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/basic/sys/ringbuf.c b/src/bacnet/basic/sys/ringbuf.c index c6b40fa6..777ecdfa 100644 --- a/src/bacnet/basic/sys/ringbuf.c +++ b/src/bacnet/basic/sys/ringbuf.c @@ -454,370 +454,3 @@ bool Ringbuf_Init(RING_BUFFER *b, return status; } - -#ifdef BAC_TEST -#include -#include -#include -#include "ctest.h" - -/** - * Unit Test for the ring buffer - * - * @param pTest - test tracking pointer - * @param test_buffer - pointer to RING_BUFFER structure - * @param data_element - one data element - * @param element_size - size of one data element - * @param element_count - number of data elements in the store - */ -static void testRingAroundBuffer(Test *pTest, - RING_BUFFER *test_buffer, - uint8_t *data_element, - unsigned element_size, - unsigned element_count) -{ - volatile uint8_t *test_data; - unsigned index; - unsigned data_index; - unsigned count; - uint8_t value; - bool status; - - ct_test(pTest, Ringbuf_Empty(test_buffer)); - /* test the ring around the buffer */ - for (index = 0; index < element_count; index++) { - for (count = 1; count < 4; count++) { - value = (index * count) % 255; - for (data_index = 0; data_index < element_size; data_index++) { - data_element[data_index] = value; - } - status = Ringbuf_Put(test_buffer, data_element); - ct_test(pTest, status == true); - ct_test(pTest, Ringbuf_Count(test_buffer) == count); - } - for (count = 1; count < 4; count++) { - value = (index * count) % 255; - test_data = Ringbuf_Peek(test_buffer); - ct_test(pTest, test_data); - if (test_data) { - for (data_index = 0; data_index < element_size; data_index++) { - ct_test(pTest, test_data[data_index] == value); - } - } - status = Ringbuf_Pop(test_buffer, NULL); - ct_test(pTest, status == true); - } - } - ct_test(pTest, Ringbuf_Empty(test_buffer)); -} - -/** - * Unit Test for the ring buffer - * - * @param pTest - test tracking pointer - * @param data_store - buffer to store elements - * @param data_element - one data element - * @param element_size - size of one data element - * @param element_count - number of data elements in the store - */ -static bool testRingBuf(Test *pTest, - uint8_t *data_store, - uint8_t *data_element, - unsigned element_size, - unsigned element_count) -{ - RING_BUFFER test_buffer; - volatile uint8_t *test_data; - unsigned index; - unsigned data_index; - bool status; - - status = - Ringbuf_Init(&test_buffer, data_store, element_size, element_count); - if (!status) { - return false; - } - ct_test(pTest, Ringbuf_Empty(&test_buffer)); - ct_test(pTest, Ringbuf_Depth(&test_buffer) == 0); - - for (data_index = 0; data_index < element_size; data_index++) { - data_element[data_index] = data_index; - } - status = Ringbuf_Put(&test_buffer, data_element); - ct_test(pTest, status == true); - ct_test(pTest, !Ringbuf_Empty(&test_buffer)); - ct_test(pTest, Ringbuf_Depth(&test_buffer) == 1); - - test_data = Ringbuf_Peek(&test_buffer); - for (data_index = 0; data_index < element_size; data_index++) { - ct_test(pTest, test_data[data_index] == data_element[data_index]); - } - ct_test(pTest, !Ringbuf_Empty(&test_buffer)); - (void)Ringbuf_Pop(&test_buffer, NULL); - ct_test(pTest, Ringbuf_Empty(&test_buffer)); - ct_test(pTest, Ringbuf_Depth(&test_buffer) == 1); - - /* fill to max */ - for (index = 0; index < element_count; index++) { - for (data_index = 0; data_index < element_size; data_index++) { - data_element[data_index] = index; - } - status = Ringbuf_Put(&test_buffer, data_element); - ct_test(pTest, status == true); - ct_test(pTest, !Ringbuf_Empty(&test_buffer)); - ct_test(pTest, Ringbuf_Depth(&test_buffer) == (index + 1)); - } - ct_test(pTest, Ringbuf_Depth(&test_buffer) == element_count); - /* verify actions on full buffer */ - for (index = 0; index < element_count; index++) { - for (data_index = 0; data_index < element_size; data_index++) { - data_element[data_index] = index; - } - status = Ringbuf_Put(&test_buffer, data_element); - ct_test(pTest, status == false); - ct_test(pTest, !Ringbuf_Empty(&test_buffer)); - ct_test(pTest, Ringbuf_Depth(&test_buffer) == element_count); - } - - /* check buffer full */ - for (index = 0; index < element_count; index++) { - test_data = Ringbuf_Peek(&test_buffer); - ct_test(pTest, test_data); - if (test_data) { - for (data_index = 0; data_index < element_size; data_index++) { - ct_test(pTest, test_data[data_index] == index); - } - } - (void)Ringbuf_Pop(&test_buffer, NULL); - } - ct_test(pTest, Ringbuf_Empty(&test_buffer)); - ct_test(pTest, Ringbuf_Depth(&test_buffer) == element_count); - Ringbuf_Depth_Reset(&test_buffer); - ct_test(pTest, Ringbuf_Depth(&test_buffer) == 0); - - testRingAroundBuffer( - pTest, &test_buffer, data_element, element_size, element_count); - - /* adjust the internal index of Ringbuf to test unsigned wrapping */ - test_buffer.head = UINT_MAX - 1; - test_buffer.tail = UINT_MAX - 1; - - testRingAroundBuffer( - pTest, &test_buffer, data_element, element_size, element_count); - - return true; -} - -/** - * Unit Test for the ring buffer with 16 data elements - * - * @param pTest - test tracking pointer - */ -void testRingBufSizeSmall(Test *pTest) -{ - bool status; - uint8_t data_element[5]; - uint8_t data_store[sizeof(data_element) * NEXT_POWER_OF_2(16)]; - - status = testRingBuf(pTest, data_store, data_element, sizeof(data_element), - sizeof(data_store) / sizeof(data_element)); - ct_test(pTest, status); -} - -/** - * Unit Test for the ring buffer with 32 data elements - * - * @param pTest - test tracking pointer - */ -void testRingBufSizeLarge(Test *pTest) -{ - bool status; - uint8_t data_element[16]; - uint8_t data_store[sizeof(data_element) * NEXT_POWER_OF_2(99)]; - - status = testRingBuf(pTest, data_store, data_element, sizeof(data_element), - sizeof(data_store) / sizeof(data_element)); - ct_test(pTest, status); -} - -/** - * Unit Test for the ring buffer with 32 data elements - * - * @param pTest - test tracking pointer - */ -void testRingBufSizeInvalid(Test *pTest) -{ - bool status; - uint8_t data_element[16]; - uint8_t data_store[sizeof(data_element) * 99]; - - status = testRingBuf(pTest, data_store, data_element, sizeof(data_element), - sizeof(data_store) / sizeof(data_element)); - ct_test(pTest, status == false); -} - -void testRingBufPowerOfTwo(Test *pTest) -{ - ct_test(pTest, NEXT_POWER_OF_2(3) == 4); - ct_test(pTest, NEXT_POWER_OF_2(100) == 128); - ct_test(pTest, NEXT_POWER_OF_2(127) == 128); - ct_test(pTest, NEXT_POWER_OF_2(128) == 128); - ct_test(pTest, NEXT_POWER_OF_2(129) == 256); - ct_test(pTest, NEXT_POWER_OF_2(300) == 512); - ct_test(pTest, NEXT_POWER_OF_2(500) == 512); -} - -/** - * Unit Test for the ring buffer peek/pop next element - * - * @param pTest - test tracking pointer - * @param data_store - buffer to store elements - * @param data_element - one data element - * @param element_size - size of one data element - * @param element_count - number of data elements in the store - */ -static bool testRingBufNextElement(Test *pTest, - uint8_t *data_store, - uint8_t *data_element, - unsigned element_size, - unsigned element_count) -{ - RING_BUFFER test_buffer; - volatile uint8_t *test_data; - unsigned index; - unsigned data_index; - bool status; - status = - Ringbuf_Init(&test_buffer, data_store, element_size, element_count); - if (!status) { - return false; - } - ct_test(pTest, Ringbuf_Empty(&test_buffer)); - ct_test(pTest, Ringbuf_Depth(&test_buffer) == 0); - - for (data_index = 0; data_index < element_size; data_index++) { - data_element[data_index] = data_index; - } - status = Ringbuf_Put(&test_buffer, data_element); - ct_test(pTest, status == true); - ct_test(pTest, !Ringbuf_Empty(&test_buffer)); - ct_test(pTest, Ringbuf_Depth(&test_buffer) == 1); - - test_data = Ringbuf_Peek(&test_buffer); - for (data_index = 0; data_index < element_size; data_index++) { - ct_test(pTest, test_data[data_index] == data_element[data_index]); - } - ct_test(pTest, !Ringbuf_Empty(&test_buffer)); - (void)Ringbuf_Pop(&test_buffer, NULL); - ct_test(pTest, Ringbuf_Empty(&test_buffer)); - ct_test(pTest, Ringbuf_Depth(&test_buffer) == 1); - - /* fill to max */ - for (index = 0; index < element_count; index++) { - for (data_index = 0; data_index < element_size; data_index++) { - data_element[data_index] = index; - } - status = Ringbuf_Put(&test_buffer, data_element); - ct_test(pTest, status == true); - ct_test(pTest, !Ringbuf_Empty(&test_buffer)); - ct_test(pTest, Ringbuf_Depth(&test_buffer) == (index + 1)); - } - ct_test(pTest, Ringbuf_Depth(&test_buffer) == element_count); - ct_test(pTest, Ringbuf_Count(&test_buffer) == element_count); - - /* Walk through ring buffer */ - test_data = Ringbuf_Peek(&test_buffer); - ct_test(pTest, test_data); - for (index = 1; index < element_count; index++) { - test_data = Ringbuf_Peek_Next(&test_buffer, (uint8_t *)test_data); - ct_test(pTest, test_data); - if (test_data) { - for (data_index = 0; data_index < element_size; data_index++) { - ct_test(pTest, test_data[data_index] == index); - } - } - } - ct_test(pTest, Ringbuf_Count(&test_buffer) == element_count); - /* Try to walk off end of buffer - should return NULL */ - test_data = Ringbuf_Peek_Next(&test_buffer, (uint8_t *)test_data); - ct_test(pTest, (test_data == NULL)); - - /* Walk through ring buffer and pop alternate elements */ - test_data = Ringbuf_Peek(&test_buffer); - ct_test(pTest, test_data); - for (index = 1; index < element_count / 2; index++) { - test_data = Ringbuf_Peek_Next(&test_buffer, (uint8_t *)test_data); - ct_test(pTest, test_data); - (void)Ringbuf_Pop_Element(&test_buffer, (uint8_t *)test_data, NULL); - test_data = Ringbuf_Peek_Next(&test_buffer, (uint8_t *)test_data); - } - ct_test(pTest, Ringbuf_Count(&test_buffer) == element_count / 2 + 1); - - /* Walk through ring buffer and check data */ - test_data = Ringbuf_Peek(&test_buffer); - ct_test(pTest, test_data); - for (index = 0; index < element_count / 2; index++) { - if (test_data) { - for (data_index = 0; data_index < element_size; data_index++) { - ct_test(pTest, test_data[data_index] == index * 2); - } - } - test_data = Ringbuf_Peek_Next(&test_buffer, (uint8_t *)test_data); - ct_test(pTest, test_data); - } - ct_test(pTest, Ringbuf_Count(&test_buffer) == element_count / 2 + 1); - - return true; -} - -/** - * Unit Test for the ring buffer with 16 data elements - * - * @param pTest - test tracking pointer - */ -void testRingBufNextElementSizeSmall(Test *pTest) -{ - bool status; - uint8_t data_element[5]; - uint8_t data_store[sizeof(data_element) * NEXT_POWER_OF_2(16)]; - - status = testRingBufNextElement(pTest, data_store, data_element, - sizeof(data_element), sizeof(data_store) / sizeof(data_element)); - ct_test(pTest, status); -} - -#ifdef TEST_RING_BUFFER -/** - * Main program entry for Unit Test - * - * @return returns 0 on success, and non-zero on fail. - */ -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("Ring Buffer", NULL); - - /* individual tests */ - rc = ct_addTestFunction(pTest, testRingBufPowerOfTwo); - assert(rc); - rc = ct_addTestFunction(pTest, testRingBufSizeSmall); - assert(rc); - rc = ct_addTestFunction(pTest, testRingBufSizeLarge); - assert(rc); - rc = ct_addTestFunction(pTest, testRingBufSizeInvalid); - assert(rc); - rc = ct_addTestFunction(pTest, testRingBufNextElementSizeSmall); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - - ct_destroy(pTest); - - return 0; -} -#endif -#endif diff --git a/src/bacnet/basic/sys/ringbuf.h b/src/bacnet/basic/sys/ringbuf.h index cab6fc4c..94568551 100644 --- a/src/bacnet/basic/sys/ringbuf.h +++ b/src/bacnet/basic/sys/ringbuf.h @@ -96,18 +96,6 @@ extern "C" { unsigned element_size, unsigned element_count); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void testRingBufPowerOfTwo(Test * pTest); - BACNET_STACK_EXPORT - void testRingBufSizeSmall(Test * pTest); - BACNET_STACK_EXPORT - void testRingBufSizeLarge(Test * pTest); - BACNET_STACK_EXPORT - void testRingBufSizeInvalid(Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/basic/sys/sbuf.c b/src/bacnet/basic/sys/sbuf.c index 80c7ad44..87c10445 100644 --- a/src/bacnet/basic/sys/sbuf.c +++ b/src/bacnet/basic/sys/sbuf.c @@ -129,84 +129,3 @@ bool sbuf_truncate(STATIC_BUFFER *b, /* static buffer structure */ return status; } - -#ifdef BAC_TEST -#include -#include - -#include "ctest.h" - -void testStaticBuffer(Test *pTest) -{ - STATIC_BUFFER sbuffer; - char *data1 = "Joshua"; - char *data2 = "Anna"; - char *data3 = "Christopher"; - char *data4 = "Mary"; - char data_buffer[480] = ""; - char test_data_buffer[480] = ""; - char *data; - unsigned count; - - sbuf_init(&sbuffer, NULL, 0); - ct_test(pTest, sbuf_empty(&sbuffer) == true); - ct_test(pTest, sbuf_data(&sbuffer) == NULL); - ct_test(pTest, sbuf_size(&sbuffer) == 0); - ct_test(pTest, sbuf_count(&sbuffer) == 0); - ct_test(pTest, sbuf_append(&sbuffer, data1, strlen(data1)) == false); - - sbuf_init(&sbuffer, data_buffer, sizeof(data_buffer)); - ct_test(pTest, sbuf_empty(&sbuffer) == true); - ct_test(pTest, sbuf_data(&sbuffer) == data_buffer); - ct_test(pTest, sbuf_size(&sbuffer) == sizeof(data_buffer)); - ct_test(pTest, sbuf_count(&sbuffer) == 0); - - ct_test(pTest, sbuf_append(&sbuffer, data1, strlen(data1)) == true); - ct_test(pTest, sbuf_append(&sbuffer, data2, strlen(data2)) == true); - ct_test(pTest, sbuf_append(&sbuffer, data3, strlen(data3)) == true); - ct_test(pTest, sbuf_append(&sbuffer, data4, strlen(data4)) == true); - strcat(test_data_buffer, data1); - strcat(test_data_buffer, data2); - strcat(test_data_buffer, data3); - strcat(test_data_buffer, data4); - ct_test(pTest, sbuf_count(&sbuffer) == strlen(test_data_buffer)); - - data = sbuf_data(&sbuffer); - count = sbuf_count(&sbuffer); - ct_test(pTest, memcmp(data, test_data_buffer, count) == 0); - ct_test(pTest, count == strlen(test_data_buffer)); - - ct_test(pTest, sbuf_truncate(&sbuffer, 0) == true); - ct_test(pTest, sbuf_count(&sbuffer) == 0); - ct_test(pTest, sbuf_size(&sbuffer) == sizeof(data_buffer)); - ct_test(pTest, sbuf_append(&sbuffer, data4, strlen(data4)) == true); - data = sbuf_data(&sbuffer); - count = sbuf_count(&sbuffer); - ct_test(pTest, memcmp(data, data4, count) == 0); - ct_test(pTest, count == strlen(data4)); - - return; -} - -#ifdef TEST_STATIC_BUFFER -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("static buffer", NULL); - - /* individual tests */ - rc = ct_addTestFunction(pTest, testStaticBuffer); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_STATIC_BUFFER */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/basic/tsm/tsm.c b/src/bacnet/basic/tsm/tsm.c index c4a1eea6..730ab626 100644 --- a/src/bacnet/basic/tsm/tsm.c +++ b/src/bacnet/basic/tsm/tsm.c @@ -414,59 +414,4 @@ bool tsm_invoke_id_failed(uint8_t invokeID) return status; } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -/* flag to send an I-Am */ -bool I_Am_Request = true; - -/* dummy function stubs */ -int datalink_send_pdu(BACNET_ADDRESS *dest, - BACNET_NPDU_DATA *npdu_data, - uint8_t *pdu, - unsigned pdu_len) -{ - (void)dest; - (void)npdu_data; - (void)pdu; - (void)pdu_len; - - return 0; -} - -/* dummy function stubs */ -void datalink_get_broadcast_address(BACNET_ADDRESS *dest) -{ - (void)dest; -} - -void testTSM(Test *pTest) -{ - /* FIXME: add some unit testing... */ - return; -} - -#ifdef TEST_TSM -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet TSM", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testTSM); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_TSM */ -#endif /* BAC_TEST */ -#endif /* MAX_TSM_TRANSACTIONS */ +#endif \ No newline at end of file diff --git a/src/bacnet/config.h b/src/bacnet/config.h index 0946dadc..ce3dba69 100644 --- a/src/bacnet/config.h +++ b/src/bacnet/config.h @@ -203,15 +203,11 @@ */ /* -** First we see if this is a test build and enable all the services as they -** may be required. -** -** Note: I've left everything enabled here in the main config.h. You should +** Note: I've left everything enabled here in the default config.h. You should ** use a local copy of config.h with settings configured for your needs to -** make use of the code space reductions. +** make use of any code space reductions in your device. **/ -#ifdef BAC_TEST #define BACNET_SVC_I_HAVE_A 1 #define BACNET_SVC_WP_A 1 #define BACNET_SVC_RP_A 1 @@ -223,19 +219,6 @@ #define BACNET_USE_OCTETSTRING 1 #define BACNET_USE_DOUBLE 1 #define BACNET_USE_SIGNED 1 -#else /* Otherwise define our working set - all enabled here to avoid breaking things */ -#define BACNET_SVC_I_HAVE_A 1 -#define BACNET_SVC_WP_A 1 -#define BACNET_SVC_RP_A 1 -#define BACNET_SVC_RPM_A 1 -#define BACNET_SVC_DCC_A 1 -#define BACNET_SVC_RD_A 1 -#define BACNET_SVC_TS_A 1 -#define BACNET_SVC_SERVER 0 -#define BACNET_USE_OCTETSTRING 1 -#define BACNET_USE_DOUBLE 1 -#define BACNET_USE_SIGNED 1 -#endif /* Do them one by one */ #ifndef BACNET_SVC_I_HAVE_A /* Do we send I_Have requests? */ diff --git a/src/bacnet/cov.c b/src/bacnet/cov.c index cf170b70..58b3e61c 100644 --- a/src/bacnet/cov.c +++ b/src/bacnet/cov.c @@ -983,374 +983,3 @@ bool cov_value_list_encode_character_string( return status; } #endif - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" -#include "bacnet/bacapp.h" - -int ccov_notify_decode_apdu( - uint8_t *apdu, unsigned apdu_len, uint8_t *invoke_id, BACNET_COV_DATA *data) -{ - int len = 0; - unsigned offset = 0; - - if (!apdu) { - return -1; - } - /* optional checking - most likely was already done prior to this call */ - if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) - return -2; - /* apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); */ - *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ - if (apdu[3] != SERVICE_CONFIRMED_COV_NOTIFICATION) - return -3; - offset = 4; - - /* optional limits - must be used as a pair */ - if (apdu_len > offset) { - len = cov_notify_decode_service_request( - &apdu[offset], apdu_len - offset, data); - } - - return len; -} - -int ucov_notify_decode_apdu( - uint8_t *apdu, unsigned apdu_len, BACNET_COV_DATA *data) -{ - int len = 0; - unsigned offset = 0; - - if (!apdu) - return -1; - /* optional checking - most likely was already done prior to this call */ - if (apdu[0] != PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST) - return -2; - if (apdu[1] != SERVICE_UNCONFIRMED_COV_NOTIFICATION) - return -3; - /* optional limits - must be used as a pair */ - offset = 2; - if (apdu_len > offset) { - len = cov_notify_decode_service_request( - &apdu[offset], apdu_len - offset, data); - } - - return len; -} - -int cov_subscribe_decode_apdu(uint8_t *apdu, - unsigned apdu_len, - uint8_t *invoke_id, - BACNET_SUBSCRIBE_COV_DATA *data) -{ - int len = 0; - unsigned offset = 0; - - if (!apdu) - return -1; - /* optional checking - most likely was already done prior to this call */ - if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) - return -2; - /* apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); */ - *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ - if (apdu[3] != SERVICE_CONFIRMED_SUBSCRIBE_COV) - return -3; - offset = 4; - - /* optional limits - must be used as a pair */ - if (apdu_len > offset) { - len = cov_subscribe_decode_service_request( - &apdu[offset], apdu_len - offset, data); - } - - return len; -} - -int cov_subscribe_property_decode_apdu(uint8_t *apdu, - unsigned apdu_len, - uint8_t *invoke_id, - BACNET_SUBSCRIBE_COV_DATA *data) -{ - int len = 0; - unsigned offset = 0; - - if (!apdu) - return -1; - /* optional checking - most likely was already done prior to this call */ - if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) - return -2; - /* apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); */ - *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ - if (apdu[3] != SERVICE_CONFIRMED_SUBSCRIBE_COV_PROPERTY) - return -3; - offset = 4; - - /* optional limits - must be used as a pair */ - if (apdu_len > offset) { - len = cov_subscribe_property_decode_service_request( - &apdu[offset], apdu_len - offset, data); - } - - return len; -} - -/* dummy function stubs */ -void testCOVNotifyData( - Test *pTest, BACNET_COV_DATA *data, BACNET_COV_DATA *test_data) -{ - BACNET_PROPERTY_VALUE *value = NULL; - BACNET_PROPERTY_VALUE *test_value = NULL; - - ct_test(pTest, - test_data->subscriberProcessIdentifier == - data->subscriberProcessIdentifier); - ct_test(pTest, - test_data->initiatingDeviceIdentifier == - data->initiatingDeviceIdentifier); - ct_test(pTest, - test_data->monitoredObjectIdentifier.type == - data->monitoredObjectIdentifier.type); - ct_test(pTest, - test_data->monitoredObjectIdentifier.instance == - data->monitoredObjectIdentifier.instance); - ct_test(pTest, test_data->timeRemaining == data->timeRemaining); - /* test the listOfValues in some clever manner */ - value = data->listOfValues; - test_value = test_data->listOfValues; - while (value) { - ct_test(pTest, test_value); - if (test_value) { - ct_test(pTest, - test_value->propertyIdentifier == value->propertyIdentifier); - ct_test(pTest, - test_value->propertyArrayIndex == value->propertyArrayIndex); - ct_test(pTest, test_value->priority == value->priority); - ct_test( - pTest, bacapp_same_value(&test_value->value, &value->value)); - test_value = test_value->next; - } - value = value->next; - } -} - -void testUCOVNotifyData(Test *pTest, BACNET_COV_DATA *data) -{ - uint8_t apdu[480] = { 0 }; - int len = 0; - int apdu_len = 0; - BACNET_COV_DATA test_data; - BACNET_PROPERTY_VALUE value_list[5] = { { 0 } }; - - len = ucov_notify_encode_apdu(&apdu[0], sizeof(apdu), data); - ct_test(pTest, len > 0); - apdu_len = len; - - cov_data_value_list_link(&test_data, &value_list[0], 5); - len = ucov_notify_decode_apdu(&apdu[0], apdu_len, &test_data); - ct_test(pTest, len != -1); - testCOVNotifyData(pTest, data, &test_data); -} - -void testCCOVNotifyData(Test *pTest, uint8_t invoke_id, BACNET_COV_DATA *data) -{ - uint8_t apdu[480] = { 0 }; - int len = 0; - int apdu_len = 0; - BACNET_COV_DATA test_data; - BACNET_PROPERTY_VALUE value_list[2] = { { 0 } }; - uint8_t test_invoke_id = 0; - - len = ccov_notify_encode_apdu(&apdu[0], sizeof(apdu), invoke_id, data); - ct_test(pTest, len != 0); - apdu_len = len; - - cov_data_value_list_link(&test_data, &value_list[0], 2); - len = ccov_notify_decode_apdu( - &apdu[0], apdu_len, &test_invoke_id, &test_data); - ct_test(pTest, len > 0); - ct_test(pTest, test_invoke_id == invoke_id); - testCOVNotifyData(pTest, data, &test_data); -} - -void testCOVNotify(Test *pTest) -{ - uint8_t invoke_id = 12; - BACNET_COV_DATA data; - BACNET_PROPERTY_VALUE value_list[2] = { { 0 } }; - - data.subscriberProcessIdentifier = 1; - data.initiatingDeviceIdentifier = 123; - data.monitoredObjectIdentifier.type = OBJECT_ANALOG_INPUT; - data.monitoredObjectIdentifier.instance = 321; - data.timeRemaining = 456; - - cov_data_value_list_link(&data, &value_list[0], 2); - /* first value */ - value_list[0].propertyIdentifier = PROP_PRESENT_VALUE; - value_list[0].propertyArrayIndex = BACNET_ARRAY_ALL; - bacapp_parse_application_data( - BACNET_APPLICATION_TAG_REAL, "21.0", &value_list[0].value); - value_list[0].priority = 0; - /* second value */ - value_list[1].propertyIdentifier = PROP_STATUS_FLAGS; - value_list[1].propertyArrayIndex = BACNET_ARRAY_ALL; - bacapp_parse_application_data( - BACNET_APPLICATION_TAG_BIT_STRING, "0000", &value_list[1].value); - value_list[1].priority = 0; - - testUCOVNotifyData(pTest, &data); - testCCOVNotifyData(pTest, invoke_id, &data); -} - -void testCOVSubscribeData(Test *pTest, - BACNET_SUBSCRIBE_COV_DATA *data, - BACNET_SUBSCRIBE_COV_DATA *test_data) -{ - ct_test(pTest, - test_data->subscriberProcessIdentifier == - data->subscriberProcessIdentifier); - ct_test(pTest, - test_data->monitoredObjectIdentifier.type == - data->monitoredObjectIdentifier.type); - ct_test(pTest, - test_data->monitoredObjectIdentifier.instance == - data->monitoredObjectIdentifier.instance); - ct_test(pTest, test_data->cancellationRequest == data->cancellationRequest); - if (test_data->cancellationRequest != data->cancellationRequest) { - printf("cancellation request failed!\n"); - } - if (!test_data->cancellationRequest) { - ct_test(pTest, - test_data->issueConfirmedNotifications == - data->issueConfirmedNotifications); - ct_test(pTest, test_data->lifetime == data->lifetime); - } -} - -void testCOVSubscribePropertyData(Test *pTest, - BACNET_SUBSCRIBE_COV_DATA *data, - BACNET_SUBSCRIBE_COV_DATA *test_data) -{ - testCOVSubscribeData(pTest, data, test_data); - ct_test(pTest, - test_data->monitoredProperty.propertyIdentifier == - data->monitoredProperty.propertyIdentifier); - ct_test(pTest, - test_data->monitoredProperty.propertyArrayIndex == - data->monitoredProperty.propertyArrayIndex); - ct_test(pTest, test_data->covIncrementPresent == data->covIncrementPresent); - if (test_data->covIncrementPresent) { - ct_test(pTest, test_data->covIncrement == data->covIncrement); - } -} - -void testCOVSubscribeEncoding( - Test *pTest, uint8_t invoke_id, BACNET_SUBSCRIBE_COV_DATA *data) -{ - uint8_t apdu[480] = { 0 }; - int len = 0; - int apdu_len = 0; - BACNET_SUBSCRIBE_COV_DATA test_data; - uint8_t test_invoke_id = 0; - - len = cov_subscribe_encode_apdu(&apdu[0], sizeof(apdu), invoke_id, data); - ct_test(pTest, len != 0); - apdu_len = len; - - len = cov_subscribe_decode_apdu( - &apdu[0], apdu_len, &test_invoke_id, &test_data); - ct_test(pTest, len > 0); - ct_test(pTest, test_invoke_id == invoke_id); - testCOVSubscribeData(pTest, data, &test_data); -} - -void testCOVSubscribePropertyEncoding( - Test *pTest, uint8_t invoke_id, BACNET_SUBSCRIBE_COV_DATA *data) -{ - uint8_t apdu[480] = { 0 }; - int len = 0; - int apdu_len = 0; - BACNET_SUBSCRIBE_COV_DATA test_data; - uint8_t test_invoke_id = 0; - - len = cov_subscribe_property_encode_apdu( - &apdu[0], sizeof(apdu), invoke_id, data); - ct_test(pTest, len != 0); - apdu_len = len; - - len = cov_subscribe_property_decode_apdu( - &apdu[0], apdu_len, &test_invoke_id, &test_data); - ct_test(pTest, len > 0); - ct_test(pTest, test_invoke_id == invoke_id); - testCOVSubscribePropertyData(pTest, data, &test_data); -} - -void testCOVSubscribe(Test *pTest) -{ - uint8_t invoke_id = 12; - BACNET_SUBSCRIBE_COV_DATA data; - - data.subscriberProcessIdentifier = 1; - data.monitoredObjectIdentifier.type = OBJECT_ANALOG_INPUT; - data.monitoredObjectIdentifier.instance = 321; - data.cancellationRequest = false; - data.issueConfirmedNotifications = true; - data.lifetime = 456; - - testCOVSubscribeEncoding(pTest, invoke_id, &data); - data.cancellationRequest = true; - testCOVSubscribeEncoding(pTest, invoke_id, &data); -} - -void testCOVSubscribeProperty(Test *pTest) -{ - uint8_t invoke_id = 12; - BACNET_SUBSCRIBE_COV_DATA data; - - data.subscriberProcessIdentifier = 1; - data.monitoredObjectIdentifier.type = OBJECT_ANALOG_INPUT; - data.monitoredObjectIdentifier.instance = 321; - data.cancellationRequest = false; - data.issueConfirmedNotifications = true; - data.lifetime = 456; - data.monitoredProperty.propertyIdentifier = PROP_FILE_SIZE; - data.monitoredProperty.propertyArrayIndex = BACNET_ARRAY_ALL; - data.covIncrementPresent = true; - data.covIncrement = 1.0; - - testCOVSubscribePropertyEncoding(pTest, invoke_id, &data); - - data.cancellationRequest = true; - testCOVSubscribePropertyEncoding(pTest, invoke_id, &data); - - data.cancellationRequest = false; - data.covIncrementPresent = false; - testCOVSubscribePropertyEncoding(pTest, invoke_id, &data); -} - -#ifdef TEST_COV -int main(int argc, char *argv[]) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet COV", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testCOVNotify); - assert(rc); - rc = ct_addTestFunction(pTest, testCOVSubscribe); - assert(rc); - rc = ct_addTestFunction(pTest, testCOVSubscribeProperty); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_COV */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/cov.h b/src/bacnet/cov.h index 502d1941..06d9697e 100644 --- a/src/bacnet/cov.h +++ b/src/bacnet/cov.h @@ -169,19 +169,6 @@ extern "C" { bool overridden, bool out_of_service); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void testCOVNotify( - Test * pTest); - BACNET_STACK_EXPORT - void testCOVSubscribeProperty( - Test * pTest); - BACNET_STACK_EXPORT - void testCOVSubscribe( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/datalink/bvlc.c b/src/bacnet/datalink/bvlc.c index 72e9a5a3..65784326 100644 --- a/src/bacnet/datalink/bvlc.c +++ b/src/bacnet/datalink/bvlc.c @@ -2620,952 +2620,3 @@ const char *bvlc_result_code_name(uint16_t result_code) return name; } - -#ifdef BAC_TEST -#include -#include -#include -#include "ctest.h" - -static void test_BVLC_Address(Test *pTest, - BACNET_IP_ADDRESS *bip_address_1, - BACNET_IP_ADDRESS *bip_address_2) -{ - ct_test(pTest, !bvlc_address_different(bip_address_1, bip_address_2)); -} - -static void test_BVLC_Broadcast_Distribution_Mask(Test *pTest, - BACNET_IP_BROADCAST_DISTRIBUTION_MASK *bd_mask_1, - BACNET_IP_BROADCAST_DISTRIBUTION_MASK *bd_mask_2) -{ - ct_test(pTest, - !bvlc_broadcast_distribution_mask_different(bd_mask_1, bd_mask_2)); -} - -static void test_BVLC_Broadcast_Distribution_Table_Entry(Test *pTest, - BACNET_IP_BROADCAST_DISTRIBUTION_TABLE_ENTRY *bdt_entry_1, - BACNET_IP_BROADCAST_DISTRIBUTION_TABLE_ENTRY *bdt_entry_2) -{ - if (bdt_entry_1 && bdt_entry_2) { - ct_test(pTest, bdt_entry_1->valid == bdt_entry_2->valid); - test_BVLC_Address( - pTest, &bdt_entry_1->dest_address, &bdt_entry_2->dest_address); - test_BVLC_Broadcast_Distribution_Mask( - pTest, &bdt_entry_1->broadcast_mask, &bdt_entry_2->broadcast_mask); - } - - return; -} - -static void test_BVLC_Foreign_Device_Table_Entry(Test *pTest, - BACNET_IP_FOREIGN_DEVICE_TABLE_ENTRY *fdt_entry_1, - BACNET_IP_FOREIGN_DEVICE_TABLE_ENTRY *fdt_entry_2) -{ - if (fdt_entry_1 && fdt_entry_2) { - ct_test(pTest, fdt_entry_1->valid == fdt_entry_2->valid); - test_BVLC_Address( - pTest, &fdt_entry_1->dest_address, &fdt_entry_2->dest_address); - ct_test(pTest, fdt_entry_1->ttl_seconds == fdt_entry_2->ttl_seconds); - ct_test(pTest, - fdt_entry_1->ttl_seconds_remaining == - fdt_entry_2->ttl_seconds_remaining); - } - - return; -} - -static int test_BVLC_Header(Test *pTest, - uint8_t *pdu, - uint16_t pdu_len, - uint8_t *message_type, - uint16_t *message_length) - -{ - int bytes_consumed = 0; - int len = 0; - - if (pdu && message_type && message_length) { - len = bvlc_decode_header(pdu, pdu_len, message_type, message_length); - ct_test(pTest, len == 4); - bytes_consumed = len; - } - - return bytes_consumed; -} - -static void test_BVLC_Result_Code(Test *pTest, uint16_t result_code) -{ - uint8_t pdu[50] = { 0 }; - uint16_t test_result_code = 0; - uint8_t message_type = 0; - uint16_t length = 0; - int len = 0, test_len = 0; - - len = bvlc_encode_result(pdu, sizeof(pdu), result_code); - ct_test(pTest, len == 6); - test_len = test_BVLC_Header(pTest, pdu, len, &message_type, &length); - ct_test(pTest, test_len == 4); - ct_test(pTest, message_type == BVLC_RESULT); - ct_test(pTest, length == 6); - test_len += bvlc_decode_result(&pdu[4], length - 4, &test_result_code); - ct_test(pTest, len == test_len); - ct_test(pTest, result_code == test_result_code); -} - -static void test_BVLC_Result(Test *pTest) -{ - uint16_t result_code[] = { BVLC_RESULT_SUCCESSFUL_COMPLETION, - BVLC_RESULT_WRITE_BROADCAST_DISTRIBUTION_TABLE_NAK, - BVLC_RESULT_READ_BROADCAST_DISTRIBUTION_TABLE_NAK, - BVLC_RESULT_REGISTER_FOREIGN_DEVICE_NAK, - BVLC_RESULT_READ_FOREIGN_DEVICE_TABLE_NAK, - BVLC_RESULT_DELETE_FOREIGN_DEVICE_TABLE_ENTRY_NAK, - BVLC_RESULT_DISTRIBUTE_BROADCAST_TO_NETWORK_NAK }; - unsigned int i = 0; - size_t result_code_max = sizeof(result_code) / sizeof(result_code[0]); - - for (i = 0; i < result_code_max; i++) { - test_BVLC_Result_Code(pTest, result_code[i]); - } -} - -static void test_BVLC_Original_Unicast_NPDU_Message( - Test *pTest, uint8_t *npdu, uint16_t npdu_len) -{ - uint8_t test_npdu[50] = { 0 }; - uint8_t pdu[60] = { 0 }; - uint16_t test_npdu_len = 0; - uint8_t message_type = 0; - uint16_t length = 0; - int len = 0, msg_len = 0, test_len = 0; - uint16_t i = 0; - - len = bvlc_encode_original_unicast(pdu, sizeof(pdu), npdu, npdu_len); - msg_len = 4 + npdu_len; - ct_test(pTest, len == msg_len); - test_len = test_BVLC_Header(pTest, pdu, len, &message_type, &length); - ct_test(pTest, test_len == 4); - ct_test(pTest, message_type == BVLC_ORIGINAL_UNICAST_NPDU); - ct_test(pTest, length == msg_len); - test_len += bvlc_decode_original_unicast( - &pdu[4], length - 4, test_npdu, sizeof(test_npdu), &test_npdu_len); - ct_test(pTest, len == test_len); - ct_test(pTest, msg_len == test_len); - ct_test(pTest, npdu_len == test_npdu_len); - for (i = 0; i < npdu_len; i++) { - ct_test(pTest, npdu[i] == test_npdu[i]); - } -} - -static void test_BVLC_Original_Unicast_NPDU(Test *pTest) -{ - uint8_t npdu[50] = { 0 }; - uint16_t npdu_len = 0; - uint16_t i = 0; - - test_BVLC_Original_Unicast_NPDU_Message(pTest, npdu, npdu_len); - /* now with some NPDU data */ - for (i = 0; i < sizeof(npdu); i++) { - npdu[i] = i; - } - npdu_len = sizeof(npdu); - test_BVLC_Original_Unicast_NPDU_Message(pTest, npdu, npdu_len); -} - -static void test_BVLC_Original_Broadcast_NPDU_Message( - Test *pTest, uint8_t *npdu, uint16_t npdu_len) -{ - uint8_t test_npdu[50] = { 0 }; - uint8_t pdu[60] = { 0 }; - uint16_t test_npdu_len = 0; - uint8_t message_type = 0; - uint16_t length = 0; - int len = 0, msg_len = 0, test_len = 0; - uint16_t i = 0; - - len = bvlc_encode_original_broadcast(pdu, sizeof(pdu), npdu, npdu_len); - msg_len = 4 + npdu_len; - ct_test(pTest, len == msg_len); - test_len = test_BVLC_Header(pTest, pdu, len, &message_type, &length); - ct_test(pTest, test_len == 4); - ct_test(pTest, message_type == BVLC_ORIGINAL_BROADCAST_NPDU); - ct_test(pTest, length == msg_len); - test_len += bvlc_decode_original_broadcast( - &pdu[4], length - 4, test_npdu, sizeof(test_npdu), &test_npdu_len); - ct_test(pTest, len == test_len); - ct_test(pTest, msg_len == test_len); - ct_test(pTest, npdu_len == test_npdu_len); - for (i = 0; i < npdu_len; i++) { - ct_test(pTest, npdu[i] == test_npdu[i]); - } -} - -static void test_BVLC_Original_Broadcast_NPDU(Test *pTest) -{ - uint8_t npdu[50] = { 0 }; - uint16_t npdu_len = 0; - uint16_t i = 0; - - test_BVLC_Original_Broadcast_NPDU_Message(pTest, npdu, npdu_len); - /* now with some NPDU data */ - for (i = 0; i < sizeof(npdu); i++) { - npdu[i] = i; - } - npdu_len = sizeof(npdu); - test_BVLC_Original_Broadcast_NPDU_Message(pTest, npdu, npdu_len); -} - -static void test_BVLC_Forwarded_NPDU_Message(Test *pTest, - uint8_t *npdu, - uint16_t npdu_len, - BACNET_IP_ADDRESS *bip_address) -{ - uint8_t test_npdu[50] = { 0 }; - uint8_t pdu[75] = { 0 }; - BACNET_IP_ADDRESS test_bip_address = { 0 }; - uint16_t test_npdu_len = 0; - uint8_t message_type = 0; - uint16_t length = 0; - int len = 0, msg_len = 0, test_len = 0; - uint16_t i = 0; - - len = bvlc_encode_forwarded_npdu( - pdu, sizeof(pdu), bip_address, npdu, npdu_len); - msg_len = 1 + 1 + 2 + BIP_ADDRESS_MAX + npdu_len; - ct_test(pTest, len == msg_len); - test_len = test_BVLC_Header(pTest, pdu, len, &message_type, &length); - ct_test(pTest, test_len == 4); - ct_test(pTest, message_type == BVLC_FORWARDED_NPDU); - ct_test(pTest, length == msg_len); - test_len += bvlc_decode_forwarded_npdu(&pdu[4], length - 4, - &test_bip_address, test_npdu, sizeof(test_npdu), &test_npdu_len); - ct_test(pTest, len == test_len); - ct_test(pTest, msg_len == test_len); - test_BVLC_Address(pTest, bip_address, &test_bip_address); - ct_test(pTest, npdu_len == test_npdu_len); - for (i = 0; i < npdu_len; i++) { - ct_test(pTest, npdu[i] == test_npdu[i]); - } -} - -static void test_BVLC_Forwarded_NPDU(Test *pTest) -{ - uint8_t npdu[50] = { 0 }; - BACNET_IP_ADDRESS bip_address = { 0 }; - uint16_t npdu_len = 0; - uint16_t i = 0; - - test_BVLC_Forwarded_NPDU_Message(pTest, npdu, npdu_len, &bip_address); - for (i = 0; i < sizeof(bip_address.address); i++) { - bip_address.address[i] = i; - } - bip_address.port = 47808; - /* now with some NPDU data */ - for (i = 0; i < sizeof(npdu); i++) { - npdu[i] = i; - } - npdu_len = sizeof(npdu); - test_BVLC_Forwarded_NPDU_Message(pTest, npdu, npdu_len, &bip_address); -} - -static void test_BVLC_Register_Foreign_Device_Message( - Test *pTest, uint16_t ttl_seconds) -{ - uint8_t pdu[60] = { 0 }; - uint16_t test_ttl_seconds = 0; - uint8_t message_type = 0; - uint16_t length = 0; - int len = 0, test_len = 0; - const int msg_len = 6; - - len = bvlc_encode_register_foreign_device(pdu, sizeof(pdu), ttl_seconds); - ct_test(pTest, len == msg_len); - test_len = test_BVLC_Header(pTest, pdu, len, &message_type, &length); - ct_test(pTest, test_len == 4); - ct_test(pTest, message_type == BVLC_REGISTER_FOREIGN_DEVICE); - ct_test(pTest, length == msg_len); - test_len += bvlc_decode_register_foreign_device( - &pdu[4], length - 4, &test_ttl_seconds); - ct_test(pTest, len == test_len); - ct_test(pTest, msg_len == test_len); - ct_test(pTest, ttl_seconds == test_ttl_seconds); -} - -static void test_BVLC_Register_Foreign_Device(Test *pTest) -{ - uint16_t ttl_seconds = 0; - - test_BVLC_Register_Foreign_Device_Message(pTest, ttl_seconds); - ttl_seconds = 600; - test_BVLC_Register_Foreign_Device_Message(pTest, ttl_seconds); -} - -static void test_BVLC_Delete_Foreign_Device_Message( - Test *pTest, BACNET_IP_FOREIGN_DEVICE_TABLE_ENTRY *fdt_entry) -{ - uint8_t pdu[64] = { 0 }; - BACNET_IP_FOREIGN_DEVICE_TABLE_ENTRY test_fdt_entry = { 0 }; - uint8_t message_type = 0; - uint16_t length = 0; - int len = 0, test_len = 0; - const int msg_len = 0x000A; - - len = bvlc_encode_delete_foreign_device( - pdu, sizeof(pdu), &fdt_entry->dest_address); - ct_test(pTest, len == msg_len); - test_len = test_BVLC_Header(pTest, pdu, len, &message_type, &length); - ct_test(pTest, test_len == 4); - ct_test(pTest, message_type == BVLC_DELETE_FOREIGN_DEVICE_TABLE_ENTRY); - ct_test(pTest, length == msg_len); - test_len += bvlc_decode_delete_foreign_device( - &pdu[4], length - 4, &test_fdt_entry.dest_address); - ct_test(pTest, len == test_len); - ct_test(pTest, msg_len == test_len); - if (msg_len != test_len) { - printf("msg:%u test:%u\n", msg_len, test_len); - } - test_BVLC_Address( - pTest, &fdt_entry->dest_address, &test_fdt_entry.dest_address); -} - -static void test_BVLC_Delete_Foreign_Device(Test *pTest) -{ - BACNET_IP_FOREIGN_DEVICE_TABLE_ENTRY fdt_entry = { 0 }; - unsigned int i = 0; - - /* test with zeros */ - test_BVLC_Delete_Foreign_Device_Message(pTest, &fdt_entry); - /* test with valid values */ - for (i = 0; i < sizeof(fdt_entry.dest_address.address); i++) { - fdt_entry.dest_address.address[i] = i; - } - fdt_entry.dest_address.port = 47808; - fdt_entry.ttl_seconds = 600; - fdt_entry.ttl_seconds_remaining = 42; - fdt_entry.next = NULL; - test_BVLC_Delete_Foreign_Device_Message(pTest, &fdt_entry); -} - -static void test_BVLC_Secure_BVLL_Message( - Test *pTest, uint8_t *sbuf, uint16_t sbuf_len) -{ - uint8_t test_sbuf[50] = { 0 }; - uint8_t pdu[60] = { 0 }; - uint16_t test_sbuf_len = 0; - uint8_t message_type = 0; - uint16_t length = 0; - int len = 0, msg_len = 0, test_len = 0; - uint16_t i = 0; - - len = bvlc_encode_secure_bvll(pdu, sizeof(pdu), sbuf, sbuf_len); - msg_len = 1 + 1 + 2 + sbuf_len; - ct_test(pTest, len == msg_len); - test_len = test_BVLC_Header(pTest, pdu, len, &message_type, &length); - ct_test(pTest, test_len == 4); - ct_test(pTest, message_type == BVLC_SECURE_BVLL); - ct_test(pTest, length == msg_len); - test_len += bvlc_decode_secure_bvll( - &pdu[4], length - 4, test_sbuf, sizeof(test_sbuf), &test_sbuf_len); - ct_test(pTest, len == test_len); - ct_test(pTest, msg_len == test_len); - ct_test(pTest, sbuf_len == test_sbuf_len); - for (i = 0; i < sbuf_len; i++) { - ct_test(pTest, sbuf[i] == test_sbuf[i]); - } -} - -static void test_BVLC_Secure_BVLL(Test *pTest) -{ - uint8_t sbuf[50] = { 0 }; - uint16_t sbuf_len = 0; - uint16_t i = 0; - - test_BVLC_Secure_BVLL_Message(pTest, sbuf, sbuf_len); - /* now with some NPDU data */ - for (i = 0; i < sizeof(sbuf); i++) { - sbuf[i] = i; - } - sbuf_len = sizeof(sbuf); - test_BVLC_Secure_BVLL_Message(pTest, sbuf, sbuf_len); -} - -static void test_BVLC_Read_Broadcast_Distribution_Table_Message(Test *pTest) -{ - uint8_t pdu[60] = { 0 }; - uint8_t message_type = 0; - uint16_t length = 0; - int len = 0, msg_len = 0, test_len = 0; - - len = bvlc_encode_read_broadcast_distribution_table(pdu, sizeof(pdu)); - msg_len = 1 + 1 + 2; - ct_test(pTest, len == msg_len); - test_len = test_BVLC_Header(pTest, pdu, len, &message_type, &length); - ct_test(pTest, test_len == 4); - ct_test(pTest, message_type == BVLC_READ_BROADCAST_DIST_TABLE); - ct_test(pTest, length == msg_len); -} - -static void test_BVLC_Distribute_Broadcast_To_Network_Message( - Test *pTest, uint8_t *npdu, uint16_t npdu_len) -{ - uint8_t test_npdu[50] = { 0 }; - uint8_t pdu[60] = { 0 }; - uint16_t test_npdu_len = 0; - uint8_t message_type = 0; - uint16_t length = 0; - int len = 0, msg_len = 0, test_len = 0; - uint16_t i = 0; - - len = bvlc_encode_distribute_broadcast_to_network( - pdu, sizeof(pdu), npdu, npdu_len); - msg_len = 4 + npdu_len; - ct_test(pTest, len == msg_len); - test_len = test_BVLC_Header(pTest, pdu, len, &message_type, &length); - ct_test(pTest, test_len == 4); - ct_test(pTest, message_type == BVLC_DISTRIBUTE_BROADCAST_TO_NETWORK); - ct_test(pTest, length == msg_len); - test_len += bvlc_decode_distribute_broadcast_to_network( - &pdu[4], length - 4, test_npdu, sizeof(test_npdu), &test_npdu_len); - ct_test(pTest, len == test_len); - ct_test(pTest, msg_len == test_len); - ct_test(pTest, npdu_len == test_npdu_len); - for (i = 0; i < npdu_len; i++) { - ct_test(pTest, npdu[i] == test_npdu[i]); - } -} - -static void test_BVLC_Distribute_Broadcast_To_Network(Test *pTest) -{ - uint8_t npdu[50] = { 0 }; - uint16_t npdu_len = 0; - uint16_t i = 0; - - test_BVLC_Distribute_Broadcast_To_Network_Message(pTest, npdu, npdu_len); - /* now with some NPDU data */ - for (i = 0; i < sizeof(npdu); i++) { - npdu[i] = i; - } - npdu_len = sizeof(npdu); - test_BVLC_Distribute_Broadcast_To_Network_Message(pTest, npdu, npdu_len); -} - -static void test_BVLC_Write_Broadcast_Distribution_Table_Message(Test *pTest, - uint8_t *npdu, - uint16_t npdu_len, - BACNET_IP_BROADCAST_DISTRIBUTION_TABLE_ENTRY *bdt_list) -{ - uint8_t pdu[480] = { 0 }; - uint8_t message_type = 0; - uint16_t length = 0; - int len = 0, msg_len = 0, test_len = 0; - BACNET_IP_BROADCAST_DISTRIBUTION_TABLE_ENTRY *test_bdt_list = NULL; - uint16_t i = 0; - uint16_t count = 0; - - count = bvlc_broadcast_distribution_table_valid_count(bdt_list); - test_bdt_list = - calloc(count, sizeof(BACNET_IP_BROADCAST_DISTRIBUTION_TABLE_ENTRY)); - bvlc_broadcast_distribution_table_link_array(test_bdt_list, count); - /* encode the message */ - len = bvlc_encode_write_broadcast_distribution_table( - pdu, sizeof(pdu), bdt_list); - msg_len = 4 + (count * BACNET_IP_BDT_ENTRY_SIZE); - ct_test(pTest, len == msg_len); - test_len = test_BVLC_Header(pTest, pdu, len, &message_type, &length); - ct_test(pTest, test_len == 4); - ct_test(pTest, message_type == BVLC_WRITE_BROADCAST_DISTRIBUTION_TABLE); - ct_test(pTest, length == msg_len); - test_len += bvlc_decode_write_broadcast_distribution_table( - &pdu[4], length - 4, test_bdt_list); - ct_test(pTest, msg_len == test_len); - for (i = 0; i < count; i++) { - test_BVLC_Broadcast_Distribution_Table_Entry( - pTest, &bdt_list[i], &test_bdt_list[i]); - } -} - -static void test_BVLC_Broadcast_Distribution_Table_Encode(Test *pTest) -{ - uint8_t apdu[480] = { 0 }; - uint16_t apdu_len = 0; - uint16_t test_apdu_len = 0; - uint16_t i = 0; - uint16_t count = 0; - uint16_t test_count = 0; - bool status = false; - BACNET_ERROR_CODE error_code; - BACNET_IP_BROADCAST_DISTRIBUTION_TABLE_ENTRY bdt_list[5] = { 0 }; - BACNET_IP_BROADCAST_DISTRIBUTION_TABLE_ENTRY bdt_entry = { 0 }; - BACNET_IP_ADDRESS dest_address = { 0 }; - BACNET_IP_BROADCAST_DISTRIBUTION_MASK broadcast_mask = { 0 }; - BACNET_IP_BROADCAST_DISTRIBUTION_TABLE_ENTRY test_bdt_list[5] = { 0 }; - - /* configure a BDT entry */ - count = sizeof(bdt_list) / sizeof(bdt_list[0]); - bvlc_broadcast_distribution_table_link_array(&bdt_list[0], count); - for (i = 0; i < count; i++) { - status = bvlc_address_port_from_ascii( - &dest_address, "192.168.0.255", "0xBAC0"); - ct_test(pTest, status); - dest_address.port += i; - broadcast_mask.address[0] = 255; - broadcast_mask.address[1] = 255; - broadcast_mask.address[2] = 255; - broadcast_mask.address[3] = 255; - status = bvlc_broadcast_distribution_table_entry_set( - &bdt_entry, &dest_address, &broadcast_mask); - ct_test(pTest, status); - status = bvlc_broadcast_distribution_table_entry_append( - &bdt_list[0], &bdt_entry); - ct_test(pTest, status); - } - test_count = bvlc_broadcast_distribution_table_count(&bdt_list[0]); - if (test_count != count) { - printf("size=%u count=%u\n", count, test_count); - } - ct_test(pTest, test_count == count); - /* test the encode/decode pair */ - apdu_len = bvlc_broadcast_distribution_table_encode(&apdu[0], - sizeof(apdu), &bdt_list[0]); - test_count = sizeof(test_bdt_list) / sizeof(test_bdt_list[0]); - bvlc_broadcast_distribution_table_link_array(&test_bdt_list[0], test_count); - test_apdu_len = bvlc_broadcast_distribution_table_decode(&apdu[0], - apdu_len, &error_code, &test_bdt_list[0]); - ct_test(pTest, test_apdu_len == apdu_len); - count = bvlc_broadcast_distribution_table_count(&test_bdt_list[0]); - ct_test(pTest, test_count == count); - for (i = 0; i < count; i++) { - status = bvlc_broadcast_distribution_table_entry_different( - &bdt_list[i], &test_bdt_list[i]); - ct_test(pTest, !status); - } -} - -static void test_BVLC_Write_Broadcast_Distribution_Table(Test *pTest) -{ - uint8_t npdu[480] = { 0 }; - uint16_t npdu_len = 0; - uint16_t i = 0; - uint16_t count = 0; - uint16_t test_count = 0; - bool status = false; - BACNET_IP_BROADCAST_DISTRIBUTION_TABLE_ENTRY bdt_list[5] = { 0 }; - BACNET_IP_BROADCAST_DISTRIBUTION_TABLE_ENTRY bdt_entry = { 0 }; - BACNET_IP_ADDRESS dest_address = { 0 }; - BACNET_IP_BROADCAST_DISTRIBUTION_MASK broadcast_mask = { 0 }; - - /* configure a BDT entry */ - count = sizeof(bdt_list) / sizeof(bdt_list[0]); - bvlc_broadcast_distribution_table_link_array(&bdt_list[0], count); - for (i = 0; i < count; i++) { - status = bvlc_address_port_from_ascii( - &dest_address, "192.168.0.255", "0xBAC0"); - ct_test(pTest, status); - dest_address.port += i; - broadcast_mask.address[0] = 255; - broadcast_mask.address[1] = 255; - broadcast_mask.address[2] = 255; - broadcast_mask.address[3] = 255; - status = bvlc_broadcast_distribution_table_entry_set( - &bdt_entry, &dest_address, &broadcast_mask); - ct_test(pTest, status); - status = bvlc_broadcast_distribution_table_entry_append( - &bdt_list[0], &bdt_entry); - ct_test(pTest, status); - } - test_count = bvlc_broadcast_distribution_table_count(&bdt_list[0]); - if (test_count != count) { - printf("size=%u count=%u\n", count, test_count); - } - ct_test(pTest, test_count == count); - test_count = bvlc_broadcast_distribution_table_valid_count(&bdt_list[0]); - ct_test(pTest, test_count == count); - for (i = 1; i < 5; i++) { - status = bvlc_broadcast_distribution_table_entry_different( - &bdt_list[0], &bdt_list[i]); - ct_test(pTest, status); - } - test_BVLC_Write_Broadcast_Distribution_Table_Message( - pTest, npdu, npdu_len, &bdt_list[0]); - /* now with some NPDU data */ - for (i = 0; i < sizeof(npdu); i++) { - npdu[i] = i; - } - npdu_len = sizeof(npdu); - test_BVLC_Write_Broadcast_Distribution_Table_Message( - pTest, npdu, npdu_len, &bdt_list[0]); -} - -static void test_BVLC_Read_Broadcast_Distribution_Table_Ack_Message(Test *pTest, - uint8_t *npdu, - uint16_t npdu_len, - BACNET_IP_BROADCAST_DISTRIBUTION_TABLE_ENTRY *bdt_list) -{ - uint8_t pdu[480] = { 0 }; - uint8_t message_type = 0; - uint16_t length = 0; - int len = 0, msg_len = 0, test_len = 0; - BACNET_IP_BROADCAST_DISTRIBUTION_TABLE_ENTRY *test_bdt_list = NULL; - uint16_t i = 0; - uint16_t count = 0; - - count = bvlc_broadcast_distribution_table_valid_count(bdt_list); - test_bdt_list = - calloc(count, sizeof(BACNET_IP_BROADCAST_DISTRIBUTION_TABLE_ENTRY)); - bvlc_broadcast_distribution_table_link_array(test_bdt_list, count); - /* encode the message */ - len = bvlc_encode_read_broadcast_distribution_table_ack( - pdu, sizeof(pdu), bdt_list); - msg_len = 4 + (count * BACNET_IP_BDT_ENTRY_SIZE); - ct_test(pTest, len == msg_len); - test_len = test_BVLC_Header(pTest, pdu, len, &message_type, &length); - ct_test(pTest, test_len == 4); - ct_test(pTest, message_type == BVLC_READ_BROADCAST_DIST_TABLE_ACK); - ct_test(pTest, length == msg_len); - test_len += bvlc_decode_read_broadcast_distribution_table_ack( - &pdu[4], length - 4, test_bdt_list); - ct_test(pTest, msg_len == test_len); - for (i = 0; i < count; i++) { - test_BVLC_Broadcast_Distribution_Table_Entry( - pTest, &bdt_list[i], &test_bdt_list[i]); - } -} - -static void test_BVLC_Read_Broadcast_Distribution_Table_Ack(Test *pTest) -{ - uint8_t npdu[480] = { 0 }; - uint16_t npdu_len = 0; - uint16_t i = 0; - uint16_t count = 0; - uint16_t test_count = 0; - bool status = false; - BACNET_IP_BROADCAST_DISTRIBUTION_TABLE_ENTRY bdt_list[5] = { 0 }; - BACNET_IP_BROADCAST_DISTRIBUTION_TABLE_ENTRY bdt_entry = { 0 }; - - /* configure a BDT entry */ - count = sizeof(bdt_list) / sizeof(bdt_list[0]); - for (i = 0; i < count; i++) { - status = bvlc_address_port_from_ascii( - &bdt_entry.dest_address, "192.168.0.255", "0xBAC0"); - ct_test(pTest, status); - bdt_entry.dest_address.port += i; - bdt_entry.broadcast_mask.address[0] = 255; - bdt_entry.broadcast_mask.address[1] = 255; - bdt_entry.broadcast_mask.address[2] = 255; - bdt_entry.broadcast_mask.address[3] = 255; - status = bvlc_broadcast_distribution_table_entry_copy( - &bdt_list[i], &bdt_entry); - ct_test(pTest, status); - bdt_list[i].valid = true; - if (i > 0) { - bdt_list[i - 1].next = &bdt_list[i]; - } - bdt_list[i].next = NULL; - } - test_count = bvlc_broadcast_distribution_table_count(&bdt_list[0]); - if (test_count != count) { - printf("size=%u count=%u\n", count, test_count); - } - ct_test(pTest, test_count == count); - test_count = bvlc_broadcast_distribution_table_valid_count(&bdt_list[0]); - ct_test(pTest, test_count == count); - bvlc_broadcast_distribution_table_entry_copy(&bdt_entry, &bdt_list[0]); - status = bvlc_broadcast_distribution_table_entry_different( - &bdt_entry, &bdt_list[0]); - ct_test(pTest, !status); - test_BVLC_Read_Broadcast_Distribution_Table_Ack_Message( - pTest, npdu, npdu_len, &bdt_list[0]); - /* now with some NPDU data */ - for (i = 0; i < sizeof(npdu); i++) { - npdu[i] = i; - } - npdu_len = sizeof(npdu); - test_BVLC_Read_Broadcast_Distribution_Table_Ack_Message( - pTest, npdu, npdu_len, &bdt_list[0]); -} - -static void test_BVLC_Read_Foreign_Device_Table_Ack_Message(Test *pTest, - uint8_t *npdu, - uint16_t npdu_len, - BACNET_IP_FOREIGN_DEVICE_TABLE_ENTRY *fdt_list) -{ - uint8_t pdu[480] = { 0 }; - uint8_t message_type = 0; - uint16_t length = 0; - int len = 0, msg_len = 0, test_len = 0; - BACNET_IP_FOREIGN_DEVICE_TABLE_ENTRY *test_fdt_list = NULL; - uint16_t i = 0; - uint16_t count = 0; - - count = bvlc_foreign_device_table_valid_count(fdt_list); - test_fdt_list = calloc(count, sizeof(BACNET_IP_FOREIGN_DEVICE_TABLE_ENTRY)); - bvlc_foreign_device_table_link_array(test_fdt_list, count); - /* encode the message */ - len = bvlc_encode_read_foreign_device_table_ack(pdu, sizeof(pdu), fdt_list); - msg_len = 4 + (count * BACNET_IP_FDT_ENTRY_SIZE); - ct_test(pTest, len == msg_len); - test_len = test_BVLC_Header(pTest, pdu, len, &message_type, &length); - ct_test(pTest, test_len == 4); - ct_test(pTest, message_type == BVLC_READ_FOREIGN_DEVICE_TABLE_ACK); - ct_test(pTest, length == msg_len); - test_len += bvlc_decode_read_foreign_device_table_ack( - &pdu[4], length - 4, test_fdt_list); - ct_test(pTest, msg_len == test_len); - for (i = 0; i < count; i++) { - test_BVLC_Foreign_Device_Table_Entry( - pTest, &fdt_list[i], &test_fdt_list[i]); - } -} - -static void test_BVLC_Read_Foreign_Device_Table_Ack(Test *pTest) -{ - uint8_t npdu[480] = { 0 }; - uint16_t npdu_len = 0; - uint16_t i = 0; - uint16_t count = 0; - uint16_t test_count = 0; - uint16_t test_port_start = 0xBAC1; - bool status = false; - BACNET_IP_FOREIGN_DEVICE_TABLE_ENTRY fdt_list[5] = { 0 }; - BACNET_IP_ADDRESS dest_address = { 0 }; - - status = bvlc_address_from_ascii(&dest_address, "192.168.0.1"); - ct_test(pTest, status); - /* configure a FDT entry */ - count = sizeof(fdt_list) / sizeof(fdt_list[0]); - bvlc_foreign_device_table_link_array(fdt_list, count); - for (i = 0; i < count; i++) { - dest_address.port = test_port_start + i; - status = bvlc_foreign_device_table_entry_add( - &fdt_list[0], &dest_address, 12345); - ct_test(pTest, status); - /* add again should only update TTL */ - status = bvlc_foreign_device_table_entry_add( - &fdt_list[0], &dest_address, 12345); - ct_test(pTest, status); - } - test_count = bvlc_foreign_device_table_count(fdt_list); - ct_test(pTest, test_count == count); - if (test_count != count) { - printf("size=%u count=%u\n", count, test_count); - } - test_count = bvlc_foreign_device_table_valid_count(fdt_list); - ct_test(pTest, test_count == count); - test_BVLC_Read_Foreign_Device_Table_Ack_Message( - pTest, npdu, npdu_len, fdt_list); - /* now with some NPDU data */ - for (i = 0; i < sizeof(npdu); i++) { - npdu[i] = i; - } - npdu_len = sizeof(npdu); - test_BVLC_Read_Foreign_Device_Table_Ack_Message( - pTest, npdu, npdu_len, fdt_list); - /* cleanup */ - for (i = 0; i < count; i++) { - dest_address.port = test_port_start + i; - status = - bvlc_foreign_device_table_entry_delete(&fdt_list[0], &dest_address); - ct_test(pTest, status); - } - test_count = bvlc_foreign_device_table_valid_count(fdt_list); - ct_test(pTest, test_count == 0); -} - -static void test_BVLC_Address_Copy(Test *pTest) -{ - unsigned int i = 0; - BACNET_IP_ADDRESS src = { 0 }; - BACNET_IP_ADDRESS dst = { 0 }; - bool status = false; - - /* test with zeros */ - status = bvlc_address_copy(&dst, &src); - ct_test(pTest, status); - status = bvlc_address_different(&dst, &src); - ct_test(pTest, !status); - /* test with valid values */ - for (i = 0; i < sizeof(src.address); i++) { - src.address[i] = 1 + i; - } - src.port = 47808; - status = bvlc_address_copy(&dst, &src); - ct_test(pTest, status); - status = bvlc_address_different(&dst, &src); - ct_test(pTest, !status); - /* test for different port */ - dst.port = 47809; - status = bvlc_address_different(&dst, &src); - ct_test(pTest, status); - /* test for different address */ - dst.port = src.port; - for (i = 0; i < sizeof(src.address); i++) { - dst.address[i] = 0; - status = bvlc_address_different(&dst, &src); - ct_test(pTest, status); - dst.address[i] = 1 + i; - } -} - -static void test_BVLC_Address_Get_Set(Test *pTest) -{ - uint16_t i = 0; - BACNET_ADDRESS bsrc = { 0 }; - BACNET_IP_ADDRESS src = { 0 }; - BACNET_IP_ADDRESS dst = { 0 }; - BACNET_IP_BROADCAST_DISTRIBUTION_MASK mask = { 0 }; - BACNET_IP_BROADCAST_DISTRIBUTION_MASK test_mask = { 0 }; - const uint32_t broadcast_mask = 0x12345678; - uint32_t test_broadcast_mask = 0; - uint8_t octet0 = 192; - uint8_t octet1 = 168; - uint8_t octet2 = 1; - uint8_t octet3 = 255; - uint8_t test_octet0 = 0; - uint8_t test_octet1 = 0; - uint8_t test_octet2 = 0; - uint8_t test_octet3 = 0; - const uint16_t dnet = 12345; - uint16_t snet = 0; - bool status = false; - - for (i = 0; i < 255; i++) { - octet0 = i; - octet1 = i; - octet2 = i; - octet3 = i; - status = bvlc_address_set(&src, octet0, octet1, octet2, octet3); - ct_test(pTest, status); - status = bvlc_address_get( - &src, &test_octet0, &test_octet1, &test_octet2, &test_octet3); - ct_test(pTest, status); - ct_test(pTest, octet0 == test_octet0); - ct_test(pTest, octet1 == test_octet1); - ct_test(pTest, octet2 == test_octet2); - ct_test(pTest, octet3 == test_octet3); - } - /* test the ASCII hex to address */ - /* test invalid */ - status = bvlc_address_from_ascii(&src, "256"); - ct_test(pTest, status == false); - status = bvlc_address_from_ascii(&src, "192.168.0.1"); - ct_test(pTest, status); - status = bvlc_address_set(&dst, 192, 168, 0, 1); - ct_test(pTest, status); - status = bvlc_address_different(&dst, &src); - ct_test(pTest, status == false); - /* test zero compression */ - status = bvlc_address_from_ascii(&src, "127..."); - ct_test(pTest, status); - status = bvlc_address_set(&dst, 127, 0, 0, 0); - ct_test(pTest, status); - status = bvlc_address_different(&dst, &src); - if (status) { - status = bvlc_address_get( - &src, &test_octet0, &test_octet1, &test_octet2, &test_octet3); - printf("src:%u.%u.%u.%u\n", (unsigned)test_octet0, - (unsigned)test_octet1, (unsigned)test_octet2, - (unsigned)test_octet3); - status = bvlc_address_get( - &dst, &test_octet0, &test_octet1, &test_octet2, &test_octet3); - printf("dst:%u.%u.%u.%u\n", (unsigned)test_octet0, - (unsigned)test_octet1, (unsigned)test_octet2, - (unsigned)test_octet3); - } - ct_test(pTest, status == false); - /* BACnet to IPv4 address conversions */ - status = bvlc_address_port_from_ascii(&src, "192.168.0.1", "0xBAC0"); - ct_test(pTest, status); - status = bvlc_ip_address_to_bacnet_local(&bsrc, &src); - ct_test(pTest, status); - status = bvlc_ip_address_from_bacnet_local(&dst, &bsrc); - ct_test(pTest, status); - status = bvlc_address_different(&dst, &src); - ct_test(pTest, !status); - status = bvlc_ip_address_to_bacnet_remote(&bsrc, dnet, &src); - ct_test(pTest, status); - status = bvlc_ip_address_from_bacnet_remote(&dst, &snet, &bsrc); - ct_test(pTest, status); - ct_test(pTest, snet == dnet); - status = bvlc_ip_address_from_bacnet_remote(&dst, NULL, &bsrc); - ct_test(pTest, status); - /* Broadcast Distribution Mask conversions */ - status = bvlc_broadcast_distribution_mask_from_host(&mask, broadcast_mask); - ct_test(pTest, status); - status = - bvlc_broadcast_distribution_mask_to_host(&test_broadcast_mask, &mask); - ct_test(pTest, status); - ct_test(pTest, test_broadcast_mask == broadcast_mask); - octet0 = 0x12; - octet1 = 0x34; - octet2 = 0x56; - octet3 = 0x78; - bvlc_broadcast_distribution_mask_set( - &test_mask, octet0, octet1, octet2, octet3); - status = bvlc_broadcast_distribution_mask_different(&mask, &test_mask); - ct_test(pTest, !status); - bvlc_broadcast_distribution_mask_get( - &test_mask, &test_octet0, &test_octet1, &test_octet2, &test_octet3); - ct_test(pTest, octet0 == test_octet0); - ct_test(pTest, octet1 == test_octet1); - ct_test(pTest, octet2 == test_octet2); - ct_test(pTest, octet3 == test_octet3); -} - -void test_BVLC(Test *pTest) -{ - bool rc; - - /* individual tests */ - rc = ct_addTestFunction(pTest, test_BVLC_Result); - assert(rc); - rc = ct_addTestFunction(pTest, - test_BVLC_Broadcast_Distribution_Table_Encode); - assert(rc); - rc = - ct_addTestFunction(pTest, test_BVLC_Write_Broadcast_Distribution_Table); - assert(rc); - rc = ct_addTestFunction( - pTest, test_BVLC_Read_Broadcast_Distribution_Table_Message); - assert(rc); - rc = ct_addTestFunction( - pTest, test_BVLC_Read_Broadcast_Distribution_Table_Ack); - assert(rc); - rc = ct_addTestFunction(pTest, test_BVLC_Forwarded_NPDU); - assert(rc); - rc = ct_addTestFunction(pTest, test_BVLC_Register_Foreign_Device); - assert(rc); - rc = ct_addTestFunction(pTest, test_BVLC_Read_Foreign_Device_Table_Ack); - assert(rc); - rc = ct_addTestFunction(pTest, test_BVLC_Delete_Foreign_Device); - assert(rc); - rc = ct_addTestFunction(pTest, test_BVLC_Distribute_Broadcast_To_Network); - assert(rc); - rc = ct_addTestFunction(pTest, test_BVLC_Original_Unicast_NPDU); - assert(rc); - rc = ct_addTestFunction(pTest, test_BVLC_Original_Broadcast_NPDU); - assert(rc); - rc = ct_addTestFunction(pTest, test_BVLC_Secure_BVLL); - assert(rc); - rc = ct_addTestFunction(pTest, test_BVLC_Address_Copy); - assert(rc); - rc = ct_addTestFunction(pTest, test_BVLC_Address_Get_Set); - assert(rc); -} - -#ifdef TEST_BVLC -int main(void) -{ - Test *pTest; - - pTest = ct_create("BACnet Virtual Link Control IP/v4", NULL); - test_BVLC(pTest); - /* configure output */ - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_BBMD */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/datalink/bvlc.h b/src/bacnet/datalink/bvlc.h index 38351ce4..ab5fd700 100644 --- a/src/bacnet/datalink/bvlc.h +++ b/src/bacnet/datalink/bvlc.h @@ -511,12 +511,6 @@ extern "C" { BACNET_STACK_EXPORT const char *bvlc_result_code_name(uint16_t result_code); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void test_BVLC(Test *pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/datalink/bvlc6.c b/src/bacnet/datalink/bvlc6.c index e1e2a75a..aad61804 100644 --- a/src/bacnet/datalink/bvlc6.c +++ b/src/bacnet/datalink/bvlc6.c @@ -1572,798 +1572,3 @@ int bvlc6_decode_distribute_broadcast_to_network(uint8_t *pdu, return bytes_consumed; } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -static void test_BVLC6_Address(Test *pTest, - BACNET_IP6_ADDRESS *bip6_address_1, - BACNET_IP6_ADDRESS *bip6_address_2) -{ - unsigned i = 0; - - if (bip6_address_1 && bip6_address_2) { - ct_test(pTest, bip6_address_1->port == bip6_address_2->port); - for (i = 0; i < IP6_ADDRESS_MAX; i++) { - ct_test(pTest, - bip6_address_1->address[i] == bip6_address_2->address[i]); - } - } - - return; -} - -static int test_BVLC6_Header(Test *pTest, - uint8_t *pdu, - uint16_t pdu_len, - uint8_t *message_type, - uint16_t *length) - -{ - int bytes_consumed = 0; - int len = 0; - - if (pdu && message_type && length) { - len = bvlc6_decode_header(pdu, pdu_len, message_type, length); - ct_test(pTest, len == 4); - bytes_consumed = len; - } - - return bytes_consumed; -} - -static void test_BVLC6_Result_Code( - Test *pTest, uint32_t vmac, uint16_t result_code) -{ - uint8_t pdu[50] = { 0 }; - uint32_t test_vmac = 0; - uint16_t test_result_code = 0; - uint8_t message_type = 0; - uint16_t length = 0; - int len = 0, test_len = 0; - - len = bvlc6_encode_result(pdu, sizeof(pdu), vmac, result_code); - ct_test(pTest, len == 9); - test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length); - ct_test(pTest, test_len == 4); - ct_test(pTest, message_type == BVLC6_RESULT); - ct_test(pTest, length == 9); - test_len += - bvlc6_decode_result(&pdu[4], length - 4, &test_vmac, &test_result_code); - ct_test(pTest, len == test_len); - ct_test(pTest, vmac == test_vmac); - ct_test(pTest, result_code == test_result_code); - len = bvlc6_encode_result(pdu, sizeof(pdu), 0xffffff + 1, result_code); - ct_test(pTest, len == 0); -} - -static void test_BVLC6_Result(Test *pTest) -{ - uint32_t vmac = 0; - uint16_t result_code[6] = { BVLC6_RESULT_SUCCESSFUL_COMPLETION, - BVLC6_RESULT_ADDRESS_RESOLUTION_NAK, - BVLC6_RESULT_VIRTUAL_ADDRESS_RESOLUTION_NAK, - BVLC6_RESULT_REGISTER_FOREIGN_DEVICE_NAK, - BVLC6_RESULT_DELETE_FOREIGN_DEVICE_NAK, - BVLC6_RESULT_DISTRIBUTE_BROADCAST_TO_NETWORK_NAK }; - unsigned int i = 0; - - vmac = 4194303; - for (i = 0; i < 6; i++) { - test_BVLC6_Result_Code(pTest, vmac, result_code[i]); - } -} - -static void test_BVLC6_Original_Unicast_NPDU_Message(Test *pTest, - uint8_t *npdu, - uint16_t npdu_len, - uint32_t vmac_src, - uint32_t vmac_dst) -{ - uint8_t test_npdu[50] = { 0 }; - uint8_t pdu[60] = { 0 }; - uint32_t test_vmac_src = 0; - uint32_t test_vmac_dst = 0; - uint16_t test_npdu_len = 0; - uint8_t message_type = 0; - uint16_t length = 0; - int len = 0, msg_len = 0, test_len = 0; - uint16_t i = 0; - - len = bvlc6_encode_original_unicast( - pdu, sizeof(pdu), vmac_src, vmac_dst, npdu, npdu_len); - msg_len = 10 + npdu_len; - ct_test(pTest, len == msg_len); - test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length); - ct_test(pTest, test_len == 4); - ct_test(pTest, message_type == BVLC6_ORIGINAL_UNICAST_NPDU); - ct_test(pTest, length == msg_len); - test_len += - bvlc6_decode_original_unicast(&pdu[4], length - 4, &test_vmac_src, - &test_vmac_dst, test_npdu, sizeof(test_npdu), &test_npdu_len); - ct_test(pTest, len == test_len); - ct_test(pTest, msg_len == test_len); - ct_test(pTest, vmac_src == test_vmac_src); - ct_test(pTest, vmac_dst == test_vmac_dst); - ct_test(pTest, npdu_len == test_npdu_len); - for (i = 0; i < npdu_len; i++) { - ct_test(pTest, npdu[i] == test_npdu[i]); - } -} - -static void test_BVLC6_Original_Unicast_NPDU(Test *pTest) -{ - uint8_t npdu[50] = { 0 }; - uint32_t vmac_src = 0; - uint32_t vmac_dst = 0; - uint16_t npdu_len = 0; - uint16_t i = 0; - - test_BVLC6_Original_Unicast_NPDU_Message( - pTest, npdu, npdu_len, vmac_src, vmac_dst); - /* now with some NPDU data */ - for (i = 0; i < sizeof(npdu); i++) { - npdu[i] = i; - } - npdu_len = sizeof(npdu); - vmac_src = 4194303; - vmac_dst = 4194302; - test_BVLC6_Original_Unicast_NPDU_Message( - pTest, npdu, npdu_len, vmac_src, vmac_dst); -} - -static void test_BVLC6_Original_Broadcast_NPDU_Message( - Test *pTest, uint8_t *npdu, uint16_t npdu_len, uint32_t vmac) -{ - uint8_t test_npdu[50] = { 0 }; - uint8_t pdu[60] = { 0 }; - uint32_t test_vmac = 0; - uint16_t test_npdu_len = 0; - uint8_t message_type = 0; - uint16_t length = 0; - int len = 0, msg_len = 0, test_len = 0; - uint16_t i = 0; - - len = - bvlc6_encode_original_broadcast(pdu, sizeof(pdu), vmac, npdu, npdu_len); - msg_len = 7 + npdu_len; - ct_test(pTest, len == msg_len); - test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length); - ct_test(pTest, test_len == 4); - ct_test(pTest, message_type == BVLC6_ORIGINAL_BROADCAST_NPDU); - ct_test(pTest, length == msg_len); - test_len += bvlc6_decode_original_broadcast(&pdu[4], length - 4, &test_vmac, - test_npdu, sizeof(test_npdu), &test_npdu_len); - ct_test(pTest, len == test_len); - ct_test(pTest, msg_len == test_len); - ct_test(pTest, vmac == test_vmac); - ct_test(pTest, npdu_len == test_npdu_len); - for (i = 0; i < npdu_len; i++) { - ct_test(pTest, npdu[i] == test_npdu[i]); - } -} - -static void test_BVLC6_Original_Broadcast_NPDU(Test *pTest) -{ - uint8_t npdu[50] = { 0 }; - uint32_t vmac = 0; - uint16_t npdu_len = 0; - uint16_t i = 0; - - test_BVLC6_Original_Broadcast_NPDU_Message(pTest, npdu, npdu_len, vmac); - /* now with some NPDU data */ - for (i = 0; i < sizeof(npdu); i++) { - npdu[i] = i; - } - npdu_len = sizeof(npdu); - vmac = 4194303; - test_BVLC6_Original_Broadcast_NPDU_Message(pTest, npdu, npdu_len, vmac); -} - -static void test_BVLC6_Address_Resolution_Message( - Test *pTest, uint32_t vmac_src, uint32_t vmac_target) -{ - uint8_t pdu[60] = { 0 }; - uint32_t test_vmac_src = 0; - uint32_t test_vmac_target = 0; - uint8_t message_type = 0; - uint16_t length = 0; - int len = 0, test_len = 0; - const int msg_len = 10; - - len = bvlc6_encode_address_resolution( - pdu, sizeof(pdu), vmac_src, vmac_target); - ct_test(pTest, len == msg_len); - test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length); - ct_test(pTest, test_len == 4); - ct_test(pTest, message_type == BVLC6_ADDRESS_RESOLUTION); - ct_test(pTest, length == msg_len); - test_len += bvlc6_decode_address_resolution( - &pdu[4], length - 4, &test_vmac_src, &test_vmac_target); - ct_test(pTest, len == test_len); - ct_test(pTest, msg_len == test_len); - ct_test(pTest, vmac_src == test_vmac_src); - ct_test(pTest, vmac_target == test_vmac_target); -} - -static void test_BVLC6_Address_Resolution(Test *pTest) -{ - uint32_t vmac_src = 0; - uint32_t vmac_target = 0; - - test_BVLC6_Address_Resolution_Message(pTest, vmac_src, vmac_target); - vmac_src = 4194303; - vmac_target = 4194302; - test_BVLC6_Address_Resolution_Message(pTest, vmac_src, vmac_target); -} - -static void test_BVLC6_Forwarded_Address_Resolution_Message(Test *pTest, - uint32_t vmac_src, - uint32_t vmac_dst, - BACNET_IP6_ADDRESS *bip6_address) -{ - BACNET_IP6_ADDRESS test_bip6_address = { { 0 } }; - uint8_t pdu[60] = { 0 }; - uint32_t test_vmac_src = 0; - uint32_t test_vmac_dst = 0; - uint8_t message_type = 0; - uint16_t length = 0; - int len = 0, test_len = 0; - const int msg_len = 4 + 3 + 3 + BIP6_ADDRESS_MAX; - - len = bvlc6_encode_forwarded_address_resolution( - pdu, sizeof(pdu), vmac_src, vmac_dst, bip6_address); - ct_test(pTest, len == msg_len); - test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length); - ct_test(pTest, test_len == 4); - ct_test(pTest, message_type == BVLC6_FORWARDED_ADDRESS_RESOLUTION); - ct_test(pTest, length == msg_len); - test_len += bvlc6_decode_forwarded_address_resolution(&pdu[4], length - 4, - &test_vmac_src, &test_vmac_dst, &test_bip6_address); - ct_test(pTest, len == test_len); - ct_test(pTest, msg_len == test_len); - ct_test(pTest, vmac_src == test_vmac_src); - ct_test(pTest, vmac_dst == test_vmac_dst); - test_BVLC6_Address(pTest, bip6_address, &test_bip6_address); -} - -static void test_BVLC6_Forwarded_Address_Resolution(Test *pTest) -{ - BACNET_IP6_ADDRESS bip6_address = { { 0 } }; - uint32_t vmac_src = 0; - uint32_t vmac_target = 0; - uint16_t i = 0; - - test_BVLC6_Forwarded_Address_Resolution_Message( - pTest, vmac_src, vmac_target, &bip6_address); - /* now with some address data */ - for (i = 0; i < sizeof(bip6_address.address); i++) { - bip6_address.address[i] = i; - } - bip6_address.port = 47808; - vmac_src = 4194303; - vmac_target = 4194302; - test_BVLC6_Forwarded_Address_Resolution_Message( - pTest, vmac_src, vmac_target, &bip6_address); -} - -static void test_BVLC6_Address_Resolution_Ack_Message( - Test *pTest, uint32_t vmac_src, uint32_t vmac_dst) -{ - uint8_t pdu[60] = { 0 }; - uint32_t test_vmac_src = 0; - uint32_t test_vmac_dst = 0; - uint8_t message_type = 0; - uint16_t length = 0; - int len = 0, test_len = 0; - const int msg_len = 10; - - len = bvlc6_encode_address_resolution_ack( - pdu, sizeof(pdu), vmac_src, vmac_dst); - ct_test(pTest, len == msg_len); - test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length); - ct_test(pTest, test_len == 4); - ct_test(pTest, message_type == BVLC6_ADDRESS_RESOLUTION_ACK); - ct_test(pTest, length == msg_len); - test_len += bvlc6_decode_address_resolution_ack( - &pdu[4], length - 4, &test_vmac_src, &test_vmac_dst); - ct_test(pTest, len == test_len); - ct_test(pTest, msg_len == test_len); - ct_test(pTest, vmac_src == test_vmac_src); - ct_test(pTest, vmac_dst == test_vmac_dst); -} - -static void test_BVLC6_Address_Resolution_Ack(Test *pTest) -{ - uint32_t vmac_src = 0; - uint32_t vmac_dst = 0; - - test_BVLC6_Address_Resolution_Ack_Message(pTest, vmac_src, vmac_dst); - vmac_src = 4194303; - vmac_dst = 4194302; - test_BVLC6_Address_Resolution_Ack_Message(pTest, vmac_src, vmac_dst); -} - -static void test_BVLC6_Virtual_Address_Resolution_Message( - Test *pTest, uint32_t vmac_src) -{ - uint8_t pdu[60] = { 0 }; - uint32_t test_vmac_src = 0; - uint8_t message_type = 0; - uint16_t length = 0; - int len = 0, test_len = 0; - const int msg_len = 7; - - len = bvlc6_encode_virtual_address_resolution(pdu, sizeof(pdu), vmac_src); - ct_test(pTest, len == msg_len); - test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length); - ct_test(pTest, test_len == 4); - ct_test(pTest, message_type == BVLC6_VIRTUAL_ADDRESS_RESOLUTION); - ct_test(pTest, length == msg_len); - test_len += bvlc6_decode_virtual_address_resolution( - &pdu[4], length - 4, &test_vmac_src); - ct_test(pTest, len == test_len); - ct_test(pTest, msg_len == test_len); - ct_test(pTest, vmac_src == test_vmac_src); -} - -static void test_BVLC6_Virtual_Address_Resolution(Test *pTest) -{ - uint32_t vmac_src = 0; - - test_BVLC6_Virtual_Address_Resolution_Message(pTest, vmac_src); - vmac_src = 0x1234; - test_BVLC6_Virtual_Address_Resolution_Message(pTest, vmac_src); -} - -static void test_BVLC6_Virtual_Address_Resolution_Ack_Message( - Test *pTest, uint32_t vmac_src, uint32_t vmac_dst) -{ - uint8_t pdu[60] = { 0 }; - uint32_t test_vmac_src = 0; - uint32_t test_vmac_dst = 0; - uint8_t message_type = 0; - uint16_t length = 0; - int len = 0, test_len = 0; - const int msg_len = 10; - - len = bvlc6_encode_virtual_address_resolution_ack( - pdu, sizeof(pdu), vmac_src, vmac_dst); - ct_test(pTest, len == msg_len); - test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length); - ct_test(pTest, test_len == 4); - ct_test(pTest, message_type == BVLC6_VIRTUAL_ADDRESS_RESOLUTION_ACK); - ct_test(pTest, length == msg_len); - test_len += bvlc6_decode_virtual_address_resolution_ack( - &pdu[4], length - 4, &test_vmac_src, &test_vmac_dst); - ct_test(pTest, len == test_len); - ct_test(pTest, msg_len == test_len); - ct_test(pTest, vmac_src == test_vmac_src); - ct_test(pTest, vmac_dst == test_vmac_dst); -} - -static void test_BVLC6_Virtual_Address_Resolution_Ack(Test *pTest) -{ - uint32_t vmac_src = 0; - uint32_t vmac_dst = 0; - - test_BVLC6_Virtual_Address_Resolution_Ack_Message( - pTest, vmac_src, vmac_dst); - vmac_src = 4194303; - vmac_dst = 4194302; - test_BVLC6_Virtual_Address_Resolution_Ack_Message( - pTest, vmac_src, vmac_dst); -} - -static void test_BVLC6_Forwarded_NPDU_Message(Test *pTest, - uint8_t *npdu, - uint16_t npdu_len, - uint32_t vmac_src, - BACNET_IP6_ADDRESS *bip6_address) -{ - uint8_t test_npdu[50] = { 0 }; - uint8_t pdu[75] = { 0 }; - uint32_t test_vmac_src = 0; - BACNET_IP6_ADDRESS test_bip6_address = { { 0 } }; - uint16_t test_npdu_len = 0; - uint8_t message_type = 0; - uint16_t length = 0; - int len = 0, msg_len = 0, test_len = 0; - uint16_t i = 0; - - len = bvlc6_encode_forwarded_npdu( - pdu, sizeof(pdu), vmac_src, bip6_address, npdu, npdu_len); - msg_len = 1 + 1 + 2 + 3 + BIP6_ADDRESS_MAX + npdu_len; - ct_test(pTest, len == msg_len); - test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length); - ct_test(pTest, test_len == 4); - ct_test(pTest, message_type == BVLC6_FORWARDED_NPDU); - ct_test(pTest, length == msg_len); - test_len += bvlc6_decode_forwarded_npdu(&pdu[4], length - 4, &test_vmac_src, - &test_bip6_address, test_npdu, sizeof(test_npdu), &test_npdu_len); - ct_test(pTest, len == test_len); - ct_test(pTest, msg_len == test_len); - ct_test(pTest, vmac_src == test_vmac_src); - test_BVLC6_Address(pTest, bip6_address, &test_bip6_address); - ct_test(pTest, npdu_len == test_npdu_len); - for (i = 0; i < npdu_len; i++) { - ct_test(pTest, npdu[i] == test_npdu[i]); - } -} - -static void test_BVLC6_Forwarded_NPDU(Test *pTest) -{ - uint8_t npdu[50] = { 0 }; - uint32_t vmac_src = 0; - BACNET_IP6_ADDRESS bip6_address = { { 0 } }; - uint16_t npdu_len = 0; - uint16_t i = 0; - - test_BVLC6_Forwarded_NPDU_Message( - pTest, npdu, npdu_len, vmac_src, &bip6_address); - for (i = 0; i < sizeof(bip6_address.address); i++) { - bip6_address.address[i] = i; - } - bip6_address.port = 47808; - /* now with some NPDU data */ - for (i = 0; i < sizeof(npdu); i++) { - npdu[i] = i; - } - npdu_len = sizeof(npdu); - vmac_src = 4194303; - test_BVLC6_Forwarded_NPDU_Message( - pTest, npdu, npdu_len, vmac_src, &bip6_address); -} - -static void test_BVLC6_Register_Foreign_Device_Message( - Test *pTest, uint32_t vmac_src, uint16_t ttl_seconds) -{ - uint8_t pdu[60] = { 0 }; - uint32_t test_vmac_src = 0; - uint16_t test_ttl_seconds = 0; - uint8_t message_type = 0; - uint16_t length = 0; - int len = 0, test_len = 0; - const int msg_len = 9; - - len = bvlc6_encode_register_foreign_device( - pdu, sizeof(pdu), vmac_src, ttl_seconds); - ct_test(pTest, len == msg_len); - test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length); - ct_test(pTest, test_len == 4); - ct_test(pTest, message_type == BVLC6_REGISTER_FOREIGN_DEVICE); - ct_test(pTest, length == msg_len); - test_len += bvlc6_decode_register_foreign_device( - &pdu[4], length - 4, &test_vmac_src, &test_ttl_seconds); - ct_test(pTest, len == test_len); - ct_test(pTest, msg_len == test_len); - ct_test(pTest, vmac_src == test_vmac_src); - ct_test(pTest, ttl_seconds == test_ttl_seconds); -} - -static void test_BVLC6_Register_Foreign_Device(Test *pTest) -{ - uint32_t vmac_src = 0; - uint16_t ttl_seconds = 0; - - test_BVLC6_Register_Foreign_Device_Message(pTest, vmac_src, ttl_seconds); - vmac_src = 4194303; - ttl_seconds = 600; - test_BVLC6_Register_Foreign_Device_Message(pTest, vmac_src, ttl_seconds); -} - -static void test_BVLC6_Delete_Foreign_Device_Message(Test *pTest, - uint32_t vmac_src, - BACNET_IP6_FOREIGN_DEVICE_TABLE_ENTRY *fdt_entry) -{ - uint8_t pdu[64] = { 0 }; - uint32_t test_vmac_src = 0; - BACNET_IP6_FOREIGN_DEVICE_TABLE_ENTRY test_fdt_entry = { 0 }; - uint8_t message_type = 0; - uint16_t length = 0; - int len = 0, test_len = 0; - const int msg_len = 0x0019; - - len = bvlc6_encode_delete_foreign_device( - pdu, sizeof(pdu), vmac_src, &fdt_entry->bip6_address); - ct_test(pTest, len == msg_len); - test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length); - ct_test(pTest, test_len == 4); - ct_test(pTest, message_type == BVLC6_DELETE_FOREIGN_DEVICE); - ct_test(pTest, length == msg_len); - test_len += bvlc6_decode_delete_foreign_device( - &pdu[4], length - 4, &test_vmac_src, &test_fdt_entry.bip6_address); - ct_test(pTest, len == test_len); - ct_test(pTest, msg_len == test_len); - ct_test(pTest, vmac_src == test_vmac_src); - test_BVLC6_Address( - pTest, &fdt_entry->bip6_address, &test_fdt_entry.bip6_address); -} - -static void test_BVLC6_Delete_Foreign_Device(Test *pTest) -{ - uint32_t vmac_src = 0; - BACNET_IP6_FOREIGN_DEVICE_TABLE_ENTRY fdt_entry = { 0 }; - unsigned int i = 0; - - /* test with zeros */ - test_BVLC6_Delete_Foreign_Device_Message(pTest, vmac_src, &fdt_entry); - /* test with valid values */ - vmac_src = 4194303; - for (i = 0; i < sizeof(fdt_entry.bip6_address.address); i++) { - fdt_entry.bip6_address.address[i] = i; - } - fdt_entry.bip6_address.port = 47808; - fdt_entry.ttl_seconds = 600; - fdt_entry.ttl_seconds_remaining = 42; - fdt_entry.next = NULL; - test_BVLC6_Delete_Foreign_Device_Message(pTest, vmac_src, &fdt_entry); -} - -static void test_BVLC6_Secure_BVLL_Message( - Test *pTest, uint8_t *sbuf, uint16_t sbuf_len) -{ - uint8_t test_sbuf[50] = { 0 }; - uint8_t pdu[60] = { 0 }; - uint16_t test_sbuf_len = 0; - uint8_t message_type = 0; - uint16_t length = 0; - int len = 0, msg_len = 0, test_len = 0; - uint16_t i = 0; - - len = bvlc6_encode_secure_bvll(pdu, sizeof(pdu), sbuf, sbuf_len); - msg_len = 1 + 1 + 2 + sbuf_len; - ct_test(pTest, len == msg_len); - test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length); - ct_test(pTest, test_len == 4); - ct_test(pTest, message_type == BVLC6_SECURE_BVLL); - ct_test(pTest, length == msg_len); - test_len += bvlc6_decode_secure_bvll( - &pdu[4], length - 4, test_sbuf, sizeof(test_sbuf), &test_sbuf_len); - ct_test(pTest, len == test_len); - ct_test(pTest, msg_len == test_len); - ct_test(pTest, sbuf_len == test_sbuf_len); - for (i = 0; i < sbuf_len; i++) { - ct_test(pTest, sbuf[i] == test_sbuf[i]); - } -} - -static void test_BVLC6_Secure_BVLL(Test *pTest) -{ - uint8_t sbuf[50] = { 0 }; - uint16_t sbuf_len = 0; - uint16_t i = 0; - - test_BVLC6_Secure_BVLL_Message(pTest, sbuf, sbuf_len); - /* now with some NPDU data */ - for (i = 0; i < sizeof(sbuf); i++) { - sbuf[i] = i; - } - sbuf_len = sizeof(sbuf); - test_BVLC6_Secure_BVLL_Message(pTest, sbuf, sbuf_len); -} - -static void test_BVLC6_Distribute_Broadcast_To_Network_Message( - Test *pTest, uint8_t *npdu, uint16_t npdu_len, uint32_t vmac) -{ - uint8_t test_npdu[50] = { 0 }; - uint8_t pdu[60] = { 0 }; - uint32_t test_vmac = 0; - uint16_t test_npdu_len = 0; - uint8_t message_type = 0; - uint16_t length = 0; - int len = 0, msg_len = 0, test_len = 0; - uint16_t i = 0; - - len = bvlc6_encode_distribute_broadcast_to_network( - pdu, sizeof(pdu), vmac, npdu, npdu_len); - msg_len = 7 + npdu_len; - ct_test(pTest, len == msg_len); - test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length); - ct_test(pTest, test_len == 4); - ct_test(pTest, message_type == BVLC6_DISTRIBUTE_BROADCAST_TO_NETWORK); - ct_test(pTest, length == msg_len); - test_len += bvlc6_decode_distribute_broadcast_to_network(&pdu[4], - length - 4, &test_vmac, test_npdu, sizeof(test_npdu), &test_npdu_len); - ct_test(pTest, len == test_len); - ct_test(pTest, msg_len == test_len); - ct_test(pTest, vmac == test_vmac); - ct_test(pTest, npdu_len == test_npdu_len); - for (i = 0; i < npdu_len; i++) { - ct_test(pTest, npdu[i] == test_npdu[i]); - } -} - -static void test_BVLC6_Distribute_Broadcast_To_Network(Test *pTest) -{ - uint8_t npdu[50] = { 0 }; - uint32_t vmac = 0; - uint16_t npdu_len = 0; - uint16_t i = 0; - - test_BVLC6_Distribute_Broadcast_To_Network_Message( - pTest, npdu, npdu_len, vmac); - /* now with some NPDU data */ - for (i = 0; i < sizeof(npdu); i++) { - npdu[i] = i; - } - npdu_len = sizeof(npdu); - vmac = 4194303; - test_BVLC6_Distribute_Broadcast_To_Network_Message( - pTest, npdu, npdu_len, vmac); -} - -static void test_BVLC6_Address_Copy(Test *pTest) -{ - unsigned int i = 0; - BACNET_IP6_ADDRESS src = { { 0 } }; - BACNET_IP6_ADDRESS dst = { { 0 } }; - bool status = false; - - /* test with zeros */ - status = bvlc6_address_copy(&dst, &src); - ct_test(pTest, status); - status = bvlc6_address_different(&dst, &src); - ct_test(pTest, !status); - /* test with valid values */ - for (i = 0; i < sizeof(src.address); i++) { - src.address[i] = 1 + i; - } - src.port = 47808; - status = bvlc6_address_copy(&dst, &src); - ct_test(pTest, status); - status = bvlc6_address_different(&dst, &src); - ct_test(pTest, !status); - /* test for different port */ - dst.port = 47809; - status = bvlc6_address_different(&dst, &src); - ct_test(pTest, status); - /* test for different address */ - dst.port = src.port; - for (i = 0; i < sizeof(src.address); i++) { - dst.address[i] = 0; - status = bvlc6_address_different(&dst, &src); - ct_test(pTest, status); - dst.address[i] = 1 + i; - } -} - -static void test_BVLC6_Address_Get_Set(Test *pTest) -{ - uint16_t i = 0; - BACNET_IP6_ADDRESS src = { { 0 } }; - BACNET_IP6_ADDRESS dst = { { 0 } }; - uint16_t group = 1; - uint16_t test_group = 0; - uint16_t hextet[8] = { 0 }; - bool status = false; - - for (i = 0; i < 16; i++) { - status = bvlc6_address_set(&src, group, 0, 0, 0, 0, 0, 0, 0); - ct_test(pTest, status); - status = bvlc6_address_get( - &src, &test_group, NULL, NULL, NULL, NULL, NULL, NULL, NULL); - ct_test(pTest, status); - ct_test(pTest, group == test_group); - group = group << 1; - } - /* test the ASCII hex to address */ - /* test too short */ - status = bvlc6_address_from_ascii(&src, "[1234:5678]"); - ct_test(pTest, status == false); - status = bvlc6_address_from_ascii( - &src, "[1234:5678:9ABC:DEF0:1234:5678:9ABC:DEF0]"); - ct_test(pTest, status); - status = bvlc6_address_set( - &dst, 0x1234, 0x5678, 0x9ABC, 0xDEF0, 0x1234, 0x5678, 0x9ABC, 0xDEF0); - ct_test(pTest, status); - status = bvlc6_address_different(&dst, &src); - ct_test(pTest, status == false); - /* test zero compression */ - status = bvlc6_address_from_ascii(&src, "[1234:5678:9ABC::5678:9ABC:DEF0]"); - ct_test(pTest, status); - status = bvlc6_address_set( - &dst, 0x1234, 0x5678, 0x9ABC, 0x0000, 0x0000, 0x5678, 0x9ABC, 0xDEF0); - ct_test(pTest, status); - status = bvlc6_address_different(&dst, &src); - if (status) { - status = bvlc6_address_get(&src, &hextet[0], &hextet[1], &hextet[2], - &hextet[3], &hextet[4], &hextet[5], &hextet[6], &hextet[7]); - printf("src:[%X:%X:%X:%X:%X:%X:%X:%X]\n", hextet[0], hextet[1], - hextet[2], hextet[3], hextet[4], hextet[5], hextet[6], hextet[7]); - status = bvlc6_address_get(&dst, &hextet[0], &hextet[1], &hextet[2], - &hextet[3], &hextet[4], &hextet[5], &hextet[6], &hextet[7]); - printf("dst:[%X:%X:%X:%X:%X:%X:%X:%X]\n", hextet[0], hextet[1], - hextet[2], hextet[3], hextet[4], hextet[5], hextet[6], hextet[7]); - } - ct_test(pTest, status == false); - /* test some compressed 16-bit zero fields */ - status = - bvlc6_address_from_ascii(&src, "[234:678:ABC:EF0:1234:5678:9ABC:DEF0]"); - ct_test(pTest, status); - status = bvlc6_address_set( - &dst, 0x0234, 0x0678, 0x0ABC, 0x0EF0, 0x1234, 0x5678, 0x9ABC, 0xDEF0); - ct_test(pTest, status); - status = bvlc6_address_different(&dst, &src); - ct_test(pTest, status == false); -} - -static void test_BVLC6_VMAC_Address_Get_Set(Test *pTest) -{ - uint16_t i = 0; - BACNET_ADDRESS addr; - uint32_t device_id = 1; - uint32_t test_device_id = 0; - bool status = false; - - for (i = 0; i < 24; i++) { - status = bvlc6_vmac_address_set(&addr, device_id); - ct_test(pTest, status); - ct_test(pTest, addr.mac_len == 3); - ct_test(pTest, addr.net == 0); - ct_test(pTest, addr.len == 0); - status = bvlc6_vmac_address_get(&addr, &test_device_id); - ct_test(pTest, status); - ct_test(pTest, device_id == test_device_id); - device_id = device_id << 1; - } -} - -void test_BVLC6(Test *pTest) -{ - bool rc; - - /* individual tests */ - rc = ct_addTestFunction(pTest, test_BVLC6_Result); - assert(rc); - rc = ct_addTestFunction(pTest, test_BVLC6_Original_Unicast_NPDU); - assert(rc); - rc = ct_addTestFunction(pTest, test_BVLC6_Original_Broadcast_NPDU); - assert(rc); - rc = ct_addTestFunction(pTest, test_BVLC6_Address_Resolution); - assert(rc); - rc = ct_addTestFunction(pTest, test_BVLC6_Forwarded_Address_Resolution); - assert(rc); - rc = ct_addTestFunction(pTest, test_BVLC6_Address_Resolution_Ack); - assert(rc); - rc = ct_addTestFunction(pTest, test_BVLC6_Virtual_Address_Resolution); - assert(rc); - rc = ct_addTestFunction(pTest, test_BVLC6_Virtual_Address_Resolution_Ack); - assert(rc); - rc = ct_addTestFunction(pTest, test_BVLC6_Forwarded_NPDU); - assert(rc); - rc = ct_addTestFunction(pTest, test_BVLC6_Register_Foreign_Device); - assert(rc); - rc = ct_addTestFunction(pTest, test_BVLC6_Delete_Foreign_Device); - assert(rc); - rc = ct_addTestFunction(pTest, test_BVLC6_Secure_BVLL); - assert(rc); - rc = ct_addTestFunction(pTest, test_BVLC6_Distribute_Broadcast_To_Network); - assert(rc); - rc = ct_addTestFunction(pTest, test_BVLC6_Address_Copy); - assert(rc); - rc = ct_addTestFunction(pTest, test_BVLC6_Address_Get_Set); - assert(rc); - rc = ct_addTestFunction(pTest, test_BVLC6_VMAC_Address_Get_Set); - assert(rc); -} - -#ifdef TEST_BVLC6 -int main(void) -{ - Test *pTest; - - pTest = ct_create("BACnet Virtual Link Control IP/v6", NULL); - test_BVLC6(pTest); - /* configure output */ - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_BBMD */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/datalink/bvlc6.h b/src/bacnet/datalink/bvlc6.h index 1789bf9c..67e88e73 100644 --- a/src/bacnet/datalink/bvlc6.h +++ b/src/bacnet/datalink/bvlc6.h @@ -421,13 +421,6 @@ extern "C" { uint16_t npdu_size, uint16_t * npdu_len); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void test_BVLC6( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/datalink/crc.c b/src/bacnet/datalink/crc.c index df0508f7..5004c079 100644 --- a/src/bacnet/datalink/crc.c +++ b/src/bacnet/datalink/crc.c @@ -140,130 +140,3 @@ uint16_t CRC_Calc_Data(uint8_t dataValue, uint16_t crcValue) (crcLow >> 4) ^ (crcLow & 0x0f) ^ ((crcLow & 0x0f) << 7); } #endif - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" -#include "bacnet/bytes.h" - -/* test from Annex G 1.0 of BACnet Standard */ -void testCRC8(Test *pTest) -{ - uint8_t crc = 0xff; /* accumulates the crc value */ - uint8_t frame_crc; /* appended to the end of the frame */ - - crc = CRC_Calc_Header(0x00, crc); - ct_test(pTest, crc == 0x55); - crc = CRC_Calc_Header(0x10, crc); - ct_test(pTest, crc == 0xC2); - crc = CRC_Calc_Header(0x05, crc); - ct_test(pTest, crc == 0xBC); - crc = CRC_Calc_Header(0x00, crc); - ct_test(pTest, crc == 0x95); - crc = CRC_Calc_Header(0x00, crc); - ct_test(pTest, crc == 0x73); - /* send the ones complement of the CRC in place of */ - /* the CRC, and the resulting CRC will always equal 0x55. */ - frame_crc = ~crc; - ct_test(pTest, frame_crc == 0x8C); - /* use the ones complement value and the next to last CRC value */ - crc = CRC_Calc_Header(frame_crc, crc); - ct_test(pTest, crc == 0x55); -} - -/* test from Annex G 2.0 of BACnet Standard */ -void testCRC16(Test *pTest) -{ - uint16_t crc = 0xffff; - uint16_t data_crc; - - crc = CRC_Calc_Data(0x01, crc); - ct_test(pTest, crc == 0x1E0E); - crc = CRC_Calc_Data(0x22, crc); - ct_test(pTest, crc == 0xEB70); - crc = CRC_Calc_Data(0x30, crc); - ct_test(pTest, crc == 0x42EF); - /* send the ones complement of the CRC in place of */ - /* the CRC, and the resulting CRC will always equal 0xF0B8. */ - data_crc = ~crc; - ct_test(pTest, data_crc == 0xBD10); - crc = CRC_Calc_Data(LO_BYTE(data_crc), crc); - ct_test(pTest, crc == 0x0F3A); - crc = CRC_Calc_Data(HI_BYTE(data_crc), crc); - ct_test(pTest, crc == 0xF0B8); -} - -void testCRC8CreateTable(Test *pTest) -{ - uint8_t crc = 0xff; /* accumulates the crc value */ - int i; - - (void)pTest; - printf("static const uint8_t HeaderCRC[256] =\n"); - printf("{\n"); - printf(" "); - for (i = 0; i < 256; i++) { - crc = CRC_Calc_Header(i, 0); - printf("0x%02x, ", crc); - if (!((i + 1) % 8)) { - printf("\n"); - if (i != 255) { - printf(" "); - } - } - } - printf("};\n"); -} - -void testCRC16CreateTable(Test *pTest) -{ - uint16_t crc; - int i; - - (void)pTest; - printf("static const uint16_t DataCRC[256] =\n"); - printf("{\n"); - printf(" "); - for (i = 0; i < 256; i++) { - crc = CRC_Calc_Data(i, 0); - printf("0x%04x, ", crc); - if (!((i + 1) % 8)) { - printf("\n"); - if (i != 255) { - printf(" "); - } - } - } - printf("};\n"); -} - -#endif - -#ifdef TEST_CRC -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("crc", NULL); - - /* individual tests */ - rc = ct_addTestFunction(pTest, testCRC8); - assert(rc); - rc = ct_addTestFunction(pTest, testCRC16); - assert(rc); - rc = ct_addTestFunction(pTest, testCRC8CreateTable); - assert(rc); - rc = ct_addTestFunction(pTest, testCRC16CreateTable); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - - ct_destroy(pTest); - - return 0; -} -#endif diff --git a/src/bacnet/datalink/mstp.c b/src/bacnet/datalink/mstp.c index 4743d0cf..ea792c75 100644 --- a/src/bacnet/datalink/mstp.c +++ b/src/bacnet/datalink/mstp.c @@ -1251,487 +1251,3 @@ void MSTP_Init(volatile struct mstp_port_struct_t *mstp_port) mstp_port->TokenCount = 0; } } - -#ifdef BAC_TEST -#include -#include -#include "bacnet/basic/sys/ringbuf.h" -#include "ctest.h" - -static uint8_t RxBuffer[MAX_MPDU]; -static uint8_t TxBuffer[MAX_MPDU]; -/* test stub functions */ -void RS485_Send_Frame( - volatile struct mstp_port_struct_t *mstp_port, /* port specific data */ - uint8_t *buffer, /* frame to send (up to 501 bytes of data) */ - uint16_t nbytes) -{ /* number of bytes of data (up to 501) */ - (void)mstp_port; - (void)buffer; - (void)nbytes; -} - -#define RING_BUFFER_DATA_SIZE 1 -#define RING_BUFFER_SIZE MAX_MPDU -static RING_BUFFER Test_Buffer; -static uint8_t Test_Buffer_Data[RING_BUFFER_DATA_SIZE * RING_BUFFER_SIZE]; -static void Load_Input_Buffer(uint8_t *buffer, size_t len) -{ - static bool initialized = false; /* tracks our init */ - if (!initialized) { - initialized = true; - Ringbuf_Init(&Test_Buffer, (char *)Test_Buffer_Data, - RING_BUFFER_DATA_SIZE, RING_BUFFER_SIZE); - } - /* empty any the existing data */ - while (!Ringbuf_Empty(&Test_Buffer)) { - (void)Ringbuf_Pop(&Test_Buffer, NULL); - } - - if (buffer) { - while (len) { - (void)Ringbuf_Put(&Test_Buffer, (char *)buffer); - len--; - buffer++; - } - } -} - -void RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port) -{ /* port specific data */ - char *data; - if (!Ringbuf_Empty(&Test_Buffer) && mstp_port && - (mstp_port->DataAvailable == false)) { - data = Ringbuf_Peek(&Test_Buffer); - if (data) { - mstp_port->DataRegister = *data; - mstp_port->DataAvailable = true; - } - (void)Ringbuf_Pop(&Test_Buffer, NULL); - } -} - -uint16_t MSTP_Put_Receive(volatile struct mstp_port_struct_t *mstp_port) -{ - return mstp_port->DataLength; -} - -/* for the MS/TP state machine to use for getting data to send */ -/* Return: amount of PDU data */ -uint16_t MSTP_Get_Send( - volatile struct mstp_port_struct_t *mstp_port, unsigned timeout) -{ /* milliseconds to wait for a packet */ - return 0; -} - -uint16_t MSTP_Get_Reply( - volatile struct mstp_port_struct_t *mstp_port, unsigned timeout) -{ /* milliseconds to wait for a packet */ - return 0; -} - -uint16_t SilenceTime = 0; -static uint16_t Timer_Silence(void) -{ - return SilenceTime; -} - -static void Timer_Silence_Reset(void) -{ - SilenceTime = 0; -} - -void testReceiveNodeFSM(Test *pTest) -{ - volatile struct mstp_port_struct_t mstp_port; /* port data */ - unsigned EventCount = 0; /* local counter */ - uint8_t my_mac = 0x05; /* local MAC address */ - uint8_t HeaderCRC = 0; /* for local CRC calculation */ - uint8_t FrameType = 0; /* type of packet that was sent */ - unsigned len; /* used for the size of the message packet */ - size_t i; /* used to loop through the message bytes */ - uint8_t buffer[MAX_MPDU] = { 0 }; - uint8_t data[MAX_PDU] = { 0 }; - mstp_port.InputBuffer = &RxBuffer[0]; - mstp_port.InputBufferSize = sizeof(RxBuffer); - mstp_port.OutputBuffer = &TxBuffer[0]; - mstp_port.OutputBufferSize = sizeof(TxBuffer); - mstp_port.SilenceTimer = Timer_Silence; - mstp_port.SilenceTimerReset = Timer_Silence_Reset; - mstp_port.This_Station = my_mac; - mstp_port.Nmax_info_frames = 1; - mstp_port.Nmax_master = 127; - MSTP_Init(&mstp_port); - /* check the receive error during idle */ - mstp_port.receive_state = MSTP_RECEIVE_STATE_IDLE; - mstp_port.ReceiveError = true; - SilenceTime = 255; - mstp_port.EventCount = 0; - INCREMENT_AND_LIMIT_UINT8(EventCount); - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.EventCount == EventCount); - ct_test(pTest, mstp_port.SilenceTimer() == 0); - ct_test(pTest, mstp_port.ReceiveError == false); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE); - /* check for bad packet header */ - mstp_port.DataAvailable = true; - mstp_port.DataRegister = 0x11; - INCREMENT_AND_LIMIT_UINT8(EventCount); - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.DataAvailable == false); - ct_test(pTest, mstp_port.SilenceTimer() == 0); - ct_test(pTest, mstp_port.EventCount == EventCount); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE); - /* check for good packet header, but timeout */ - mstp_port.DataAvailable = true; - mstp_port.DataRegister = 0x55; - INCREMENT_AND_LIMIT_UINT8(EventCount); - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.DataAvailable == false); - ct_test(pTest, mstp_port.SilenceTimer() == 0); - ct_test(pTest, mstp_port.EventCount == EventCount); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE); - /* force the timeout */ - SilenceTime = Tframe_abort + 1; - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE); - /* check for good packet header preamble, but receive error */ - mstp_port.DataAvailable = true; - mstp_port.DataRegister = 0x55; - INCREMENT_AND_LIMIT_UINT8(EventCount); - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.DataAvailable == false); - ct_test(pTest, mstp_port.SilenceTimer() == 0); - ct_test(pTest, mstp_port.EventCount == EventCount); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE); - /* force the error */ - mstp_port.ReceiveError = true; - INCREMENT_AND_LIMIT_UINT8(EventCount); - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.ReceiveError == false); - ct_test(pTest, mstp_port.SilenceTimer() == 0); - ct_test(pTest, mstp_port.EventCount == EventCount); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE); - /* check for good packet header preamble1, but bad preamble2 */ - mstp_port.DataAvailable = true; - mstp_port.DataRegister = 0x55; - INCREMENT_AND_LIMIT_UINT8(EventCount); - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.DataAvailable == false); - ct_test(pTest, mstp_port.SilenceTimer() == 0); - ct_test(pTest, mstp_port.EventCount == EventCount); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE); - MSTP_Receive_Frame_FSM(&mstp_port); - /* no change of state if no data yet */ - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE); - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE); - /* repeated preamble1 */ - mstp_port.DataAvailable = true; - mstp_port.DataRegister = 0x55; - INCREMENT_AND_LIMIT_UINT8(EventCount); - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.DataAvailable == false); - ct_test(pTest, mstp_port.SilenceTimer() == 0); - ct_test(pTest, mstp_port.EventCount == EventCount); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE); - /* repeated preamble1 */ - mstp_port.DataAvailable = true; - mstp_port.DataRegister = 0x55; - INCREMENT_AND_LIMIT_UINT8(EventCount); - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.DataAvailable == false); - ct_test(pTest, mstp_port.SilenceTimer() == 0); - ct_test(pTest, mstp_port.EventCount == EventCount); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE); - /* bad data */ - mstp_port.DataAvailable = true; - mstp_port.DataRegister = 0x11; - INCREMENT_AND_LIMIT_UINT8(EventCount); - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.ReceiveError == false); - ct_test(pTest, mstp_port.SilenceTimer() == 0); - ct_test(pTest, mstp_port.EventCount == EventCount); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE); - /* check for good packet header preamble, but timeout in packet */ - mstp_port.DataAvailable = true; - mstp_port.DataRegister = 0x55; - INCREMENT_AND_LIMIT_UINT8(EventCount); - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.DataAvailable == false); - ct_test(pTest, mstp_port.SilenceTimer() == 0); - ct_test(pTest, mstp_port.EventCount == EventCount); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE); - MSTP_Receive_Frame_FSM(&mstp_port); - /* preamble2 */ - mstp_port.DataAvailable = true; - mstp_port.DataRegister = 0xFF; - INCREMENT_AND_LIMIT_UINT8(EventCount); - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.DataAvailable == false); - ct_test(pTest, mstp_port.SilenceTimer() == 0); - ct_test(pTest, mstp_port.EventCount == EventCount); - ct_test(pTest, mstp_port.Index == 0); - ct_test(pTest, mstp_port.HeaderCRC == 0xFF); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER); - /* force the timeout */ - SilenceTime = Tframe_abort + 1; - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE); - ct_test(pTest, mstp_port.ReceivedInvalidFrame == true); - /* check for good packet header preamble, but error in packet */ - mstp_port.DataAvailable = true; - mstp_port.DataRegister = 0x55; - INCREMENT_AND_LIMIT_UINT8(EventCount); - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.DataAvailable == false); - ct_test(pTest, mstp_port.SilenceTimer() == 0); - ct_test(pTest, mstp_port.EventCount == EventCount); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE); - MSTP_Receive_Frame_FSM(&mstp_port); - /* preamble2 */ - mstp_port.DataAvailable = true; - mstp_port.DataRegister = 0xFF; - INCREMENT_AND_LIMIT_UINT8(EventCount); - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.DataAvailable == false); - ct_test(pTest, mstp_port.SilenceTimer() == 0); - ct_test(pTest, mstp_port.EventCount == EventCount); - ct_test(pTest, mstp_port.Index == 0); - ct_test(pTest, mstp_port.HeaderCRC == 0xFF); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER); - /* force the error */ - mstp_port.ReceiveError = true; - INCREMENT_AND_LIMIT_UINT8(EventCount); - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.ReceiveError == false); - ct_test(pTest, mstp_port.SilenceTimer() == 0); - ct_test(pTest, mstp_port.EventCount == EventCount); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE); - /* check for good packet header preamble */ - mstp_port.DataAvailable = true; - mstp_port.DataRegister = 0x55; - INCREMENT_AND_LIMIT_UINT8(EventCount); - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.DataAvailable == false); - ct_test(pTest, mstp_port.SilenceTimer() == 0); - ct_test(pTest, mstp_port.EventCount == EventCount); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE); - MSTP_Receive_Frame_FSM(&mstp_port); - /* preamble2 */ - mstp_port.DataAvailable = true; - mstp_port.DataRegister = 0xFF; - INCREMENT_AND_LIMIT_UINT8(EventCount); - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.DataAvailable == false); - ct_test(pTest, mstp_port.SilenceTimer() == 0); - ct_test(pTest, mstp_port.EventCount == EventCount); - ct_test(pTest, mstp_port.Index == 0); - ct_test(pTest, mstp_port.HeaderCRC == 0xFF); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER); - /* no change of state if no data yet */ - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER); - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER); - /* Data is received - index is incremented */ - /* FrameType */ - mstp_port.DataAvailable = true; - mstp_port.DataRegister = FRAME_TYPE_TOKEN; - HeaderCRC = 0xFF; - HeaderCRC = CRC_Calc_Header(mstp_port.DataRegister, HeaderCRC); - INCREMENT_AND_LIMIT_UINT8(EventCount); - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.DataAvailable == false); - ct_test(pTest, mstp_port.SilenceTimer() == 0); - ct_test(pTest, mstp_port.EventCount == EventCount); - ct_test(pTest, mstp_port.Index == 1); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER); - ct_test(pTest, FrameType == FRAME_TYPE_TOKEN); - /* Destination */ - mstp_port.DataAvailable = true; - mstp_port.DataRegister = 0x10; - HeaderCRC = CRC_Calc_Header(mstp_port.DataRegister, HeaderCRC); - INCREMENT_AND_LIMIT_UINT8(EventCount); - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.DataAvailable == false); - ct_test(pTest, mstp_port.SilenceTimer() == 0); - ct_test(pTest, mstp_port.EventCount == EventCount); - ct_test(pTest, mstp_port.Index == 2); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER); - ct_test(pTest, mstp_port.DestinationAddress == 0x10); - /* Source */ - mstp_port.DataAvailable = true; - mstp_port.DataRegister = my_mac; - HeaderCRC = CRC_Calc_Header(mstp_port.DataRegister, HeaderCRC); - INCREMENT_AND_LIMIT_UINT8(EventCount); - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.DataAvailable == false); - ct_test(pTest, mstp_port.SilenceTimer() == 0); - ct_test(pTest, mstp_port.EventCount == EventCount); - ct_test(pTest, mstp_port.Index == 3); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER); - ct_test(pTest, mstp_port.SourceAddress == my_mac); - /* Length1 = length*256 */ - mstp_port.DataAvailable = true; - mstp_port.DataRegister = 0; - HeaderCRC = CRC_Calc_Header(mstp_port.DataRegister, HeaderCRC); - INCREMENT_AND_LIMIT_UINT8(EventCount); - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.DataAvailable == false); - ct_test(pTest, mstp_port.SilenceTimer() == 0); - ct_test(pTest, mstp_port.EventCount == EventCount); - ct_test(pTest, mstp_port.Index == 4); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER); - ct_test(pTest, mstp_port.DataLength == 0); - /* Length2 */ - mstp_port.DataAvailable = true; - mstp_port.DataRegister = 0; - HeaderCRC = CRC_Calc_Header(mstp_port.DataRegister, HeaderCRC); - INCREMENT_AND_LIMIT_UINT8(EventCount); - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.DataAvailable == false); - ct_test(pTest, mstp_port.SilenceTimer() == 0); - ct_test(pTest, mstp_port.EventCount == EventCount); - ct_test(pTest, mstp_port.Index == 5); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER); - ct_test(pTest, mstp_port.DataLength == 0); - /* HeaderCRC */ - mstp_port.DataAvailable = true; - ct_test(pTest, HeaderCRC == 0x73); /* per Annex G example */ - mstp_port.DataRegister = ~HeaderCRC; /* one's compliment of CRC is sent */ - INCREMENT_AND_LIMIT_UINT8(EventCount); - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.DataAvailable == false); - ct_test(pTest, mstp_port.SilenceTimer() == 0); - ct_test(pTest, mstp_port.EventCount == EventCount); - ct_test(pTest, mstp_port.Index == 5); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE); - ct_test(pTest, mstp_port.HeaderCRC == 0x55); - /* BadCRC in header check */ - mstp_port.ReceivedInvalidFrame = false; - mstp_port.ReceivedValidFrame = false; - len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_TOKEN, - 0x10, /* destination */ - my_mac, /* source */ - NULL, /* data */ - 0); /* data size */ - ct_test(pTest, len > 0); - /* make the header CRC bad */ - buffer[7] = 0x00; - Load_Input_Buffer(buffer, len); - for (i = 0; i < len; i++) { - RS485_Check_UART_Data(&mstp_port); - INCREMENT_AND_LIMIT_UINT8(EventCount); - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.DataAvailable == false); - ct_test(pTest, mstp_port.SilenceTimer() == 0); - ct_test(pTest, mstp_port.EventCount == EventCount); - } - ct_test(pTest, mstp_port.ReceivedInvalidFrame == true); - ct_test(pTest, mstp_port.ReceivedValidFrame == false); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE); - /* NoData for us */ - mstp_port.ReceivedInvalidFrame = false; - mstp_port.ReceivedValidFrame = false; - len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_TOKEN, - my_mac, /* destination */ - my_mac, /* source */ - NULL, /* data */ - 0); /* data size */ - ct_test(pTest, len > 0); - Load_Input_Buffer(buffer, len); - for (i = 0; i < len; i++) { - RS485_Check_UART_Data(&mstp_port); - INCREMENT_AND_LIMIT_UINT8(EventCount); - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.DataAvailable == false); - ct_test(pTest, mstp_port.SilenceTimer() == 0); - ct_test(pTest, mstp_port.EventCount == EventCount); - } - ct_test(pTest, mstp_port.ReceivedInvalidFrame == false); - ct_test(pTest, mstp_port.ReceivedValidFrame == true); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE); - /* FrameTooLong */ - mstp_port.ReceivedInvalidFrame = false; - mstp_port.ReceivedValidFrame = false; - len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_TOKEN, - my_mac, /* destination */ - my_mac, /* source */ - NULL, /* data */ - 0); /* data size */ - ct_test(pTest, len > 0); - /* make the header data length bad */ - buffer[5] = 0x02; - Load_Input_Buffer(buffer, len); - for (i = 0; i < len; i++) { - RS485_Check_UART_Data(&mstp_port); - INCREMENT_AND_LIMIT_UINT8(EventCount); - MSTP_Receive_Frame_FSM(&mstp_port); - ct_test(pTest, mstp_port.DataAvailable == false); - ct_test(pTest, mstp_port.SilenceTimer() == 0); - ct_test(pTest, mstp_port.EventCount == EventCount); - } - ct_test(pTest, mstp_port.ReceivedInvalidFrame == true); - ct_test(pTest, mstp_port.ReceivedValidFrame == false); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE); - /* Data */ - mstp_port.ReceivedInvalidFrame = false; - mstp_port.ReceivedValidFrame = false; - memset(data, 0, sizeof(data)); - len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_PROPRIETARY_MIN, - my_mac, my_mac, data, sizeof(data)); - ct_test(pTest, len > 0); - Load_Input_Buffer(buffer, len); - RS485_Check_UART_Data(&mstp_port); - MSTP_Receive_Frame_FSM(&mstp_port); - while (mstp_port.receive_state != MSTP_RECEIVE_STATE_IDLE) { - RS485_Check_UART_Data(&mstp_port); - MSTP_Receive_Frame_FSM(&mstp_port); - } - ct_test(pTest, mstp_port.DataLength == sizeof(data)); - ct_test(pTest, mstp_port.ReceivedInvalidFrame == false); - ct_test(pTest, mstp_port.ReceivedValidFrame == true); - ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE); - return; -} - -void testMasterNodeFSM(Test *pTest) -{ - volatile struct mstp_port_struct_t MSTP_Port; /* port data */ - uint8_t my_mac = 0x05; /* local MAC address */ - MSTP_Port.InputBuffer = &RxBuffer[0]; - MSTP_Port.InputBufferSize = sizeof(RxBuffer); - MSTP_Port.OutputBuffer = &TxBuffer[0]; - MSTP_Port.OutputBufferSize = sizeof(TxBuffer); - MSTP_Port.This_Station = my_mac; - MSTP_Port.Nmax_info_frames = 1; - MSTP_Port.Nmax_master = 127; - MSTP_Port.SilenceTimer = Timer_Silence; - MSTP_Port.SilenceTimerReset = Timer_Silence_Reset; - MSTP_Init(&MSTP_Port); - ct_test(pTest, MSTP_Port.master_state == MSTP_MASTER_STATE_INITIALIZE); - /* FIXME: write a unit test for the Master Node State Machine */ -} - -#endif - -#ifdef TEST_MSTP -int main(void) -{ - Test *pTest; - bool rc; - pTest = ct_create("mstp", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testReceiveNodeFSM); - assert(rc); - rc = ct_addTestFunction(pTest, testMasterNodeFSM); - assert(rc); - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - return 0; -} -#endif diff --git a/src/bacnet/datetime.c b/src/bacnet/datetime.c index e00eb6fb..2e317fd6 100644 --- a/src/bacnet/datetime.c +++ b/src/bacnet/datetime.c @@ -1177,564 +1177,3 @@ bool datetime_time_init_ascii(BACNET_TIME *btime, const char *ascii) return status; } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -static void datetime_print(const char *title, BACNET_DATE_TIME *bdatetime) -{ - printf("%s: %04u/%02u/%02u %02u:%02u:%02u.%03u\n", title, - (unsigned int)bdatetime->date.year, (unsigned int)bdatetime->date.month, - (unsigned int)bdatetime->date.wday, (unsigned int)bdatetime->time.hour, - (unsigned int)bdatetime->time.min, (unsigned int)bdatetime->time.sec, - (unsigned int)bdatetime->time.hundredths); -} - -static void testBACnetDateTimeWildcard(Test *pTest) -{ - BACNET_DATE_TIME bdatetime; - bool status = false; - - datetime_set_values(&bdatetime, BACNET_DATE_YEAR_EPOCH, 1, 1, 0, 0, 0, 0); - status = datetime_wildcard(&bdatetime); - ct_test(pTest, status == false); - - datetime_wildcard_set(&bdatetime); - status = datetime_wildcard(&bdatetime); - ct_test(pTest, status == true); -} - -static void testBACnetDateTimeAdd(Test *pTest) -{ - BACNET_DATE_TIME bdatetime, test_bdatetime; - uint32_t minutes = 0; - int diff = 0; - - datetime_set_values(&bdatetime, BACNET_DATE_YEAR_EPOCH, 1, 1, 0, 0, 0, 0); - datetime_copy(&test_bdatetime, &bdatetime); - datetime_add_minutes(&bdatetime, minutes); - diff = datetime_compare(&test_bdatetime, &bdatetime); - ct_test(pTest, diff == 0); - - datetime_set_values(&bdatetime, BACNET_DATE_YEAR_EPOCH, 1, 1, 0, 0, 0, 0); - datetime_add_minutes(&bdatetime, 60); - datetime_set_values( - &test_bdatetime, BACNET_DATE_YEAR_EPOCH, 1, 1, 1, 0, 0, 0); - diff = datetime_compare(&test_bdatetime, &bdatetime); - ct_test(pTest, diff == 0); - - datetime_set_values(&bdatetime, BACNET_DATE_YEAR_EPOCH, 1, 1, 0, 0, 0, 0); - datetime_add_minutes(&bdatetime, (24 * 60)); - datetime_set_values( - &test_bdatetime, BACNET_DATE_YEAR_EPOCH, 1, 2, 0, 0, 0, 0); - diff = datetime_compare(&test_bdatetime, &bdatetime); - ct_test(pTest, diff == 0); - - datetime_set_values(&bdatetime, BACNET_DATE_YEAR_EPOCH, 1, 1, 0, 0, 0, 0); - datetime_add_minutes(&bdatetime, (31 * 24 * 60)); - datetime_set_values( - &test_bdatetime, BACNET_DATE_YEAR_EPOCH, 2, 1, 0, 0, 0, 0); - diff = datetime_compare(&test_bdatetime, &bdatetime); - ct_test(pTest, diff == 0); - - datetime_set_values(&bdatetime, 2013, 6, 6, 23, 59, 59, 0); - datetime_add_minutes(&bdatetime, 60); - datetime_set_values(&test_bdatetime, 2013, 6, 7, 0, 59, 59, 0); - diff = datetime_compare(&test_bdatetime, &bdatetime); - ct_test(pTest, diff == 0); - - datetime_set_values(&bdatetime, 2013, 6, 6, 0, 59, 59, 0); - datetime_add_minutes(&bdatetime, -60); - datetime_set_values(&test_bdatetime, 2013, 6, 5, 23, 59, 59, 0); - diff = datetime_compare(&test_bdatetime, &bdatetime); - ct_test(pTest, diff == 0); -} - -static void testBACnetDateTimeSeconds(Test *pTest) -{ - uint8_t hour = 0, minute = 0, second = 0; - uint8_t test_hour = 0, test_minute = 0, test_second = 0; - uint32_t seconds = 0, test_seconds; - - for (hour = 0; hour < 24; hour++) { - for (minute = 0; minute < 60; minute += 3) { - for (second = 0; second < 60; second += 17) { - seconds = datetime_hms_to_seconds_since_midnight( - hour, minute, second); - datetime_hms_from_seconds_since_midnight( - seconds, &test_hour, &test_minute, &test_second); - test_seconds = datetime_hms_to_seconds_since_midnight( - test_hour, test_minute, test_second); - ct_test(pTest, seconds == test_seconds); - } - } - } -} - -static void testBACnetDate(Test *pTest) -{ - BACNET_DATE bdate1, bdate2; - int diff = 0; - - datetime_set_date(&bdate1, BACNET_DATE_YEAR_EPOCH, 1, 1); - datetime_copy_date(&bdate2, &bdate1); - diff = datetime_compare_date(&bdate1, &bdate2); - ct_test(pTest, diff == 0); - datetime_set_date(&bdate2, BACNET_DATE_YEAR_EPOCH, 1, 2); - diff = datetime_compare_date(&bdate1, &bdate2); - ct_test(pTest, diff < 0); - datetime_set_date(&bdate2, BACNET_DATE_YEAR_EPOCH, 2, 1); - diff = datetime_compare_date(&bdate1, &bdate2); - ct_test(pTest, diff < 0); - datetime_set_date(&bdate2, 1901, 1, 1); - diff = datetime_compare_date(&bdate1, &bdate2); - ct_test(pTest, diff < 0); - - /* midpoint */ - datetime_set_date(&bdate1, 2007, 7, 15); - datetime_copy_date(&bdate2, &bdate1); - diff = datetime_compare_date(&bdate1, &bdate2); - ct_test(pTest, diff == 0); - datetime_set_date(&bdate2, 2007, 7, 14); - diff = datetime_compare_date(&bdate1, &bdate2); - ct_test(pTest, diff > 0); - datetime_set_date(&bdate2, 2007, 7, 1); - diff = datetime_compare_date(&bdate1, &bdate2); - ct_test(pTest, diff > 0); - datetime_set_date(&bdate2, 2007, 7, 31); - diff = datetime_compare_date(&bdate1, &bdate2); - ct_test(pTest, diff < 0); - datetime_set_date(&bdate2, 2007, 8, 15); - diff = datetime_compare_date(&bdate1, &bdate2); - ct_test(pTest, diff < 0); - datetime_set_date(&bdate2, 2007, 12, 15); - diff = datetime_compare_date(&bdate1, &bdate2); - ct_test(pTest, diff < 0); - datetime_set_date(&bdate2, 2007, 6, 15); - diff = datetime_compare_date(&bdate1, &bdate2); - ct_test(pTest, diff > 0); - datetime_set_date(&bdate2, 2007, 1, 15); - diff = datetime_compare_date(&bdate1, &bdate2); - ct_test(pTest, diff > 0); - datetime_set_date(&bdate2, 2006, 7, 15); - diff = datetime_compare_date(&bdate1, &bdate2); - ct_test(pTest, diff > 0); - datetime_set_date(&bdate2, BACNET_DATE_YEAR_EPOCH, 7, 15); - diff = datetime_compare_date(&bdate1, &bdate2); - ct_test(pTest, diff > 0); - datetime_set_date(&bdate2, 2008, 7, 15); - diff = datetime_compare_date(&bdate1, &bdate2); - ct_test(pTest, diff < 0); - datetime_set_date(&bdate2, 2154, 7, 15); - diff = datetime_compare_date(&bdate1, &bdate2); - ct_test(pTest, diff < 0); - - return; -} - -static void testBACnetTime(Test *pTest) -{ - BACNET_TIME btime1, btime2; - int diff = 0; - - datetime_set_time(&btime1, 0, 0, 0, 0); - datetime_copy_time(&btime2, &btime1); - diff = datetime_compare_time(&btime1, &btime2); - ct_test(pTest, diff == 0); - - datetime_set_time(&btime1, 23, 59, 59, 99); - datetime_copy_time(&btime2, &btime1); - diff = datetime_compare_time(&btime1, &btime2); - ct_test(pTest, diff == 0); - - /* midpoint */ - datetime_set_time(&btime1, 12, 30, 30, 50); - datetime_copy_time(&btime2, &btime1); - diff = datetime_compare_time(&btime1, &btime2); - ct_test(pTest, diff == 0); - datetime_set_time(&btime2, 12, 30, 30, 51); - diff = datetime_compare_time(&btime1, &btime2); - ct_test(pTest, diff < 0); - datetime_set_time(&btime2, 12, 30, 31, 50); - diff = datetime_compare_time(&btime1, &btime2); - ct_test(pTest, diff < 0); - datetime_set_time(&btime2, 12, 31, 30, 50); - diff = datetime_compare_time(&btime1, &btime2); - ct_test(pTest, diff < 0); - datetime_set_time(&btime2, 13, 30, 30, 50); - diff = datetime_compare_time(&btime1, &btime2); - ct_test(pTest, diff < 0); - - datetime_set_time(&btime2, 12, 30, 30, 49); - diff = datetime_compare_time(&btime1, &btime2); - ct_test(pTest, diff > 0); - datetime_set_time(&btime2, 12, 30, 29, 50); - diff = datetime_compare_time(&btime1, &btime2); - ct_test(pTest, diff > 0); - datetime_set_time(&btime2, 12, 29, 30, 50); - diff = datetime_compare_time(&btime1, &btime2); - ct_test(pTest, diff > 0); - datetime_set_time(&btime2, 11, 30, 30, 50); - diff = datetime_compare_time(&btime1, &btime2); - ct_test(pTest, diff > 0); - - return; -} - -static void testBACnetDateTime(Test *pTest) -{ - BACNET_DATE_TIME bdatetime1, bdatetime2; - BACNET_DATE bdate; - BACNET_TIME btime; - int diff = 0; - - datetime_set_values(&bdatetime1, BACNET_DATE_YEAR_EPOCH, 1, 1, 0, 0, 0, 0); - datetime_copy(&bdatetime2, &bdatetime1); - diff = datetime_compare(&bdatetime1, &bdatetime2); - ct_test(pTest, diff == 0); - datetime_set_time(&btime, 0, 0, 0, 0); - datetime_set_date(&bdate, BACNET_DATE_YEAR_EPOCH, 1, 1); - datetime_set(&bdatetime1, &bdate, &btime); - diff = datetime_compare(&bdatetime1, &bdatetime2); - ct_test(pTest, diff == 0); - - /* midpoint */ - /* if datetime1 is before datetime2, returns negative */ - datetime_set_values(&bdatetime1, 2000, 7, 15, 12, 30, 30, 50); - datetime_set_values(&bdatetime2, 2000, 7, 15, 12, 30, 30, 51); - diff = datetime_compare(&bdatetime1, &bdatetime2); - ct_test(pTest, diff < 0); - datetime_set_values(&bdatetime2, 2000, 7, 15, 12, 30, 31, 50); - diff = datetime_compare(&bdatetime1, &bdatetime2); - ct_test(pTest, diff < 0); - datetime_set_values(&bdatetime2, 2000, 7, 15, 12, 31, 30, 50); - diff = datetime_compare(&bdatetime1, &bdatetime2); - ct_test(pTest, diff < 0); - datetime_set_values(&bdatetime2, 2000, 7, 15, 13, 30, 30, 50); - diff = datetime_compare(&bdatetime1, &bdatetime2); - ct_test(pTest, diff < 0); - datetime_set_values(&bdatetime2, 2000, 7, 16, 12, 30, 30, 50); - diff = datetime_compare(&bdatetime1, &bdatetime2); - ct_test(pTest, diff < 0); - datetime_set_values(&bdatetime2, 2000, 8, 15, 12, 30, 30, 50); - diff = datetime_compare(&bdatetime1, &bdatetime2); - ct_test(pTest, diff < 0); - datetime_set_values(&bdatetime2, 2001, 7, 15, 12, 30, 30, 50); - diff = datetime_compare(&bdatetime1, &bdatetime2); - ct_test(pTest, diff < 0); - datetime_set_values(&bdatetime2, 2000, 7, 15, 12, 30, 30, 49); - diff = datetime_compare(&bdatetime1, &bdatetime2); - ct_test(pTest, diff > 0); - datetime_set_values(&bdatetime2, 2000, 7, 15, 12, 30, 29, 50); - diff = datetime_compare(&bdatetime1, &bdatetime2); - ct_test(pTest, diff > 0); - datetime_set_values(&bdatetime2, 2000, 7, 15, 12, 29, 30, 50); - diff = datetime_compare(&bdatetime1, &bdatetime2); - ct_test(pTest, diff > 0); - datetime_set_values(&bdatetime2, 2000, 7, 15, 11, 30, 30, 50); - diff = datetime_compare(&bdatetime1, &bdatetime2); - ct_test(pTest, diff > 0); - datetime_set_values(&bdatetime2, 2000, 7, 14, 12, 30, 30, 50); - diff = datetime_compare(&bdatetime1, &bdatetime2); - ct_test(pTest, diff > 0); - datetime_set_values(&bdatetime2, 2000, 6, 15, 12, 30, 30, 50); - diff = datetime_compare(&bdatetime1, &bdatetime2); - ct_test(pTest, diff > 0); - datetime_set_values(&bdatetime2, 1999, 7, 15, 12, 30, 30, 50); - diff = datetime_compare(&bdatetime1, &bdatetime2); - ct_test(pTest, diff > 0); - - return; -} - -static void testWildcardDateTime(Test *pTest) -{ - BACNET_DATE_TIME bdatetime1, bdatetime2; - BACNET_DATE bdate; - BACNET_TIME btime; - int diff = 0; - - datetime_wildcard_set(&bdatetime1); - ct_test(pTest, datetime_wildcard(&bdatetime1)); - ct_test(pTest, datetime_wildcard_present(&bdatetime1)); - datetime_copy(&bdatetime2, &bdatetime1); - diff = datetime_wildcard_compare(&bdatetime1, &bdatetime2); - ct_test(pTest, diff == 0); - datetime_time_wildcard_set(&btime); - datetime_date_wildcard_set(&bdate); - datetime_set(&bdatetime1, &bdate, &btime); - diff = datetime_wildcard_compare(&bdatetime1, &bdatetime2); - ct_test(pTest, diff == 0); - - return; -} - -static void testDayOfYear(Test *pTest) -{ - uint32_t days = 0; - uint8_t month = 0, test_month = 0; - uint8_t day = 0, test_day = 0; - uint16_t year = 0; - BACNET_DATE bdate; - BACNET_DATE test_bdate; - - days = datetime_ymd_day_of_year(1900, 1, 1); - ct_test(pTest, days == 1); - days_of_year_to_month_day(days, 1900, &month, &day); - ct_test(pTest, month == 1); - ct_test(pTest, day == 1); - - for (year = 1900; year <= 2154; year++) { - for (month = 1; month <= 12; month++) { - for (day = 1; day <= days_per_month(year, month); day++) { - days = datetime_ymd_day_of_year(year, month, day); - days_of_year_to_month_day(days, year, &test_month, &test_day); - ct_test(pTest, month == test_month); - ct_test(pTest, day == test_day); - } - } - } - for (year = 1900; year <= 2154; year++) { - for (month = 1; month <= 12; month++) { - for (day = 1; day <= days_per_month(year, month); day++) { - datetime_set_date(&bdate, year, month, day); - days = datetime_day_of_year(&bdate); - datetime_day_of_year_into_date(days, year, &test_bdate); - ct_test(pTest, datetime_compare_date(&bdate, &test_bdate) == 0); - } - } - } -} - -static void testDateEpochConversionCompare(Test *pTest, - uint16_t year, - uint8_t month, - uint8_t day, - uint8_t hour, - uint8_t minute, - uint8_t second, - uint8_t hundredth) -{ - uint64_t epoch_seconds = 0; - BACNET_DATE_TIME bdatetime = { 0 }; - BACNET_DATE_TIME test_bdatetime = { 0 }; - int compare = 0; - - datetime_set_date(&bdatetime.date, year, month, day); - datetime_set_time(&bdatetime.time, hour, minute, second, hundredth); - epoch_seconds = datetime_seconds_since_epoch(&bdatetime); - datetime_since_epoch_seconds(&test_bdatetime, epoch_seconds); - compare = datetime_compare(&bdatetime, &test_bdatetime); - ct_test(pTest, compare == 0); - if (compare != 0) { - datetime_print("bdatetime", &bdatetime); - datetime_print("test_bdatetime", &test_bdatetime); - } -} - -static void testDateEpochConversion(Test *pTest) -{ - /* min */ - testDateEpochConversionCompare( - pTest, BACNET_DATE_YEAR_EPOCH, 1, 1, 0, 0, 0, 0); - /* middle */ - testDateEpochConversionCompare(pTest, 2020, 6, 26, 12, 30, 30, 0); - /* max */ - testDateEpochConversionCompare( - pTest, BACNET_DATE_YEAR_EPOCH + 0xFF - 1, 12, 31, 23, 59, 59, 0); -} - -static void testDateEpoch(Test *pTest) -{ - uint32_t days = 0; - uint16_t year = 0, test_year = 0; - uint8_t month = 0, test_month = 0; - uint8_t day = 0, test_day = 0; - - days = datetime_ymd_to_days_since_epoch(BACNET_DATE_YEAR_EPOCH, 1, 1); - ct_test(pTest, days == 0); - datetime_ymd_from_days_since_epoch(days, &year, &month, &day); - ct_test(pTest, year == BACNET_DATE_YEAR_EPOCH); - ct_test(pTest, month == 1); - ct_test(pTest, day == 1); - - for (year = BACNET_DATE_YEAR_EPOCH; year < (BACNET_DATE_YEAR_EPOCH + 0xFF); - year++) { - for (month = 1; month <= 12; month++) { - for (day = 1; day <= days_per_month(year, month); day++) { - days = datetime_ymd_to_days_since_epoch(year, month, day); - datetime_ymd_from_days_since_epoch( - days, &test_year, &test_month, &test_day); - ct_test(pTest, year == test_year); - ct_test(pTest, month == test_month); - ct_test(pTest, day == test_day); - } - } - } -} - -static void testBACnetDayOfWeek(Test *pTest) -{ - uint8_t dow = 0; - - /* 1/1/1900 is a Monday */ - dow = datetime_day_of_week(1900, 1, 1); - ct_test(pTest, dow == BACNET_WEEKDAY_MONDAY); - - /* 1/1/2007 is a Monday */ - dow = datetime_day_of_week(2007, 1, 1); - ct_test(pTest, dow == BACNET_WEEKDAY_MONDAY); - dow = datetime_day_of_week(2007, 1, 2); - ct_test(pTest, dow == BACNET_WEEKDAY_TUESDAY); - dow = datetime_day_of_week(2007, 1, 3); - ct_test(pTest, dow == BACNET_WEEKDAY_WEDNESDAY); - dow = datetime_day_of_week(2007, 1, 4); - ct_test(pTest, dow == BACNET_WEEKDAY_THURSDAY); - dow = datetime_day_of_week(2007, 1, 5); - ct_test(pTest, dow == BACNET_WEEKDAY_FRIDAY); - dow = datetime_day_of_week(2007, 1, 6); - ct_test(pTest, dow == BACNET_WEEKDAY_SATURDAY); - dow = datetime_day_of_week(2007, 1, 7); - ct_test(pTest, dow == BACNET_WEEKDAY_SUNDAY); - - dow = datetime_day_of_week(2007, 1, 31); - ct_test(pTest, dow == 3); -} - -static void testDatetimeCodec(Test *pTest) -{ - uint8_t apdu[MAX_APDU]; - BACNET_DATE_TIME datetimeIn; - BACNET_DATE_TIME datetimeOut; - int inLen; - int outLen; - - datetimeIn.date.day = 1; - datetimeIn.date.month = 2; - datetimeIn.date.wday = 3; - datetimeIn.date.year = 1904; - - datetimeIn.time.hour = 5; - datetimeIn.time.min = 6; - datetimeIn.time.sec = 7; - datetimeIn.time.hundredths = 8; - - inLen = bacapp_encode_context_datetime(apdu, 10, &datetimeIn); - outLen = bacapp_decode_context_datetime(apdu, 10, &datetimeOut); - - ct_test(pTest, inLen == outLen); - - ct_test(pTest, datetimeIn.date.day == datetimeOut.date.day); - ct_test(pTest, datetimeIn.date.month == datetimeOut.date.month); - ct_test(pTest, datetimeIn.date.wday == datetimeOut.date.wday); - ct_test(pTest, datetimeIn.date.year == datetimeOut.date.year); - - ct_test(pTest, datetimeIn.time.hour == datetimeOut.time.hour); - ct_test(pTest, datetimeIn.time.min == datetimeOut.time.min); - ct_test(pTest, datetimeIn.time.sec == datetimeOut.time.sec); - ct_test(pTest, datetimeIn.time.hundredths == datetimeOut.time.hundredths); -} - -static void testDatetimeConvertUTCSpecific(Test *pTest, - BACNET_DATE_TIME *utc_time, - BACNET_DATE_TIME *local_time, - int16_t utc_offset_minutes, - int8_t dst_adjust_minutes) -{ - bool status = false; - BACNET_DATE_TIME test_local_time; - - status = datetime_local_to_utc( - utc_time, local_time, utc_offset_minutes, dst_adjust_minutes); - ct_test(pTest, status); - status = datetime_utc_to_local( - &test_local_time, utc_time, utc_offset_minutes, dst_adjust_minutes); - ct_test(pTest, status); - /* validate the conversion */ - ct_test(pTest, local_time->date.day == test_local_time.date.day); - ct_test(pTest, local_time->date.month == test_local_time.date.month); - ct_test(pTest, local_time->date.wday == test_local_time.date.wday); - ct_test(pTest, local_time->date.year == test_local_time.date.year); - ct_test(pTest, local_time->time.hour == test_local_time.time.hour); - ct_test(pTest, local_time->time.min == test_local_time.time.min); - ct_test(pTest, local_time->time.sec == test_local_time.time.sec); - ct_test( - pTest, local_time->time.hundredths == test_local_time.time.hundredths); -} - -static void testDatetimeConvertUTC(Test *pTest) -{ - BACNET_DATE_TIME local_time; - BACNET_DATE_TIME utc_time; - /* values are positive east of UTC and negative west of UTC */ - int16_t utc_offset_minutes = 0; - int8_t dst_adjust_minutes = 0; - - datetime_set_date(&local_time.date, 1999, 12, 23); - datetime_set_time(&local_time.time, 8, 30, 0, 0); - testDatetimeConvertUTCSpecific( - pTest, &utc_time, &local_time, utc_offset_minutes, dst_adjust_minutes); - /* check a timezone West of UTC */ - utc_offset_minutes = -6 * 60; - dst_adjust_minutes = -60; - testDatetimeConvertUTCSpecific( - pTest, &utc_time, &local_time, utc_offset_minutes, dst_adjust_minutes); - /* check a timezone East of UTC */ - utc_offset_minutes = 6 * 60; - dst_adjust_minutes = 60; - testDatetimeConvertUTCSpecific( - pTest, &utc_time, &local_time, utc_offset_minutes, dst_adjust_minutes); -} - -void testDateTime(Test *pTest) -{ - bool rc; - - /* individual tests */ - rc = ct_addTestFunction(pTest, testBACnetDate); - assert(rc); - rc = ct_addTestFunction(pTest, testBACnetTime); - assert(rc); - rc = ct_addTestFunction(pTest, testBACnetDateTime); - assert(rc); - rc = ct_addTestFunction(pTest, testBACnetDayOfWeek); - assert(rc); - rc = ct_addTestFunction(pTest, testDateEpoch); - assert(rc); - rc = ct_addTestFunction(pTest, testDateEpochConversion); - assert(rc); - rc = ct_addTestFunction(pTest, testBACnetDateTimeSeconds); - assert(rc); - rc = ct_addTestFunction(pTest, testBACnetDateTimeAdd); - assert(rc); - rc = ct_addTestFunction(pTest, testBACnetDateTimeWildcard); - assert(rc); - rc = ct_addTestFunction(pTest, testDatetimeCodec); - assert(rc); - rc = ct_addTestFunction(pTest, testDayOfYear); - assert(rc); - rc = ct_addTestFunction(pTest, testWildcardDateTime); - assert(rc); - rc = ct_addTestFunction(pTest, testDatetimeConvertUTC); - assert(rc); -} - -#ifdef TEST_DATE_TIME -int main(void) -{ - Test *pTest; - - pTest = ct_create("BACnet Date Time", NULL); - testDateTime(pTest); - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} - -#endif /* TEST_DATE_TIME */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/datetime.h b/src/bacnet/datetime.h index c3cadb30..ab2b053f 100644 --- a/src/bacnet/datetime.h +++ b/src/bacnet/datetime.h @@ -277,12 +277,6 @@ bool datetime_local(BACNET_DATE *bdate, BACNET_STACK_EXPORT void datetime_init(void); -#ifdef BAC_TEST -#include "ctest.h" -BACNET_STACK_EXPORT -void testDateTime(Test *pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/dcc.c b/src/bacnet/dcc.c index aec64c64..b0d67696 100644 --- a/src/bacnet/dcc.c +++ b/src/bacnet/dcc.c @@ -307,151 +307,3 @@ int dcc_decode_service_request(uint8_t *apdu, return apdu_len; } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -int dcc_decode_apdu(uint8_t *apdu, - unsigned apdu_len, - uint8_t *invoke_id, - uint16_t *timeDuration, - BACNET_COMMUNICATION_ENABLE_DISABLE *enable_disable, - BACNET_CHARACTER_STRING *password) -{ - int len = 0; - unsigned offset = 0; - - if (!apdu) - return -1; - /* optional checking - most likely was already done prior to this call */ - if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) - return -1; - /* apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); */ - *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ - if (apdu[3] != SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL) - return -1; - offset = 4; - - if (apdu_len > offset) { - len = dcc_decode_service_request(&apdu[offset], apdu_len - offset, - timeDuration, enable_disable, password); - } - - return len; -} - -void test_DeviceCommunicationControlData(Test *pTest, - uint8_t invoke_id, - uint16_t timeDuration, - BACNET_COMMUNICATION_ENABLE_DISABLE enable_disable, - BACNET_CHARACTER_STRING *password) -{ - uint8_t apdu[480] = { 0 }; - int len = 0; - int apdu_len = 0; - uint8_t test_invoke_id = 0; - uint16_t test_timeDuration = 0; - BACNET_COMMUNICATION_ENABLE_DISABLE test_enable_disable; - BACNET_CHARACTER_STRING test_password; - - len = dcc_encode_apdu( - &apdu[0], invoke_id, timeDuration, enable_disable, password); - ct_test(pTest, len != 0); - apdu_len = len; - - len = dcc_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, - &test_timeDuration, &test_enable_disable, &test_password); - ct_test(pTest, len != -1); - ct_test(pTest, test_invoke_id == invoke_id); - ct_test(pTest, test_timeDuration == timeDuration); - ct_test(pTest, test_enable_disable == enable_disable); - ct_test(pTest, characterstring_same(&test_password, password)); -} - -void test_DeviceCommunicationControl(Test *pTest) -{ - uint8_t invoke_id = 128; - uint16_t timeDuration = 0; - BACNET_COMMUNICATION_ENABLE_DISABLE enable_disable; - BACNET_CHARACTER_STRING password; - - timeDuration = 0; - enable_disable = COMMUNICATION_DISABLE_INITIATION; - characterstring_init_ansi(&password, "John 3:16"); - test_DeviceCommunicationControlData( - pTest, invoke_id, timeDuration, enable_disable, &password); - - timeDuration = 12345; - enable_disable = COMMUNICATION_DISABLE; - test_DeviceCommunicationControlData( - pTest, invoke_id, timeDuration, enable_disable, NULL); - - return; -} - -void test_DeviceCommunicationControlMalformedData(Test *pTest) -{ - /* payload with enable-disable, and password with wrong characterstring - * length */ - uint8_t payload_1[] = { 0x19, 0x00, 0x2a, 0x00, 0x41 }; - /* payload with enable-disable, and password with wrong characterstring - * length */ - uint8_t payload_2[] = { 0x19, 0x00, 0x2d, 0x55, 0x00, 0x66, 0x69, 0x73, - 0x74, 0x65, 0x72 }; - /* payload with enable-disable - wrong context tag number for password */ - uint8_t payload_3[] = { 0x19, 0x01, 0x3d, 0x09, 0x00, 0x66, 0x69, 0x73, - 0x74, 0x65, 0x72 }; - /* payload with duration, enable-disable, and password */ - uint8_t payload_4[] = { 0x00, 0x05, 0xf1, 0x11, 0x0a, 0x00, 0x19, 0x00, - 0x2d, 0x09, 0x00, 0x66, 0x69, 0x73, 0x74, 0x65, 0x72 }; - /* payload submitted with bug report */ - uint8_t payload_5[] = { 0x0d, 0xff, 0x80, 0x00, 0x03, 0x1a, 0x0a, 0x19, - 0x00, 0x2a, 0x00, 0x41 }; - int len = 0; - uint8_t test_invoke_id = 0; - uint16_t test_timeDuration = 0; - BACNET_COMMUNICATION_ENABLE_DISABLE test_enable_disable; - BACNET_CHARACTER_STRING test_password; - - len = dcc_decode_apdu(&payload_1[0], sizeof(payload_1), &test_invoke_id, - &test_timeDuration, &test_enable_disable, &test_password); - ct_test(pTest, len == BACNET_STATUS_ERROR); - len = dcc_decode_apdu(&payload_2[0], sizeof(payload_2), &test_invoke_id, - &test_timeDuration, &test_enable_disable, &test_password); - ct_test(pTest, len == BACNET_STATUS_ERROR); - len = dcc_decode_apdu(&payload_3[0], sizeof(payload_3), &test_invoke_id, - &test_timeDuration, &test_enable_disable, &test_password); - ct_test(pTest, len == BACNET_STATUS_ERROR); - len = dcc_decode_apdu(&payload_4[0], sizeof(payload_4), &test_invoke_id, - &test_timeDuration, &test_enable_disable, &test_password); - ct_test(pTest, len == BACNET_STATUS_ABORT); - len = dcc_decode_apdu(&payload_5[0], sizeof(payload_5), &test_invoke_id, - &test_timeDuration, &test_enable_disable, &test_password); - ct_test(pTest, len == BACNET_STATUS_ERROR); -} - -#ifdef TEST_DEVICE_COMMUNICATION_CONTROL -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet DeviceCommunicationControl", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, test_DeviceCommunicationControl); - assert(rc); - rc = - ct_addTestFunction(pTest, test_DeviceCommunicationControlMalformedData); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_DEVICE_COMMUNICATION_CONTROL */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/dcc.h b/src/bacnet/dcc.h index a4667e09..ae9bfc81 100644 --- a/src/bacnet/dcc.h +++ b/src/bacnet/dcc.h @@ -80,22 +80,6 @@ extern "C" { BACNET_COMMUNICATION_ENABLE_DISABLE * enable_disable, BACNET_CHARACTER_STRING * password); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - int dcc_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - uint8_t * invoke_id, - uint16_t * timeDuration, - BACNET_COMMUNICATION_ENABLE_DISABLE * enable_disable, - BACNET_CHARACTER_STRING * password); - - BACNET_STACK_EXPORT - void test_DeviceCommunicationControl( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/event.c b/src/bacnet/event.c index 170a9bdb..cfb9352f 100644 --- a/src/bacnet/event.c +++ b/src/bacnet/event.c @@ -1137,944 +1137,3 @@ int event_notify_decode_service_request( return len; } - -#ifdef BAC_TEST - -#include -#include -#include "ctest.h" - -BACNET_EVENT_NOTIFICATION_DATA data; -BACNET_EVENT_NOTIFICATION_DATA data2; - -void testBaseEventState(Test *pTest) -{ - ct_test(pTest, data.processIdentifier == data2.processIdentifier); - ct_test(pTest, - data.initiatingObjectIdentifier.instance == - data2.initiatingObjectIdentifier.instance); - ct_test(pTest, - data.initiatingObjectIdentifier.type == - data2.initiatingObjectIdentifier.type); - ct_test(pTest, - data.eventObjectIdentifier.instance == - data2.eventObjectIdentifier.instance); - ct_test(pTest, - data.eventObjectIdentifier.type == data2.eventObjectIdentifier.type); - ct_test(pTest, data.notificationClass == data2.notificationClass); - ct_test(pTest, data.priority == data2.priority); - ct_test(pTest, data.notifyType == data2.notifyType); - ct_test(pTest, data.fromState == data2.fromState); - ct_test(pTest, data.toState == data2.toState); - ct_test(pTest, data.toState == data2.toState); - - if (data.messageText != NULL && data2.messageText != NULL) { - ct_test( - pTest, data.messageText->encoding == data2.messageText->encoding); - ct_test(pTest, data.messageText->length == data2.messageText->length); - ct_test(pTest, - strcmp(data.messageText->value, data2.messageText->value) == 0); - } - - ct_test(pTest, data.timeStamp.tag == data2.timeStamp.tag); - - switch (data.timeStamp.tag) { - case TIME_STAMP_SEQUENCE: - ct_test(pTest, - data.timeStamp.value.sequenceNum == - data2.timeStamp.value.sequenceNum); - break; - - case TIME_STAMP_DATETIME: - ct_test(pTest, - data.timeStamp.value.dateTime.time.hour == - data2.timeStamp.value.dateTime.time.hour); - ct_test(pTest, - data.timeStamp.value.dateTime.time.min == - data2.timeStamp.value.dateTime.time.min); - ct_test(pTest, - data.timeStamp.value.dateTime.time.sec == - data2.timeStamp.value.dateTime.time.sec); - ct_test(pTest, - data.timeStamp.value.dateTime.time.hundredths == - data2.timeStamp.value.dateTime.time.hundredths); - - ct_test(pTest, - data.timeStamp.value.dateTime.date.day == - data2.timeStamp.value.dateTime.date.day); - ct_test(pTest, - data.timeStamp.value.dateTime.date.month == - data2.timeStamp.value.dateTime.date.month); - ct_test(pTest, - data.timeStamp.value.dateTime.date.wday == - data2.timeStamp.value.dateTime.date.wday); - ct_test(pTest, - data.timeStamp.value.dateTime.date.year == - data2.timeStamp.value.dateTime.date.year); - break; - - case TIME_STAMP_TIME: - ct_test(pTest, - data.timeStamp.value.time.hour == - data2.timeStamp.value.time.hour); - ct_test(pTest, - data.timeStamp.value.time.min == - data2.timeStamp.value.time.min); - ct_test(pTest, - data.timeStamp.value.time.sec == - data2.timeStamp.value.time.sec); - ct_test(pTest, - data.timeStamp.value.time.hundredths == - data2.timeStamp.value.time.hundredths); - break; - - default: - ct_fail(pTest, "Unknown type"); - break; - } -} - -void testEventEventState(Test *pTest) -{ - uint8_t buffer[MAX_APDU]; - int inLen; - int outLen; - BACNET_CHARACTER_STRING messageText; - BACNET_CHARACTER_STRING messageText2; - characterstring_init_ansi( - &messageText, "This is a test of the message text\n"); - - data.messageText = &messageText; - data2.messageText = &messageText2; - - data.processIdentifier = 1234; - data.initiatingObjectIdentifier.type = OBJECT_ANALOG_INPUT; - data.initiatingObjectIdentifier.instance = 100; - data.eventObjectIdentifier.type = OBJECT_ANALOG_INPUT; - data.eventObjectIdentifier.instance = 200; - data.timeStamp.value.sequenceNum = 1234; - data.timeStamp.tag = TIME_STAMP_SEQUENCE; - data.notificationClass = 50; - data.priority = 50; - data.notifyType = NOTIFY_ALARM; - data.fromState = EVENT_STATE_NORMAL; - data.toState = EVENT_STATE_OFFNORMAL; - - data.eventType = EVENT_CHANGE_OF_STATE; - data.notificationParams.changeOfState.newState.tag = UNITS; - data.notificationParams.changeOfState.newState.state.units = - UNITS_SQUARE_METERS; - - bitstring_init(&data.notificationParams.changeOfState.statusFlags); - bitstring_set_bit(&data.notificationParams.changeOfState.statusFlags, - STATUS_FLAG_IN_ALARM, true); - bitstring_set_bit(&data.notificationParams.changeOfState.statusFlags, - STATUS_FLAG_FAULT, false); - bitstring_set_bit(&data.notificationParams.changeOfState.statusFlags, - STATUS_FLAG_OVERRIDDEN, false); - bitstring_set_bit(&data.notificationParams.changeOfState.statusFlags, - STATUS_FLAG_OUT_OF_SERVICE, false); - - inLen = event_notify_encode_service_request(&buffer[0], &data); - - outLen = event_notify_decode_service_request(&buffer[0], inLen, &data2); - - ct_test(pTest, inLen == outLen); - testBaseEventState(pTest); - - ct_test(pTest, - data.notificationParams.changeOfState.newState.tag == - data2.notificationParams.changeOfState.newState.tag); - ct_test(pTest, - data.notificationParams.changeOfState.newState.state.units == - data2.notificationParams.changeOfState.newState.state.units); - - ct_test(pTest, - bitstring_same(&data.notificationParams.changeOfState.statusFlags, - &data2.notificationParams.changeOfState.statusFlags)); - - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - - /* - ** Same, but timestamp of - */ - data.timeStamp.tag = TIME_STAMP_DATETIME; - data.timeStamp.value.dateTime.time.hour = 1; - data.timeStamp.value.dateTime.time.min = 2; - data.timeStamp.value.dateTime.time.sec = 3; - data.timeStamp.value.dateTime.time.hundredths = 4; - - data.timeStamp.value.dateTime.date.day = 1; - data.timeStamp.value.dateTime.date.month = 1; - data.timeStamp.value.dateTime.date.wday = 1; - data.timeStamp.value.dateTime.date.year = 1945; - - memset(buffer, 0, MAX_APDU); - inLen = event_notify_encode_service_request(&buffer[0], &data); - - memset(&data2, 0, sizeof(data2)); - data2.messageText = &messageText2; - outLen = event_notify_decode_service_request(&buffer[0], inLen, &data2); - - ct_test(pTest, inLen == outLen); - testBaseEventState(pTest); - ct_test(pTest, - data.notificationParams.changeOfState.newState.tag == - data2.notificationParams.changeOfState.newState.tag); - ct_test(pTest, - data.notificationParams.changeOfState.newState.state.units == - data2.notificationParams.changeOfState.newState.state.units); - - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - - /* - ** Event Type = EVENT_CHANGE_OF_BITSTRING - */ - data.timeStamp.value.sequenceNum = 1234; - data.timeStamp.tag = TIME_STAMP_SEQUENCE; - - data.eventType = EVENT_CHANGE_OF_BITSTRING; - - bitstring_init( - &data.notificationParams.changeOfBitstring.referencedBitString); - bitstring_set_bit( - &data.notificationParams.changeOfBitstring.referencedBitString, 0, - true); - bitstring_set_bit( - &data.notificationParams.changeOfBitstring.referencedBitString, 1, - false); - bitstring_set_bit( - &data.notificationParams.changeOfBitstring.referencedBitString, 2, - true); - bitstring_set_bit( - &data.notificationParams.changeOfBitstring.referencedBitString, 2, - false); - - bitstring_init(&data.notificationParams.changeOfBitstring.statusFlags); - - bitstring_set_bit(&data.notificationParams.changeOfBitstring.statusFlags, - STATUS_FLAG_IN_ALARM, true); - bitstring_set_bit(&data.notificationParams.changeOfBitstring.statusFlags, - STATUS_FLAG_FAULT, false); - bitstring_set_bit(&data.notificationParams.changeOfBitstring.statusFlags, - STATUS_FLAG_OVERRIDDEN, false); - bitstring_set_bit(&data.notificationParams.changeOfBitstring.statusFlags, - STATUS_FLAG_OUT_OF_SERVICE, false); - - memset(buffer, 0, MAX_APDU); - inLen = event_notify_encode_service_request(&buffer[0], &data); - - memset(&data2, 0, sizeof(data2)); - data2.messageText = &messageText2; - outLen = event_notify_decode_service_request(&buffer[0], inLen, &data2); - - ct_test(pTest, inLen == outLen); - testBaseEventState(pTest); - - ct_test(pTest, - bitstring_same( - &data.notificationParams.changeOfBitstring.referencedBitString, - &data2.notificationParams.changeOfBitstring.referencedBitString)); - - ct_test(pTest, - bitstring_same(&data.notificationParams.changeOfBitstring.statusFlags, - &data2.notificationParams.changeOfBitstring.statusFlags)); - - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /* - ** Event Type = EVENT_CHANGE_OF_VALUE - float value - */ - - data.eventType = EVENT_CHANGE_OF_VALUE; - data.notificationParams.changeOfValue.tag = CHANGE_OF_VALUE_REAL; - data.notificationParams.changeOfValue.newValue.changeValue = 1.23f; - - bitstring_init(&data.notificationParams.changeOfValue.statusFlags); - - bitstring_set_bit(&data.notificationParams.changeOfValue.statusFlags, - STATUS_FLAG_IN_ALARM, true); - bitstring_set_bit(&data.notificationParams.changeOfValue.statusFlags, - STATUS_FLAG_FAULT, false); - bitstring_set_bit(&data.notificationParams.changeOfValue.statusFlags, - STATUS_FLAG_OVERRIDDEN, false); - bitstring_set_bit(&data.notificationParams.changeOfValue.statusFlags, - STATUS_FLAG_OUT_OF_SERVICE, false); - - memset(buffer, 0, MAX_APDU); - inLen = event_notify_encode_service_request(&buffer[0], &data); - - memset(&data2, 0, sizeof(data2)); - data2.messageText = &messageText2; - outLen = event_notify_decode_service_request(&buffer[0], inLen, &data2); - - ct_test(pTest, inLen == outLen); - testBaseEventState(pTest); - - ct_test(pTest, - bitstring_same(&data.notificationParams.changeOfValue.statusFlags, - &data2.notificationParams.changeOfValue.statusFlags)); - - ct_test(pTest, - data.notificationParams.changeOfValue.tag == - data2.notificationParams.changeOfValue.tag); - - ct_test(pTest, - data.notificationParams.changeOfValue.newValue.changeValue == - data2.notificationParams.changeOfValue.newValue.changeValue); - - /* - ** Event Type = EVENT_CHANGE_OF_VALUE - bitstring value - */ - - data.notificationParams.changeOfValue.tag = CHANGE_OF_VALUE_BITS; - - bitstring_init(&data.notificationParams.changeOfValue.newValue.changedBits); - bitstring_set_bit( - &data.notificationParams.changeOfValue.newValue.changedBits, 0, true); - bitstring_set_bit( - &data.notificationParams.changeOfValue.newValue.changedBits, 1, false); - bitstring_set_bit( - &data.notificationParams.changeOfValue.newValue.changedBits, 2, false); - bitstring_set_bit( - &data.notificationParams.changeOfValue.newValue.changedBits, 3, false); - - memset(buffer, 0, MAX_APDU); - inLen = event_notify_encode_service_request(&buffer[0], &data); - - memset(&data2, 0, sizeof(data2)); - data2.messageText = &messageText2; - outLen = event_notify_decode_service_request(&buffer[0], inLen, &data2); - - ct_test(pTest, inLen == outLen); - testBaseEventState(pTest); - - ct_test(pTest, - bitstring_same(&data.notificationParams.changeOfValue.statusFlags, - &data2.notificationParams.changeOfValue.statusFlags)); - - ct_test(pTest, - data.notificationParams.changeOfValue.tag == - data2.notificationParams.changeOfValue.tag); - - ct_test(pTest, - bitstring_same( - &data.notificationParams.changeOfValue.newValue.changedBits, - &data2.notificationParams.changeOfValue.newValue.changedBits)); - - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /* - ** Event Type = EVENT_COMMAND_FAILURE - */ - - - /* - ** commandValue = enumerated - */ - data.eventType = EVENT_COMMAND_FAILURE; - data.notificationParams.commandFailure.tag = COMMAND_FAILURE_BINARY_PV; - data.notificationParams.commandFailure.commandValue.binaryValue = - BINARY_INACTIVE; - data.notificationParams.commandFailure.feedbackValue.binaryValue = - BINARY_ACTIVE; - - bitstring_init(&data.notificationParams.commandFailure.statusFlags); - - bitstring_set_bit(&data.notificationParams.commandFailure.statusFlags, - STATUS_FLAG_IN_ALARM, true); - bitstring_set_bit(&data.notificationParams.commandFailure.statusFlags, - STATUS_FLAG_FAULT, false); - bitstring_set_bit(&data.notificationParams.commandFailure.statusFlags, - STATUS_FLAG_OVERRIDDEN, false); - bitstring_set_bit(&data.notificationParams.commandFailure.statusFlags, - STATUS_FLAG_OUT_OF_SERVICE, false); - - memset(buffer, 0, MAX_APDU); - inLen = event_notify_encode_service_request(&buffer[0], &data); - - memset(&data2, 0, sizeof(data2)); - data2.messageText = &messageText2; - outLen = event_notify_decode_service_request(&buffer[0], inLen, &data2); - - ct_test(pTest, inLen == outLen); - testBaseEventState(pTest); - - ct_test(pTest, - data.notificationParams.commandFailure.commandValue.binaryValue == - data2.notificationParams.commandFailure.commandValue.binaryValue); - - ct_test(pTest, - data.notificationParams.commandFailure.feedbackValue.binaryValue == - data2.notificationParams.commandFailure.feedbackValue.binaryValue); - - ct_test(pTest, - bitstring_same(&data.notificationParams.commandFailure.statusFlags, - &data2.notificationParams.commandFailure.statusFlags)); - - /* - ** commandValue = unsigned - */ - data.eventType = EVENT_COMMAND_FAILURE; - data.notificationParams.commandFailure.tag = COMMAND_FAILURE_UNSIGNED; - data.notificationParams.commandFailure.commandValue.unsignedValue = 10; - data.notificationParams.commandFailure.feedbackValue.unsignedValue = 2; - - bitstring_init(&data.notificationParams.commandFailure.statusFlags); - - bitstring_set_bit(&data.notificationParams.commandFailure.statusFlags, - STATUS_FLAG_IN_ALARM, true); - bitstring_set_bit(&data.notificationParams.commandFailure.statusFlags, - STATUS_FLAG_FAULT, false); - bitstring_set_bit(&data.notificationParams.commandFailure.statusFlags, - STATUS_FLAG_OVERRIDDEN, false); - bitstring_set_bit(&data.notificationParams.commandFailure.statusFlags, - STATUS_FLAG_OUT_OF_SERVICE, false); - - memset(buffer, 0, MAX_APDU); - inLen = event_notify_encode_service_request(&buffer[0], &data); - - memset(&data2, 0, sizeof(data2)); - data2.messageText = &messageText2; - outLen = event_notify_decode_service_request(&buffer[0], inLen, &data2); - - ct_test(pTest, inLen == outLen); - testBaseEventState(pTest); - - ct_test(pTest, - data.notificationParams.commandFailure.commandValue.unsignedValue == - data2.notificationParams.commandFailure.commandValue.unsignedValue); - - ct_test(pTest, - data.notificationParams.commandFailure.feedbackValue.unsignedValue == - data2.notificationParams.commandFailure.feedbackValue.unsignedValue); - - ct_test(pTest, - bitstring_same(&data.notificationParams.commandFailure.statusFlags, - &data2.notificationParams.commandFailure.statusFlags)); - - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /* - ** Event Type = EVENT_FLOATING_LIMIT - */ - data.eventType = EVENT_FLOATING_LIMIT; - data.notificationParams.floatingLimit.referenceValue = 1.23f; - data.notificationParams.floatingLimit.setPointValue = 2.34f; - data.notificationParams.floatingLimit.errorLimit = 3.45f; - - bitstring_init(&data.notificationParams.floatingLimit.statusFlags); - - bitstring_set_bit(&data.notificationParams.floatingLimit.statusFlags, - STATUS_FLAG_IN_ALARM, true); - bitstring_set_bit(&data.notificationParams.floatingLimit.statusFlags, - STATUS_FLAG_FAULT, false); - bitstring_set_bit(&data.notificationParams.floatingLimit.statusFlags, - STATUS_FLAG_OVERRIDDEN, false); - bitstring_set_bit(&data.notificationParams.floatingLimit.statusFlags, - STATUS_FLAG_OUT_OF_SERVICE, false); - - memset(buffer, 0, MAX_APDU); - inLen = event_notify_encode_service_request(&buffer[0], &data); - - memset(&data2, 0, sizeof(data2)); - data2.messageText = &messageText2; - outLen = event_notify_decode_service_request(&buffer[0], inLen, &data2); - - ct_test(pTest, inLen == outLen); - testBaseEventState(pTest); - - ct_test(pTest, - data.notificationParams.floatingLimit.referenceValue == - data2.notificationParams.floatingLimit.referenceValue); - - ct_test(pTest, - data.notificationParams.floatingLimit.setPointValue == - data2.notificationParams.floatingLimit.setPointValue); - - ct_test(pTest, - data.notificationParams.floatingLimit.errorLimit == - data2.notificationParams.floatingLimit.errorLimit); - ct_test(pTest, - bitstring_same(&data.notificationParams.floatingLimit.statusFlags, - &data2.notificationParams.floatingLimit.statusFlags)); - - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /* - ** Event Type = EVENT_OUT_OF_RANGE - */ - data.eventType = EVENT_OUT_OF_RANGE; - data.notificationParams.outOfRange.exceedingValue = 3.45f; - data.notificationParams.outOfRange.deadband = 2.34f; - data.notificationParams.outOfRange.exceededLimit = 1.23f; - - bitstring_init(&data.notificationParams.outOfRange.statusFlags); - - bitstring_set_bit(&data.notificationParams.outOfRange.statusFlags, - STATUS_FLAG_IN_ALARM, true); - bitstring_set_bit(&data.notificationParams.outOfRange.statusFlags, - STATUS_FLAG_FAULT, false); - bitstring_set_bit(&data.notificationParams.outOfRange.statusFlags, - STATUS_FLAG_OVERRIDDEN, false); - bitstring_set_bit(&data.notificationParams.outOfRange.statusFlags, - STATUS_FLAG_OUT_OF_SERVICE, false); - - memset(buffer, 0, MAX_APDU); - inLen = event_notify_encode_service_request(&buffer[0], &data); - - memset(&data2, 0, sizeof(data2)); - data2.messageText = &messageText2; - outLen = event_notify_decode_service_request(&buffer[0], inLen, &data2); - - ct_test(pTest, inLen == outLen); - testBaseEventState(pTest); - - ct_test(pTest, - data.notificationParams.outOfRange.deadband == - data2.notificationParams.outOfRange.deadband); - - ct_test(pTest, - data.notificationParams.outOfRange.exceededLimit == - data2.notificationParams.outOfRange.exceededLimit); - - ct_test(pTest, - data.notificationParams.outOfRange.exceedingValue == - data2.notificationParams.outOfRange.exceedingValue); - ct_test(pTest, - bitstring_same(&data.notificationParams.outOfRange.statusFlags, - &data2.notificationParams.outOfRange.statusFlags)); - - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /* - ** Event Type = EVENT_CHANGE_OF_LIFE_SAFETY - */ - data.eventType = EVENT_CHANGE_OF_LIFE_SAFETY; - data.notificationParams.changeOfLifeSafety.newState = - LIFE_SAFETY_STATE_ALARM; - data.notificationParams.changeOfLifeSafety.newMode = LIFE_SAFETY_MODE_ARMED; - data.notificationParams.changeOfLifeSafety.operationExpected = - LIFE_SAFETY_OP_RESET; - - bitstring_init(&data.notificationParams.changeOfLifeSafety.statusFlags); - - bitstring_set_bit(&data.notificationParams.changeOfLifeSafety.statusFlags, - STATUS_FLAG_IN_ALARM, true); - bitstring_set_bit(&data.notificationParams.changeOfLifeSafety.statusFlags, - STATUS_FLAG_FAULT, false); - bitstring_set_bit(&data.notificationParams.changeOfLifeSafety.statusFlags, - STATUS_FLAG_OVERRIDDEN, false); - bitstring_set_bit(&data.notificationParams.changeOfLifeSafety.statusFlags, - STATUS_FLAG_OUT_OF_SERVICE, false); - - memset(buffer, 0, MAX_APDU); - inLen = event_notify_encode_service_request(&buffer[0], &data); - - memset(&data2, 0, sizeof(data2)); - data2.messageText = &messageText2; - outLen = event_notify_decode_service_request(&buffer[0], inLen, &data2); - - ct_test(pTest, inLen == outLen); - testBaseEventState(pTest); - - ct_test(pTest, - data.notificationParams.changeOfLifeSafety.newMode == - data2.notificationParams.changeOfLifeSafety.newMode); - - ct_test(pTest, - data.notificationParams.changeOfLifeSafety.newState == - data2.notificationParams.changeOfLifeSafety.newState); - - ct_test(pTest, - data.notificationParams.changeOfLifeSafety.operationExpected == - data2.notificationParams.changeOfLifeSafety.operationExpected); - - ct_test(pTest, - bitstring_same(&data.notificationParams.changeOfLifeSafety.statusFlags, - &data2.notificationParams.changeOfLifeSafety.statusFlags)); - - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /* - ** Event Type = EVENT_UNSIGNED_RANGE - */ - data.eventType = EVENT_UNSIGNED_RANGE; - data.notificationParams.unsignedRange.exceedingValue = 1234; - data.notificationParams.unsignedRange.exceededLimit = 2345; - - bitstring_init(&data.notificationParams.unsignedRange.statusFlags); - - bitstring_set_bit(&data.notificationParams.unsignedRange.statusFlags, - STATUS_FLAG_IN_ALARM, true); - bitstring_set_bit(&data.notificationParams.unsignedRange.statusFlags, - STATUS_FLAG_FAULT, false); - bitstring_set_bit(&data.notificationParams.unsignedRange.statusFlags, - STATUS_FLAG_OVERRIDDEN, false); - bitstring_set_bit(&data.notificationParams.unsignedRange.statusFlags, - STATUS_FLAG_OUT_OF_SERVICE, false); - - memset(buffer, 0, MAX_APDU); - inLen = event_notify_encode_service_request(&buffer[0], &data); - - memset(&data2, 0, sizeof(data2)); - data2.messageText = &messageText2; - outLen = event_notify_decode_service_request(&buffer[0], inLen, &data2); - - ct_test(pTest, inLen == outLen); - testBaseEventState(pTest); - - ct_test(pTest, - data.notificationParams.unsignedRange.exceedingValue == - data2.notificationParams.unsignedRange.exceedingValue); - - ct_test(pTest, - data.notificationParams.unsignedRange.exceededLimit == - data2.notificationParams.unsignedRange.exceededLimit); - - ct_test(pTest, - bitstring_same(&data.notificationParams.unsignedRange.statusFlags, - &data2.notificationParams.unsignedRange.statusFlags)); - - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /* - ** Event Type = EVENT_BUFFER_READY - */ - data.eventType = EVENT_BUFFER_READY; - data.notificationParams.bufferReady.previousNotification = 1234; - data.notificationParams.bufferReady.currentNotification = 2345; - data.notificationParams.bufferReady.bufferProperty.deviceIdentifier.type = - OBJECT_DEVICE; - data.notificationParams.bufferReady.bufferProperty.deviceIdentifier - .instance = 500; - data.notificationParams.bufferReady.bufferProperty.objectIdentifier.type = - OBJECT_ANALOG_INPUT; - data.notificationParams.bufferReady.bufferProperty.objectIdentifier - .instance = 100; - data.notificationParams.bufferReady.bufferProperty.propertyIdentifier = - PROP_PRESENT_VALUE; - data.notificationParams.bufferReady.bufferProperty.arrayIndex = 0; - - memset(buffer, 0, MAX_APDU); - inLen = event_notify_encode_service_request(&buffer[0], &data); - - memset(&data2, 0, sizeof(data2)); - data2.messageText = &messageText2; - outLen = event_notify_decode_service_request(&buffer[0], inLen, &data2); - - ct_test(pTest, inLen == outLen); - testBaseEventState(pTest); - - ct_test(pTest, - data.notificationParams.bufferReady.previousNotification == - data2.notificationParams.bufferReady.previousNotification); - - ct_test(pTest, - data.notificationParams.bufferReady.currentNotification == - data2.notificationParams.bufferReady.currentNotification); - - ct_test(pTest, - data.notificationParams.bufferReady.bufferProperty.deviceIdentifier - .type == - data2.notificationParams.bufferReady.bufferProperty.deviceIdentifier - .type); - - ct_test(pTest, - data.notificationParams.bufferReady.bufferProperty.deviceIdentifier - .instance == - data2.notificationParams.bufferReady.bufferProperty.deviceIdentifier - .instance); - - ct_test(pTest, - data.notificationParams.bufferReady.bufferProperty.objectIdentifier - .instance == - data2.notificationParams.bufferReady.bufferProperty.objectIdentifier - .instance); - - ct_test(pTest, - data.notificationParams.bufferReady.bufferProperty.objectIdentifier - .type == - data2.notificationParams.bufferReady.bufferProperty.objectIdentifier - .type); - - ct_test(pTest, - data.notificationParams.bufferReady.bufferProperty.propertyIdentifier == - data2.notificationParams.bufferReady.bufferProperty - .propertyIdentifier); - - ct_test(pTest, - data.notificationParams.bufferReady.bufferProperty.arrayIndex == - data2.notificationParams.bufferReady.bufferProperty.arrayIndex); - - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /* - ** Event Type = EVENT_ACCESS_EVENT - */ - - // OPTIONAL authenticationFactor omitted - data.eventType = EVENT_ACCESS_EVENT; - data.notificationParams.accessEvent.accessEvent = - ACCESS_EVENT_LOCKED_BY_HIGHER_AUTHORITY; - data.notificationParams.accessEvent.accessEventTag = 7; - data.notificationParams.accessEvent.accessEventTime.tag = - TIME_STAMP_SEQUENCE; - data.notificationParams.accessEvent.accessEventTime.value.sequenceNum = 17; - data.notificationParams.accessEvent.accessCredential. - deviceIdentifier.instance = 1234; - data.notificationParams.accessEvent.accessCredential. - deviceIdentifier.type = OBJECT_DEVICE; - data.notificationParams.accessEvent.accessCredential. - objectIdentifier.instance = 17; - data.notificationParams.accessEvent.accessCredential. - objectIdentifier.type = OBJECT_ACCESS_POINT; - data.notificationParams.accessEvent.authenticationFactor.format_type = AUTHENTICATION_FACTOR_MAX; // omit authenticationFactor - - bitstring_init(&data.notificationParams.accessEvent.statusFlags); - bitstring_set_bit(&data.notificationParams.accessEvent.statusFlags, - STATUS_FLAG_IN_ALARM, true); - bitstring_set_bit(&data.notificationParams.accessEvent.statusFlags, - STATUS_FLAG_FAULT, false); - bitstring_set_bit(&data.notificationParams.accessEvent.statusFlags, - STATUS_FLAG_OVERRIDDEN, false); - bitstring_set_bit(&data.notificationParams.accessEvent.statusFlags, - STATUS_FLAG_OUT_OF_SERVICE, false); - - memset(buffer, 0, MAX_APDU); - inLen = event_notify_encode_service_request(&buffer[0], &data); - - memset(&data2, 0, sizeof(data2)); - data2.messageText = &messageText2; - outLen = event_notify_decode_service_request(&buffer[0], inLen, &data2); - - ct_test(pTest, inLen == outLen); - testBaseEventState(pTest); - - ct_test(pTest, - data.notificationParams.accessEvent.accessEvent == - data2.notificationParams.accessEvent.accessEvent); - - ct_test(pTest, - bitstring_same(&data.notificationParams.accessEvent.statusFlags, - &data2.notificationParams.accessEvent.statusFlags)); - - ct_test(pTest, - data.notificationParams.accessEvent.accessEventTag == - data2.notificationParams.accessEvent.accessEventTag); - - ct_test(pTest, - data.notificationParams.accessEvent.accessEventTime.tag == - data2.notificationParams.accessEvent.accessEventTime.tag); - - ct_test(pTest, - data.notificationParams.accessEvent.accessEventTime. - value.sequenceNum == - data2.notificationParams.accessEvent.accessEventTime. - value.sequenceNum); - - ct_test(pTest, - data.notificationParams.accessEvent.accessCredential. - deviceIdentifier.instance == - data2.notificationParams.accessEvent.accessCredential. - deviceIdentifier.instance); - - ct_test(pTest, - data.notificationParams.accessEvent.accessCredential. - deviceIdentifier.type == - data2.notificationParams.accessEvent.accessCredential. - deviceIdentifier.type); - - ct_test(pTest, - data.notificationParams.accessEvent.accessCredential. - objectIdentifier.instance == - data2.notificationParams.accessEvent.accessCredential. - objectIdentifier.instance); - - ct_test(pTest, - data.notificationParams.accessEvent.accessCredential. - objectIdentifier.type == - data2.notificationParams.accessEvent.accessCredential. - objectIdentifier.type); - - // OPTIONAL authenticationFactor included - data.eventType = EVENT_ACCESS_EVENT; - data.notificationParams.accessEvent.accessEvent = - ACCESS_EVENT_LOCKED_BY_HIGHER_AUTHORITY; - data.notificationParams.accessEvent.accessEventTag = 7; - data.notificationParams.accessEvent.accessEventTime.tag = - TIME_STAMP_SEQUENCE; - data.notificationParams.accessEvent.accessEventTime.value.sequenceNum = 17; - data.notificationParams.accessEvent.accessCredential. - deviceIdentifier.instance = 1234; - data.notificationParams.accessEvent.accessCredential. - deviceIdentifier.type = OBJECT_DEVICE; - data.notificationParams.accessEvent.accessCredential. - objectIdentifier.instance = 17; - data.notificationParams.accessEvent.accessCredential. - objectIdentifier.type = OBJECT_ACCESS_POINT; - data.notificationParams.accessEvent.authenticationFactor.format_type = - AUTHENTICATION_FACTOR_SIMPLE_NUMBER16; - data.notificationParams.accessEvent.authenticationFactor.format_class = - 215; - uint8_t octetstringValue[2] = { 0x00, 0x10 }; - - octetstring_init(&data.notificationParams.accessEvent. - authenticationFactor.value, octetstringValue, 2); - - bitstring_init(&data.notificationParams.accessEvent.statusFlags); - bitstring_set_bit(&data.notificationParams.accessEvent.statusFlags, - STATUS_FLAG_IN_ALARM, true); - bitstring_set_bit(&data.notificationParams.accessEvent.statusFlags, - STATUS_FLAG_FAULT, false); - bitstring_set_bit(&data.notificationParams.accessEvent.statusFlags, - STATUS_FLAG_OVERRIDDEN, false); - bitstring_set_bit(&data.notificationParams.accessEvent.statusFlags, - STATUS_FLAG_OUT_OF_SERVICE, false); - - memset(buffer, 0, MAX_APDU); - inLen = event_notify_encode_service_request(&buffer[0], &data); - - memset(&data2, 0, sizeof(data2)); - data2.messageText = &messageText2; - outLen = event_notify_decode_service_request(&buffer[0], inLen, &data2); - - ct_test(pTest, inLen == outLen); - testBaseEventState(pTest); - - ct_test(pTest, - data.notificationParams.accessEvent.accessEvent == - data2.notificationParams.accessEvent.accessEvent); - - ct_test(pTest, - bitstring_same(&data.notificationParams.accessEvent.statusFlags, - &data2.notificationParams.accessEvent.statusFlags)); - - ct_test(pTest, - data.notificationParams.accessEvent.accessEventTag == - data2.notificationParams.accessEvent.accessEventTag); - - ct_test(pTest, - data.notificationParams.accessEvent.accessEventTime.tag == - data2.notificationParams.accessEvent.accessEventTime.tag); - - ct_test(pTest, - data.notificationParams.accessEvent.accessEventTime. - value.sequenceNum == - data2.notificationParams.accessEvent.accessEventTime. - value.sequenceNum); - - ct_test(pTest, - data.notificationParams.accessEvent.accessCredential. - deviceIdentifier.instance == - data2.notificationParams.accessEvent.accessCredential. - deviceIdentifier.instance); - - ct_test(pTest, - data.notificationParams.accessEvent.accessCredential. - deviceIdentifier.type == - data2.notificationParams.accessEvent.accessCredential. - deviceIdentifier.type); - - ct_test(pTest, - data.notificationParams.accessEvent.accessCredential. - objectIdentifier.instance == - data2.notificationParams.accessEvent.accessCredential. - objectIdentifier.instance); - - ct_test(pTest, - data.notificationParams.accessEvent.accessCredential. - objectIdentifier.type == - data2.notificationParams.accessEvent.accessCredential. - objectIdentifier.type); - - ct_test(pTest, - data.notificationParams.accessEvent.authenticationFactor.format_type == - data2.notificationParams.accessEvent.authenticationFactor.format_type); - - ct_test(pTest, - data.notificationParams.accessEvent. - authenticationFactor.format_class == - data2.notificationParams.accessEvent. - authenticationFactor.format_class); - - ct_test(pTest, - octetstring_value_same(&data.notificationParams. - accessEvent.authenticationFactor.value, - &data2.notificationParams.accessEvent.authenticationFactor.value)); -} - -#ifdef TEST_EVENT - -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet Event", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testEventEventState); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} - -#endif /* TEST_EVENT */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/getevent.c b/src/bacnet/getevent.c index 822b45ad..5f6856aa 100644 --- a/src/bacnet/getevent.c +++ b/src/bacnet/getevent.c @@ -317,182 +317,3 @@ int getevent_ack_decode_service_request(uint8_t *apdu, return len; } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -int getevent_decode_apdu(uint8_t *apdu, - unsigned apdu_len, - uint8_t *invoke_id, - BACNET_OBJECT_ID *lastReceivedObjectIdentifier) -{ - int len = 0; - unsigned offset = 0; - - if (!apdu) - return -1; - /* optional checking - most likely was already done prior to this call */ - if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) - return -1; - /* apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); */ - *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ - if (apdu[3] != SERVICE_CONFIRMED_GET_EVENT_INFORMATION) - return -1; - offset = 4; - - if (apdu_len > offset) { - len = getevent_decode_service_request( - &apdu[offset], apdu_len - offset, lastReceivedObjectIdentifier); - } - - return len; -} - -int getevent_ack_decode_apdu(uint8_t *apdu, - int apdu_len, /* total length of the apdu */ - uint8_t *invoke_id, - BACNET_GET_EVENT_INFORMATION_DATA *get_event_data, - bool *moreEvents) -{ - int len = 0; - int offset = 0; - - if (!apdu) - return -1; - /* optional checking - most likely was already done prior to this call */ - if (apdu[0] != PDU_TYPE_COMPLEX_ACK) - return -1; - *invoke_id = apdu[1]; - if (apdu[2] != SERVICE_CONFIRMED_GET_EVENT_INFORMATION) - return -1; - offset = 3; - if (apdu_len > offset) { - len = getevent_ack_decode_service_request( - &apdu[offset], apdu_len - offset, get_event_data, moreEvents); - } - - return len; -} - -void testGetEventInformationAck(Test *pTest) -{ - uint8_t apdu[480] = { 0 }; - int len = 0; - int apdu_len = 0; - uint8_t invoke_id = 1; - uint8_t test_invoke_id = 0; - BACNET_GET_EVENT_INFORMATION_DATA event_data; - BACNET_GET_EVENT_INFORMATION_DATA test_event_data; - bool moreEvents = false; - bool test_moreEvents = false; - unsigned i = 0; - - event_data.objectIdentifier.type = OBJECT_BINARY_INPUT; - event_data.objectIdentifier.instance = 1; - event_data.eventState = EVENT_STATE_NORMAL; - bitstring_init(&event_data.acknowledgedTransitions); - bitstring_set_bit( - &event_data.acknowledgedTransitions, TRANSITION_TO_OFFNORMAL, false); - bitstring_set_bit( - &event_data.acknowledgedTransitions, TRANSITION_TO_FAULT, false); - bitstring_set_bit( - &event_data.acknowledgedTransitions, TRANSITION_TO_NORMAL, false); - for (i = 0; i < 3; i++) { - event_data.eventTimeStamps[i].tag = TIME_STAMP_SEQUENCE; - event_data.eventTimeStamps[i].value.sequenceNum = 0; - } - event_data.notifyType = NOTIFY_ALARM; - bitstring_init(&event_data.eventEnable); - bitstring_set_bit(&event_data.eventEnable, TRANSITION_TO_OFFNORMAL, true); - bitstring_set_bit(&event_data.eventEnable, TRANSITION_TO_FAULT, true); - bitstring_set_bit(&event_data.eventEnable, TRANSITION_TO_NORMAL, true); - for (i = 0; i < 3; i++) { - event_data.eventPriorities[i] = 1; - } - event_data.next = NULL; - - len = getevent_ack_encode_apdu_init(&apdu[0], sizeof(apdu), invoke_id); - ct_test(pTest, len != 0); - ct_test(pTest, len != -1); - apdu_len = len; - len = getevent_ack_encode_apdu_data( - &apdu[apdu_len], sizeof(apdu) - apdu_len, &event_data); - ct_test(pTest, len != 0); - ct_test(pTest, len != -1); - apdu_len += len; - len = getevent_ack_encode_apdu_end( - &apdu[apdu_len], sizeof(apdu) - apdu_len, moreEvents); - ct_test(pTest, len != 0); - ct_test(pTest, len != -1); - apdu_len += len; - len = getevent_ack_decode_apdu(&apdu[0], - apdu_len, /* total length of the apdu */ - &test_invoke_id, &test_event_data, &test_moreEvents); - ct_test(pTest, len != -1); - ct_test(pTest, test_invoke_id == invoke_id); - - ct_test(pTest, - event_data.objectIdentifier.type == - test_event_data.objectIdentifier.type); - ct_test(pTest, - event_data.objectIdentifier.instance == - test_event_data.objectIdentifier.instance); - - ct_test(pTest, event_data.eventState == test_event_data.eventState); -} - -void testGetEventInformation(Test *pTest) -{ - uint8_t apdu[480] = { 0 }; - int len = 0; - int apdu_len = 0; - uint8_t invoke_id = 128; - uint8_t test_invoke_id = 0; - BACNET_OBJECT_ID lastReceivedObjectIdentifier; - BACNET_OBJECT_ID test_lastReceivedObjectIdentifier; - - lastReceivedObjectIdentifier.type = OBJECT_BINARY_INPUT; - lastReceivedObjectIdentifier.instance = 12345; - len = getevent_encode_apdu( - &apdu[0], invoke_id, &lastReceivedObjectIdentifier); - ct_test(pTest, len != 0); - apdu_len = len; - - len = getevent_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, - &test_lastReceivedObjectIdentifier); - ct_test(pTest, len != -1); - ct_test(pTest, test_invoke_id == invoke_id); - ct_test(pTest, - test_lastReceivedObjectIdentifier.type == - lastReceivedObjectIdentifier.type); - ct_test(pTest, - test_lastReceivedObjectIdentifier.instance == - lastReceivedObjectIdentifier.instance); - - return; -} - -#ifdef TEST_GET_EVENT_INFORMATION -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet GetEventInformation", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testGetEventInformation); - assert(rc); - rc = ct_addTestFunction(pTest, testGetEventInformationAck); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif -#endif /* BAC_TEST */ diff --git a/src/bacnet/getevent.h b/src/bacnet/getevent.h index 20c3966f..69ff86e4 100644 --- a/src/bacnet/getevent.h +++ b/src/bacnet/getevent.h @@ -93,33 +93,6 @@ extern "C" { BACNET_GET_EVENT_INFORMATION_DATA * get_event_data, bool * moreEvents); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - int getevent_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - uint8_t * invoke_id, - BACNET_OBJECT_ID * lastReceivedObjectIdentifier); - - BACNET_STACK_EXPORT - int getevent_ack_decode_apdu( - uint8_t * apdu, - int apdu_len, /* total length of the apdu */ - uint8_t * invoke_id, - BACNET_GET_EVENT_INFORMATION_DATA * get_event_data, - bool * moreEvents); - - BACNET_STACK_EXPORT - void testGetEventInformationAck( - Test * pTest); - - BACNET_STACK_EXPORT - void testGetEventInformation( - Test * pTest); - -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/iam.c b/src/bacnet/iam.c index 24884264..79b36403 100644 --- a/src/bacnet/iam.c +++ b/src/bacnet/iam.c @@ -163,78 +163,3 @@ int iam_decode_service_request(uint8_t *apdu, return apdu_len; } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -int iam_decode_apdu(uint8_t *apdu, - uint32_t *pDevice_id, - unsigned *pMax_apdu, - int *pSegmentation, - uint16_t *pVendor_id) -{ - int apdu_len = 0; /* total length of the apdu, return value */ - - /* valid data? */ - if (!apdu) - return -1; - /* optional checking - most likely was already done prior to this call */ - if (apdu[0] != PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST) - return -1; - if (apdu[1] != SERVICE_UNCONFIRMED_I_AM) - return -1; - apdu_len = iam_decode_service_request( - &apdu[2], pDevice_id, pMax_apdu, pSegmentation, pVendor_id); - - return apdu_len; -} - -void testIAm(Test *pTest) -{ - uint8_t apdu[480] = { 0 }; - int len = 0; - uint32_t device_id = 42; - unsigned max_apdu = 480; - int segmentation = SEGMENTATION_NONE; - uint16_t vendor_id = 42; - uint32_t test_device_id = 0; - unsigned test_max_apdu = 0; - int test_segmentation = 0; - uint16_t test_vendor_id = 0; - - len = - iam_encode_apdu(&apdu[0], device_id, max_apdu, segmentation, vendor_id); - ct_test(pTest, len != 0); - - len = iam_decode_apdu(&apdu[0], &test_device_id, &test_max_apdu, - &test_segmentation, &test_vendor_id); - - ct_test(pTest, len != -1); - ct_test(pTest, test_device_id == device_id); - ct_test(pTest, test_vendor_id == vendor_id); - ct_test(pTest, test_max_apdu == max_apdu); - ct_test(pTest, test_segmentation == segmentation); -} - -#ifdef TEST_IAM -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet I-Am", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testIAm); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_IAM */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/iam.h b/src/bacnet/iam.h index ce0e3aba..6ad89889 100644 --- a/src/bacnet/iam.h +++ b/src/bacnet/iam.h @@ -51,21 +51,6 @@ extern "C" { int *pSegmentation, uint16_t * pVendor_id); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - int iam_decode_apdu( - uint8_t * apdu, - uint32_t * pDevice_id, - unsigned *pMax_apdu, - int *pSegmentation, - uint16_t * pVendor_id); - - BACNET_STACK_EXPORT - void testIAm( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/ihave.c b/src/bacnet/ihave.c index cc42d793..746fa299 100644 --- a/src/bacnet/ihave.c +++ b/src/bacnet/ihave.c @@ -161,71 +161,3 @@ int ihave_decode_apdu( return len; } #endif - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -void testIHaveData(Test *pTest, BACNET_I_HAVE_DATA *data) -{ - uint8_t apdu[480] = { 0 }; - int len = 0; - int apdu_len = 0; - BACNET_I_HAVE_DATA test_data; - - len = ihave_encode_apdu(&apdu[0], data); - ct_test(pTest, len != 0); - apdu_len = len; - - len = ihave_decode_apdu(&apdu[0], apdu_len, &test_data); - ct_test(pTest, len != -1); - ct_test(pTest, test_data.device_id.type == data->device_id.type); - ct_test(pTest, test_data.device_id.instance == data->device_id.instance); - ct_test(pTest, test_data.object_id.type == data->object_id.type); - ct_test(pTest, test_data.object_id.instance == data->object_id.instance); - ct_test(pTest, - characterstring_same(&test_data.object_name, &data->object_name)); -} - -void testIHave(Test *pTest) -{ - BACNET_I_HAVE_DATA data; - - characterstring_init_ansi(&data.object_name, "Patricia - my love!"); - data.device_id.type = OBJECT_DEVICE; - for (data.device_id.instance = 1; - data.device_id.instance <= BACNET_MAX_INSTANCE; - data.device_id.instance <<= 1) { - for (data.object_id.type = OBJECT_ANALOG_INPUT; - data.object_id.type < MAX_BACNET_OBJECT_TYPE; - data.object_id.type++) { - for (data.object_id.instance = 1; - data.object_id.instance <= BACNET_MAX_INSTANCE; - data.object_id.instance <<= 1) { - testIHaveData(pTest, &data); - } - } - } -} - -#ifdef TEST_I_HAVE -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet I-Have", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testIHave); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_WHOIS */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/ihave.h b/src/bacnet/ihave.h index 15a6edf2..5cf4e213 100644 --- a/src/bacnet/ihave.h +++ b/src/bacnet/ihave.h @@ -56,13 +56,6 @@ extern "C" { unsigned apdu_len, BACNET_I_HAVE_DATA * data); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void testIHave( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/indtext.c b/src/bacnet/indtext.c index 214c0111..9c8da85b 100644 --- a/src/bacnet/indtext.c +++ b/src/bacnet/indtext.c @@ -181,67 +181,3 @@ unsigned indtext_count(INDTEXT_DATA *data_list) } return count; } - -#ifdef BAC_TEST -#include -#include "ctest.h" - -static INDTEXT_DATA data_list[] = { { 1, "Joshua" }, { 2, "Mary" }, - { 3, "Anna" }, { 4, "Christopher" }, { 5, "Patricia" }, { 0, NULL } }; - -void testIndexText(Test *pTest) -{ - unsigned i; /*counter */ - const char *pString; - unsigned index; - bool valid; - unsigned count = 0; - - for (i = 0; i < 10; i++) { - pString = indtext_by_index(data_list, i); - if (pString) { - count++; - valid = indtext_by_string(data_list, pString, &index); - ct_test(pTest, valid == true); - ct_test(pTest, index == i); - ct_test(pTest, - index == indtext_by_string_default(data_list, pString, index)); - } - } - ct_test(pTest, indtext_count(data_list) == count); - ct_test(pTest, indtext_by_string(data_list, "Harry", NULL) == false); - ct_test(pTest, indtext_by_string(data_list, NULL, NULL) == false); - ct_test(pTest, indtext_by_string(NULL, NULL, NULL) == false); - ct_test(pTest, indtext_by_index(data_list, 0) == NULL); - ct_test(pTest, indtext_by_index(data_list, 10) == NULL); - ct_test(pTest, indtext_by_index(NULL, 10) == NULL); - /* case insensitive versions */ - ct_test(pTest, indtext_by_istring(data_list, "JOSHUA", NULL) == true); - ct_test(pTest, indtext_by_istring(data_list, "joshua", NULL) == true); - valid = indtext_by_istring(data_list, "ANNA", &index); - ct_test( - pTest, index == indtext_by_istring_default(data_list, "ANNA", index)); -} -#endif - -#ifdef TEST_INDEX_TEXT -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("index text", NULL); - - /* individual tests */ - rc = ct_addTestFunction(pTest, testIndexText); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_INDEX_TEXT */ diff --git a/src/bacnet/indtext.h b/src/bacnet/indtext.h index c7058df1..cec1af08 100644 --- a/src/bacnet/indtext.h +++ b/src/bacnet/indtext.h @@ -105,13 +105,6 @@ extern "C" { const char *s2); #endif -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void testIndexText( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/lso.c b/src/bacnet/lso.c index 8529af99..44766f71 100644 --- a/src/bacnet/lso.c +++ b/src/bacnet/lso.c @@ -125,61 +125,3 @@ int lso_decode_service_request( return 0; } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" -#include "bacnet/bacapp.h" - -void testLSO(Test *pTest) -{ - uint8_t apdu[1000]; - int len; - - BACNET_LSO_DATA data; - BACNET_LSO_DATA rxdata; - - memset(&rxdata, 0, sizeof(rxdata)); - - characterstring_init_ansi(&data.requestingSrc, "foobar"); - data.operation = LIFE_SAFETY_OP_RESET; - data.processId = 0x1234; - data.use_target = true; - data.targetObject.instance = 0x1000; - data.targetObject.type = OBJECT_BINARY_INPUT; - - len = lso_encode_apdu(apdu, 100, &data); - - lso_decode_service_request(&apdu[4], len, &rxdata); - - ct_test(pTest, data.operation == rxdata.operation); - ct_test(pTest, data.processId == rxdata.processId); - ct_test(pTest, data.use_target == rxdata.use_target); - ct_test(pTest, data.targetObject.instance == rxdata.targetObject.instance); - ct_test(pTest, data.targetObject.type == rxdata.targetObject.type); - ct_test(pTest, - memcmp(data.requestingSrc.value, rxdata.requestingSrc.value, - rxdata.requestingSrc.length) == 0); -} - -#ifdef TEST_LSO -int main(int argc, char *argv[]) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet Life Safety Operation", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testLSO); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_COV */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/lso.h b/src/bacnet/lso.h index db8c1ba5..9f6c33be 100644 --- a/src/bacnet/lso.h +++ b/src/bacnet/lso.h @@ -58,14 +58,6 @@ extern "C" { unsigned apdu_len, BACNET_LSO_DATA * data); - -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void testLSO( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/memcopy.c b/src/bacnet/memcopy.c index 9208fc78..79862cc2 100644 --- a/src/bacnet/memcopy.c +++ b/src/bacnet/memcopy.c @@ -119,50 +119,3 @@ size_t memcopy(void *dest, return 0; } #endif - -#ifdef BAC_TEST -#include -#include - -#include "ctest.h" - -void test_memcopy(Test *pTest) -{ - char *data1 = "Joshua"; - char *data2 = "Anna"; - char buffer[480] = ""; - char big_buffer[480] = ""; - size_t len = 0; - - len = memcopy(&buffer[0], &data1[0], 0, sizeof(data1), sizeof(buffer)); - ct_test(pTest, len == sizeof(data1)); - ct_test(pTest, memcmp(&buffer[0], &data1[0], len) == 0); - len = memcopy(&buffer[0], &data2[0], len, sizeof(data2), sizeof(buffer)); - ct_test(pTest, len == sizeof(data2)); - len = memcopy( - &buffer[0], &big_buffer[0], 1, sizeof(big_buffer), sizeof(buffer)); - ct_test(pTest, len == 0); -} - -#ifdef TEST_MEM_COPY -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("Memory Copy", NULL); - - /* individual tests */ - rc = ct_addTestFunction(pTest, test_memcopy); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - - ct_destroy(pTest); - - return 0; -} -#endif -#endif /* BAC_TEST */ diff --git a/src/bacnet/npdu.c b/src/bacnet/npdu.c index c9549bea..d02cf9a7 100644 --- a/src/bacnet/npdu.c +++ b/src/bacnet/npdu.c @@ -532,164 +532,3 @@ bool npdu_confirmed_service( return status; } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -void testNPDU2(Test *pTest) -{ - uint8_t pdu[480] = { 0 }; - BACNET_ADDRESS dest = { 0 }; - BACNET_ADDRESS src = { 0 }; - BACNET_ADDRESS npdu_dest = { 0 }; - BACNET_ADDRESS npdu_src = { 0 }; - int len = 0; - bool data_expecting_reply = true; - BACNET_MESSAGE_PRIORITY priority = MESSAGE_PRIORITY_NORMAL; - BACNET_NPDU_DATA npdu_data = { 0 }; - int i = 0; /* counter */ - int npdu_len = 0; - bool network_layer_message = false; /* false if APDU */ - BACNET_NETWORK_MESSAGE_TYPE network_message_type = 0; /* optional */ - uint16_t vendor_id = 0; /* optional, if net message type is > 0x80 */ - - dest.mac_len = 6; - for (i = 0; i < dest.mac_len; i++) { - dest.mac[i] = i; - } - /* DNET,DLEN,DADR */ - dest.net = 1; - dest.len = 6; - for (i = 0; i < dest.len; i++) { - dest.adr[i] = i * 10; - } - src.mac_len = 1; - for (i = 0; i < src.mac_len; i++) { - src.mac[i] = 0x80; - } - /* SNET,SLEN,SADR */ - src.net = 2; - src.len = 1; - for (i = 0; i < src.len; i++) { - src.adr[i] = 0x40; - } - npdu_encode_npdu_data(&npdu_data, true, priority); - len = npdu_encode_pdu(&pdu[0], &dest, &src, &npdu_data); - ct_test(pTest, len != 0); - /* can we get the info back? */ - npdu_len = npdu_decode(&pdu[0], &npdu_dest, &npdu_src, &npdu_data); - ct_test(pTest, npdu_len != 0); - ct_test(pTest, npdu_data.data_expecting_reply == data_expecting_reply); - ct_test(pTest, npdu_data.network_layer_message == network_layer_message); - if (npdu_data.network_layer_message) { - ct_test(pTest, npdu_data.network_message_type == network_message_type); - } - ct_test(pTest, npdu_data.vendor_id == vendor_id); - ct_test(pTest, npdu_data.priority == priority); - /* DNET,DLEN,DADR */ - ct_test(pTest, npdu_dest.net == dest.net); - ct_test(pTest, npdu_dest.len == dest.len); - for (i = 0; i < dest.len; i++) { - ct_test(pTest, npdu_dest.adr[i] == dest.adr[i]); - } - /* SNET,SLEN,SADR */ - ct_test(pTest, npdu_src.net == src.net); - ct_test(pTest, npdu_src.len == src.len); - for (i = 0; i < src.len; i++) { - ct_test(pTest, npdu_src.adr[i] == src.adr[i]); - } -} - -void testNPDU1(Test *pTest) -{ - uint8_t pdu[480] = { 0 }; - BACNET_ADDRESS dest = { 0 }; - BACNET_ADDRESS src = { 0 }; - BACNET_ADDRESS npdu_dest = { 0 }; - BACNET_ADDRESS npdu_src = { 0 }; - int len = 0; - bool data_expecting_reply = false; - BACNET_MESSAGE_PRIORITY priority = MESSAGE_PRIORITY_NORMAL; - BACNET_NPDU_DATA npdu_data = { 0 }; - int i = 0; /* counter */ - int npdu_len = 0; - bool network_layer_message = false; /* false if APDU */ - BACNET_NETWORK_MESSAGE_TYPE network_message_type = 0; /* optional */ - uint16_t vendor_id = 0; /* optional, if net message type is > 0x80 */ - - /* mac_len = 0 if global address */ - dest.mac_len = 0; - for (i = 0; i < MAX_MAC_LEN; i++) { - dest.mac[i] = 0; - } - /* DNET,DLEN,DADR */ - dest.net = 0; - dest.len = 0; - for (i = 0; i < MAX_MAC_LEN; i++) { - dest.adr[i] = 0; - } - src.mac_len = 0; - for (i = 0; i < MAX_MAC_LEN; i++) { - src.mac[i] = 0; - } - /* SNET,SLEN,SADR */ - src.net = 0; - src.len = 0; - for (i = 0; i < MAX_MAC_LEN; i++) { - src.adr[i] = 0; - } - npdu_encode_npdu_data(&npdu_data, false, priority); - len = npdu_encode_pdu(&pdu[0], &dest, &src, &npdu_data); - ct_test(pTest, len != 0); - /* can we get the info back? */ - npdu_len = npdu_decode(&pdu[0], &npdu_dest, &npdu_src, &npdu_data); - ct_test(pTest, npdu_len != 0); - ct_test(pTest, npdu_data.data_expecting_reply == data_expecting_reply); - ct_test(pTest, npdu_data.network_layer_message == network_layer_message); - if (npdu_data.network_layer_message) { - ct_test(pTest, npdu_data.network_message_type == network_message_type); - } - ct_test(pTest, npdu_data.vendor_id == vendor_id); - ct_test(pTest, npdu_data.priority == priority); - ct_test(pTest, npdu_dest.mac_len == src.mac_len); - ct_test(pTest, npdu_src.mac_len == dest.mac_len); -} - -#ifdef TEST_NPDU -/* dummy stub for testing */ -void tsm_free_invoke_id(uint8_t invokeID) -{ - (void)invokeID; -} - -void iam_handler( - uint8_t *service_request, uint16_t service_len, BACNET_ADDRESS *src) -{ - (void)service_request; - (void)service_len; - (void)src; -} - -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet NPDU", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testNPDU1); - assert(rc); - rc = ct_addTestFunction(pTest, testNPDU2); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_NPDU */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/property.c b/src/bacnet/property.c index 2492b423..60bff28c 100644 --- a/src/bacnet/property.c +++ b/src/bacnet/property.c @@ -1567,73 +1567,3 @@ unsigned property_list_special_count( return count; } #endif - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -void testPropList(Test *pTest) -{ - unsigned i = 0, j = 0; - unsigned count = 0; - BACNET_PROPERTY_ID property = MAX_BACNET_PROPERTY_ID; - unsigned object_id = 0, object_name = 0, object_type = 0; - struct special_property_list_t property_list = { 0 }; - - for (i = 0; i < OBJECT_PROPRIETARY_MIN; i++) { - count = property_list_special_count((BACNET_OBJECT_TYPE)i, PROP_ALL); - ct_test(pTest, count >= 3); - object_id = 0; - object_name = 0; - object_type = 0; - for (j = 0; j < count; j++) { - property = property_list_special_property( - (BACNET_OBJECT_TYPE)i, PROP_ALL, j); - if (property == PROP_OBJECT_TYPE) { - object_type++; - } - if (property == PROP_OBJECT_IDENTIFIER) { - object_id++; - } - if (property == PROP_OBJECT_NAME) { - object_name++; - } - } - ct_test(pTest, object_type == 1); - ct_test(pTest, object_id == 1); - ct_test(pTest, object_name == 1); - /* test member function */ - property_list_special((BACNET_OBJECT_TYPE)i, &property_list); - ct_test(pTest, - property_list_member( - property_list.Required.pList, PROP_OBJECT_TYPE)); - ct_test(pTest, - property_list_member( - property_list.Required.pList, PROP_OBJECT_IDENTIFIER)); - ct_test(pTest, - property_list_member( - property_list.Required.pList, PROP_OBJECT_NAME)); - } -} - -#ifdef TEST_PROPLIST -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet Property List", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testPropList); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_PROPLIST */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/ptransfer.c b/src/bacnet/ptransfer.c index c2f79aa7..aefdaa20 100644 --- a/src/bacnet/ptransfer.c +++ b/src/bacnet/ptransfer.c @@ -332,324 +332,3 @@ int ptransfer_ack_encode_apdu(uint8_t *apdu, /* ptransfer_ack_decode_service_request() is the same as ptransfer_decode_service_request */ - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" -#include "bacnet/bacapp.h" - -int ptransfer_decode_apdu(uint8_t *apdu, - unsigned apdu_len, - uint8_t *invoke_id, - BACNET_PRIVATE_TRANSFER_DATA *private_data) -{ - int len = 0; - unsigned offset = 0; - - if (!apdu) - return -1; - /* optional checking - most likely was already done prior to this call */ - if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) - return -1; - /* apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); */ - /* invoke id - filled in by net layer */ - *invoke_id = apdu[2]; - if (apdu[3] != SERVICE_CONFIRMED_PRIVATE_TRANSFER) - return -1; - offset = 4; - - if (apdu_len > offset) { - len = ptransfer_decode_service_request( - &apdu[offset], apdu_len - offset, private_data); - } - - return len; -} - -int uptransfer_decode_apdu(uint8_t *apdu, - unsigned apdu_len, - BACNET_PRIVATE_TRANSFER_DATA *private_data) -{ - int len = 0; - unsigned offset = 0; - - if (!apdu) { - return -1; - } - /* optional checking - most likely was already done prior to this call */ - if (apdu[0] != PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST) { - return -1; - } - if (apdu[1] != SERVICE_UNCONFIRMED_PRIVATE_TRANSFER) { - return -1; - } - offset = 2; - if (apdu_len > offset) { - len = ptransfer_decode_service_request( - &apdu[offset], apdu_len - offset, private_data); - } - - return len; -} - -int ptransfer_ack_decode_apdu(uint8_t *apdu, - int apdu_len, /* total length of the apdu */ - uint8_t *invoke_id, - BACNET_PRIVATE_TRANSFER_DATA *private_data) -{ - int len = 0; - int offset = 0; - - if (!apdu) - return -1; - /* optional checking - most likely was already done prior to this call */ - if (apdu[0] != PDU_TYPE_COMPLEX_ACK) - return -1; - *invoke_id = apdu[1]; - if (apdu[2] != SERVICE_CONFIRMED_PRIVATE_TRANSFER) - return -1; - offset = 3; - if (apdu_len > offset) { - len = ptransfer_decode_service_request( - &apdu[offset], apdu_len - offset, private_data); - } - - return len; -} - -int ptransfer_error_decode_apdu(uint8_t *apdu, - int apdu_len, /* total length of the apdu */ - uint8_t *invoke_id, - BACNET_ERROR_CLASS *error_class, - BACNET_ERROR_CODE *error_code, - BACNET_PRIVATE_TRANSFER_DATA *private_data) -{ - int len = 0; - int offset = 0; - - if (!apdu) - return -1; - /* optional checking - most likely was already done prior to this call */ - if (apdu[0] != PDU_TYPE_ERROR) - return -1; - *invoke_id = apdu[1]; - if (apdu[2] != SERVICE_CONFIRMED_PRIVATE_TRANSFER) - return -1; - offset = 3; - if (apdu_len > offset) { - len = ptransfer_error_decode_service_request(&apdu[offset], - apdu_len - offset, error_class, error_code, private_data); - } - - return len; -} - -void test_Private_Transfer_Ack(Test *pTest) -{ - uint8_t apdu[480] = { 0 }; - int len = 0; - int apdu_len = 0; - uint8_t invoke_id = 128; - uint8_t test_invoke_id = 0; - BACNET_PRIVATE_TRANSFER_DATA private_data; - BACNET_PRIVATE_TRANSFER_DATA test_data; - uint8_t test_value[480] = { 0 }; - int private_data_len = 0; - char private_data_chunk[33] = { "00112233445566778899AABBCCDDEEFF" }; - BACNET_APPLICATION_DATA_VALUE data_value; - BACNET_APPLICATION_DATA_VALUE test_data_value; - bool status = false; - - private_data.vendorID = BACNET_VENDOR_ID; - private_data.serviceNumber = 1; - - status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING, - &private_data_chunk[0], &data_value); - ct_test(pTest, status == true); - private_data_len = - bacapp_encode_application_data(&test_value[0], &data_value); - - private_data.serviceParameters = &test_value[0]; - private_data.serviceParametersLen = private_data_len; - - len = ptransfer_ack_encode_apdu(&apdu[0], invoke_id, &private_data); - ct_test(pTest, len != 0); - ct_test(pTest, len != -1); - apdu_len = len; - len = ptransfer_ack_decode_apdu( - &apdu[0], apdu_len, &test_invoke_id, &test_data); - ct_test(pTest, len != -1); - ct_test(pTest, test_invoke_id == invoke_id); - ct_test(pTest, test_data.vendorID == private_data.vendorID); - ct_test(pTest, test_data.serviceNumber == private_data.serviceNumber); - ct_test(pTest, - test_data.serviceParametersLen == private_data.serviceParametersLen); - len = bacapp_decode_application_data(test_data.serviceParameters, - test_data.serviceParametersLen, &test_data_value); - ct_test(pTest, bacapp_same_value(&data_value, &test_data_value) == true); -} - -void test_Private_Transfer_Error(Test *pTest) -{ - uint8_t apdu[480] = { 0 }; - int len = 0; - int apdu_len = 0; - uint8_t invoke_id = 128; - uint8_t test_invoke_id = 0; - BACNET_ERROR_CLASS error_class = ERROR_CLASS_RESOURCES; - BACNET_ERROR_CODE error_code = ERROR_CODE_OPERATIONAL_PROBLEM; - BACNET_ERROR_CLASS test_error_class = 0; - BACNET_ERROR_CODE test_error_code = 0; - BACNET_PRIVATE_TRANSFER_DATA private_data; - BACNET_PRIVATE_TRANSFER_DATA test_data; - uint8_t test_value[480] = { 0 }; - int private_data_len = 0; - char private_data_chunk[33] = { "00112233445566778899AABBCCDDEEFF" }; - BACNET_APPLICATION_DATA_VALUE data_value; - BACNET_APPLICATION_DATA_VALUE test_data_value; - bool status = false; - - private_data.vendorID = BACNET_VENDOR_ID; - private_data.serviceNumber = 1; - - status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING, - &private_data_chunk[0], &data_value); - ct_test(pTest, status == true); - private_data_len = - bacapp_encode_application_data(&test_value[0], &data_value); - private_data.serviceParameters = &test_value[0]; - private_data.serviceParametersLen = private_data_len; - - len = ptransfer_error_encode_apdu( - &apdu[0], invoke_id, error_class, error_code, &private_data); - ct_test(pTest, len != 0); - ct_test(pTest, len != -1); - apdu_len = len; - len = ptransfer_error_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, - &test_error_class, &test_error_code, &test_data); - ct_test(pTest, len != -1); - ct_test(pTest, test_invoke_id == invoke_id); - ct_test(pTest, test_data.vendorID == private_data.vendorID); - ct_test(pTest, test_data.serviceNumber == private_data.serviceNumber); - ct_test(pTest, test_error_class == error_class); - ct_test(pTest, test_error_code == error_code); - ct_test(pTest, - test_data.serviceParametersLen == private_data.serviceParametersLen); - len = bacapp_decode_application_data(test_data.serviceParameters, - test_data.serviceParametersLen, &test_data_value); - ct_test(pTest, bacapp_same_value(&data_value, &test_data_value) == true); -} - -void test_Private_Transfer_Request(Test *pTest) -{ - uint8_t apdu[480] = { 0 }; - uint8_t test_value[480] = { 0 }; - int len = 0; - int apdu_len = 0; - uint8_t invoke_id = 128; - uint8_t test_invoke_id = 0; - int private_data_len = 0; - char private_data_chunk[33] = { "00112233445566778899AABBCCDDEEFF" }; - BACNET_APPLICATION_DATA_VALUE data_value = { 0 }; - BACNET_APPLICATION_DATA_VALUE test_data_value = { 0 }; - BACNET_PRIVATE_TRANSFER_DATA private_data = { 0 }; - BACNET_PRIVATE_TRANSFER_DATA test_data = { 0 }; - bool status = false; - - private_data.vendorID = BACNET_VENDOR_ID; - private_data.serviceNumber = 1; - - status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING, - &private_data_chunk[0], &data_value); - ct_test(pTest, status == true); - private_data_len = - bacapp_encode_application_data(&test_value[0], &data_value); - private_data.serviceParameters = &test_value[0]; - private_data.serviceParametersLen = private_data_len; - - len = ptransfer_encode_apdu(&apdu[0], invoke_id, &private_data); - ct_test(pTest, len != 0); - apdu_len = len; - len = - ptransfer_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &test_data); - ct_test(pTest, len != -1); - ct_test(pTest, test_data.vendorID == private_data.vendorID); - ct_test(pTest, test_data.serviceNumber == private_data.serviceNumber); - ct_test(pTest, - test_data.serviceParametersLen == private_data.serviceParametersLen); - len = bacapp_decode_application_data(test_data.serviceParameters, - test_data.serviceParametersLen, &test_data_value); - ct_test(pTest, bacapp_same_value(&data_value, &test_data_value) == true); - - return; -} - -void test_Unconfirmed_Private_Transfer_Request(Test *pTest) -{ - uint8_t apdu[480] = { 0 }; - uint8_t test_value[480] = { 0 }; - int len = 0; - int apdu_len = 0; - int private_data_len = 0; - char private_data_chunk[32] = { "I Love You, Patricia!" }; - BACNET_APPLICATION_DATA_VALUE data_value; - BACNET_APPLICATION_DATA_VALUE test_data_value; - BACNET_PRIVATE_TRANSFER_DATA private_data; - BACNET_PRIVATE_TRANSFER_DATA test_data; - bool status = false; - - private_data.vendorID = BACNET_VENDOR_ID; - private_data.serviceNumber = 1; - - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_CHARACTER_STRING, - &private_data_chunk[0], &data_value); - ct_test(pTest, status == true); - private_data_len = - bacapp_encode_application_data(&test_value[0], &data_value); - private_data.serviceParameters = &test_value[0]; - private_data.serviceParametersLen = private_data_len; - - len = uptransfer_encode_apdu(&apdu[0], &private_data); - ct_test(pTest, len != 0); - apdu_len = len; - len = uptransfer_decode_apdu(&apdu[0], apdu_len, &test_data); - ct_test(pTest, len != -1); - ct_test(pTest, test_data.vendorID == private_data.vendorID); - ct_test(pTest, test_data.serviceNumber == private_data.serviceNumber); - ct_test(pTest, - test_data.serviceParametersLen == private_data.serviceParametersLen); - len = bacapp_decode_application_data(test_data.serviceParameters, - test_data.serviceParametersLen, &test_data_value); - ct_test(pTest, bacapp_same_value(&data_value, &test_data_value) == true); - - return; -} - -#ifdef TEST_PRIVATE_TRANSFER -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet PrivateTransfer", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, test_Private_Transfer_Request); - assert(rc); - rc = ct_addTestFunction(pTest, test_Private_Transfer_Ack); - assert(rc); - rc = ct_addTestFunction(pTest, test_Private_Transfer_Error); - assert(rc); - rc = ct_addTestFunction(pTest, test_Unconfirmed_Private_Transfer_Request); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_READ_PROPERTY */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/ptransfer.h b/src/bacnet/ptransfer.h index 7262c727..c1b5f3d9 100644 --- a/src/bacnet/ptransfer.h +++ b/src/bacnet/ptransfer.h @@ -77,19 +77,6 @@ extern "C" { /* ptransfer_ack_decode_service_request() is the same as ptransfer_decode_service_request */ -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void test_Private_Transfer_Request( - Test * pTest); - BACNET_STACK_EXPORT - void test_Private_Transfer_Ack( - Test * pTest); - BACNET_STACK_EXPORT - void test_Private_Transfer_Error( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/rd.c b/src/bacnet/rd.c index 25d42e11..a64d921b 100644 --- a/src/bacnet/rd.c +++ b/src/bacnet/rd.c @@ -130,85 +130,3 @@ int rd_decode_service_request(uint8_t *apdu, return (int)len; } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -int rd_decode_apdu(uint8_t *apdu, - unsigned apdu_len, - uint8_t *invoke_id, - BACNET_REINITIALIZED_STATE *state, - BACNET_CHARACTER_STRING *password) -{ - int len = 0; - unsigned offset = 0; - - if (!apdu) - return -1; - /* optional checking - most likely was already done prior to this call */ - if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) - return -1; - /* apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); */ - *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ - if (apdu[3] != SERVICE_CONFIRMED_REINITIALIZE_DEVICE) - return -1; - offset = 4; - - if (apdu_len > offset) { - len = rd_decode_service_request( - &apdu[offset], apdu_len - offset, state, password); - } - - return len; -} - -void test_ReinitializeDevice(Test *pTest) -{ - uint8_t apdu[480] = { 0 }; - int len = 0; - int apdu_len = 0; - uint8_t invoke_id = 128; - uint8_t test_invoke_id = 0; - BACNET_REINITIALIZED_STATE state; - BACNET_REINITIALIZED_STATE test_state; - BACNET_CHARACTER_STRING password; - BACNET_CHARACTER_STRING test_password; - - state = BACNET_REINIT_WARMSTART; - characterstring_init_ansi(&password, "John 3:16"); - len = rd_encode_apdu(&apdu[0], invoke_id, state, &password); - ct_test(pTest, len != 0); - apdu_len = len; - - len = rd_decode_apdu( - &apdu[0], apdu_len, &test_invoke_id, &test_state, &test_password); - ct_test(pTest, len != -1); - ct_test(pTest, test_invoke_id == invoke_id); - ct_test(pTest, test_state == state); - ct_test(pTest, characterstring_same(&test_password, &password)); - - return; -} - -#ifdef TEST_REINITIALIZE_DEVICE -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet ReinitializeDevice", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, test_ReinitializeDevice); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_REINITIALIZE_DEVICE */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/rd.h b/src/bacnet/rd.h index aeb6c4e2..b3bc7fdf 100644 --- a/src/bacnet/rd.h +++ b/src/bacnet/rd.h @@ -61,21 +61,6 @@ extern "C" { BACNET_REINITIALIZED_STATE * state, BACNET_CHARACTER_STRING * password); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - int rd_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - uint8_t * invoke_id, - BACNET_REINITIALIZED_STATE * state, - BACNET_CHARACTER_STRING * password); - - BACNET_STACK_EXPORT - void test_ReinitializeDevice( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/reject.c b/src/bacnet/reject.c index 0d36f48d..c999685b 100644 --- a/src/bacnet/reject.c +++ b/src/bacnet/reject.c @@ -198,127 +198,3 @@ int reject_decode_service_request(uint8_t *apdu, return len; } #endif - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -/* decode the whole APDU - mainly used for unit testing */ -static int reject_decode_apdu(uint8_t *apdu, - unsigned apdu_len, - uint8_t *invoke_id, - uint8_t *reject_reason) -{ - int len = 0; - - if (!apdu) - return -1; - /* optional checking - most likely was already done prior to this call */ - if (apdu_len) { - if (apdu[0] != PDU_TYPE_REJECT) - return -1; - if (apdu_len > 1) { - len = reject_decode_service_request( - &apdu[1], apdu_len - 1, invoke_id, reject_reason); - } - } - - return len; -} - -static void testRejectEncodeDecode(Test *pTest) -{ - uint8_t apdu[480] = { 0 }; - int len = 0; - int apdu_len = 0; - uint8_t invoke_id = 0; - uint8_t reject_reason = 0; - uint8_t test_invoke_id = 0; - uint8_t test_reject_reason = 0; - - len = reject_encode_apdu(&apdu[0], invoke_id, reject_reason); - ct_test(pTest, len != 0); - apdu_len = len; - - len = reject_decode_apdu( - &apdu[0], apdu_len, &test_invoke_id, &test_reject_reason); - ct_test(pTest, len != -1); - ct_test(pTest, test_invoke_id == invoke_id); - ct_test(pTest, test_reject_reason == reject_reason); - - /* change type to get negative response */ - apdu[0] = PDU_TYPE_ABORT; - len = reject_decode_apdu( - &apdu[0], apdu_len, &test_invoke_id, &test_reject_reason); - ct_test(pTest, len == -1); - - /* test NULL APDU */ - len = reject_decode_apdu( - NULL, apdu_len, &test_invoke_id, &test_reject_reason); - ct_test(pTest, len == -1); - - /* force a zero length */ - len = reject_decode_apdu(&apdu[0], 0, &test_invoke_id, &test_reject_reason); - ct_test(pTest, len == 0); - - /* check them all... */ - for (invoke_id = 0; invoke_id < 255; invoke_id++) { - for (reject_reason = 0; reject_reason < 255; reject_reason++) { - len = reject_encode_apdu(&apdu[0], invoke_id, reject_reason); - apdu_len = len; - ct_test(pTest, len != 0); - len = reject_decode_apdu( - &apdu[0], apdu_len, &test_invoke_id, &test_reject_reason); - ct_test(pTest, len != -1); - ct_test(pTest, test_invoke_id == invoke_id); - ct_test(pTest, test_reject_reason == reject_reason); - } - } -} - -static void testRejectErrorCode(Test *pTest) -{ - int i; - BACNET_ERROR_CODE error_code; - BACNET_REJECT_REASON reject_reason; - BACNET_REJECT_REASON test_reject_reason; - - for (i = 0; i < MAX_BACNET_REJECT_REASON; i++) { - reject_reason = (BACNET_REJECT_REASON)i; - error_code = reject_convert_to_error_code(reject_reason); - test_reject_reason = reject_convert_error_code(error_code); - if (test_reject_reason != reject_reason) { - printf("Reject: result=%u reject-code=%u\n", test_reject_reason, - reject_reason); - } - ct_test(pTest, test_reject_reason == reject_reason); - } -} - -void testReject(Test *pTest) -{ - testRejectEncodeDecode(pTest); - testRejectErrorCode(pTest); -} - -#ifdef TEST_REJECT -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet Reject", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testReject); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_REJECT */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/reject.h b/src/bacnet/reject.h index 119e5a1c..964db721 100644 --- a/src/bacnet/reject.h +++ b/src/bacnet/reject.h @@ -53,12 +53,6 @@ extern "C" { uint8_t * invoke_id, uint8_t * reject_reason); -#ifdef BAC_TEST - BACNET_STACK_EXPORT - void testReject( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/rp.c b/src/bacnet/rp.c index 043f56d7..ebef3401 100644 --- a/src/bacnet/rp.c +++ b/src/bacnet/rp.c @@ -341,159 +341,3 @@ int rp_ack_decode_service_request(uint8_t *apdu, return len; } #endif - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -int rp_decode_apdu(uint8_t *apdu, - unsigned apdu_len, - uint8_t *invoke_id, - BACNET_READ_PROPERTY_DATA *rpdata) -{ - int len = 0; - unsigned offset = 0; - - if (!apdu) - return -1; - /* optional checking - most likely was already done prior to this call */ - if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) - return -1; - /* apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); */ - *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ - if (apdu[3] != SERVICE_CONFIRMED_READ_PROPERTY) - return -1; - offset = 4; - - if (apdu_len > offset) { - len = - rp_decode_service_request(&apdu[offset], apdu_len - offset, rpdata); - } - - return len; -} - -int rp_ack_decode_apdu(uint8_t *apdu, - int apdu_len, /* total length of the apdu */ - uint8_t *invoke_id, - BACNET_READ_PROPERTY_DATA *rpdata) -{ - int len = 0; - int offset = 0; - - if (!apdu) - return -1; - /* optional checking - most likely was already done prior to this call */ - if (apdu[0] != PDU_TYPE_COMPLEX_ACK) - return -1; - *invoke_id = apdu[1]; - if (apdu[2] != SERVICE_CONFIRMED_READ_PROPERTY) - return -1; - offset = 3; - if (apdu_len > offset) { - len = rp_ack_decode_service_request( - &apdu[offset], apdu_len - offset, rpdata); - } - - return len; -} - -void testReadPropertyAck(Test *pTest) -{ - uint8_t apdu[480] = { 0 }; - uint8_t apdu2[480] = { 0 }; - int len = 0; - int apdu_len = 0; - uint8_t invoke_id = 1; - uint8_t test_invoke_id = 0; - BACNET_READ_PROPERTY_DATA rpdata; - BACNET_READ_PROPERTY_DATA test_data; - BACNET_OBJECT_TYPE object_type = OBJECT_DEVICE; - uint32_t object_instance = 0; - BACNET_OBJECT_TYPE object = 0; - - rpdata.object_type = OBJECT_DEVICE; - rpdata.object_instance = 1; - rpdata.object_property = PROP_OBJECT_IDENTIFIER; - rpdata.array_index = BACNET_ARRAY_ALL; - - rpdata.application_data_len = encode_bacnet_object_id( - &apdu2[0], rpdata.object_type, rpdata.object_instance); - rpdata.application_data = &apdu2[0]; - - len = rp_ack_encode_apdu(&apdu[0], invoke_id, &rpdata); - ct_test(pTest, len != 0); - ct_test(pTest, len != -1); - apdu_len = len; - len = rp_ack_decode_apdu(&apdu[0], apdu_len, /* total length of the apdu */ - &test_invoke_id, &test_data); - ct_test(pTest, len != -1); - ct_test(pTest, test_invoke_id == invoke_id); - - ct_test(pTest, test_data.object_type == rpdata.object_type); - ct_test(pTest, test_data.object_instance == rpdata.object_instance); - ct_test(pTest, test_data.object_property == rpdata.object_property); - ct_test(pTest, test_data.array_index == rpdata.array_index); - ct_test( - pTest, test_data.application_data_len == rpdata.application_data_len); - - /* since object property == object_id, decode the application data using - the appropriate decode function */ - len = - decode_object_id(test_data.application_data, &object, &object_instance); - object_type = object; - ct_test(pTest, object_type == rpdata.object_type); - ct_test(pTest, object_instance == rpdata.object_instance); -} - -void testReadProperty(Test *pTest) -{ - uint8_t apdu[480] = { 0 }; - int len = 0; - int apdu_len = 0; - uint8_t invoke_id = 128; - uint8_t test_invoke_id = 0; - BACNET_READ_PROPERTY_DATA rpdata; - BACNET_READ_PROPERTY_DATA test_data; - - rpdata.object_type = OBJECT_DEVICE; - rpdata.object_instance = 1; - rpdata.object_property = PROP_OBJECT_IDENTIFIER; - rpdata.array_index = BACNET_ARRAY_ALL; - len = rp_encode_apdu(&apdu[0], invoke_id, &rpdata); - ct_test(pTest, len != 0); - apdu_len = len; - - len = rp_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &test_data); - ct_test(pTest, len != -1); - ct_test(pTest, test_data.object_type == rpdata.object_type); - ct_test(pTest, test_data.object_instance == rpdata.object_instance); - ct_test(pTest, test_data.object_property == rpdata.object_property); - ct_test(pTest, test_data.array_index == rpdata.array_index); - - return; -} - -#ifdef TEST_READ_PROPERTY -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet ReadProperty", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testReadProperty); - assert(rc); - rc = ct_addTestFunction(pTest, testReadPropertyAck); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_READ_PROPERTY */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/rp.h b/src/bacnet/rp.h index 2e947fd1..87e63fa7 100644 --- a/src/bacnet/rp.h +++ b/src/bacnet/rp.h @@ -106,30 +106,6 @@ extern "C" { int apdu_len, struct BACnet_Read_Access_Data *read_access_data); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - int rp_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - uint8_t * invoke_id, - BACNET_READ_PROPERTY_DATA * rpdata); - - BACNET_STACK_EXPORT - int rp_ack_decode_apdu( - uint8_t * apdu, - int apdu_len, /* total length of the apdu */ - uint8_t * invoke_id, - BACNET_READ_PROPERTY_DATA * rpdata); - - BACNET_STACK_EXPORT - void test_ReadProperty( - Test * pTest); - BACNET_STACK_EXPORT - void test_ReadPropertyAck( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/rpm.c b/src/bacnet/rpm.c index 8d0ba156..49e6817e 100644 --- a/src/bacnet/rpm.c +++ b/src/bacnet/rpm.c @@ -587,411 +587,4 @@ int rpm_ack_decode_object_property(uint8_t *apdu, return (int)len; } - #endif - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -int rpm_ack_decode_apdu(uint8_t *apdu, - int apdu_len, /* total length of the apdu */ - uint8_t *invoke_id, - uint8_t **service_request, - unsigned *service_request_len) -{ - int offset = 0; - - if (!apdu) - return -1; - /* optional checking - most likely was already done prior to this call */ - if (apdu[0] != PDU_TYPE_COMPLEX_ACK) - return -1; - *invoke_id = apdu[1]; - if (apdu[2] != SERVICE_CONFIRMED_READ_PROP_MULTIPLE) - return -1; - offset = 3; - if (apdu_len > offset) { - if (service_request) - *service_request = &apdu[offset]; - if (service_request_len) - *service_request_len = apdu_len - offset; - } - - return offset; -} - -int rpm_decode_apdu(uint8_t *apdu, - unsigned apdu_len, - uint8_t *invoke_id, - uint8_t **service_request, - unsigned *service_request_len) -{ - unsigned offset = 0; - - if (!apdu) - return -1; - /* optional checking - most likely was already done prior to this call */ - if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) - return -1; - /* apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); */ - *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ - if (apdu[3] != SERVICE_CONFIRMED_READ_PROP_MULTIPLE) - return -1; - offset = 4; - - if (apdu_len > offset) { - if (service_request) - *service_request = &apdu[offset]; - if (service_request_len) - *service_request_len = apdu_len - offset; - } - - return offset; -} - -void testReadPropertyMultiple(Test *pTest) -{ - uint8_t apdu[480] = { 0 }; - int len = 0; - int test_len = 0; - int apdu_len = 0; - uint8_t invoke_id = 12; - uint8_t test_invoke_id = 0; - uint8_t *service_request = NULL; - unsigned service_request_len = 0; - BACNET_RPM_DATA rpmdata; - - rpmdata.object_type = OBJECT_DEVICE; - rpmdata.object_instance = 0; - rpmdata.object_property = PROP_OBJECT_IDENTIFIER; - rpmdata.array_index = 0; - - /* build the RPM - try to make it easy for the Application Layer development - */ - /* IDEA: similar construction, but pass apdu, apdu_len pointer, size of apdu - to let the called function handle the out of space problem that these get - into by returning a boolean of success/failure. It almost needs to use - the keylist library or something similar. Also check case of storing a - backoff point (i.e. save enough room for object_end) */ - apdu_len = rpm_encode_apdu_init(&apdu[0], invoke_id); - /* each object has a beginning and an end */ - apdu_len += - rpm_encode_apdu_object_begin(&apdu[apdu_len], OBJECT_DEVICE, 123); - /* then stuff as many properties into it as APDU length will allow */ - apdu_len += rpm_encode_apdu_object_property( - &apdu[apdu_len], PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL); - apdu_len += rpm_encode_apdu_object_property( - &apdu[apdu_len], PROP_OBJECT_NAME, BACNET_ARRAY_ALL); - apdu_len += rpm_encode_apdu_object_end(&apdu[apdu_len]); - /* each object has a beginning and an end */ - apdu_len += - rpm_encode_apdu_object_begin(&apdu[apdu_len], OBJECT_ANALOG_INPUT, 33); - apdu_len += rpm_encode_apdu_object_property( - &apdu[apdu_len], PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL); - apdu_len += rpm_encode_apdu_object_property( - &apdu[apdu_len], PROP_ALL, BACNET_ARRAY_ALL); - apdu_len += rpm_encode_apdu_object_end(&apdu[apdu_len]); - - ct_test(pTest, apdu_len != 0); - - test_len = rpm_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, - &service_request, /* will point to the service request in the apdu */ - &service_request_len); - ct_test(pTest, test_len != -1); - ct_test(pTest, test_invoke_id == invoke_id); - ct_test(pTest, service_request != NULL); - ct_test(pTest, service_request_len > 0); - - test_len = - rpm_decode_object_id(service_request, service_request_len, &rpmdata); - ct_test(pTest, test_len > 0); - ct_test(pTest, rpmdata.object_type == OBJECT_DEVICE); - ct_test(pTest, rpmdata.object_instance == 123); - len = test_len; - /* decode the object property portion of the service request */ - test_len = rpm_decode_object_property( - &service_request[len], service_request_len - len, &rpmdata); - ct_test(pTest, test_len > 0); - ct_test(pTest, rpmdata.object_property == PROP_OBJECT_IDENTIFIER); - ct_test(pTest, rpmdata.array_index == BACNET_ARRAY_ALL); - len += test_len; - test_len = rpm_decode_object_property( - &service_request[len], service_request_len - len, &rpmdata); - ct_test(pTest, test_len > 0); - ct_test(pTest, rpmdata.object_property == PROP_OBJECT_NAME); - ct_test(pTest, rpmdata.array_index == BACNET_ARRAY_ALL); - len += test_len; - /* try again - we should fail */ - test_len = rpm_decode_object_property( - &service_request[len], service_request_len - len, &rpmdata); - ct_test(pTest, test_len < 0); - /* is it the end of this object? */ - test_len = - rpm_decode_object_end(&service_request[len], service_request_len - len); - ct_test(pTest, test_len == 1); - len += test_len; - /* try to decode an object id */ - test_len = rpm_decode_object_id( - &service_request[len], service_request_len - len, &rpmdata); - ct_test(pTest, test_len > 0); - ct_test(pTest, rpmdata.object_type == OBJECT_ANALOG_INPUT); - ct_test(pTest, rpmdata.object_instance == 33); - len += test_len; - /* decode the object property portion of the service request only */ - test_len = rpm_decode_object_property( - &service_request[len], service_request_len - len, &rpmdata); - ct_test(pTest, test_len > 0); - ct_test(pTest, rpmdata.object_property == PROP_OBJECT_IDENTIFIER); - ct_test(pTest, rpmdata.array_index == BACNET_ARRAY_ALL); - len += test_len; - test_len = rpm_decode_object_property( - &service_request[len], service_request_len - len, &rpmdata); - ct_test(pTest, test_len > 0); - ct_test(pTest, rpmdata.object_property == PROP_ALL); - ct_test(pTest, rpmdata.array_index == BACNET_ARRAY_ALL); - len += test_len; - test_len = rpm_decode_object_property( - &service_request[len], service_request_len - len, &rpmdata); - ct_test(pTest, test_len < 0); - /* got an error -1, is it the end of this object? */ - test_len = - rpm_decode_object_end(&service_request[len], service_request_len - len); - ct_test(pTest, test_len == 1); - len += test_len; - ct_test(pTest, len == service_request_len); -} - -void testReadPropertyMultipleAck(Test *pTest) -{ - uint8_t apdu[480] = { 0 }; - int len = 0; - int test_len = 0; - int apdu_len = 0; - uint8_t invoke_id = 12; - uint8_t test_invoke_id = 0; - uint8_t *service_request = NULL; - unsigned service_request_len = 0; - BACNET_OBJECT_TYPE object_type = OBJECT_DEVICE; - uint32_t object_instance = 0; - BACNET_PROPERTY_ID object_property = PROP_OBJECT_IDENTIFIER; - uint32_t array_index = 0; - BACNET_APPLICATION_DATA_VALUE application_data[4] = { { 0 } }; - BACNET_APPLICATION_DATA_VALUE test_application_data = { 0 }; - uint8_t application_data_buffer[MAX_APDU] = { 0 }; - int application_data_buffer_len = 0; - BACNET_ERROR_CLASS error_class; - BACNET_ERROR_CODE error_code; - BACNET_RPM_DATA rpmdata; - - /* build the RPM - try to make it easy for the - Application Layer development */ - /* IDEA: similar construction, but pass apdu, apdu_len pointer, - size of apdu to let the called function handle the out of - space problem that these get into by returning a boolean - of success/failure. - It almost needs to use the keylist library or something similar. - Also check case of storing a backoff point - (i.e. save enough room for object_end) */ - apdu_len = rpm_ack_encode_apdu_init(&apdu[0], invoke_id); - /* object beginning */ - rpmdata.object_type = OBJECT_DEVICE; - rpmdata.object_instance = 123; - apdu_len += rpm_ack_encode_apdu_object_begin(&apdu[apdu_len], &rpmdata); - /* reply property */ - apdu_len += rpm_ack_encode_apdu_object_property( - &apdu[apdu_len], PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL); - /* reply value */ - application_data[0].tag = BACNET_APPLICATION_TAG_OBJECT_ID; - application_data[0].type.Object_Id.type = OBJECT_DEVICE; - application_data[0].type.Object_Id.instance = 123; - application_data_buffer_len = bacapp_encode_application_data( - &application_data_buffer[0], &application_data[0]); - apdu_len += rpm_ack_encode_apdu_object_property_value(&apdu[apdu_len], - &application_data_buffer[0], application_data_buffer_len); - /* reply property */ - apdu_len += rpm_ack_encode_apdu_object_property( - &apdu[apdu_len], PROP_OBJECT_TYPE, BACNET_ARRAY_ALL); - /* reply value */ - application_data[1].tag = BACNET_APPLICATION_TAG_ENUMERATED; - application_data[1].type.Enumerated = OBJECT_DEVICE; - application_data_buffer_len = bacapp_encode_application_data( - &application_data_buffer[0], &application_data[1]); - apdu_len += rpm_ack_encode_apdu_object_property_value(&apdu[apdu_len], - &application_data_buffer[0], application_data_buffer_len); - /* object end */ - apdu_len += rpm_ack_encode_apdu_object_end(&apdu[apdu_len]); - - /* object beginning */ - rpmdata.object_type = OBJECT_ANALOG_INPUT; - rpmdata.object_instance = 33; - apdu_len += rpm_ack_encode_apdu_object_begin(&apdu[apdu_len], &rpmdata); - /* reply property */ - apdu_len += rpm_ack_encode_apdu_object_property( - &apdu[apdu_len], PROP_PRESENT_VALUE, BACNET_ARRAY_ALL); - /* reply value */ - application_data[2].tag = BACNET_APPLICATION_TAG_REAL; - application_data[2].type.Real = 0.0; - application_data_buffer_len = bacapp_encode_application_data( - &application_data_buffer[0], &application_data[2]); - apdu_len += rpm_ack_encode_apdu_object_property_value(&apdu[apdu_len], - &application_data_buffer[0], application_data_buffer_len); - /* reply property */ - apdu_len += rpm_ack_encode_apdu_object_property( - &apdu[apdu_len], PROP_DEADBAND, BACNET_ARRAY_ALL); - /* reply error */ - apdu_len += rpm_ack_encode_apdu_object_property_error( - &apdu[apdu_len], ERROR_CLASS_PROPERTY, ERROR_CODE_UNKNOWN_PROPERTY); - /* object end */ - apdu_len += rpm_ack_encode_apdu_object_end(&apdu[apdu_len]); - ct_test(pTest, apdu_len != 0); - - /****** decode the packet ******/ - test_len = rpm_ack_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, - &service_request, /* will point to the service request in the apdu */ - &service_request_len); - ct_test(pTest, test_len != -1); - ct_test(pTest, test_invoke_id == invoke_id); - ct_test(pTest, service_request != NULL); - ct_test(pTest, service_request_len > 0); - /* the first part should be the first object id */ - test_len = rpm_ack_decode_object_id( - service_request, service_request_len, &object_type, &object_instance); - ct_test(pTest, test_len != -1); - ct_test(pTest, object_type == OBJECT_DEVICE); - ct_test(pTest, object_instance == 123); - len = test_len; - /* extract the property */ - test_len = rpm_ack_decode_object_property(&service_request[len], - service_request_len - len, &object_property, &array_index); - ct_test(pTest, object_property == PROP_OBJECT_IDENTIFIER); - ct_test(pTest, array_index == BACNET_ARRAY_ALL); - len += test_len; - /* what is the result? An error or a value? */ - ct_test(pTest, decode_is_opening_tag_number(&service_request[len], 4)); - len++; - /* decode the object property portion of the service request */ - /* note: if this was an array, there could have been - more than one element to decode */ - test_len = bacapp_decode_application_data(&service_request[len], - service_request_len - len, &test_application_data); - ct_test(pTest, test_len > 0); - ct_test( - pTest, bacapp_same_value(&application_data[0], &test_application_data)); - len += test_len; - ct_test(pTest, decode_is_closing_tag_number(&service_request[len], 4)); - len++; - /* see if there is another property */ - test_len = rpm_ack_decode_object_property(&service_request[len], - service_request_len - len, &object_property, &array_index); - ct_test(pTest, test_len != -1); - ct_test(pTest, object_property == PROP_OBJECT_TYPE); - ct_test(pTest, array_index == BACNET_ARRAY_ALL); - len += test_len; - /* what is the result value? */ - ct_test(pTest, decode_is_opening_tag_number(&service_request[len], 4)); - len++; - /* decode the object property portion of the service request */ - test_len = bacapp_decode_application_data(&service_request[len], - service_request_len - len, &test_application_data); - ct_test(pTest, test_len > 0); - ct_test( - pTest, bacapp_same_value(&application_data[1], &test_application_data)); - len += test_len; - ct_test(pTest, decode_is_closing_tag_number(&service_request[len], 4)); - len++; - /* see if there is another property */ - /* this time we should fail */ - test_len = rpm_ack_decode_object_property(&service_request[len], - service_request_len - len, &object_property, &array_index); - ct_test(pTest, test_len == -1); - /* see if it is the end of this object */ - test_len = rpm_ack_decode_object_end( - &service_request[len], service_request_len - len); - ct_test(pTest, test_len == 1); - len += test_len; - /* try to decode another object id */ - test_len = rpm_ack_decode_object_id(&service_request[len], - service_request_len - len, &object_type, &object_instance); - ct_test(pTest, test_len != -1); - ct_test(pTest, object_type == OBJECT_ANALOG_INPUT); - ct_test(pTest, object_instance == 33); - len += test_len; - /* decode the object property portion of the service request only */ - test_len = rpm_ack_decode_object_property(&service_request[len], - service_request_len - len, &object_property, &array_index); - ct_test(pTest, test_len != -1); - ct_test(pTest, object_property == PROP_PRESENT_VALUE); - ct_test(pTest, array_index == BACNET_ARRAY_ALL); - len += test_len; - /* what is the result value? */ - ct_test(pTest, decode_is_opening_tag_number(&service_request[len], 4)); - len++; - /* decode the object property portion of the service request */ - test_len = bacapp_decode_application_data(&service_request[len], - service_request_len - len, &test_application_data); - ct_test(pTest, test_len > 0); - ct_test( - pTest, bacapp_same_value(&application_data[2], &test_application_data)); - len += test_len; - ct_test(pTest, decode_is_closing_tag_number(&service_request[len], 4)); - len++; - /* see if there is another property */ - test_len = rpm_ack_decode_object_property(&service_request[len], - service_request_len - len, &object_property, &array_index); - ct_test(pTest, test_len != -1); - ct_test(pTest, object_property == PROP_DEADBAND); - ct_test(pTest, array_index == BACNET_ARRAY_ALL); - len += test_len; - /* what is the result value? */ - ct_test(pTest, decode_is_opening_tag_number(&service_request[len], 5)); - len++; - /* it was an error reply */ - test_len = bacerror_decode_error_class_and_code(&service_request[len], - service_request_len - len, &error_class, &error_code); - ct_test(pTest, test_len != 0); - ct_test(pTest, error_class == ERROR_CLASS_PROPERTY); - ct_test(pTest, error_code == ERROR_CODE_UNKNOWN_PROPERTY); - len += test_len; - ct_test(pTest, decode_is_closing_tag_number(&service_request[len], 5)); - len++; - /* is there another property? */ - test_len = rpm_ack_decode_object_property(&service_request[len], - service_request_len - len, &object_property, &array_index); - ct_test(pTest, test_len == -1); - /* got an error -1, is it the end of this object? */ - test_len = rpm_ack_decode_object_end( - &service_request[len], service_request_len - len); - ct_test(pTest, test_len == 1); - len += test_len; - /* check for another object */ - test_len = rpm_ack_decode_object_id(&service_request[len], - service_request_len - len, &object_type, &object_instance); - ct_test(pTest, test_len == 0); - ct_test(pTest, len == service_request_len); -} - -#ifdef TEST_READ_PROPERTY_MULTIPLE -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet ReadPropertyMultiple", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testReadPropertyMultiple); - assert(rc); - rc = ct_addTestFunction(pTest, testReadPropertyMultipleAck); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_READ_PROPERTY_MULTIPLE */ - -#endif /* BAC_TEST */ diff --git a/src/bacnet/rpm.h b/src/bacnet/rpm.h index 161cb07c..0dabf97c 100644 --- a/src/bacnet/rpm.h +++ b/src/bacnet/rpm.h @@ -184,31 +184,6 @@ extern "C" { unsigned apdu_len, BACNET_PROPERTY_ID * object_property, BACNET_ARRAY_INDEX * array_index); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - int rpm_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - uint8_t * invoke_id, - uint8_t ** service_request, - unsigned *service_request_len); - - BACNET_STACK_EXPORT - int rpm_ack_decode_apdu( - uint8_t * apdu, - int apdu_len, /* total length of the apdu */ - uint8_t * invoke_id, - uint8_t ** service_request, - unsigned *service_request_len); - - BACNET_STACK_EXPORT - void testReadPropertyMultiple( - Test * pTest); - BACNET_STACK_EXPORT - void testReadPropertyMultipleAck( - Test * pTest); -#endif #ifdef __cplusplus } diff --git a/src/bacnet/timestamp.c b/src/bacnet/timestamp.c index 549a4ee0..9b149200 100644 --- a/src/bacnet/timestamp.c +++ b/src/bacnet/timestamp.c @@ -346,146 +346,3 @@ bool bacapp_timestamp_init_ascii(BACNET_TIMESTAMP *timestamp, const char *ascii) return status; } - -#ifdef BAC_TEST - -#include -#include -#include "ctest.h" - -void testTimestampSequence(Test *pTest) -{ - BACNET_TIMESTAMP testTimestampIn; - BACNET_TIMESTAMP testTimestampOut; - uint8_t buffer[MAX_APDU]; - int inLen; - int outLen; - - testTimestampIn.tag = TIME_STAMP_SEQUENCE; - testTimestampIn.value.sequenceNum = 0x1234; - - memset(&testTimestampOut, 0, sizeof(testTimestampOut)); - - inLen = bacapp_encode_context_timestamp(buffer, 2, &testTimestampIn); - outLen = bacapp_decode_context_timestamp(buffer, 2, &testTimestampOut); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, testTimestampIn.tag == testTimestampOut.tag); - ct_test(pTest, - testTimestampIn.value.sequenceNum == - testTimestampOut.value.sequenceNum); -} - -void testTimestampTime(Test *pTest) -{ - BACNET_TIMESTAMP testTimestampIn; - BACNET_TIMESTAMP testTimestampOut; - uint8_t buffer[MAX_APDU]; - int inLen; - int outLen; - - testTimestampIn.tag = TIME_STAMP_TIME; - testTimestampIn.value.time.hour = 1; - testTimestampIn.value.time.min = 2; - testTimestampIn.value.time.sec = 3; - testTimestampIn.value.time.hundredths = 4; - - memset(&testTimestampOut, 0, sizeof(testTimestampOut)); - - inLen = bacapp_encode_context_timestamp(buffer, 2, &testTimestampIn); - outLen = bacapp_decode_context_timestamp(buffer, 2, &testTimestampOut); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, testTimestampIn.tag == testTimestampOut.tag); - ct_test(pTest, - testTimestampIn.value.time.hour == testTimestampOut.value.time.hour); - ct_test(pTest, - testTimestampIn.value.time.min == testTimestampOut.value.time.min); - ct_test(pTest, - testTimestampIn.value.time.sec == testTimestampOut.value.time.sec); - ct_test(pTest, - testTimestampIn.value.time.hundredths == - testTimestampOut.value.time.hundredths); -} - -void testTimestampTimeDate(Test *pTest) -{ - BACNET_TIMESTAMP testTimestampIn; - BACNET_TIMESTAMP testTimestampOut; - uint8_t buffer[MAX_APDU]; - int inLen; - int outLen; - - testTimestampIn.tag = TIME_STAMP_DATETIME; - testTimestampIn.value.dateTime.time.hour = 1; - testTimestampIn.value.dateTime.time.min = 2; - testTimestampIn.value.dateTime.time.sec = 3; - testTimestampIn.value.dateTime.time.hundredths = 4; - - testTimestampIn.value.dateTime.date.year = 1901; - testTimestampIn.value.dateTime.date.month = 1; - testTimestampIn.value.dateTime.date.wday = 2; - testTimestampIn.value.dateTime.date.day = 3; - - memset(&testTimestampOut, 0, sizeof(testTimestampOut)); - - inLen = bacapp_encode_context_timestamp(buffer, 2, &testTimestampIn); - outLen = bacapp_decode_context_timestamp(buffer, 2, &testTimestampOut); - - ct_test(pTest, inLen == outLen); - ct_test(pTest, testTimestampIn.tag == testTimestampOut.tag); - ct_test(pTest, - testTimestampIn.value.dateTime.time.hour == - testTimestampOut.value.dateTime.time.hour); - ct_test(pTest, - testTimestampIn.value.dateTime.time.min == - testTimestampOut.value.dateTime.time.min); - ct_test(pTest, - testTimestampIn.value.dateTime.time.sec == - testTimestampOut.value.dateTime.time.sec); - ct_test(pTest, - testTimestampIn.value.dateTime.time.hundredths == - testTimestampOut.value.dateTime.time.hundredths); - - ct_test(pTest, - testTimestampIn.value.dateTime.date.year == - testTimestampOut.value.dateTime.date.year); - ct_test(pTest, - testTimestampIn.value.dateTime.date.month == - testTimestampOut.value.dateTime.date.month); - ct_test(pTest, - testTimestampIn.value.dateTime.date.wday == - testTimestampOut.value.dateTime.date.wday); - ct_test(pTest, - testTimestampIn.value.dateTime.date.day == - testTimestampOut.value.dateTime.date.day); -} - -#ifdef TEST_TIME_STAMP - -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet Time Stamp", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testTimestampSequence); - assert(rc); - - rc = ct_addTestFunction(pTest, testTimestampTime); - assert(rc); - - rc = ct_addTestFunction(pTest, testTimestampTimeDate); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} - -#endif /* TEST_TIME_STAMP */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/timesync.c b/src/bacnet/timesync.c index f6b56d69..95c25f3c 100644 --- a/src/bacnet/timesync.c +++ b/src/bacnet/timesync.c @@ -351,213 +351,3 @@ int timesync_decode_timesync_recipients( return apdu_len; } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -void testTimeSyncRecipientData(Test *pTest, - BACNET_RECIPIENT_LIST *recipient1, - BACNET_RECIPIENT_LIST *recipient2) -{ - unsigned i = 0; - - if (recipient1 && recipient2) { - ct_test(pTest, recipient1->tag == recipient2->tag); - if (recipient1->tag == 0) { - ct_test(pTest, - recipient1->type.device.type == recipient2->type.device.type); - ct_test(pTest, - recipient1->type.device.instance == - recipient2->type.device.instance); - } else if (recipient1->tag == 1) { - ct_test(pTest, - recipient1->type.address.net == recipient2->type.address.net); - if (recipient1->type.address.net == BACNET_BROADCAST_NETWORK) { - ct_test(pTest, - recipient1->type.address.mac_len == - recipient2->type.address.mac_len); - } else if (recipient1->type.address.net) { - ct_test(pTest, - recipient1->type.address.len == - recipient2->type.address.len); - for (i = 0; i < recipient1->type.address.len; i++) { - ct_test(pTest, - recipient1->type.address.adr[i] == - recipient2->type.address.adr[i]); - } - } else { - ct_test(pTest, - recipient1->type.address.mac_len == - recipient2->type.address.mac_len); - for (i = 0; i < recipient1->type.address.mac_len; i++) { - ct_test(pTest, - recipient1->type.address.mac[i] == - recipient2->type.address.mac[i]); - } - } - } else { - ct_test(pTest, recipient1->tag <= 1); - } - } -} - -void testTimeSyncRecipient(Test *pTest) -{ - uint8_t apdu[480] = { 0 }; - int len = 0; - BACNET_RECIPIENT_LIST recipient[4]; - BACNET_RECIPIENT_LIST test_recipient[4]; - - /* link the recipient list */ - recipient[0].next = &recipient[1]; - recipient[1].next = &recipient[2]; - recipient[2].next = &recipient[3]; - recipient[3].next = NULL; - /* link the test recipient list */ - test_recipient[0].next = &test_recipient[1]; - test_recipient[1].next = &test_recipient[2]; - test_recipient[2].next = &test_recipient[3]; - test_recipient[3].next = NULL; - /* load the test data - device */ - recipient[0].tag = 0; - recipient[0].type.device.type = OBJECT_DEVICE; - recipient[0].type.device.instance = 1234; - /* load the test data - address */ - /* network = broadcast */ - recipient[1].tag = 1; - recipient[1].type.address.net = BACNET_BROADCAST_NETWORK; - recipient[2].type.address.mac_len = 0; - /* network = non-zero */ - recipient[1].tag = 1; - recipient[2].type.address.net = 4201; - recipient[2].type.address.adr[0] = 127; - recipient[2].type.address.len = 1; - /* network = zero */ - recipient[2].type.address.net = 0; - recipient[2].type.address.mac[0] = 10; - recipient[2].type.address.mac[1] = 1; - recipient[2].type.address.mac[2] = 0; - recipient[2].type.address.mac[3] = 86; - recipient[2].type.address.mac[4] = 0xBA; - recipient[2].type.address.mac[5] = 0xC1; - recipient[2].type.address.mac_len = 6; - /* perform positive test */ - len = timesync_encode_timesync_recipients( - &apdu[0], sizeof(apdu), &recipient[0]); - ct_test(pTest, len != BACNET_STATUS_ABORT); - ct_test(pTest, len > 0); - len = timesync_decode_timesync_recipients( - &apdu[0], sizeof(apdu), &test_recipient[0]); - ct_test(pTest, len != BACNET_STATUS_ABORT); - ct_test(pTest, len > 0); - testTimeSyncRecipientData(pTest, &recipient[0], &test_recipient[0]); -} - -int timesync_decode_apdu_service(uint8_t *apdu, - BACNET_UNCONFIRMED_SERVICE service, - unsigned apdu_len, - BACNET_DATE *my_date, - BACNET_TIME *my_time) -{ - int len = 0; - - if (!apdu) - return -1; - /* optional checking - most likely was already done prior to this call */ - if (apdu[0] != PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST) - return -1; - if (apdu[1] != service) - return -1; - /* optional limits - must be used as a pair */ - if (apdu_len > 2) { - len = timesync_decode_service_request( - &apdu[2], apdu_len - 2, my_date, my_time); - } - - return len; -} - -int timesync_utc_decode_apdu(uint8_t *apdu, - unsigned apdu_len, - BACNET_DATE *my_date, - BACNET_TIME *my_time) -{ - return timesync_decode_apdu_service(apdu, - SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION, apdu_len, my_date, - my_time); -} - -int timesync_decode_apdu(uint8_t *apdu, - unsigned apdu_len, - BACNET_DATE *my_date, - BACNET_TIME *my_time) -{ - return timesync_decode_apdu_service(apdu, - SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, apdu_len, my_date, my_time); -} - -void testTimeSyncData(Test *pTest, BACNET_DATE *my_date, BACNET_TIME *my_time) -{ - uint8_t apdu[480] = { 0 }; - int len = 0; - int apdu_len = 0; - BACNET_DATE test_date; - BACNET_TIME test_time; - - len = timesync_encode_apdu(&apdu[0], my_date, my_time); - ct_test(pTest, len != 0); - apdu_len = len; - len = timesync_decode_apdu(&apdu[0], apdu_len, &test_date, &test_time); - ct_test(pTest, len != -1); - ct_test(pTest, datetime_compare_time(my_time, &test_time) == 0); - ct_test(pTest, datetime_compare_date(my_date, &test_date) == 0); - - len = timesync_utc_encode_apdu(&apdu[0], my_date, my_time); - ct_test(pTest, len != 0); - apdu_len = len; - len = timesync_utc_decode_apdu(&apdu[0], apdu_len, &test_date, &test_time); - ct_test(pTest, len != -1); - ct_test(pTest, datetime_compare_time(my_time, &test_time) == 0); - ct_test(pTest, datetime_compare_date(my_date, &test_date) == 0); -} - -void testTimeSync(Test *pTest) -{ - BACNET_DATE bdate; - BACNET_TIME btime; - - bdate.year = 2006; /* AD */ - bdate.month = 4; /* 1=Jan */ - bdate.day = 11; /* 1..31 */ - bdate.wday = 1; /* 1=Monday */ - - btime.hour = 7; - btime.min = 0; - btime.sec = 3; - btime.hundredths = 1; - - testTimeSyncData(pTest, &bdate, &btime); -} - -#ifdef TEST_TIMESYNC -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet Time-Sync", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testTimeSync); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_WHOIS */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/timesync.h b/src/bacnet/timesync.h index a3761a29..6a8d36e9 100644 --- a/src/bacnet/timesync.h +++ b/src/bacnet/timesync.h @@ -98,13 +98,6 @@ extern "C" { unsigned apdu_len, BACNET_RECIPIENT_LIST * recipient); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void testTimeSync( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/whohas.c b/src/bacnet/whohas.c index be6f3c11..709e7b37 100644 --- a/src/bacnet/whohas.c +++ b/src/bacnet/whohas.c @@ -156,112 +156,3 @@ int whohas_decode_service_request( return len; } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -int whohas_decode_apdu( - uint8_t *apdu, unsigned apdu_len, BACNET_WHO_HAS_DATA *data) -{ - int len = 0; - - if (!apdu) - return -1; - /* optional checking - most likely was already done prior to this call */ - if (apdu[0] != PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST) - return -1; - if (apdu[1] != SERVICE_UNCONFIRMED_WHO_HAS) - return -1; - /* optional limits - must be used as a pair */ - if (apdu_len > 2) { - len = whohas_decode_service_request(&apdu[2], apdu_len - 2, data); - } - - return len; -} - -void testWhoHasData(Test *pTest, BACNET_WHO_HAS_DATA *data) -{ - uint8_t apdu[480] = { 0 }; - int len = 0; - int apdu_len = 0; - BACNET_WHO_HAS_DATA test_data; - - len = whohas_encode_apdu(&apdu[0], data); - ct_test(pTest, len != 0); - apdu_len = len; - - len = whohas_decode_apdu(&apdu[0], apdu_len, &test_data); - ct_test(pTest, len != -1); - ct_test(pTest, test_data.low_limit == data->low_limit); - ct_test(pTest, test_data.high_limit == data->high_limit); - ct_test(pTest, test_data.is_object_name == data->is_object_name); - /* Object ID */ - if (data->is_object_name == false) { - ct_test(pTest, - test_data.object.identifier.type == data->object.identifier.type); - ct_test(pTest, - test_data.object.identifier.instance == - data->object.identifier.instance); - } - /* Object Name */ - else { - ct_test(pTest, - characterstring_same(&test_data.object.name, &data->object.name)); - } -} - -void testWhoHas(Test *pTest) -{ - BACNET_WHO_HAS_DATA data; - - data.low_limit = -1; - data.high_limit = -1; - data.is_object_name = false; - data.object.identifier.type = OBJECT_ANALOG_INPUT; - data.object.identifier.instance = 1; - testWhoHasData(pTest, &data); - - for (data.low_limit = 0; data.low_limit <= BACNET_MAX_INSTANCE; - data.low_limit += (BACNET_MAX_INSTANCE / 4)) { - for (data.high_limit = 0; data.high_limit <= BACNET_MAX_INSTANCE; - data.high_limit += (BACNET_MAX_INSTANCE / 4)) { - data.is_object_name = false; - for (data.object.identifier.type = OBJECT_ANALOG_INPUT; - data.object.identifier.type < MAX_BACNET_OBJECT_TYPE; - data.object.identifier.type++) { - for (data.object.identifier.instance = 1; - data.object.identifier.instance <= BACNET_MAX_INSTANCE; - data.object.identifier.instance <<= 1) { - testWhoHasData(pTest, &data); - } - } - data.is_object_name = true; - characterstring_init_ansi(&data.object.name, "patricia"); - testWhoHasData(pTest, &data); - } - } -} - -#ifdef TEST_WHOHAS -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet Who-Has", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testWhoHas); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_WHOIS */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/whohas.h b/src/bacnet/whohas.h index 5b7012dc..da040af4 100644 --- a/src/bacnet/whohas.h +++ b/src/bacnet/whohas.h @@ -61,13 +61,6 @@ extern "C" { unsigned apdu_len, BACNET_WHO_HAS_DATA * data); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - void testWhoHas( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/whois.c b/src/bacnet/whois.c index 680064aa..afc97335 100644 --- a/src/bacnet/whois.c +++ b/src/bacnet/whois.c @@ -120,109 +120,3 @@ int whois_decode_service_request( return (int)len; } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -int whois_decode_apdu( - uint8_t *apdu, unsigned apdu_len, int32_t *pLow_limit, int32_t *pHigh_limit) -{ - int len = 0; - - if (!apdu) { - return BACNET_STATUS_ERROR; - } - /* optional limits - must be used as a pair */ - if (apdu_len >= 2) { - /* optional checking - most likely was already done prior to this call - */ - if (apdu[0] != PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST) { - return BACNET_STATUS_ERROR; - } - if (apdu[1] != SERVICE_UNCONFIRMED_WHO_IS) { - return BACNET_STATUS_ERROR; - } - len = whois_decode_service_request( - &apdu[2], apdu_len - 2, pLow_limit, pHigh_limit); - } - - return len; -} - -void testWhoIs(Test *pTest) -{ - uint8_t apdu[480] = { 0 }; - int len = 0; - int apdu_len = 0; - int32_t low_limit = -1; - int32_t high_limit = -1; - int32_t test_low_limit = 0; - int32_t test_high_limit = 0; - - /* normal who-is without limits */ - len = whois_encode_apdu(&apdu[0], low_limit, high_limit); - ct_test(pTest, len > 0); - apdu_len = len; - - len = whois_decode_apdu( - &apdu[0], apdu_len, &test_low_limit, &test_high_limit); - ct_test(pTest, len != BACNET_STATUS_ERROR); - ct_test(pTest, test_low_limit == low_limit); - ct_test(pTest, test_high_limit == high_limit); - - /* normal who-is with limits - complete range */ - for (low_limit = 0; low_limit <= BACNET_MAX_INSTANCE; - low_limit += (BACNET_MAX_INSTANCE / 4)) { - for (high_limit = 0; high_limit <= BACNET_MAX_INSTANCE; - high_limit += (BACNET_MAX_INSTANCE / 4)) { - len = whois_encode_apdu(&apdu[0], low_limit, high_limit); - apdu_len = len; - ct_test(pTest, len > 0); - len = whois_decode_apdu( - &apdu[0], apdu_len, &test_low_limit, &test_high_limit); - ct_test(pTest, len != BACNET_STATUS_ERROR); - ct_test(pTest, test_low_limit == low_limit); - ct_test(pTest, test_high_limit == high_limit); - } - } - /* abnormal case: - who-is with no limits, but with APDU containing 2 limits */ - low_limit = 0; - high_limit = 0; - len = whois_encode_apdu(&apdu[0], low_limit, high_limit); - ct_test(pTest, len > 0); - apdu_len = len; - low_limit = -1; - high_limit = -1; - len = whois_encode_apdu(&apdu[0], low_limit, high_limit); - ct_test(pTest, len > 0); - apdu_len = len; - len = whois_decode_apdu( - &apdu[0], apdu_len, &test_low_limit, &test_high_limit); - ct_test(pTest, len != BACNET_STATUS_ERROR); - ct_test(pTest, test_low_limit == low_limit); - ct_test(pTest, test_high_limit == high_limit); -} - -#ifdef TEST_WHOIS -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet Who-Is", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testWhoIs); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_WHOIS */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/whois.h b/src/bacnet/whois.h index cf1e6e40..d61314da 100644 --- a/src/bacnet/whois.h +++ b/src/bacnet/whois.h @@ -46,19 +46,6 @@ extern "C" { int32_t * pLow_limit, int32_t * pHigh_limit); -#ifdef BAC_TEST - BACNET_STACK_EXPORT - int whois_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - int32_t * pLow_limit, - int32_t * pHigh_limit); - - BACNET_STACK_EXPORT - void testWhoIs( - Test * pTest); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/wp.c b/src/bacnet/wp.c index b0fc0719..c8978198 100644 --- a/src/bacnet/wp.c +++ b/src/bacnet/wp.c @@ -322,207 +322,3 @@ bool write_property_empty_string_valid( return (valid); } - -#ifdef BAC_TEST -#include -#include -#include "ctest.h" - -int wp_decode_apdu(uint8_t *apdu, - unsigned apdu_len, - uint8_t *invoke_id, - BACNET_WRITE_PROPERTY_DATA *wpdata) -{ - int len = 0; - unsigned offset = 0; - - if (!apdu) - return -1; - /* optional checking - most likely was already done prior to this call */ - if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) - return -1; - /* apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); */ - *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ - if (apdu[3] != SERVICE_CONFIRMED_WRITE_PROPERTY) - return -1; - offset = 4; - - if (apdu_len > offset) { - len = - wp_decode_service_request(&apdu[offset], apdu_len - offset, wpdata); - } - - return len; -} - -void testWritePropertyTag(Test *pTest, BACNET_APPLICATION_DATA_VALUE *value) -{ - BACNET_WRITE_PROPERTY_DATA wpdata = { 0 }; - BACNET_WRITE_PROPERTY_DATA test_data = { 0 }; - BACNET_APPLICATION_DATA_VALUE test_value; - uint8_t apdu[480] = { 0 }; - int len = 0; - int apdu_len = 0; - uint8_t invoke_id = 128; - uint8_t test_invoke_id = 0; - - wpdata.application_data_len = - bacapp_encode_application_data(&wpdata.application_data[0], value); - len = wp_encode_apdu(&apdu[0], invoke_id, &wpdata); - ct_test(pTest, len != 0); - /* decode the data */ - apdu_len = len; - len = wp_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &test_data); - ct_test(pTest, len != -1); - ct_test(pTest, test_data.object_type == wpdata.object_type); - ct_test(pTest, test_data.object_instance == wpdata.object_instance); - ct_test(pTest, test_data.object_property == wpdata.object_property); - ct_test(pTest, test_data.array_index == wpdata.array_index); - /* decode the application value of the request */ - len = bacapp_decode_application_data(test_data.application_data, - test_data.application_data_len, &test_value); - ct_test(pTest, test_value.tag == value->tag); - ct_test(pTest, write_property_type_valid(&wpdata, value, test_value.tag)); - switch (test_value.tag) { - case BACNET_APPLICATION_TAG_NULL: - break; - case BACNET_APPLICATION_TAG_BOOLEAN: - ct_test(pTest, test_value.type.Boolean == value->type.Boolean); - break; - case BACNET_APPLICATION_TAG_UNSIGNED_INT: - ct_test(pTest, - test_value.type.Unsigned_Int == value->type.Unsigned_Int); - break; - case BACNET_APPLICATION_TAG_SIGNED_INT: - ct_test( - pTest, test_value.type.Signed_Int == value->type.Signed_Int); - break; - case BACNET_APPLICATION_TAG_REAL: - ct_test(pTest, test_value.type.Real == value->type.Real); - break; - case BACNET_APPLICATION_TAG_ENUMERATED: - ct_test( - pTest, test_value.type.Enumerated == value->type.Enumerated); - break; - case BACNET_APPLICATION_TAG_DATE: - ct_test(pTest, test_value.type.Date.year == value->type.Date.year); - ct_test( - pTest, test_value.type.Date.month == value->type.Date.month); - ct_test(pTest, test_value.type.Date.day == value->type.Date.day); - ct_test(pTest, test_value.type.Date.wday == value->type.Date.wday); - break; - case BACNET_APPLICATION_TAG_TIME: - ct_test(pTest, test_value.type.Time.hour == value->type.Time.hour); - ct_test(pTest, test_value.type.Time.min == value->type.Time.min); - ct_test(pTest, test_value.type.Time.sec == value->type.Time.sec); - ct_test(pTest, - test_value.type.Time.hundredths == value->type.Time.hundredths); - break; - case BACNET_APPLICATION_TAG_OBJECT_ID: - ct_test(pTest, - test_value.type.Object_Id.type == value->type.Object_Id.type); - ct_test(pTest, - test_value.type.Object_Id.instance == - value->type.Object_Id.instance); - break; - default: - break; - } -} - -void testWriteProperty(Test *pTest) -{ - BACNET_APPLICATION_DATA_VALUE value; - - value.tag = BACNET_APPLICATION_TAG_NULL; - testWritePropertyTag(pTest, &value); - - value.tag = BACNET_APPLICATION_TAG_BOOLEAN; - value.type.Boolean = true; - testWritePropertyTag(pTest, &value); - value.type.Boolean = false; - testWritePropertyTag(pTest, &value); - - value.tag = BACNET_APPLICATION_TAG_UNSIGNED_INT; - value.type.Unsigned_Int = 0; - testWritePropertyTag(pTest, &value); - value.type.Unsigned_Int = 0xFFFF; - testWritePropertyTag(pTest, &value); - value.type.Unsigned_Int = 0xFFFFFFFF; - testWritePropertyTag(pTest, &value); - - value.tag = BACNET_APPLICATION_TAG_SIGNED_INT; - value.type.Signed_Int = 0; - testWritePropertyTag(pTest, &value); - value.type.Signed_Int = -1; - testWritePropertyTag(pTest, &value); - value.type.Signed_Int = 32768; - testWritePropertyTag(pTest, &value); - value.type.Signed_Int = -32768; - testWritePropertyTag(pTest, &value); - - value.tag = BACNET_APPLICATION_TAG_REAL; - value.type.Real = 0.0; - testWritePropertyTag(pTest, &value); - value.type.Real = -1.0; - testWritePropertyTag(pTest, &value); - value.type.Real = 1.0; - testWritePropertyTag(pTest, &value); - value.type.Real = 3.14159; - testWritePropertyTag(pTest, &value); - value.type.Real = -3.14159; - testWritePropertyTag(pTest, &value); - - value.tag = BACNET_APPLICATION_TAG_ENUMERATED; - value.type.Enumerated = 0; - testWritePropertyTag(pTest, &value); - value.type.Enumerated = 0xFFFF; - testWritePropertyTag(pTest, &value); - value.type.Enumerated = 0xFFFFFFFF; - testWritePropertyTag(pTest, &value); - - value.tag = BACNET_APPLICATION_TAG_DATE; - value.type.Date.year = 2005; - value.type.Date.month = 5; - value.type.Date.day = 22; - value.type.Date.wday = 1; - testWritePropertyTag(pTest, &value); - - value.tag = BACNET_APPLICATION_TAG_TIME; - value.type.Time.hour = 23; - value.type.Time.min = 59; - value.type.Time.sec = 59; - value.type.Time.hundredths = 12; - testWritePropertyTag(pTest, &value); - - value.tag = BACNET_APPLICATION_TAG_OBJECT_ID; - value.type.Object_Id.type = OBJECT_ANALOG_INPUT; - value.type.Object_Id.instance = 0; - testWritePropertyTag(pTest, &value); - value.type.Object_Id.type = OBJECT_LIFE_SAFETY_ZONE; - value.type.Object_Id.instance = BACNET_MAX_INSTANCE; - testWritePropertyTag(pTest, &value); - - return; -} - -#ifdef TEST_WRITE_PROPERTY -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACnet WriteProperty", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testWriteProperty); - assert(rc); - - ct_setStream(pTest, stdout); - ct_run(pTest); - (void)ct_report(pTest); - ct_destroy(pTest); - - return 0; -} -#endif /* TEST_WRITE_PROPERTY */ -#endif /* BAC_TEST */ diff --git a/src/bacnet/wp.h b/src/bacnet/wp.h index bc7289eb..4a134637 100644 --- a/src/bacnet/wp.h +++ b/src/bacnet/wp.h @@ -96,24 +96,6 @@ extern "C" { BACNET_APPLICATION_DATA_VALUE * value, int len_max); -#ifdef BAC_TEST -#include "ctest.h" - BACNET_STACK_EXPORT - int wp_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - uint8_t * invoke_id, - BACNET_WRITE_PROPERTY_DATA * wp_data); - - BACNET_STACK_EXPORT - void testWriteProperty( - Test * pTest); - BACNET_STACK_EXPORT - void testWritePropertyTag( - Test * pTest, - BACNET_APPLICATION_DATA_VALUE * value); -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 00000000..4c21b2f5 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,141 @@ +# SPDX-License-Identifier: MIT + +cmake_minimum_required(VERSION 3.10 FATAL_ERROR) +# set the project name +project(Unit_Tests) + +# add definitions +add_definitions(-fprofile-arcs -ftest-coverage) + +# Set the compiler options +if (NOT MSVC) + add_compile_options(-Wall -g -O0 -W -fprofile-arcs -ftest-coverage) + # 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_link_options(-fprofile-arcs -ftest-coverage) +endif() + +# Create the lcov target. Run result tests with 'make lcov' +add_custom_target(lcov + COMMAND mkdir -p lcoverage + ) +add_custom_command(TARGET lcov + COMMAND echo "=================== LCOV ====================" + COMMAND echo "-- Passing lcov tool under code coverage" + COMMAND lcov --capture --directory ../ --output-file lcoverage/main_coverage.info + COMMAND echo "-- Generating HTML output files" + COMMAND genhtml lcoverage/main_coverage.info --output-directory lcoverage + ) + +# +# add tests +# + +list(APPEND testdirs + bacnet/abort + bacnet/alarm_ack + bacnet/arf + bacnet/awf + bacnet/bacapp + bacnet/bacdcode + bacnet/bacdevobjpropref + bacnet/bacerror + bacnet/bacint + bacnet/bacpropstates + bacnet/bacreal + bacnet/bacstr + bacnet/cov + bacnet/datetime + bacnet/dcc + bacnet/event + bacnet/getevent + bacnet/iam + bacnet/ihave + bacnet/indtext + bacnet/lighting + bacnet/lso + bacnet/memcopy + bacnet/npdu + bacnet/property + bacnet/ptransfer + bacnet/rd + bacnet/reject + bacnet/rp + bacnet/rpm + bacnet/timestamp + bacnet/timesync + bacnet/whohas + bacnet/whois + bacnet/wp + ) + +# bacnet/basic/* +list(APPEND testdirs + # basic/object/binding + bacnet/basic/binding/address + # basic/object + bacnet/basic/object/acc + bacnet/basic/object/access_credential + bacnet/basic/object/access_door + bacnet/basic/object/access_point + bacnet/basic/object/access_rights + bacnet/basic/object/access_user + bacnet/basic/object/access_zone + bacnet/basic/object/ai + bacnet/basic/object/ao + bacnet/basic/object/av + bacnet/basic/object/bi + bacnet/basic/object/bo + bacnet/basic/object/bv + bacnet/basic/object/command + bacnet/basic/object/credential_data_input + bacnet/basic/object/device + #bacnet/basic/object/lc #Tests skipped, redesign to use only API + bacnet/basic/object/lo + bacnet/basic/object/lsp + bacnet/basic/object/ms-input + bacnet/basic/object/mso + bacnet/basic/object/msv + bacnet/basic/object/netport + bacnet/basic/object/objects + bacnet/basic/object/osv + bacnet/basic/object/piv + bacnet/basic/object/schedule + # basic/sys + bacnet/basic/sys/days + bacnet/basic/sys/fifo + bacnet/basic/sys/filename + bacnet/basic/sys/keylist + bacnet/basic/sys/ringbuf + bacnet/basic/sys/sbuf + ) + +# bacnet/datalink/* +list(APPEND testdirs + bacnet/datalink/cobs + bacnet/datalink/crc + bacnet/datalink/bvlc + ) + +enable_testing() +foreach(testdir IN ITEMS ${testdirs}) + get_filename_component(basename ${testdir} NAME) + add_subdirectory(${testdir}) + add_test(build_${basename} + "${CMAKE_COMMAND}" + --build "${CMAKE_BINARY_DIR}" + --config "$" + --target test_${basename} + ) + add_test(test_${basename} ${testdir}/test_${basename}) + set_tests_properties(test_${basename} PROPERTIES FIXTURES_REQUIRED test_fixture) + set_tests_properties(build_${basename} PROPERTIES FIXTURES_SETUP test_fixture) +endforeach() + +message(STATUS "BACNET: using cmake:....................\"${CMAKE_VERSION}\"") +message(STATUS "BACNET: CMAKE_C_COMPILER_ID:............\"${CMAKE_C_COMPILER_ID}\"") +message(STATUS "BACNET: CMAKE_C_COMPILER_VERSION:.......\"${CMAKE_C_COMPILER_VERSION}\"") +message(STATUS "BACNET: CMAKE_CXX_COMPILER_ID:..........\"${CMAKE_CXX_COMPILER_ID}\"") +message(STATUS "BACNET: CMAKE_CXX_COMPILER_VERSION:.....\"${CMAKE_CXX_COMPILER_VERSION}\"") +message(STATUS "BACNET: CMAKE_INSTALL_PREFIX:...........\"${CMAKE_INSTALL_PREFIX}\"") diff --git a/test/Makefile b/test/Makefile index 374c2747..ae2eb19c 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,247 +1,31 @@ -# Unit tests for the BACnet Stack project +# Main Makefile for BACnet-stack applications, tests, and sample ports -LOGFILE = test.log +# Export the variables defined here to all subprocesses +# (see http://www.gnu.org/software/automake/manual/make/Special-Targets.html) +.EXPORT_ALL_VARIABLES: -all: abort address arf awf bvlc bvlc6 bacapp bacdcode bacerror bacint bacstr \ - cov crc datetime dcc event filename fifo getevent iam ihave \ - indtext keylist key lighting lso memcopy npdu proplist ptransfer \ - rd reject ringbuf rp rpm sbuf timesync vmac \ - bbmd bbmd6 objects \ - whohas whois wp +# all: demos router-ipv6 ${DEMO_LINUX} -clean: logfile - rm ${LOGFILE} +.PHONY: all +all: test -logfile: - touch ${LOGFILE} +BUILD_DIR=build +CTEST_OPTIONS := --quiet --output-on-failure --parallel 4 +CTEST_OPTIONS += --output-junit test-results.xml + +.PHONY: test +test: + [ -d $(BUILD_DIR) ] || mkdir -p $(BUILD_DIR) + [ -d $(BUILD_DIR) ] && cd $(BUILD_DIR) && cmake .. && cd .. + [ -d $(BUILD_DIR) ] && cd $(BUILD_DIR) && cmake --build . --clean-first && cd .. + [ -d $(BUILD_DIR) ] && cd $(BUILD_DIR) && ctest $(CTEST_OPTIONS) + [ -d $(BUILD_DIR) ] && $(MAKE) -C $(BUILD_DIR) lcov + +.PHONY: report report: - cat ${LOGFILE} - cat ${LOGFILE} | grep Failed: | \ - awk 'BEGIN { err = 0 } $$2 > 0 { print "Unit Tests Failed!"; err = 1} \ - END {exit err}' + [ -d $(BUILD_DIR) ] && cat $(BUILD_DIR)/Testing/Temporary/LastTest*.log -abort: logfile abort.mak - $(MAKE) -s -f abort.mak clean all - ( ./abort >> ${LOGFILE} ) - $(MAKE) -s -f abort.mak clean - -address: logfile address.mak - $(MAKE) -s -f address.mak clean all - ( ./address >> ${LOGFILE} ) - $(MAKE) -s -f address.mak clean - -arf: logfile arf.mak - $(MAKE) -s -f arf.mak clean all - ( ./arf >> ${LOGFILE} ) - $(MAKE) -s -f arf.mak clean - -awf: logfile awf.mak - $(MAKE) -s -f awf.mak clean all - ( ./awf >> ${LOGFILE} ) - $(MAKE) -s -f awf.mak clean - -bacapp: logfile bacapp.mak - $(MAKE) -s -f bacapp.mak clean all - ( ./bacapp >> ${LOGFILE} ) - $(MAKE) -s -f bacapp.mak clean - -bacdcode: logfile bacdcode.mak - $(MAKE) -s -f bacdcode.mak clean all - ( ./bacdcode >> ${LOGFILE} ) - $(MAKE) -s -f bacdcode.mak clean - -bacerror: logfile bacerror.mak - $(MAKE) -s -f bacerror.mak clean all - ( ./bacerror >> ${LOGFILE} ) - $(MAKE) -s -f bacerror.mak clean - -bacint: logfile bacint.mak - $(MAKE) -s -f bacint.mak clean all - ( ./bacint >> ${LOGFILE} ) - $(MAKE) -s -f bacint.mak clean - -bacreal: logfile bacnet/bacreal/Makefile - $(MAKE) -s -C bacnet/bacreal/ clean all - ( ./bacnet/bacreal/unittest >> ${LOGFILE} ) - $(MAKE) -s -C bacnet/bacreal/ clean - -bacstr: logfile bacstr.mak - $(MAKE) -s -f bacstr.mak clean all - ( ./bacstr >> ${LOGFILE} ) - $(MAKE) -s -f bacstr.mak clean - -bvlc: logfile bvlc.mak - $(MAKE) -s -f bvlc.mak clean all - ( ./bvlc >> ${LOGFILE} ) - $(MAKE) -s -f bvlc.mak clean - -bbmd: logfile bacnet/basic/bbmd/Makefile - $(MAKE) -s -C bacnet/basic/bbmd/ clean all - ( ./bacnet/basic/bbmd/unittest >> ${LOGFILE} ) - $(MAKE) -s -C bacnet/basic/bbmd/ clean - -bvlc6: logfile bvlc6.mak - $(MAKE) -s -f bvlc6.mak clean all - ( ./bvlc6 >> ${LOGFILE} ) - $(MAKE) -s -f bvlc6.mak clean - -bbmd6: logfile bacnet/basic/bbmd6/Makefile - $(MAKE) -s -C bacnet/basic/bbmd6/ clean all - ( ./bacnet/basic/bbmd6/unittest >> ${LOGFILE} ) - $(MAKE) -s -C bacnet/basic/bbmd6/ clean - -cov: logfile cov.mak - $(MAKE) -s -f cov.mak clean all - ( ./cov >> ${LOGFILE} ) - $(MAKE) -s -f cov.mak clean - -crc: logfile crc.mak - $(MAKE) -s -f crc.mak clean all - ( ./crc >> ${LOGFILE} ) - $(MAKE) -s -f crc.mak clean - -datetime: logfile datetime.mak - $(MAKE) -s -f datetime.mak clean all - ( ./datetime >> ${LOGFILE} ) - $(MAKE) -s -f datetime.mak clean - -dcc: logfile dcc.mak - $(MAKE) -s -f dcc.mak clean all - ( ./dcc >> ${LOGFILE} ) - $(MAKE) -s -f dcc.mak clean - -event: logfile event.mak - $(MAKE) -s -f event.mak clean all - ( ./event >> ${LOGFILE} ) - $(MAKE) -s -f event.mak clean - -filename: logfile filename.mak - $(MAKE) -s -f filename.mak clean all - ( ./filename >> ${LOGFILE} ) - $(MAKE) -s -f filename.mak clean - -fifo: logfile fifo.mak - $(MAKE) -s -f fifo.mak clean all - ( ./fifo >> ${LOGFILE} ) - $(MAKE) -s -f fifo.mak clean - -getevent: logfile getevent.mak - $(MAKE) -s -f getevent.mak clean all - ( ./getevent >> ${LOGFILE} ) - $(MAKE) -s -f getevent.mak clean - -iam: logfile iam.mak - $(MAKE) -s -f iam.mak clean all - ( ./iam >> ${LOGFILE} ) - $(MAKE) -s -f iam.mak clean - -ihave: logfile ihave.mak - $(MAKE) -s -f ihave.mak clean all - ( ./ihave >> ${LOGFILE} ) - $(MAKE) -s -f ihave.mak clean - -indtext: logfile indtext.mak - $(MAKE) -s -f indtext.mak clean all - ( ./indtext >> ${LOGFILE} ) - $(MAKE) -s -f indtext.mak clean - -keylist: logfile keylist.mak - $(MAKE) -s -f keylist.mak clean all - ( ./keylist >> ${LOGFILE} ) - $(MAKE) -s -f keylist.mak clean - -key: logfile key.mak - $(MAKE) -s -f key.mak clean all - ( ./key >> ${LOGFILE} ) - $(MAKE) -s -f key.mak clean - -lighting: logfile lighting.mak - $(MAKE) -s -f lighting.mak clean all - ( ./lighting >> ${LOGFILE} ) - $(MAKE) -s -f lighting.mak clean - -lso: logfile lso.mak - $(MAKE) -s -f lso.mak clean all - ( ./lso >> ${LOGFILE} ) - $(MAKE) -s -f lso.mak clean - -memcopy: logfile memcopy.mak - $(MAKE) -s -f memcopy.mak clean all - ( ./memcopy >> ${LOGFILE} ) - $(MAKE) -s -f memcopy.mak clean - -npdu: logfile npdu.mak - $(MAKE) -s -f npdu.mak clean all - ( ./npdu >> ${LOGFILE} ) - $(MAKE) -s -f npdu.mak clean - -objects: logfile bacnet/basic/object/objects/Makefile - $(MAKE) -s -C bacnet/basic/object/objects/ clean all - ( ./bacnet/basic/object/objects/unittest >> ${LOGFILE} ) - $(MAKE) -s -C bacnet/basic/object/objects/ clean - -proplist: logfile proplist.mak - $(MAKE) -s -f proplist.mak clean all - ( ./proplist >> ${LOGFILE} ) - $(MAKE) -s -f proplist.mak clean - -ptransfer: logfile ptransfer.mak - $(MAKE) -s -f ptransfer.mak clean all - ( ./ptransfer >> ${LOGFILE} ) - $(MAKE) -s -f ptransfer.mak clean - -rd: logfile rd.mak - $(MAKE) -s -f rd.mak clean all - ( ./rd >> ${LOGFILE} ) - $(MAKE) -s -f rd.mak clean - -reject: logfile reject.mak - $(MAKE) -s -f reject.mak clean all - ( ./reject >> ${LOGFILE} ) - $(MAKE) -s -f reject.mak clean - -ringbuf: logfile ringbuf.mak - $(MAKE) -s -f ringbuf.mak clean all - ( ./ringbuf >> ${LOGFILE} ) - $(MAKE) -s -f ringbuf.mak clean - -rp: logfile rp.mak - $(MAKE) -s -f rp.mak clean all - ( ./rp >> ${LOGFILE} ) - $(MAKE) -s -f rp.mak clean - -rpm: logfile rpm.mak - $(MAKE) -s -f rpm.mak clean all - ( ./rpm >> ${LOGFILE} ) - $(MAKE) -s -f rpm.mak clean - -sbuf: logfile sbuf.mak - $(MAKE) -s -f sbuf.mak clean all - ( ./sbuf >> ${LOGFILE} ) - $(MAKE) -s -f sbuf.mak clean - -timesync: logfile timesync.mak - $(MAKE) -s -f timesync.mak clean all - ( ./timesync >> ${LOGFILE} ) - $(MAKE) -s -f timesync.mak clean - -vmac: logfile vmac.mak - $(MAKE) -s -f vmac.mak clean all - ( ./vmac >> ${LOGFILE} ) - $(MAKE) -s -f vmac.mak clean - -whohas: logfile whohas.mak - $(MAKE) -s -f whohas.mak clean all - ( ./whohas >> ${LOGFILE} ) - $(MAKE) -s -f whohas.mak clean - -whois: logfile whois.mak - $(MAKE) -s -f whois.mak clean all - ( ./whois >> ${LOGFILE} ) - $(MAKE) -s -f whois.mak clean - -wp: logfile wp.mak - $(MAKE) -s -f wp.mak clean all - ( ./wp >> ${LOGFILE} ) - $(MAKE) -s -f wp.mak clean +.PHONY: clean +clean: + -rm -rf $(BUILD_DIR) diff --git a/test/abort.mak b/test/abort.mak deleted file mode 100644 index 765ec27c..00000000 --- a/test/abort.mak +++ /dev/null @@ -1,41 +0,0 @@ -#Makefile to build test case - -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_ABORT - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - $(SRC_DIR)/bacnet/abort.c \ - ctest.c - -TARGET_NAME = abort -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -OBJS = ${SRCS:.c=.o} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf ${TARGET} $(OBJS) - -include: .depend diff --git a/test/address.mak b/test/address.mak deleted file mode 100644 index eb861cbf..00000000 --- a/test/address.mak +++ /dev/null @@ -1,52 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_ADDRESS -DBACNET_ADDRESS_CACHE_FILE - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/basic/binding/address.c \ - $(SRC_DIR)/bacnet/bacaddr.c \ - $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - $(SRC_DIR)/bacnet/bacapp.c \ - $(SRC_DIR)/bacnet/bacdevobjpropref.c \ - $(SRC_DIR)/bacnet/datetime.c \ - $(SRC_DIR)/bacnet/lighting.c \ - $(SRC_DIR)/bacnet/bactext.c \ - $(SRC_DIR)/bacnet/indtext.c \ - $(SRC_DIR)/bacnet/basic/sys/days.c \ - ctest.c - -OBJS = ${SRCS:.c=.o} - -TARGET_NAME = address -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf ${TARGET} $(OBJS) - -test: - ./${TARGET} - -include: .depend diff --git a/test/arf.mak b/test/arf.mak deleted file mode 100644 index c5d22610..00000000 --- a/test/arf.mak +++ /dev/null @@ -1,41 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -I../demo/object -DEFINES = -DBACFILE=1 -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_ATOMIC_READ_FILE -DEFINES += -DBACNET_READ_FILE_RECORD_COUNT=2 -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - $(SRC_DIR)/bacnet/arf.c \ - ctest.c - -OBJS = ${SRCS:.c=.o} - -TARGET_NAME = arf -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf ${TARGET} $(OBJS) - -include: .depend diff --git a/test/awf.mak b/test/awf.mak deleted file mode 100644 index 635166d1..00000000 --- a/test/awf.mak +++ /dev/null @@ -1,41 +0,0 @@ -#Makefile to build test case -CC = gcc - -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -I../demo/object -DEFINES = -DBACFILE=1 -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_ATOMIC_WRITE_FILE -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - $(SRC_DIR)/bacnet/awf.c \ - ctest.c - -OBJS = ${SRCS:.c=.o} - -TARGET_NAME = awf -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf ${TARGET} $(OBJS) - -include: .depend diff --git a/test/bacapp.mak b/test/bacapp.mak deleted file mode 100644 index 7e85e608..00000000 --- a/test/bacapp.mak +++ /dev/null @@ -1,47 +0,0 @@ -#Makefile to build test case -CC = gcc - -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_BACNET_APPLICATION_DATA -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - $(SRC_DIR)/bacnet/bacapp.c \ - $(SRC_DIR)/bacnet/bacdevobjpropref.c \ - $(SRC_DIR)/bacnet/datetime.c \ - $(SRC_DIR)/bacnet/bactext.c \ - $(SRC_DIR)/bacnet/lighting.c \ - $(SRC_DIR)/bacnet/indtext.c \ - $(SRC_DIR)/bacnet/basic/sys/days.c \ - ctest.c - -OBJS = ${SRCS:.c=.o} - -TARGET_NAME = bacapp -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf ${TARGET} $(OBJS) - -include: .depend diff --git a/test/bacdcode.mak b/test/bacdcode.mak deleted file mode 100644 index 38268a9f..00000000 --- a/test/bacdcode.mak +++ /dev/null @@ -1,40 +0,0 @@ -#Makefile to build unit tests -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_DECODE -DMAX_APDU=50 - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -TARGET_NAME = bacdcode -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -SRCS = $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - ctest.c - -OBJS = ${SRCS:.c=.o} - -all: ${TARGET} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf ${OBJS} ${TARGET} - -include: .depend diff --git a/test/bacdevobjpropref.mak b/test/bacdevobjpropref.mak deleted file mode 100644 index 594e339f..00000000 --- a/test/bacdevobjpropref.mak +++ /dev/null @@ -1,47 +0,0 @@ -#Makefile to build test case -CC = gcc - -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_DEV_ID_PROP_REF -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - $(SRC_DIR)/bacnet/bacapp.c \ - $(SRC_DIR)/bacnet/bacdevobjpropref.c \ - $(SRC_DIR)/bacnet/datetime.c \ - $(SRC_DIR)/bacnet/bactext.c \ - $(SRC_DIR)/bacnet/lighting.c \ - $(SRC_DIR)/bacnet/indtext.c \ - $(SRC_DIR)/bacnet/basic/sys/days.c \ - ctest.c - -OBJS = ${SRCS:.c=.o} - -TARGET_NAME = bacdevobjpropref -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf ${TARGET} $(OBJS) - -include: .depend diff --git a/test/bacerror.mak b/test/bacerror.mak deleted file mode 100644 index e37aa702..00000000 --- a/test/bacerror.mak +++ /dev/null @@ -1,41 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_BACERROR - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - $(SRC_DIR)/bacnet/bacerror.c \ - ctest.c - -OBJS = ${SRCS:.c=.o} - -TARGET_NAME = bacerror -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf ${TARGET} $(OBJS) - -include: .depend diff --git a/test/bacint.mak b/test/bacint.mak deleted file mode 100644 index 2aa3251c..00000000 --- a/test/bacint.mak +++ /dev/null @@ -1,38 +0,0 @@ -#Makefile to build unit tests -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_BACINT - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -TARGET_NAME = bacint -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -SRCS = $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - ctest.c - -OBJS = ${SRCS:.c=.o} - -all: ${TARGET} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf ${OBJS} ${TARGET} - -include: .depend diff --git a/test/bacnet/basic/object/objects/CMakeLists.txt b/test/bacnet/basic/object/objects/CMakeLists.txt index 88ebb593..8a8cbb56 100644 --- a/test/bacnet/basic/object/objects/CMakeLists.txt +++ b/test/bacnet/basic/object/objects/CMakeLists.txt @@ -34,7 +34,6 @@ add_executable(${PROJECT_NAME} # File(s) under test ${SRC_DIR}/bacnet/basic/object/objects.c # Support files and stubs (pathname alphabetical) - ${SRC_DIR}/bacnet/basic/sys/key.c ${SRC_DIR}/bacnet/basic/sys/keylist.c # Test and test library files ./src/main.c diff --git a/test/bacnet/basic/sys/key/CMakeLists.txt b/test/bacnet/basic/sys/key/CMakeLists.txt deleted file mode 100644 index c180c5be..00000000 --- a/test/bacnet/basic/sys/key/CMakeLists.txt +++ /dev/null @@ -1,41 +0,0 @@ -# SPDX-License-Identifier: MIT - -cmake_minimum_required(VERSION 3.10 FATAL_ERROR) - -get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME) -project(test_${basename} - VERSION 1.0.0 - LANGUAGES C) - - -string(REGEX REPLACE - "/test/bacnet/[a-zA-Z_/-]*$" - "/src" - SRC_DIR - ${CMAKE_CURRENT_SOURCE_DIR}) -string(REGEX REPLACE - "/test/bacnet/[a-zA-Z_/-]*$" - "/test" - TST_DIR - ${CMAKE_CURRENT_SOURCE_DIR}) -set(ZTST_DIR "${TST_DIR}/ztest/src") - -add_compile_definitions( - BIG_ENDIAN=0 - CONFIG_ZTEST=1 - ) - -include_directories( - ${SRC_DIR} - ${TST_DIR}/ztest/include - ) - -add_executable(${PROJECT_NAME} - # File(s) under test - ${SRC_DIR}/bacnet/basic/sys/key.c - # Support files and stubs (pathname alphabetical) - # Test and test library files - ./src/main.c - ${ZTST_DIR}/ztest_mock.c - ${ZTST_DIR}/ztest.c - ) diff --git a/test/bacnet/basic/sys/key/src/main.c b/test/bacnet/basic/sys/key/src/main.c deleted file mode 100644 index 19faacf9..00000000 --- a/test/bacnet/basic/sys/key/src/main.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2020 Legrand North America, LLC. - * - * SPDX-License-Identifier: MIT - */ - -/* @file - * @brief test BACnet integer encode/decode APIs - */ - -#include -#include - -/** - * @addtogroup bacnet_tests - * @{ - */ - -/** - * @brief 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; - int 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; -} -/** - * @} - */ - - -void test_main(void) -{ - ztest_test_suite(key_tests, - ztest_unit_test(testKeySample) - ); - - ztest_run_test_suite(key_tests); -} diff --git a/test/bacstr.mak b/test/bacstr.mak deleted file mode 100644 index 547d194d..00000000 --- a/test/bacstr.mak +++ /dev/null @@ -1,37 +0,0 @@ -#Makefile to build unit tests -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_BACSTR - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -TARGET_NAME = bacstr -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -SRCS = $(SRC_DIR)/bacnet/bacstr.c \ - ctest.c - -OBJS = ${SRCS:.c=.o} - -all: ${TARGET} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${OBJS} ${TARGET} *.bak - -include: .depend diff --git a/test/bbmd6.mak b/test/bbmd6.mak deleted file mode 100644 index 7e025158..00000000 --- a/test/bbmd6.mak +++ /dev/null @@ -1,48 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../src -SRC_INC = ../include -DEMO_DIR = ../demo/handler -DEMO_INC = ../demo/object -INCLUDES = -I. -I$(SRC_INC) -I$(DEMO_INC) -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_BBMD6 - -CFLAGS = -Wall -Wmissing-prototypes $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - $(SRC_DIR)/bacnet/bvlc6.c \ - $(SRC_DIR)/bacnet/debug.c \ - $(SRC_DIR)/bacnet/basic/sys/keylist.c \ - $(SRC_DIR)/bacnet/basic/bbmd6/vmac.c \ - $(DEMO_DIR)/h_bbmd6.c \ - ctest.c - -TARGET_NAME = bbmd6 -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -OBJS = ${SRCS:.c=.o} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf ${TARGET} $(OBJS) - -include: .depend diff --git a/test/bvlc.mak b/test/bvlc.mak deleted file mode 100644 index daa66e7b..00000000 --- a/test/bvlc.mak +++ /dev/null @@ -1,44 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBACDL_BIP -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_BVLC - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - $(SRC_DIR)/bacnet/datalink/bvlc.c \ - ctest.c - -OBJS = ${SRCS:.c=.o} - -TARGET_NAME = bvlc -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) *.bak *.1 *.ini - -test: ${TARGET} - ./${TARGET} - -include: .depend diff --git a/test/bvlc6.mak b/test/bvlc6.mak deleted file mode 100644 index 62c950fa..00000000 --- a/test/bvlc6.mak +++ /dev/null @@ -1,44 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_BVLC6 - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - $(SRC_DIR)/bacnet/datalink/bvlc6.c \ - ctest.c - -TARGET_NAME = bvlc6 -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -OBJS = ${SRCS:.c=.o} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf ${TARGET} $(OBJS) - -test: ${TARGET} - ./${TARGET} - -include: .depend diff --git a/test/cov.mak b/test/cov.mak deleted file mode 100644 index cc035245..00000000 --- a/test/cov.mak +++ /dev/null @@ -1,49 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -I../demo/object -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_COV -DBACAPP_ALL - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - $(SRC_DIR)/bacnet/datetime.c \ - $(SRC_DIR)/bacnet/bacapp.c \ - $(SRC_DIR)/bacnet/bacdevobjpropref.c \ - $(SRC_DIR)/bacnet/lighting.c \ - $(SRC_DIR)/bacnet/indtext.c \ - $(SRC_DIR)/bacnet/memcopy.c \ - $(SRC_DIR)/bacnet/bactext.c \ - $(SRC_DIR)/bacnet/cov.c \ - $(SRC_DIR)/bacnet/basic/sys/days.c \ - ctest.c - -OBJS = ${SRCS:.c=.o} - -TARGET_NAME = cov -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) *.bak *.1 *.ini - -include: .depend diff --git a/test/crc.mak b/test/crc.mak deleted file mode 100644 index 07a84011..00000000 --- a/test/crc.mak +++ /dev/null @@ -1,38 +0,0 @@ -#Makefile to build CRC tests -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -I../demo/object -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_CRC - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/datalink/crc.c \ - ctest.c - -OBJS = ${SRCS:.c=.o} - -TARGET_NAME = crc -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) *.bak *.1 *.ini - -include: .depend - diff --git a/test/ctest.c b/test/ctest.c deleted file mode 100644 index 184a02b0..00000000 --- a/test/ctest.c +++ /dev/null @@ -1,191 +0,0 @@ -/* ctest.c: Implements the CTest Framework */ - -#include "ctest.h" -#include -#include -#include -#include - -/* Number of tests to hold incrementally */ -enum { CHUNK = 10 }; - -Test *ct_create( - const char *name, - void (*init) (Test *)) -{ - int backOutLevel = 0; - Test *pTest = malloc(sizeof(Test)); - if (pTest) { - pTest->nPass = pTest->nFail = pTest->nTests = 0; - pTest->pStream = stdout; - - /* Allocate array of fptrs: */ - assert(CHUNK); - pTest->pTestFuns = calloc(CHUNK, sizeof(TestFunc)); - if (pTest->pTestFuns) { - pTest->maxTests = CHUNK; - /* Allocate test name: */ - assert(name); - pTest->name = malloc(strlen(name) + 1); - if (pTest->name) - strcpy(pTest->name, name); - else - ++backOutLevel; - } else - ++backOutLevel; - } - - /* Back-out allocations if memory failed: */ - if (backOutLevel) { - switch (backOutLevel) { - case 2: - free(pTest->pTestFuns); - pTest->pTestFuns = NULL; - case 1: - free(pTest); - pTest = NULL; - } - } else if (init) { - assert(pTest); - init(pTest); - } - return pTest; -} - -void ct_destroy( - Test * pTest) -{ - assert(pTest); - assert(pTest->pTestFuns); - free(pTest->pTestFuns); - pTest->pTestFuns = NULL; - assert(pTest->name); - free(pTest->name); - pTest->name = NULL; - free(pTest); -} - -bool ct_addTestFunction( - Test * pTest, - TestFunc tfun) -{ - assert(pTest); - assert(pTest->pTestFuns); - if (pTest->nTests == pTest->maxTests) { - size_t newSize = pTest->nTests + CHUNK; - TestFunc *new_pTestFuns = realloc(pTest->pTestFuns, - newSize * sizeof(TestFunc)); - if (!new_pTestFuns) - return false; - pTest->pTestFuns = new_pTestFuns; - pTest->maxTests += CHUNK; - } - assert(pTest->nTests < pTest->maxTests); - pTest->pTestFuns[pTest->nTests++] = tfun; - return true; -} - -void ct_setStream( - Test * pTest, - FILE * pStream) -{ - pTest->pStream = pStream; -} - -FILE *ct_getStream( - Test * pTest) -{ - return pTest->pStream; -} - -long ct_report( - Test * pTest) -{ - assert(pTest); - if (pTest->pStream) { - fprintf(pTest->pStream, "Test \"%s\":\n\tPassed: %ld\n\tFailed: %ld\n", - pTest->name, pTest->nPass, pTest->nFail); - } - return pTest->nFail; -} - - -void ct_succeed( - Test * pTest) -{ - assert(pTest); - ++pTest->nPass; -} - -void ct_do_test( - Test * pTest, - const char *str, - bool cond, - const char *file, - long line) -{ - assert(pTest); - if (!cond) - ct_do_fail(pTest, str, file, line); - else - ct_succeed(pTest); -} - -void ct_do_fail( - Test * pTest, - const char *str, - const char *file, - long line) -{ - assert(pTest); - ++pTest->nFail; - if (pTest->pStream) { - fprintf(pTest->pStream, "%s failure: (%s), %s (line %ld)\n", - pTest->name, str, file, line); - } -} - -long ct_getNumPassed( - Test * pTest) -{ - assert(pTest); - return pTest->nPass; -} - -long ct_getNumFailed( - Test * pTest) -{ - assert(pTest); - return pTest->nFail; -} - -long ct_run( - Test * pTest) -{ - size_t testNum; - assert(pTest); - for (testNum = 0; testNum < pTest->nTests; ++testNum) - pTest->pTestFuns[testNum] (pTest); - return pTest->nFail; -} - -void ct_reset( - Test * pTest) -{ - assert(pTest); - pTest->nFail = pTest->nPass = 0; -} - -const char *ct_getName( - Test * pTest) -{ - assert(pTest); - return (pTest->name); -} - -long ct_getNumTests( - Test * pTest) -{ - assert(pTest); - return pTest->nTests; -} diff --git a/test/ctest.h b/test/ctest.h deleted file mode 100644 index ddb0d059..00000000 --- a/test/ctest.h +++ /dev/null @@ -1,84 +0,0 @@ -/* ctest.h - * - * Defines a test framework for C projects. - */ -#ifndef CTEST_H -#define CTEST_H - -#include -#include - -#define ct_test(test, cond) \ - ct_do_test(test, #cond, cond, __FILE__, __LINE__) -#define ct_fail(test, str) \ - ct_do_fail(test, str, __FILE__, __LINE__) - -typedef struct _Test Test; - -typedef void ( - *TestFunc) ( - Test *); - -struct _Test { - char *name; - FILE *pStream; - size_t nTests; - size_t maxTests; - TestFunc *pTestFuns; - long nPass; - long nFail; -}; - -#ifdef __cplusplus -extern "C" { -#endif - - Test *ct_create( - const char *name, - void (*init) (Test *)); - void ct_destroy( - Test * pTest); - - const char *ct_getName( - Test * pTest); - long ct_getNumPassed( - Test * pTest); - long ct_getNumFailed( - Test * pTest); - long ct_getNumTests( - Test * pTest); - FILE *ct_getStream( - Test * pTest); - void ct_setStream( - Test * pTest, - FILE * stream); - - bool ct_addTestFunction( - Test * pTest, - TestFunc tfun); - void ct_succeed( - Test * pTest); - long ct_run( - Test * pTest); - long ct_report( - Test * pTest); - void ct_reset( - Test * pTest); - -/* Not intended for end-users: */ - void ct_do_test( - Test * pTest, - const char *str, - bool cond, - const char *file, - long line); - void ct_do_fail( - Test * pTest, - const char *str, - const char *file, - long line); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/test/datetime.mak b/test/datetime.mak deleted file mode 100644 index 58d36d02..00000000 --- a/test/datetime.mak +++ /dev/null @@ -1,47 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_DATE_TIME - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g -Wmissing-prototypes - -SRCS = $(SRC_DIR)/bacnet/datetime.c \ - $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - $(SRC_DIR)/bacnet/bacapp.c \ - $(SRC_DIR)/bacnet/bacdevobjpropref.c \ - $(SRC_DIR)/bacnet/lighting.c \ - $(SRC_DIR)/bacnet/bactext.c \ - $(SRC_DIR)/bacnet/indtext.c \ - $(SRC_DIR)/bacnet/basic/sys/days.c \ - ctest.c - -OBJS = ${SRCS:.c=.o} - -TARGET_NAME = datetime -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) *.bak *.1 *.ini - -include: .depend diff --git a/test/dcc.mak b/test/dcc.mak deleted file mode 100644 index 2a0d4748..00000000 --- a/test/dcc.mak +++ /dev/null @@ -1,41 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_DEVICE_COMMUNICATION_CONTROL - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - $(SRC_DIR)/bacnet/dcc.c \ - ctest.c - -TARGET_NAME = dcc -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -OBJS = ${SRCS:.c=.o} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) *.bak *.1 *.ini - -include: .depend diff --git a/test/event.mak b/test/event.mak deleted file mode 100644 index f58dd383..00000000 --- a/test/event.mak +++ /dev/null @@ -1,53 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -I../demo/object -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DBACAPP_ALL -DTEST_EVENT - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - $(SRC_DIR)/bacnet/bacerror.c \ - $(SRC_DIR)/bacnet/bacapp.c \ - $(SRC_DIR)/bacnet/bactext.c \ - $(SRC_DIR)/bacnet/indtext.c \ - $(SRC_DIR)/bacnet/datetime.c \ - $(SRC_DIR)/bacnet/lighting.c \ - $(SRC_DIR)/bacnet/memcopy.c \ - $(SRC_DIR)/bacnet/timestamp.c \ - $(SRC_DIR)/bacnet/bacpropstates.c \ - $(SRC_DIR)/bacnet/bacdevobjpropref.c \ - $(SRC_DIR)/bacnet/event.c \ - $(SRC_DIR)/bacnet/authentication_factor.c \ - $(SRC_DIR)/bacnet/basic/sys/days.c \ - ctest.c - -TARGET_NAME = event -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -OBJS = ${SRCS:.c=.o} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) *.bak *.1 *.ini - -include: .depend diff --git a/test/fifo.mak b/test/fifo.mak deleted file mode 100644 index 0db09601..00000000 --- a/test/fifo.mak +++ /dev/null @@ -1,38 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_FIFO_BUFFER - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/basic/sys/fifo.c \ - ctest.c - -TARGET_NAME = fifo -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -OBJS = ${SRCS:.c=.o} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) *.bak *.1 *.ini - -include: .depend - diff --git a/test/filename.mak b/test/filename.mak deleted file mode 100644 index ce2c9e1f..00000000 --- a/test/filename.mak +++ /dev/null @@ -1,38 +0,0 @@ -#Makefile to build filename tests -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_FILENAME - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/basic/sys/filename.c \ - ctest.c - -OBJS = ${SRCS:.c=.o} - -TARGET_NAME = filename -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) *.bak *.1 *.ini - -include: .depend - diff --git a/test/getevent.mak b/test/getevent.mak deleted file mode 100644 index 723c7ca7..00000000 --- a/test/getevent.mak +++ /dev/null @@ -1,49 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_GET_EVENT_INFORMATION - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - $(SRC_DIR)/bacnet/bacapp.c \ - $(SRC_DIR)/bacnet/bacdevobjpropref.c \ - $(SRC_DIR)/bacnet/datetime.c \ - $(SRC_DIR)/bacnet/lighting.c \ - $(SRC_DIR)/bacnet/bactext.c \ - $(SRC_DIR)/bacnet/indtext.c \ - $(SRC_DIR)/bacnet/timestamp.c \ - $(SRC_DIR)/bacnet/getevent.c \ - $(SRC_DIR)/bacnet/basic/sys/days.c \ - ctest.c - -TARGET_NAME = getevent -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -OBJS = ${SRCS:.c=.o} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) *.bak *.1 *.ini - -include: .depend diff --git a/test/iam.mak b/test/iam.mak deleted file mode 100755 index e268da2e..00000000 --- a/test/iam.mak +++ /dev/null @@ -1,41 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -I../demo/object -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_IAM - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - $(SRC_DIR)/bacnet/iam.c \ - ctest.c - -OBJS = ${SRCS:.c=.o} - -TARGET_NAME = iam -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) *.bak *.1 *.ini - -include: .depend diff --git a/test/ihave.mak b/test/ihave.mak deleted file mode 100644 index 88bb7529..00000000 --- a/test/ihave.mak +++ /dev/null @@ -1,41 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_I_HAVE - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - $(SRC_DIR)/bacnet/ihave.c \ - ctest.c - -OBJS = ${SRCS:.c=.o} - -TARGET_NAME = ihave -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) *.bak *.1 *.ini - -include: .depend diff --git a/test/indtext.mak b/test/indtext.mak deleted file mode 100644 index 97203315..00000000 --- a/test/indtext.mak +++ /dev/null @@ -1,37 +0,0 @@ -#Makefile to build unit tests -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_INDEX_TEXT - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/indtext.c \ - ctest.c - -OBJS = ${SRCS:.c=.o} - -TARGET_NAME = indtext -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${OBJS} ${TARGET} *.bak - -include: .depend diff --git a/test/key.mak b/test/key.mak deleted file mode 100644 index 0d444837..00000000 --- a/test/key.mak +++ /dev/null @@ -1,37 +0,0 @@ -#Makefile to build unit tests -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_KEY - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/basic/sys/key.c \ - ctest.c - -TARGET_NAME = key -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -OBJS = ${SRCS:.c=.o} - -all: ${TARGET} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) - -include: .depend diff --git a/test/keylist.mak b/test/keylist.mak deleted file mode 100644 index 620355f4..00000000 --- a/test/keylist.mak +++ /dev/null @@ -1,37 +0,0 @@ -#Makefile to build unit tests -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_KEYLIST - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/basic/sys/keylist.c \ - ctest.c - -TARGET_NAME = keylist -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -OBJS = ${SRCS:.c=.o} - -all: ${TARGET} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) - -include: .depend diff --git a/test/lighting.mak b/test/lighting.mak deleted file mode 100644 index cf3d95a0..00000000 --- a/test/lighting.mak +++ /dev/null @@ -1,41 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_LIGHTING_COMMAND - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - $(SRC_DIR)/bacnet/lighting.c \ - ctest.c - -TARGET_NAME = lighting -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -OBJS = ${SRCS:.c=.o} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) *.bak *.1 *.ini - -include: .depend diff --git a/test/lso.mak b/test/lso.mak deleted file mode 100644 index 6c306478..00000000 --- a/test/lso.mak +++ /dev/null @@ -1,50 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DBACAPP_ALL -DTEST_LSO - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - $(SRC_DIR)/bacnet/bacerror.c \ - $(SRC_DIR)/bacnet/bacapp.c \ - $(SRC_DIR)/bacnet/bacdevobjpropref.c \ - $(SRC_DIR)/bacnet/bactext.c \ - $(SRC_DIR)/bacnet/indtext.c \ - $(SRC_DIR)/bacnet/datetime.c \ - $(SRC_DIR)/bacnet/lighting.c \ - $(SRC_DIR)/bacnet/memcopy.c \ - $(SRC_DIR)/bacnet/lso.c \ - $(SRC_DIR)/bacnet/basic/sys/days.c \ - ctest.c - -TARGET_NAME = lso -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -OBJS = ${SRCS:.c=.o} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) *.bak *.1 *.ini - -include: .depend diff --git a/test/memcopy.mak b/test/memcopy.mak deleted file mode 100644 index a33358b8..00000000 --- a/test/memcopy.mak +++ /dev/null @@ -1,38 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_MEM_COPY - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/memcopy.c \ - ctest.c - -TARGET_NAME = memcopy -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -OBJS = ${SRCS:.c=.o} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) *.bak *.1 *.ini - -include: .depend - diff --git a/test/mstp.mak b/test/mstp.mak deleted file mode 100644 index a3361b53..00000000 --- a/test/mstp.mak +++ /dev/null @@ -1,41 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -I../ports/linux -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_MSTP - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/datalink/mstp.c \ - $(SRC_DIR)/bacnet/datalink/mstptext.c \ - $(SRC_DIR)/bacnet/indtext.c \ - $(SRC_DIR)/bacnet/datalink/crc.c \ - $(SRC_DIR)/bacnet/basic/sys/ringbuf.c \ - ctest.c - -TARGET_NAME = mstp -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -OBJS = ${SRCS:.c=.o} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) - -include: .depend diff --git a/test/npdu.mak b/test/npdu.mak deleted file mode 100644 index e66f1be9..00000000 --- a/test/npdu.mak +++ /dev/null @@ -1,43 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_NPDU - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - $(SRC_DIR)/bacnet/npdu.c \ - $(SRC_DIR)/bacnet/basic/service/h_apdu.c \ - $(SRC_DIR)/bacnet/dcc.c \ - ctest.c - -TARGET_NAME = npdu -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -OBJS = ${SRCS:.c=.o} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) *.bak *.1 *.ini - -include: .depend diff --git a/test/proplist.mak b/test/proplist.mak deleted file mode 100644 index a152d8b9..00000000 --- a/test/proplist.mak +++ /dev/null @@ -1,46 +0,0 @@ -#Makefile to build unit tests -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_PROPLIST -DEFINES += -DBACNET_PROPERTY_LISTS=1 - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/proplist.c \ - $(SRC_DIR)/bacnet/property.c \ - $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/datetime.c \ - $(SRC_DIR)/bacnet/lighting.c \ - $(SRC_DIR)/bacnet/basic/sys/days.c \ - ctest.c - -TARGET_NAME = proplist -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -OBJS = ${SRCS:.c=.o} - -all: ${TARGET} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) - -include: .depend diff --git a/test/ptransfer.mak b/test/ptransfer.mak deleted file mode 100644 index a982df83..00000000 --- a/test/ptransfer.mak +++ /dev/null @@ -1,48 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DPRINT_ENABLE=1 -DBAC_TEST -DTEST_PRIVATE_TRANSFER - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacapp.c \ - $(SRC_DIR)/bacnet/bacdevobjpropref.c \ - $(SRC_DIR)/bacnet/bactext.c \ - $(SRC_DIR)/bacnet/indtext.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - $(SRC_DIR)/bacnet/datetime.c \ - $(SRC_DIR)/bacnet/lighting.c \ - $(SRC_DIR)/bacnet/ptransfer.c \ - $(SRC_DIR)/bacnet/basic/sys/days.c \ - ctest.c - -TARGET_NAME = ptransfer -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -OBJS = ${SRCS:.c=.o} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) *.bak *.1 *.ini - -include: .depend diff --git a/test/rd.mak b/test/rd.mak deleted file mode 100644 index 9da523c8..00000000 --- a/test/rd.mak +++ /dev/null @@ -1,41 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_REINITIALIZE_DEVICE - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - $(SRC_DIR)/bacnet/rd.c \ - ctest.c - -TARGET_NAME = rd -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -OBJS = ${SRCS:.c=.o} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) *.bak *.1 *.ini - -include: .depend diff --git a/test/reject.mak b/test/reject.mak deleted file mode 100644 index e574377c..00000000 --- a/test/reject.mak +++ /dev/null @@ -1,41 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_REJECT - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - $(SRC_DIR)/bacnet/reject.c \ - ctest.c - -TARGET_NAME = reject -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -OBJS = ${SRCS:.c=.o} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) *.bak *.1 *.ini - -include: .depend diff --git a/test/ringbuf.mak b/test/ringbuf.mak deleted file mode 100644 index 4240c501..00000000 --- a/test/ringbuf.mak +++ /dev/null @@ -1,38 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_RING_BUFFER - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/basic/sys/ringbuf.c \ - ctest.c - -TARGET_NAME = ringbuf -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -OBJS = ${SRCS:.c=.o} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) *.bak *.1 *.ini - -include: .depend - diff --git a/test/rp.mak b/test/rp.mak deleted file mode 100644 index a2baf1d6..00000000 --- a/test/rp.mak +++ /dev/null @@ -1,41 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_READ_PROPERTY - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - $(SRC_DIR)/bacnet/rp.c \ - ctest.c - -TARGET_NAME = rp -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -OBJS = ${SRCS:.c=.o} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) *.bak *.1 *.ini - -include: .depend diff --git a/test/rpm.mak b/test/rpm.mak deleted file mode 100644 index 236cf54d..00000000 --- a/test/rpm.mak +++ /dev/null @@ -1,50 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DBACAPP_ALL -DTEST_READ_PROPERTY_MULTIPLE - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - $(SRC_DIR)/bacnet/bacerror.c \ - $(SRC_DIR)/bacnet/bacapp.c \ - $(SRC_DIR)/bacnet/bacdevobjpropref.c \ - $(SRC_DIR)/bacnet/bactext.c \ - $(SRC_DIR)/bacnet/indtext.c \ - $(SRC_DIR)/bacnet/datetime.c \ - $(SRC_DIR)/bacnet/lighting.c \ - $(SRC_DIR)/bacnet/memcopy.c \ - $(SRC_DIR)/bacnet/rpm.c \ - $(SRC_DIR)/bacnet/basic/sys/days.c \ - ctest.c - -TARGET_NAME = rpm -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -OBJS = ${SRCS:.c=.o} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) *.bak *.1 *.ini - -include: .depend diff --git a/test/sbuf.mak b/test/sbuf.mak deleted file mode 100644 index 5d2e80a4..00000000 --- a/test/sbuf.mak +++ /dev/null @@ -1,38 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_STATIC_BUFFER - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/basic/sys/sbuf.c \ - ctest.c - -TARGET_NAME = sbuf -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -OBJS = ${SRCS:.c=.o} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) *.bak *.1 *.ini - -include: .depend - diff --git a/test/timer.mak b/test/timer.mak deleted file mode 100644 index 81993537..00000000 --- a/test/timer.mak +++ /dev/null @@ -1,38 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../ports/bdk-atxx4-mstp -INCLUDES = -I$(SRC_DIR) -I${SRC_DIR} -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_TIMER - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/timer.c \ - ctest.c - -TARGET_NAME = timer -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -OBJS = ${SRCS:.c=.o} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) *.bak *.1 *.ini - -include: .depend - diff --git a/test/timesync.mak b/test/timesync.mak deleted file mode 100644 index d30fb606..00000000 --- a/test/timesync.mak +++ /dev/null @@ -1,64 +0,0 @@ -#Makefile to build test case - -# tools - only if you need them. -# Most platforms have this already defined -# CC = gcc -# AR = ar -# MAKE = make -# SIZE = size -# -# Assumes rm and cp are available - -SRC_DIR := ../src -INCLUDES := -I$(SRC_DIR) -I. -DEFINES := -DBIG_ENDIAN=0 -DBAC_TEST -DBACAPP_ALL -DTEST_TIMESYNC - -CFLAGS := $(INCLUDES) $(DEFINES) -g -CFLAGS += -Wall - -TARGET_NAME := timesync -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -SRCS := $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - $(SRC_DIR)/bacnet/bacerror.c \ - $(SRC_DIR)/bacnet/bacapp.c \ - $(SRC_DIR)/bacnet/bacdevobjpropref.c \ - $(SRC_DIR)/bacnet/bactext.c \ - $(SRC_DIR)/bacnet/indtext.c \ - $(SRC_DIR)/bacnet/datetime.c \ - $(SRC_DIR)/bacnet/lighting.c \ - $(SRC_DIR)/bacnet/timesync.c \ - $(SRC_DIR)/bacnet/basic/sys/days.c \ - ctest.c - -OBJS := ${SRCS:.c=.o} - -all: ${TARGET} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) *.bak *.1 *.ini - -run: - ./${TARGET} - -include: .depend - -.PHONY: all run clean diff --git a/test/vmac.mak b/test/vmac.mak deleted file mode 100644 index b7389466..00000000 --- a/test/vmac.mak +++ /dev/null @@ -1,38 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_VMAC - -CFLAGS = -Wall -Wmissing-prototypes $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/basic/sys/keylist.c \ - $(SRC_DIR)/bacnet/basic/bbmd6/vmac.c \ - ctest.c - -TARGET_NAME = vmac -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -OBJS = ${SRCS:.c=.o} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf ${TARGET} $(OBJS) - -include: .depend diff --git a/test/whohas.mak b/test/whohas.mak deleted file mode 100644 index 4f62563b..00000000 --- a/test/whohas.mak +++ /dev/null @@ -1,41 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_WHOHAS - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - $(SRC_DIR)/bacnet/whohas.c \ - ctest.c - -TARGET_NAME = whohas -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -OBJS = ${SRCS:.c=.o} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) *.bak *.1 *.ini - -include: .depend diff --git a/test/whois.mak b/test/whois.mak deleted file mode 100644 index 4f6ffe1c..00000000 --- a/test/whois.mak +++ /dev/null @@ -1,41 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DTEST_WHOIS - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - $(SRC_DIR)/bacnet/whois.c \ - ctest.c - -TARGET_NAME = whois -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -OBJS = ${SRCS:.c=.o} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) *.bak *.1 *.ini - -include: .depend diff --git a/test/wp.mak b/test/wp.mak deleted file mode 100644 index 5eecad59..00000000 --- a/test/wp.mak +++ /dev/null @@ -1,48 +0,0 @@ -#Makefile to build test case -CC = gcc -SRC_DIR = ../src -INCLUDES = -I$(SRC_DIR) -I. -DEFINES = -DBIG_ENDIAN=0 -DBAC_TEST -DBACAPP_ALL -DTEST_WRITE_PROPERTY - -CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g - -SRCS = $(SRC_DIR)/bacnet/bacdcode.c \ - $(SRC_DIR)/bacnet/bacint.c \ - $(SRC_DIR)/bacnet/bacstr.c \ - $(SRC_DIR)/bacnet/bacreal.c \ - $(SRC_DIR)/bacnet/datetime.c \ - $(SRC_DIR)/bacnet/lighting.c \ - $(SRC_DIR)/bacnet/bacapp.c \ - $(SRC_DIR)/bacnet/bacdevobjpropref.c \ - $(SRC_DIR)/bacnet/bactext.c \ - $(SRC_DIR)/bacnet/indtext.c \ - $(SRC_DIR)/bacnet/wp.c \ - $(SRC_DIR)/bacnet/basic/sys/days.c \ - ctest.c - -TARGET_NAME = wp -ifeq ($(OS),Windows_NT) -TARGET_EXT = .exe -else -TARGET_EXT = -endif -TARGET = $(TARGET_NAME)$(TARGET_EXT) - -all: ${TARGET} - -OBJS = ${SRCS:.c=.o} - -${TARGET}: ${OBJS} - ${CC} -o $@ ${OBJS} - -.c.o: - ${CC} -c ${CFLAGS} $*.c -o $@ - -depend: - rm -f .depend - ${CC} -MM ${CFLAGS} *.c >> .depend - -clean: - rm -rf core ${TARGET} $(OBJS) *.bak *.1 *.ini - -include: .depend diff --git a/test/ztest/include/tc_util.h b/test/ztest/include/tc_util.h index cec47d15..06a0ab06 100644 --- a/test/ztest/include/tc_util.h +++ b/test/ztest/include/tc_util.h @@ -92,7 +92,9 @@ static inline const char *TC_RESULT_TO_STR(int result) } } +#if 0 static uint32_t tc_start_time; +#endif static uint32_t tc_spend_time; static inline void get_start_time_cyc(void) diff --git a/unittest.bat b/unittest.bat index 5ac37400..d2b0e029 100644 --- a/unittest.bat +++ b/unittest.bat @@ -7,4 +7,3 @@ set AR=ar set MAKE=make rem make BACNET_PORT=win32 BUILD=release -f test.mak clean all make -s -C test clean all report -make -s -C demo/object clean all report diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index c4faaa5e..68ae6ff3 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -214,7 +214,6 @@ set(BACNETSTACK_SRCS ${BACNETSTACK_SRC}/bacnet/basic/sys/fifo.h ${BACNETSTACK_SRC}/bacnet/basic/sys/filename.c ${BACNETSTACK_SRC}/bacnet/basic/sys/filename.h - ${BACNETSTACK_SRC}/bacnet/basic/sys/key.c ${BACNETSTACK_SRC}/bacnet/basic/sys/key.h ${BACNETSTACK_SRC}/bacnet/basic/sys/keylist.c ${BACNETSTACK_SRC}/bacnet/basic/sys/keylist.h