Feature/bacnet bacerror unit tests (#407)
* Add <zephyr/fff.h> from zephyr v3.1.0 Zephyr is deprecating the zmock library in favor of using the FFF faking library for defining and controlling fake implementations of depended-upon APIs called by the code-under-test. Signed-off-by: Gregory Shue <gregory.shue@legrand.com> * Fix bacerror_decode_service_request return value; add unit tests bacerror_decode_service_request() return value now includes the apdu bytes parsed for invoke_id and service. Also added a unit test for functions in bacerror.c, using `fff` for faking the depended-upon functions. Verified by: 1. (Pass) cd $bacnet-stack/test && make test 2. (Pass) west build -p always -b unit_testing \ bacnet-stack/zephyr/tests/unit/bacnet/bacerror/ && \ ./build/testbinary 3. (Pass) ./zephyr/scripts/twister -p unit_testing \ -T bacnet-stack/zephyr/tests/unit/bacnet/bacerror/ Signed-off-by: Gregory Shue <gregory.shue@legrand.com> --------- Signed-off-by: Gregory Shue <gregory.shue@legrand.com> Co-authored-by: Gregory Shue <gregory.shue@legrand.com>
This commit is contained in:
@@ -73,7 +73,7 @@ int bacerror_decode_error_class_and_code(uint8_t *apdu,
|
||||
uint32_t len_value_type = 0;
|
||||
uint32_t decoded_value = 0;
|
||||
|
||||
if (apdu_len) {
|
||||
if (apdu && apdu_len) {
|
||||
/* error class */
|
||||
len += decode_tag_number_and_value(
|
||||
&apdu[len], &tag_number, &len_value_type);
|
||||
@@ -109,15 +109,17 @@ int bacerror_decode_service_request(uint8_t *apdu,
|
||||
{
|
||||
int len = 0;
|
||||
|
||||
if (apdu_len > 2) {
|
||||
if (apdu && apdu_len > 2) {
|
||||
if (invoke_id) {
|
||||
*invoke_id = apdu[0];
|
||||
}
|
||||
if (service) {
|
||||
*service = (BACNET_CONFIRMED_SERVICE)apdu[1];
|
||||
}
|
||||
len += 2;
|
||||
|
||||
/* decode the application class and code */
|
||||
len = bacerror_decode_error_class_and_code(
|
||||
len += bacerror_decode_error_class_and_code(
|
||||
&apdu[2], apdu_len - 2, error_class, error_code);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ add_custom_command(TARGET lcov
|
||||
#
|
||||
|
||||
list(APPEND testdirs
|
||||
unit/bacnet/bacerror
|
||||
unit/bacnet/bits
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
|
||||
|
||||
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
|
||||
project(unittest_${basename}
|
||||
VERSION 1.0.0
|
||||
LANGUAGES C)
|
||||
|
||||
|
||||
string(REGEX REPLACE
|
||||
"/test/unit/bacnet/[a-zA-Z_/-]*$"
|
||||
"/src"
|
||||
SRC_DIR
|
||||
${CMAKE_CURRENT_SOURCE_DIR})
|
||||
string(REGEX REPLACE
|
||||
"/test/unit/bacnet/[a-zA-Z_/-]*$"
|
||||
"/test"
|
||||
TST_DIR
|
||||
${CMAKE_CURRENT_SOURCE_DIR})
|
||||
set(ZTST_DIR "${TST_DIR}/ztest/src")
|
||||
|
||||
add_compile_definitions(
|
||||
BIG_ENDIAN=0
|
||||
CONFIG_ZTEST=1
|
||||
)
|
||||
|
||||
include_directories(
|
||||
./src
|
||||
${SRC_DIR}
|
||||
${TST_DIR}/ztest/include
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
# File(s) under test
|
||||
${SRC_DIR}/bacnet/bacerror.c
|
||||
# Support files and stubs (pathname alphabetical)
|
||||
# Test and test library files
|
||||
./src/main.c
|
||||
./src/fakes/bacdcode.c
|
||||
${ZTST_DIR}/ztest_mock.c
|
||||
${ZTST_DIR}/ztest.c
|
||||
)
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Legrand North America, LLC.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/fff.h>
|
||||
|
||||
#include "fakes/bacdcode.h"
|
||||
|
||||
#if 0
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_tag, uint8_t *, uint8_t, bool, uint32_t);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_opening_tag, uint8_t *, uint8_t);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_closing_tag, uint8_t *, uint8_t);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_tag_number, uint8_t *, uint8_t *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, bacnet_tag_number_decode, uint8_t *, uint32_t, uint8_t *);
|
||||
#endif
|
||||
DEFINE_FAKE_VALUE_FUNC(
|
||||
int, decode_tag_number_and_value, uint8_t *, uint8_t *, uint32_t *);
|
||||
#if 0
|
||||
DEFINE_FAKE_VALUE_FUNC(int, bacnet_tag_number_and_value_decode, uint8_t *, uint32_t, uint8_t *, uint32_t *);
|
||||
DEFINE_FAKE_VALUE_FUNC(bool, decode_is_opening_tag_number, uint8_t *, uint8_t);
|
||||
DEFINE_FAKE_VALUE_FUNC(bool, decode_is_closing_tag_number, uint8_t *, uint8_t);
|
||||
DEFINE_FAKE_VALUE_FUNC(bool, decode_is_context_tag, uint8_t *, uint8_t);
|
||||
DEFINE_FAKE_VALUE_FUNC(bool, decode_is_context_tag_with_length, uint8_t *, uint8_t, int *);
|
||||
DEFINE_FAKE_VALUE_FUNC(bool, decode_is_opening_tag, uint8_t *);
|
||||
DEFINE_FAKE_VALUE_FUNC(bool, decode_is_closing_tag, uint8_t *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_application_null, uint8_t *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_context_null, uint8_t *, uint8_t);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_application_boolean, uint8_t *, bool);
|
||||
DEFINE_FAKE_VALUE_FUNC(bool, decode_boolean, uint32_t);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_context_boolean, uint8_t *, uint8_t, bool);
|
||||
DEFINE_FAKE_VALUE_FUNC(bool, decode_context_boolean, uint8_t *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_context_boolean2, uint8_t *, uint8_t, bool *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_bitstring, uint8_t *, uint32_t, BACNET_BIT_STRING *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_context_bitstring, uint8_t *, uint8_t, BACNET_BIT_STRING *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_bitstring, uint8_t *, BACNET_BIT_STRING *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_application_bitstring, uint8_t *, BACNET_BIT_STRING *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_context_bitstring, uint8_t *, uint8_t, BACNET_BIT_STRING *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_application_real, uint8_t *, float);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_context_real, uint8_t *, uint8_t, float);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_context_real, uint8_t *, uint8_t, float *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_application_double, uint8_t *, double);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_context_double, uint8_t *, uint8_t, double);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_context_double, uint8_t *, uint8_t, double *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_object_id, uint8_t *, BACNET_OBJECT_TYPE *, uint32_t *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_object_id_safe, uint8_t *, uint32_t, BACNET_OBJECT_TYPE *, uint32_t *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, bacnet_object_id_decode, uint8_t *, uint16_t, uint32_t, BACNET_OBJECT_TYPE *, uint32_t *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, bacnet_object_id_application_decode, uint8_t *, uint16_t, BACNET_OBJECT_TYPE *, uint32_t *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, bacnet_object_id_context_decode, uint8_t *, uint16_t, uint8_t, BACNET_OBJECT_TYPE *, uint32_t *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_context_object_id, uint8_t *, uint8_t, BACNET_OBJECT_TYPE *, uint32_t *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_bacnet_object_id, uint8_t *, BACNET_OBJECT_TYPE, uint32_t);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_context_object_id, uint8_t *, uint8_t, BACNET_OBJECT_TYPE, uint32_t);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_application_object_id, uint8_t *, BACNET_OBJECT_TYPE, uint32_t);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_octet_string, uint8_t *, BACNET_OCTET_STRING *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_application_octet_string, uint8_t *, BACNET_OCTET_STRING *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_context_octet_string, uint8_t *, uint8_t, BACNET_OCTET_STRING *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_octet_string, uint8_t *, uint32_t, BACNET_OCTET_STRING *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_context_octet_string, uint8_t *, uint8_t, BACNET_OCTET_STRING *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, bacnet_octet_string_decode, uint8_t *, uint16_t, uint32_t, BACNET_OCTET_STRING *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, bacnet_octet_string_application_decode, uint8_t *, uint16_t, BACNET_OCTET_STRING *);
|
||||
DEFINE_FAKE_VALUE_FUNC(uint32_t, encode_bacnet_character_string_safe, uint8_t *apdu, uint32_t, uint8_t, char *, uint32_t);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_bacnet_character_string, uint8_t *, BACNET_CHARACTER_STRING *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_application_character_string, uint8_t *, BACNET_CHARACTER_STRING *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_context_character_string, uint8_t *, uint8_t, BACNET_CHARACTER_STRING *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_character_string, uint8_t *, uint32_t, BACNET_CHARACTER_STRING *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_context_character_string, uint8_t *, uint8_t, BACNET_CHARACTER_STRING *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, bacnet_character_string_decode, uint8_t *, uint16_t, uint32_t, BACNET_CHARACTER_STRING *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, bacnet_character_string_context_decode, uint8_t *, uint16_t, uint8_t, BACNET_CHARACTER_STRING *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_bacnet_unsigned, uint8_t *, BACNET_UNSIGNED_INTEGER);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_context_unsigned, uint8_t *, uint8_t, BACNET_UNSIGNED_INTEGER);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_application_unsigned, uint8_t *, BACNET_UNSIGNED_INTEGER);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_unsigned, uint8_t *, uint32_t, BACNET_UNSIGNED_INTEGER *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_context_unsigned, uint8_t *, uint8_t, BACNET_UNSIGNED_INTEGER *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, bacnet_unsigned_decode, uint8_t *, uint16_t, uint32_t, BACNET_UNSIGNED_INTEGER *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, bacnet_unsigned_application_decode, uint8_t *, uint16_t, BACNET_UNSIGNED_INTEGER *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, bacnet_unsigned_context_decode, uint8_t *, uint16_t, uint8_t, BACNET_UNSIGNED_INTEGER *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_bacnet_signed, uint8_t *, int32_t);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_application_signed, uint8_t *, int32_t);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_context_signed, uint8_t *, uint8_t, int32_t);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_signed, uint8_t *, uint32_t, int32_t *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_context_signed, uint8_t *, uint8_t, int32_t *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, bacnet_signed_decode, uint8_t *, uint16_t, uint32_t, int32_t *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, bacnet_signed_context_decode, uint8_t *, uint16_t, uint8_t, int32_t *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, bacnet_signed_application_decode, uint8_t *, uint16_t, int32_t *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, bacnet_enumerated_decode, uint8_t *, uint16_t, uint32_t, uint32_t *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, bacnet_enumerated_context_decode, uint8_t *, uint16_t, uint8_t, uint32_t *);
|
||||
#endif
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_enumerated, uint8_t *, uint32_t, uint32_t *);
|
||||
#if 0
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_context_enumerated, uint8_t *, uint8_t, uint32_t *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_bacnet_enumerated, uint8_t *, uint32_t);
|
||||
#endif
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_application_enumerated, uint8_t *, uint32_t);
|
||||
#if 0
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_context_enumerated, uint8_t *, uint8_t, uint32_t);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_bacnet_time, uint8_t *, BACNET_TIME *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_application_time, uint8_t *, BACNET_TIME *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_bacnet_time, uint8_t *, BACNET_TIME *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_bacnet_time_safe, uint8_t *, uint32_t, BACNET_TIME *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_context_time, uint8_t *, uint8_t, BACNET_TIME *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_application_time, uint8_t *, BACNET_TIME *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_context_bacnet_time, uint8_t *, uint8_t, BACNET_TIME *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, bacnet_time_decode, uint8_t *, uint16_t, uint32_t, BACNET_TIME *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, bacnet_time_context_decode, uint8_t *, uint16_t, uint8_t, BACNET_TIME *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, bacnet_time_application_decode, uint8_t *, uint16_t, BACNET_TIME *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_bacnet_date, uint8_t *, BACNET_DATE *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_application_date, uint8_t *, BACNET_DATE *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_context_date, uint8_t *, uint8_t, BACNET_DATE *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_date, uint8_t *, BACNET_DATE *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_date_safe, uint8_t *, uint32_t, BACNET_DATE *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_application_date, uint8_t *, BACNET_DATE *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_context_date, uint8_t *, uint8_t, BACNET_DATE *);
|
||||
DEFINE_FAKE_VALUE_FUNC(uint8_t, encode_max_segs_max_apdu, int, int);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_max_segs, uint8_t);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_max_apdu, uint8_t);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_simple_ack, uint8_t *, uint8_t, uint8_t);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_bacnet_address, uint8_t *, BACNET_ADDRESS *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_bacnet_address, uint8_t *, BACNET_ADDRESS *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_context_bacnet_address, uint8_t *, uint8_t, BACNET_ADDRESS *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_context_bacnet_address, uint8_t *, uint8_t, BACNET_ADDRESS *);
|
||||
#endif
|
||||
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Legrand North America, LLC.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef BACNET_STACK_TEST_UNIT_BACNET_BACERROR_FAKES_BACDCODE_H_
|
||||
#define BACNET_STACK_TEST_UNIT_BACNET_BACERROR_FAKES_BACDCODE_H_
|
||||
|
||||
#include <bacnet/bacdcode.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <zephyr/fff.h>
|
||||
|
||||
#define BACNET_STACK_TEST_BACNET_BACDCODE_FFF_FAKES_LIST(FAKE) \
|
||||
FAKE(decode_tag_number_and_value) \
|
||||
FAKE(decode_enumerated) \
|
||||
FAKE(encode_application_enumerated)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_tag, uint8_t *, uint8_t, bool, uint32_t);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_opening_tag, uint8_t *, uint8_t);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_closing_tag, uint8_t *, uint8_t);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, decode_tag_number, uint8_t *, uint8_t *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, bacnet_tag_number_decode, uint8_t *, uint32_t, uint8_t *);
|
||||
#endif
|
||||
DECLARE_FAKE_VALUE_FUNC(
|
||||
int, decode_tag_number_and_value, uint8_t *, uint8_t *, uint32_t *);
|
||||
#if 0
|
||||
DECLARE_FAKE_VALUE_FUNC(int, bacnet_tag_number_and_value_decode, uint8_t *, uint32_t, uint8_t *, uint32_t *);
|
||||
DECLARE_FAKE_VALUE_FUNC(bool, decode_is_opening_tag_number, uint8_t *, uint8_t);
|
||||
DECLARE_FAKE_VALUE_FUNC(bool, decode_is_closing_tag_number, uint8_t *, uint8_t);
|
||||
DECLARE_FAKE_VALUE_FUNC(bool, decode_is_context_tag, uint8_t *, uint8_t);
|
||||
DECLARE_FAKE_VALUE_FUNC(bool, decode_is_context_tag_with_length, uint8_t *, uint8_t, int *);
|
||||
DECLARE_FAKE_VALUE_FUNC(bool, decode_is_opening_tag, uint8_t *);
|
||||
DECLARE_FAKE_VALUE_FUNC(bool, decode_is_closing_tag, uint8_t *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_application_null, uint8_t *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_context_null, uint8_t *, uint8_t);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_application_boolean, uint8_t *, bool);
|
||||
DECLARE_FAKE_VALUE_FUNC(bool, decode_boolean, uint32_t);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_context_boolean, uint8_t *, uint8_t, bool);
|
||||
DECLARE_FAKE_VALUE_FUNC(bool, decode_context_boolean, uint8_t *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, decode_context_boolean2, uint8_t *, uint8_t, bool *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, decode_bitstring, uint8_t *, uint32_t, BACNET_BIT_STRING *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, decode_context_bitstring, uint8_t *, uint8_t, BACNET_BIT_STRING *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_bitstring, uint8_t *, BACNET_BIT_STRING *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_application_bitstring, uint8_t *, BACNET_BIT_STRING *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_context_bitstring, uint8_t *, uint8_t, BACNET_BIT_STRING *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_application_real, uint8_t *, float);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_context_real, uint8_t *, uint8_t, float);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, decode_context_real, uint8_t *, uint8_t, float *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_application_double, uint8_t *, double);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_context_double, uint8_t *, uint8_t, double);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, decode_context_double, uint8_t *, uint8_t, double *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, decode_object_id, uint8_t *, BACNET_OBJECT_TYPE *, uint32_t *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, decode_object_id_safe, uint8_t *, uint32_t, BACNET_OBJECT_TYPE *, uint32_t *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, bacnet_object_id_decode, uint8_t *, uint16_t, uint32_t, BACNET_OBJECT_TYPE *, uint32_t *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, bacnet_object_id_application_decode, uint8_t *, uint16_t, BACNET_OBJECT_TYPE *, uint32_t *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, bacnet_object_id_context_decode, uint8_t *, uint16_t, uint8_t, BACNET_OBJECT_TYPE *, uint32_t *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, decode_context_object_id, uint8_t *, uint8_t, BACNET_OBJECT_TYPE *, uint32_t *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_bacnet_object_id, uint8_t *, BACNET_OBJECT_TYPE, uint32_t);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_context_object_id, uint8_t *, uint8_t, BACNET_OBJECT_TYPE, uint32_t);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_application_object_id, uint8_t *, BACNET_OBJECT_TYPE, uint32_t);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_octet_string, uint8_t *, BACNET_OCTET_STRING *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_application_octet_string, uint8_t *, BACNET_OCTET_STRING *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_context_octet_string, uint8_t *, uint8_t, BACNET_OCTET_STRING *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, decode_octet_string, uint8_t *, uint32_t, BACNET_OCTET_STRING *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, decode_context_octet_string, uint8_t *, uint8_t, BACNET_OCTET_STRING *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, bacnet_octet_string_decode, uint8_t *, uint16_t, uint32_t, BACNET_OCTET_STRING *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, bacnet_octet_string_application_decode, uint8_t *, uint16_t, BACNET_OCTET_STRING *);
|
||||
DECLARE_FAKE_VALUE_FUNC(uint32_t, encode_bacnet_character_string_safe, uint8_t *apdu, uint32_t, uint8_t, char *, uint32_t);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_bacnet_character_string, uint8_t *, BACNET_CHARACTER_STRING *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_application_character_string, uint8_t *, BACNET_CHARACTER_STRING *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_context_character_string, uint8_t *, uint8_t, BACNET_CHARACTER_STRING *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, decode_character_string, uint8_t *, uint32_t, BACNET_CHARACTER_STRING *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, decode_context_character_string, uint8_t *, uint8_t, BACNET_CHARACTER_STRING *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, bacnet_character_string_decode, uint8_t *, uint16_t, uint32_t, BACNET_CHARACTER_STRING *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, bacnet_character_string_context_decode, uint8_t *, uint16_t, uint8_t, BACNET_CHARACTER_STRING *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_bacnet_unsigned, uint8_t *, BACNET_UNSIGNED_INTEGER);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_context_unsigned, uint8_t *, uint8_t, BACNET_UNSIGNED_INTEGER);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_application_unsigned, uint8_t *, BACNET_UNSIGNED_INTEGER);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, decode_unsigned, uint8_t *, uint32_t, BACNET_UNSIGNED_INTEGER *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, decode_context_unsigned, uint8_t *, uint8_t, BACNET_UNSIGNED_INTEGER *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, bacnet_unsigned_decode, uint8_t *, uint16_t, uint32_t, BACNET_UNSIGNED_INTEGER *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, bacnet_unsigned_application_decode, uint8_t *, uint16_t, BACNET_UNSIGNED_INTEGER *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, bacnet_unsigned_context_decode, uint8_t *, uint16_t, uint8_t, BACNET_UNSIGNED_INTEGER *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_bacnet_signed, uint8_t *, int32_t);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_application_signed, uint8_t *, int32_t);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_context_signed, uint8_t *, uint8_t, int32_t);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, decode_signed, uint8_t *, uint32_t, int32_t *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, decode_context_signed, uint8_t *, uint8_t, int32_t *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, bacnet_signed_decode, uint8_t *, uint16_t, uint32_t, int32_t *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, bacnet_signed_context_decode, uint8_t *, uint16_t, uint8_t, int32_t *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, bacnet_signed_application_decode, uint8_t *, uint16_t, int32_t *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, bacnet_enumerated_decode, uint8_t *, uint16_t, uint32_t, uint32_t *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, bacnet_enumerated_context_decode, uint8_t *, uint16_t, uint8_t, uint32_t *);
|
||||
#endif
|
||||
DECLARE_FAKE_VALUE_FUNC(
|
||||
int, decode_enumerated, uint8_t *, uint32_t, uint32_t *);
|
||||
#if 0
|
||||
DECLARE_FAKE_VALUE_FUNC(int, decode_context_enumerated, uint8_t *, uint8_t, uint32_t *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_bacnet_enumerated, uint8_t *, uint32_t);
|
||||
#endif
|
||||
DECLARE_FAKE_VALUE_FUNC(
|
||||
int, encode_application_enumerated, uint8_t *, uint32_t);
|
||||
#if 0
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_context_enumerated, uint8_t *, uint8_t, uint32_t);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_bacnet_time, uint8_t *, BACNET_TIME *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_application_time, uint8_t *, BACNET_TIME *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, decode_bacnet_time, uint8_t *, BACNET_TIME *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, decode_bacnet_time_safe, uint8_t *, uint32_t, BACNET_TIME *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_context_time, uint8_t *, uint8_t, BACNET_TIME *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, decode_application_time, uint8_t *, BACNET_TIME *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, decode_context_bacnet_time, uint8_t *, uint8_t, BACNET_TIME *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, bacnet_time_decode, uint8_t *, uint16_t, uint32_t, BACNET_TIME *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, bacnet_time_context_decode, uint8_t *, uint16_t, uint8_t, BACNET_TIME *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, bacnet_time_application_decode, uint8_t *, uint16_t, BACNET_TIME *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_bacnet_date, uint8_t *, BACNET_DATE *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_application_date, uint8_t *, BACNET_DATE *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_context_date, uint8_t *, uint8_t, BACNET_DATE *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, decode_date, uint8_t *, BACNET_DATE *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, decode_date_safe, uint8_t *, uint32_t, BACNET_DATE *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, decode_application_date, uint8_t *, BACNET_DATE *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, decode_context_date, uint8_t *, uint8_t, BACNET_DATE *);
|
||||
DECLARE_FAKE_VALUE_FUNC(uint8_t, encode_max_segs_max_apdu, int, int);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, decode_max_segs, uint8_t);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, decode_max_apdu, uint8_t);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_simple_ack, uint8_t *, uint8_t, uint8_t);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_bacnet_address, uint8_t *, BACNET_ADDRESS *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, decode_bacnet_address, uint8_t *, BACNET_ADDRESS *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, encode_context_bacnet_address, uint8_t *, uint8_t, BACNET_ADDRESS *);
|
||||
DECLARE_FAKE_VALUE_FUNC(int, decode_context_bacnet_address, uint8_t *, uint8_t, BACNET_ADDRESS *);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* BACNET_STACK_TEST_UNIT_BACNET_BACERROR_FAKES_BACDCODE_H_ */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 2011-2014, Wind River Systems, Inc.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Content copied out of <zephyr/sys/util.h> from Zephyr v3.2.0.
|
||||
* Copyright and licensing retained.
|
||||
*/
|
||||
|
||||
#ifndef BACNETSTACK_TEST_ZTEST_INCLUDE_ZEPHYR_SYS_UTIL_H_
|
||||
#define BACNETSTACK_TEST_ZTEST_INCLUDE_ZEPHYR_SYS_UTIL_H_
|
||||
|
||||
/** @brief 0 if @p cond is true-ish; causes a compile error otherwise. */
|
||||
#define ZERO_OR_COMPILE_ERROR(cond) ((int) sizeof(char[1 - 2 * !(cond)]) - 1)
|
||||
|
||||
#if defined(__cplusplus)
|
||||
|
||||
/* The built-in function used below for type checking in C is not
|
||||
* supported by GNU C++.
|
||||
*/
|
||||
#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
|
||||
|
||||
#else /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Zero if @p array has an array type, a compile error otherwise
|
||||
*
|
||||
* This macro is available only from C, not C++.
|
||||
*/
|
||||
#define IS_ARRAY(array) \
|
||||
ZERO_OR_COMPILE_ERROR( \
|
||||
!__builtin_types_compatible_p(__typeof__(array), \
|
||||
__typeof__(&(array)[0])))
|
||||
|
||||
/**
|
||||
* @brief Number of elements in the given @p array
|
||||
*
|
||||
* In C++, due to language limitations, this will accept as @p array
|
||||
* any type that implements <tt>operator[]</tt>. The results may not be
|
||||
* particularly meaningful in this case.
|
||||
*
|
||||
* In C, passing a pointer as @p array causes a compile error.
|
||||
*/
|
||||
#define ARRAY_SIZE(array) \
|
||||
((size_t) (IS_ARRAY(array) + (sizeof(array) / sizeof((array)[0]))))
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Get a pointer to a structure containing the element
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* struct foo {
|
||||
* int bar;
|
||||
* };
|
||||
*
|
||||
* struct foo my_foo;
|
||||
* int *ptr = &my_foo.bar;
|
||||
*
|
||||
* struct foo *container = CONTAINER_OF(ptr, struct foo, bar);
|
||||
*
|
||||
* Above, @p container points at @p my_foo.
|
||||
*
|
||||
* @param ptr pointer to a structure element
|
||||
* @param type name of the type that @p ptr is an element of
|
||||
* @param field the name of the field within the struct @p ptr points to
|
||||
* @return a pointer to the structure that contains @p ptr
|
||||
*/
|
||||
#define CONTAINER_OF(ptr, type, field) \
|
||||
((type *)(((char *)(ptr)) - offsetof(type, field)))
|
||||
|
||||
|
||||
#ifndef MAX
|
||||
/**
|
||||
* @brief Obtain the maximum of two values.
|
||||
*
|
||||
* @note Arguments are evaluated twice. Use Z_MAX for a GCC-only, single
|
||||
* evaluation version
|
||||
*
|
||||
* @param a First value.
|
||||
* @param b Second value.
|
||||
*
|
||||
* @returns Maximum value of @p a and @p b.
|
||||
*/
|
||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#ifndef MIN
|
||||
/**
|
||||
* @brief Obtain the minimum of two values.
|
||||
*
|
||||
* @note Arguments are evaluated twice. Use Z_MIN for a GCC-only, single
|
||||
* evaluation version
|
||||
*
|
||||
* @param a First value.
|
||||
* @param b Second value.
|
||||
*
|
||||
* @returns Minimum value of @p a and @p b.
|
||||
*/
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#endif /* BACNETSTACK_TEST_ZTEST_INCLUDE_ZEPHYR_SYS_UTIL_H_ */
|
||||
@@ -0,0 +1,37 @@
|
||||
# Copyright (c) 2022 Legrand North America, LLC.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
|
||||
if(NOT ZEPHYR_CURRENT_MODULE_DIR)
|
||||
string(REGEX REPLACE "/zephyr/tests/[a-zA-Z_/-]*$" ""
|
||||
ZEPHYR_CURRENT_MODULE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
endif()
|
||||
|
||||
if(BOARD STREQUAL unit_testing)
|
||||
find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
set(target testbinary)
|
||||
else()
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
set(target app)
|
||||
endif()
|
||||
|
||||
project(bacnet_bacerror)
|
||||
target_sources(${target} PRIVATE
|
||||
${ZEPHYR_CURRENT_MODULE_DIR}/src/bacnet/bacerror.c
|
||||
${ZEPHYR_CURRENT_MODULE_DIR}/test/unit/bacnet/bacerror/src/main.c
|
||||
${ZEPHYR_CURRENT_MODULE_DIR}/test/unit/bacnet/bacerror/src/fakes/bacdcode.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/main.c
|
||||
)
|
||||
|
||||
|
||||
# NOTE for Zephyr >= v3.2.0:
|
||||
# - Zephyr unittest builds for target 'testbinary' instead of 'app'.
|
||||
# - Zephyr unittest does not generate ZEPHYR_<modulename>_MODULE_DIR.
|
||||
# So we have to use relative paths to get to the source.
|
||||
|
||||
target_include_directories(${target} PRIVATE
|
||||
${ZEPHYR_CURRENT_MODULE_DIR}/test/unit/bacnet/bacerror/src
|
||||
${ZEPHYR_CURRENT_MODULE_DIR}/src
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
/* This file is intentionally empty */
|
||||
@@ -0,0 +1 @@
|
||||
# This file is intentionally empty
|
||||
@@ -0,0 +1,3 @@
|
||||
tests:
|
||||
bacnet.bacerror.unit:
|
||||
type: unit
|
||||
Reference in New Issue
Block a user