Issue 87 execute tests with GitHub ci (#234)
* Enable lcov coverage in unit testing via cmake. * fix pipeline build error * add compile options for unit test to silence some warnings * remove all BAC_TEST unit tests in src/bacnet/ folder. They are now in test/bacnet/ folders using ztest. * removed key.c - only used for unit test. * produce XML test result output for parsing * produce junit XML test result output * change lint workflow to quality * update readme badge for quality results Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 <NAME>"
|
||||
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
|
||||
|
||||
+1
-108
@@ -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 "$<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
|
||||
#
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -16,7 +16,7 @@ and unit testing to produce robust C code and BACnet functionality.
|
||||
|
||||
[](https://github.com/bacnet-stack/bacnet-stack/actions) GitHub Workflow
|
||||
|
||||
[](https://github.com/bacnet-stack/bacnet-stack/actions) GitHub Workflow
|
||||
[](https://github.com/bacnet-stack/bacnet-stack/actions) GitHub Workflow
|
||||
|
||||
[](https://github.com/bacnet-stack/bacnet-stack/actions) GitHub Workflow
|
||||
|
||||
|
||||
@@ -197,53 +197,3 @@ bool Analog_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data,
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -244,53 +244,3 @@ bool Binary_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data,
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -216,53 +216,3 @@ bool Analog_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -260,53 +260,3 @@ bool Binary_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -1137,944 +1137,3 @@ int event_notify_decode_service_request(
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -200,152 +200,3 @@ int abort_decode_service_request(
|
||||
return len;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -173,101 +173,3 @@ int alarm_ack_decode_service_request(
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -377,193 +377,3 @@ int arf_ack_decode_apdu(uint8_t *apdu,
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -311,180 +311,3 @@ int awf_ack_decode_apdu(uint8_t *apdu,
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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 */
|
||||
|
||||
@@ -400,133 +400,3 @@ int bacapp_decode_context_device_obj_ref(
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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 <assert.h>
|
||||
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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -124,135 +124,3 @@ int bacerror_decode_service_request(uint8_t *apdu,
|
||||
return len;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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 <assert.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -292,131 +292,3 @@ int bacapp_encode_property_state(uint8_t *apdu, BACNET_PROPERTY_STATE *value)
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <string.h> /* 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 <assert.h>
|
||||
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 */
|
||||
|
||||
@@ -1223,216 +1223,3 @@ bool octetstring_value_same(
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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 <stdbool.h>
|
||||
|
||||
@@ -289,63 +289,3 @@ void VMAC_Init(void)
|
||||
PRINTF("VMAC List initialized.\n");
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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 <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -538,57 +538,3 @@ bool Binary_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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 <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -362,57 +362,3 @@ bool Credential_Data_Input_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -625,57 +625,3 @@ bool CharacterString_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -1890,104 +1890,3 @@ void Routing_Device_Init(uint32_t first_object_instance)
|
||||
}
|
||||
|
||||
#endif /* BAC_ROUTING */
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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 <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -1331,57 +1331,3 @@ void Lighting_Output_Init(void)
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -371,57 +371,3 @@ bool Life_Safety_Point_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -727,64 +727,3 @@ bool Multistate_Input_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -464,57 +464,3 @@ bool Multistate_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -576,57 +576,3 @@ bool Multistate_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -2427,95 +2427,3 @@ void Network_Port_Init(void)
|
||||
{
|
||||
/* do something interesting */
|
||||
}
|
||||
|
||||
#ifdef BACNET_UNIT_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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("<decode failed!>\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("<decode failed!>\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 */
|
||||
|
||||
@@ -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 <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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 <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -424,59 +424,3 @@ void Schedule_Recalculate_PV(
|
||||
desc->Present_Value = &desc->Schedule_Default;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -327,155 +327,3 @@ void FIFO_Init(FIFO_BUFFER *b, volatile uint8_t *buffer, unsigned buffer_len)
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#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
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -58,55 +58,3 @@ char *filename_remove_path(const char *filename_in)
|
||||
|
||||
return filename_out;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#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 */
|
||||
|
||||
@@ -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 <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#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
|
||||
@@ -497,312 +497,3 @@ void Keylist_Delete(OS_Keylist list)
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -454,370 +454,3 @@ bool Ringbuf_Init(RING_BUFFER *b,
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#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
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -129,84 +129,3 @@ bool sbuf_truncate(STATIC_BUFFER *b, /* static buffer structure */
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#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 */
|
||||
|
||||
@@ -414,59 +414,4 @@ bool tsm_invoke_id_failed(uint8_t invokeID)
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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
|
||||
+2
-19
@@ -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? */
|
||||
|
||||
@@ -983,374 +983,3 @@ bool cov_value_list_encode_character_string(
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -2620,952 +2620,3 @@ const char *bvlc_result_code_name(uint16_t result_code)
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -1572,798 +1572,3 @@ int bvlc6_decode_distribute_broadcast_to_network(uint8_t *pdu,
|
||||
|
||||
return bytes_consumed;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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 <assert.h>
|
||||
#include <string.h>
|
||||
#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
|
||||
|
||||
@@ -1251,487 +1251,3 @@ void MSTP_Init(volatile struct mstp_port_struct_t *mstp_port)
|
||||
mstp_port->TokenCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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
|
||||
|
||||
@@ -1177,564 +1177,3 @@ bool datetime_time_init_ascii(BACNET_TIME *btime, const char *ascii)
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -307,151 +307,3 @@ int dcc_decode_service_request(uint8_t *apdu,
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -1137,944 +1137,3 @@ int event_notify_decode_service_request(
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -317,182 +317,3 @@ int getevent_ack_decode_service_request(uint8_t *apdu,
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -163,78 +163,3 @@ int iam_decode_service_request(uint8_t *apdu,
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -161,71 +161,3 @@ int ihave_decode_apdu(
|
||||
return len;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user