Added unit test for lighting command encoding and decoding.

This commit is contained in:
skarg
2013-11-14 20:21:46 +00:00
parent 5dd7159139
commit b363f9dedb
3 changed files with 87 additions and 5 deletions
+46 -4
View File
@@ -144,7 +144,7 @@ int lighting_command_decode(
apdu_max_len = apdu_max_len;
/* check for value pointers */
if (apdu_len && data) {
if (apdu_max_len && data) {
/* Tag 0: operation */
if (!decode_is_context_tag(&apdu[apdu_len], 0))
return BACNET_STATUS_ERROR;
@@ -278,7 +278,7 @@ bool lighting_command_same(
(dst->use_ramp_rate == src->use_ramp_rate) &&
(dst->use_step_increment == src->use_step_increment) &&
(dst->use_fade_time == src->use_fade_time) &&
(dst->use_priority = src->use_priority)) {
(dst->use_priority == src->use_priority)) {
status = true;
if ((dst->use_target_level) &&
(dst->target_level != src->target_level)) {
@@ -312,11 +312,53 @@ bool lighting_command_same(
#include "ctest.h"
void testBACnetLightingCommand(
Test * pTest)
Test * pTest,
BACNET_LIGHTING_COMMAND *data)
{
bool status = false;
BACNET_LIGHTING_COMMAND test_data;
int len, apdu_len;
uint8_t apdu[MAX_APDU] = {0};
status = lighting_command_copy(&test_data, NULL);
ct_test(pTest, status == false);
status = lighting_command_copy(NULL, data);
ct_test(pTest, status == false);
status = lighting_command_copy(&test_data, data);
ct_test(pTest, status == true);
status = lighting_command_same(&test_data, data);
ct_test(pTest, status == true);
len = lighting_command_encode(apdu, data);
apdu_len = lighting_command_decode(apdu, sizeof(apdu), &test_data);
ct_test(pTest, len > 0);
ct_test(pTest, apdu_len > 0);
status = lighting_command_same(&test_data, data);
}
void testBACnetLightingCommandAll(
Test * pTest)
{
BACNET_LIGHTING_COMMAND data;
data.operation = BACNET_LIGHTS_NONE;
data.use_target_level = false;
data.use_ramp_rate = false;
data.use_step_increment = false;
data.use_fade_time = false;
data.use_priority = false;
data.target_level = 0.0;
data.ramp_rate = 100.0;
data.step_increment = 1.0;
data.fade_time = 100;
data.priority = 1;
testBACnetLightingCommand(pTest, &data);
data.operation = BACNET_LIGHTS_STOP;
data.use_target_level = true;
data.use_ramp_rate = true;
data.use_step_increment = true;
data.use_fade_time = true;
data.use_priority = true;
testBACnetLightingCommand(pTest, &data);
}
#ifdef TEST_LIGHTING_COMMAND
@@ -328,7 +370,7 @@ int main(
pTest = ct_create("BACnet Lighting Command", NULL);
/* individual tests */
rc = ct_addTestFunction(pTest, testBACnetLightingCommand);
rc = ct_addTestFunction(pTest, testBACnetLightingCommandAll);
assert(rc);
ct_setStream(pTest, stdout);
+6 -1
View File
@@ -13,7 +13,7 @@ all: abort address arf awf bacapp bacdcode bacerror bacint bacstr \
cov crc datetime dcc event filename fifo getevent iam ihave \
indtext keylist key memcopy npdu proplist ptransfer \
rd reject ringbuf rp rpm sbuf timesync \
whohas whois wp objects
whohas whois wp objects lighting
clean: logfile
rm ${LOGFILE}
@@ -131,6 +131,11 @@ key: logfile test/key.mak
( ./test/key >> ${LOGFILE} )
$(MAKE) -s -C test -f key.mak clean
lighting: lighting test/lighting.mak
$(MAKE) -s -C test -f lighting.mak clean all
( ./test/lighting >> ${LOGFILE} )
$(MAKE) -s -C test -f lighting.mak clean
memcopy: logfile test/memcopy.mak
$(MAKE) -s -C test -f memcopy.mak clean all
( ./test/memcopy >> ${LOGFILE} )
+35
View File
@@ -0,0 +1,35 @@
#Makefile to build test case
CC = gcc
SRC_DIR = ../src
INCLUDES = -I../include -I.
DEFINES = -DBIG_ENDIAN=0 -DTEST -DTEST_LIGHTING_COMMAND
CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g
SRCS = $(SRC_DIR)/bacdcode.c \
$(SRC_DIR)/bacint.c \
$(SRC_DIR)/bacstr.c \
$(SRC_DIR)/bacreal.c \
$(SRC_DIR)/lighting.c \
ctest.c
TARGET = lighting
all: ${TARGET}
OBJS = ${SRCS:.c=.o}
${TARGET}: ${OBJS}
${CC} -o $@ ${OBJS}
.c.o:
${CC} -c ${CFLAGS} $*.c -o $@
depend:
rm -f .depend
${CC} -MM ${CFLAGS} *.c >> .depend
clean:
rm -rf core ${TARGET} $(OBJS) *.bak *.1 *.ini
include: .depend