Corrected PrivateTransfer unit tests.

Fixed hex-ascii conversion for zero length string. Fixed Octet-string unit test in BACnet application. Bug found by unit test.
This commit is contained in:
skarg
2012-05-13 15:02:40 +00:00
parent c0f2af65e0
commit 173e9fb9a9
5 changed files with 62 additions and 32 deletions
+23 -1
View File
@@ -2089,10 +2089,32 @@ void testBACnetApplicationData(
"Karg!", &value);
ct_test(pTest, status == true);
ct_test(pTest, testBACnetApplicationDataValue(&value));
/* test empty string */
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_CHARACTER_STRING,
"", &value);
ct_test(pTest, status == true);
ct_test(pTest, testBACnetApplicationDataValue(&value));
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING,
"Steve + Patricia", &value);
"1234567890ABCDEF", &value);
ct_test(pTest, status == true);
ct_test(pTest, testBACnetApplicationDataValue(&value));
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING,
"12-34-56-78-90-AB-CD-EF", &value);
ct_test(pTest, status == true);
ct_test(pTest, testBACnetApplicationDataValue(&value));
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING,
"12 34 56 78 90 AB CD EF", &value);
ct_test(pTest, status == true);
ct_test(pTest, testBACnetApplicationDataValue(&value));
/* test empty string */
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING,
"", &value);
ct_test(pTest, status == true);
ct_test(pTest, testBACnetApplicationDataValue(&value));
+27 -21
View File
@@ -668,28 +668,34 @@ bool octetstring_init_ascii_hex(
if (octet_string) {
octet_string->length = 0;
while (ascii_hex[index] != 0) {
if (!isalnum(ascii_hex[index])) {
/* skip non-numeric or alpha */
index++;
continue;
if (ascii_hex[0] == 0) {
/* nothing to decode, so success! */
status = true;
} else {
while (ascii_hex[index] != 0) {
if (!isalnum(ascii_hex[index])) {
/* skip non-numeric or alpha */
index++;
continue;
}
if (ascii_hex[index+1] == 0) {
break;
}
hex_pair_string[0] = ascii_hex[index];
hex_pair_string[1] = ascii_hex[index+1];
value = (uint8_t)strtol(hex_pair_string, NULL, 16);
if (octet_string->length <= MAX_OCTET_STRING_BYTES) {
octet_string->value[octet_string->length] = value;
octet_string->length++;
/* at least one pair was decoded */
status = true;
} else {
break;
status = false;
}
/* set up for next pair */
index += 2;
}
if (ascii_hex[index+1] == 0) {
break;
}
hex_pair_string[0] = ascii_hex[index];
hex_pair_string[1] = ascii_hex[index+1];
value = (uint8_t)strtol(hex_pair_string, NULL, 16);
if (octet_string->length <= MAX_OCTET_STRING_BYTES) {
octet_string->value[octet_string->length] = value;
octet_string->length++;
status = true;
} else {
break;
status = false;
}
/* set up for next pair */
index += 2;
}
}
+5 -4
View File
@@ -482,7 +482,7 @@ void test_Private_Transfer_Ack(
BACNET_PRIVATE_TRANSFER_DATA test_data;
uint8_t test_value[480] = { 0 };
int private_data_len = 0;
char private_data_chunk[32] = { "I Love You, Patricia!" };
char private_data_chunk[33] = { "00112233445566778899AABBCCDDEEFF" };
BACNET_APPLICATION_DATA_VALUE data_value;
BACNET_APPLICATION_DATA_VALUE test_data_value;
bool status = false;
@@ -535,7 +535,7 @@ void test_Private_Transfer_Error(
BACNET_PRIVATE_TRANSFER_DATA test_data;
uint8_t test_value[480] = { 0 };
int private_data_len = 0;
char private_data_chunk[32] = { "I Love You, Patricia!" };
char private_data_chunk[33] = { "00112233445566778899AABBCCDDEEFF" };
BACNET_APPLICATION_DATA_VALUE data_value;
BACNET_APPLICATION_DATA_VALUE test_data_value;
bool status = false;
@@ -584,7 +584,7 @@ void test_Private_Transfer_Request(
uint8_t invoke_id = 128;
uint8_t test_invoke_id = 0;
int private_data_len = 0;
char private_data_chunk[32] = { "I Love You, Patricia!" };
char private_data_chunk[33] = { "00112233445566778899AABBCCDDEEFF" };
BACNET_APPLICATION_DATA_VALUE data_value = {0};
BACNET_APPLICATION_DATA_VALUE test_data_value = {0};
BACNET_PRIVATE_TRANSFER_DATA private_data = {0};
@@ -638,7 +638,8 @@ void test_Unconfirmed_Private_Transfer_Request(
private_data.vendorID = BACNET_VENDOR_ID;
private_data.serviceNumber = 1;
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING,
status = bacapp_parse_application_data(
BACNET_APPLICATION_TAG_CHARACTER_STRING,
&private_data_chunk[0], &data_value);
ct_test(pTest, status == true);
private_data_len =
+2 -1
View File
@@ -3,7 +3,8 @@ CC = gcc
SRC_DIR = ../src
INCLUDES = -I../include -I.
DEFINES = -DBIG_ENDIAN=0 -DTEST -DBACAPP_ALL -DTEST_BACNET_APPLICATION_DATA
DEFINES = -DBIG_ENDIAN=0 -DTEST -DTEST_BACNET_APPLICATION_DATA
DEFINES += -DBACAPP_ALL -DPRINT_ENABLED=1
CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g
+5 -5
View File
@@ -2,7 +2,7 @@
CC = gcc
SRC_DIR = ../src
INCLUDES = -I../include -I.
DEFINES = -DBIG_ENDIAN=0 -DTEST -DTEST_PRIVATE_TRANSFER
DEFINES = -DBIG_ENDIAN=0 -PRINT_ENABLE=1 -DTEST -DTEST_PRIVATE_TRANSFER
CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g
@@ -20,19 +20,19 @@ SRCS = $(SRC_DIR)/bacdcode.c \
TARGET = ptransfer
all: ${TARGET}
OBJS = ${SRCS:.c=.o}
${TARGET}: ${OBJS}
${CC} -o $@ ${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