Feature/zephyr ztest (#118)

* Leverage (older) embedded unit tests into external unit tests build upon copy of Zephyr's ztest library and CMake.

* Expand top-level CMake build to run external unit tests.

* Expand Zephyr module extension to run external unit tests via west or sanitycheck.

Co-authored-by: Gregory Shue <gregory.shue@legrand.us>
This commit is contained in:
Greg Shue
2020-09-16 05:33:34 -07:00
committed by GitHub
parent a7b2e94cb7
commit 19869dccdb
399 changed files with 21885 additions and 5 deletions
@@ -0,0 +1,45 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/binding/address.c
# Support files and stubs (pathname alphabetical)
${SRC_DIR}/bacnet/bacaddr.c
${SRC_DIR}/bacnet/bacapp.c
${SRC_DIR}/bacnet/bacdcode.c
${SRC_DIR}/bacnet/bacdevobjpropref.c
${SRC_DIR}/bacnet/bacint.c
${SRC_DIR}/bacnet/bacreal.c
${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/lighting.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
@@ -0,0 +1,202 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/bacaddr.h>
#include <bacnet/basic/binding/address.h>
/* we are likely compiling the demo command line tools if print enabled */
#if !defined(BACNET_ADDRESS_CACHE_FILE)
#if PRINT_ENABLED
#define BACNET_ADDRESS_CACHE_FILE
#endif
#endif
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
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;
}
}
#if 0 /* Not used */
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);
}
}
#endif
#ifdef BACNET_ADDRESS_CACHE_FILE
static void testAddressFile(void)
{
#if 0 /* Skip file as Address_Cache_Filename is an internal data structure */
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);
zassert_true(
address_get_by_device(device_id, &test_max_apdu, &test_address), NULL);
zassert_equal(test_max_apdu, max_apdu, NULL);
zassert_true(bacnet_address_same(&test_address, &src), NULL);
/* 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);
zassert_true(
address_get_by_device(device_id, &test_max_apdu, &test_address), NULL);
zassert_equal(test_max_apdu, max_apdu, NULL);
zassert_true(bacnet_address_same(&test_address, &src), NULL);
#else
ztest_test_skip();
#endif
}
#endif
static void testAddress(void)
{
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();
zassert_equal(count, (i + 1), NULL);
}
for (i = 0; i < MAX_ADDRESS_CACHE; i++) {
device_id = i * 255;
set_address(i, &src);
/* test the lookup by device id */
zassert_true(
address_get_by_device(device_id, &test_max_apdu, &test_address), NULL);
zassert_equal(test_max_apdu, max_apdu, NULL);
zassert_true(bacnet_address_same(&test_address, &src), NULL);
zassert_true(
address_get_by_index(
i, &test_device_id, &test_max_apdu, &test_address), NULL);
zassert_equal(test_device_id, device_id, NULL);
zassert_equal(test_max_apdu, max_apdu, NULL);
zassert_true(bacnet_address_same(&test_address, &src), NULL);
zassert_equal(address_count(), MAX_ADDRESS_CACHE, NULL);
/* test the lookup by MAC */
zassert_true(address_get_device_id(&src, &test_device_id), NULL);
zassert_equal(test_device_id, device_id, NULL);
}
for (i = 0; i < MAX_ADDRESS_CACHE; i++) {
device_id = i * 255;
address_remove_device(device_id);
zassert_false(
address_get_by_device(device_id, &test_max_apdu, &test_address), NULL);
count = address_count();
zassert_equal(count, (MAX_ADDRESS_CACHE - i - 1), NULL);
}
}
/**
* @}
*/
void test_main(void)
{
#ifdef BACNET_ADDRESS_CACHE_FILE
ztest_test_suite(address_tests,
ztest_unit_test(testAddressFile),
ztest_unit_test(testAddress)
);
ztest_run_test_suite(address_tests);
#else
ztest_test_suite(address_tests,
ztest_unit_test(testAddress)
);
ztest_run_test_suite(address_tests);
#endif
}
@@ -0,0 +1,44 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/object/acc.c
# Support files and stubs (pathname alphabetical)
${SRC_DIR}/bacnet/bacapp.c
${SRC_DIR}/bacnet/bacdcode.c
${SRC_DIR}/bacnet/bacdevobjpropref.c
${SRC_DIR}/bacnet/bacint.c
${SRC_DIR}/bacnet/bacreal.c
${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/lighting.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
+87
View File
@@ -0,0 +1,87 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/basic/object/acc.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
static void test_Accumulator(void)
{
#if 0 /*TODO: Refactor implementation to expose for testing */
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0;
int test_len = 0;
BACNET_READ_PROPERTY_DATA rpdata = {0};
BACNET_APPLICATION_DATA_VALUE value = {0};
const int *property = &Properties_Required[0];
BACNET_UNSIGNED_INTEGER unsigned_value = 1;
Accumulator_Init();
rpdata.application_data = &apdu[0];
rpdata.application_data_len = sizeof(apdu);
rpdata.object_type = OBJECT_ACCUMULATOR;
rpdata.object_instance = 1;
while ((*property) >= 0) {
rpdata.object_property = *property;
rpdata.array_index = BACNET_ARRAY_ALL;
len = Accumulator_Read_Property(&rpdata);
zassert_not_equal(len, 0, NULL);
if (IS_CONTEXT_SPECIFIC(rpdata.application_data[0])) {
test_len = bacapp_decode_context_data(rpdata.application_data,
len, &value, rpdata.object_property);
} else {
test_len = bacapp_decode_application_data(rpdata.application_data,
len, &value);
}
if (len != test_len) {
printf("property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property));
}
zassert_equal(len, test_len, NULL);
property++;
}
/* test 1-bit to 64-bit encode/decode of present-value */
rpdata.object_property = PROP_PRESENT_VALUE;
while (unsigned_value != BACNET_UNSIGNED_INTEGER_MAX) {
Accumulator_Present_Value_Set(0, unsigned_value);
len = Accumulator_Read_Property(&rpdata);
zassert_not_equal(len, 0, NULL);
test_len = bacapp_decode_application_data(rpdata.application_data,
len, &value);
zassert_equal(len, test_len, NULL);
unsigned_value |= (unsigned_value<<1);
}
return;
#else
ztest_test_skip();
#endif
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(acc_tests,
ztest_unit_test(test_Accumulator)
);
ztest_run_test_suite(acc_tests);
}
@@ -0,0 +1,48 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/object/access_credential.c
# Support files and stubs (pathname alphabetical)
${SRC_DIR}/bacnet/assigned_access_rights.c
${SRC_DIR}/bacnet/authentication_factor.c
${SRC_DIR}/bacnet/bacapp.c
${SRC_DIR}/bacnet/bacdcode.c
${SRC_DIR}/bacnet/bacdevobjpropref.c
${SRC_DIR}/bacnet/bacint.c
${SRC_DIR}/bacnet/bacreal.c
${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/credential_authentication_factor.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/lighting.c
./stubs.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/basic/object/access_credential.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
static void testAccessCredential(void)
{
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0;
uint32_t len_value = 0;
uint8_t tag_number = 0;
uint32_t decoded_instance = 0;
BACNET_OBJECT_TYPE decoded_type = 0;
BACNET_READ_PROPERTY_DATA rpdata;
Access_Credential_Init();
rpdata.application_data = &apdu[0];
rpdata.application_data_len = sizeof(apdu);
rpdata.object_type = OBJECT_ACCESS_CREDENTIAL;
rpdata.object_instance = 1;
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
rpdata.array_index = BACNET_ARRAY_ALL;
len = Access_Credential_Read_Property(&rpdata);
zassert_not_equal(len, 0, NULL);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_OBJECT_ID, NULL);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
zassert_equal(decoded_type, rpdata.object_type, NULL);
zassert_equal(decoded_instance, rpdata.object_instance, NULL);
return;
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(access_credential_tests,
ztest_unit_test(testAccessCredential)
);
ztest_run_test_suite(access_credential_tests);
}
@@ -0,0 +1,43 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
/* Binary Input Objects customize for your use */
#include <stdbool.h>
#include <stdint.h>
#include "bacnet/bacapp.h"
bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue,
uint8_t ucExpectedTag,
BACNET_ERROR_CLASS *pErrorClass,
BACNET_ERROR_CODE *pErrorCode)
{
pValue = pValue;
ucExpectedTag = ucExpectedTag;
pErrorClass = pErrorClass;
pErrorCode = pErrorCode;
return false;
}
@@ -0,0 +1,45 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/object/access_door.c
# Support files and stubs (pathname alphabetical)
${SRC_DIR}/bacnet/bacapp.c
${SRC_DIR}/bacnet/bacdcode.c
${SRC_DIR}/bacnet/bacdevobjpropref.c
${SRC_DIR}/bacnet/bacint.c
${SRC_DIR}/bacnet/bacreal.c
${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/lighting.c
./stubs.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
@@ -0,0 +1,76 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/basic/object/access_door.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
#if 0
bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue,
uint8_t ucExpectedTag,
BACNET_ERROR_CLASS *pErrorClass,
BACNET_ERROR_CODE *pErrorCode)
{
pValue = pValue;
ucExpectedTag = ucExpectedTag;
pErrorClass = pErrorClass;
pErrorCode = pErrorCode;
return false;
}
#endif
static void testAccessDoor(void)
{
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0;
uint32_t len_value = 0;
uint8_t tag_number = 0;
uint32_t decoded_instance = 0;
BACNET_OBJECT_TYPE decoded_type = 0;
BACNET_READ_PROPERTY_DATA rpdata;
Access_Door_Init();
rpdata.application_data = &apdu[0];
rpdata.application_data_len = sizeof(apdu);
rpdata.object_type = OBJECT_ACCESS_DOOR;
rpdata.object_instance = 1;
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
rpdata.array_index = BACNET_ARRAY_ALL;
len = Access_Door_Read_Property(&rpdata);
zassert_not_equal(len, 0, NULL);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_OBJECT_ID, NULL);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
zassert_equal(decoded_type, rpdata.object_type, NULL);
zassert_equal(decoded_instance, rpdata.object_instance, NULL);
return;
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(access_door_tests,
ztest_unit_test(testAccessDoor)
);
ztest_run_test_suite(access_door_tests);
}
@@ -0,0 +1,43 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
/* Binary Input Objects customize for your use */
#include <stdbool.h>
#include <stdint.h>
#include "bacnet/bacapp.h"
bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue,
uint8_t ucExpectedTag,
BACNET_ERROR_CLASS *pErrorClass,
BACNET_ERROR_CODE *pErrorCode)
{
pValue = pValue;
ucExpectedTag = ucExpectedTag;
pErrorClass = pErrorClass;
pErrorCode = pErrorCode;
return false;
}
@@ -0,0 +1,45 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/object/access_point.c
# Support files and stubs (pathname alphabetical)
${SRC_DIR}/bacnet/bacapp.c
${SRC_DIR}/bacnet/bacdcode.c
${SRC_DIR}/bacnet/bacdevobjpropref.c
${SRC_DIR}/bacnet/bacint.c
${SRC_DIR}/bacnet/bacreal.c
${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/timestamp.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/basic/object/access_point.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
static void testAccessPoint(void)
{
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0;
uint32_t len_value = 0;
uint8_t tag_number = 0;
uint32_t decoded_instance = 0;
BACNET_OBJECT_TYPE decoded_type = 0;
BACNET_READ_PROPERTY_DATA rpdata;
Access_Point_Init();
rpdata.application_data = &apdu[0];
rpdata.application_data_len = sizeof(apdu);
rpdata.object_type = OBJECT_ACCESS_POINT;
rpdata.object_instance = 1;
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
rpdata.array_index = BACNET_ARRAY_ALL;
len = Access_Point_Read_Property(&rpdata);
zassert_not_equal(len, 0, NULL);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_OBJECT_ID, NULL);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
zassert_equal(decoded_type, rpdata.object_type, NULL);
zassert_equal(decoded_instance, rpdata.object_instance, NULL);
return;
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(access_point_tests,
ztest_unit_test(testAccessPoint)
);
ztest_run_test_suite(access_point_tests);
}
@@ -0,0 +1,46 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/object/access_rights.c
# Support files and stubs (pathname alphabetical)
${SRC_DIR}/bacnet/access_rule.c
${SRC_DIR}/bacnet/bacapp.c
${SRC_DIR}/bacnet/bacdcode.c
${SRC_DIR}/bacnet/bacdevobjpropref.c
${SRC_DIR}/bacnet/bacint.c
${SRC_DIR}/bacnet/bacreal.c
${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/lighting.c
./stubs.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/basic/object/access_rights.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
static void testAccessRights(void)
{
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0;
uint32_t len_value = 0;
uint8_t tag_number = 0;
uint32_t decoded_instance = 0;
BACNET_OBJECT_TYPE decoded_type = 0;
BACNET_READ_PROPERTY_DATA rpdata;
Access_Rights_Init();
rpdata.application_data = &apdu[0];
rpdata.application_data_len = sizeof(apdu);
rpdata.object_type = OBJECT_ACCESS_RIGHTS;
rpdata.object_instance = 1;
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
rpdata.array_index = BACNET_ARRAY_ALL;
len = Access_Rights_Read_Property(&rpdata);
zassert_not_equal(len, 0, NULL);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_OBJECT_ID, NULL);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
zassert_equal(decoded_type, rpdata.object_type, NULL);
zassert_equal(decoded_instance, rpdata.object_instance, NULL);
return;
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(access_rights_tests,
ztest_unit_test(testAccessRights)
);
ztest_run_test_suite(access_rights_tests);
}
@@ -0,0 +1,43 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
/* Binary Input Objects customize for your use */
#include <stdbool.h>
#include <stdint.h>
#include "bacnet/bacapp.h"
bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue,
uint8_t ucExpectedTag,
BACNET_ERROR_CLASS *pErrorClass,
BACNET_ERROR_CODE *pErrorCode)
{
pValue = pValue;
ucExpectedTag = ucExpectedTag;
pErrorClass = pErrorClass;
pErrorCode = pErrorCode;
return false;
}
@@ -0,0 +1,45 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/object/access_user.c
# Support files and stubs (pathname alphabetical)
${SRC_DIR}/bacnet/bacapp.c
${SRC_DIR}/bacnet/bacdcode.c
${SRC_DIR}/bacnet/bacdevobjpropref.c
${SRC_DIR}/bacnet/bacint.c
${SRC_DIR}/bacnet/bacreal.c
${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/lighting.c
./stubs.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/basic/object/access_user.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
static void testAccessUser(void)
{
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0;
uint32_t len_value = 0;
uint8_t tag_number = 0;
uint32_t decoded_instance = 0;
BACNET_OBJECT_TYPE decoded_type = 0;
BACNET_READ_PROPERTY_DATA rpdata;
Access_User_Init();
rpdata.application_data = &apdu[0];
rpdata.application_data_len = sizeof(apdu);
rpdata.object_type = OBJECT_ACCESS_USER;
rpdata.object_instance = 1;
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
rpdata.array_index = BACNET_ARRAY_ALL;
len = Access_User_Read_Property(&rpdata);
zassert_not_equal(len, 0, NULL);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_OBJECT_ID, NULL);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
zassert_equal(decoded_type, rpdata.object_type, NULL);
zassert_equal(decoded_instance, rpdata.object_instance, NULL);
return;
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(access_user_tests,
ztest_unit_test(testAccessUser)
);
ztest_run_test_suite(access_user_tests);
}
@@ -0,0 +1,43 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
/* Binary Input Objects customize for your use */
#include <stdbool.h>
#include <stdint.h>
#include "bacnet/bacapp.h"
bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue,
uint8_t ucExpectedTag,
BACNET_ERROR_CLASS *pErrorClass,
BACNET_ERROR_CODE *pErrorCode)
{
pValue = pValue;
ucExpectedTag = ucExpectedTag;
pErrorClass = pErrorClass;
pErrorCode = pErrorCode;
return false;
}
@@ -0,0 +1,49 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/object/access_credential.c
# Support files and stubs (pathname alphabetical)
${SRC_DIR}/bacnet/authentication_factor.c
${SRC_DIR}/bacnet/assigned_access_rights.c
${SRC_DIR}/bacnet/bacapp.c
${SRC_DIR}/bacnet/bacdcode.c
${SRC_DIR}/bacnet/bacdevobjpropref.c
${SRC_DIR}/bacnet/bacint.c
${SRC_DIR}/bacnet/bacreal.c
${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/basic/object/access_zone.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/credential_authentication_factor.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/lighting.c
./stubs.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/basic/object/access_zone.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
static void testAccessZone(void)
{
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0;
uint32_t len_value = 0;
uint8_t tag_number = 0;
uint32_t decoded_instance = 0;
BACNET_OBJECT_TYPE decoded_type = 0;
BACNET_READ_PROPERTY_DATA rpdata;
Access_Zone_Init();
rpdata.application_data = &apdu[0];
rpdata.application_data_len = sizeof(apdu);
rpdata.object_type = OBJECT_ACCESS_ZONE;
rpdata.object_instance = 1;
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
rpdata.array_index = BACNET_ARRAY_ALL;
len = Access_Zone_Read_Property(&rpdata);
zassert_not_equal(len, 0, NULL);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_OBJECT_ID, NULL);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
zassert_equal(decoded_type, rpdata.object_type, NULL);
zassert_equal(decoded_instance, rpdata.object_instance, NULL);
return;
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(access_zone_tests,
ztest_unit_test(testAccessZone)
);
ztest_run_test_suite(access_zone_tests);
}
@@ -0,0 +1,43 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
/* Binary Input Objects customize for your use */
#include <stdbool.h>
#include <stdint.h>
#include "bacnet/bacapp.h"
bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue,
uint8_t ucExpectedTag,
BACNET_ERROR_CLASS *pErrorClass,
BACNET_ERROR_CODE *pErrorCode)
{
pValue = pValue;
ucExpectedTag = ucExpectedTag;
pErrorClass = pErrorClass;
pErrorCode = pErrorCode;
return false;
}
@@ -0,0 +1,45 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/object/ai.c
# Support files and stubs (pathname alphabetical)
${SRC_DIR}/bacnet/bacdcode.c
${SRC_DIR}/bacnet/bacint.c
${SRC_DIR}/bacnet/bacreal.c
${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/bacapp.c
${SRC_DIR}/bacnet/bacdevobjpropref.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/lighting.c
./stubs.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
+61
View File
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/basic/object/ai.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
static void testAnalogInput(void)
{
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0;
uint32_t len_value = 0;
uint8_t tag_number = 0;
uint32_t decoded_instance = 0;
BACNET_OBJECT_TYPE decoded_type = 0;
BACNET_READ_PROPERTY_DATA rpdata;
Analog_Input_Init();
rpdata.application_data = &apdu[0];
rpdata.application_data_len = sizeof(apdu);
rpdata.object_type = OBJECT_ANALOG_INPUT;
rpdata.object_instance = 1;
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
rpdata.array_index = BACNET_ARRAY_ALL;
len = Analog_Input_Read_Property(&rpdata);
zassert_not_equal(len, 0, NULL);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_OBJECT_ID, NULL);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
zassert_equal(decoded_type, rpdata.object_type, NULL);
zassert_equal(decoded_instance, rpdata.object_instance, NULL);
return;
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(ai_tests,
ztest_unit_test(testAnalogInput)
);
ztest_run_test_suite(ai_tests);
}
+43
View File
@@ -0,0 +1,43 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
/* Binary Input Objects customize for your use */
#include <stdbool.h>
#include <stdint.h>
#include "bacnet/bacapp.h"
bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue,
uint8_t ucExpectedTag,
BACNET_ERROR_CLASS *pErrorClass,
BACNET_ERROR_CODE *pErrorCode)
{
pValue = pValue;
ucExpectedTag = ucExpectedTag;
pErrorClass = pErrorClass;
pErrorCode = pErrorCode;
return false;
}
@@ -0,0 +1,45 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/object/ao.c
# Support files and stubs (pathname alphabetical)
${SRC_DIR}/bacnet/bacapp.c
${SRC_DIR}/bacnet/bacdcode.c
${SRC_DIR}/bacnet/bacdevobjpropref.c
${SRC_DIR}/bacnet/bacint.c
${SRC_DIR}/bacnet/bacreal.c
${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/lighting.c
./stubs.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
+61
View File
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/basic/object/ao.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
static void testAnalogOutput(void)
{
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0;
uint32_t len_value = 0;
uint8_t tag_number = 0;
uint32_t decoded_instance = 0;
BACNET_OBJECT_TYPE decoded_type = 0;
BACNET_READ_PROPERTY_DATA rpdata;
Analog_Output_Init();
rpdata.application_data = &apdu[0];
rpdata.application_data_len = sizeof(apdu);
rpdata.object_type = OBJECT_ANALOG_OUTPUT;
rpdata.object_instance = 1;
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
rpdata.array_index = BACNET_ARRAY_ALL;
len = Analog_Output_Read_Property(&rpdata);
zassert_not_equal(len, 0, NULL);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_OBJECT_ID, NULL);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
zassert_equal(decoded_type, rpdata.object_type, NULL);
zassert_equal(decoded_instance, rpdata.object_instance, NULL);
return;
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(ao_tests,
ztest_unit_test(testAnalogOutput)
);
ztest_run_test_suite(ao_tests);
}
+43
View File
@@ -0,0 +1,43 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
/* Binary Input Objects customize for your use */
#include <stdbool.h>
#include <stdint.h>
#include "bacnet/bacapp.h"
bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue,
uint8_t ucExpectedTag,
BACNET_ERROR_CLASS *pErrorClass,
BACNET_ERROR_CODE *pErrorCode)
{
pValue = pValue;
ucExpectedTag = ucExpectedTag;
pErrorClass = pErrorClass;
pErrorCode = pErrorCode;
return false;
}
@@ -0,0 +1,45 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/object/av.c
# Support files and stubs (pathname alphabetical)
${SRC_DIR}/bacnet/bacapp.c
${SRC_DIR}/bacnet/bacdcode.c
${SRC_DIR}/bacnet/bacdevobjpropref.c
${SRC_DIR}/bacnet/bacint.c
${SRC_DIR}/bacnet/bacreal.c
${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/lighting.c
./stubs.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
+61
View File
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/basic/object/av.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
static void testAnalog_Value(void)
{
BACNET_READ_PROPERTY_DATA rpdata;
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0;
uint32_t len_value = 0;
uint8_t tag_number = 0;
BACNET_OBJECT_TYPE decoded_type = 0;
uint32_t decoded_instance = 0;
Analog_Value_Init();
rpdata.application_data = &apdu[0];
rpdata.application_data_len = sizeof(apdu);
rpdata.object_type = OBJECT_ANALOG_VALUE;
rpdata.object_instance = 1;
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
rpdata.array_index = BACNET_ARRAY_ALL;
len = Analog_Value_Read_Property(&rpdata);
zassert_not_equal(len, 0, NULL);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_OBJECT_ID, NULL);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
zassert_equal(decoded_type, rpdata.object_type, NULL);
zassert_equal(decoded_instance, rpdata.object_instance, NULL);
return;
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(av_tests,
ztest_unit_test(testAnalog_Value)
);
ztest_run_test_suite(av_tests);
}
+43
View File
@@ -0,0 +1,43 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
/* Binary Input Objects customize for your use */
#include <stdbool.h>
#include <stdint.h>
#include "bacnet/bacapp.h"
bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue,
uint8_t ucExpectedTag,
BACNET_ERROR_CLASS *pErrorClass,
BACNET_ERROR_CODE *pErrorCode)
{
pValue = pValue;
ucExpectedTag = ucExpectedTag;
pErrorClass = pErrorClass;
pErrorCode = pErrorCode;
return false;
}
@@ -0,0 +1,45 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/object/bi.c
# Support files and stubs (pathname alphabetical)
${SRC_DIR}/bacnet/bacapp.c
${SRC_DIR}/bacnet/bacdcode.c
${SRC_DIR}/bacnet/bacdevobjpropref.c
${SRC_DIR}/bacnet/bacint.c
${SRC_DIR}/bacnet/bacreal.c
${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/lighting.c
./stubs.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
+61
View File
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/basic/object/bi.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test Binary Input handling
*/
static void testBinaryInput(void)
{
BACNET_READ_PROPERTY_DATA rpdata;
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0;
uint32_t len_value = 0;
uint8_t tag_number = 0;
BACNET_OBJECT_TYPE decoded_type = 0;
uint32_t decoded_instance = 0;
Binary_Input_Init();
rpdata.application_data = &apdu[0];
rpdata.application_data_len = sizeof(apdu);
rpdata.object_type = OBJECT_BINARY_INPUT;
rpdata.object_instance = 1;
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
rpdata.array_index = BACNET_ARRAY_ALL;
len = Binary_Input_Read_Property(&rpdata);
zassert_not_equal(len, 0, NULL);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_OBJECT_ID, NULL);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
zassert_equal(decoded_type, rpdata.object_type, NULL);
zassert_equal(decoded_instance, rpdata.object_instance, NULL);
return;
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(bi_tests,
ztest_unit_test(testBinaryInput)
);
ztest_run_test_suite(bi_tests);
}
+43
View File
@@ -0,0 +1,43 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
/* Binary Input Objects customize for your use */
#include <stdbool.h>
#include <stdint.h>
#include "bacnet/bacapp.h"
bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue,
uint8_t ucExpectedTag,
BACNET_ERROR_CLASS *pErrorClass,
BACNET_ERROR_CODE *pErrorCode)
{
pValue = pValue;
ucExpectedTag = ucExpectedTag;
pErrorClass = pErrorClass;
pErrorCode = pErrorCode;
return false;
}
@@ -0,0 +1,45 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/object/bo.c
# Support files and stubs (pathname alphabetical)
${SRC_DIR}/bacnet/bacapp.c
${SRC_DIR}/bacnet/bacdcode.c
${SRC_DIR}/bacnet/bacdevobjpropref.c
${SRC_DIR}/bacnet/bacint.c
${SRC_DIR}/bacnet/bacreal.c
${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/lighting.c
./stubs.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
+61
View File
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/basic/object/bo.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
static void testBinaryOutput(void)
{
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0;
uint32_t len_value = 0;
uint8_t tag_number = 0;
BACNET_OBJECT_TYPE decoded_type = 0;
uint32_t decoded_instance = 0;
BACNET_READ_PROPERTY_DATA rpdata;
Binary_Output_Init();
rpdata.application_data = &apdu[0];
rpdata.application_data_len = sizeof(apdu);
rpdata.object_type = OBJECT_BINARY_OUTPUT;
rpdata.object_instance = 1;
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
rpdata.array_index = BACNET_ARRAY_ALL;
len = Binary_Output_Read_Property(&rpdata);
zassert_not_equal(len, 0, NULL);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_OBJECT_ID, NULL);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
zassert_equal(decoded_type, rpdata.object_type, NULL);
zassert_equal(decoded_instance, rpdata.object_instance, NULL);
return;
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(bo_tests,
ztest_unit_test(testBinaryOutput)
);
ztest_run_test_suite(bo_tests);
}
+43
View File
@@ -0,0 +1,43 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
/* Binary Input Objects customize for your use */
#include <stdbool.h>
#include <stdint.h>
#include <bacnet/wp.h>
bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue,
uint8_t ucExpectedTag,
BACNET_ERROR_CLASS *pErrorClass,
BACNET_ERROR_CODE *pErrorCode)
{
pValue = pValue;
ucExpectedTag = ucExpectedTag;
pErrorClass = pErrorClass;
pErrorCode = pErrorCode;
return false;
}
@@ -0,0 +1,45 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/object/bv.c
# Support files and stubs (pathname alphabetical)
${SRC_DIR}/bacnet/bacapp.c
${SRC_DIR}/bacnet/bacdcode.c
${SRC_DIR}/bacnet/bacdevobjpropref.c
${SRC_DIR}/bacnet/bacint.c
${SRC_DIR}/bacnet/bacreal.c
${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/lighting.c
./stubs.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
+61
View File
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/basic/object/bv.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
static void testBinary_Value(void)
{
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0;
uint32_t len_value = 0;
uint8_t tag_number = 0;
BACNET_OBJECT_TYPE decoded_type = 0;
uint32_t decoded_instance = 0;
BACNET_READ_PROPERTY_DATA rpdata;
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);
zassert_not_equal(len, 0, NULL);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_OBJECT_ID, NULL);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
zassert_equal(decoded_type, rpdata.object_type, NULL);
zassert_equal(decoded_instance, rpdata.object_instance, NULL);
return;
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(bv_tests,
ztest_unit_test(testBinary_Value)
);
ztest_run_test_suite(bv_tests);
}
+43
View File
@@ -0,0 +1,43 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
/* Binary Input Objects customize for your use */
#include <stdbool.h>
#include <stdint.h>
#include <bacnet/wp.h>
bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue,
uint8_t ucExpectedTag,
BACNET_ERROR_CLASS *pErrorClass,
BACNET_ERROR_CODE *pErrorCode)
{
pValue = pValue;
ucExpectedTag = ucExpectedTag;
pErrorClass = pErrorClass;
pErrorCode = pErrorCode;
return false;
}
@@ -0,0 +1,45 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/object/command.c
# Support files and stubs (pathname alphabetical)
${SRC_DIR}/bacnet/bacapp.c
${SRC_DIR}/bacnet/bacdcode.c
${SRC_DIR}/bacnet/bacdevobjpropref.c
${SRC_DIR}/bacnet/bacint.c
${SRC_DIR}/bacnet/bacreal.c
${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/lighting.c
./stubs.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
@@ -0,0 +1,95 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/basic/object/command.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
static void testCommand(void)
{
#if 0 /*TODO: Test does not pass */
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0;
uint32_t len_value = 0;
uint8_t tag_number = 0;
uint32_t decoded_instance = 0;
BACNET_OBJECT_TYPE 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);
zassert_not_equal(len, 0, NULL);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_OBJECT_ID, NULL);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
zassert_equal(decoded_type, rpdata.object_type, NULL);
zassert_equal(decoded_instance, rpdata.object_instance, NULL);
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);
zassert_true(len > 0, NULL);
len = cl_decode_apdu(apdu, len, BACNET_APPLICATION_TAG_REAL, &clist_test);
zassert_true(len > 0, NULL);
zassert_equal(clist.Device_Id.type, clist_test.Device_Id.type, NULL);
zassert_equal(clist.Device_Id.instance, clist_test.Device_Id.instance, NULL);
zassert_equal(clist.Object_Id.type, clist_test.Object_Id.type, NULL);
zassert_equal(clist.Object_Id.instance, clist_test.Object_Id.instance, NULL);
zassert_equal(clist.Property_Identifier, clist_test.Property_Identifier, NULL);
zassert_equal(clist.Property_Array_Index, clist_test.Property_Array_Index, NULL);
zassert_equal(clist.Value.tag, clist_test.Value.tag, NULL);
zassert_equal(clist.Value.type.Real, clist_test.Value.type.Real, NULL);
zassert_equal(clist.Priority, clist_test.Priority, NULL);
zassert_equal(clist.Post_Delay, clist_test.Post_Delay, NULL);
zassert_equal(clist.Quit_On_Failure, clist_test.Quit_On_Failure, NULL);
zassert_equal(clist.Write_Successful, clist_test.Write_Successful, NULL);
return;
#else
ztest_test_skip();
#endif
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(command_tests,
ztest_unit_test(testCommand)
);
ztest_run_test_suite(command_tests);
}
+43
View File
@@ -0,0 +1,43 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
/* Binary Input Objects customize for your use */
#include <stdbool.h>
#include <stdint.h>
#include "bacnet/bacapp.h"
bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue,
uint8_t ucExpectedTag,
BACNET_ERROR_CLASS *pErrorClass,
BACNET_ERROR_CODE *pErrorCode)
{
pValue = pValue;
ucExpectedTag = ucExpectedTag;
pErrorClass = pErrorClass;
pErrorCode = pErrorCode;
return false;
}
@@ -0,0 +1,49 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/object/credential_data_input.c
# Support files and stubs (pathname alphabetical)
${SRC_DIR}/bacnet/authentication_factor.c
${SRC_DIR}/bacnet/authentication_factor_format.c
${SRC_DIR}/bacnet/bacapp.c
${SRC_DIR}/bacnet/bacdcode.c
${SRC_DIR}/bacnet/bacdevobjpropref.c
${SRC_DIR}/bacnet/bacint.c
${SRC_DIR}/bacnet/bacreal.c
${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/credential_authentication_factor.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/timestamp.c
./stubs.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/basic/object/credential_data_input.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
static void testCredentialDataInput(void)
{
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0;
uint32_t len_value = 0;
uint8_t tag_number = 0;
uint32_t decoded_instance = 0;
BACNET_OBJECT_TYPE 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);
zassert_not_equal(len, 0, NULL);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_OBJECT_ID, NULL);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
zassert_equal(decoded_type, rpdata.object_type, NULL);
zassert_equal(decoded_instance, rpdata.object_instance, NULL);
return;
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(credential_data_input_tests,
ztest_unit_test(testCredentialDataInput)
);
ztest_run_test_suite(credential_data_input_tests);
}
@@ -0,0 +1,43 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
/* Binary Input Objects customize for your use */
#include <stdbool.h>
#include <stdint.h>
#include "bacnet/bacapp.h"
bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue,
uint8_t ucExpectedTag,
BACNET_ERROR_CLASS *pErrorClass,
BACNET_ERROR_CODE *pErrorCode)
{
pValue = pValue;
ucExpectedTag = ucExpectedTag;
pErrorClass = pErrorClass;
pErrorCode = pErrorCode;
return false;
}
@@ -0,0 +1,84 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/object/device.c
# Support files and stubs (pathname alphabetical)
${SRC_DIR}/bacnet/abort.c
${SRC_DIR}/bacnet/bacaddr.c
${SRC_DIR}/bacnet/bacapp.c
${SRC_DIR}/bacnet/bacdcode.c
${SRC_DIR}/bacnet/bacdevobjpropref.c
${SRC_DIR}/bacnet/bacerror.c
${SRC_DIR}/bacnet/bacint.c
${SRC_DIR}/bacnet/bacreal.c
${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/bactimevalue.c
${SRC_DIR}/bacnet/basic/binding/address.c
${SRC_DIR}/bacnet/basic/object/acc.c
${SRC_DIR}/bacnet/basic/object/ai.c
${SRC_DIR}/bacnet/basic/object/ao.c
${SRC_DIR}/bacnet/basic/object/av.c
${SRC_DIR}/bacnet/basic/object/bi.c
${SRC_DIR}/bacnet/basic/object/bo.c
${SRC_DIR}/bacnet/basic/object/bv.c
${SRC_DIR}/bacnet/basic/object/channel.c
${SRC_DIR}/bacnet/basic/object/command.c
${SRC_DIR}/bacnet/basic/object/csv.c
${SRC_DIR}/bacnet/basic/object/iv.c
${SRC_DIR}/bacnet/basic/object/lc.c
${SRC_DIR}/bacnet/basic/object/lo.c
${SRC_DIR}/bacnet/basic/object/lsp.c
${SRC_DIR}/bacnet/basic/object/ms-input.c
${SRC_DIR}/bacnet/basic/object/mso.c
${SRC_DIR}/bacnet/basic/object/msv.c
${SRC_DIR}/bacnet/basic/object/netport.c
${SRC_DIR}/bacnet/basic/object/osv.c
${SRC_DIR}/bacnet/basic/object/piv.c
${SRC_DIR}/bacnet/basic/object/schedule.c
${SRC_DIR}/bacnet/basic/object/trendlog.c
${SRC_DIR}/bacnet/basic/service/h_apdu.c
${SRC_DIR}/bacnet/basic/service/h_cov.c
${SRC_DIR}/bacnet/basic/service/h_wp.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/basic/tsm/tsm.c
${SRC_DIR}/bacnet/cov.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/dcc.c
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/memcopy.c
${SRC_DIR}/bacnet/npdu.c
${SRC_DIR}/bacnet/proplist.c
${SRC_DIR}/bacnet/reject.c
${SRC_DIR}/bacnet/timestamp.c
${SRC_DIR}/bacnet/wp.c
./stubs.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/basic/object/device.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
static void testDevice(void)
{
bool status = false;
const char *name = "Patricia";
status = Device_Set_Object_Instance_Number(0);
zassert_equal(Device_Object_Instance_Number(), 0, NULL);
zassert_true(status, NULL);
status = Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE);
zassert_equal(Device_Object_Instance_Number(), BACNET_MAX_INSTANCE, NULL);
zassert_true(status, NULL);
status = Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE / 2);
zassert_equal(
Device_Object_Instance_Number(), (BACNET_MAX_INSTANCE / 2), NULL);
zassert_true(status, NULL);
status = Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE + 1);
zassert_not_equal(
Device_Object_Instance_Number(), (BACNET_MAX_INSTANCE + 1), NULL);
zassert_false(status, NULL);
Device_Set_System_Status(STATUS_NON_OPERATIONAL, true);
zassert_equal(Device_System_Status(), STATUS_NON_OPERATIONAL, NULL);
zassert_equal(Device_Vendor_Identifier(), BACNET_VENDOR_ID, NULL);
Device_Set_Model_Name(name, strlen(name));
zassert_equal(strcmp(Device_Model_Name(), name), 0, NULL);
return;
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(device_tests,
ztest_unit_test(testDevice)
);
ztest_run_test_suite(device_tests);
}
+58
View File
@@ -0,0 +1,58 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
/* Binary Input Objects customize for your use */
#include <stdbool.h>
#include <stdint.h>
#include "bacnet/datetime.h"
#include "bacnet/bacdef.h"
#include "bacnet/npdu.h"
void datetime_init(void)
{
}
bool datetime_local(
BACNET_DATE * bdate,
BACNET_TIME * btime,
int16_t * utc_offset_minutes,
bool * dst_active)
{
return true;
}
void bip_get_my_address(BACNET_ADDRESS * my_address)
{
}
int bip_send_pdu(
BACNET_ADDRESS * dest,
BACNET_NPDU_DATA * npdu_data,
uint8_t * pdu,
unsigned pdu_len)
{
return 0;
}
@@ -0,0 +1,47 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/object/lc.c
# Support files and stubs (pathname alphabetical)
${SRC_DIR}/bacnet/bacapp.c
${SRC_DIR}/bacnet/bacdcode.c
${SRC_DIR}/bacnet/bacdevobjpropref.c
${SRC_DIR}/bacnet/bacerror.c
${SRC_DIR}/bacnet/bacint.c
${SRC_DIR}/bacnet/bacreal.c
${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/basic/object/ao.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/lighting.c
./stubs.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
+390
View File
@@ -0,0 +1,390 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet load control object
*/
#include <ztest.h>
#include <bacnet/bacdcode.h>
#include <bacnet/basic/object/ao.h>
#include <bacnet/basic/object/lc.h>
/* TODO: Refactor basic/object/lc.c to avoid duplication of the following:
*/
/* number of demo objects */
#ifndef MAX_LOAD_CONTROLS
#define MAX_LOAD_CONTROLS 4
#endif
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
#if 0 /* TODO: How should this get exposed? */
static void Load_Control_WriteProperty_Request_Shed_Level(
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);
zassert_true(wp_data.application_data_len > 0, NULL);
status = Load_Control_Write_Property(&wp_data);
zassert_true(status, NULL);
}
#endif
#if 0 /* TODO: How should this get exposed? */
static void Load_Control_WriteProperty_Enable(
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);
zassert_true(wp_data.application_data_len > 0, NULL);
status = Load_Control_Write_Property(&wp_data);
zassert_true(status, NULL);
}
#endif
#if 0 /* TODO: How should this get exposed? */
static void Load_Control_WriteProperty_Shed_Duration(
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);
zassert_true(wp_data.application_data_len > 0, NULL);
status = Load_Control_Write_Property(&wp_data);
zassert_true(status, NULL);
}
#endif
#if 0 /* TODO: How should this get exposed? */
static void Load_Control_WriteProperty_Duty_Window(
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);
zassert_true(wp_data.application_data_len > 0, NULL);
status = Load_Control_Write_Property(&wp_data);
zassert_true(status, NULL);
}
#endif
#if 0 /* TODO: How should this get exposed? */
static void Load_Control_WriteProperty_Start_Time_Wildcards(
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);
zassert_true(wp_data.application_data_len > 0, NULL);
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);
zassert_true(wp_data.application_data_len > 0, NULL);
wp_data.application_data_len += len;
status = Load_Control_Write_Property(&wp_data);
zassert_true(status, NULL);
}
#endif
#if 0 /* TODO: How should this get exposed? */
static void Load_Control_WriteProperty_Start_Time(
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);
zassert_true(wp_data.application_data_len > 0, NULL);
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);
zassert_true(wp_data.application_data_len > 0, NULL);
wp_data.application_data_len += len;
status = Load_Control_Write_Property(&wp_data);
zassert_true(status, NULL);
}
#endif
static void testLoadControlStateMachine(void)
{
#if 0 /*TODO: Need visiblity inside LoadControlStateMachine */
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++) {
zassert_equal(Load_Control_State[i], SHED_INACTIVE, NULL);
}
}
/* 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);
zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL);
Load_Control_State_Machine(0);
zassert_equal(Load_Control_State[0], SHED_INACTIVE, NULL);
/* 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);
zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL);
Load_Control_State_Machine(0);
zassert_equal(Load_Control_State[0], SHED_INACTIVE, NULL);
/* 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);
zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL);
Load_Control_State_Machine(0);
zassert_equal(Load_Control_State[0], SHED_INACTIVE, NULL);
/* 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);
zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL);
Load_Control_State_Machine(0);
zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL);
Load_Control_WriteProperty_Request_Shed_Level(pTest, 0, 2);
Load_Control_State_Machine(0);
zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL);
Load_Control_WriteProperty_Shed_Duration(pTest, 0, 6);
Load_Control_State_Machine(0);
zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL);
Load_Control_WriteProperty_Duty_Window(pTest, 0, 60);
Load_Control_State_Machine(0);
zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL);
Load_Control_WriteProperty_Start_Time(pTest, 0, 2007, 2, 27, 15, 0, 0, 1);
Load_Control_State_Machine(0);
zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL);
Load_Control_State_Machine(0);
zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL);
Load_Control_State_Machine(0);
zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL);
/* 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);
zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL);
Load_Control_State_Machine(0);
zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL);
/* 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);
zassert_equal(Load_Control_State[0], SHED_NON_COMPLIANT, NULL);
Load_Control_State_Machine(0);
zassert_equal(Load_Control_State[0], SHED_NON_COMPLIANT, NULL);
/* FinishedUnsuccessfulShed */
datetime_set_values(&Current_Time, 2007, 2, 27, 23, 0, 0, 0);
Load_Control_State_Machine(0);
zassert_equal(Load_Control_State[0], SHED_INACTIVE, NULL);
/* 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);
zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL);
Load_Control_State_Machine(0);
zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL);
/* 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);
zassert_equal(Load_Control_State[0], SHED_NON_COMPLIANT, NULL);
Load_Control_State_Machine(0);
zassert_equal(Load_Control_State[0], SHED_NON_COMPLIANT, NULL);
/* FinishedUnsuccessfulShed */
Load_Control_WriteProperty_Start_Time(pTest, 0, 2007, 2, 27, 16, 0, 0, 0);
Load_Control_State_Machine(0);
zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL);
Load_Control_State_Machine(0);
zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL);
datetime_set_values(&Current_Time, 2007, 2, 27, 16, 0, 1, 0);
Load_Control_State_Machine(0);
zassert_equal(Load_Control_State[0], SHED_NON_COMPLIANT, NULL);
/* 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);
zassert_equal(Load_Control_State[0], SHED_COMPLIANT, NULL);
level = Analog_Output_Present_Value(0);
zassert_equal(level, 90, NULL);
/* FinishedSuccessfulShed */
datetime_set_values(&Current_Time, 2007, 2, 27, 23, 0, 0, 0);
Load_Control_State_Machine(0);
zassert_equal(Load_Control_State[0], SHED_INACTIVE, NULL);
level = Analog_Output_Present_Value(0);
zassert_equal(level, 100, NULL);
#else
ztest_test_skip();
#endif
}
static void testLoadControl(void)
{
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0;
uint32_t len_value = 0;
uint8_t tag_number = 0;
BACNET_OBJECT_TYPE decoded_type = 0;
uint32_t decoded_instance = 0;
BACNET_READ_PROPERTY_DATA rpdata;
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);
zassert_true(len != 0, NULL);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_OBJECT_ID, NULL);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
zassert_equal(decoded_type, rpdata.object_type, NULL);
zassert_equal(decoded_instance, rpdata.object_instance, NULL);
return;
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(lc_tests,
ztest_unit_test(testLoadControl),
ztest_unit_test(testLoadControlStateMachine)
);
ztest_run_test_suite(lc_tests);
}
+59
View File
@@ -0,0 +1,59 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
/* Binary Input Objects customize for your use */
#include <stdbool.h>
#include <stdint.h>
#include "bacnet/bacapp.h"
#include "bacnet/datetime.h"
//#include "bacnet/bacdef.h"
//#include "bacnet/npdu.h"
bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue,
uint8_t ucExpectedTag,
BACNET_ERROR_CLASS *pErrorClass,
BACNET_ERROR_CODE *pErrorCode)
{
pValue = pValue;
ucExpectedTag = ucExpectedTag;
pErrorClass = pErrorClass;
pErrorCode = pErrorCode;
return false;
}
void datetime_init(void)
{
}
bool datetime_local(
BACNET_DATE * bdate,
BACNET_TIME * btime,
int16_t * utc_offset_minutes,
bool * dst_active)
{
return true;
}
@@ -0,0 +1,47 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/object/lo.c
# Support files and stubs (pathname alphabetical)
${SRC_DIR}/bacnet/bacapp.c
${SRC_DIR}/bacnet/bacdcode.c
${SRC_DIR}/bacnet/bacdevobjpropref.c
${SRC_DIR}/bacnet/bacerror.c
${SRC_DIR}/bacnet/bacint.c
${SRC_DIR}/bacnet/bacreal.c
${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/basic/object/ao.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/lighting.c
./stubs.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
+61
View File
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/basic/object/lo.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
static void testLightingOutput(void)
{
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0;
uint32_t len_value = 0;
uint8_t tag_number = 0;
BACNET_OBJECT_TYPE decoded_type = 0;
uint32_t decoded_instance = 0;
BACNET_READ_PROPERTY_DATA rpdata;
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);
zassert_not_equal(len, 0, NULL);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_OBJECT_ID, NULL);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
zassert_equal(decoded_type, rpdata.object_type, NULL);
zassert_equal(decoded_instance, rpdata.object_instance, NULL);
return;
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(lo_tests,
ztest_unit_test(testLightingOutput)
);
ztest_run_test_suite(lo_tests);
}
+59
View File
@@ -0,0 +1,59 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
/* Binary Input Objects customize for your use */
#include <stdbool.h>
#include <stdint.h>
#include "bacnet/bacapp.h"
#include "bacnet/datetime.h"
//#include "bacnet/bacdef.h"
//#include "bacnet/npdu.h"
bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue,
uint8_t ucExpectedTag,
BACNET_ERROR_CLASS *pErrorClass,
BACNET_ERROR_CODE *pErrorCode)
{
pValue = pValue;
ucExpectedTag = ucExpectedTag;
pErrorClass = pErrorClass;
pErrorCode = pErrorCode;
return false;
}
void datetime_init(void)
{
}
bool datetime_local(
BACNET_DATE * bdate,
BACNET_TIME * btime,
int16_t * utc_offset_minutes,
bool * dst_active)
{
return true;
}
@@ -0,0 +1,46 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/object/lsp.c
# Support files and stubs (pathname alphabetical)
${SRC_DIR}/bacnet/bacapp.c
${SRC_DIR}/bacnet/bacdcode.c
${SRC_DIR}/bacnet/bacdevobjpropref.c
${SRC_DIR}/bacnet/bacerror.c
${SRC_DIR}/bacnet/bacint.c
${SRC_DIR}/bacnet/bacreal.c
${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/lighting.c
./stubs.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
+61
View File
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/basic/object/lsp.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
static void testLifeSafetyPoint(void)
{
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0;
uint32_t len_value = 0;
uint8_t tag_number = 0;
BACNET_OBJECT_TYPE decoded_type = 0;
uint32_t decoded_instance = 0;
BACNET_READ_PROPERTY_DATA rpdata;
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);
zassert_not_equal(len, 0, NULL);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_OBJECT_ID, NULL);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
zassert_equal(decoded_type, rpdata.object_type, NULL);
zassert_equal(decoded_instance, rpdata.object_instance, NULL);
return;
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(lsp_tests,
ztest_unit_test(testLifeSafetyPoint)
);
ztest_run_test_suite(lsp_tests);
}
+43
View File
@@ -0,0 +1,43 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
/* Binary Input Objects customize for your use */
#include <stdbool.h>
#include <stdint.h>
#include "bacnet/bacapp.h"
bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue,
uint8_t ucExpectedTag,
BACNET_ERROR_CLASS *pErrorClass,
BACNET_ERROR_CODE *pErrorCode)
{
pValue = pValue;
ucExpectedTag = ucExpectedTag;
pErrorClass = pErrorClass;
pErrorCode = pErrorCode;
return false;
}
@@ -0,0 +1,84 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/object/ms-input.c
# Support files and stubs (pathname alphabetical)
${SRC_DIR}/bacnet/abort.c
${SRC_DIR}/bacnet/bacaddr.c
${SRC_DIR}/bacnet/bacapp.c
${SRC_DIR}/bacnet/bacdcode.c
${SRC_DIR}/bacnet/bacdevobjpropref.c
${SRC_DIR}/bacnet/bacerror.c
${SRC_DIR}/bacnet/bacint.c
${SRC_DIR}/bacnet/bacreal.c
${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/bactimevalue.c
${SRC_DIR}/bacnet/basic/binding/address.c
${SRC_DIR}/bacnet/basic/object/acc.c
${SRC_DIR}/bacnet/basic/object/ai.c
${SRC_DIR}/bacnet/basic/object/ao.c
${SRC_DIR}/bacnet/basic/object/av.c
${SRC_DIR}/bacnet/basic/object/bi.c
${SRC_DIR}/bacnet/basic/object/bo.c
${SRC_DIR}/bacnet/basic/object/bv.c
${SRC_DIR}/bacnet/basic/object/channel.c
${SRC_DIR}/bacnet/basic/object/command.c
${SRC_DIR}/bacnet/basic/object/csv.c
${SRC_DIR}/bacnet/basic/object/device.c
${SRC_DIR}/bacnet/basic/object/iv.c
${SRC_DIR}/bacnet/basic/object/lc.c
${SRC_DIR}/bacnet/basic/object/lo.c
${SRC_DIR}/bacnet/basic/object/lsp.c
${SRC_DIR}/bacnet/basic/object/mso.c
${SRC_DIR}/bacnet/basic/object/msv.c
${SRC_DIR}/bacnet/basic/object/netport.c
${SRC_DIR}/bacnet/basic/object/osv.c
${SRC_DIR}/bacnet/basic/object/piv.c
${SRC_DIR}/bacnet/basic/object/schedule.c
${SRC_DIR}/bacnet/basic/object/trendlog.c
${SRC_DIR}/bacnet/basic/service/h_apdu.c
${SRC_DIR}/bacnet/basic/service/h_cov.c
${SRC_DIR}/bacnet/basic/service/h_wp.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/basic/tsm/tsm.c
${SRC_DIR}/bacnet/cov.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/dcc.c
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/memcopy.c
${SRC_DIR}/bacnet/npdu.c
${SRC_DIR}/bacnet/proplist.c
${SRC_DIR}/bacnet/reject.c
${SRC_DIR}/bacnet/timestamp.c
${SRC_DIR}/bacnet/wp.c
./stubs.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/basic/object/ms-input.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
static void testMultistateInput(void)
{
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0;
uint32_t len_value = 0;
uint8_t tag_number = 0;
BACNET_OBJECT_TYPE decoded_type = 0;
uint32_t decoded_instance = 0;
BACNET_READ_PROPERTY_DATA rpdata;
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);
zassert_not_equal(len, 0, NULL);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_OBJECT_ID, NULL);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
zassert_equal(decoded_type, rpdata.object_type, NULL);
zassert_equal(decoded_instance, rpdata.object_instance, NULL);
return;
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(ms_input_tests,
ztest_unit_test(testMultistateInput)
);
ztest_run_test_suite(ms_input_tests);
}
+58
View File
@@ -0,0 +1,58 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
/* Binary Input Objects customize for your use */
#include <stdbool.h>
#include <stdint.h>
#include "bacnet/datetime.h"
#include "bacnet/bacdef.h"
#include "bacnet/npdu.h"
void datetime_init(void)
{
}
bool datetime_local(
BACNET_DATE * bdate,
BACNET_TIME * btime,
int16_t * utc_offset_minutes,
bool * dst_active)
{
return true;
}
void bip_get_my_address(BACNET_ADDRESS * my_address)
{
}
int bip_send_pdu(
BACNET_ADDRESS * dest,
BACNET_NPDU_DATA * npdu_data,
uint8_t * pdu,
unsigned pdu_len)
{
return 0;
}
@@ -0,0 +1,45 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/object/mso.c
# Support files and stubs (pathname alphabetical)
${SRC_DIR}/bacnet/bacapp.c
${SRC_DIR}/bacnet/bacdcode.c
${SRC_DIR}/bacnet/bacdevobjpropref.c
${SRC_DIR}/bacnet/bacint.c
${SRC_DIR}/bacnet/bacreal.c
${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/lighting.c
./stubs.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
+61
View File
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/basic/object/mso.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
static void testMultistateOutput(void)
{
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0;
uint32_t len_value = 0;
uint8_t tag_number = 0;
BACNET_OBJECT_TYPE decoded_type = 0;
uint32_t decoded_instance = 0;
BACNET_READ_PROPERTY_DATA rpdata;
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);
zassert_not_equal(len, 0, NULL);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_OBJECT_ID, NULL);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
zassert_equal(decoded_type, rpdata.object_type, NULL);
zassert_equal(decoded_instance, rpdata.object_instance, NULL);
return;
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(mso_tests,
ztest_unit_test(testMultistateOutput)
);
ztest_run_test_suite(mso_tests);
}
+43
View File
@@ -0,0 +1,43 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
/* Binary Input Objects customize for your use */
#include <stdbool.h>
#include <stdint.h>
#include "bacnet/bacapp.h"
bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue,
uint8_t ucExpectedTag,
BACNET_ERROR_CLASS *pErrorClass,
BACNET_ERROR_CODE *pErrorCode)
{
pValue = pValue;
ucExpectedTag = ucExpectedTag;
pErrorClass = pErrorClass;
pErrorCode = pErrorCode;
return false;
}
@@ -0,0 +1,45 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/object/msv.c
# Support files and stubs (pathname alphabetical)
${SRC_DIR}/bacnet/bacapp.c
${SRC_DIR}/bacnet/bacdcode.c
${SRC_DIR}/bacnet/bacdevobjpropref.c
${SRC_DIR}/bacnet/bacint.c
${SRC_DIR}/bacnet/bacreal.c
${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/lighting.c
./stubs.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
+61
View File
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/basic/object/msv.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
static void testMultistateInput(void)
{
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0;
uint32_t len_value = 0;
uint8_t tag_number = 0;
BACNET_OBJECT_TYPE decoded_type = 0;
uint32_t decoded_instance = 0;
BACNET_READ_PROPERTY_DATA rpdata;
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);
zassert_not_equal(len, 0, NULL);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_OBJECT_ID, NULL);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
zassert_equal(decoded_type, rpdata.object_type, NULL);
zassert_equal(decoded_instance, rpdata.object_instance, NULL);
return;
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(msv_tests,
ztest_unit_test(testMultistateInput)
);
ztest_run_test_suite(msv_tests);
}
+43
View File
@@ -0,0 +1,43 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
/* Binary Input Objects customize for your use */
#include <stdbool.h>
#include <stdint.h>
#include "bacnet/bacapp.h"
bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue,
uint8_t ucExpectedTag,
BACNET_ERROR_CLASS *pErrorClass,
BACNET_ERROR_CODE *pErrorCode)
{
pValue = pValue;
ucExpectedTag = ucExpectedTag;
pErrorClass = pErrorClass;
pErrorCode = pErrorCode;
return false;
}
@@ -0,0 +1,46 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/object/netport.c
# Support files and stubs (pathname alphabetical)
${SRC_DIR}/bacnet/bacapp.c
${SRC_DIR}/bacnet/bacdcode.c
${SRC_DIR}/bacnet/bacdevobjpropref.c
${SRC_DIR}/bacnet/bacerror.c
${SRC_DIR}/bacnet/bacint.c
${SRC_DIR}/bacnet/bacreal.c
${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/proplist.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
+100
View File
@@ -0,0 +1,100 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/readrange.h>
#include <bacnet/basic/object/netport.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
static void test_network_port(void)
{
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);
zassert_true(status, NULL);
status = Network_Port_Type_Set(object_instance, port_type[port]);
zassert_true(status, NULL);
Network_Port_Init();
count = Network_Port_Count();
zassert_true(count > 0, NULL);
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);
zassert_not_equal(len, 0, NULL);
test_len = bacapp_decode_application_data(rpdata.application_data,
(uint8_t)rpdata.application_data_len, &value);
zassert_true(test_len >= 0, NULL);
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);
zassert_not_equal(len, 0, NULL);
test_len = bacapp_decode_application_data(rpdata.application_data,
(uint8_t)rpdata.application_data_len, &value);
zassert_true(test_len >= 0, NULL);
if (test_len < 0) {
printf("<decode failed!>\n");
}
pOptional++;
}
port++;
}
return;
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(netport_tests,
ztest_unit_test(test_network_port)
);
ztest_run_test_suite(netport_tests);
}
@@ -0,0 +1,36 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/object/objects.c
# Support files and stubs (pathname alphabetical)
${SRC_DIR}/bacnet/basic/sys/key.c
${SRC_DIR}/bacnet/basic/sys/keylist.c
./stubs.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
@@ -0,0 +1,83 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/basic/sys/keylist.h>
#include <bacnet/basic/object/objects.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
#if 0 /*TODO: Change to use external methods */
static void testBACnetObjectsCompare(
OBJECT_DEVICE_T *pDevice, uint32_t device_id)
{
zassert_not_null(pDevice, NULL);
if (pDevice) {
zassert_not_null(pDevice->Object_List, NULL);
zassert_equal(pDevice->Object_Identifier.instance, device_id, NULL);
zassert_equal(pDevice->Object_Identifier.type, OBJECT_DEVICE, NULL);
zassert_equal(pDevice->Object_Type, OBJECT_DEVICE, NULL);
}
}
#endif
static void testBACnetObjects(void)
{
#if 0 /*TODO: Change to use external methods */
uint32_t device_id = 0;
unsigned test_point = 0;
const unsigned max_test_points = 20;
OBJECT_DEVICE_T *pDevice;
for (test_point = 0; test_point < max_test_points; test_point++) {
device_id = test_point * (BACNET_MAX_INSTANCE / max_test_points);
pDevice = objects_device_new(device_id);
testBACnetObjectsCompare(pDevice, device_id);
pDevice = objects_device_by_instance(device_id);
testBACnetObjectsCompare(pDevice, device_id);
}
zassert_equal(max_test_points, objects_device_count(), NULL);
for (test_point = 0; test_point < max_test_points; test_point++) {
device_id = test_point * (BACNET_MAX_INSTANCE / max_test_points);
pDevice = objects_device_by_instance(device_id);
testBACnetObjectsCompare(pDevice, device_id);
}
for (test_point = 0; test_point < max_test_points; test_point++) {
device_id = test_point * (BACNET_MAX_INSTANCE / max_test_points);
pDevice = objects_device_data(test_point);
testBACnetObjectsCompare(
pDevice, Keylist_Key(Device_List, test_point));
}
for (test_point = 0; test_point < max_test_points; test_point++) {
pDevice = objects_device_delete(0);
}
#else
ztest_test_skip();
#endif
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(objects_tests,
ztest_unit_test(testBACnetObjects)
);
ztest_run_test_suite(objects_tests);
}
+43
View File
@@ -0,0 +1,43 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
/* Binary Input Objects customize for your use */
#include <stdbool.h>
#include <stdint.h>
#include "bacnet/bacapp.h"
bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue,
uint8_t ucExpectedTag,
BACNET_ERROR_CLASS *pErrorClass,
BACNET_ERROR_CODE *pErrorCode)
{
pValue = pValue;
ucExpectedTag = ucExpectedTag;
pErrorClass = pErrorClass;
pErrorCode = pErrorCode;
return false;
}
@@ -0,0 +1,45 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/object/osv.c
# Support files and stubs (pathname alphabetical)
${SRC_DIR}/bacnet/bacapp.c
${SRC_DIR}/bacnet/bacdcode.c
${SRC_DIR}/bacnet/bacdevobjpropref.c
${SRC_DIR}/bacnet/bacint.c
${SRC_DIR}/bacnet/bacreal.c
${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/lighting.c
./stubs.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
+61
View File
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/basic/object/osv.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
static void testOctetString_Value(void)
{
BACNET_READ_PROPERTY_DATA rpdata;
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0;
uint32_t len_value = 0;
uint8_t tag_number = 0;
BACNET_OBJECT_TYPE decoded_type = 0;
uint32_t decoded_instance = 0;
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);
zassert_not_equal(len, 0, NULL);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_OBJECT_ID, NULL);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
zassert_equal(decoded_type, rpdata.object_type, NULL);
zassert_equal(decoded_instance, rpdata.object_instance, NULL);
return;
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(osv_tests,
ztest_unit_test(testOctetString_Value)
);
ztest_run_test_suite(osv_tests);
}
+43
View File
@@ -0,0 +1,43 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
/* Binary Input Objects customize for your use */
#include <stdbool.h>
#include <stdint.h>
#include "bacnet/bacapp.h"
bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue,
uint8_t ucExpectedTag,
BACNET_ERROR_CLASS *pErrorClass,
BACNET_ERROR_CODE *pErrorCode)
{
pValue = pValue;
ucExpectedTag = ucExpectedTag;
pErrorClass = pErrorClass;
pErrorCode = pErrorCode;
return false;
}
@@ -0,0 +1,45 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/object/piv.c
# Support files and stubs (pathname alphabetical)
${SRC_DIR}/bacnet/bacapp.c
${SRC_DIR}/bacnet/bacdcode.c
${SRC_DIR}/bacnet/bacdevobjpropref.c
${SRC_DIR}/bacnet/bacint.c
${SRC_DIR}/bacnet/bacreal.c
${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/lighting.c
./stubs.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
+61
View File
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/basic/object/piv.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
static void testPositiveInteger_Value(void)
{
BACNET_READ_PROPERTY_DATA rpdata;
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0;
uint32_t len_value = 0;
uint8_t tag_number = 0;
BACNET_OBJECT_TYPE decoded_type = 0;
uint32_t decoded_instance = 0;
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);
zassert_not_equal(len, 0, NULL);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_OBJECT_ID, NULL);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
zassert_equal(decoded_type, rpdata.object_type, NULL);
zassert_equal(decoded_instance, rpdata.object_instance, NULL);
return;
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(piv_tests,
ztest_unit_test(testPositiveInteger_Value)
);
ztest_run_test_suite(piv_tests);
}
+43
View File
@@ -0,0 +1,43 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
/* Binary Input Objects customize for your use */
#include <stdbool.h>
#include <stdint.h>
#include "bacnet/bacapp.h"
bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue,
uint8_t ucExpectedTag,
BACNET_ERROR_CLASS *pErrorClass,
BACNET_ERROR_CODE *pErrorCode)
{
pValue = pValue;
ucExpectedTag = ucExpectedTag;
pErrorClass = pErrorClass;
pErrorCode = pErrorCode;
return false;
}
@@ -0,0 +1,46 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/object/schedule.c
# Support files and stubs (pathname alphabetical)
${SRC_DIR}/bacnet/bacapp.c
${SRC_DIR}/bacnet/bacdcode.c
${SRC_DIR}/bacnet/bacdevobjpropref.c
${SRC_DIR}/bacnet/bacint.c
${SRC_DIR}/bacnet/bacreal.c
${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/bactimevalue.c
${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/lighting.c
./stubs.c
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/basic/object/schedule.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
static void testSchedule(void)
{
BACNET_READ_PROPERTY_DATA rpdata;
uint8_t apdu[MAX_APDU] = { 0 };
int len = 0;
uint32_t len_value = 0;
uint8_t tag_number = 0;
BACNET_OBJECT_TYPE decoded_type = 0;
uint32_t decoded_instance = 0;
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);
zassert_not_equal(len, 0, NULL);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_OBJECT_ID, NULL);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
zassert_equal(decoded_type, rpdata.object_type, NULL);
zassert_equal(decoded_instance, rpdata.object_instance, NULL);
return;
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(schedule_tests,
ztest_unit_test(testSchedule)
);
ztest_run_test_suite(schedule_tests);
}
+43
View File
@@ -0,0 +1,43 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
/* Binary Input Objects customize for your use */
#include <stdbool.h>
#include <stdint.h>
#include "bacnet/bacapp.h"
bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue,
uint8_t ucExpectedTag,
BACNET_ERROR_CLASS *pErrorClass,
BACNET_ERROR_CODE *pErrorCode)
{
pValue = pValue;
ucExpectedTag = ucExpectedTag;
pErrorClass = pErrorClass;
pErrorCode = pErrorCode;
return false;
}
+33
View File
@@ -0,0 +1,33 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/sys/fifo.c
# Support files and stubs (pathname alphabetical)
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
+147
View File
@@ -0,0 +1,147 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <limits.h>
#include <ztest.h>
#include <bacnet/basic/sys/fifo.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Unit Test for the FIFO buffer
*/
static void testFIFOBuffer(void)
{
/* FIFO data structure */
FIFO_BUFFER test_buffer = { 0 };
/* FIFO data store. Note: size must be a power of two! */
volatile uint8_t data_store[64] = { 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;
FIFO_Init(&test_buffer, data_store, sizeof(data_store));
zassert_true(FIFO_Empty(&test_buffer), NULL);
/* load the buffer */
for (test_data = 0; test_data < sizeof(data_store); test_data++) {
zassert_false(FIFO_Full(&test_buffer), NULL);
zassert_true(FIFO_Available(&test_buffer, 1), NULL);
status = FIFO_Put(&test_buffer, test_data);
zassert_true(status, NULL);
zassert_false(FIFO_Empty(&test_buffer), NULL);
}
/* not able to put any more */
zassert_true(FIFO_Full(&test_buffer), NULL);
zassert_false(FIFO_Available(&test_buffer, 1), NULL);
status = FIFO_Put(&test_buffer, 42);
zassert_false(status, NULL);
/* unload the buffer */
for (index = 0; index < sizeof(data_store); index++) {
zassert_false(FIFO_Empty(&test_buffer), NULL);
test_data = FIFO_Peek(&test_buffer);
zassert_equal(test_data, index, NULL);
test_data = FIFO_Get(&test_buffer);
zassert_equal(test_data, index, NULL);
zassert_true(FIFO_Available(&test_buffer, 1), NULL);
zassert_false(FIFO_Full(&test_buffer), NULL);
}
zassert_true(FIFO_Empty(&test_buffer), NULL);
test_data = FIFO_Get(&test_buffer);
zassert_equal(test_data, 0, NULL);
test_data = FIFO_Peek(&test_buffer);
zassert_equal(test_data, 0, NULL);
zassert_true(FIFO_Empty(&test_buffer), NULL);
/* test the ring around the buffer */
for (index = 0; index < sizeof(data_store); index++) {
zassert_true(FIFO_Empty(&test_buffer), NULL);
zassert_true(FIFO_Available(&test_buffer, 4), NULL);
for (count = 1; count < 4; count++) {
test_data = count;
status = FIFO_Put(&test_buffer, test_data);
zassert_true(status, NULL);
zassert_false(FIFO_Empty(&test_buffer), NULL);
}
for (count = 1; count < 4; count++) {
zassert_false(FIFO_Empty(&test_buffer), NULL);
test_data = FIFO_Peek(&test_buffer);
zassert_equal(test_data, count, NULL);
test_data = FIFO_Get(&test_buffer);
zassert_equal(test_data, count, NULL);
}
}
zassert_true(FIFO_Empty(&test_buffer), NULL);
/* test Add */
zassert_true(FIFO_Available(&test_buffer, sizeof(add_data)), NULL);
status = FIFO_Add(&test_buffer, add_data, sizeof(add_data));
zassert_true(status, NULL);
count = FIFO_Count(&test_buffer);
zassert_equal(count, sizeof(add_data), NULL);
zassert_false(FIFO_Empty(&test_buffer), NULL);
for (index = 0; index < sizeof(add_data); index++) {
/* unload the buffer */
zassert_false(FIFO_Empty(&test_buffer), NULL);
test_data = FIFO_Peek(&test_buffer);
zassert_equal(test_data, add_data[index], NULL);
test_data = FIFO_Get(&test_buffer);
zassert_equal(test_data, add_data[index], NULL);
}
zassert_true(FIFO_Empty(&test_buffer), NULL);
/* test Pull */
zassert_true(FIFO_Available(&test_buffer, sizeof(add_data)), NULL);
status = FIFO_Add(&test_buffer, add_data, sizeof(add_data));
zassert_true(status, NULL);
count = FIFO_Count(&test_buffer);
zassert_equal(count, sizeof(add_data), NULL);
zassert_false(FIFO_Empty(&test_buffer), NULL);
count = FIFO_Pull(&test_buffer, &test_add_data[0], sizeof(test_add_data));
zassert_true(FIFO_Empty(&test_buffer), NULL);
zassert_equal(count, sizeof(test_add_data), NULL);
for (index = 0; index < sizeof(add_data); index++) {
zassert_equal(test_add_data[index], add_data[index], NULL);
}
zassert_true(FIFO_Available(&test_buffer, sizeof(add_data)), NULL);
status = FIFO_Add(&test_buffer, test_add_data, sizeof(add_data));
zassert_true(status, NULL);
zassert_false(FIFO_Empty(&test_buffer), NULL);
for (index = 0; index < sizeof(add_data); index++) {
count = FIFO_Pull(&test_buffer, &test_add_data[0], 1);
zassert_equal(count, 1, NULL);
zassert_equal(test_add_data[0], add_data[index], NULL);
}
zassert_true(FIFO_Empty(&test_buffer), NULL);
/* test flush */
status = FIFO_Add(&test_buffer, test_add_data, sizeof(test_add_data));
zassert_true(status, NULL);
zassert_false(FIFO_Empty(&test_buffer), NULL);
FIFO_Flush(&test_buffer);
zassert_true(FIFO_Empty(&test_buffer), NULL);
return;
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(fifo_tests,
ztest_unit_test(testFIFOBuffer)
);
ztest_run_test_suite(fifo_tests);
}
@@ -0,0 +1,33 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/sys/filename.c
# Support files and stubs (pathname alphabetical)
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
+56
View File
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/basic/sys/filename.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
static void testFilename(void)
{
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);
zassert_equal(strcmp("run", filename), 0, NULL);
filename = filename_remove_path(data2);
zassert_equal(strcmp("run", filename), 0, NULL);
filename = filename_remove_path(data3);
zassert_equal(strcmp("run.exe", filename), 0, NULL);
filename = filename_remove_path(data4);
zassert_equal(strcmp("run", filename), 0, NULL);
filename = filename_remove_path(data5);
zassert_equal(strcmp("run", filename), 0, NULL);
return;
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(filename_tests,
ztest_unit_test(testFilename)
);
ztest_run_test_suite(filename_tests);
}
+33
View File
@@ -0,0 +1,33 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/sys/key.c
# Support files and stubs (pathname alphabetical)
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
+63
View File
@@ -0,0 +1,63 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/basic/sys/key.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test the encode and decode macros
*/
static void testKeySample(void)
{
int type, id;
int type_list[] = { 0, 1, KEY_TYPE_MAX / 2, KEY_TYPE_MAX - 1, -1 };
int id_list[] = { 0, 1, KEY_ID_MAX / 2, KEY_ID_MAX - 1, -1 };
int type_index = 0;
int id_index = 0;
int decoded_type;
int decoded_id;
KEY key;
while (type_list[type_index] != -1) {
while (id_list[id_index] != -1) {
type = type_list[type_index];
id = id_list[id_index];
key = KEY_ENCODE(type, id);
decoded_type = KEY_DECODE_TYPE(key);
decoded_id = KEY_DECODE_ID(key);
zassert_equal(decoded_type, type, NULL);
zassert_equal(decoded_id, id, NULL);
id_index++;
}
id_index = 0;
type_index++;
}
return;
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(key_tests,
ztest_unit_test(testKeySample)
);
ztest_run_test_suite(key_tests);
}
@@ -0,0 +1,33 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/sys/keylist.c
# Support files and stubs (pathname alphabetical)
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
+303
View File
@@ -0,0 +1,303 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/basic/sys/keylist.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test the FIFO
*/
static void testKeyListFIFO(void)
{
OS_Keylist list;
KEY key;
int index;
char *data1 = "Joshua";
char *data2 = "Anna";
char *data3 = "Mary";
char *data;
list = Keylist_Create();
zassert_not_null(list, NULL);
key = 0;
index = Keylist_Data_Add(list, key, data1);
zassert_equal(index, 0, NULL);
index = Keylist_Data_Add(list, key, data2);
zassert_equal(index, 0, NULL);
index = Keylist_Data_Add(list, key, data3);
zassert_equal(index, 0, NULL);
zassert_equal(Keylist_Count(list), 3, NULL);
data = Keylist_Data_Pop(list);
zassert_not_null(data, NULL);
zassert_equal(strcmp(data, data1), 0, NULL);
data = Keylist_Data_Pop(list);
zassert_not_null(data, NULL);
zassert_equal(strcmp(data, data2), 0, NULL);
data = Keylist_Data_Pop(list);
zassert_not_null(data, NULL);
zassert_equal(strcmp(data, data3), 0, NULL);
data = Keylist_Data_Pop(list);
zassert_equal(data, NULL, NULL);
data = Keylist_Data_Pop(list);
zassert_equal(data, NULL, NULL);
Keylist_Delete(list);
return;
}
/* test the FILO */
static void testKeyListFILO(void)
{
OS_Keylist list;
KEY key;
int index;
char *data1 = "Joshua";
char *data2 = "Anna";
char *data3 = "Mary";
char *data;
list = Keylist_Create();
zassert_not_null(list, NULL);
key = 0;
index = Keylist_Data_Add(list, key, data1);
zassert_equal(index, 0, NULL);
index = Keylist_Data_Add(list, key, data2);
zassert_equal(index, 0, NULL);
index = Keylist_Data_Add(list, key, data3);
zassert_equal(index, 0, NULL);
zassert_equal(Keylist_Count(list), 3, NULL);
data = Keylist_Data_Delete_By_Index(list, 0);
zassert_not_null(data, NULL);
zassert_equal(strcmp(data, data3), 0, NULL);
data = Keylist_Data_Delete_By_Index(list, 0);
zassert_not_null(data, NULL);
zassert_equal(strcmp(data, data2), 0, NULL);
data = Keylist_Data_Delete_By_Index(list, 0);
zassert_not_null(data, NULL);
zassert_equal(strcmp(data, data1), 0, NULL);
data = Keylist_Data_Delete_By_Index(list, 0);
zassert_equal(data, NULL, NULL);
data = Keylist_Data_Delete_By_Index(list, 0);
zassert_equal(data, NULL, NULL);
Keylist_Delete(list);
return;
}
static void testKeyListDataKey(void)
{
OS_Keylist list;
KEY key;
KEY test_key;
int index;
char *data1 = "Joshua";
char *data2 = "Anna";
char *data3 = "Mary";
char *data;
list = Keylist_Create();
zassert_not_null(list, NULL);
key = 1;
index = Keylist_Data_Add(list, key, data1);
zassert_equal(index, 0, NULL);
test_key = Keylist_Key(list, index);
zassert_equal(test_key, key, NULL);
key = 2;
index = Keylist_Data_Add(list, key, data2);
zassert_equal(index, 1, NULL);
test_key = Keylist_Key(list, index);
zassert_equal(test_key, key, NULL);
key = 3;
index = Keylist_Data_Add(list, key, data3);
zassert_equal(index, 2, NULL);
test_key = Keylist_Key(list, index);
zassert_equal(test_key, key, NULL);
zassert_equal(Keylist_Count(list), 3, NULL);
/* look at the data */
key = 2;
data = Keylist_Data(list, key);
zassert_not_null(data, NULL);
zassert_equal(strcmp(data, data2), 0, NULL);
key = 1;
data = Keylist_Data(list, key);
zassert_not_null(data, NULL);
zassert_equal(strcmp(data, data1), 0, NULL);
key = 3;
data = Keylist_Data(list, key);
zassert_not_null(data, NULL);
zassert_equal(strcmp(data, data3), 0, NULL);
/* work the data */
key = 2;
data = Keylist_Data_Delete(list, key);
zassert_not_null(data, NULL);
zassert_equal(strcmp(data, data2), 0, NULL);
data = Keylist_Data_Delete(list, key);
zassert_equal(data, NULL, NULL);
zassert_equal(Keylist_Count(list), 2, NULL);
key = 1;
data = Keylist_Data(list, key);
zassert_not_null(data, NULL);
zassert_equal(strcmp(data, data1), 0, NULL);
key = 3;
data = Keylist_Data(list, key);
zassert_not_null(data, NULL);
zassert_equal(strcmp(data, data3), 0, NULL);
/* cleanup */
do {
data = Keylist_Data_Pop(list);
} while (data);
Keylist_Delete(list);
return;
}
static void testKeyListDataIndex(void)
{
OS_Keylist list;
KEY key;
int index;
char *data1 = "Joshua";
char *data2 = "Anna";
char *data3 = "Mary";
char *data;
list = Keylist_Create();
zassert_not_null(list, NULL);
key = 0;
index = Keylist_Data_Add(list, key, data1);
zassert_equal(index, 0, NULL);
index = Keylist_Data_Add(list, key, data2);
zassert_equal(index, 0, NULL);
index = Keylist_Data_Add(list, key, data3);
zassert_equal(index, 0, NULL);
zassert_equal(Keylist_Count(list), 3, NULL);
/* look at the data */
data = Keylist_Data_Index(list, 0);
zassert_not_null(data, NULL);
zassert_equal(strcmp(data, data3), 0, NULL);
data = Keylist_Data_Index(list, 1);
zassert_not_null(data, NULL);
zassert_equal(strcmp(data, data2), 0, NULL);
data = Keylist_Data_Index(list, 2);
zassert_not_null(data, NULL);
zassert_equal(strcmp(data, data1), 0, NULL);
/* work the data */
data = Keylist_Data_Delete_By_Index(list, 1);
zassert_not_null(data, NULL);
zassert_equal(strcmp(data, data2), 0, NULL);
zassert_equal(Keylist_Count(list), 2, NULL);
data = Keylist_Data_Index(list, 0);
zassert_not_null(data, NULL);
zassert_equal(strcmp(data, data3), 0, NULL);
data = Keylist_Data_Index(list, 1);
zassert_not_null(data, NULL);
zassert_equal(strcmp(data, data1), 0, NULL);
data = Keylist_Data_Delete_By_Index(list, 1);
zassert_not_null(data, NULL);
zassert_equal(strcmp(data, data1), 0, NULL);
data = Keylist_Data_Delete_By_Index(list, 1);
zassert_equal(data, NULL, NULL);
/* cleanup */
do {
data = Keylist_Data_Pop(list);
} while (data);
Keylist_Delete(list);
return;
}
/* test access of a lot of entries */
static void testKeyListLarge(void)
{
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);
zassert_equal(*data, data1, NULL);
}
for (index = 0; index < num_keys; index++) {
data = Keylist_Data_Index(list, index);
zassert_equal(*data, data1, NULL);
}
Keylist_Delete(list);
return;
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(keylist_tests,
ztest_unit_test(testKeyListFIFO),
ztest_unit_test(testKeyListFILO),
ztest_unit_test(testKeyListDataKey),
ztest_unit_test(testKeyListDataIndex),
ztest_unit_test(testKeyListLarge)
);
ztest_run_test_suite(keylist_tests);
}
@@ -0,0 +1,33 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/sys/ringbuf.c
# Support files and stubs (pathname alphabetical)
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
+352
View File
@@ -0,0 +1,352 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <limits.h>
#include <ztest.h>
#include <bacnet/basic/sys/ringbuf.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
/**
* Unit Test for the ring buffer
*
* @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(
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;
zassert_true(Ringbuf_Empty(test_buffer), NULL);
/* 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);
zassert_true(status, NULL);
zassert_equal(Ringbuf_Count(test_buffer), count, NULL);
}
for (count = 1; count < 4; count++) {
value = (index * count) % 255;
test_data = Ringbuf_Peek(test_buffer);
zassert_not_null(test_data, NULL);
if (test_data) {
for (data_index = 0; data_index < element_size; data_index++) {
zassert_equal(test_data[data_index], value, NULL);
}
}
status = Ringbuf_Pop(test_buffer, NULL);
zassert_true(status, NULL);
}
}
zassert_true(Ringbuf_Empty(test_buffer), NULL);
}
/**
* Unit Test for the ring buffer
*
* @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(
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;
}
zassert_true(Ringbuf_Empty(&test_buffer), NULL);
zassert_equal(Ringbuf_Depth(&test_buffer), 0, NULL);
for (data_index = 0; data_index < element_size; data_index++) {
data_element[data_index] = data_index;
}
status = Ringbuf_Put(&test_buffer, data_element);
zassert_true(status, NULL);
zassert_false(Ringbuf_Empty(&test_buffer), NULL);
zassert_equal(Ringbuf_Depth(&test_buffer), 1, NULL);
test_data = Ringbuf_Peek(&test_buffer);
for (data_index = 0; data_index < element_size; data_index++) {
zassert_equal(test_data[data_index], data_element[data_index], NULL);
}
zassert_false(Ringbuf_Empty(&test_buffer), NULL);
(void)Ringbuf_Pop(&test_buffer, NULL);
zassert_true(Ringbuf_Empty(&test_buffer), NULL);
zassert_equal(Ringbuf_Depth(&test_buffer), 1, NULL);
/* 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);
zassert_true(status, NULL);
zassert_false(Ringbuf_Empty(&test_buffer), NULL);
zassert_equal(Ringbuf_Depth(&test_buffer), (index + 1), NULL);
}
zassert_equal(Ringbuf_Depth(&test_buffer), element_count, NULL);
/* 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);
zassert_false(status, NULL);
zassert_false(Ringbuf_Empty(&test_buffer), NULL);
zassert_equal(Ringbuf_Depth(&test_buffer), element_count, NULL);
}
/* check buffer full */
for (index = 0; index < element_count; index++) {
test_data = Ringbuf_Peek(&test_buffer);
zassert_not_null(test_data, NULL);
if (test_data) {
for (data_index = 0; data_index < element_size; data_index++) {
zassert_equal(test_data[data_index], index, NULL);
}
}
(void)Ringbuf_Pop(&test_buffer, NULL);
}
zassert_true(Ringbuf_Empty(&test_buffer), NULL);
zassert_equal(Ringbuf_Depth(&test_buffer), element_count, NULL);
Ringbuf_Depth_Reset(&test_buffer);
zassert_equal(Ringbuf_Depth(&test_buffer), 0, NULL);
testRingAroundBuffer(
&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(
&test_buffer, data_element, element_size, element_count);
return true;
}
/**
* Unit Test for the ring buffer with 16 data elements
*/
static void testRingBufSizeSmall(void)
{
bool status;
uint8_t data_element[5];
uint8_t data_store[sizeof(data_element) * NEXT_POWER_OF_2(16)];
status = testRingBuf(data_store, data_element, sizeof(data_element),
sizeof(data_store) / sizeof(data_element));
zassert_true(status, NULL);
}
/**
* Unit Test for the ring buffer with 32 data elements
*/
static void testRingBufSizeLarge(void)
{
bool status;
uint8_t data_element[16];
uint8_t data_store[sizeof(data_element) * NEXT_POWER_OF_2(99)];
status = testRingBuf(data_store, data_element, sizeof(data_element),
sizeof(data_store) / sizeof(data_element));
zassert_true(status, NULL);
}
/**
* Unit Test for the ring buffer with 32 data elements
*/
static void testRingBufSizeInvalid(void)
{
bool status;
uint8_t data_element[16];
uint8_t data_store[sizeof(data_element) * 99];
status = testRingBuf(data_store, data_element, sizeof(data_element),
sizeof(data_store) / sizeof(data_element));
zassert_false(status, NULL);
}
static void testRingBufPowerOfTwo(void)
{
zassert_equal(NEXT_POWER_OF_2(3), 4, NULL);
zassert_equal(NEXT_POWER_OF_2(100), 128, NULL);
zassert_equal(NEXT_POWER_OF_2(127), 128, NULL);
zassert_equal(NEXT_POWER_OF_2(128), 128, NULL);
zassert_equal(NEXT_POWER_OF_2(129), 256, NULL);
zassert_equal(NEXT_POWER_OF_2(300), 512, NULL);
zassert_equal(NEXT_POWER_OF_2(500), 512, NULL);
}
/**
* Unit Test for the ring buffer peek/pop next element
*
* @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(
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;
}
zassert_true(Ringbuf_Empty(&test_buffer), NULL);
zassert_equal(Ringbuf_Depth(&test_buffer), 0, NULL);
for (data_index = 0; data_index < element_size; data_index++) {
data_element[data_index] = data_index;
}
status = Ringbuf_Put(&test_buffer, data_element);
zassert_true(status, NULL);
zassert_false(Ringbuf_Empty(&test_buffer), NULL);
zassert_equal(Ringbuf_Depth(&test_buffer), 1, NULL);
test_data = Ringbuf_Peek(&test_buffer);
for (data_index = 0; data_index < element_size; data_index++) {
zassert_equal(test_data[data_index], data_element[data_index], NULL);
}
zassert_false(Ringbuf_Empty(&test_buffer), NULL);
(void)Ringbuf_Pop(&test_buffer, NULL);
zassert_true(Ringbuf_Empty(&test_buffer), NULL);
zassert_equal(Ringbuf_Depth(&test_buffer), 1, NULL);
/* 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);
zassert_true(status, NULL);
zassert_false(Ringbuf_Empty(&test_buffer), NULL);
zassert_equal(Ringbuf_Depth(&test_buffer), (index + 1), NULL);
}
zassert_equal(Ringbuf_Depth(&test_buffer), element_count, NULL);
zassert_equal(Ringbuf_Count(&test_buffer), element_count, NULL);
/* Walk through ring buffer */
test_data = Ringbuf_Peek(&test_buffer);
zassert_not_null(test_data, NULL);
for (index = 1; index < element_count; index++) {
test_data = Ringbuf_Peek_Next(&test_buffer, (uint8_t *)test_data);
zassert_not_null(test_data, NULL);
if (test_data) {
for (data_index = 0; data_index < element_size; data_index++) {
zassert_equal(test_data[data_index], index, NULL);
}
}
}
zassert_equal(Ringbuf_Count(&test_buffer), element_count, NULL);
/* Try to walk off end of buffer - should return NULL */
test_data = Ringbuf_Peek_Next(&test_buffer, (uint8_t *)test_data);
zassert_is_null(test_data, NULL);
/* Walk through ring buffer and pop alternate elements */
test_data = Ringbuf_Peek(&test_buffer);
zassert_not_null(test_data, NULL);
for (index = 1; index < element_count / 2; index++) {
test_data = Ringbuf_Peek_Next(&test_buffer, (uint8_t *)test_data);
zassert_not_null(test_data, NULL);
(void)Ringbuf_Pop_Element(&test_buffer, (uint8_t *)test_data, NULL);
test_data = Ringbuf_Peek_Next(&test_buffer, (uint8_t *)test_data);
}
zassert_equal(Ringbuf_Count(&test_buffer), element_count / 2 + 1, NULL);
/* Walk through ring buffer and check data */
test_data = Ringbuf_Peek(&test_buffer);
zassert_not_null(test_data, NULL);
for (index = 0; index < element_count / 2; index++) {
if (test_data) {
for (data_index = 0; data_index < element_size; data_index++) {
zassert_equal(test_data[data_index], index * 2, NULL);
}
}
test_data = Ringbuf_Peek_Next(&test_buffer, (uint8_t *)test_data);
zassert_not_null(test_data, NULL);
}
zassert_equal(Ringbuf_Count(&test_buffer), element_count / 2 + 1, NULL);
return true;
}
/**
* Unit Test for the ring buffer with 16 data elements
*/
static void testRingBufNextElementSizeSmall(void)
{
bool status;
uint8_t data_element[5];
uint8_t data_store[sizeof(data_element) * NEXT_POWER_OF_2(16)];
status = testRingBufNextElement(data_store, data_element,
sizeof(data_element), sizeof(data_store) / sizeof(data_element));
zassert_true(status, NULL);
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(ringbuf_tests,
ztest_unit_test(testRingBufPowerOfTwo),
ztest_unit_test(testRingBufSizeSmall),
ztest_unit_test(testRingBufSizeLarge),
ztest_unit_test(testRingBufSizeInvalid),
ztest_unit_test(testRingBufNextElementSizeSmall)
);
ztest_run_test_suite(ringbuf_tests);
}
+33
View File
@@ -0,0 +1,33 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE "/bacnet/[a-zA-Z_/-]*$" "" TST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
string(REGEX REPLACE "/test$" "/src" SRC_DIR ${TST_DIR})
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/sys/sbuf.c
# Support files and stubs (pathname alphabetical)
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
+85
View File
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2020 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*/
/* @file
* @brief test BACnet integer encode/decode APIs
*/
#include <ztest.h>
#include <bacnet/basic/sys/sbuf.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* @brief Test
*/
static void testStaticBuffer(void)
{
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);
zassert_true(sbuf_empty(&sbuffer), NULL);
zassert_equal(sbuf_data(&sbuffer), NULL, NULL);
zassert_equal(sbuf_size(&sbuffer), 0, NULL);
zassert_equal(sbuf_count(&sbuffer), 0, NULL);
zassert_false(sbuf_append(&sbuffer, data1, strlen(data1)), NULL);
sbuf_init(&sbuffer, data_buffer, sizeof(data_buffer));
zassert_true(sbuf_empty(&sbuffer), NULL);
zassert_equal(sbuf_data(&sbuffer), data_buffer, NULL);
zassert_equal(sbuf_size(&sbuffer), sizeof(data_buffer), NULL);
zassert_equal(sbuf_count(&sbuffer), 0, NULL);
zassert_true(sbuf_append(&sbuffer, data1, strlen(data1)), NULL);
zassert_true(sbuf_append(&sbuffer, data2, strlen(data2)), NULL);
zassert_true(sbuf_append(&sbuffer, data3, strlen(data3)), NULL);
zassert_true(sbuf_append(&sbuffer, data4, strlen(data4)), NULL);
strcat(test_data_buffer, data1);
strcat(test_data_buffer, data2);
strcat(test_data_buffer, data3);
strcat(test_data_buffer, data4);
zassert_equal(sbuf_count(&sbuffer), strlen(test_data_buffer), NULL);
data = sbuf_data(&sbuffer);
count = sbuf_count(&sbuffer);
zassert_equal(memcmp(data, test_data_buffer, count), 0, NULL);
zassert_equal(count, strlen(test_data_buffer), NULL);
zassert_true(sbuf_truncate(&sbuffer, 0), NULL);
zassert_equal(sbuf_count(&sbuffer), 0, NULL);
zassert_equal(sbuf_size(&sbuffer), sizeof(data_buffer), NULL);
zassert_true(sbuf_append(&sbuffer, data4, strlen(data4)), NULL);
data = sbuf_data(&sbuffer);
count = sbuf_count(&sbuffer);
zassert_equal(memcmp(data, data4, count), 0, NULL);
zassert_equal(count, strlen(data4), NULL);
return;
}
/**
* @}
*/
void test_main(void)
{
ztest_test_suite(sbuf_tests,
ztest_unit_test(testStaticBuffer)
);
ztest_run_test_suite(sbuf_tests);
}