Bugfix/bacnet real endian simplify (#89)

* Remove dependence on endian define

* Make use of existing big_endian function if BACNET_BIG_ENDIAN is not defined

* Add efficient endian macro option if available

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
Steve Karg
2020-05-24 09:36:21 -05:00
committed by GitHub
parent 764e0e8448
commit cbfa74e48d
25 changed files with 354 additions and 257 deletions
+5
View File
@@ -61,6 +61,11 @@ bacint: logfile bacint.mak
( ./bacint >> ${LOGFILE} )
$(MAKE) -s -f bacint.mak clean
bacreal: logfile bacnet/bacreal/Makefile
$(MAKE) -s -C bacnet/bacreal/ clean all
( ./bacnet/bacreal/unittest >> ${LOGFILE} )
$(MAKE) -s -C bacnet/bacreal/ clean
bacstr: logfile bacstr.mak
$(MAKE) -s -f bacstr.mak clean all
( ./bacstr >> ${LOGFILE} )
+43
View File
@@ -0,0 +1,43 @@
#Makefile to build test case
CC = gcc
SRC_DIR = ../../../src
TEST_DIR = ../../../test
INCLUDES = -I$(SRC_DIR) -I$(TEST_DIR)
DEFINES = -DDEBUG_ENABLED=0
CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g
SRCS = main.c \
$(SRC_DIR)/bacnet/bacreal.c \
$(SRC_DIR)/bacnet/basic/sys/bigend.c \
$(TEST_DIR)/ctest.c
TARGET_NAME = unittest
ifeq ($(OS),Windows_NT)
TARGET_EXT = .exe
else
TARGET_EXT =
endif
TARGET = $(TARGET_NAME)$(TARGET_EXT)
all: ${TARGET}
OBJS = ${SRCS:.c=.o}
${TARGET}: ${OBJS}
${CC} -o $@ ${OBJS}
.c.o:
${CC} -c ${CFLAGS} $*.c -o $@
depend:
rm -f .depend
${CC} -MM ${CFLAGS} *.c >> .depend
clean:
rm -rf ${TARGET} $(OBJS)
test: ${TARGET}
./${TARGET}
include: .depend
+98
View File
@@ -0,0 +1,98 @@
/**
* @file
* @author Steve Karg
* @date April 2020
* @brief Test file for a REAL and DOUBLE encode and decode
*
* @section LICENSE
*
* 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.
*/
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
#include <string.h>
#include "bacnet/bacreal.h"
#include "ctest.h"
static void test_setup(void)
{
}
static void test_cleanup(void)
{
}
void testBACreal(Test *pTest)
{
float real_value = 3.14159F, test_real_value = 0.0;
uint8_t apdu[50] = { 0 };
int len = 0, test_len = 0;
test_setup();
len = encode_bacnet_real(real_value, &apdu[0]);
ct_test(pTest, len == 4);
test_len = decode_real(&apdu[0], &test_real_value);
ct_test(pTest, test_len == len);
ct_test(pTest, test_real_value == real_value);
test_cleanup();
}
void testBACdouble(Test *pTest)
{
double double_value = 3.1415927, test_double_value = 0.0;
uint8_t apdu[50] = { 0 };
int len = 0, test_len = 0;
test_setup();
len = encode_bacnet_double(double_value, &apdu[0]);
ct_test(pTest, len == 8);
test_len = decode_double(&apdu[0], &test_double_value);
ct_test(pTest, test_len == len);
ct_test(pTest, test_double_value == double_value);
test_cleanup();
}
int main(void)
{
Test *pTest;
bool rc;
pTest = ct_create("BACreal", NULL);
/* individual tests */
rc = ct_addTestFunction(pTest, testBACreal);
assert(rc);
rc = ct_addTestFunction(pTest, testBACdouble);
assert(rc);
/* configure output */
ct_setStream(pTest, stdout);
ct_run(pTest);
(void)ct_report(pTest);
ct_destroy(pTest);
return 0;
}