Added AlignAfterOpenBracket: AlwaysBreak and BinPackArguments: true to clang-format. Updated test/bacnet c/h files with updated format.

This commit is contained in:
Steve Karg
2024-04-24 09:38:12 -05:00
parent 1aaebe9414
commit 70c54817fd
120 changed files with 2182 additions and 1894 deletions
+5 -3
View File
@@ -1,15 +1,17 @@
--- ---
BasedOnStyle: WebKit BasedOnStyle: WebKit
AlignAfterOpenBracket: AlwaysBreak
BinPackArguments: true
BinPackParameters: false BinPackParameters: false
AlignEscapedNewlines: Left PenaltyBreakBeforeFirstCallParameter: 1
PointerAlignment: Right
AllowShortFunctionsOnASingleLine: None AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false AllowShortLoopsOnASingleLine: false
AlignEscapedNewlines: Left
PointerAlignment: Right
BreakBeforeBraces: Linux BreakBeforeBraces: Linux
BreakBeforeBinaryOperators: None BreakBeforeBinaryOperators: None
KeepEmptyLinesAtTheStartOfBlocks: false KeepEmptyLinesAtTheStartOfBlocks: false
PenaltyBreakBeforeFirstCallParameter: 1
IndentCaseLabels: true IndentCaseLabels: true
IndentWidth: 4 IndentWidth: 4
UseTab: Never UseTab: Never
+1 -1
View File
@@ -322,7 +322,7 @@ pretty-ports:
.PHONY: pretty-test .PHONY: pretty-test
pretty-test: pretty-test:
find ./test/bacnet -maxdepth 2 -type f -iname *.h -o -iname *.c -exec \ find ./test/bacnet -type f -iname *.h -o -iname *.c -exec \
clang-format -i -style=file -fallback-style=none {} \; clang-format -i -style=file -fallback-style=none {} \;
CLANG_TIDY_OPTIONS = -fix-errors -checks="readability-braces-around-statements" CLANG_TIDY_OPTIONS = -fix-errors -checks="readability-braces-around-statements"
+8 -10
View File
@@ -19,7 +19,8 @@
/** /**
* @brief decode the whole APDU - mainly used for unit testing * @brief decode the whole APDU - mainly used for unit testing
*/ */
static int abort_decode_apdu(uint8_t *apdu, static int abort_decode_apdu(
uint8_t *apdu,
unsigned apdu_len, unsigned apdu_len,
uint8_t *invoke_id, uint8_t *invoke_id,
uint8_t *abort_reason, uint8_t *abort_reason,
@@ -49,8 +50,7 @@ static int abort_decode_apdu(uint8_t *apdu,
/** /**
* @brief Test Abort ADPU * @brief Test Abort ADPU
*/ */
static void testAbortAPDU( static void testAbortAPDU(uint8_t invoke_id, uint8_t abort_reason, bool server)
uint8_t invoke_id, uint8_t abort_reason, bool server)
{ {
uint8_t apdu[480] = { 0 }; uint8_t apdu[480] = { 0 };
int len = 0; int len = 0;
@@ -145,8 +145,8 @@ static void testAbortError(void)
error_code = abort_convert_to_error_code(abort_code); error_code = abort_convert_to_error_code(abort_code);
test_abort_code = abort_convert_error_code(error_code); test_abort_code = abort_convert_error_code(error_code);
if (test_abort_code != abort_code) { if (test_abort_code != abort_code) {
printf("Abort: result=%u abort-code=%u\n", printf(
test_abort_code, "Abort: result=%u abort-code=%u\n", test_abort_code,
abort_code); abort_code);
} }
zassert_equal(test_abort_code, abort_code, NULL); zassert_equal(test_abort_code, abort_code, NULL);
@@ -156,16 +156,14 @@ static void testAbortError(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(abort_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(abort_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(abort_tests, ztest_test_suite(
ztest_unit_test(testAbortEncodeDecode), abort_tests, ztest_unit_test(testAbortEncodeDecode),
ztest_unit_test(testAbortError) ztest_unit_test(testAbortError));
);
ztest_run_test_suite(abort_tests); ztest_run_test_suite(abort_tests);
} }
+25 -14
View File
@@ -54,32 +54,43 @@ static void testAlarmAck(void)
zassert_equal(inLen, outLen, "inlen=%d outlen=%d", inLen, outLen); zassert_equal(inLen, outLen, "inlen=%d outlen=%d", inLen, outLen);
zassert_equal(testAlarmAckIn.ackProcessIdentifier, zassert_equal(
testAlarmAckIn.ackProcessIdentifier,
testAlarmAckOut.ackProcessIdentifier, NULL); testAlarmAckOut.ackProcessIdentifier, NULL);
zassert_equal(testAlarmAckIn.ackTimeStamp.tag, zassert_equal(
testAlarmAckOut.ackTimeStamp.tag, "in-tag=%d out-tag=%d", testAlarmAckIn.ackTimeStamp.tag, testAlarmAckOut.ackTimeStamp.tag,
testAlarmAckIn.ackTimeStamp.tag, testAlarmAckOut.ackTimeStamp.tag); "in-tag=%d out-tag=%d", testAlarmAckIn.ackTimeStamp.tag,
zassert_equal(testAlarmAckIn.ackTimeStamp.value.sequenceNum, testAlarmAckOut.ackTimeStamp.tag);
zassert_equal(
testAlarmAckIn.ackTimeStamp.value.sequenceNum,
testAlarmAckOut.ackTimeStamp.value.sequenceNum, NULL); testAlarmAckOut.ackTimeStamp.value.sequenceNum, NULL);
zassert_equal(testAlarmAckIn.ackProcessIdentifier, zassert_equal(
testAlarmAckIn.ackProcessIdentifier,
testAlarmAckOut.ackProcessIdentifier, NULL); testAlarmAckOut.ackProcessIdentifier, NULL);
zassert_equal(testAlarmAckIn.eventObjectIdentifier.instance, zassert_equal(
testAlarmAckIn.eventObjectIdentifier.instance,
testAlarmAckOut.eventObjectIdentifier.instance, NULL); testAlarmAckOut.eventObjectIdentifier.instance, NULL);
zassert_equal(testAlarmAckIn.eventObjectIdentifier.type, zassert_equal(
testAlarmAckIn.eventObjectIdentifier.type,
testAlarmAckOut.eventObjectIdentifier.type, NULL); testAlarmAckOut.eventObjectIdentifier.type, NULL);
zassert_equal(testAlarmAckIn.eventTimeStamp.tag, zassert_equal(
testAlarmAckOut.eventTimeStamp.tag, NULL); testAlarmAckIn.eventTimeStamp.tag, testAlarmAckOut.eventTimeStamp.tag,
zassert_equal(testAlarmAckIn.eventTimeStamp.value.time.hour, NULL);
zassert_equal(
testAlarmAckIn.eventTimeStamp.value.time.hour,
testAlarmAckOut.eventTimeStamp.value.time.hour, NULL); testAlarmAckOut.eventTimeStamp.value.time.hour, NULL);
zassert_equal(testAlarmAckIn.eventTimeStamp.value.time.min, zassert_equal(
testAlarmAckIn.eventTimeStamp.value.time.min,
testAlarmAckOut.eventTimeStamp.value.time.min, NULL); testAlarmAckOut.eventTimeStamp.value.time.min, NULL);
zassert_equal(testAlarmAckIn.eventTimeStamp.value.time.sec, zassert_equal(
testAlarmAckIn.eventTimeStamp.value.time.sec,
testAlarmAckOut.eventTimeStamp.value.time.sec, NULL); testAlarmAckOut.eventTimeStamp.value.time.sec, NULL);
zassert_equal(testAlarmAckIn.eventTimeStamp.value.time.hundredths, zassert_equal(
testAlarmAckIn.eventTimeStamp.value.time.hundredths,
testAlarmAckOut.eventTimeStamp.value.time.hundredths, NULL); testAlarmAckOut.eventTimeStamp.value.time.hundredths, NULL);
zassert_equal( zassert_equal(
+29 -25
View File
@@ -19,8 +19,7 @@
/** /**
* @brief Test * @brief Test
*/ */
static void testAtomicReadFileAckAccess( static void testAtomicReadFileAckAccess(BACNET_ATOMIC_READ_FILE_DATA *data)
BACNET_ATOMIC_READ_FILE_DATA *data)
{ {
BACNET_ATOMIC_READ_FILE_DATA test_data = { 0 }; BACNET_ATOMIC_READ_FILE_DATA test_data = { 0 };
uint8_t apdu[480] = { 0 }; uint8_t apdu[480] = { 0 };
@@ -31,7 +30,7 @@ static void testAtomicReadFileAckAccess(
uint8_t test_invoke_id = 0; uint8_t test_invoke_id = 0;
unsigned int i = 0; unsigned int i = 0;
null_len = arf_ack_encode_apdu(NULL, invoke_id, data); null_len = arf_ack_encode_apdu(NULL, invoke_id, data);
len = arf_ack_encode_apdu(&apdu[0], invoke_id, data); len = arf_ack_encode_apdu(&apdu[0], invoke_id, data);
zassert_not_equal(len, 0, NULL); zassert_not_equal(len, 0, NULL);
zassert_equal(null_len, len, NULL); zassert_equal(null_len, len, NULL);
@@ -46,28 +45,33 @@ static void testAtomicReadFileAckAccess(
if (test_data.access == FILE_STREAM_ACCESS) { if (test_data.access == FILE_STREAM_ACCESS) {
zassert_equal( zassert_equal(
test_data.type.stream.fileStartPosition, test_data.type.stream.fileStartPosition,
data->type.stream.fileStartPosition, NULL); data->type.stream.fileStartPosition, NULL);
zassert_equal( zassert_equal(
octetstring_length(&test_data.fileData[0]), octetstring_length(&test_data.fileData[0]),
octetstring_length(&data->fileData[0]), NULL); octetstring_length(&data->fileData[0]), NULL);
zassert_equal( zassert_equal(
memcmp(octetstring_value(&test_data.fileData[0]), memcmp(
octetstring_value(&test_data.fileData[0]),
octetstring_value(&data->fileData[0]), octetstring_value(&data->fileData[0]),
octetstring_length(&test_data.fileData[0])), 0, NULL); octetstring_length(&test_data.fileData[0])),
0, NULL);
} else if (test_data.access == FILE_RECORD_ACCESS) { } else if (test_data.access == FILE_RECORD_ACCESS) {
zassert_equal( zassert_equal(
test_data.type.record.fileStartRecord, test_data.type.record.fileStartRecord,
data->type.record.fileStartRecord, NULL); data->type.record.fileStartRecord, NULL);
zassert_equal( zassert_equal(
test_data.type.record.RecordCount, data->type.record.RecordCount, NULL); test_data.type.record.RecordCount, data->type.record.RecordCount,
NULL);
for (i = 0; i < data->type.record.RecordCount; i++) { for (i = 0; i < data->type.record.RecordCount; i++) {
zassert_equal( zassert_equal(
octetstring_length(&test_data.fileData[i]), octetstring_length(&test_data.fileData[i]),
octetstring_length(&data->fileData[i]), NULL); octetstring_length(&data->fileData[i]), NULL);
zassert_equal( zassert_equal(
memcmp(octetstring_value(&test_data.fileData[i]), memcmp(
octetstring_value(&test_data.fileData[i]),
octetstring_value(&data->fileData[i]), octetstring_value(&data->fileData[i]),
octetstring_length(&test_data.fileData[i])), 0, NULL); octetstring_length(&test_data.fileData[i])),
0, NULL);
} }
} }
/* test APDU too short */ /* test APDU too short */
@@ -134,16 +138,17 @@ static void testAtomicReadFileAccess(BACNET_ATOMIC_READ_FILE_DATA *data)
if (test_data.access == FILE_STREAM_ACCESS) { if (test_data.access == FILE_STREAM_ACCESS) {
zassert_equal( zassert_equal(
test_data.type.stream.fileStartPosition, test_data.type.stream.fileStartPosition,
data->type.stream.fileStartPosition, NULL); data->type.stream.fileStartPosition, NULL);
zassert_equal( zassert_equal(
test_data.type.stream.requestedOctetCount, test_data.type.stream.requestedOctetCount,
data->type.stream.requestedOctetCount, NULL); data->type.stream.requestedOctetCount, NULL);
} else if (test_data.access == FILE_RECORD_ACCESS) { } else if (test_data.access == FILE_RECORD_ACCESS) {
zassert_equal( zassert_equal(
test_data.type.record.fileStartRecord, test_data.type.record.fileStartRecord,
data->type.record.fileStartRecord, NULL); data->type.record.fileStartRecord, NULL);
zassert_equal( zassert_equal(
test_data.type.record.RecordCount, data->type.record.RecordCount, NULL); test_data.type.record.RecordCount, data->type.record.RecordCount,
NULL);
} }
/* test APDU too short */ /* test APDU too short */
while (apdu_len) { while (apdu_len) {
@@ -186,10 +191,11 @@ static void testAtomicReadFileMalformed(void)
{ {
uint8_t apdu[480] = { 0 }; uint8_t apdu[480] = { 0 };
/* payloads with malformation */ /* payloads with malformation */
uint8_t payload_1[] = { 0xc4, 0x02, 0x80, 0x00, 0x00, 0x0e, 0x35, 0xff, uint8_t payload_1[] = { 0xc4, 0x02, 0x80, 0x00, 0x00, 0x0e,
0xdf, 0x62, 0xee, 0x00, 0x00, 0x22, 0x05, 0x84, 0x0f }; 0x35, 0xff, 0xdf, 0x62, 0xee, 0x00,
0x00, 0x22, 0x05, 0x84, 0x0f };
uint8_t payload_2[] = { 0xc4, 0x02, 0x80, 0x00, 0x00, 0x0e, 0x31, 0x00, uint8_t payload_2[] = { 0xc4, 0x02, 0x80, 0x00, 0x00, 0x0e, 0x31, 0x00,
0x25, 0xff, 0xd4, 0x9e, 0xbf, 0x79, 0x05, 0x84 }; 0x25, 0xff, 0xd4, 0x9e, 0xbf, 0x79, 0x05, 0x84 };
BACNET_ATOMIC_READ_FILE_DATA data = { 0 }; BACNET_ATOMIC_READ_FILE_DATA data = { 0 };
int len = 0; int len = 0;
uint8_t test_invoke_id = 0; uint8_t test_invoke_id = 0;
@@ -216,17 +222,15 @@ static void testAtomicReadFileMalformed(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(arf_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(arf_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(arf_tests, ztest_test_suite(
ztest_unit_test(testAtomicReadFile), arf_tests, ztest_unit_test(testAtomicReadFile),
ztest_unit_test(testAtomicReadFileAck), ztest_unit_test(testAtomicReadFileAck),
ztest_unit_test(testAtomicReadFileMalformed) ztest_unit_test(testAtomicReadFileMalformed));
);
ztest_run_test_suite(arf_tests); ztest_run_test_suite(arf_tests);
} }
+23 -22
View File
@@ -45,22 +45,24 @@ static void testAtomicWriteFileAccess(BACNET_ATOMIC_WRITE_FILE_DATA *data)
if (test_data.access == FILE_STREAM_ACCESS) { if (test_data.access == FILE_STREAM_ACCESS) {
zassert_equal( zassert_equal(
test_data.type.stream.fileStartPosition, test_data.type.stream.fileStartPosition,
data->type.stream.fileStartPosition, NULL); data->type.stream.fileStartPosition, NULL);
} else if (test_data.access == FILE_RECORD_ACCESS) { } else if (test_data.access == FILE_RECORD_ACCESS) {
zassert_equal( zassert_equal(
test_data.type.record.fileStartRecord, test_data.type.record.fileStartRecord,
data->type.record.fileStartRecord, NULL); data->type.record.fileStartRecord, NULL);
zassert_equal( zassert_equal(
test_data.type.record.returnedRecordCount, test_data.type.record.returnedRecordCount,
data->type.record.returnedRecordCount, NULL); data->type.record.returnedRecordCount, NULL);
} }
zassert_equal( zassert_equal(
octetstring_length(&test_data.fileData[0]), octetstring_length(&test_data.fileData[0]),
octetstring_length(&data->fileData[0]), NULL); octetstring_length(&data->fileData[0]), NULL);
zassert_equal( zassert_equal(
memcmp(octetstring_value(&test_data.fileData[0]), memcmp(
octetstring_value(&test_data.fileData[0]),
octetstring_value(&data->fileData[0]), octetstring_value(&data->fileData[0]),
octetstring_length(&test_data.fileData[0])), 0, NULL); octetstring_length(&test_data.fileData[0])),
0, NULL);
/* test APDU too short */ /* test APDU too short */
while (apdu_len) { while (apdu_len) {
apdu_len--; apdu_len--;
@@ -98,8 +100,7 @@ static void testAtomicWriteFile(void)
return; return;
} }
static void testAtomicWriteFileAckAccess( static void testAtomicWriteFileAckAccess(BACNET_ATOMIC_WRITE_FILE_DATA *data)
BACNET_ATOMIC_WRITE_FILE_DATA *data)
{ {
BACNET_ATOMIC_WRITE_FILE_DATA test_data = { 0 }; BACNET_ATOMIC_WRITE_FILE_DATA test_data = { 0 };
uint8_t apdu[480] = { 0 }; uint8_t apdu[480] = { 0 };
@@ -130,11 +131,11 @@ static void testAtomicWriteFileAckAccess(
if (test_data.access == FILE_STREAM_ACCESS) { if (test_data.access == FILE_STREAM_ACCESS) {
zassert_equal( zassert_equal(
test_data.type.stream.fileStartPosition, test_data.type.stream.fileStartPosition,
data->type.stream.fileStartPosition, NULL); data->type.stream.fileStartPosition, NULL);
} else if (test_data.access == FILE_RECORD_ACCESS) { } else if (test_data.access == FILE_RECORD_ACCESS) {
zassert_equal( zassert_equal(
test_data.type.record.fileStartRecord, test_data.type.record.fileStartRecord,
data->type.record.fileStartRecord, NULL); data->type.record.fileStartRecord, NULL);
} }
/* test APDU too short */ /* test APDU too short */
while (apdu_len) { while (apdu_len) {
@@ -171,12 +172,14 @@ static void testAtomicWriteFileMalformed(void)
{ {
uint8_t apdu[480] = { 0 }; uint8_t apdu[480] = { 0 };
/* payloads with malformation */ /* payloads with malformation */
uint8_t payload_1[] = { 0xc4, 0x02, 0x80, 0x00, 0x00, 0x0e, 0x35, 0xff, uint8_t payload_1[] = { 0xc4, 0x02, 0x80, 0x00, 0x00, 0x0e,
0x5e, 0xd5, 0xc0, 0x85, 0x0a, 0x62, 0x64, 0x0a, 0x0f }; 0x35, 0xff, 0x5e, 0xd5, 0xc0, 0x85,
uint8_t payload_2[] = { 0xc4, 0x02, 0x80, 0x00, 0x00, 0x0e, 0x35, 0xff, 0x0a, 0x62, 0x64, 0x0a, 0x0f };
0xc4, 0x4d, 0x92, 0xd9, 0x0a, 0x62, 0x64, 0x0a, 0x0f, 0x0f, 0x0f, 0x0f, uint8_t payload_2[] = { 0xc4, 0x02, 0x80, 0x00, 0x00, 0x0e, 0x35,
0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xc4, 0x4d, 0x92, 0xd9, 0x0a, 0x62,
0x0f }; 0x64, 0x0a, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
0x0f, 0x0f, 0x0f, 0x0f, 0x0f };
BACNET_ATOMIC_WRITE_FILE_DATA data = { 0 }; BACNET_ATOMIC_WRITE_FILE_DATA data = { 0 };
int len = 0; int len = 0;
uint8_t test_invoke_id = 0; uint8_t test_invoke_id = 0;
@@ -203,17 +206,15 @@ static void testAtomicWriteFileMalformed(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(awf_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(awf_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(awf_tests, ztest_test_suite(
ztest_unit_test(testAtomicWriteFile), awf_tests, ztest_unit_test(testAtomicWriteFile),
ztest_unit_test(testAtomicWriteFileAck), ztest_unit_test(testAtomicWriteFileAck),
ztest_unit_test(testAtomicWriteFileMalformed) ztest_unit_test(testAtomicWriteFileMalformed));
);
ztest_run_test_suite(awf_tests); ztest_run_test_suite(awf_tests);
} }
+2 -1
View File
@@ -258,7 +258,8 @@ ZTEST_SUITE(bacnet_address_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(bacnet_address_tests, ztest_unit_test(test_BACNET_ADDRESS), ztest_test_suite(
bacnet_address_tests, ztest_unit_test(test_BACNET_ADDRESS),
ztest_unit_test(test_BACNET_MAC_ADDRESS), ztest_unit_test(test_BACNET_MAC_ADDRESS),
ztest_unit_test(test_BACnetAddress_Codec)); ztest_unit_test(test_BACnetAddress_Codec));
+66 -43
View File
@@ -98,81 +98,94 @@ static void test_bacapp_decode_data_len(void)
bacapp_decode_data_len(apdu, UINT8_MAX, sizeof(apdu)), 0, NULL); bacapp_decode_data_len(apdu, UINT8_MAX, sizeof(apdu)), 0, NULL);
expected_value = (int)(~0U >> 1); /* INT_MAX is not universally defined */ expected_value = (int)(~0U >> 1); /* INT_MAX is not universally defined */
zassert_equal(bacapp_decode_data_len( zassert_equal(
apdu, BACNET_APPLICATION_TAG_UNSIGNED_INT, UINT32_MAX), bacapp_decode_data_len(
apdu, BACNET_APPLICATION_TAG_UNSIGNED_INT, UINT32_MAX),
expected_value, NULL); expected_value, NULL);
zassert_equal( zassert_equal(
bacapp_decode_data_len(apdu, BACNET_APPLICATION_TAG_NULL, sizeof(apdu)), bacapp_decode_data_len(apdu, BACNET_APPLICATION_TAG_NULL, sizeof(apdu)),
0, NULL); 0, NULL);
zassert_equal(bacapp_decode_data_len( zassert_equal(
apdu, BACNET_APPLICATION_TAG_BOOLEAN, sizeof(apdu)), bacapp_decode_data_len(
apdu, BACNET_APPLICATION_TAG_BOOLEAN, sizeof(apdu)),
0, NULL); 0, NULL);
len_value_type = INT32_MAX - 1; len_value_type = INT32_MAX - 1;
expected_value = (int)len_value_type; expected_value = (int)len_value_type;
zassert_equal(bacapp_decode_data_len(apdu, zassert_equal(
BACNET_APPLICATION_TAG_UNSIGNED_INT, len_value_type), bacapp_decode_data_len(
apdu, BACNET_APPLICATION_TAG_UNSIGNED_INT, len_value_type),
expected_value, NULL); expected_value, NULL);
len_value_type = INT32_MAX - 2; len_value_type = INT32_MAX - 2;
expected_value = (int)len_value_type; expected_value = (int)len_value_type;
zassert_equal(bacapp_decode_data_len( zassert_equal(
apdu, BACNET_APPLICATION_TAG_SIGNED_INT, len_value_type), bacapp_decode_data_len(
apdu, BACNET_APPLICATION_TAG_SIGNED_INT, len_value_type),
expected_value, NULL); expected_value, NULL);
len_value_type = INT32_MAX - 5; len_value_type = INT32_MAX - 5;
expected_value = (int)len_value_type; expected_value = (int)len_value_type;
zassert_equal(bacapp_decode_data_len( zassert_equal(
apdu, BACNET_APPLICATION_TAG_REAL, len_value_type), bacapp_decode_data_len(
apdu, BACNET_APPLICATION_TAG_REAL, len_value_type),
expected_value, NULL); expected_value, NULL);
len_value_type = INT32_MAX - 9; len_value_type = INT32_MAX - 9;
expected_value = (int)len_value_type; expected_value = (int)len_value_type;
zassert_equal(bacapp_decode_data_len( zassert_equal(
apdu, BACNET_APPLICATION_TAG_DOUBLE, len_value_type), bacapp_decode_data_len(
apdu, BACNET_APPLICATION_TAG_DOUBLE, len_value_type),
expected_value, NULL); expected_value, NULL);
len_value_type = INT32_MAX - 13; len_value_type = INT32_MAX - 13;
expected_value = (int)len_value_type; expected_value = (int)len_value_type;
zassert_equal(bacapp_decode_data_len(apdu, zassert_equal(
BACNET_APPLICATION_TAG_OCTET_STRING, len_value_type), bacapp_decode_data_len(
apdu, BACNET_APPLICATION_TAG_OCTET_STRING, len_value_type),
expected_value, NULL); expected_value, NULL);
len_value_type = INT32_MAX - 17; len_value_type = INT32_MAX - 17;
expected_value = (int)len_value_type; expected_value = (int)len_value_type;
zassert_equal(bacapp_decode_data_len(apdu, zassert_equal(
BACNET_APPLICATION_TAG_CHARACTER_STRING, len_value_type), bacapp_decode_data_len(
apdu, BACNET_APPLICATION_TAG_CHARACTER_STRING, len_value_type),
expected_value, NULL); expected_value, NULL);
len_value_type = INT32_MAX - 19; len_value_type = INT32_MAX - 19;
expected_value = (int)len_value_type; expected_value = (int)len_value_type;
zassert_equal(bacapp_decode_data_len( zassert_equal(
apdu, BACNET_APPLICATION_TAG_BIT_STRING, len_value_type), bacapp_decode_data_len(
apdu, BACNET_APPLICATION_TAG_BIT_STRING, len_value_type),
expected_value, NULL); expected_value, NULL);
len_value_type = INT32_MAX - 23; len_value_type = INT32_MAX - 23;
expected_value = (int)len_value_type; expected_value = (int)len_value_type;
zassert_equal(bacapp_decode_data_len( zassert_equal(
apdu, BACNET_APPLICATION_TAG_ENUMERATED, len_value_type), bacapp_decode_data_len(
apdu, BACNET_APPLICATION_TAG_ENUMERATED, len_value_type),
expected_value, NULL); expected_value, NULL);
len_value_type = INT32_MAX - 29; len_value_type = INT32_MAX - 29;
expected_value = (int)len_value_type; expected_value = (int)len_value_type;
zassert_equal(bacapp_decode_data_len( zassert_equal(
apdu, BACNET_APPLICATION_TAG_DATE, len_value_type), bacapp_decode_data_len(
apdu, BACNET_APPLICATION_TAG_DATE, len_value_type),
expected_value, NULL); expected_value, NULL);
len_value_type = INT32_MAX - 31; len_value_type = INT32_MAX - 31;
expected_value = (int)len_value_type; expected_value = (int)len_value_type;
zassert_equal(bacapp_decode_data_len( zassert_equal(
apdu, BACNET_APPLICATION_TAG_TIME, len_value_type), bacapp_decode_data_len(
apdu, BACNET_APPLICATION_TAG_TIME, len_value_type),
expected_value, NULL); expected_value, NULL);
len_value_type = INT32_MAX - 37; len_value_type = INT32_MAX - 37;
expected_value = (int)len_value_type; expected_value = (int)len_value_type;
zassert_equal(bacapp_decode_data_len( zassert_equal(
apdu, BACNET_APPLICATION_TAG_OBJECT_ID, len_value_type), bacapp_decode_data_len(
apdu, BACNET_APPLICATION_TAG_OBJECT_ID, len_value_type),
expected_value, NULL); expected_value, NULL);
} }
@@ -216,7 +229,8 @@ static void test_bacapp_copy(void)
zassert_equal(result, expected_result, NULL); zassert_equal(result, expected_result, NULL);
result = bacapp_same_value(&dest_value, &src_value); result = bacapp_same_value(&dest_value, &src_value);
if (!result) { if (!result) {
printf("bacapp: same-value of tag=%s[%u]\n", printf(
"bacapp: same-value of tag=%s[%u]\n",
bactext_application_tag_name(tag), tag); bactext_application_tag_name(tag), tag);
} }
zassert_true(result, NULL); zassert_true(result, NULL);
@@ -252,7 +266,8 @@ static void test_bacapp_value_list_init(void)
zassert_equal(value[count].tag, BACNET_APPLICATION_TAG_NULL, NULL); zassert_equal(value[count].tag, BACNET_APPLICATION_TAG_NULL, NULL);
zassert_equal(value[count].context_specific, 0, NULL); zassert_equal(value[count].context_specific, 0, NULL);
zassert_equal(value[count].context_tag, 0, NULL); zassert_equal(value[count].context_tag, 0, NULL);
zassert_equal(value[count].next, zassert_equal(
value[count].next,
((count + 1 >= max_count) ? NULL : &value[count + 1]), NULL); ((count + 1 >= max_count) ? NULL : &value[count + 1]), NULL);
} }
} }
@@ -291,7 +306,8 @@ static void test_bacapp_property_value_list(void)
zassert_equal( zassert_equal(
value[count].propertyArrayIndex, BACNET_ARRAY_ALL, NULL); value[count].propertyArrayIndex, BACNET_ARRAY_ALL, NULL);
zassert_equal(value[count].priority, BACNET_NO_PRIORITY, NULL); zassert_equal(value[count].priority, BACNET_NO_PRIORITY, NULL);
zassert_equal(value[count].next, zassert_equal(
value[count].next,
((count + 1 >= max_count) ? NULL : &value[count + 1]), NULL); ((count + 1 >= max_count) ? NULL : &value[count + 1]), NULL);
} }
} }
@@ -316,14 +332,17 @@ static void test_bacapp_property_value_list(void)
if (test_len != BACNET_STATUS_ERROR) { if (test_len != BACNET_STATUS_ERROR) {
/* shorter packet leaves off the OPTIONAL priority */ /* shorter packet leaves off the OPTIONAL priority */
zassert_equal(len, test_len, "len=%d test_len=%d", len, test_len); zassert_equal(len, test_len, "len=%d test_len=%d", len, test_len);
zassert_equal(value[1].priority, BACNET_NO_PRIORITY, "priority=%u", zassert_equal(
value[1].priority, BACNET_NO_PRIORITY, "priority=%u",
(unsigned)value[1].priority); (unsigned)value[1].priority);
} else { } else {
zassert_equal(test_len, BACNET_STATUS_ERROR, "len=%d test_len=%d", zassert_equal(
len, test_len); test_len, BACNET_STATUS_ERROR, "len=%d test_len=%d", len,
test_len);
test_len = bacapp_property_value_decode(apdu, len, NULL); test_len = bacapp_property_value_decode(apdu, len, NULL);
zassert_equal(test_len, BACNET_STATUS_ERROR, "len=%d test_len=%d", zassert_equal(
len, test_len); test_len, BACNET_STATUS_ERROR, "len=%d test_len=%d", len,
test_len);
} }
} }
} }
@@ -564,7 +583,8 @@ static void testBACnetApplicationData_Safe(void)
case BACNET_APPLICATION_TAG_OCTET_STRING: { case BACNET_APPLICATION_TAG_OCTET_STRING: {
uint8_t test_octet[5] = { "Karg" }; uint8_t test_octet[5] = { "Karg" };
octetstring_init(&input_value[i].type.Octet_String, test_octet, octetstring_init(
&input_value[i].type.Octet_String, test_octet,
sizeof(test_octet)); sizeof(test_octet));
} break; } break;
@@ -823,8 +843,8 @@ static void testBACnetApplicationDataLength(void)
/** /**
* @brief Test * @brief Test
*/ */
static bool verifyBACnetApplicationDataValue( static bool
BACNET_APPLICATION_DATA_VALUE *value) verifyBACnetApplicationDataValue(BACNET_APPLICATION_DATA_VALUE *value)
{ {
uint8_t apdu[480] = { 0 }; uint8_t apdu[480] = { 0 };
int apdu_len = 0; int apdu_len = 0;
@@ -845,10 +865,12 @@ static bool verifyBACnetApplicationDataValue(
test_len = test_len =
bacapp_decode_application_data(&apdu[0], apdu_len, &test_value); bacapp_decode_application_data(&apdu[0], apdu_len, &test_value);
if (apdu_len == 0) { if (apdu_len == 0) {
zassert_equal(test_len, 0, "tag=%u apdu_len=%d test_len=%d\n", zassert_equal(
value->tag, apdu_len, test_len); test_len, 0, "tag=%u apdu_len=%d test_len=%d\n", value->tag,
apdu_len, test_len);
} else { } else {
zassert_equal(test_len, BACNET_STATUS_ERROR, zassert_equal(
test_len, BACNET_STATUS_ERROR,
"tag=%u apdu_len=%d test_len=%d null_len=%d\n", value->tag, "tag=%u apdu_len=%d test_len=%d null_len=%d\n", value->tag,
apdu_len, test_len, null_len); apdu_len, test_len, null_len);
} }
@@ -1162,7 +1184,8 @@ static void test_bacapp_context_data(void)
apdu_len = apdu_len =
bacapp_encode_context_data_value(apdu, context_tag_number, &value); bacapp_encode_context_data_value(apdu, context_tag_number, &value);
if (apdu_len != null_len) { if (apdu_len != null_len) {
printf("bacapp: NULL len=%d != APDU len=%d for tag=%s", null_len, printf(
"bacapp: NULL len=%d != APDU len=%d for tag=%s", null_len,
apdu_len, bactext_application_tag_name(tag)); apdu_len, bactext_application_tag_name(tag));
} }
zassert_equal(apdu_len, null_len, NULL); zassert_equal(apdu_len, null_len, NULL);
@@ -1209,8 +1232,8 @@ ZTEST_SUITE(bacapp_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(bacapp_tests, ztest_test_suite(
ztest_unit_test(test_bacapp_decode_application_data), bacapp_tests, ztest_unit_test(test_bacapp_decode_application_data),
ztest_unit_test(test_bacapp_decode_data_len), ztest_unit_test(test_bacapp_decode_data_len),
ztest_unit_test(test_bacapp_copy), ztest_unit_test(test_bacapp_copy),
ztest_unit_test(test_bacapp_value_list_init), ztest_unit_test(test_bacapp_value_list_init),
+62 -40
View File
@@ -41,7 +41,8 @@ static int get_apdu_len(bool extended_tag, uint32_t value)
return test_len; return test_len;
} }
static void test_bacnet_tag_codec(uint8_t tag_number, static void test_bacnet_tag_codec(
uint8_t tag_number,
bool context_specific, bool context_specific,
bool opening, bool opening,
bool closing, bool closing,
@@ -448,8 +449,8 @@ static void testBACnetDateRangeDecodes(void)
#endif #endif
{ {
uint8_t apdu[MAX_APDU]; uint8_t apdu[MAX_APDU];
uint8_t sample[10] = { 0xa4, 0xff, 0xff, 0xff, 0xff, 0xa4, 0xff, 0xff, 0xff, uint8_t sample[10] = { 0xa4, 0xff, 0xff, 0xff, 0xff,
0xff }; 0xa4, 0xff, 0xff, 0xff, 0xff };
int len; int len;
int null_len; int null_len;
int test_len; int test_len;
@@ -515,7 +516,8 @@ static void verifyBACDCodeUnsignedValue(BACNET_UNSIGNED_INTEGER value)
len_value = encode_application_unsigned(&array[0], value); len_value = encode_application_unsigned(&array[0], value);
len = decode_tag_number_and_value(&array[0], &tag_number, &len_value); len = decode_tag_number_and_value(&array[0], &tag_number, &len_value);
len = decode_unsigned(&array[len], len_value, &decoded_value); len = decode_unsigned(&array[len], len_value, &decoded_value);
zassert_equal(decoded_value, value, "value=%lu decoded_value=%lu\n", zassert_equal(
decoded_value, value, "value=%lu decoded_value=%lu\n",
(unsigned long)value, (unsigned long)decoded_value); (unsigned long)value, (unsigned long)decoded_value);
encode_application_unsigned(&encoded_array[0], decoded_value); encode_application_unsigned(&encoded_array[0], decoded_value);
zassert_equal(memcmp(&array[0], &encoded_array[0], sizeof(array)), 0, NULL); zassert_equal(memcmp(&array[0], &encoded_array[0], sizeof(array)), 0, NULL);
@@ -619,8 +621,9 @@ static void testBACnetUnsigned(void)
zassert_equal(value, test_value, NULL); zassert_equal(value, test_value, NULL);
#endif #endif
null_len = bacnet_unsigned_decode(apdu, apdu_len, len_value, NULL); null_len = bacnet_unsigned_decode(apdu, apdu_len, len_value, NULL);
zassert_equal(apdu_len, null_len, "apdu_len=%d null_len=%d value=%u", zassert_equal(
apdu_len, null_len, value); apdu_len, null_len, "apdu_len=%d null_len=%d value=%u", apdu_len,
null_len, value);
test_len = test_len =
bacnet_unsigned_decode(apdu, apdu_len, len_value, &test_value); bacnet_unsigned_decode(apdu, apdu_len, len_value, &test_value);
zassert_equal(apdu_len, test_len, NULL); zassert_equal(apdu_len, test_len, NULL);
@@ -648,8 +651,9 @@ static void testBACDCodeSignedValue(int32_t value)
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
len = decode_signed(&apdu[len], len_value, &decoded_value); len = decode_signed(&apdu[len], len_value, &decoded_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_SIGNED_INT, NULL); zassert_equal(tag_number, BACNET_APPLICATION_TAG_SIGNED_INT, NULL);
zassert_equal(decoded_value, value, "value=%ld decoded_value=%ld\n", zassert_equal(
(long)value, (long)decoded_value); decoded_value, value, "value=%ld decoded_value=%ld\n", (long)value,
(long)decoded_value);
#endif #endif
len = encode_application_signed(&apdu[0], value); len = encode_application_signed(&apdu[0], value);
null_len = encode_application_signed(NULL, value); null_len = encode_application_signed(NULL, value);
@@ -670,9 +674,11 @@ static void testBACDCodeSignedValue(int32_t value)
zassert_false(tag.opening, NULL); zassert_false(tag.opening, NULL);
test_len = bacnet_signed_application_decode(apdu, len, &decoded_value); test_len = bacnet_signed_application_decode(apdu, len, &decoded_value);
null_len = bacnet_signed_application_decode(apdu, len, NULL); null_len = bacnet_signed_application_decode(apdu, len, NULL);
zassert_equal(null_len, len, "test_len=%d null_len=%d len=%d", test_len, zassert_equal(
null_len, len); null_len, len, "test_len=%d null_len=%d len=%d", test_len, null_len,
zassert_equal(decoded_value, value, "value=%ld decoded_value=%ld", value, len);
zassert_equal(
decoded_value, value, "value=%ld decoded_value=%ld", value,
decoded_value); decoded_value);
while (len) { while (len) {
len--; len--;
@@ -783,7 +789,8 @@ static void testBACDCodeOctetString(void)
zassert_equal(tag_number, BACNET_APPLICATION_TAG_OCTET_STRING, NULL); zassert_equal(tag_number, BACNET_APPLICATION_TAG_OCTET_STRING, NULL);
len += decode_octet_string(&apdu[len], len_value, &test_octet_string); len += decode_octet_string(&apdu[len], len_value, &test_octet_string);
zassert_equal(apdu_len, len, NULL); zassert_equal(apdu_len, len, NULL);
diff = memcmp(octetstring_value(&octet_string), &test_value[0], diff = memcmp(
octetstring_value(&octet_string), &test_value[0],
octetstring_length(&octet_string)); octetstring_length(&octet_string));
zassert_equal(diff, 0, NULL); zassert_equal(diff, 0, NULL);
#endif #endif
@@ -799,14 +806,16 @@ static void testBACDCodeOctetString(void)
zassert_equal(tag_number, BACNET_APPLICATION_TAG_OCTET_STRING, NULL); zassert_equal(tag_number, BACNET_APPLICATION_TAG_OCTET_STRING, NULL);
len += decode_octet_string(&apdu[len], len_value, &test_octet_string); len += decode_octet_string(&apdu[len], len_value, &test_octet_string);
zassert_equal(apdu_len, len, "test octet string=#%d\n", i); zassert_equal(apdu_len, len, "test octet string=#%d\n", i);
diff = memcmp(octetstring_value(&octet_string), &test_value[0], diff = memcmp(
octetstring_value(&octet_string), &test_value[0],
octetstring_length(&octet_string)); octetstring_length(&octet_string));
zassert_equal(diff, 0, "test octet string=#%d\n", i); zassert_equal(diff, 0, "test octet string=#%d\n", i);
#endif #endif
test_len = bacnet_octet_string_application_decode( test_len = bacnet_octet_string_application_decode(
apdu, apdu_len, &test_octet_string); apdu, apdu_len, &test_octet_string);
zassert_equal(apdu_len, test_len, "apdu_len=%d test_len=%d i=%d", zassert_equal(
apdu_len, test_len, i); apdu_len, test_len, "apdu_len=%d test_len=%d i=%d", apdu_len,
test_len, i);
zassert_true( zassert_true(
octetstring_value_same(&octet_string, &test_octet_string), NULL); octetstring_value_same(&octet_string, &test_octet_string), NULL);
} }
@@ -843,7 +852,8 @@ static void testBACDCodeCharacterString(void)
zassert_equal(tag_number, BACNET_APPLICATION_TAG_CHARACTER_STRING, NULL); zassert_equal(tag_number, BACNET_APPLICATION_TAG_CHARACTER_STRING, NULL);
len += decode_character_string(&apdu[len], len_value, &test_char_string); len += decode_character_string(&apdu[len], len_value, &test_char_string);
zassert_equal(apdu_len, len, NULL); zassert_equal(apdu_len, len, NULL);
diff = memcmp(characterstring_value(&char_string), &test_value[0], diff = memcmp(
characterstring_value(&char_string), &test_value[0],
characterstring_length(&char_string)); characterstring_length(&char_string));
zassert_equal(diff, 0, NULL); zassert_equal(diff, 0, NULL);
#endif #endif
@@ -871,7 +881,8 @@ static void testBACDCodeCharacterString(void)
printf("test string=#%d apdu_len=%d len=%d\n", i, apdu_len, len); printf("test string=#%d apdu_len=%d len=%d\n", i, apdu_len, len);
} }
zassert_equal(apdu_len, len, NULL); zassert_equal(apdu_len, len, NULL);
diff = memcmp(characterstring_value(&char_string), &test_value[0], diff = memcmp(
characterstring_value(&char_string), &test_value[0],
characterstring_length(&char_string)); characterstring_length(&char_string));
if (diff) { if (diff) {
printf("test string=#%d\n", i); printf("test string=#%d\n", i);
@@ -926,14 +937,16 @@ static void testBACDCodeObject(void)
len = encode_context_object_id( len = encode_context_object_id(
&encoded_apdu[0], tag_number, type, instance); &encoded_apdu[0], tag_number, type, instance);
zassert_true(len > 0, NULL); zassert_true(len > 0, NULL);
len = bacnet_object_id_context_decode(&encoded_apdu[0], len, len = bacnet_object_id_context_decode(
tag_number, &decoded_type, &decoded_instance); &encoded_apdu[0], len, tag_number, &decoded_type,
&decoded_instance);
zassert_true(len > 0, NULL); zassert_true(len > 0, NULL);
zassert_equal(decoded_type, type, NULL); zassert_equal(decoded_type, type, NULL);
zassert_equal(decoded_instance, instance, NULL); zassert_equal(decoded_instance, instance, NULL);
tag_number = 100; tag_number = 100;
len = bacnet_object_id_context_decode(&encoded_apdu[0], len, len = bacnet_object_id_context_decode(
tag_number, &decoded_type, &decoded_instance); &encoded_apdu[0], len, tag_number, &decoded_type,
&decoded_instance);
zassert_equal(len, 0, NULL); zassert_equal(len, 0, NULL);
} }
} }
@@ -946,8 +959,9 @@ static void testBACDCodeObject(void)
zassert_true(len > 0, NULL); zassert_true(len > 0, NULL);
null_len = encode_context_object_id(NULL, tag_number, type, instance); null_len = encode_context_object_id(NULL, tag_number, type, instance);
zassert_equal(len, null_len, NULL); zassert_equal(len, null_len, NULL);
len = bacnet_object_id_context_decode(&encoded_apdu[0], null_len, len = bacnet_object_id_context_decode(
tag_number, &decoded_type, &decoded_instance); &encoded_apdu[0], null_len, tag_number, &decoded_type,
&decoded_instance);
zassert_true(len > 0, NULL); zassert_true(len > 0, NULL);
zassert_equal(decoded_type, type, NULL); zassert_equal(decoded_type, type, NULL);
zassert_equal(decoded_instance, instance, NULL); zassert_equal(decoded_instance, instance, NULL);
@@ -1043,8 +1057,8 @@ static void testBACDCodeBitString(void)
} }
} }
static void test_unsigned_context_codec( static void
BACNET_UNSIGNED_INTEGER value, uint8_t context_tag) test_unsigned_context_codec(BACNET_UNSIGNED_INTEGER value, uint8_t context_tag)
{ {
uint8_t apdu[MAX_APDU] = { 0 }; uint8_t apdu[MAX_APDU] = { 0 };
int len = 0, test_len = 0, null_len = 0, match_len = 0; int len = 0, test_len = 0, null_len = 0, match_len = 0;
@@ -1721,8 +1735,9 @@ static void test_bacnet_array_encode(void)
BACNET_TAG tag = { 0 }; BACNET_TAG tag = { 0 };
/* element zero returns the apdu size */ /* element zero returns the apdu size */
apdu_len = bacnet_array_encode(object_instance, apdu_index, apdu_len = bacnet_array_encode(
bacnet_apdu_property_element_encode, apdu_size, apdu, sizeof(apdu)); object_instance, apdu_index, bacnet_apdu_property_element_encode,
apdu_size, apdu, sizeof(apdu));
zassert_true(apdu_len > 0, NULL); zassert_true(apdu_len > 0, NULL);
len = bacnet_tag_decode(apdu, apdu_len, &tag); len = bacnet_tag_decode(apdu, apdu_len, &tag);
zassert_true(len > 0, NULL); zassert_true(len > 0, NULL);
@@ -1731,34 +1746,40 @@ static void test_bacnet_array_encode(void)
&apdu[len], apdu_len - len, tag.len_value_type, &decoded_value); &apdu[len], apdu_len - len, tag.len_value_type, &decoded_value);
zassert_equal(decoded_value, apdu_size, NULL); zassert_equal(decoded_value, apdu_size, NULL);
/* element zero - APDU too small */ /* element zero - APDU too small */
apdu_len = bacnet_array_encode(object_instance, apdu_index, apdu_len = bacnet_array_encode(
bacnet_apdu_property_element_encode, apdu_size, apdu, 1); object_instance, apdu_index, bacnet_apdu_property_element_encode,
apdu_size, apdu, 1);
zassert_true(apdu_len == BACNET_STATUS_ABORT, NULL); zassert_true(apdu_len == BACNET_STATUS_ABORT, NULL);
/* element 1 returns the first element */ /* element 1 returns the first element */
apdu_index = 1; apdu_index = 1;
apdu_len = bacnet_array_encode(object_instance, apdu_index, apdu_len = bacnet_array_encode(
bacnet_apdu_property_element_encode, apdu_size, apdu, sizeof(apdu)); object_instance, apdu_index, bacnet_apdu_property_element_encode,
apdu_size, apdu, sizeof(apdu));
zassert_true(apdu_len > 0, NULL); zassert_true(apdu_len > 0, NULL);
len = decode_tag_number_and_value(apdu, &tag_number, &len_value); len = decode_tag_number_and_value(apdu, &tag_number, &len_value);
zassert_true(len > 0, NULL); zassert_true(len > 0, NULL);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_OBJECT_ID, NULL); zassert_equal(tag_number, BACNET_APPLICATION_TAG_OBJECT_ID, NULL);
/* element 1 - APDU too small */ /* element 1 - APDU too small */
apdu_len = bacnet_array_encode(object_instance, apdu_index, apdu_len = bacnet_array_encode(
bacnet_apdu_property_element_encode, apdu_size, apdu, 1); object_instance, apdu_index, bacnet_apdu_property_element_encode,
apdu_size, apdu, 1);
zassert_true(apdu_len == BACNET_STATUS_ABORT, NULL); zassert_true(apdu_len == BACNET_STATUS_ABORT, NULL);
/* element 2, in this test case, returns an error */ /* element 2, in this test case, returns an error */
apdu_index = 2; apdu_index = 2;
apdu_len = bacnet_array_encode(object_instance, apdu_index, apdu_len = bacnet_array_encode(
bacnet_apdu_property_element_encode, apdu_size, apdu, sizeof(apdu)); object_instance, apdu_index, bacnet_apdu_property_element_encode,
apdu_size, apdu, sizeof(apdu));
zassert_true(apdu_len < 0, NULL); zassert_true(apdu_len < 0, NULL);
/* ALL - fits in APDU */ /* ALL - fits in APDU */
apdu_index = BACNET_ARRAY_ALL; apdu_index = BACNET_ARRAY_ALL;
apdu_len = bacnet_array_encode(object_instance, apdu_index, apdu_len = bacnet_array_encode(
bacnet_apdu_property_element_encode, apdu_size, apdu, sizeof(apdu)); object_instance, apdu_index, bacnet_apdu_property_element_encode,
apdu_size, apdu, sizeof(apdu));
zassert_true(apdu_len == 5, "len=%d", apdu_len); zassert_true(apdu_len == 5, "len=%d", apdu_len);
/* ALL - APDU too small */ /* ALL - APDU too small */
apdu_len = bacnet_array_encode(object_instance, apdu_index, apdu_len = bacnet_array_encode(
bacnet_apdu_property_element_encode, apdu_size, apdu, 4); object_instance, apdu_index, bacnet_apdu_property_element_encode,
apdu_size, apdu, 4);
zassert_true(apdu_len == BACNET_STATUS_ABORT, NULL); zassert_true(apdu_len == BACNET_STATUS_ABORT, NULL);
} }
@@ -1771,7 +1792,8 @@ ZTEST_SUITE(bacdcode_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(bacdcode_tests, ztest_unit_test(testBACnetTagCodec), ztest_test_suite(
bacdcode_tests, ztest_unit_test(testBACnetTagCodec),
ztest_unit_test(testBACDCodeTags), ztest_unit_test(testBACDCodeReal), ztest_unit_test(testBACDCodeTags), ztest_unit_test(testBACDCodeReal),
ztest_unit_test(testBACDCodeUnsigned), ztest_unit_test(testBACDCodeUnsigned),
ztest_unit_test(testBACnetUnsigned), ztest_unit_test(testBACnetUnsigned),
+32 -43
View File
@@ -22,9 +22,8 @@
/** /**
* @brief Test * @brief Test
*/ */
static void testBACnetRecipientData( static void
BACNET_RECIPIENT *data1, testBACnetRecipientData(BACNET_RECIPIENT *data1, BACNET_RECIPIENT *data2)
BACNET_RECIPIENT *data2)
{ {
unsigned i = 0; unsigned i = 0;
@@ -34,32 +33,30 @@ static void testBACnetRecipientData(
zassert_equal( zassert_equal(
data1->type.device.type, data2->type.device.type, NULL); data1->type.device.type, data2->type.device.type, NULL);
zassert_equal( zassert_equal(
data1->type.device.instance, data1->type.device.instance, data2->type.device.instance, NULL);
data2->type.device.instance, NULL);
} else if (data1->tag == BACNET_RECIPIENT_TAG_ADDRESS) { } else if (data1->tag == BACNET_RECIPIENT_TAG_ADDRESS) {
zassert_equal( zassert_equal(
data1->type.address.net, data2->type.address.net, NULL); data1->type.address.net, data2->type.address.net, NULL);
if (data1->type.address.net == BACNET_BROADCAST_NETWORK) { if (data1->type.address.net == BACNET_BROADCAST_NETWORK) {
zassert_equal( zassert_equal(
data1->type.address.mac_len, data1->type.address.mac_len, data2->type.address.mac_len,
data2->type.address.mac_len, NULL); NULL);
} else if (data1->type.address.net) { } else if (data1->type.address.net) {
zassert_equal( zassert_equal(
data1->type.address.len, data1->type.address.len, data2->type.address.len, NULL);
data2->type.address.len, NULL);
for (i = 0; i < data1->type.address.len; i++) { for (i = 0; i < data1->type.address.len; i++) {
zassert_equal( zassert_equal(
data1->type.address.adr[i], data1->type.address.adr[i], data2->type.address.adr[i],
data2->type.address.adr[i], NULL); NULL);
} }
} else { } else {
zassert_equal( zassert_equal(
data1->type.address.mac_len, data1->type.address.mac_len, data2->type.address.mac_len,
data2->type.address.mac_len, NULL); NULL);
for (i = 0; i < data1->type.address.mac_len; i++) { for (i = 0; i < data1->type.address.mac_len; i++) {
zassert_equal( zassert_equal(
data1->type.address.mac[i], data1->type.address.mac[i], data2->type.address.mac[i],
data2->type.address.mac[i], NULL); NULL);
} }
} }
} else { } else {
@@ -82,34 +79,28 @@ static void testBACnetDestination(void)
null_len = bacnet_destination_encode(NULL, &destination); null_len = bacnet_destination_encode(NULL, &destination);
apdu_len = bacnet_destination_encode(apdu, &destination); apdu_len = bacnet_destination_encode(apdu, &destination);
zassert_equal(apdu_len, null_len, NULL); zassert_equal(apdu_len, null_len, NULL);
test_len = bacnet_destination_decode(apdu, apdu_len, test_len = bacnet_destination_decode(apdu, apdu_len, &test_destination);
&test_destination);
zassert_equal(apdu_len, test_len, NULL); zassert_equal(apdu_len, test_len, NULL);
destination.Recipient.tag = BACNET_RECIPIENT_TAG_ADDRESS; destination.Recipient.tag = BACNET_RECIPIENT_TAG_ADDRESS;
null_len = bacnet_destination_encode(NULL, &destination); null_len = bacnet_destination_encode(NULL, &destination);
apdu_len = bacnet_destination_encode(apdu, &destination); apdu_len = bacnet_destination_encode(apdu, &destination);
zassert_equal(apdu_len, null_len, NULL); zassert_equal(apdu_len, null_len, NULL);
test_len = bacnet_destination_decode(apdu, apdu_len, test_len = bacnet_destination_decode(apdu, apdu_len, &test_destination);
&test_destination);
zassert_equal(test_len, apdu_len, NULL); zassert_equal(test_len, apdu_len, NULL);
null_len = bacnet_destination_encode(NULL, &destination); null_len = bacnet_destination_encode(NULL, &destination);
apdu_len = bacnet_destination_encode(apdu, &destination); apdu_len = bacnet_destination_encode(apdu, &destination);
zassert_equal(apdu_len, null_len, NULL); zassert_equal(apdu_len, null_len, NULL);
test_len = bacnet_destination_decode(apdu, apdu_len, test_len = bacnet_destination_decode(apdu, apdu_len, &test_destination);
&test_destination);
zassert_equal(test_len, apdu_len, NULL); zassert_equal(test_len, apdu_len, NULL);
/* decoding, some negative tests */ /* decoding, some negative tests */
test_len = bacnet_destination_decode(NULL, apdu_len, test_len = bacnet_destination_decode(NULL, apdu_len, &test_destination);
&test_destination);
zassert_equal(test_len, BACNET_STATUS_REJECT, NULL); zassert_equal(test_len, BACNET_STATUS_REJECT, NULL);
test_len = bacnet_destination_decode(apdu, 0, test_len = bacnet_destination_decode(apdu, 0, &test_destination);
&test_destination);
zassert_equal(test_len, BACNET_STATUS_REJECT, NULL); zassert_equal(test_len, BACNET_STATUS_REJECT, NULL);
test_len = bacnet_destination_decode(apdu, apdu_len, test_len = bacnet_destination_decode(apdu, apdu_len, NULL);
NULL);
zassert_equal(test_len, BACNET_STATUS_REJECT, NULL); zassert_equal(test_len, BACNET_STATUS_REJECT, NULL);
} }
/** /**
@@ -117,8 +108,8 @@ static void testBACnetDestination(void)
*/ */
/** /**
* Unit Test for ASCII conversion * Unit Test for ASCII conversion
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST(bacnet_destination_tests, test_BACnetDestination_ASCII) ZTEST(bacnet_destination_tests, test_BACnetDestination_ASCII)
#else #else
@@ -128,13 +119,13 @@ static void test_BACnetDestination_ASCII(void)
BACNET_DESTINATION destination = { 0 }, test_destination = { 0 }; BACNET_DESTINATION destination = { 0 }, test_destination = { 0 };
int len = 0, test_len = 0; int len = 0, test_len = 0;
const char *ascii = "(" const char *ascii = "("
"ValidDays=[1,2,3,4,5,6,7];" "ValidDays=[1,2,3,4,5,6,7];"
"FromTime=0:00:00.0;ToTime=23:59:59.99;" "FromTime=0:00:00.0;ToTime=23:59:59.99;"
"Recipient=Device(type=8,instance=4194303);" "Recipient=Device(type=8,instance=4194303);"
"ProcessIdentifier=0;" "ProcessIdentifier=0;"
"ConfirmedNotify=false;" "ConfirmedNotify=false;"
"Transitions=[]" "Transitions=[]"
")"; ")";
bool status = false; bool status = false;
char *test_ascii = NULL; char *test_ascii = NULL;
@@ -148,13 +139,12 @@ static void test_BACnetDestination_ASCII(void)
if (len > 0) { if (len > 0) {
test_ascii = calloc(len, 1); test_ascii = calloc(len, 1);
if (test_ascii) { if (test_ascii) {
test_len = bacnet_destination_to_ascii( test_len =
&test_destination, test_ascii, len); bacnet_destination_to_ascii(&test_destination, test_ascii, len);
zassert_equal(len, test_len, NULL); zassert_equal(len, test_len, NULL);
free(test_ascii); free(test_ascii);
} }
} }
} }
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
@@ -162,10 +152,9 @@ ZTEST_SUITE(bacnet_destination_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(bacnet_destination_tests, ztest_test_suite(
ztest_unit_test(testBACnetDestination), bacnet_destination_tests, ztest_unit_test(testBACnetDestination),
ztest_unit_test(test_BACnetDestination_ASCII) ztest_unit_test(test_BACnetDestination_ASCII));
);
ztest_run_test_suite(bacnet_destination_tests); ztest_run_test_suite(bacnet_destination_tests);
} }
+18 -11
View File
@@ -43,8 +43,9 @@ static void testDevObjPropRef(BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE *data)
bacnet_device_object_property_reference_decode(apdu, len, &test_data); bacnet_device_object_property_reference_decode(apdu, len, &test_data);
zassert_equal(null_len, len, "null_len=%d len=%d", null_len, len); zassert_equal(null_len, len, "null_len=%d len=%d", null_len, len);
zassert_equal(test_len, len, "test_len=%d len=%d", test_len, len); zassert_equal(test_len, len, "test_len=%d len=%d", test_len, len);
zassert_equal(data->objectIdentifier.instance, zassert_equal(
test_data.objectIdentifier.instance, NULL); data->objectIdentifier.instance, test_data.objectIdentifier.instance,
NULL);
zassert_equal( zassert_equal(
data->objectIdentifier.type, test_data.objectIdentifier.type, NULL); data->objectIdentifier.type, test_data.objectIdentifier.type, NULL);
zassert_equal(data->propertyIdentifier, test_data.propertyIdentifier, NULL); zassert_equal(data->propertyIdentifier, test_data.propertyIdentifier, NULL);
@@ -54,7 +55,8 @@ static void testDevObjPropRef(BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE *data)
zassert_equal(test_data.arrayIndex, BACNET_ARRAY_ALL, NULL); zassert_equal(test_data.arrayIndex, BACNET_ARRAY_ALL, NULL);
} }
if (data->deviceIdentifier.type == OBJECT_DEVICE) { if (data->deviceIdentifier.type == OBJECT_DEVICE) {
zassert_equal(data->deviceIdentifier.instance, zassert_equal(
data->deviceIdentifier.instance,
test_data.deviceIdentifier.instance, NULL); test_data.deviceIdentifier.instance, NULL);
zassert_equal( zassert_equal(
data->deviceIdentifier.type, test_data.deviceIdentifier.type, NULL); data->deviceIdentifier.type, test_data.deviceIdentifier.type, NULL);
@@ -69,7 +71,8 @@ static void testDevObjPropRef(BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE *data)
apdu, len, &test_data); apdu, len, &test_data);
if ((len > 0) && (test_data.arrayIndex == BACNET_ARRAY_ALL)) { if ((len > 0) && (test_data.arrayIndex == BACNET_ARRAY_ALL)) {
/* special case when optional portion is exactly missing */ /* special case when optional portion is exactly missing */
} else if ((len > 0) && } else if (
(len > 0) &&
(test_data.deviceIdentifier.type == BACNET_NO_DEV_TYPE)) { (test_data.deviceIdentifier.type == BACNET_NO_DEV_TYPE)) {
/* special case when optional portion is exactly missing */ /* special case when optional portion is exactly missing */
} else { } else {
@@ -145,8 +148,9 @@ static void testDevIdRef(void)
zassert_equal(test_len, len, NULL); zassert_equal(test_len, len, NULL);
null_len = bacnet_device_object_reference_decode(apdu, len, NULL); null_len = bacnet_device_object_reference_decode(apdu, len, NULL);
zassert_equal(test_len, null_len, NULL); zassert_equal(test_len, null_len, NULL);
zassert_equal(data.deviceIdentifier.instance, zassert_equal(
test_data.deviceIdentifier.instance, NULL); data.deviceIdentifier.instance, test_data.deviceIdentifier.instance,
NULL);
zassert_equal( zassert_equal(
data.deviceIdentifier.type, test_data.deviceIdentifier.type, NULL); data.deviceIdentifier.type, test_data.deviceIdentifier.type, NULL);
while (--len) { while (--len) {
@@ -183,8 +187,9 @@ static void testObjPropRef(void)
zassert_equal(test_len, len, NULL); zassert_equal(test_len, len, NULL);
zassert_equal( zassert_equal(
data.object_identifier.type, test_data.object_identifier.type, NULL); data.object_identifier.type, test_data.object_identifier.type, NULL);
zassert_equal(data.object_identifier.instance, zassert_equal(
test_data.object_identifier.instance, NULL); data.object_identifier.instance, test_data.object_identifier.instance,
NULL);
zassert_equal( zassert_equal(
data.property_identifier, test_data.property_identifier, NULL); data.property_identifier, test_data.property_identifier, NULL);
zassert_equal( zassert_equal(
@@ -202,8 +207,9 @@ static void testObjPropRef(void)
zassert_equal(test_len, len, "len=%d test_len=%d", len, test_len); zassert_equal(test_len, len, "len=%d test_len=%d", len, test_len);
zassert_equal( zassert_equal(
data.object_identifier.type, test_data.object_identifier.type, NULL); data.object_identifier.type, test_data.object_identifier.type, NULL);
zassert_equal(data.object_identifier.instance, zassert_equal(
test_data.object_identifier.instance, NULL); data.object_identifier.instance, test_data.object_identifier.instance,
NULL);
zassert_equal( zassert_equal(
data.property_identifier, test_data.property_identifier, NULL); data.property_identifier, test_data.property_identifier, NULL);
zassert_equal( zassert_equal(
@@ -227,7 +233,8 @@ ZTEST_SUITE(bacdevobjpropref_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(bacdevobjpropref_tests, ztest_unit_test(testDevIdPropRef), ztest_test_suite(
bacdevobjpropref_tests, ztest_unit_test(testDevIdPropRef),
ztest_unit_test(testDevIdRef), ztest_unit_test(testObjPropRef)); ztest_unit_test(testDevIdRef), ztest_unit_test(testObjPropRef));
ztest_run_test_suite(bacdevobjpropref_tests); ztest_run_test_suite(bacdevobjpropref_tests);
+23 -17
View File
@@ -17,7 +17,8 @@
* @{ * @{
*/ */
static int bacerror_decode_apdu(uint8_t *apdu, static int bacerror_decode_apdu(
uint8_t *apdu,
unsigned apdu_size, unsigned apdu_size,
uint8_t *invoke_id, uint8_t *invoke_id,
BACNET_CONFIRMED_SERVICE *service, BACNET_CONFIRMED_SERVICE *service,
@@ -31,8 +32,9 @@ static int bacerror_decode_apdu(uint8_t *apdu,
return BACNET_STATUS_ERROR; return BACNET_STATUS_ERROR;
} }
apdu_len = 1; apdu_len = 1;
apdu_len = bacerror_decode_service_request(&apdu[apdu_len], apdu_len = bacerror_decode_service_request(
apdu_size - apdu_len, invoke_id, service, error_class, error_code); &apdu[apdu_len], apdu_size - apdu_len, invoke_id, service,
error_class, error_code);
} }
return apdu_len; return apdu_len;
@@ -67,8 +69,9 @@ static void testBACError(void)
apdu_len = len; apdu_len = len;
null_len = bacerror_decode_apdu(&apdu[0], apdu_len, NULL, NULL, NULL, NULL); null_len = bacerror_decode_apdu(&apdu[0], apdu_len, NULL, NULL, NULL, NULL);
len = bacerror_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, len = bacerror_decode_apdu(
&test_service, &test_error_class, &test_error_code); &apdu[0], apdu_len, &test_invoke_id, &test_service, &test_error_class,
&test_error_code);
zassert_not_equal(len, BACNET_STATUS_ERROR, "len=%d", len); zassert_not_equal(len, BACNET_STATUS_ERROR, "len=%d", len);
zassert_equal(len, null_len, NULL); zassert_equal(len, null_len, NULL);
zassert_equal(test_invoke_id, invoke_id, NULL); zassert_equal(test_invoke_id, invoke_id, NULL);
@@ -79,22 +82,24 @@ static void testBACError(void)
/* test too short lengths */ /* test too short lengths */
while (len) { while (len) {
len--; len--;
test_len = test_len = bacerror_decode_apdu(
bacerror_decode_apdu(&apdu[0], len, &test_invoke_id, &apdu[0], len, &test_invoke_id, &test_service, &test_error_class,
&test_service, &test_error_class, &test_error_code); &test_error_code);
zassert_equal( zassert_equal(
test_len, BACNET_STATUS_ERROR, "len=%d test_len=%d", len, test_len); test_len, BACNET_STATUS_ERROR, "len=%d test_len=%d", len, test_len);
} }
/* change type to get negative response */ /* change type to get negative response */
apdu[0] = PDU_TYPE_ABORT; apdu[0] = PDU_TYPE_ABORT;
len = bacerror_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, len = bacerror_decode_apdu(
&test_service, &test_error_class, &test_error_code); &apdu[0], apdu_len, &test_invoke_id, &test_service, &test_error_class,
&test_error_code);
zassert_true(len <= 0, NULL); zassert_true(len <= 0, NULL);
/* test NULL APDU */ /* test NULL APDU */
len = bacerror_decode_apdu(NULL, apdu_len, &test_invoke_id, len = bacerror_decode_apdu(
&test_service, &test_error_class, &test_error_code); NULL, apdu_len, &test_invoke_id, &test_service, &test_error_class,
&test_error_code);
zassert_true(len <= 0, NULL); zassert_true(len <= 0, NULL);
/* check them all... */ /* check them all... */
@@ -107,9 +112,9 @@ static void testBACError(void)
&apdu[0], invoke_id, service, error_class, error_code); &apdu[0], invoke_id, service, error_class, error_code);
apdu_len = len; apdu_len = len;
zassert_not_equal(len, 0, NULL); zassert_not_equal(len, 0, NULL);
len = bacerror_decode_apdu(&apdu[0], apdu_len, len = bacerror_decode_apdu(
&test_invoke_id, &test_service, &test_error_class, &apdu[0], apdu_len, &test_invoke_id, &test_service,
&test_error_code); &test_error_class, &test_error_code);
zassert_not_equal(len, -1, NULL); zassert_not_equal(len, -1, NULL);
zassert_equal(test_invoke_id, invoke_id, NULL); zassert_equal(test_invoke_id, invoke_id, NULL);
zassert_equal(test_service, service, NULL); zassert_equal(test_service, service, NULL);
@@ -127,8 +132,9 @@ static void testBACError(void)
&apdu[0], invoke_id, service, error_class, error_code); &apdu[0], invoke_id, service, error_class, error_code);
apdu_len = len; apdu_len = len;
zassert_not_equal(len, 0, NULL); zassert_not_equal(len, 0, NULL);
len = bacerror_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, len = bacerror_decode_apdu(
&test_service, &test_error_class, &test_error_code); &apdu[0], apdu_len, &test_invoke_id, &test_service, &test_error_class,
&test_error_code);
zassert_not_equal(len, BACNET_STATUS_ERROR, NULL); zassert_not_equal(len, BACNET_STATUS_ERROR, NULL);
zassert_equal(test_invoke_id, invoke_id, NULL); zassert_equal(test_invoke_id, invoke_id, NULL);
zassert_equal(test_service, service, NULL); zassert_equal(test_service, service, NULL);
+22 -25
View File
@@ -37,15 +37,15 @@ static void testBACnetUnsigned16(void)
memset(apdu, -1, sizeof(apdu)); memset(apdu, -1, sizeof(apdu));
len = encode_unsigned16(&apdu[0], value); len = encode_unsigned16(&apdu[0], value);
zassert_equal(len, 2, NULL); zassert_equal(len, 2, NULL);
test_value = (uint16_t) ~0U; test_value = (uint16_t)~0U;
len = decode_unsigned16(&apdu[0], &test_value); len = decode_unsigned16(&apdu[0], &test_value);
zassert_equal(len, 2, NULL); zassert_equal(len, 2, NULL);
zassert_equal(value, test_value, NULL); zassert_equal(value, test_value, NULL);
for (value = 1; value != 0; value = (value << 1) & ((1UL<<16)-1)) { for (value = 1; value != 0; value = (value << 1) & ((1UL << 16) - 1)) {
len = encode_unsigned16(&apdu[0], value); len = encode_unsigned16(&apdu[0], value);
zassert_equal(len, 2, NULL); zassert_equal(len, 2, NULL);
test_value = (uint16_t) ~0U; test_value = (uint16_t)~0U;
len = decode_unsigned16(&apdu[0], &test_value); len = decode_unsigned16(&apdu[0], &test_value);
zassert_equal(value, test_value, NULL); zassert_equal(value, test_value, NULL);
} }
@@ -77,7 +77,7 @@ static void testBACnetUnsigned24(void)
zassert_equal(len, 3, NULL); zassert_equal(len, 3, NULL);
zassert_equal(value, test_value, NULL); zassert_equal(value, test_value, NULL);
for (value = 1; value != 0; value = (value << 1) & ((1UL<<24)-1)) { for (value = 1; value != 0; value = (value << 1) & ((1UL << 24) - 1)) {
len = encode_unsigned24(&apdu[0], value); len = encode_unsigned24(&apdu[0], value);
zassert_equal(len, 3, NULL); zassert_equal(len, 3, NULL);
test_value = ~0U; test_value = ~0U;
@@ -148,7 +148,7 @@ static void testBACnetUnsigned40(void)
zassert_equal(len, 5, NULL); zassert_equal(len, 5, NULL);
zassert_equal(value, test_value, NULL); zassert_equal(value, test_value, NULL);
for (value = 1; value != 0; value = (value << 1) & ((1ULL<<40)-1)) { for (value = 1; value != 0; value = (value << 1) & ((1ULL << 40) - 1)) {
len = encode_unsigned40(&apdu[0], value); len = encode_unsigned40(&apdu[0], value);
zassert_equal(len, 5, NULL); zassert_equal(len, 5, NULL);
test_value = ~0ULL; test_value = ~0ULL;
@@ -189,7 +189,7 @@ static void testBACnetUnsigned48(void)
zassert_equal(len, 6, NULL); zassert_equal(len, 6, NULL);
zassert_equal(value, test_value, NULL); zassert_equal(value, test_value, NULL);
for (value = 1; value != 0; value = (value << 1) & ((1ULL<<48)-1)) { for (value = 1; value != 0; value = (value << 1) & ((1ULL << 48) - 1)) {
len = encode_unsigned48(&apdu[0], value); len = encode_unsigned48(&apdu[0], value);
zassert_equal(len, 6, NULL); zassert_equal(len, 6, NULL);
test_value = ~0ULL; test_value = ~0ULL;
@@ -230,7 +230,7 @@ static void testBACnetUnsigned56(void)
zassert_equal(len, 7, NULL); zassert_equal(len, 7, NULL);
zassert_equal(value, test_value, NULL); zassert_equal(value, test_value, NULL);
for (value = 1; value != 0; value = (value << 1) & ((1ULL<<56)-1)) { for (value = 1; value != 0; value = (value << 1) & ((1ULL << 56) - 1)) {
len = encode_unsigned56(&apdu[0], value); len = encode_unsigned56(&apdu[0], value);
zassert_equal(len, 7, NULL); zassert_equal(len, 7, NULL);
test_value = ~0ULL; test_value = ~0ULL;
@@ -299,9 +299,9 @@ static void testBACnetUnsignedLength(void)
int bits = (8 * sizeof(BACNET_UNSIGNED_INTEGER)); int bits = (8 * sizeof(BACNET_UNSIGNED_INTEGER));
for (value = ~value; value > 0; value >>= 1) { for (value = ~value; value > 0; value >>= 1) {
len = bacnet_unsigned_length(value); len = bacnet_unsigned_length(value);
zassert_equal(len, (bits + 7)/8, NULL); zassert_equal(len, (bits + 7) / 8, NULL);
bits -= 1; bits -= 1;
} }
len = bacnet_unsigned_length(0); len = bacnet_unsigned_length(0);
zassert_equal(len, 1, NULL); zassert_equal(len, 1, NULL);
@@ -461,26 +461,23 @@ static void testBACnetSigned32(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(bacint_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(bacint_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(bacint_tests, ztest_test_suite(
ztest_unit_test(testBACnetUnsigned16), bacint_tests, ztest_unit_test(testBACnetUnsigned16),
ztest_unit_test(testBACnetUnsigned24), ztest_unit_test(testBACnetUnsigned24),
ztest_unit_test(testBACnetUnsigned32), ztest_unit_test(testBACnetUnsigned32),
ztest_unit_test(testBACnetUnsigned40), ztest_unit_test(testBACnetUnsigned40),
ztest_unit_test(testBACnetUnsigned48), ztest_unit_test(testBACnetUnsigned48),
ztest_unit_test(testBACnetUnsigned56), ztest_unit_test(testBACnetUnsigned56),
ztest_unit_test(testBACnetUnsigned64), ztest_unit_test(testBACnetUnsigned64),
ztest_unit_test(testBACnetUnsignedLength), ztest_unit_test(testBACnetUnsignedLength),
ztest_unit_test(testBACnetSigned8), ztest_unit_test(testBACnetSigned8), ztest_unit_test(testBACnetSigned16),
ztest_unit_test(testBACnetSigned16), ztest_unit_test(testBACnetSigned24),
ztest_unit_test(testBACnetSigned24), ztest_unit_test(testBACnetSigned32));
ztest_unit_test(testBACnetSigned32)
);
ztest_run_test_suite(bacint_tests); ztest_run_test_suite(bacint_tests);
} }
+1 -4
View File
@@ -25,7 +25,7 @@
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
@@ -37,12 +37,10 @@
static void test_setup(void) static void test_setup(void)
{ {
} }
static void test_cleanup(void) static void test_cleanup(void)
{ {
} }
void testBACreal(Test *pTest) void testBACreal(Test *pTest)
@@ -95,4 +93,3 @@ int main(void)
return 0; return 0;
} }
+3 -5
View File
@@ -60,16 +60,14 @@ static void testBACdouble(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(bacreal_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(bacreal_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(bacreal_tests, ztest_test_suite(
ztest_unit_test(testBACreal), bacreal_tests, ztest_unit_test(testBACreal),
ztest_unit_test(testBACdouble) ztest_unit_test(testBACdouble));
);
ztest_run_test_suite(bacreal_tests); ztest_run_test_suite(bacreal_tests);
} }
+24 -25
View File
@@ -69,7 +69,8 @@ static void testBitString(void)
/* Set the first bit of bit_string2 and the last bit of bit_string3 to /* Set the first bit of bit_string2 and the last bit of bit_string3 to
* be different */ * be different */
bitstring_set_bit(&bit_string2, 0, !bitstring_bit(&bit_string, 0)); bitstring_set_bit(&bit_string2, 0, !bitstring_bit(&bit_string, 0));
bitstring_set_bit(&bit_string3, max_bit - 1, bitstring_set_bit(
&bit_string3, max_bit - 1,
!bitstring_bit(&bit_string, max_bit - 1)); !bitstring_bit(&bit_string, max_bit - 1));
zassert_false(bitstring_same(&bit_string, &bit_string2), NULL); zassert_false(bitstring_same(&bit_string, &bit_string2), NULL);
zassert_false(bitstring_same(&bit_string, &bit_string3), NULL); zassert_false(bitstring_same(&bit_string, &bit_string3), NULL);
@@ -80,8 +81,8 @@ static void testBitString(void)
zassert_true(status, NULL); zassert_true(status, NULL);
status = bitstring_same(&bit_string, &bit_string2); status = bitstring_same(&bit_string, &bit_string2);
zassert_false(status, NULL); zassert_false(status, NULL);
zassert_equal(bitstring_bits_capacity(&bit_string), zassert_equal(
(MAX_BITSTRING_BYTES * 8), NULL); bitstring_bits_capacity(&bit_string), (MAX_BITSTRING_BYTES * 8), NULL);
} }
/** /**
@@ -107,10 +108,11 @@ static void testCharacterString(void)
status = characterstring_init(&bacnet_string, CHARACTER_ANSI_X34, NULL, 0); status = characterstring_init(&bacnet_string, CHARACTER_ANSI_X34, NULL, 0);
zassert_true(status, NULL); zassert_true(status, NULL);
zassert_equal(characterstring_length(&bacnet_string), 0, NULL); zassert_equal(characterstring_length(&bacnet_string), 0, NULL);
zassert_equal(characterstring_encoding(&bacnet_string), CHARACTER_ANSI_X34, zassert_equal(
NULL); characterstring_encoding(&bacnet_string), CHARACTER_ANSI_X34, NULL);
/* bounds check */ /* bounds check */
status = characterstring_init(&bacnet_string, CHARACTER_ANSI_X34, NULL, status = characterstring_init(
&bacnet_string, CHARACTER_ANSI_X34, NULL,
characterstring_capacity(&bacnet_string) + 1); characterstring_capacity(&bacnet_string) + 1);
zassert_false(status, NULL); zassert_false(status, NULL);
status = characterstring_truncate( status = characterstring_truncate(
@@ -173,10 +175,10 @@ static void testCharacterString(void)
status = characterstring_ansi_same(&bacnet_string, NULL); status = characterstring_ansi_same(&bacnet_string, NULL);
zassert_true(status, NULL); zassert_true(status, NULL);
/* alternate API for init and copy */ /* alternate API for init and copy */
status = characterstring_init_ansi_safe(&bacnet_string, value, status =
strlen(value)); characterstring_init_ansi_safe(&bacnet_string, value, strlen(value));
status = characterstring_ansi_copy(test_append_string, status = characterstring_ansi_copy(
sizeof(test_append_string), &bacnet_string); test_append_string, sizeof(test_append_string), &bacnet_string);
zassert_equal(strncmp(value, test_append_string, strlen(value)), 0, NULL); zassert_equal(strncmp(value, test_append_string, strlen(value)), 0, NULL);
} }
@@ -196,10 +198,10 @@ static void testOctetString(void)
uint8_t test_value_twin[MAX_APDU] = "PATRICIA"; uint8_t test_value_twin[MAX_APDU] = "PATRICIA";
uint8_t test_append_value[MAX_APDU] = " and the Kids"; uint8_t test_append_value[MAX_APDU] = " and the Kids";
uint8_t test_append_string[MAX_APDU] = ""; uint8_t test_append_string[MAX_APDU] = "";
const char * hex_value_valid = "1234567890ABCDEF"; const char *hex_value_valid = "1234567890ABCDEF";
const char * hex_value_skips = "12:34:56:78:90:AB:CD:EF"; const char *hex_value_skips = "12:34:56:78:90:AB:CD:EF";
const char * hex_value_odd = "1234567890ABCDE"; const char *hex_value_odd = "1234567890ABCDE";
char hex_value_long[MAX_APDU+MAX_APDU] = ""; char hex_value_long[MAX_APDU + MAX_APDU] = "";
bool status = false; bool status = false;
size_t length = 0; size_t length = 0;
size_t test_length = 0; size_t test_length = 0;
@@ -255,8 +257,8 @@ static void testOctetString(void)
status = octetstring_init(&bacnet_string, &test_value[0], test_length); status = octetstring_init(&bacnet_string, &test_value[0], test_length);
zassert_true(status, NULL); zassert_true(status, NULL);
test_length = strlen((char *)test_value_twin); test_length = strlen((char *)test_value_twin);
status = octetstring_init(&bacnet_string_twin, &test_value_twin[0], status =
test_length); octetstring_init(&bacnet_string_twin, &test_value_twin[0], test_length);
zassert_true(status, NULL); zassert_true(status, NULL);
status = octetstring_value_same(&bacnet_string, &bacnet_string_twin); status = octetstring_value_same(&bacnet_string, &bacnet_string_twin);
zassert_false(status, NULL); zassert_false(status, NULL);
@@ -268,7 +270,7 @@ static void testOctetString(void)
status = octetstring_value_same(NULL, NULL); status = octetstring_value_same(NULL, NULL);
zassert_false(status, NULL); zassert_false(status, NULL);
/* self-healing length too long */ /* self-healing length too long */
bacnet_string.length = MAX_OCTET_STRING_BYTES+1; bacnet_string.length = MAX_OCTET_STRING_BYTES + 1;
length = octetstring_length(&bacnet_string); length = octetstring_length(&bacnet_string);
zassert_equal(length, MAX_OCTET_STRING_BYTES, NULL); zassert_equal(length, MAX_OCTET_STRING_BYTES, NULL);
/* valid case - empty string */ /* valid case - empty string */
@@ -277,7 +279,7 @@ static void testOctetString(void)
/* valid case - valid hex string */ /* valid case - valid hex string */
status = octetstring_init_ascii_hex(&bacnet_string, hex_value_valid); status = octetstring_init_ascii_hex(&bacnet_string, hex_value_valid);
zassert_true(status, NULL); zassert_true(status, NULL);
test_length = strlen(hex_value_valid)/2; test_length = strlen(hex_value_valid) / 2;
length = octetstring_length(&bacnet_string); length = octetstring_length(&bacnet_string);
zassert_equal(length, test_length, NULL); zassert_equal(length, test_length, NULL);
/* valid case - with non-hex characters interspersed */ /* valid case - with non-hex characters interspersed */
@@ -290,7 +292,7 @@ static void testOctetString(void)
zassert_false(status, NULL); zassert_false(status, NULL);
/* invalid case - too long */ /* invalid case - too long */
memset(hex_value_long, 'F', sizeof(hex_value_long)); memset(hex_value_long, 'F', sizeof(hex_value_long));
hex_value_long[sizeof(hex_value_long)-1] = 0; hex_value_long[sizeof(hex_value_long) - 1] = 0;
status = octetstring_init_ascii_hex(&bacnet_string, hex_value_long); status = octetstring_init_ascii_hex(&bacnet_string, hex_value_long);
zassert_false(status, NULL); zassert_false(status, NULL);
/* invalid case - null arguments */ /* invalid case - null arguments */
@@ -305,17 +307,14 @@ static void testOctetString(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(bacstr_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(bacstr_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(bacstr_tests, ztest_test_suite(
ztest_unit_test(testBitString), bacstr_tests, ztest_unit_test(testBitString),
ztest_unit_test(testCharacterString), ztest_unit_test(testCharacterString), ztest_unit_test(testOctetString));
ztest_unit_test(testOctetString)
);
ztest_run_test_suite(bacstr_tests); ztest_run_test_suite(bacstr_tests);
} }
+14 -14
View File
@@ -18,7 +18,6 @@
#include "bacnet/datetime.h" #include "bacnet/datetime.h"
#include "bacnet/bacapp.h" #include "bacnet/bacapp.h"
/** /**
* @addtogroup bacnet_tests * @addtogroup bacnet_tests
* @{ * @{
@@ -43,23 +42,25 @@ static void test_BACnetTimeValue(BACNET_TIME_VALUE *value)
diff = datetime_compare_time(&test_value.Time, &value->Time); diff = datetime_compare_time(&test_value.Time, &value->Time);
zassert_true(diff == 0, NULL); zassert_true(diff == 0, NULL);
status = bacapp_same_value( status = bacapp_same_value(
(BACNET_APPLICATION_DATA_VALUE *) &test_value.Value, (BACNET_APPLICATION_DATA_VALUE *)&test_value.Value,
(BACNET_APPLICATION_DATA_VALUE *) &value->Value); (BACNET_APPLICATION_DATA_VALUE *)&value->Value);
zassert_true(status, NULL); zassert_true(status, NULL);
len = bacnet_time_value_context_encode(apdu, tag_number, value); len = bacnet_time_value_context_encode(apdu, tag_number, value);
apdu_len = bacnet_time_value_context_decode(apdu, len, tag_number, &test_value); apdu_len =
bacnet_time_value_context_decode(apdu, len, tag_number, &test_value);
zassert_true(len > 0, NULL); zassert_true(len > 0, NULL);
zassert_true(apdu_len > 0, NULL); zassert_true(apdu_len > 0, NULL);
diff = datetime_compare_time(&test_value.Time, &value->Time); diff = datetime_compare_time(&test_value.Time, &value->Time);
zassert_true(diff == 0, NULL); zassert_true(diff == 0, NULL);
status = bacapp_same_value( status = bacapp_same_value(
(BACNET_APPLICATION_DATA_VALUE *) &test_value.Value, (BACNET_APPLICATION_DATA_VALUE *)&test_value.Value,
(BACNET_APPLICATION_DATA_VALUE *) &value->Value); (BACNET_APPLICATION_DATA_VALUE *)&value->Value);
zassert_true(status, NULL); zassert_true(status, NULL);
/* negative testing */ /* negative testing */
tag_number++; tag_number++;
apdu_len = bacnet_time_value_context_decode(apdu, len, tag_number, &test_value); apdu_len =
bacnet_time_value_context_decode(apdu, len, tag_number, &test_value);
zassert_true(apdu_len < 0, NULL); zassert_true(apdu_len < 0, NULL);
} }
@@ -75,12 +76,12 @@ static void test_BACnetTimeValues(void)
BACNET_TIME_VALUE time_value = { 0 }; BACNET_TIME_VALUE time_value = { 0 };
test_BACnetTimeValue(&time_value); test_BACnetTimeValue(&time_value);
bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, "4.2", bacapp_parse_application_data(
&time_value.Value); BACNET_APPLICATION_TAG_REAL, "4.2", &time_value.Value);
datetime_time_init_ascii(&time_value.Time, "12:00"); datetime_time_init_ascii(&time_value.Time, "12:00");
test_BACnetTimeValue(&time_value); test_BACnetTimeValue(&time_value);
bacapp_parse_application_data(BACNET_APPLICATION_TAG_UNSIGNED_INT, "99999", bacapp_parse_application_data(
&time_value.Value); BACNET_APPLICATION_TAG_UNSIGNED_INT, "99999", &time_value.Value);
datetime_time_init_ascii(&time_value.Time, "23:59:59"); datetime_time_init_ascii(&time_value.Time, "23:59:59");
test_BACnetTimeValue(&time_value); test_BACnetTimeValue(&time_value);
} }
@@ -93,9 +94,8 @@ ZTEST_SUITE(BACnetTimeValue_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(BACnetTimeValue_tests, ztest_test_suite(
ztest_unit_test(test_BACnetTimeValues) BACnetTimeValue_tests, ztest_unit_test(test_BACnetTimeValues));
);
ztest_run_test_suite(BACnetTimeValue_tests); ztest_run_test_suite(BACnetTimeValue_tests);
} }
+21 -18
View File
@@ -97,7 +97,7 @@ int bip_send_mpdu(BACNET_IP_ADDRESS *dest, uint8_t *mtu, uint16_t mtu_len)
Test_Sent_Message_Length = message_length; Test_Sent_Message_Length = message_length;
bvlc_address_copy(&Test_Sent_Message_Dest, dest); bvlc_address_copy(&Test_Sent_Message_Dest, dest);
if ((header_len == 4) && (mtu_len >= 4)) { if ((header_len == 4) && (mtu_len >= 4)) {
memcpy(&Test_Sent_Message_Buffer[0], &mtu[4], mtu_len-4); memcpy(&Test_Sent_Message_Buffer[0], &mtu[4], mtu_len - 4);
Test_Sent_Message_Buffer_Length = mtu_len - 4; Test_Sent_Message_Buffer_Length = mtu_len - 4;
} else { } else {
Test_Sent_Message_Buffer_Length = 0; Test_Sent_Message_Buffer_Length = 0;
@@ -151,7 +151,6 @@ static void test_setup(void)
static void test_cleanup(void) static void test_cleanup(void)
{ {
} }
/** /**
@@ -159,13 +158,13 @@ static void test_cleanup(void)
*/ */
static void test_Initiate_Original_Broadcast_NPDU(Test *pTest) static void test_Initiate_Original_Broadcast_NPDU(Test *pTest)
{ {
uint8_t pdu[MAX_MPDU] = {0}; uint8_t pdu[MAX_MPDU] = { 0 };
int npdu_len = 0; int npdu_len = 0;
int apdu_len = 0; int apdu_len = 0;
int pdu_len = 0; int pdu_len = 0;
BACNET_ADDRESS dest = {0}; BACNET_ADDRESS dest = { 0 };
BACNET_NPDU_DATA npdu_data = {0}; BACNET_NPDU_DATA npdu_data = { 0 };
uint8_t test_pdu[MAX_MPDU] = {0}; uint8_t test_pdu[MAX_MPDU] = { 0 };
uint16_t test_pdu_len = 0; uint16_t test_pdu_len = 0;
int function_len = 0; int function_len = 0;
@@ -174,23 +173,25 @@ static void test_Initiate_Original_Broadcast_NPDU(Test *pTest)
dest.net = BACNET_BROADCAST_NETWORK; dest.net = BACNET_BROADCAST_NETWORK;
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
npdu_len = npdu_encode_pdu(&pdu[0], &dest, &IUT.BACnet_Address, &npdu_data); npdu_len = npdu_encode_pdu(&pdu[0], &dest, &IUT.BACnet_Address, &npdu_data);
apdu_len = iam_encode_apdu(&pdu[npdu_len], IUT.Device_ID, MAX_APDU, apdu_len = iam_encode_apdu(
SEGMENTATION_NONE, BACNET_VENDOR_ID); &pdu[npdu_len], IUT.Device_ID, MAX_APDU, SEGMENTATION_NONE,
BACNET_VENDOR_ID);
pdu_len = npdu_len + apdu_len; pdu_len = npdu_len + apdu_len;
bvlc_send_pdu(&dest, &npdu_data, pdu, pdu_len); bvlc_send_pdu(&dest, &npdu_data, pdu, pdu_len);
/* DA=Link Local Multicast Address */ /* DA=Link Local Multicast Address */
ct_test(pTest, !bvlc_address_different(&TD.BIP_Broadcast_Addr, ct_test(
&Test_Sent_Message_Dest)); pTest,
!bvlc_address_different(
&TD.BIP_Broadcast_Addr, &Test_Sent_Message_Dest));
/* SA = IUT - done in port layer */ /* SA = IUT - done in port layer */
/* Original-Broadcast-NPDU */ /* Original-Broadcast-NPDU */
ct_test(pTest, Test_Sent_Message_Type == ct_test(pTest, Test_Sent_Message_Type == BVLC_ORIGINAL_BROADCAST_NPDU);
BVLC_ORIGINAL_BROADCAST_NPDU);
if (Test_Sent_Message_Type == BVLC_ORIGINAL_BROADCAST_NPDU) { if (Test_Sent_Message_Type == BVLC_ORIGINAL_BROADCAST_NPDU) {
function_len = bvlc_decode_original_broadcast( function_len = bvlc_decode_original_broadcast(
Test_Sent_Message_Buffer, Test_Sent_Message_Buffer_Length, Test_Sent_Message_Buffer, Test_Sent_Message_Buffer_Length, test_pdu,
test_pdu, sizeof(test_pdu), &test_pdu_len); sizeof(test_pdu), &test_pdu_len);
printf("len=%u pdu[%u] test_pdu[%u]\n", printf(
(unsigned)function_len, "len=%u pdu[%u] test_pdu[%u]\n", (unsigned)function_len,
(unsigned)Test_Sent_Message_Buffer_Length, (unsigned)Test_Sent_Message_Buffer_Length,
(unsigned)sizeof(test_pdu)); (unsigned)sizeof(test_pdu));
ct_test(pTest, function_len > 0); ct_test(pTest, function_len > 0);
@@ -204,13 +205,15 @@ static void test_Initiate_Original_Broadcast_NPDU(Test *pTest)
static void test_BBMD_Result(Test *pTest) static void test_BBMD_Result(Test *pTest)
{ {
int result = 0; int result = 0;
uint16_t result_code[] = { BVLC_RESULT_SUCCESSFUL_COMPLETION, uint16_t result_code[] = {
BVLC_RESULT_SUCCESSFUL_COMPLETION,
BVLC_RESULT_WRITE_BROADCAST_DISTRIBUTION_TABLE_NAK, BVLC_RESULT_WRITE_BROADCAST_DISTRIBUTION_TABLE_NAK,
BVLC_RESULT_READ_BROADCAST_DISTRIBUTION_TABLE_NAK, BVLC_RESULT_READ_BROADCAST_DISTRIBUTION_TABLE_NAK,
BVLC_RESULT_REGISTER_FOREIGN_DEVICE_NAK, BVLC_RESULT_REGISTER_FOREIGN_DEVICE_NAK,
BVLC_RESULT_READ_FOREIGN_DEVICE_TABLE_NAK, BVLC_RESULT_READ_FOREIGN_DEVICE_TABLE_NAK,
BVLC_RESULT_DELETE_FOREIGN_DEVICE_TABLE_ENTRY_NAK, BVLC_RESULT_DELETE_FOREIGN_DEVICE_TABLE_ENTRY_NAK,
BVLC_RESULT_DISTRIBUTE_BROADCAST_TO_NETWORK_NAK }; BVLC_RESULT_DISTRIBUTE_BROADCAST_TO_NETWORK_NAK
};
size_t result_code_max = sizeof(result_code) / sizeof(result_code[0]); size_t result_code_max = sizeof(result_code) / sizeof(result_code[0]);
uint16_t test_result_code = 0; uint16_t test_result_code = 0;
uint8_t test_function_code = 0; uint8_t test_function_code = 0;
+41 -44
View File
@@ -82,7 +82,7 @@ int bip6_send_mpdu(BACNET_IP6_ADDRESS *dest, uint8_t *mtu, uint16_t mtu_len)
Test_Sent_Message_Length = message_length; Test_Sent_Message_Length = message_length;
bvlc6_address_copy(&Test_Sent_Message_Dest, dest); bvlc6_address_copy(&Test_Sent_Message_Dest, dest);
if ((header_len == 4) && (mtu_len >= 4)) { if ((header_len == 4) && (mtu_len >= 4)) {
memcpy(&Test_Sent_Message_Buffer[0], &mtu[4], mtu_len-4); memcpy(&Test_Sent_Message_Buffer[0], &mtu[4], mtu_len - 4);
Test_Sent_Message_Buffer_Length = mtu_len - 4; Test_Sent_Message_Buffer_Length = mtu_len - 4;
} else { } else {
Test_Sent_Message_Buffer_Length = 0; Test_Sent_Message_Buffer_Length = 0;
@@ -126,22 +126,21 @@ static void test_setup(void)
{ {
bvlc6_init(); bvlc6_init();
/* BACnet_IPv6_Multicast_Address is FF02::BAC0 */ /* BACnet_IPv6_Multicast_Address is FF02::BAC0 */
bvlc6_address_set(&TD.BIP6_Broadcast_Addr, bvlc6_address_set(
BIP6_MULTICAST_LINK_LOCAL, 0, 0, 0, 0, 0, 0, &TD.BIP6_Broadcast_Addr, BIP6_MULTICAST_LINK_LOCAL, 0, 0, 0, 0, 0, 0,
BIP6_MULTICAST_GROUP_ID); BIP6_MULTICAST_GROUP_ID);
bvlc6_address_set(&TD.BIP6_Addr, bvlc6_address_set(
0x2001, 0x0DBB, 0xAC10, 0xFE01, 0, 0, 0, &TD.BIP6_Addr, 0x2001, 0x0DBB, 0xAC10, 0xFE01, 0, 0, 0,
BIP6_MULTICAST_GROUP_ID); BIP6_MULTICAST_GROUP_ID);
TD.Device_ID = 12345; TD.Device_ID = 12345;
bvlc6_vmac_address_set(&TD.BACnet_Address, TD.Device_ID); bvlc6_vmac_address_set(&TD.BACnet_Address, TD.Device_ID);
/* BACnet_IPv6_Multicast_Address is FF02::BAC0 */ /* BACnet_IPv6_Multicast_Address is FF02::BAC0 */
bvlc6_address_set(&IUT.BIP6_Broadcast_Addr, bvlc6_address_set(
BIP6_MULTICAST_LINK_LOCAL, 0, 0, 0, 0, 0, 0, &IUT.BIP6_Broadcast_Addr, BIP6_MULTICAST_LINK_LOCAL, 0, 0, 0, 0, 0, 0,
BIP6_MULTICAST_GROUP_ID); BIP6_MULTICAST_GROUP_ID);
bvlc6_address_set(&IUT.BIP6_Addr, bvlc6_address_set(
0x2001, 0x0DBB, 0xAC10, 0xFE01, 0, 0, 1, &IUT.BIP6_Addr, 0x2001, 0x0DBB, 0xAC10, 0xFE01, 0, 0, 1,
BIP6_MULTICAST_GROUP_ID); BIP6_MULTICAST_GROUP_ID);
IUT.Device_ID = 54321; IUT.Device_ID = 54321;
bvlc6_vmac_address_set(&IUT.BACnet_Address, IUT.Device_ID); bvlc6_vmac_address_set(&IUT.BACnet_Address, IUT.Device_ID);
@@ -157,13 +156,13 @@ static void test_cleanup(void)
*/ */
static void test_Initiate_Original_Broadcast_NPDU(void) static void test_Initiate_Original_Broadcast_NPDU(void)
{ {
uint8_t pdu[MAX_MPDU] = {0}; uint8_t pdu[MAX_MPDU] = { 0 };
int npdu_len = 0; int npdu_len = 0;
int apdu_len = 0; int apdu_len = 0;
int pdu_len = 0; int pdu_len = 0;
BACNET_ADDRESS dest = {0}; BACNET_ADDRESS dest = { 0 };
BACNET_NPDU_DATA npdu_data = {0}; BACNET_NPDU_DATA npdu_data = { 0 };
uint8_t test_pdu[MAX_MPDU] = {0}; uint8_t test_pdu[MAX_MPDU] = { 0 };
uint16_t test_pdu_len = 0; uint16_t test_pdu_len = 0;
uint32_t test_vmac_src = 0; uint32_t test_vmac_src = 0;
int function_len = 0; int function_len = 0;
@@ -173,17 +172,17 @@ static void test_Initiate_Original_Broadcast_NPDU(void)
dest.net = BACNET_BROADCAST_NETWORK; dest.net = BACNET_BROADCAST_NETWORK;
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
npdu_len = npdu_encode_pdu(&pdu[0], &dest, &IUT.BACnet_Address, &npdu_data); npdu_len = npdu_encode_pdu(&pdu[0], &dest, &IUT.BACnet_Address, &npdu_data);
apdu_len = iam_encode_apdu(&pdu[npdu_len], IUT.Device_ID, MAX_APDU, apdu_len = iam_encode_apdu(
SEGMENTATION_NONE, BACNET_VENDOR_ID); &pdu[npdu_len], IUT.Device_ID, MAX_APDU, SEGMENTATION_NONE,
BACNET_VENDOR_ID);
pdu_len = npdu_len + apdu_len; pdu_len = npdu_len + apdu_len;
bvlc6_send_pdu(&dest, &npdu_data, pdu, pdu_len); bvlc6_send_pdu(&dest, &npdu_data, pdu, pdu_len);
/* DA=Link Local Multicast Address */ /* DA=Link Local Multicast Address */
assert(!bvlc6_address_different(&TD.BIP6_Broadcast_Addr, assert(!bvlc6_address_different(
&Test_Sent_Message_Dest)); &TD.BIP6_Broadcast_Addr, &Test_Sent_Message_Dest));
/* SA = IUT - done in port layer */ /* SA = IUT - done in port layer */
/* Original-Broadcast-NPDU */ /* Original-Broadcast-NPDU */
assert(Test_Sent_Message_Type == assert(Test_Sent_Message_Type == BVLC6_ORIGINAL_BROADCAST_NPDU);
BVLC6_ORIGINAL_BROADCAST_NPDU);
if (Test_Sent_Message_Type == BVLC6_ORIGINAL_BROADCAST_NPDU) { if (Test_Sent_Message_Type == BVLC6_ORIGINAL_BROADCAST_NPDU) {
function_len = bvlc6_decode_original_broadcast( function_len = bvlc6_decode_original_broadcast(
Test_Sent_Message_Buffer, Test_Sent_Message_Buffer_Length, Test_Sent_Message_Buffer, Test_Sent_Message_Buffer_Length,
@@ -203,7 +202,7 @@ static void test_Initiate_Original_Broadcast_NPDU(void)
*/ */
static void test_Execute_Virtual_Address_Resolution(void) static void test_Execute_Virtual_Address_Resolution(void)
{ {
uint8_t mtu[MAX_MPDU] = {0}; uint8_t mtu[MAX_MPDU] = { 0 };
uint16_t mtu_len = 0; uint16_t mtu_len = 0;
uint32_t test_vmac_src = 0; uint32_t test_vmac_src = 0;
uint32_t test_vmac_dst = 0; uint32_t test_vmac_dst = 0;
@@ -214,13 +213,11 @@ static void test_Execute_Virtual_Address_Resolution(void)
test_setup(); test_setup();
mtu_len = bvlc6_encode_virtual_address_resolution( mtu_len = bvlc6_encode_virtual_address_resolution(
&mtu[0], sizeof(mtu), TD.Device_ID); &mtu[0], sizeof(mtu), TD.Device_ID);
result = bvlc6_bbmd_disabled_handler(&TD.BIP6_Addr, &TD.BACnet_Address, result = bvlc6_bbmd_disabled_handler(
&mtu[0], mtu_len); &TD.BIP6_Addr, &TD.BACnet_Address, &mtu[0], mtu_len);
assert(result == 0); assert(result == 0);
assert(bvlc6_get_function_code() == assert(bvlc6_get_function_code() == BVLC6_VIRTUAL_ADDRESS_RESOLUTION);
BVLC6_VIRTUAL_ADDRESS_RESOLUTION); assert(Test_Sent_Message_Type == BVLC6_VIRTUAL_ADDRESS_RESOLUTION_ACK);
assert(Test_Sent_Message_Type ==
BVLC6_VIRTUAL_ADDRESS_RESOLUTION_ACK);
assert(VMAC_Find_By_Key(TD.Device_ID) != NULL); assert(VMAC_Find_By_Key(TD.Device_ID) != NULL);
if (Test_Sent_Message_Type == BVLC6_VIRTUAL_ADDRESS_RESOLUTION_ACK) { if (Test_Sent_Message_Type == BVLC6_VIRTUAL_ADDRESS_RESOLUTION_ACK) {
function_len = bvlc6_decode_virtual_address_resolution_ack( function_len = bvlc6_decode_virtual_address_resolution_ack(
@@ -235,34 +232,31 @@ static void test_Execute_Virtual_Address_Resolution(void)
TD.Device_ID += 42; TD.Device_ID += 42;
mtu_len = bvlc6_encode_virtual_address_resolution( mtu_len = bvlc6_encode_virtual_address_resolution(
&mtu[0], sizeof(mtu), TD.Device_ID); &mtu[0], sizeof(mtu), TD.Device_ID);
result = bvlc6_bbmd_disabled_handler(&TD.BIP6_Addr, &TD.BACnet_Address, result = bvlc6_bbmd_disabled_handler(
&mtu[0], mtu_len); &TD.BIP6_Addr, &TD.BACnet_Address, &mtu[0], mtu_len);
assert(result == 0); assert(result == 0);
assert(bvlc6_get_function_code() == assert(bvlc6_get_function_code() == BVLC6_VIRTUAL_ADDRESS_RESOLUTION);
BVLC6_VIRTUAL_ADDRESS_RESOLUTION);
assert(VMAC_Find_By_Key(TD.Device_ID) != NULL); assert(VMAC_Find_By_Key(TD.Device_ID) != NULL);
assert(VMAC_Find_By_Key(old_device_id) == NULL); assert(VMAC_Find_By_Key(old_device_id) == NULL);
/* change IPv6 address */ /* change IPv6 address */
mtu_len = bvlc6_encode_virtual_address_resolution( mtu_len = bvlc6_encode_virtual_address_resolution(
&mtu[0], sizeof(mtu), TD.Device_ID); &mtu[0], sizeof(mtu), TD.Device_ID);
bvlc6_address_set(&TD.BIP6_Addr, bvlc6_address_set(
0x2001, 0x0DBB, 0xAC10, 0xFE01, 0, 0, 42, &TD.BIP6_Addr, 0x2001, 0x0DBB, 0xAC10, 0xFE01, 0, 0, 42,
BIP6_MULTICAST_GROUP_ID); BIP6_MULTICAST_GROUP_ID);
result = bvlc6_bbmd_disabled_handler(&TD.BIP6_Addr, &TD.BACnet_Address, result = bvlc6_bbmd_disabled_handler(
&mtu[0], mtu_len); &TD.BIP6_Addr, &TD.BACnet_Address, &mtu[0], mtu_len);
assert(result == 0); assert(result == 0);
assert(bvlc6_get_function_code() == assert(bvlc6_get_function_code() == BVLC6_VIRTUAL_ADDRESS_RESOLUTION);
BVLC6_VIRTUAL_ADDRESS_RESOLUTION);
assert(VMAC_Find_By_Key(TD.Device_ID) != NULL); assert(VMAC_Find_By_Key(TD.Device_ID) != NULL);
/* repeat with same device ID and address */ /* repeat with same device ID and address */
/* change IPv6 address */ /* change IPv6 address */
mtu_len = bvlc6_encode_virtual_address_resolution( mtu_len = bvlc6_encode_virtual_address_resolution(
&mtu[0], sizeof(mtu), TD.Device_ID); &mtu[0], sizeof(mtu), TD.Device_ID);
result = bvlc6_bbmd_disabled_handler(&TD.BIP6_Addr, &TD.BACnet_Address, result = bvlc6_bbmd_disabled_handler(
&mtu[0], mtu_len); &TD.BIP6_Addr, &TD.BACnet_Address, &mtu[0], mtu_len);
assert(result == 0); assert(result == 0);
assert(bvlc6_get_function_code() == assert(bvlc6_get_function_code() == BVLC6_VIRTUAL_ADDRESS_RESOLUTION);
BVLC6_VIRTUAL_ADDRESS_RESOLUTION);
assert(VMAC_Find_By_Key(TD.Device_ID) != NULL); assert(VMAC_Find_By_Key(TD.Device_ID) != NULL);
test_cleanup(); test_cleanup();
@@ -272,12 +266,14 @@ static void test_BBMD_Result(void)
{ {
int result = 0; int result = 0;
uint32_t vmac_src = 0x1234; uint32_t vmac_src = 0x1234;
uint16_t result_code[6] = { BVLC6_RESULT_SUCCESSFUL_COMPLETION, uint16_t result_code[6] = {
BVLC6_RESULT_SUCCESSFUL_COMPLETION,
BVLC6_RESULT_ADDRESS_RESOLUTION_NAK, BVLC6_RESULT_ADDRESS_RESOLUTION_NAK,
BVLC6_RESULT_VIRTUAL_ADDRESS_RESOLUTION_NAK, BVLC6_RESULT_VIRTUAL_ADDRESS_RESOLUTION_NAK,
BVLC6_RESULT_REGISTER_FOREIGN_DEVICE_NAK, BVLC6_RESULT_REGISTER_FOREIGN_DEVICE_NAK,
BVLC6_RESULT_DELETE_FOREIGN_DEVICE_NAK, BVLC6_RESULT_DELETE_FOREIGN_DEVICE_NAK,
BVLC6_RESULT_DISTRIBUTE_BROADCAST_TO_NETWORK_NAK }; BVLC6_RESULT_DISTRIBUTE_BROADCAST_TO_NETWORK_NAK
};
uint16_t test_result_code = 0; uint16_t test_result_code = 0;
uint8_t test_function_code = 0; uint8_t test_function_code = 0;
BACNET_IP6_ADDRESS addr; BACNET_IP6_ADDRESS addr;
@@ -286,7 +282,8 @@ static void test_BBMD_Result(void)
uint8_t mtu[MAX_MPDU] = { 0 }; uint8_t mtu[MAX_MPDU] = { 0 };
uint16_t mtu_len = 0; uint16_t mtu_len = 0;
bvlc6_address_set(&addr, BIP6_MULTICAST_LINK_LOCAL, 0, 0, 0, 0, 0, 0, bvlc6_address_set(
&addr, BIP6_MULTICAST_LINK_LOCAL, 0, 0, 0, 0, 0, 0,
BIP6_MULTICAST_GROUP_ID); BIP6_MULTICAST_GROUP_ID);
addr.port = 0xBAC0U; addr.port = 0xBAC0U;
bvlc6_vmac_address_set(&src, vmac_src); bvlc6_vmac_address_set(&src, vmac_src);
+12 -14
View File
@@ -44,7 +44,8 @@ static void set_address(unsigned index, BACNET_ADDRESS *dest)
} }
} }
static void set_file_address(const char *pFilename, static void set_file_address(
const char *pFilename,
uint32_t device_id, uint32_t device_id,
BACNET_ADDRESS *dest, BACNET_ADDRESS *dest,
uint16_t max_apdu) uint16_t max_apdu)
@@ -114,7 +115,6 @@ static void testAddressFile(void)
address_remove_device(device_id); address_remove_device(device_id);
zassert_equal(address_count(), 0, NULL); zassert_equal(address_count(), 0, NULL);
/* create a fake address */ /* create a fake address */
device_id = 55555; device_id = 55555;
src.mac_len = 6; src.mac_len = 6;
@@ -170,12 +170,14 @@ static void testAddress(void)
set_address(i, &src); set_address(i, &src);
/* test the lookup by device id */ /* test the lookup by device id */
zassert_true( zassert_true(
address_get_by_device(device_id, &test_max_apdu, &test_address), NULL); address_get_by_device(device_id, &test_max_apdu, &test_address),
NULL);
zassert_equal(test_max_apdu, max_apdu, NULL); zassert_equal(test_max_apdu, max_apdu, NULL);
zassert_true(bacnet_address_same(&test_address, &src), NULL); zassert_true(bacnet_address_same(&test_address, &src), NULL);
zassert_true( zassert_true(
address_get_by_index( address_get_by_index(
i, &test_device_id, &test_max_apdu, &test_address), NULL); i, &test_device_id, &test_max_apdu, &test_address),
NULL);
zassert_equal(test_device_id, device_id, NULL); zassert_equal(test_device_id, device_id, NULL);
zassert_equal(test_max_apdu, max_apdu, NULL); zassert_equal(test_max_apdu, max_apdu, NULL);
zassert_true(bacnet_address_same(&test_address, &src), NULL); zassert_true(bacnet_address_same(&test_address, &src), NULL);
@@ -189,7 +191,8 @@ static void testAddress(void)
device_id = i * 255; device_id = i * 255;
address_remove_device(device_id); address_remove_device(device_id);
zassert_false( zassert_false(
address_get_by_device(device_id, &test_max_apdu, &test_address), NULL); address_get_by_device(device_id, &test_max_apdu, &test_address),
NULL);
count = address_count(); count = address_count();
zassert_equal(count, (MAX_ADDRESS_CACHE - i - 1), NULL); zassert_equal(count, (MAX_ADDRESS_CACHE - i - 1), NULL);
} }
@@ -198,26 +201,21 @@ static void testAddress(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(address_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(address_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
#ifdef BACNET_ADDRESS_CACHE_FILE #ifdef BACNET_ADDRESS_CACHE_FILE
ztest_test_suite(address_tests, ztest_test_suite(
ztest_unit_test(testAddressFile), address_tests, ztest_unit_test(testAddressFile),
ztest_unit_test(testAddress) ztest_unit_test(testAddress));
);
ztest_run_test_suite(address_tests); ztest_run_test_suite(address_tests);
#else #else
ztest_test_suite(address_tests, ztest_test_suite(address_tests, ztest_unit_test(testAddress));
ztest_unit_test(testAddress)
);
ztest_run_test_suite(address_tests); ztest_run_test_suite(address_tests);
#endif #endif
} }
#endif #endif
+11 -12
View File
@@ -29,8 +29,8 @@ static void test_Accumulator(void)
uint8_t apdu[MAX_APDU] = { 0 }; uint8_t apdu[MAX_APDU] = { 0 };
int len = 0; int len = 0;
int test_len = 0; int test_len = 0;
BACNET_READ_PROPERTY_DATA rpdata = {0}; BACNET_READ_PROPERTY_DATA rpdata = { 0 };
BACNET_APPLICATION_DATA_VALUE value = {0}; BACNET_APPLICATION_DATA_VALUE value = { 0 };
const int *required_property = NULL; const int *required_property = NULL;
BACNET_UNSIGNED_INTEGER unsigned_value = 1; BACNET_UNSIGNED_INTEGER unsigned_value = 1;
@@ -48,14 +48,16 @@ static void test_Accumulator(void)
zassert_true(len >= 0, NULL); zassert_true(len >= 0, NULL);
if (len >= 0) { if (len >= 0) {
if (IS_CONTEXT_SPECIFIC(rpdata.application_data[0])) { if (IS_CONTEXT_SPECIFIC(rpdata.application_data[0])) {
test_len = bacapp_decode_context_data(rpdata.application_data, test_len = bacapp_decode_context_data(
len, &value, rpdata.object_property); rpdata.application_data, len, &value,
rpdata.object_property);
} else { } else {
test_len = bacapp_decode_application_data( test_len = bacapp_decode_application_data(
rpdata.application_data, len, &value); rpdata.application_data, len, &value);
} }
if (len != test_len) { if (len != test_len) {
printf("property '%s': failed to decode!\n", printf(
"property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
zassert_equal(len, test_len, NULL); zassert_equal(len, test_len, NULL);
@@ -68,10 +70,10 @@ static void test_Accumulator(void)
Accumulator_Present_Value_Set(0, unsigned_value); Accumulator_Present_Value_Set(0, unsigned_value);
len = Accumulator_Read_Property(&rpdata); len = Accumulator_Read_Property(&rpdata);
zassert_not_equal(len, 0, NULL); zassert_not_equal(len, 0, NULL);
test_len = bacapp_decode_application_data(rpdata.application_data, test_len = bacapp_decode_application_data(
len, &value); rpdata.application_data, len, &value);
zassert_equal(len, test_len, NULL); zassert_equal(len, test_len, NULL);
unsigned_value |= (unsigned_value<<1); unsigned_value |= (unsigned_value << 1);
} }
return; return;
@@ -80,15 +82,12 @@ static void test_Accumulator(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(acc_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(acc_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(acc_tests, ztest_test_suite(acc_tests, ztest_unit_test(test_Accumulator));
ztest_unit_test(test_Accumulator)
);
ztest_run_test_suite(acc_tests); ztest_run_test_suite(acc_tests);
} }
@@ -49,8 +49,9 @@ static void testAccessCredential(void)
zassert_true(len >= 0, NULL); zassert_true(len >= 0, NULL);
if (len >= 0) { if (len >= 0) {
if (IS_CONTEXT_SPECIFIC(rpdata.application_data[0])) { if (IS_CONTEXT_SPECIFIC(rpdata.application_data[0])) {
test_len = bacapp_decode_context_data(rpdata.application_data, test_len = bacapp_decode_context_data(
len, &value, rpdata.object_property); rpdata.application_data, len, &value,
rpdata.object_property);
} else { } else {
test_len = bacapp_decode_application_data( test_len = bacapp_decode_application_data(
rpdata.application_data, len, &value); rpdata.application_data, len, &value);
@@ -61,7 +62,8 @@ static void testAccessCredential(void)
} }
} }
if (len != test_len) { if (len != test_len) {
fprintf(stderr, "property '%d': failed to decode!\n", fprintf(
stderr, "property '%d': failed to decode!\n",
rpdata.object_property); rpdata.object_property);
} }
zassert_true(len == test_len, NULL); zassert_true(len == test_len, NULL);
@@ -75,7 +77,6 @@ static void testAccessCredential(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(access_credential_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(access_credential_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
@@ -52,8 +52,9 @@ static void test_object_access_door(void)
len = Access_Door_Read_Property(&rpdata); len = Access_Door_Read_Property(&rpdata);
zassert_not_equal(len, BACNET_STATUS_ERROR, NULL); zassert_not_equal(len, BACNET_STATUS_ERROR, NULL);
if (len > 0) { if (len > 0) {
test_len = bacapp_decode_application_data(rpdata.application_data, test_len = bacapp_decode_application_data(
(uint8_t)rpdata.application_data_len, &value); rpdata.application_data, (uint8_t)rpdata.application_data_len,
&value);
zassert_true(test_len >= 0, NULL); zassert_true(test_len >= 0, NULL);
} }
pRequired++; pRequired++;
@@ -64,8 +65,9 @@ static void test_object_access_door(void)
len = Access_Door_Read_Property(&rpdata); len = Access_Door_Read_Property(&rpdata);
zassert_not_equal(len, BACNET_STATUS_ERROR, NULL); zassert_not_equal(len, BACNET_STATUS_ERROR, NULL);
if (len > 0) { if (len > 0) {
test_len = bacapp_decode_application_data(rpdata.application_data, test_len = bacapp_decode_application_data(
(uint8_t)rpdata.application_data_len, &value); rpdata.application_data, (uint8_t)rpdata.application_data_len,
&value);
zassert_true(test_len >= 0, NULL); zassert_true(test_len >= 0, NULL);
} }
pOptional++; pOptional++;
@@ -77,7 +79,6 @@ static void test_object_access_door(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(tests_object_access_door, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(tests_object_access_door, NULL, NULL, NULL, NULL, NULL);
#else #else
@@ -30,7 +30,7 @@ static void testAccessPoint(void)
uint8_t apdu[MAX_APDU] = { 0 }; uint8_t apdu[MAX_APDU] = { 0 };
int len = 0, test_len = 0; int len = 0, test_len = 0;
BACNET_READ_PROPERTY_DATA rpdata = { 0 }; BACNET_READ_PROPERTY_DATA rpdata = { 0 };
BACNET_APPLICATION_DATA_VALUE value = {0}; BACNET_APPLICATION_DATA_VALUE value = { 0 };
const int *required_property = NULL; const int *required_property = NULL;
unsigned count = 0; unsigned count = 0;
uint32_t object_instance = 0; uint32_t object_instance = 0;
@@ -50,10 +50,12 @@ static void testAccessPoint(void)
len = Access_Point_Read_Property(&rpdata); len = Access_Point_Read_Property(&rpdata);
if (len >= 0) { if (len >= 0) {
zassert_true(len >= 0, NULL); zassert_true(len >= 0, NULL);
test_len = bacapp_decode_known_property(rpdata.application_data, test_len = bacapp_decode_known_property(
len, &value, rpdata.object_type, rpdata.object_property); rpdata.application_data, len, &value, rpdata.object_type,
rpdata.object_property);
if (len != test_len) { if (len != test_len) {
printf("property '%s': failed to decode!\n", printf(
"property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
if (rpdata.object_property == PROP_ACCESS_DOORS) { if (rpdata.object_property == PROP_ACCESS_DOORS) {
@@ -62,7 +64,8 @@ static void testAccessPoint(void)
} }
zassert_equal(len, test_len, NULL); zassert_equal(len, test_len, NULL);
} else { } else {
printf("property '%s': failed to read!\n", printf(
"property '%s': failed to read!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
required_property++; required_property++;
@@ -72,7 +75,6 @@ static void testAccessPoint(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(access_point_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(access_point_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
@@ -52,15 +52,12 @@ static void testAccessRights(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(access_rights_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(access_rights_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(access_rights_tests, ztest_test_suite(access_rights_tests, ztest_unit_test(testAccessRights));
ztest_unit_test(testAccessRights)
);
ztest_run_test_suite(access_rights_tests); ztest_run_test_suite(access_rights_tests);
} }
@@ -52,15 +52,12 @@ static void testAccessUser(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(access_user_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(access_user_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(access_user_tests, ztest_test_suite(access_user_tests, ztest_unit_test(testAccessUser));
ztest_unit_test(testAccessUser)
);
ztest_run_test_suite(access_user_tests); ztest_run_test_suite(access_user_tests);
} }
@@ -52,15 +52,12 @@ static void testAccessZone(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(access_zone_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(access_zone_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(access_zone_tests, ztest_test_suite(access_zone_tests, ztest_unit_test(testAccessZone));
ztest_unit_test(testAccessZone)
);
ztest_run_test_suite(access_zone_tests); ztest_run_test_suite(access_zone_tests);
} }
+3 -9
View File
@@ -37,11 +37,8 @@ static void testAnalogInput(void)
test_object_instance = Analog_Input_Index_To_Instance(0); test_object_instance = Analog_Input_Index_To_Instance(0);
zassert_equal(object_instance, test_object_instance, NULL); zassert_equal(object_instance, test_object_instance, NULL);
bacnet_object_properties_read_write_test( bacnet_object_properties_read_write_test(
OBJECT_ANALOG_INPUT, OBJECT_ANALOG_INPUT, object_instance, Analog_Input_Property_Lists,
object_instance, Analog_Input_Read_Property, Analog_Input_Write_Property,
Analog_Input_Property_Lists,
Analog_Input_Read_Property,
Analog_Input_Write_Property,
skip_fail_property_list); skip_fail_property_list);
status = Analog_Input_Delete(object_instance); status = Analog_Input_Delete(object_instance);
zassert_true(status, NULL); zassert_true(status, NULL);
@@ -50,15 +47,12 @@ static void testAnalogInput(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(ai_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(ai_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(ai_tests, ztest_test_suite(ai_tests, ztest_unit_test(testAnalogInput));
ztest_unit_test(testAnalogInput)
);
ztest_run_test_suite(ai_tests); ztest_run_test_suite(ai_tests);
} }
+2 -1
View File
@@ -18,7 +18,8 @@
#include "bacnet/get_alarm_sum.h" #include "bacnet/get_alarm_sum.h"
#include "bacnet/npdu.h" #include "bacnet/npdu.h"
bool datetime_local(BACNET_DATE *bdate, bool datetime_local(
BACNET_DATE *bdate,
BACNET_TIME *btime, BACNET_TIME *btime,
int16_t *utc_offset_minutes, int16_t *utc_offset_minutes,
bool *dst_active) bool *dst_active)
+3 -9
View File
@@ -37,11 +37,8 @@ static void testAnalogOutput(void)
test_object_instance = Analog_Output_Index_To_Instance(0); test_object_instance = Analog_Output_Index_To_Instance(0);
zassert_equal(object_instance, test_object_instance, NULL); zassert_equal(object_instance, test_object_instance, NULL);
bacnet_object_properties_read_write_test( bacnet_object_properties_read_write_test(
OBJECT_ANALOG_OUTPUT, OBJECT_ANALOG_OUTPUT, object_instance, Analog_Output_Property_Lists,
object_instance, Analog_Output_Read_Property, Analog_Output_Write_Property,
Analog_Output_Property_Lists,
Analog_Output_Read_Property,
Analog_Output_Write_Property,
skip_fail_property_list); skip_fail_property_list);
status = Analog_Output_Delete(object_instance); status = Analog_Output_Delete(object_instance);
zassert_true(status, NULL); zassert_true(status, NULL);
@@ -50,15 +47,12 @@ static void testAnalogOutput(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(ao_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(ao_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(ao_tests, ztest_test_suite(ao_tests, ztest_unit_test(testAnalogOutput));
ztest_unit_test(testAnalogOutput)
);
ztest_run_test_suite(ao_tests); ztest_run_test_suite(ao_tests);
} }
+3 -9
View File
@@ -37,11 +37,8 @@ static void testAnalog_Value(void)
test_object_instance = Analog_Value_Index_To_Instance(0); test_object_instance = Analog_Value_Index_To_Instance(0);
zassert_equal(object_instance, test_object_instance, NULL); zassert_equal(object_instance, test_object_instance, NULL);
bacnet_object_properties_read_write_test( bacnet_object_properties_read_write_test(
OBJECT_ANALOG_VALUE, OBJECT_ANALOG_VALUE, object_instance, Analog_Value_Property_Lists,
object_instance, Analog_Value_Read_Property, Analog_Value_Write_Property,
Analog_Value_Property_Lists,
Analog_Value_Read_Property,
Analog_Value_Write_Property,
skip_fail_property_list); skip_fail_property_list);
status = Analog_Value_Delete(object_instance); status = Analog_Value_Delete(object_instance);
zassert_true(status, NULL); zassert_true(status, NULL);
@@ -50,15 +47,12 @@ static void testAnalog_Value(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(av_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(av_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(av_tests, ztest_test_suite(av_tests, ztest_unit_test(testAnalog_Value));
ztest_unit_test(testAnalog_Value)
);
ztest_run_test_suite(av_tests); ztest_run_test_suite(av_tests);
} }
+2 -1
View File
@@ -18,7 +18,8 @@
#include "bacnet/get_alarm_sum.h" #include "bacnet/get_alarm_sum.h"
#include "bacnet/npdu.h" #include "bacnet/npdu.h"
bool datetime_local(BACNET_DATE *bdate, bool datetime_local(
BACNET_DATE *bdate,
BACNET_TIME *btime, BACNET_TIME *btime,
int16_t *utc_offset_minutes, int16_t *utc_offset_minutes,
bool *dst_active) bool *dst_active)
+9 -9
View File
@@ -29,7 +29,7 @@ static void test_BACnet_File_Object(void)
uint8_t apdu[MAX_APDU] = { 0 }; uint8_t apdu[MAX_APDU] = { 0 };
int len = 0, test_len = 0; int len = 0, test_len = 0;
BACNET_READ_PROPERTY_DATA rpdata = { 0 }; BACNET_READ_PROPERTY_DATA rpdata = { 0 };
BACNET_APPLICATION_DATA_VALUE value = {0}; BACNET_APPLICATION_DATA_VALUE value = { 0 };
const int *required_property = NULL; const int *required_property = NULL;
const uint32_t instance = 1; const uint32_t instance = 1;
@@ -46,15 +46,18 @@ static void test_BACnet_File_Object(void)
rpdata.object_property = *required_property; rpdata.object_property = *required_property;
len = bacfile_read_property(&rpdata); len = bacfile_read_property(&rpdata);
if (len < 0) { if (len < 0) {
printf("property %u: failed to read!\n", printf(
"property %u: failed to read!\n",
(unsigned)rpdata.object_property); (unsigned)rpdata.object_property);
} }
zassert_true(len >= 0, NULL); zassert_true(len >= 0, NULL);
if (len >= 0) { if (len >= 0) {
test_len = bacapp_decode_known_property(rpdata.application_data, test_len = bacapp_decode_known_property(
len, &value, rpdata.object_type, rpdata.object_property); rpdata.application_data, len, &value, rpdata.object_type,
rpdata.object_property);
if (len != test_len) { if (len != test_len) {
printf("property %u: failed to decode!\n", printf(
"property %u: failed to decode!\n",
(unsigned)rpdata.object_property); (unsigned)rpdata.object_property);
} }
zassert_equal(len, test_len, NULL); zassert_equal(len, test_len, NULL);
@@ -68,15 +71,12 @@ static void test_BACnet_File_Object(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(bacfile_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(bacfile_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(bacfile_tests, ztest_test_suite(bacfile_tests, ztest_unit_test(test_BACnet_File_Object));
ztest_unit_test(test_BACnet_File_Object)
);
ztest_run_test_suite(bacfile_tests); ztest_run_test_suite(bacfile_tests);
} }
+3 -9
View File
@@ -38,11 +38,8 @@ static void testBinaryInput(void)
test_object_instance = Binary_Input_Index_To_Instance(0); test_object_instance = Binary_Input_Index_To_Instance(0);
zassert_equal(object_instance, test_object_instance, NULL); zassert_equal(object_instance, test_object_instance, NULL);
bacnet_object_properties_read_write_test( bacnet_object_properties_read_write_test(
OBJECT_BINARY_INPUT, OBJECT_BINARY_INPUT, object_instance, Binary_Input_Property_Lists,
object_instance, Binary_Input_Read_Property, Binary_Input_Write_Property,
Binary_Input_Property_Lists,
Binary_Input_Read_Property,
Binary_Input_Write_Property,
skip_fail_property_list); skip_fail_property_list);
status = Binary_Input_Delete(object_instance); status = Binary_Input_Delete(object_instance);
zassert_true(status, NULL); zassert_true(status, NULL);
@@ -51,15 +48,12 @@ static void testBinaryInput(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(bi_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(bi_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(bi_tests, ztest_test_suite(bi_tests, ztest_unit_test(testBinaryInput));
ztest_unit_test(testBinaryInput)
);
ztest_run_test_suite(bi_tests); ztest_run_test_suite(bi_tests);
} }
+31 -21
View File
@@ -57,15 +57,17 @@ static void testBinaryLightingOutput(void)
rpdata.object_property = *pRequired; rpdata.object_property = *pRequired;
rpdata.array_index = BACNET_ARRAY_ALL; rpdata.array_index = BACNET_ARRAY_ALL;
len = Binary_Lighting_Output_Read_Property(&rpdata); len = Binary_Lighting_Output_Read_Property(&rpdata);
zassert_not_equal(len, BACNET_STATUS_ERROR, zassert_not_equal(
len, BACNET_STATUS_ERROR,
"property '%s': failed to ReadProperty!\n", "property '%s': failed to ReadProperty!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
if (len >= 0) { if (len >= 0) {
test_len = bacapp_decode_known_property(rpdata.application_data, test_len = bacapp_decode_known_property(
len, &value, rpdata.object_type, rpdata.object_property); rpdata.application_data, len, &value, rpdata.object_type,
rpdata.object_property);
if (rpdata.object_property != PROP_PRIORITY_ARRAY) { if (rpdata.object_property != PROP_PRIORITY_ARRAY) {
zassert_equal(len, test_len, zassert_equal(
"property '%s': failed to decode!\n", len, test_len, "property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
/* check WriteProperty properties */ /* check WriteProperty properties */
@@ -79,8 +81,8 @@ static void testBinaryLightingOutput(void)
status = Binary_Lighting_Output_Write_Property(&wpdata); status = Binary_Lighting_Output_Write_Property(&wpdata);
if (!status) { if (!status) {
/* verify WriteProperty property is known */ /* verify WriteProperty property is known */
zassert_not_equal(wpdata.error_code, zassert_not_equal(
ERROR_CODE_UNKNOWN_PROPERTY, wpdata.error_code, ERROR_CODE_UNKNOWN_PROPERTY,
"property '%s': WriteProperty Unknown!\n", "property '%s': WriteProperty Unknown!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
@@ -91,13 +93,16 @@ static void testBinaryLightingOutput(void)
rpdata.object_property = *pOptional; rpdata.object_property = *pOptional;
rpdata.array_index = BACNET_ARRAY_ALL; rpdata.array_index = BACNET_ARRAY_ALL;
len = Binary_Lighting_Output_Read_Property(&rpdata); len = Binary_Lighting_Output_Read_Property(&rpdata);
zassert_not_equal(len, BACNET_STATUS_ERROR, zassert_not_equal(
len, BACNET_STATUS_ERROR,
"property '%s': failed to ReadProperty!\n", "property '%s': failed to ReadProperty!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
if (len > 0) { if (len > 0) {
test_len = bacapp_decode_application_data(rpdata.application_data, test_len = bacapp_decode_application_data(
(uint8_t)rpdata.application_data_len, &value); rpdata.application_data, (uint8_t)rpdata.application_data_len,
zassert_equal(len, test_len, "property '%s': failed to decode!\n", &value);
zassert_equal(
len, test_len, "property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
/* check WriteProperty properties */ /* check WriteProperty properties */
wpdata.object_type = rpdata.object_type; wpdata.object_type = rpdata.object_type;
@@ -110,8 +115,8 @@ static void testBinaryLightingOutput(void)
status = Binary_Lighting_Output_Write_Property(&wpdata); status = Binary_Lighting_Output_Write_Property(&wpdata);
if (!status) { if (!status) {
/* verify WriteProperty property is known */ /* verify WriteProperty property is known */
zassert_not_equal(wpdata.error_code, zassert_not_equal(
ERROR_CODE_UNKNOWN_PROPERTY, wpdata.error_code, ERROR_CODE_UNKNOWN_PROPERTY,
"property '%s': WriteProperty Unknown!\n", "property '%s': WriteProperty Unknown!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
@@ -137,7 +142,8 @@ static struct {
BACNET_BINARY_LIGHTING_PV pv; BACNET_BINARY_LIGHTING_PV pv;
uint32_t count; uint32_t count;
} BLO_Value; } BLO_Value;
static void Binary_Lighting_Output_Write_Value_Handler(uint32_t object_instance, static void Binary_Lighting_Output_Write_Value_Handler(
uint32_t object_instance,
BACNET_BINARY_LIGHTING_PV old_value, BACNET_BINARY_LIGHTING_PV old_value,
BACNET_BINARY_LIGHTING_PV value) BACNET_BINARY_LIGHTING_PV value)
{ {
@@ -210,8 +216,9 @@ static void testBinaryLightingOutputBlink(void)
zassert_equal(expect_pv, test_pv, NULL); zassert_equal(expect_pv, test_pv, NULL);
test_priority = test_priority =
Binary_Lighting_Output_Present_Value_Priority(object_instance); Binary_Lighting_Output_Present_Value_Priority(object_instance);
zassert_equal(wpdata.priority, test_priority, zassert_equal(
"priority=%u test_priority=%u", wpdata.priority, test_priority); wpdata.priority, test_priority, "priority=%u test_priority=%u",
wpdata.priority, test_priority);
zassert_equal(BLO_Blink.count, 0, NULL); zassert_equal(BLO_Blink.count, 0, NULL);
zassert_equal(BLO_Value.count, 1, "count=%u", BLO_Value.count); zassert_equal(BLO_Value.count, 1, "count=%u", BLO_Value.count);
zassert_equal(BLO_Value.pv, expect_pv, NULL); zassert_equal(BLO_Value.pv, expect_pv, NULL);
@@ -232,8 +239,9 @@ static void testBinaryLightingOutputBlink(void)
zassert_equal(expect_pv, test_pv, NULL); zassert_equal(expect_pv, test_pv, NULL);
test_priority = test_priority =
Binary_Lighting_Output_Present_Value_Priority(object_instance); Binary_Lighting_Output_Present_Value_Priority(object_instance);
zassert_equal(wpdata.priority, test_priority, zassert_equal(
"priority=%u test_priority=%u", wpdata.priority, test_priority); wpdata.priority, test_priority, "priority=%u test_priority=%u",
wpdata.priority, test_priority);
zassert_equal(BLO_Blink.count, 0, NULL); zassert_equal(BLO_Blink.count, 0, NULL);
zassert_equal(BLO_Value.count, 2, "count=%u", BLO_Value.count); zassert_equal(BLO_Value.count, 2, "count=%u", BLO_Value.count);
zassert_equal(BLO_Value.pv, expect_pv, NULL); zassert_equal(BLO_Value.pv, expect_pv, NULL);
@@ -254,8 +262,9 @@ static void testBinaryLightingOutputBlink(void)
zassert_equal(expect_pv, test_pv, "pv=%u", test_pv); zassert_equal(expect_pv, test_pv, "pv=%u", test_pv);
test_priority = test_priority =
Binary_Lighting_Output_Present_Value_Priority(object_instance); Binary_Lighting_Output_Present_Value_Priority(object_instance);
zassert_equal(wpdata.priority, test_priority, zassert_equal(
"priority=%u test_priority=%u", wpdata.priority, test_priority); wpdata.priority, test_priority, "priority=%u test_priority=%u",
wpdata.priority, test_priority);
zassert_equal(BLO_Blink.count, 0, NULL); zassert_equal(BLO_Blink.count, 0, NULL);
zassert_equal(BLO_Value.count, 2, "count=%u", BLO_Value.count); zassert_equal(BLO_Value.count, 2, "count=%u", BLO_Value.count);
zassert_equal(BLO_Value.pv, expect_pv, NULL); zassert_equal(BLO_Value.pv, expect_pv, NULL);
@@ -271,7 +280,8 @@ ZTEST_SUITE(blo_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(blo_tests, ztest_unit_test(testBinaryLightingOutput), ztest_test_suite(
blo_tests, ztest_unit_test(testBinaryLightingOutput),
ztest_unit_test(testBinaryLightingOutputBlink)); ztest_unit_test(testBinaryLightingOutputBlink));
ztest_run_test_suite(blo_tests); ztest_run_test_suite(blo_tests);
+3 -9
View File
@@ -37,11 +37,8 @@ static void testBinaryOutput(void)
test_object_instance = Binary_Output_Index_To_Instance(0); test_object_instance = Binary_Output_Index_To_Instance(0);
zassert_equal(object_instance, test_object_instance, NULL); zassert_equal(object_instance, test_object_instance, NULL);
bacnet_object_properties_read_write_test( bacnet_object_properties_read_write_test(
OBJECT_BINARY_OUTPUT, OBJECT_BINARY_OUTPUT, object_instance, Binary_Output_Property_Lists,
object_instance, Binary_Output_Read_Property, Binary_Output_Write_Property,
Binary_Output_Property_Lists,
Binary_Output_Read_Property,
Binary_Output_Write_Property,
skip_fail_property_list); skip_fail_property_list);
status = Binary_Output_Delete(object_instance); status = Binary_Output_Delete(object_instance);
zassert_true(status, NULL); zassert_true(status, NULL);
@@ -50,15 +47,12 @@ static void testBinaryOutput(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(bo_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(bo_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(bo_tests, ztest_test_suite(bo_tests, ztest_unit_test(testBinaryOutput));
ztest_unit_test(testBinaryOutput)
);
ztest_run_test_suite(bo_tests); ztest_run_test_suite(bo_tests);
} }
+3 -9
View File
@@ -39,11 +39,8 @@ static void testBinary_Value(void)
test_object_instance = Binary_Value_Index_To_Instance(0); test_object_instance = Binary_Value_Index_To_Instance(0);
zassert_equal(object_instance, test_object_instance, NULL); zassert_equal(object_instance, test_object_instance, NULL);
bacnet_object_properties_read_write_test( bacnet_object_properties_read_write_test(
OBJECT_BINARY_VALUE, OBJECT_BINARY_VALUE, object_instance, Binary_Value_Property_Lists,
object_instance, Binary_Value_Read_Property, Binary_Value_Write_Property,
Binary_Value_Property_Lists,
Binary_Value_Read_Property,
Binary_Value_Write_Property,
skip_fail_property_list); skip_fail_property_list);
status = Binary_Value_Delete(object_instance); status = Binary_Value_Delete(object_instance);
zassert_true(status, NULL); zassert_true(status, NULL);
@@ -52,15 +49,12 @@ static void testBinary_Value(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(bv_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(bv_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(bv_tests, ztest_test_suite(bv_tests, ztest_unit_test(testBinary_Value));
ztest_unit_test(testBinary_Value)
);
ztest_run_test_suite(bv_tests); ztest_run_test_suite(bv_tests);
} }
+24 -20
View File
@@ -29,7 +29,7 @@ static void testCalendar(void)
int len = 0, test_len = 0; int len = 0, test_len = 0;
BACNET_READ_PROPERTY_DATA rpdata = { 0 }; BACNET_READ_PROPERTY_DATA rpdata = { 0 };
BACNET_WRITE_PROPERTY_DATA wpdata = { 0 }; BACNET_WRITE_PROPERTY_DATA wpdata = { 0 };
BACNET_APPLICATION_DATA_VALUE value = {0}; BACNET_APPLICATION_DATA_VALUE value = { 0 };
const int *pRequired = NULL; const int *pRequired = NULL;
const int *pOptional = NULL; const int *pOptional = NULL;
const int *pProprietary = NULL; const int *pProprietary = NULL;
@@ -57,14 +57,16 @@ static void testCalendar(void)
rpdata.object_property = *pRequired; rpdata.object_property = *pRequired;
rpdata.array_index = BACNET_ARRAY_ALL; rpdata.array_index = BACNET_ARRAY_ALL;
len = Calendar_Read_Property(&rpdata); len = Calendar_Read_Property(&rpdata);
zassert_not_equal(len, BACNET_STATUS_ERROR, zassert_not_equal(
len, BACNET_STATUS_ERROR,
"property '%s': failed to ReadProperty!\n", "property '%s': failed to ReadProperty!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
if (len >= 0) { if (len >= 0) {
test_len = bacapp_decode_known_property(rpdata.application_data, test_len = bacapp_decode_known_property(
len, &value, rpdata.object_type, rpdata.object_property); rpdata.application_data, len, &value, rpdata.object_type,
zassert_equal(len, test_len, rpdata.object_property);
"property '%s': failed to decode!\n", zassert_equal(
len, test_len, "property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
/* check WriteProperty properties */ /* check WriteProperty properties */
wpdata.object_type = rpdata.object_type; wpdata.object_type = rpdata.object_type;
@@ -77,8 +79,8 @@ static void testCalendar(void)
status = Calendar_Write_Property(&wpdata); status = Calendar_Write_Property(&wpdata);
if (!status) { if (!status) {
/* verify WriteProperty property is known */ /* verify WriteProperty property is known */
zassert_not_equal(wpdata.error_code, zassert_not_equal(
ERROR_CODE_UNKNOWN_PROPERTY, wpdata.error_code, ERROR_CODE_UNKNOWN_PROPERTY,
"property '%s': WriteProperty Unknown!\n", "property '%s': WriteProperty Unknown!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
@@ -89,13 +91,16 @@ static void testCalendar(void)
rpdata.object_property = *pOptional; rpdata.object_property = *pOptional;
rpdata.array_index = BACNET_ARRAY_ALL; rpdata.array_index = BACNET_ARRAY_ALL;
len = Calendar_Read_Property(&rpdata); len = Calendar_Read_Property(&rpdata);
zassert_not_equal(len, BACNET_STATUS_ERROR, zassert_not_equal(
len, BACNET_STATUS_ERROR,
"property '%s': failed to ReadProperty!\n", "property '%s': failed to ReadProperty!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
if (len > 0) { if (len > 0) {
test_len = bacapp_decode_application_data(rpdata.application_data, test_len = bacapp_decode_application_data(
(uint8_t)rpdata.application_data_len, &value); rpdata.application_data, (uint8_t)rpdata.application_data_len,
zassert_equal(len, test_len, "property '%s': failed to decode!\n", &value);
zassert_equal(
len, test_len, "property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
/* check WriteProperty properties */ /* check WriteProperty properties */
wpdata.object_type = rpdata.object_type; wpdata.object_type = rpdata.object_type;
@@ -108,8 +113,8 @@ static void testCalendar(void)
status = Calendar_Write_Property(&wpdata); status = Calendar_Write_Property(&wpdata);
if (!status) { if (!status) {
/* verify WriteProperty property is known */ /* verify WriteProperty property is known */
zassert_not_equal(wpdata.error_code, zassert_not_equal(
ERROR_CODE_UNKNOWN_PROPERTY, wpdata.error_code, ERROR_CODE_UNKNOWN_PROPERTY,
"property '%s': WriteProperty Unknown!\n", "property '%s': WriteProperty Unknown!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
@@ -182,7 +187,7 @@ static void testPresentValue(void)
zassert_true(Calendar_Present_Value(instance), NULL); zassert_true(Calendar_Present_Value(instance), NULL);
if (date.day > 1) { if (date.day > 1) {
value->type.DateRange.startdate.day --; value->type.DateRange.startdate.day--;
value->type.DateRange.enddate.day = date.day; value->type.DateRange.enddate.day = date.day;
zassert_true(Calendar_Present_Value(instance), NULL); zassert_true(Calendar_Present_Value(instance), NULL);
} }
@@ -214,7 +219,7 @@ static void testPresentValue(void)
value->type.WeekNDay.weekofmonth = (date.day - 1) % 7 + 1; value->type.WeekNDay.weekofmonth = (date.day - 1) % 7 + 1;
zassert_true(Calendar_Present_Value(instance), NULL); zassert_true(Calendar_Present_Value(instance), NULL);
value->type.WeekNDay.weekofmonth++; value->type.WeekNDay.weekofmonth++;
if (value->type.WeekNDay.weekofmonth >5) if (value->type.WeekNDay.weekofmonth > 5)
value->type.WeekNDay.weekofmonth = 1; value->type.WeekNDay.weekofmonth = 1;
zassert_false(Calendar_Present_Value(instance), NULL); zassert_false(Calendar_Present_Value(instance), NULL);
value->type.WeekNDay.weekofmonth = 0xff; value->type.WeekNDay.weekofmonth = 0xff;
@@ -241,10 +246,9 @@ ZTEST_SUITE(bacnet_calendar, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(calendar_tests, ztest_test_suite(
ztest_unit_test(testCalendar), calendar_tests, ztest_unit_test(testCalendar),
ztest_unit_test(testPresentValue) ztest_unit_test(testPresentValue));
);
ztest_run_test_suite(calendar_tests); ztest_run_test_suite(calendar_tests);
} }
+4 -4
View File
@@ -11,10 +11,10 @@
#include "bacnet/datetime.h" #include "bacnet/datetime.h"
bool datetime_local( bool datetime_local(
BACNET_DATE * bdate, BACNET_DATE *bdate,
BACNET_TIME * btime, BACNET_TIME *btime,
int16_t * utc_offset_minutes, int16_t *utc_offset_minutes,
bool * dst_active) bool *dst_active)
{ {
bdate->year = 2023; bdate->year = 2023;
bdate->month = 6; bdate->month = 6;
+19 -13
View File
@@ -55,20 +55,23 @@ static void test_Channel_ReadProperty(void)
rpdata.object_property = *pRequired; rpdata.object_property = *pRequired;
rpdata.array_index = BACNET_ARRAY_ALL; rpdata.array_index = BACNET_ARRAY_ALL;
len = Channel_Read_Property(&rpdata); len = Channel_Read_Property(&rpdata);
zassert_not_equal(len, BACNET_STATUS_ERROR, zassert_not_equal(
len, BACNET_STATUS_ERROR,
"property '%s': failed to ReadProperty!\n", "property '%s': failed to ReadProperty!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
if (len > 0) { if (len > 0) {
test_len = bacapp_decode_application_data(rpdata.application_data, test_len = bacapp_decode_application_data(
(uint8_t)rpdata.application_data_len, &value); rpdata.application_data, (uint8_t)rpdata.application_data_len,
&value);
if ((rpdata.object_property == PROP_PRIORITY_ARRAY) || if ((rpdata.object_property == PROP_PRIORITY_ARRAY) ||
(rpdata.object_property == PROP_CONTROL_GROUPS) || (rpdata.object_property == PROP_CONTROL_GROUPS) ||
(rpdata.object_property == (rpdata.object_property ==
PROP_LIST_OF_OBJECT_PROPERTY_REFERENCES)) { PROP_LIST_OF_OBJECT_PROPERTY_REFERENCES)) {
/* FIXME: known fail to decode */ /* FIXME: known fail to decode */
len = test_len; len = test_len;
} }
zassert_equal(len, test_len, "property '%s': failed to decode!\n", zassert_equal(
len, test_len, "property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
/* check WriteProperty properties */ /* check WriteProperty properties */
wpdata.object_type = rpdata.object_type; wpdata.object_type = rpdata.object_type;
@@ -81,8 +84,8 @@ static void test_Channel_ReadProperty(void)
status = Channel_Write_Property(&wpdata); status = Channel_Write_Property(&wpdata);
if (!status) { if (!status) {
/* verify WriteProperty property is known */ /* verify WriteProperty property is known */
zassert_not_equal(wpdata.error_code, zassert_not_equal(
ERROR_CODE_UNKNOWN_PROPERTY, wpdata.error_code, ERROR_CODE_UNKNOWN_PROPERTY,
"property '%s': WriteProperty Unknown!\n", "property '%s': WriteProperty Unknown!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
@@ -93,13 +96,16 @@ static void test_Channel_ReadProperty(void)
rpdata.object_property = *pOptional; rpdata.object_property = *pOptional;
rpdata.array_index = BACNET_ARRAY_ALL; rpdata.array_index = BACNET_ARRAY_ALL;
len = Channel_Read_Property(&rpdata); len = Channel_Read_Property(&rpdata);
zassert_not_equal(len, BACNET_STATUS_ERROR, zassert_not_equal(
len, BACNET_STATUS_ERROR,
"property '%s': failed to ReadProperty!\n", "property '%s': failed to ReadProperty!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
if (len > 0) { if (len > 0) {
test_len = bacapp_decode_application_data(rpdata.application_data, test_len = bacapp_decode_application_data(
(uint8_t)rpdata.application_data_len, &value); rpdata.application_data, (uint8_t)rpdata.application_data_len,
zassert_equal(len, test_len, "property '%s': failed to decode!\n", &value);
zassert_equal(
len, test_len, "property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
/* check WriteProperty properties */ /* check WriteProperty properties */
wpdata.object_type = rpdata.object_type; wpdata.object_type = rpdata.object_type;
@@ -112,8 +118,8 @@ static void test_Channel_ReadProperty(void)
status = Channel_Write_Property(&wpdata); status = Channel_Write_Property(&wpdata);
if (!status) { if (!status) {
/* verify WriteProperty property is known */ /* verify WriteProperty property is known */
zassert_not_equal(wpdata.error_code, zassert_not_equal(
ERROR_CODE_UNKNOWN_PROPERTY, wpdata.error_code, ERROR_CODE_UNKNOWN_PROPERTY,
"property '%s': WriteProperty Unknown!\n", "property '%s': WriteProperty Unknown!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
@@ -55,13 +55,16 @@ static void testColorObject(void)
rpdata.object_property = *pRequired; rpdata.object_property = *pRequired;
rpdata.array_index = BACNET_ARRAY_ALL; rpdata.array_index = BACNET_ARRAY_ALL;
len = Color_Read_Property(&rpdata); len = Color_Read_Property(&rpdata);
zassert_not_equal(len, BACNET_STATUS_ERROR, zassert_not_equal(
len, BACNET_STATUS_ERROR,
"property '%s': failed to ReadProperty!\n", "property '%s': failed to ReadProperty!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
if (len >= 0) { if (len >= 0) {
test_len = bacapp_decode_known_property(rpdata.application_data, test_len = bacapp_decode_known_property(
len, &value, rpdata.object_type, rpdata.object_property); rpdata.application_data, len, &value, rpdata.object_type,
zassert_equal(len, test_len, "property '%s': failed to decode!\n", rpdata.object_property);
zassert_equal(
len, test_len, "property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
/* check WriteProperty properties */ /* check WriteProperty properties */
wpdata.object_type = rpdata.object_type; wpdata.object_type = rpdata.object_type;
@@ -74,8 +77,8 @@ static void testColorObject(void)
status = Color_Write_Property(&wpdata); status = Color_Write_Property(&wpdata);
if (!status) { if (!status) {
/* verify WriteProperty property is known */ /* verify WriteProperty property is known */
zassert_not_equal(wpdata.error_code, zassert_not_equal(
ERROR_CODE_UNKNOWN_PROPERTY, wpdata.error_code, ERROR_CODE_UNKNOWN_PROPERTY,
"property '%s': WriteProperty Unknown!\n", "property '%s': WriteProperty Unknown!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
@@ -86,13 +89,16 @@ static void testColorObject(void)
rpdata.object_property = *pOptional; rpdata.object_property = *pOptional;
rpdata.array_index = BACNET_ARRAY_ALL; rpdata.array_index = BACNET_ARRAY_ALL;
len = Color_Read_Property(&rpdata); len = Color_Read_Property(&rpdata);
zassert_not_equal(len, BACNET_STATUS_ERROR, zassert_not_equal(
len, BACNET_STATUS_ERROR,
"property '%s': failed to ReadProperty!\n", "property '%s': failed to ReadProperty!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
if (len > 0) { if (len > 0) {
test_len = bacapp_decode_application_data(rpdata.application_data, test_len = bacapp_decode_application_data(
(uint8_t)rpdata.application_data_len, &value); rpdata.application_data, (uint8_t)rpdata.application_data_len,
zassert_equal(len, test_len, "property '%s': failed to decode!\n", &value);
zassert_equal(
len, test_len, "property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
/* check WriteProperty properties */ /* check WriteProperty properties */
wpdata.object_type = rpdata.object_type; wpdata.object_type = rpdata.object_type;
@@ -105,8 +111,8 @@ static void testColorObject(void)
status = Color_Write_Property(&wpdata); status = Color_Write_Property(&wpdata);
if (!status) { if (!status) {
/* verify WriteProperty property is known */ /* verify WriteProperty property is known */
zassert_not_equal(wpdata.error_code, zassert_not_equal(
ERROR_CODE_UNKNOWN_PROPERTY, wpdata.error_code, ERROR_CODE_UNKNOWN_PROPERTY,
"property '%s': WriteProperty Unknown!\n", "property '%s': WriteProperty Unknown!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
@@ -10,7 +10,6 @@
#include <bacnet/bactext.h> #include <bacnet/bactext.h>
#include <bacnet/basic/object/color_temperature.h> #include <bacnet/basic/object/color_temperature.h>
/** /**
* @addtogroup bacnet_tests * @addtogroup bacnet_tests
* @{ * @{
@@ -28,8 +27,8 @@ static void testColorTemperature(void)
uint8_t apdu[MAX_APDU] = { 0 }; uint8_t apdu[MAX_APDU] = { 0 };
int len = 0; int len = 0;
int test_len = 0; int test_len = 0;
BACNET_READ_PROPERTY_DATA rpdata = {0}; BACNET_READ_PROPERTY_DATA rpdata = { 0 };
BACNET_APPLICATION_DATA_VALUE value = {0}; BACNET_APPLICATION_DATA_VALUE value = { 0 };
const int *pRequired = NULL; const int *pRequired = NULL;
const int *pOptional = NULL; const int *pOptional = NULL;
const int *pProprietary = NULL; const int *pProprietary = NULL;
@@ -51,14 +50,17 @@ static void testColorTemperature(void)
rpdata.object_property = *pRequired; rpdata.object_property = *pRequired;
rpdata.array_index = BACNET_ARRAY_ALL; rpdata.array_index = BACNET_ARRAY_ALL;
len = Color_Temperature_Read_Property(&rpdata); len = Color_Temperature_Read_Property(&rpdata);
zassert_not_equal(len, BACNET_STATUS_ERROR, zassert_not_equal(
len, BACNET_STATUS_ERROR,
"property '%s': failed to ReadProperty!\n", "property '%s': failed to ReadProperty!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
if (len >= 0) { if (len >= 0) {
test_len = bacapp_decode_known_property(rpdata.application_data, test_len = bacapp_decode_known_property(
len, &value, rpdata.object_type, rpdata.object_property); rpdata.application_data, len, &value, rpdata.object_type,
zassert_equal(len, test_len, "property '%s': failed to decode!\n", rpdata.object_property);
bactext_property_name(rpdata.object_property)); zassert_equal(
len, test_len, "property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property));
/* check WriteProperty properties */ /* check WriteProperty properties */
wpdata.object_type = rpdata.object_type; wpdata.object_type = rpdata.object_type;
wpdata.object_instance = rpdata.object_instance; wpdata.object_instance = rpdata.object_instance;
@@ -70,8 +72,8 @@ static void testColorTemperature(void)
status = Color_Temperature_Write_Property(&wpdata); status = Color_Temperature_Write_Property(&wpdata);
if (!status) { if (!status) {
/* verify WriteProperty property is known */ /* verify WriteProperty property is known */
zassert_not_equal(wpdata.error_code, zassert_not_equal(
ERROR_CODE_UNKNOWN_PROPERTY, wpdata.error_code, ERROR_CODE_UNKNOWN_PROPERTY,
"property '%s': WriteProperty Unknown!\n", "property '%s': WriteProperty Unknown!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
@@ -82,15 +84,17 @@ static void testColorTemperature(void)
rpdata.object_property = *pOptional; rpdata.object_property = *pOptional;
rpdata.array_index = BACNET_ARRAY_ALL; rpdata.array_index = BACNET_ARRAY_ALL;
len = Color_Temperature_Read_Property(&rpdata); len = Color_Temperature_Read_Property(&rpdata);
zassert_not_equal(len, BACNET_STATUS_ERROR, zassert_not_equal(
len, BACNET_STATUS_ERROR,
"property '%s': failed to ReadProperty!\n", "property '%s': failed to ReadProperty!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
if (len > 0) { if (len > 0) {
test_len = bacapp_decode_application_data( test_len = bacapp_decode_application_data(
rpdata.application_data, rpdata.application_data, (uint8_t)rpdata.application_data_len,
(uint8_t)rpdata.application_data_len, &value); &value);
zassert_equal(len, test_len, "property '%s': failed to decode!\n", zassert_equal(
bactext_property_name(rpdata.object_property)); len, test_len, "property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property));
/* check WriteProperty properties */ /* check WriteProperty properties */
wpdata.object_type = rpdata.object_type; wpdata.object_type = rpdata.object_type;
wpdata.object_instance = rpdata.object_instance; wpdata.object_instance = rpdata.object_instance;
@@ -102,8 +106,8 @@ static void testColorTemperature(void)
status = Color_Temperature_Write_Property(&wpdata); status = Color_Temperature_Write_Property(&wpdata);
if (!status) { if (!status) {
/* verify WriteProperty property is known */ /* verify WriteProperty property is known */
zassert_not_equal(wpdata.error_code, zassert_not_equal(
ERROR_CODE_UNKNOWN_PROPERTY, wpdata.error_code, ERROR_CODE_UNKNOWN_PROPERTY,
"property '%s': WriteProperty Unknown!\n", "property '%s': WriteProperty Unknown!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
@@ -125,15 +129,13 @@ static void testColorTemperature(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(color_temperature_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(color_temperature_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(color_temperature_tests, ztest_test_suite(
ztest_unit_test(testColorTemperature) color_temperature_tests, ztest_unit_test(testColorTemperature));
);
ztest_run_test_suite(color_temperature_tests); ztest_run_test_suite(color_temperature_tests);
} }
+2 -6
View File
@@ -34,12 +34,8 @@ static void test_object_command(void)
zassert_true(count > 0, NULL); zassert_true(count > 0, NULL);
object_instance = Command_Index_To_Instance(0); object_instance = Command_Index_To_Instance(0);
bacnet_object_properties_read_write_test( bacnet_object_properties_read_write_test(
OBJECT_COMMAND, OBJECT_COMMAND, object_instance, Command_Property_Lists,
object_instance, Command_Read_Property, Command_Write_Property, skip_fail_property_list);
Command_Property_Lists,
Command_Read_Property,
Command_Write_Property,
skip_fail_property_list);
} }
/** /**
* @} * @}
@@ -27,37 +27,31 @@ static void testCredentialDataInput(void)
{ {
unsigned count = 0; unsigned count = 0;
uint32_t object_instance = 0; uint32_t object_instance = 0;
const int skip_fail_property_list[] = { const int skip_fail_property_list[] = { PROP_PRESENT_VALUE,
PROP_PRESENT_VALUE, PROP_UPDATE_TIME,
PROP_UPDATE_TIME, PROP_SUPPORTED_FORMATS, -1 };
PROP_SUPPORTED_FORMATS,
-1 };
Credential_Data_Input_Init(); Credential_Data_Input_Init();
count = Credential_Data_Input_Count(); count = Credential_Data_Input_Count();
zassert_true(count > 0, NULL); zassert_true(count > 0, NULL);
object_instance = Credential_Data_Input_Index_To_Instance(0); object_instance = Credential_Data_Input_Index_To_Instance(0);
bacnet_object_properties_read_write_test( bacnet_object_properties_read_write_test(
OBJECT_CREDENTIAL_DATA_INPUT, OBJECT_CREDENTIAL_DATA_INPUT, object_instance,
object_instance,
Credential_Data_Input_Property_Lists, Credential_Data_Input_Property_Lists,
Credential_Data_Input_Read_Property, Credential_Data_Input_Read_Property,
Credential_Data_Input_Write_Property, Credential_Data_Input_Write_Property, skip_fail_property_list);
skip_fail_property_list);
} }
/** /**
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(credential_data_input_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(credential_data_input_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(credential_data_input_tests, ztest_test_suite(
ztest_unit_test(testCredentialDataInput) credential_data_input_tests, ztest_unit_test(testCredentialDataInput));
);
ztest_run_test_suite(credential_data_input_tests); ztest_run_test_suite(credential_data_input_tests);
} }
+15 -9
View File
@@ -24,7 +24,7 @@ static void testCharacterString_Value(void)
uint8_t apdu[MAX_APDU] = { 0 }; uint8_t apdu[MAX_APDU] = { 0 };
int len = 0, test_len = 0; int len = 0, test_len = 0;
BACNET_READ_PROPERTY_DATA rpdata = { 0 }; BACNET_READ_PROPERTY_DATA rpdata = { 0 };
BACNET_APPLICATION_DATA_VALUE value = {0}; BACNET_APPLICATION_DATA_VALUE value = { 0 };
const int *pRequired = NULL; const int *pRequired = NULL;
const int *pOptional = NULL; const int *pOptional = NULL;
const int *pProprietary = NULL; const int *pProprietary = NULL;
@@ -47,10 +47,12 @@ static void testCharacterString_Value(void)
len = CharacterString_Value_Read_Property(&rpdata); len = CharacterString_Value_Read_Property(&rpdata);
zassert_true(len >= 0, NULL); zassert_true(len >= 0, NULL);
if (len >= 0) { if (len >= 0) {
test_len = bacapp_decode_known_property(rpdata.application_data, test_len = bacapp_decode_known_property(
len, &value, rpdata.object_type, rpdata.object_property); rpdata.application_data, len, &value, rpdata.object_type,
rpdata.object_property);
if (len != test_len) { if (len != test_len) {
printf("property '%s': failed to decode!\n", printf(
"property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
if (rpdata.object_property == PROP_PRIORITY_ARRAY) { if (rpdata.object_property == PROP_PRIORITY_ARRAY) {
@@ -59,7 +61,8 @@ static void testCharacterString_Value(void)
} }
zassert_equal(len, test_len, NULL); zassert_equal(len, test_len, NULL);
} else { } else {
printf("property '%s': failed to read!\n", printf(
"property '%s': failed to read!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
pRequired++; pRequired++;
@@ -70,15 +73,18 @@ static void testCharacterString_Value(void)
len = CharacterString_Value_Read_Property(&rpdata); len = CharacterString_Value_Read_Property(&rpdata);
zassert_not_equal(len, BACNET_STATUS_ERROR, NULL); zassert_not_equal(len, BACNET_STATUS_ERROR, NULL);
if (len > 0) { if (len > 0) {
test_len = bacapp_decode_application_data(rpdata.application_data, test_len = bacapp_decode_application_data(
(uint8_t)rpdata.application_data_len, &value); rpdata.application_data, (uint8_t)rpdata.application_data_len,
&value);
if (len != test_len) { if (len != test_len) {
printf("property '%s': failed to decode!\n", printf(
"property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
zassert_true(test_len >= 0, NULL); zassert_true(test_len >= 0, NULL);
} else { } else {
printf("property '%s': failed to read!\n", printf(
"property '%s': failed to read!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
pOptional++; pOptional++;
+46 -28
View File
@@ -48,18 +48,21 @@ static void test_Device_Data_Sharing(void)
rpdata.object_property = *pRequired; rpdata.object_property = *pRequired;
rpdata.array_index = BACNET_ARRAY_ALL; rpdata.array_index = BACNET_ARRAY_ALL;
len = Device_Read_Property(&rpdata); len = Device_Read_Property(&rpdata);
zassert_not_equal(len, BACNET_STATUS_ERROR, zassert_not_equal(
len, BACNET_STATUS_ERROR,
"property '%s': failed to ReadProperty!\n", "property '%s': failed to ReadProperty!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
if (len > 0) { if (len > 0) {
test_len = bacapp_decode_application_data(rpdata.application_data, test_len = bacapp_decode_application_data(
(uint8_t)rpdata.application_data_len, &value); rpdata.application_data, (uint8_t)rpdata.application_data_len,
&value);
if ((rpdata.object_property == PROP_PRIORITY_ARRAY) || if ((rpdata.object_property == PROP_PRIORITY_ARRAY) ||
(rpdata.object_property == PROP_OBJECT_LIST)) { (rpdata.object_property == PROP_OBJECT_LIST)) {
/* FIXME: known fail to decode */ /* FIXME: known fail to decode */
len = test_len; len = test_len;
} }
zassert_equal(test_len, len, "property '%s': failed to decode!\n", zassert_equal(
test_len, len, "property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
/* check WriteProperty properties */ /* check WriteProperty properties */
wpdata.object_type = rpdata.object_type; wpdata.object_type = rpdata.object_type;
@@ -72,8 +75,8 @@ static void test_Device_Data_Sharing(void)
status = Device_Write_Property(&wpdata); status = Device_Write_Property(&wpdata);
if (!status) { if (!status) {
/* verify WriteProperty property is known */ /* verify WriteProperty property is known */
zassert_not_equal(wpdata.error_code, zassert_not_equal(
ERROR_CODE_UNKNOWN_PROPERTY, wpdata.error_code, ERROR_CODE_UNKNOWN_PROPERTY,
"property '%s': WriteProperty Unknown!\n", "property '%s': WriteProperty Unknown!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
@@ -84,17 +87,21 @@ static void test_Device_Data_Sharing(void)
rpdata.object_property = *pOptional; rpdata.object_property = *pOptional;
rpdata.array_index = BACNET_ARRAY_ALL; rpdata.array_index = BACNET_ARRAY_ALL;
len = Device_Read_Property(&rpdata); len = Device_Read_Property(&rpdata);
zassert_not_equal(len, BACNET_STATUS_ERROR, zassert_not_equal(
len, BACNET_STATUS_ERROR,
"property '%s': failed to ReadProperty!\n", "property '%s': failed to ReadProperty!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
if (len > 0) { if (len > 0) {
test_len = bacapp_decode_application_data(rpdata.application_data, test_len = bacapp_decode_application_data(
(uint8_t)rpdata.application_data_len, &value); rpdata.application_data, (uint8_t)rpdata.application_data_len,
&value);
if (len != test_len) { if (len != test_len) {
printf("property '%s': failed to decode!\n", printf(
"property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
zassert_equal(test_len, len, "property '%s': failed to decode!\n", zassert_equal(
test_len, len, "property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
/* check WriteProperty properties */ /* check WriteProperty properties */
wpdata.object_type = rpdata.object_type; wpdata.object_type = rpdata.object_type;
@@ -107,8 +114,8 @@ static void test_Device_Data_Sharing(void)
status = Device_Write_Property(&wpdata); status = Device_Write_Property(&wpdata);
if (!status) { if (!status) {
/* verify WriteProperty property is known */ /* verify WriteProperty property is known */
zassert_not_equal(wpdata.error_code, zassert_not_equal(
ERROR_CODE_UNKNOWN_PROPERTY, wpdata.error_code, ERROR_CODE_UNKNOWN_PROPERTY,
"property '%s': WriteProperty Unknown!\n", "property '%s': WriteProperty Unknown!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
@@ -161,9 +168,11 @@ static void testDevice(void)
status = Device_Reinitialize_Password_Set(NULL); status = Device_Reinitialize_Password_Set(NULL);
status = Device_Reinitialize(&rd_data); status = Device_Reinitialize(&rd_data);
zassert_true(status, NULL); zassert_true(status, NULL);
zassert_equal(rd_data.error_class, ERROR_CLASS_DEVICE, "error-class=%s", zassert_equal(
rd_data.error_class, ERROR_CLASS_DEVICE, "error-class=%s",
bactext_error_class_name(rd_data.error_class)); bactext_error_class_name(rd_data.error_class));
zassert_equal(rd_data.error_code, ERROR_CODE_SUCCESS, "error-code=%s", zassert_equal(
rd_data.error_code, ERROR_CODE_SUCCESS, "error-code=%s",
bactext_error_code_name(rd_data.error_code)); bactext_error_code_name(rd_data.error_code));
/* Reinitialize with device valid password, service no password */ /* Reinitialize with device valid password, service no password */
status = Device_Reinitialize_Password_Set("valid"); status = Device_Reinitialize_Password_Set("valid");
@@ -172,19 +181,23 @@ static void testDevice(void)
zassert_true(status, NULL); zassert_true(status, NULL);
status = Device_Reinitialize(&rd_data); status = Device_Reinitialize(&rd_data);
zassert_false(status, NULL); zassert_false(status, NULL);
zassert_equal(rd_data.error_class, ERROR_CLASS_SECURITY, "error-class=%s", zassert_equal(
rd_data.error_class, ERROR_CLASS_SECURITY, "error-class=%s",
bactext_error_class_name(rd_data.error_class)); bactext_error_class_name(rd_data.error_class));
zassert_equal(rd_data.error_code, ERROR_CODE_PASSWORD_FAILURE, zassert_equal(
"error-code=%s", bactext_error_code_name(rd_data.error_code)); rd_data.error_code, ERROR_CODE_PASSWORD_FAILURE, "error-code=%s",
bactext_error_code_name(rd_data.error_code));
/* Reinitialize with device valid password, service invalid password */ /* Reinitialize with device valid password, service invalid password */
status = characterstring_init_ansi(&rd_data.password, "invalid"); status = characterstring_init_ansi(&rd_data.password, "invalid");
zassert_true(status, NULL); zassert_true(status, NULL);
status = Device_Reinitialize(&rd_data); status = Device_Reinitialize(&rd_data);
zassert_false(status, NULL); zassert_false(status, NULL);
zassert_equal(rd_data.error_class, ERROR_CLASS_SECURITY, "error-class=%s", zassert_equal(
rd_data.error_class, ERROR_CLASS_SECURITY, "error-class=%s",
bactext_error_class_name(rd_data.error_class)); bactext_error_class_name(rd_data.error_class));
zassert_equal(rd_data.error_code, ERROR_CODE_PASSWORD_FAILURE, zassert_equal(
"error-code=%s", bactext_error_code_name(rd_data.error_code)); rd_data.error_code, ERROR_CODE_PASSWORD_FAILURE, "error-code=%s",
bactext_error_code_name(rd_data.error_code));
/* Reinitialize with device valid password, service valid password */ /* Reinitialize with device valid password, service valid password */
characterstring_init_ansi(&rd_data.password, "valid"); characterstring_init_ansi(&rd_data.password, "valid");
status = Device_Reinitialize(&rd_data); status = Device_Reinitialize(&rd_data);
@@ -193,20 +206,24 @@ static void testDevice(void)
characterstring_init_ansi(&rd_data.password, "abcdefghijklmnopqrstuvwxyz"); characterstring_init_ansi(&rd_data.password, "abcdefghijklmnopqrstuvwxyz");
status = Device_Reinitialize(&rd_data); status = Device_Reinitialize(&rd_data);
zassert_false(status, NULL); zassert_false(status, NULL);
zassert_equal(rd_data.error_class, ERROR_CLASS_SERVICES, "error-class=%s", zassert_equal(
rd_data.error_class, ERROR_CLASS_SERVICES, "error-class=%s",
bactext_error_class_name(rd_data.error_class)); bactext_error_class_name(rd_data.error_class));
zassert_equal(rd_data.error_code, ERROR_CODE_PARAMETER_OUT_OF_RANGE, zassert_equal(
"error-code=%s", bactext_error_code_name(rd_data.error_code)); rd_data.error_code, ERROR_CODE_PARAMETER_OUT_OF_RANGE, "error-code=%s",
bactext_error_code_name(rd_data.error_code));
/* Reinitialize with device no password, unsupported state */ /* Reinitialize with device no password, unsupported state */
status = Device_Reinitialize_Password_Set(NULL); status = Device_Reinitialize_Password_Set(NULL);
zassert_true(status, NULL); zassert_true(status, NULL);
rd_data.state = BACNET_REINIT_MAX; rd_data.state = BACNET_REINIT_MAX;
status = Device_Reinitialize(&rd_data); status = Device_Reinitialize(&rd_data);
zassert_false(status, NULL); zassert_false(status, NULL);
zassert_equal(rd_data.error_class, ERROR_CLASS_SERVICES, "error-class=%s", zassert_equal(
rd_data.error_class, ERROR_CLASS_SERVICES, "error-class=%s",
bactext_error_class_name(rd_data.error_class)); bactext_error_class_name(rd_data.error_class));
zassert_equal(rd_data.error_code, ERROR_CODE_PARAMETER_OUT_OF_RANGE, zassert_equal(
"error-code=%s", bactext_error_code_name(rd_data.error_code)); rd_data.error_code, ERROR_CODE_PARAMETER_OUT_OF_RANGE, "error-code=%s",
bactext_error_code_name(rd_data.error_code));
return; return;
} }
@@ -219,7 +236,8 @@ ZTEST_SUITE(device_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(device_tests, ztest_unit_test(testDevice), ztest_test_suite(
device_tests, ztest_unit_test(testDevice),
ztest_unit_test(test_Device_Data_Sharing)); ztest_unit_test(test_Device_Data_Sharing));
ztest_run_test_suite(device_tests); ztest_run_test_suite(device_tests);
+8 -8
View File
@@ -36,22 +36,22 @@ void datetime_init(void)
} }
bool datetime_local( bool datetime_local(
BACNET_DATE * bdate, BACNET_DATE *bdate,
BACNET_TIME * btime, BACNET_TIME *btime,
int16_t * utc_offset_minutes, int16_t *utc_offset_minutes,
bool * dst_active) bool *dst_active)
{ {
return true; return true;
} }
void bip_get_my_address(BACNET_ADDRESS * my_address) void bip_get_my_address(BACNET_ADDRESS *my_address)
{ {
} }
int bip_send_pdu( int bip_send_pdu(
BACNET_ADDRESS * dest, BACNET_ADDRESS *dest,
BACNET_NPDU_DATA * npdu_data, BACNET_NPDU_DATA *npdu_data,
uint8_t * pdu, uint8_t *pdu,
unsigned pdu_len) unsigned pdu_len)
{ {
return 0; return 0;
+15 -9
View File
@@ -24,7 +24,7 @@ static void testInteger_Value(void)
uint8_t apdu[MAX_APDU] = { 0 }; uint8_t apdu[MAX_APDU] = { 0 };
int len = 0, test_len = 0; int len = 0, test_len = 0;
BACNET_READ_PROPERTY_DATA rpdata = { 0 }; BACNET_READ_PROPERTY_DATA rpdata = { 0 };
BACNET_APPLICATION_DATA_VALUE value = {0}; BACNET_APPLICATION_DATA_VALUE value = { 0 };
const int *pRequired = NULL; const int *pRequired = NULL;
const int *pOptional = NULL; const int *pOptional = NULL;
const int *pProprietary = NULL; const int *pProprietary = NULL;
@@ -47,10 +47,12 @@ static void testInteger_Value(void)
len = Integer_Value_Read_Property(&rpdata); len = Integer_Value_Read_Property(&rpdata);
zassert_true(len >= 0, NULL); zassert_true(len >= 0, NULL);
if (len >= 0) { if (len >= 0) {
test_len = bacapp_decode_known_property(rpdata.application_data, test_len = bacapp_decode_known_property(
len, &value, rpdata.object_type, rpdata.object_property); rpdata.application_data, len, &value, rpdata.object_type,
rpdata.object_property);
if (len != test_len) { if (len != test_len) {
printf("property '%s': failed to decode!\n", printf(
"property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
if (rpdata.object_property == PROP_PRIORITY_ARRAY) { if (rpdata.object_property == PROP_PRIORITY_ARRAY) {
@@ -59,7 +61,8 @@ static void testInteger_Value(void)
} }
zassert_equal(len, test_len, NULL); zassert_equal(len, test_len, NULL);
} else { } else {
printf("property '%s': failed to read!\n", printf(
"property '%s': failed to read!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
pRequired++; pRequired++;
@@ -70,15 +73,18 @@ static void testInteger_Value(void)
len = Integer_Value_Read_Property(&rpdata); len = Integer_Value_Read_Property(&rpdata);
zassert_not_equal(len, BACNET_STATUS_ERROR, NULL); zassert_not_equal(len, BACNET_STATUS_ERROR, NULL);
if (len > 0) { if (len > 0) {
test_len = bacapp_decode_application_data(rpdata.application_data, test_len = bacapp_decode_application_data(
(uint8_t)rpdata.application_data_len, &value); rpdata.application_data, (uint8_t)rpdata.application_data_len,
&value);
if (len != test_len) { if (len != test_len) {
printf("property '%s': failed to decode!\n", printf(
"property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
zassert_true(test_len >= 0, NULL); zassert_true(test_len >= 0, NULL);
} else { } else {
printf("property '%s': failed to read!\n", printf(
"property '%s': failed to read!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
pOptional++; pOptional++;
+147 -133
View File
@@ -21,7 +21,6 @@
#define MAX_LOAD_CONTROLS 4 #define MAX_LOAD_CONTROLS 4
#endif #endif
/** /**
* @addtogroup bacnet_tests * @addtogroup bacnet_tests
* @{ * @{
@@ -52,8 +51,8 @@ static void test_Load_Control_Count(void)
zassert_equal(Load_Control_Count(), MAX_LOAD_CONTROLS, NULL); zassert_equal(Load_Control_Count(), MAX_LOAD_CONTROLS, NULL);
} }
static void Load_Control_WriteProperty_Request_Shed_Level( static void
int instance, unsigned level) Load_Control_WriteProperty_Request_Shed_Level(int instance, unsigned level)
{ {
bool status = false; bool status = false;
BACNET_APPLICATION_DATA_VALUE value; BACNET_APPLICATION_DATA_VALUE value;
@@ -75,8 +74,7 @@ static void Load_Control_WriteProperty_Request_Shed_Level(
zassert_true(status, NULL); zassert_true(status, NULL);
} }
static void Load_Control_WriteProperty_Enable( static void Load_Control_WriteProperty_Enable(int instance, bool enable)
int instance, bool enable)
{ {
bool status = false; bool status = false;
BACNET_APPLICATION_DATA_VALUE value; BACNET_APPLICATION_DATA_VALUE value;
@@ -99,8 +97,8 @@ static void Load_Control_WriteProperty_Enable(
zassert_true(status, NULL); zassert_true(status, NULL);
} }
static void Load_Control_WriteProperty_Shed_Duration( static void
int instance, unsigned duration) Load_Control_WriteProperty_Shed_Duration(int instance, unsigned duration)
{ {
bool status = false; bool status = false;
BACNET_APPLICATION_DATA_VALUE value; BACNET_APPLICATION_DATA_VALUE value;
@@ -122,8 +120,8 @@ static void Load_Control_WriteProperty_Shed_Duration(
zassert_true(status, NULL); zassert_true(status, NULL);
} }
static void Load_Control_WriteProperty_Duty_Window( static void
int instance, unsigned duration) Load_Control_WriteProperty_Duty_Window(int instance, unsigned duration)
{ {
bool status = false; bool status = false;
BACNET_APPLICATION_DATA_VALUE value; BACNET_APPLICATION_DATA_VALUE value;
@@ -145,8 +143,7 @@ static void Load_Control_WriteProperty_Duty_Window(
zassert_true(status, NULL); zassert_true(status, NULL);
} }
static void Load_Control_WriteProperty_Start_Time_Wildcards( static void Load_Control_WriteProperty_Start_Time_Wildcards(int instance)
int instance)
{ {
int len = 0; int len = 0;
bool status = false; bool status = false;
@@ -220,18 +217,19 @@ ZTEST(lc_tests, testLoadControlStateMachine)
static void testLoadControlStateMachine(void) static void testLoadControlStateMachine(void)
#endif #endif
{ {
//TODO: unsigned i = 0, j = 0; // TODO: unsigned i = 0, j = 0;
uint8_t level = 0; uint8_t level = 0;
Load_Control_Init(); Load_Control_Init();
//TODO: /* validate the triggers for each state change */ // TODO: /* validate the triggers for each state change */
//TODO: for (j = 0; j < 20; j++) { // TODO: for (j = 0; j < 20; j++) {
//TODO: Load_Control_State_Machine(0); // TODO: Load_Control_State_Machine(0);
//TODO: for (i = 0; i < MAX_LOAD_CONTROLS; i++) { // TODO: for (i = 0; i < MAX_LOAD_CONTROLS; i++) {
//TODO: zassert_equal(Load_Control_State[i], SHED_INACTIVE, NULL); // TODO: zassert_equal(Load_Control_State[i], SHED_INACTIVE,
//TODO: } // NULL);
//TODO: } // TODO: }
// TODO: }
/* SHED_REQUEST_PENDING */ /* SHED_REQUEST_PENDING */
/* CancelShed - Start time has wildcards */ /* CancelShed - Start time has wildcards */
@@ -239,20 +237,22 @@ static void testLoadControlStateMachine(void)
Load_Control_WriteProperty_Shed_Duration(0, 60); Load_Control_WriteProperty_Shed_Duration(0, 60);
Load_Control_WriteProperty_Start_Time_Wildcards(0); Load_Control_WriteProperty_Start_Time_Wildcards(0);
Load_Control_State_Machine(0); Load_Control_State_Machine(0);
//TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL); // TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING,
// NULL);
Load_Control_State_Machine(0); Load_Control_State_Machine(0);
//TODO: zassert_equal(Load_Control_State[0], SHED_INACTIVE, NULL); // TODO: zassert_equal(Load_Control_State[0], SHED_INACTIVE, NULL);
/* CancelShed - Requested_Shed_Level equal to default value */ /* CancelShed - Requested_Shed_Level equal to default value */
Load_Control_Init(); Load_Control_Init();
Load_Control_WriteProperty_Request_Shed_Level(0, 0); Load_Control_WriteProperty_Request_Shed_Level(0, 0);
Load_Control_WriteProperty_Start_Time(0, 2007, 2, 27, 15, 0, 0, 0); Load_Control_WriteProperty_Start_Time(0, 2007, 2, 27, 15, 0, 0, 0);
Load_Control_WriteProperty_Shed_Duration(0, 5); Load_Control_WriteProperty_Shed_Duration(0, 5);
//TODO: datetime_set_values(&Current_Time, 2007, 2, 27, 15, 0, 0, 0); // TODO: datetime_set_values(&Current_Time, 2007, 2, 27, 15, 0, 0, 0);
Load_Control_State_Machine(0); Load_Control_State_Machine(0);
//TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL); // TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING,
// NULL);
Load_Control_State_Machine(0); Load_Control_State_Machine(0);
//TODO: zassert_equal(Load_Control_State[0], SHED_INACTIVE, NULL); // TODO: zassert_equal(Load_Control_State[0], SHED_INACTIVE, NULL);
/* CancelShed - Non-default values, but Start time is passed */ /* CancelShed - Non-default values, but Start time is passed */
Load_Control_Init(); Load_Control_Init();
@@ -260,11 +260,12 @@ static void testLoadControlStateMachine(void)
Load_Control_WriteProperty_Request_Shed_Level(0, 1); Load_Control_WriteProperty_Request_Shed_Level(0, 1);
Load_Control_WriteProperty_Shed_Duration(0, 5); Load_Control_WriteProperty_Shed_Duration(0, 5);
Load_Control_WriteProperty_Start_Time(0, 2007, 2, 27, 15, 0, 0, 0); Load_Control_WriteProperty_Start_Time(0, 2007, 2, 27, 15, 0, 0, 0);
//TODO: datetime_set_values(&Current_Time, 2007, 2, 28, 15, 0, 0, 0); // TODO: datetime_set_values(&Current_Time, 2007, 2, 28, 15, 0, 0, 0);
Load_Control_State_Machine(0); Load_Control_State_Machine(0);
//TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL); // TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING,
// NULL);
Load_Control_State_Machine(0); Load_Control_State_Machine(0);
//TODO: zassert_equal(Load_Control_State[0], SHED_INACTIVE, NULL); // TODO: zassert_equal(Load_Control_State[0], SHED_INACTIVE, NULL);
/* ReconfigurePending - new write received while pending */ /* ReconfigurePending - new write received while pending */
Load_Control_Init(); Load_Control_Init();
@@ -272,27 +273,35 @@ static void testLoadControlStateMachine(void)
Load_Control_WriteProperty_Request_Shed_Level(0, 1); Load_Control_WriteProperty_Request_Shed_Level(0, 1);
Load_Control_WriteProperty_Shed_Duration(0, 5); Load_Control_WriteProperty_Shed_Duration(0, 5);
Load_Control_WriteProperty_Start_Time(0, 2007, 2, 27, 15, 0, 0, 0); Load_Control_WriteProperty_Start_Time(0, 2007, 2, 27, 15, 0, 0, 0);
//TODO: datetime_set_values(&Current_Time, 2007, 2, 27, 5, 0, 0, 0); // TODO: datetime_set_values(&Current_Time, 2007, 2, 27, 5, 0, 0, 0);
Load_Control_State_Machine(0); Load_Control_State_Machine(0);
//TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL); // TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING,
// NULL);
Load_Control_State_Machine(0); Load_Control_State_Machine(0);
//TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL); // TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING,
// NULL);
Load_Control_WriteProperty_Request_Shed_Level(0, 2); Load_Control_WriteProperty_Request_Shed_Level(0, 2);
Load_Control_State_Machine(0); Load_Control_State_Machine(0);
//TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL); // TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING,
// NULL);
Load_Control_WriteProperty_Shed_Duration(0, 6); Load_Control_WriteProperty_Shed_Duration(0, 6);
Load_Control_State_Machine(0); Load_Control_State_Machine(0);
//TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL); // TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING,
// NULL);
Load_Control_WriteProperty_Duty_Window(0, 60); Load_Control_WriteProperty_Duty_Window(0, 60);
Load_Control_State_Machine(0); Load_Control_State_Machine(0);
//TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL); // TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING,
// NULL);
Load_Control_WriteProperty_Start_Time(0, 2007, 2, 27, 15, 0, 0, 1); Load_Control_WriteProperty_Start_Time(0, 2007, 2, 27, 15, 0, 0, 1);
Load_Control_State_Machine(0); Load_Control_State_Machine(0);
//TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL); // TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING,
// NULL);
Load_Control_State_Machine(0); Load_Control_State_Machine(0);
//TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL); // TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING,
// NULL);
Load_Control_State_Machine(0); Load_Control_State_Machine(0);
//TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL); // TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING,
// NULL);
/* CannotMeetShed -> FinishedUnsuccessfulShed */ /* CannotMeetShed -> FinishedUnsuccessfulShed */
Load_Control_Init(); Load_Control_Init();
@@ -300,22 +309,24 @@ static void testLoadControlStateMachine(void)
Load_Control_WriteProperty_Request_Shed_Level(0, 1); Load_Control_WriteProperty_Request_Shed_Level(0, 1);
Load_Control_WriteProperty_Shed_Duration(0, 120); Load_Control_WriteProperty_Shed_Duration(0, 120);
Load_Control_WriteProperty_Start_Time(0, 2007, 2, 27, 15, 0, 0, 0); Load_Control_WriteProperty_Start_Time(0, 2007, 2, 27, 15, 0, 0, 0);
//TODO: datetime_set_values(&Current_Time, 2007, 2, 27, 5, 0, 0, 0); // TODO: datetime_set_values(&Current_Time, 2007, 2, 27, 5, 0, 0, 0);
Load_Control_State_Machine(0); Load_Control_State_Machine(0);
//TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL); // TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING,
// NULL);
Load_Control_State_Machine(0); Load_Control_State_Machine(0);
//TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL); // TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING,
// NULL);
/* set to lowest value so we cannot meet the shed level */ /* set to lowest value so we cannot meet the shed level */
//TODO: datetime_set_values(&Current_Time, 2007, 2, 27, 16, 0, 0, 0); // TODO: datetime_set_values(&Current_Time, 2007, 2, 27, 16, 0, 0, 0);
Analog_Output_Present_Value_Set(0, 0, 16); Analog_Output_Present_Value_Set(0, 0, 16);
Load_Control_State_Machine(0); Load_Control_State_Machine(0);
//TODO: zassert_equal(Load_Control_State[0], SHED_NON_COMPLIANT, NULL); // TODO: zassert_equal(Load_Control_State[0], SHED_NON_COMPLIANT, NULL);
Load_Control_State_Machine(0); Load_Control_State_Machine(0);
//TODO: zassert_equal(Load_Control_State[0], SHED_NON_COMPLIANT, NULL); // TODO: zassert_equal(Load_Control_State[0], SHED_NON_COMPLIANT, NULL);
/* FinishedUnsuccessfulShed */ /* FinishedUnsuccessfulShed */
//TODO: datetime_set_values(&Current_Time, 2007, 2, 27, 23, 0, 0, 0); // TODO: datetime_set_values(&Current_Time, 2007, 2, 27, 23, 0, 0, 0);
Load_Control_State_Machine(0); Load_Control_State_Machine(0);
//TODO: zassert_equal(Load_Control_State[0], SHED_INACTIVE, NULL); // TODO: zassert_equal(Load_Control_State[0], SHED_INACTIVE, NULL);
/* CannotMeetShed -> UnsuccessfulShedReconfigured */ /* CannotMeetShed -> UnsuccessfulShedReconfigured */
Load_Control_Init(); Load_Control_Init();
@@ -323,44 +334,47 @@ static void testLoadControlStateMachine(void)
Load_Control_WriteProperty_Request_Shed_Level(0, 1); Load_Control_WriteProperty_Request_Shed_Level(0, 1);
Load_Control_WriteProperty_Shed_Duration(0, 120); Load_Control_WriteProperty_Shed_Duration(0, 120);
Load_Control_WriteProperty_Start_Time(0, 2007, 2, 27, 15, 0, 0, 0); Load_Control_WriteProperty_Start_Time(0, 2007, 2, 27, 15, 0, 0, 0);
//TODO: datetime_set_values(&Current_Time, 2007, 2, 27, 5, 0, 0, 0); // TODO: datetime_set_values(&Current_Time, 2007, 2, 27, 5, 0, 0, 0);
Load_Control_State_Machine(0); Load_Control_State_Machine(0);
//TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL); // TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING,
// NULL);
Load_Control_State_Machine(0); Load_Control_State_Machine(0);
//TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL); // TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING,
// NULL);
/* set to lowest value so we cannot meet the shed level */ /* set to lowest value so we cannot meet the shed level */
//TODO: datetime_set_values(&Current_Time, 2007, 2, 27, 16, 0, 0, 0); // TODO: datetime_set_values(&Current_Time, 2007, 2, 27, 16, 0, 0, 0);
Analog_Output_Present_Value_Set(0, 0, 16); Analog_Output_Present_Value_Set(0, 0, 16);
Load_Control_State_Machine(0); Load_Control_State_Machine(0);
//TODO: zassert_equal(Load_Control_State[0], SHED_NON_COMPLIANT, NULL); // TODO: zassert_equal(Load_Control_State[0], SHED_NON_COMPLIANT, NULL);
Load_Control_State_Machine(0); Load_Control_State_Machine(0);
//TODO: zassert_equal(Load_Control_State[0], SHED_NON_COMPLIANT, NULL); // TODO: zassert_equal(Load_Control_State[0], SHED_NON_COMPLIANT, NULL);
/* FinishedUnsuccessfulShed */ /* FinishedUnsuccessfulShed */
Load_Control_WriteProperty_Start_Time(0, 2007, 2, 27, 16, 0, 0, 0); Load_Control_WriteProperty_Start_Time(0, 2007, 2, 27, 16, 0, 0, 0);
Load_Control_State_Machine(0); Load_Control_State_Machine(0);
//TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL); // TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING,
// NULL);
Load_Control_State_Machine(0); Load_Control_State_Machine(0);
//TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING, NULL); // TODO: zassert_equal(Load_Control_State[0], SHED_REQUEST_PENDING,
//TODO: datetime_set_values(&Current_Time, 2007, 2, 27, 16, 0, 1, 0); // NULL);
// TODO: datetime_set_values(&Current_Time, 2007, 2, 27, 16, 0, 1, 0);
Load_Control_State_Machine(0); Load_Control_State_Machine(0);
//TODO: zassert_equal(Load_Control_State[0], SHED_NON_COMPLIANT, NULL); // TODO: zassert_equal(Load_Control_State[0], SHED_NON_COMPLIANT, NULL);
/* CanNowComplyWithShed */ /* CanNowComplyWithShed */
Analog_Output_Present_Value_Set(0, 100, 16); Analog_Output_Present_Value_Set(0, 100, 16);
//TODO: datetime_set_values(&Current_Time, 2007, 2, 27, 16, 0, 2, 0); // TODO: datetime_set_values(&Current_Time, 2007, 2, 27, 16, 0, 2, 0);
Load_Control_State_Machine(0); Load_Control_State_Machine(0);
//TODO: zassert_equal(Load_Control_State[0], SHED_COMPLIANT, NULL); // TODO: zassert_equal(Load_Control_State[0], SHED_COMPLIANT, NULL);
level = Analog_Output_Present_Value(0); level = Analog_Output_Present_Value(0);
//TODO: Fails: zassert_equal(level, 90, NULL); // TODO: Fails: zassert_equal(level, 90, NULL);
/* FinishedSuccessfulShed */ /* FinishedSuccessfulShed */
//TODO: datetime_set_values(&Current_Time, 2007, 2, 27, 23, 0, 0, 0); // TODO: datetime_set_values(&Current_Time, 2007, 2, 27, 23, 0, 0, 0);
Load_Control_State_Machine(0); Load_Control_State_Machine(0);
//TODO: zassert_equal(Load_Control_State[0], SHED_INACTIVE, NULL); // TODO: zassert_equal(Load_Control_State[0], SHED_INACTIVE, NULL);
level = Analog_Output_Present_Value(0); level = Analog_Output_Present_Value(0);
//TODO: Fails: zassert_equal(level, 100, NULL); // TODO: Fails: zassert_equal(level, 100, NULL);
(void)level; // TODO: remove when level will be checked (void)level; // TODO: remove when level will be checked
} }
#ifndef MAX_LOAD_CONTROLS #ifndef MAX_LOAD_CONTROLS
#define MAX_LOAD_CONTROLS (4) #define MAX_LOAD_CONTROLS (4)
#endif #endif
@@ -376,12 +390,18 @@ static void test_api_stubs(void)
zassert_equal(Load_Control_Count(), MAX_LOAD_CONTROLS, NULL); zassert_equal(Load_Control_Count(), MAX_LOAD_CONTROLS, NULL);
zassert_false(Load_Control_Valid_Instance(MAX_LOAD_CONTROLS), NULL); zassert_false(Load_Control_Valid_Instance(MAX_LOAD_CONTROLS), NULL);
zassert_equal(Load_Control_Index_To_Instance(MAX_LOAD_CONTROLS), Load_Control_Count(), NULL); zassert_equal(
zassert_equal(Load_Control_Instance_To_Index(MAX_LOAD_CONTROLS), Load_Control_Count(), NULL); Load_Control_Index_To_Instance(MAX_LOAD_CONTROLS), Load_Control_Count(),
NULL);
zassert_equal(
Load_Control_Instance_To_Index(MAX_LOAD_CONTROLS), Load_Control_Count(),
NULL);
zassert_false(Load_Control_Valid_Instance(UINT32_MAX), NULL); zassert_false(Load_Control_Valid_Instance(UINT32_MAX), NULL);
zassert_equal(Load_Control_Index_To_Instance(UINT32_MAX), Load_Control_Count(), NULL); zassert_equal(
zassert_equal(Load_Control_Instance_To_Index(UINT32_MAX), Load_Control_Count(), NULL); Load_Control_Index_To_Instance(UINT32_MAX), Load_Control_Count(), NULL);
zassert_equal(
Load_Control_Instance_To_Index(UINT32_MAX), Load_Control_Count(), NULL);
zassert_true(Load_Control_Valid_Instance(0), NULL); zassert_true(Load_Control_Valid_Instance(0), NULL);
zassert_equal(Load_Control_Index_To_Instance(0), 0, NULL); zassert_equal(Load_Control_Index_To_Instance(0), 0, NULL);
@@ -390,7 +410,6 @@ static void test_api_stubs(void)
zassert_false(Load_Control_Object_Name(0, NULL), NULL); zassert_false(Load_Control_Object_Name(0, NULL), NULL);
zassert_false(Load_Control_Object_Name(UINT32_MAX, &object_name_st), NULL); zassert_false(Load_Control_Object_Name(UINT32_MAX, &object_name_st), NULL);
zassert_true(Load_Control_Object_Name(0, &object_name_st), NULL); zassert_true(Load_Control_Object_Name(0, &object_name_st), NULL);
zassert_true(characterstring_valid(&object_name_st), NULL); zassert_true(characterstring_valid(&object_name_st), NULL);
zassert_true(characterstring_printable(&object_name_st), NULL); zassert_true(characterstring_printable(&object_name_st), NULL);
@@ -414,7 +433,6 @@ static void test_Load_Control_Read_Write_Property(void)
unsigned count = 0; unsigned count = 0;
uint32_t object_instance = 0; uint32_t object_instance = 0;
zassert_equal(Load_Control_Read_Property(NULL), 0, NULL); zassert_equal(Load_Control_Read_Property(NULL), 0, NULL);
zassert_false(Load_Control_Write_Property(NULL), NULL); zassert_false(Load_Control_Write_Property(NULL), NULL);
@@ -428,58 +446,57 @@ static void test_Load_Control_Read_Write_Property(void)
rpdata.object_instance = object_instance; rpdata.object_instance = object_instance;
Load_Control_Property_Lists(&pRequired, &pOptional, &pProprietary); Load_Control_Property_Lists(&pRequired, &pOptional, &pProprietary);
while ((*pRequired) != -1) { while ((*pRequired) != -1) {
rpdata.object_property = *pRequired; rpdata.object_property = *pRequired;
rpdata.array_index = BACNET_ARRAY_ALL; rpdata.array_index = BACNET_ARRAY_ALL;
len = Load_Control_Read_Property(&rpdata); len = Load_Control_Read_Property(&rpdata);
zassert_not_equal(len, BACNET_STATUS_ERROR, NULL); zassert_not_equal(len, BACNET_STATUS_ERROR, NULL);
if (len > 0) { if (len > 0) {
test_len = bacapp_decode_application_data( test_len = bacapp_decode_application_data(
rpdata.application_data, rpdata.application_data, (uint8_t)rpdata.application_data_len,
(uint8_t)rpdata.application_data_len, &value); &value);
zassert_true(test_len >= 0, NULL); zassert_true(test_len >= 0, NULL);
} }
pRequired++; pRequired++;
} }
while ((*pOptional) != -1) { while ((*pOptional) != -1) {
rpdata.object_property = *pOptional; rpdata.object_property = *pOptional;
rpdata.array_index = BACNET_ARRAY_ALL; rpdata.array_index = BACNET_ARRAY_ALL;
len = Load_Control_Read_Property(&rpdata); len = Load_Control_Read_Property(&rpdata);
zassert_not_equal(len, BACNET_STATUS_ERROR, NULL); zassert_not_equal(len, BACNET_STATUS_ERROR, NULL);
if (len > 0) { if (len > 0) {
test_len = bacapp_decode_application_data( test_len = bacapp_decode_application_data(
rpdata.application_data, rpdata.application_data, (uint8_t)rpdata.application_data_len,
(uint8_t)rpdata.application_data_len, &value); &value);
zassert_true(test_len >= 0, NULL); zassert_true(test_len >= 0, NULL);
} }
pOptional++; pOptional++;
} }
} }
static bool init_wp_data_and_value( static bool init_wp_data_and_value(
BACNET_WRITE_PROPERTY_DATA *wp_data, BACNET_WRITE_PROPERTY_DATA *wp_data, BACNET_APPLICATION_DATA_VALUE *value)
BACNET_APPLICATION_DATA_VALUE * value)
{ {
bool status = false; bool status = false;
if ((wp_data != NULL) && (value != NULL)) if ((wp_data != NULL) && (value != NULL)) {
{ memset(value, 0, sizeof(*value));
memset(value, 0, sizeof(*value)); memset(wp_data, 0, sizeof(*wp_data));
memset(wp_data, 0, sizeof(*wp_data));
wp_data->object_type = OBJECT_LOAD_CONTROL; wp_data->object_type = OBJECT_LOAD_CONTROL;
wp_data->object_instance = 0; wp_data->object_instance = 0;
wp_data->array_index = BACNET_ARRAY_ALL; wp_data->array_index = BACNET_ARRAY_ALL;
wp_data->priority = BACNET_NO_PRIORITY; wp_data->priority = BACNET_NO_PRIORITY;
wp_data->object_property = PROP_SHED_DURATION; wp_data->object_property = PROP_SHED_DURATION;
value->context_specific = false; value->context_specific = false;
value->context_tag = 0; value->context_tag = 0;
value->tag = BACNET_APPLICATION_TAG_UNSIGNED_INT; value->tag = BACNET_APPLICATION_TAG_UNSIGNED_INT;
value->type.Unsigned_Int = 0; /* duration */ value->type.Unsigned_Int = 0; /* duration */
wp_data->application_data_len = bacapp_encode_application_data(&wp_data->application_data[0], value); wp_data->application_data_len = bacapp_encode_application_data(
zassert_true(wp_data->application_data_len >= 0, NULL); &wp_data->application_data[0], value);
zassert_equal(wp_data->error_class, 0, NULL); zassert_true(wp_data->application_data_len >= 0, NULL);
zassert_equal(wp_data->error_code, 0, NULL); zassert_equal(wp_data->error_class, 0, NULL);
zassert_equal(wp_data->error_code, 0, NULL);
status = true; status = true;
} }
return status; return status;
@@ -513,12 +530,11 @@ static void test_ShedInactive_gets_RcvShedRequests(void)
zassert_equal(wp_data.error_class, ERROR_CLASS_PROPERTY, NULL); zassert_equal(wp_data.error_class, ERROR_CLASS_PROPERTY, NULL);
zassert_equal(wp_data.error_code, ERROR_CODE_VALUE_OUT_OF_RANGE, NULL); zassert_equal(wp_data.error_code, ERROR_CODE_VALUE_OUT_OF_RANGE, NULL);
/* Verify calls to dependencies are properly made */ /* Verify calls to dependencies are properly made */
// object_property == PROP_REQUESTED_SHED_LEVEL calls bacapp_decode_context_data() // object_property == PROP_REQUESTED_SHED_LEVEL calls
// object_property == PROP_START_TIME calls bacapp_decode_application_data() // bacapp_decode_context_data() object_property == PROP_START_TIME calls
// object_property == PROP_SHED_DURATION calls nothing // bacapp_decode_application_data() object_property == PROP_SHED_DURATION
// object_property == PROP_DUTY_WINDOW calls nothing // calls nothing object_property == PROP_DUTY_WINDOW calls nothing
// object_property == PROP_SHED_LEVELS calls nothing // object_property == PROP_SHED_LEVELS calls nothing
// object_property == PROP_ENABLE calls nothing // object_property == PROP_ENABLE calls nothing
// default returns error // default returns error
@@ -649,30 +665,28 @@ static void test_ShedCommpliant_gets_CanNoLongerComplyWithShed(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(lc_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(lc_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(lc_tests, ztest_test_suite(
ztest_unit_test(test_api_stubs), lc_tests, ztest_unit_test(test_api_stubs),
ztest_unit_test(test_Load_Control_Count), ztest_unit_test(test_Load_Control_Count),
ztest_unit_test(test_Load_Control_Read_Write_Property), ztest_unit_test(test_Load_Control_Read_Write_Property),
ztest_unit_test(testLoadControlStateMachine), ztest_unit_test(testLoadControlStateMachine),
ztest_unit_test(test_ShedInactive_gets_RcvShedRequests), ztest_unit_test(test_ShedInactive_gets_RcvShedRequests),
ztest_unit_test(test_ShedReqPending_gets_ReconfigPending), ztest_unit_test(test_ShedReqPending_gets_ReconfigPending),
ztest_unit_test(test_ShedReqPending_gets_CancelShed), ztest_unit_test(test_ShedReqPending_gets_CancelShed),
ztest_unit_test(test_ShedReqPending_gets_CannotMeetShed), ztest_unit_test(test_ShedReqPending_gets_CannotMeetShed),
ztest_unit_test(test_ShedReqPending_gets_PrepareToShed), ztest_unit_test(test_ShedReqPending_gets_PrepareToShed),
ztest_unit_test(test_ShedReqPending_gets_AbleToMeetShed), ztest_unit_test(test_ShedReqPending_gets_AbleToMeetShed),
ztest_unit_test(test_ShedNonCommpliant_gets_UnsuccessfulShedReconfig), ztest_unit_test(test_ShedNonCommpliant_gets_UnsuccessfulShedReconfig),
ztest_unit_test(test_ShedNonCommpliant_gets_FinishedUnsuccessfulShed), ztest_unit_test(test_ShedNonCommpliant_gets_FinishedUnsuccessfulShed),
ztest_unit_test(test_ShedNonCommpliant_gets_CanNowComplyWithShed), ztest_unit_test(test_ShedNonCommpliant_gets_CanNowComplyWithShed),
ztest_unit_test(test_ShedCommpliant_gets_FinishedSuccessfulShed), ztest_unit_test(test_ShedCommpliant_gets_FinishedSuccessfulShed),
ztest_unit_test(test_ShedCommpliant_gets_SuccessfulShedReconfig), ztest_unit_test(test_ShedCommpliant_gets_SuccessfulShedReconfig),
ztest_unit_test(test_ShedCommpliant_gets_CanNoLongerComplyWithShed) ztest_unit_test(test_ShedCommpliant_gets_CanNoLongerComplyWithShed));
);
ztest_run_test_suite(lc_tests); ztest_run_test_suite(lc_tests);
} }
+4 -4
View File
@@ -35,10 +35,10 @@ void datetime_init(void)
} }
bool datetime_local( bool datetime_local(
BACNET_DATE * bdate, BACNET_DATE *bdate,
BACNET_TIME * btime, BACNET_TIME *btime,
int16_t * utc_offset_minutes, int16_t *utc_offset_minutes,
bool * dst_active) bool *dst_active)
{ {
return true; return true;
} }
+22 -19
View File
@@ -29,7 +29,7 @@ static void testLightingOutput(void)
uint8_t apdu[MAX_APDU] = { 0 }; uint8_t apdu[MAX_APDU] = { 0 };
int len = 0, test_len = 0; int len = 0, test_len = 0;
BACNET_READ_PROPERTY_DATA rpdata; BACNET_READ_PROPERTY_DATA rpdata;
BACNET_APPLICATION_DATA_VALUE value = {0}; BACNET_APPLICATION_DATA_VALUE value = { 0 };
const int *pRequired = NULL; const int *pRequired = NULL;
const int *pOptional = NULL; const int *pOptional = NULL;
const int *pProprietary = NULL; const int *pProprietary = NULL;
@@ -57,15 +57,18 @@ static void testLightingOutput(void)
rpdata.object_property = *pRequired; rpdata.object_property = *pRequired;
rpdata.array_index = BACNET_ARRAY_ALL; rpdata.array_index = BACNET_ARRAY_ALL;
len = Lighting_Output_Read_Property(&rpdata); len = Lighting_Output_Read_Property(&rpdata);
zassert_not_equal(len, BACNET_STATUS_ERROR, zassert_not_equal(
len, BACNET_STATUS_ERROR,
"property '%s': failed to ReadProperty!\n", "property '%s': failed to ReadProperty!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
if (len >= 0) { if (len >= 0) {
test_len = bacapp_decode_known_property(rpdata.application_data, test_len = bacapp_decode_known_property(
len, &value, rpdata.object_type, rpdata.object_property); rpdata.application_data, len, &value, rpdata.object_type,
rpdata.object_property);
if (rpdata.object_property != PROP_PRIORITY_ARRAY) { if (rpdata.object_property != PROP_PRIORITY_ARRAY) {
zassert_equal(len, test_len, "property '%s': failed to decode!\n", zassert_equal(
bactext_property_name(rpdata.object_property)); len, test_len, "property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property));
} }
/* check WriteProperty properties */ /* check WriteProperty properties */
wpdata.object_type = rpdata.object_type; wpdata.object_type = rpdata.object_type;
@@ -78,8 +81,8 @@ static void testLightingOutput(void)
status = Lighting_Output_Write_Property(&wpdata); status = Lighting_Output_Write_Property(&wpdata);
if (!status) { if (!status) {
/* verify WriteProperty property is known */ /* verify WriteProperty property is known */
zassert_not_equal(wpdata.error_code, zassert_not_equal(
ERROR_CODE_UNKNOWN_PROPERTY, wpdata.error_code, ERROR_CODE_UNKNOWN_PROPERTY,
"property '%s': WriteProperty Unknown!\n", "property '%s': WriteProperty Unknown!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
@@ -90,14 +93,17 @@ static void testLightingOutput(void)
rpdata.object_property = *pOptional; rpdata.object_property = *pOptional;
rpdata.array_index = BACNET_ARRAY_ALL; rpdata.array_index = BACNET_ARRAY_ALL;
len = Lighting_Output_Read_Property(&rpdata); len = Lighting_Output_Read_Property(&rpdata);
zassert_not_equal(len, BACNET_STATUS_ERROR, zassert_not_equal(
len, BACNET_STATUS_ERROR,
"property '%s': failed to ReadProperty!\n", "property '%s': failed to ReadProperty!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
if (len > 0) { if (len > 0) {
test_len = bacapp_decode_application_data(rpdata.application_data, test_len = bacapp_decode_application_data(
(uint8_t)rpdata.application_data_len, &value); rpdata.application_data, (uint8_t)rpdata.application_data_len,
zassert_equal(len, test_len, "property '%s': failed to decode!\n", &value);
bactext_property_name(rpdata.object_property)); zassert_equal(
len, test_len, "property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property));
/* check WriteProperty properties */ /* check WriteProperty properties */
wpdata.object_type = rpdata.object_type; wpdata.object_type = rpdata.object_type;
wpdata.object_instance = rpdata.object_instance; wpdata.object_instance = rpdata.object_instance;
@@ -109,8 +115,8 @@ static void testLightingOutput(void)
status = Lighting_Output_Write_Property(&wpdata); status = Lighting_Output_Write_Property(&wpdata);
if (!status) { if (!status) {
/* verify WriteProperty property is known */ /* verify WriteProperty property is known */
zassert_not_equal(wpdata.error_code, zassert_not_equal(
ERROR_CODE_UNKNOWN_PROPERTY, wpdata.error_code, ERROR_CODE_UNKNOWN_PROPERTY,
"property '%s': WriteProperty Unknown!\n", "property '%s': WriteProperty Unknown!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
@@ -135,15 +141,12 @@ static void testLightingOutput(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(lo_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(lo_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(lo_tests, ztest_test_suite(lo_tests, ztest_unit_test(testLightingOutput));
ztest_unit_test(testLightingOutput)
);
ztest_run_test_suite(lo_tests); ztest_run_test_suite(lo_tests);
} }
+19 -16
View File
@@ -58,14 +58,17 @@ static void testLifeSafetyPoint(void)
rpdata.object_property = *pRequired; rpdata.object_property = *pRequired;
rpdata.array_index = BACNET_ARRAY_ALL; rpdata.array_index = BACNET_ARRAY_ALL;
len = Life_Safety_Point_Read_Property(&rpdata); len = Life_Safety_Point_Read_Property(&rpdata);
zassert_not_equal(len, BACNET_STATUS_ERROR, zassert_not_equal(
len, BACNET_STATUS_ERROR,
"property '%s': failed to ReadProperty!\n", "property '%s': failed to ReadProperty!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
if (len >= 0) { if (len >= 0) {
test_len = bacapp_decode_known_property(rpdata.application_data, test_len = bacapp_decode_known_property(
len, &value, rpdata.object_type, rpdata.object_property); rpdata.application_data, len, &value, rpdata.object_type,
rpdata.object_property);
if (len != test_len) { if (len != test_len) {
printf("property '%s': failed to decode!\n", printf(
"property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} else { } else {
zassert_equal(len, test_len, NULL); zassert_equal(len, test_len, NULL);
@@ -81,8 +84,8 @@ static void testLifeSafetyPoint(void)
status = Life_Safety_Point_Write_Property(&wpdata); status = Life_Safety_Point_Write_Property(&wpdata);
if (!status) { if (!status) {
/* verify WriteProperty property is known */ /* verify WriteProperty property is known */
zassert_not_equal(wpdata.error_code, zassert_not_equal(
ERROR_CODE_UNKNOWN_PROPERTY, wpdata.error_code, ERROR_CODE_UNKNOWN_PROPERTY,
"property '%s': WriteProperty Unknown!\n", "property '%s': WriteProperty Unknown!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
@@ -93,13 +96,16 @@ static void testLifeSafetyPoint(void)
rpdata.object_property = *pOptional; rpdata.object_property = *pOptional;
rpdata.array_index = BACNET_ARRAY_ALL; rpdata.array_index = BACNET_ARRAY_ALL;
len = Life_Safety_Point_Read_Property(&rpdata); len = Life_Safety_Point_Read_Property(&rpdata);
zassert_not_equal(len, BACNET_STATUS_ERROR, zassert_not_equal(
len, BACNET_STATUS_ERROR,
"property '%s': failed to ReadProperty!\n", "property '%s': failed to ReadProperty!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
if (len > 0) { if (len > 0) {
test_len = bacapp_decode_application_data(rpdata.application_data, test_len = bacapp_decode_application_data(
(uint8_t)rpdata.application_data_len, &value); rpdata.application_data, (uint8_t)rpdata.application_data_len,
zassert_equal(len, test_len, "property '%s': failed to decode!\n", &value);
zassert_equal(
len, test_len, "property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
/* check WriteProperty properties */ /* check WriteProperty properties */
wpdata.object_type = rpdata.object_type; wpdata.object_type = rpdata.object_type;
@@ -112,8 +118,8 @@ static void testLifeSafetyPoint(void)
status = Life_Safety_Point_Write_Property(&wpdata); status = Life_Safety_Point_Write_Property(&wpdata);
if (!status) { if (!status) {
/* verify WriteProperty property is known */ /* verify WriteProperty property is known */
zassert_not_equal(wpdata.error_code, zassert_not_equal(
ERROR_CODE_UNKNOWN_PROPERTY, wpdata.error_code, ERROR_CODE_UNKNOWN_PROPERTY,
"property '%s': WriteProperty Unknown!\n", "property '%s': WriteProperty Unknown!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
@@ -135,15 +141,12 @@ static void testLifeSafetyPoint(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(lsp_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(lsp_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(lsp_tests, ztest_test_suite(lsp_tests, ztest_unit_test(testLifeSafetyPoint));
ztest_unit_test(testLifeSafetyPoint)
);
ztest_run_test_suite(lsp_tests); ztest_run_test_suite(lsp_tests);
} }
+4 -9
View File
@@ -39,12 +39,9 @@ static void testLifeSafetyZone(void)
test_object_instance = Life_Safety_Zone_Index_To_Instance(0); test_object_instance = Life_Safety_Zone_Index_To_Instance(0);
zassert_equal(test_object_instance, object_instance, NULL); zassert_equal(test_object_instance, object_instance, NULL);
bacnet_object_properties_read_write_test( bacnet_object_properties_read_write_test(
OBJECT_LIFE_SAFETY_ZONE, OBJECT_LIFE_SAFETY_ZONE, object_instance,
object_instance, Life_Safety_Zone_Property_Lists, Life_Safety_Zone_Read_Property,
Life_Safety_Zone_Property_Lists, Life_Safety_Zone_Write_Property, skip_fail_property_list);
Life_Safety_Zone_Read_Property,
Life_Safety_Zone_Write_Property,
skip_fail_property_list);
} }
/** /**
* @} * @}
@@ -55,9 +52,7 @@ ZTEST_SUITE(testsLifeSafetyZone, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(testsLifeSafetyZone, ztest_test_suite(testsLifeSafetyZone, ztest_unit_test(testLifeSafetyZone));
ztest_unit_test(testLifeSafetyZone)
);
ztest_run_test_suite(testsLifeSafetyZone); ztest_run_test_suite(testsLifeSafetyZone);
} }
+7 -15
View File
@@ -10,11 +10,10 @@
#include <bacnet/bactext.h> #include <bacnet/bactext.h>
#include <bacnet/basic/object/device.h> #include <bacnet/basic/object/device.h>
bool Device_Valid_Object_Name( bool Device_Valid_Object_Name(
BACNET_CHARACTER_STRING * object_name, BACNET_CHARACTER_STRING *object_name,
BACNET_OBJECT_TYPE *object_type, BACNET_OBJECT_TYPE *object_type,
uint32_t * object_instance) uint32_t *object_instance)
{ {
(void)object_name; (void)object_name;
(void)object_type; (void)object_type;
@@ -22,35 +21,28 @@ bool Device_Valid_Object_Name(
return true; return true;
} }
void Device_Inc_Database_Revision( void Device_Inc_Database_Revision(void)
void)
{ {
} }
uint32_t Device_Object_Instance_Number( uint32_t Device_Object_Instance_Number(void)
void)
{ {
return 0; return 0;
} }
bool Device_Write_Property( bool Device_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
BACNET_WRITE_PROPERTY_DATA * wp_data)
{ {
(void)wp_data; (void)wp_data;
return false; return false;
} }
void Device_getCurrentDateTime( void Device_getCurrentDateTime(BACNET_DATE_TIME *DateTime)
BACNET_DATE_TIME * DateTime)
{ {
(void)DateTime; (void)DateTime;
} }
int Device_Read_Property( int Device_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
BACNET_READ_PROPERTY_DATA * rpdata)
{ {
(void)rpdata; (void)rpdata;
return 0; return 0;
} }
+4 -4
View File
@@ -11,10 +11,10 @@
bool tsm_get_transaction_pdu( bool tsm_get_transaction_pdu(
uint8_t invokeID, uint8_t invokeID,
BACNET_ADDRESS * dest, BACNET_ADDRESS *dest,
BACNET_NPDU_DATA * ndpu_data, BACNET_NPDU_DATA *ndpu_data,
uint8_t * apdu, uint8_t *apdu,
uint16_t * apdu_len) uint16_t *apdu_len)
{ {
(void)invokeID; (void)invokeID;
(void)dest; (void)dest;
+4 -10
View File
@@ -38,12 +38,9 @@ static void testMultistateInput(void)
test_object_instance = Multistate_Input_Index_To_Instance(0); test_object_instance = Multistate_Input_Index_To_Instance(0);
zassert_equal(object_instance, test_object_instance, NULL); zassert_equal(object_instance, test_object_instance, NULL);
bacnet_object_properties_read_write_test( bacnet_object_properties_read_write_test(
OBJECT_MULTI_STATE_INPUT, OBJECT_MULTI_STATE_INPUT, object_instance,
object_instance, Multistate_Input_Property_Lists, Multistate_Input_Read_Property,
Multistate_Input_Property_Lists, Multistate_Input_Write_Property, skip_fail_property_list);
Multistate_Input_Read_Property,
Multistate_Input_Write_Property,
skip_fail_property_list);
status = Multistate_Input_Delete(object_instance); status = Multistate_Input_Delete(object_instance);
zassert_true(status, NULL); zassert_true(status, NULL);
} }
@@ -51,15 +48,12 @@ static void testMultistateInput(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(ms_input_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(ms_input_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(ms_input_tests, ztest_test_suite(ms_input_tests, ztest_unit_test(testMultistateInput));
ztest_unit_test(testMultistateInput)
);
ztest_run_test_suite(ms_input_tests); ztest_run_test_suite(ms_input_tests);
} }
+4 -10
View File
@@ -37,12 +37,9 @@ static void testMultistateOutput(void)
test_object_instance = Multistate_Output_Index_To_Instance(0); test_object_instance = Multistate_Output_Index_To_Instance(0);
zassert_equal(object_instance, test_object_instance, NULL); zassert_equal(object_instance, test_object_instance, NULL);
bacnet_object_properties_read_write_test( bacnet_object_properties_read_write_test(
OBJECT_MULTI_STATE_OUTPUT, OBJECT_MULTI_STATE_OUTPUT, object_instance,
object_instance, Multistate_Output_Property_Lists, Multistate_Output_Read_Property,
Multistate_Output_Property_Lists, Multistate_Output_Write_Property, skip_fail_property_list);
Multistate_Output_Read_Property,
Multistate_Output_Write_Property,
skip_fail_property_list);
status = Multistate_Output_Delete(object_instance); status = Multistate_Output_Delete(object_instance);
zassert_true(status, NULL); zassert_true(status, NULL);
} }
@@ -50,15 +47,12 @@ static void testMultistateOutput(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(mso_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(mso_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(mso_tests, ztest_test_suite(mso_tests, ztest_unit_test(testMultistateOutput));
ztest_unit_test(testMultistateOutput)
);
ztest_run_test_suite(mso_tests); ztest_run_test_suite(mso_tests);
} }
+4 -10
View File
@@ -38,12 +38,9 @@ static void testMultistateValue(void)
test_object_instance = Multistate_Value_Index_To_Instance(0); test_object_instance = Multistate_Value_Index_To_Instance(0);
zassert_equal(object_instance, test_object_instance, NULL); zassert_equal(object_instance, test_object_instance, NULL);
bacnet_object_properties_read_write_test( bacnet_object_properties_read_write_test(
OBJECT_MULTI_STATE_VALUE, OBJECT_MULTI_STATE_VALUE, object_instance,
object_instance, Multistate_Value_Property_Lists, Multistate_Value_Read_Property,
Multistate_Value_Property_Lists, Multistate_Value_Write_Property, skip_fail_property_list);
Multistate_Value_Read_Property,
Multistate_Value_Write_Property,
skip_fail_property_list);
status = Multistate_Value_Delete(object_instance); status = Multistate_Value_Delete(object_instance);
zassert_true(status, NULL); zassert_true(status, NULL);
} }
@@ -51,15 +48,12 @@ static void testMultistateValue(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(msv_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(msv_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(msv_tests, ztest_test_suite(msv_tests, ztest_unit_test(testMultistateValue));
ztest_unit_test(testMultistateValue)
);
ztest_run_test_suite(msv_tests); ztest_run_test_suite(msv_tests);
} }
+21 -17
View File
@@ -56,16 +56,19 @@ static void test_Notification_Class(void)
rpdata.object_property = *pRequired; rpdata.object_property = *pRequired;
rpdata.array_index = BACNET_ARRAY_ALL; rpdata.array_index = BACNET_ARRAY_ALL;
len = Notification_Class_Read_Property(&rpdata); len = Notification_Class_Read_Property(&rpdata);
zassert_not_equal(len, BACNET_STATUS_ERROR, zassert_not_equal(
len, BACNET_STATUS_ERROR,
"property '%s': failed to ReadProperty!\n", "property '%s': failed to ReadProperty!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
if (len >= 0) { if (len >= 0) {
test_len = bacapp_decode_known_property(rpdata.application_data, test_len = bacapp_decode_known_property(
len, &value, rpdata.object_type, rpdata.object_property); rpdata.application_data, len, &value, rpdata.object_type,
rpdata.object_property);
if ((rpdata.object_property != PROP_PRIORITY) && if ((rpdata.object_property != PROP_PRIORITY) &&
(rpdata.object_property != PROP_RECIPIENT_LIST)) { (rpdata.object_property != PROP_RECIPIENT_LIST)) {
zassert_equal(len, test_len, "property '%s': failed to decode!\n", zassert_equal(
bactext_property_name(rpdata.object_property)); len, test_len, "property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property));
} }
/* check WriteProperty properties */ /* check WriteProperty properties */
wpdata.object_type = rpdata.object_type; wpdata.object_type = rpdata.object_type;
@@ -78,8 +81,8 @@ static void test_Notification_Class(void)
status = Notification_Class_Write_Property(&wpdata); status = Notification_Class_Write_Property(&wpdata);
if (!status) { if (!status) {
/* verify WriteProperty property is known */ /* verify WriteProperty property is known */
zassert_not_equal(wpdata.error_code, zassert_not_equal(
ERROR_CODE_UNKNOWN_PROPERTY, wpdata.error_code, ERROR_CODE_UNKNOWN_PROPERTY,
"property '%s': WriteProperty Unknown!\n", "property '%s': WriteProperty Unknown!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
@@ -90,13 +93,16 @@ static void test_Notification_Class(void)
rpdata.object_property = *pOptional; rpdata.object_property = *pOptional;
rpdata.array_index = BACNET_ARRAY_ALL; rpdata.array_index = BACNET_ARRAY_ALL;
len = Notification_Class_Read_Property(&rpdata); len = Notification_Class_Read_Property(&rpdata);
zassert_not_equal(len, BACNET_STATUS_ERROR, zassert_not_equal(
len, BACNET_STATUS_ERROR,
"property '%s': failed to ReadProperty!\n", "property '%s': failed to ReadProperty!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
if (len > 0) { if (len > 0) {
test_len = bacapp_decode_application_data(rpdata.application_data, test_len = bacapp_decode_application_data(
(uint8_t)rpdata.application_data_len, &value); rpdata.application_data, (uint8_t)rpdata.application_data_len,
zassert_equal(len, test_len, "property '%s': failed to decode!\n", &value);
zassert_equal(
len, test_len, "property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
/* check WriteProperty properties */ /* check WriteProperty properties */
wpdata.object_type = rpdata.object_type; wpdata.object_type = rpdata.object_type;
@@ -109,8 +115,8 @@ static void test_Notification_Class(void)
status = Notification_Class_Write_Property(&wpdata); status = Notification_Class_Write_Property(&wpdata);
if (!status) { if (!status) {
/* verify WriteProperty property is known */ /* verify WriteProperty property is known */
zassert_not_equal(wpdata.error_code, zassert_not_equal(
ERROR_CODE_UNKNOWN_PROPERTY, wpdata.error_code, ERROR_CODE_UNKNOWN_PROPERTY,
"property '%s': WriteProperty Unknown!\n", "property '%s': WriteProperty Unknown!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
@@ -130,15 +136,13 @@ static void test_Notification_Class(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(notification_class_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(notification_class_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(notification_class_tests, ztest_test_suite(
ztest_unit_test(test_Notification_Class) notification_class_tests, ztest_unit_test(test_Notification_Class));
);
ztest_run_test_suite(notification_class_tests); ztest_run_test_suite(notification_class_tests);
} }
+6 -6
View File
@@ -27,8 +27,8 @@ int Send_UEvent_Notify(
return 0; return 0;
} }
uint8_t Send_CEvent_Notify( uint8_t
uint32_t device_id, BACNET_EVENT_NOTIFICATION_DATA *data) Send_CEvent_Notify(uint32_t device_id, BACNET_EVENT_NOTIFICATION_DATA *data)
{ {
(void)device_id; (void)device_id;
(void)data; (void)data;
@@ -42,10 +42,10 @@ void Send_WhoIs(int32_t low_limit, int32_t high_limit)
} }
bool datetime_local( bool datetime_local(
BACNET_DATE * bdate, BACNET_DATE *bdate,
BACNET_TIME * btime, BACNET_TIME *btime,
int16_t * utc_offset_minutes, int16_t *utc_offset_minutes,
bool * dst_active) bool *dst_active)
{ {
(void)bdate; (void)bdate;
(void)btime; (void)btime;
+15 -12
View File
@@ -29,14 +29,20 @@ static void test_network_port(void)
bool status = false; bool status = false;
unsigned count = 0; unsigned count = 0;
uint32_t object_instance = 0; uint32_t object_instance = 0;
uint8_t port_type[] = { PORT_TYPE_ETHERNET, PORT_TYPE_ARCNET, uint8_t port_type[] = { PORT_TYPE_ETHERNET, PORT_TYPE_ARCNET,
PORT_TYPE_MSTP, PORT_TYPE_PTP, PORT_TYPE_LONTALK, PORT_TYPE_BIP, PORT_TYPE_MSTP, PORT_TYPE_PTP,
PORT_TYPE_ZIGBEE, PORT_TYPE_VIRTUAL, PORT_TYPE_NON_BACNET, PORT_TYPE_LONTALK, PORT_TYPE_BIP,
PORT_TYPE_BIP6, PORT_TYPE_MAX }; PORT_TYPE_ZIGBEE, PORT_TYPE_VIRTUAL,
const int known_fail_property_list[] = { PROP_IP_DNS_SERVER, PORT_TYPE_NON_BACNET, PORT_TYPE_BIP6,
PORT_TYPE_MAX };
const int known_fail_property_list[] = {
PROP_IP_DNS_SERVER,
PROP_BBMD_BROADCAST_DISTRIBUTION_TABLE, PROP_BBMD_BROADCAST_DISTRIBUTION_TABLE,
PROP_BBMD_FOREIGN_DEVICE_TABLE, PROP_FD_BBMD_ADDRESS, PROP_BBMD_FOREIGN_DEVICE_TABLE,
PROP_IPV6_DNS_SERVER, -1 }; PROP_FD_BBMD_ADDRESS,
PROP_IPV6_DNS_SERVER,
-1
};
while (port_type[port] != PORT_TYPE_MAX) { while (port_type[port] != PORT_TYPE_MAX) {
object_instance = 1234; object_instance = 1234;
@@ -48,11 +54,8 @@ static void test_network_port(void)
count = Network_Port_Count(); count = Network_Port_Count();
zassert_true(count > 0, NULL); zassert_true(count > 0, NULL);
bacnet_object_properties_read_write_test( bacnet_object_properties_read_write_test(
OBJECT_NETWORK_PORT, OBJECT_NETWORK_PORT, object_instance, Network_Port_Property_Lists,
object_instance, Network_Port_Read_Property, Network_Port_Write_Property,
Network_Port_Property_Lists,
Network_Port_Read_Property,
Network_Port_Write_Property,
known_fail_property_list); known_fail_property_list);
port++; port++;
} }
+1 -3
View File
@@ -71,8 +71,7 @@ void testBACnetObjects(Test *pTest)
for (test_point = 0; test_point < max_test_points; test_point++) { for (test_point = 0; test_point < max_test_points; test_point++) {
device_id = test_point * (BACNET_MAX_INSTANCE / max_test_points); device_id = test_point * (BACNET_MAX_INSTANCE / max_test_points);
pDevice = objects_device_data(test_point); pDevice = objects_device_data(test_point);
testBACnetObjectsCompare( testBACnetObjectsCompare(pTest, pDevice, objects_device_id(test_point));
pTest, pDevice, objects_device_id(test_point));
} }
for (test_point = 0; test_point < max_test_points; test_point++) { for (test_point = 0; test_point < max_test_points; test_point++) {
status = objects_device_delete(0); status = objects_device_delete(0);
@@ -99,4 +98,3 @@ int main(void)
return 0; return 0;
} }
+6 -9
View File
@@ -20,13 +20,14 @@
/** /**
* @brief Test * @brief Test
*/ */
static void testBACnetObjectsCompare( static void
OBJECT_DEVICE_T *pDevice, uint32_t expected_device_id) testBACnetObjectsCompare(OBJECT_DEVICE_T *pDevice, uint32_t expected_device_id)
{ {
zassert_not_null(pDevice, NULL); zassert_not_null(pDevice, NULL);
if (pDevice) { if (pDevice) {
zassert_not_null(pDevice->Object_List, NULL); zassert_not_null(pDevice->Object_List, NULL);
zassert_equal(pDevice->Object_Identifier.instance, expected_device_id, NULL); zassert_equal(
pDevice->Object_Identifier.instance, expected_device_id, NULL);
zassert_equal(pDevice->Object_Identifier.type, OBJECT_DEVICE, NULL); zassert_equal(pDevice->Object_Identifier.type, OBJECT_DEVICE, NULL);
zassert_equal(pDevice->Object_Type, OBJECT_DEVICE, NULL); zassert_equal(pDevice->Object_Type, OBJECT_DEVICE, NULL);
} }
@@ -43,7 +44,6 @@ static void testBACnetObjects(void)
const unsigned max_test_points = 20; const unsigned max_test_points = 20;
OBJECT_DEVICE_T *pDevice; OBJECT_DEVICE_T *pDevice;
/* Verify deleting a non-existant object returns the correct value */ /* Verify deleting a non-existant object returns the correct value */
zassert_false(objects_device_delete(0), NULL); zassert_false(objects_device_delete(0), NULL);
@@ -53,7 +53,7 @@ static void testBACnetObjects(void)
pDevice = objects_device_new(device_id); pDevice = objects_device_new(device_id);
testBACnetObjectsCompare(pDevice, device_id); testBACnetObjectsCompare(pDevice, device_id);
/* Verify the last created device can be fetched by ID */ /* Verify the last created device can be fetched by ID */
pDevice = objects_device_by_instance(device_id); pDevice = objects_device_by_instance(device_id);
testBACnetObjectsCompare(pDevice, device_id); testBACnetObjectsCompare(pDevice, device_id);
} }
@@ -83,15 +83,12 @@ static void testBACnetObjects(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(objects_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(objects_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(objects_tests, ztest_test_suite(objects_tests, ztest_unit_test(testBACnetObjects));
ztest_unit_test(testBACnetObjects)
);
ztest_run_test_suite(objects_tests); ztest_run_test_suite(objects_tests);
} }
+9 -9
View File
@@ -27,7 +27,7 @@ static void testOctetString_Value(void)
uint8_t apdu[MAX_APDU] = { 0 }; uint8_t apdu[MAX_APDU] = { 0 };
int len = 0, test_len = 0; int len = 0, test_len = 0;
BACNET_READ_PROPERTY_DATA rpdata = { 0 }; BACNET_READ_PROPERTY_DATA rpdata = { 0 };
BACNET_APPLICATION_DATA_VALUE value = {0}; BACNET_APPLICATION_DATA_VALUE value = { 0 };
const int *required_property = NULL; const int *required_property = NULL;
const uint32_t instance = 1; const uint32_t instance = 1;
@@ -44,10 +44,12 @@ static void testOctetString_Value(void)
len = OctetString_Value_Read_Property(&rpdata); len = OctetString_Value_Read_Property(&rpdata);
zassert_true(len >= 0, NULL); zassert_true(len >= 0, NULL);
if (len >= 0) { if (len >= 0) {
test_len = bacapp_decode_known_property(rpdata.application_data, test_len = bacapp_decode_known_property(
len, &value, rpdata.object_type, rpdata.object_property); rpdata.application_data, len, &value, rpdata.object_type,
rpdata.object_property);
if (len != test_len) { if (len != test_len) {
printf("property '%s': failed to decode!\n", printf(
"property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
if (rpdata.object_property == PROP_PRIORITY_ARRAY) { if (rpdata.object_property == PROP_PRIORITY_ARRAY) {
@@ -56,7 +58,8 @@ static void testOctetString_Value(void)
} }
zassert_equal(len, test_len, NULL); zassert_equal(len, test_len, NULL);
} else { } else {
printf("property '%s': failed to read!\n", printf(
"property '%s': failed to read!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
required_property++; required_property++;
@@ -66,15 +69,12 @@ static void testOctetString_Value(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(osv_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(osv_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(osv_tests, ztest_test_suite(osv_tests, ztest_unit_test(testOctetString_Value));
ztest_unit_test(testOctetString_Value)
);
ztest_run_test_suite(osv_tests); ztest_run_test_suite(osv_tests);
} }
+7 -8
View File
@@ -28,7 +28,7 @@ static void testPositiveInteger_Value(void)
uint8_t apdu[MAX_APDU] = { 0 }; uint8_t apdu[MAX_APDU] = { 0 };
int len = 0, test_len = 0; int len = 0, test_len = 0;
BACNET_READ_PROPERTY_DATA rpdata = { 0 }; BACNET_READ_PROPERTY_DATA rpdata = { 0 };
BACNET_APPLICATION_DATA_VALUE value = {0}; BACNET_APPLICATION_DATA_VALUE value = { 0 };
const int *required_property = NULL; const int *required_property = NULL;
const uint32_t instance = 1; const uint32_t instance = 1;
@@ -45,10 +45,12 @@ static void testPositiveInteger_Value(void)
len = PositiveInteger_Value_Read_Property(&rpdata); len = PositiveInteger_Value_Read_Property(&rpdata);
zassert_true(len >= 0, NULL); zassert_true(len >= 0, NULL);
if (len >= 0) { if (len >= 0) {
test_len = bacapp_decode_known_property(rpdata.application_data, test_len = bacapp_decode_known_property(
len, &value, rpdata.object_type, rpdata.object_property); rpdata.application_data, len, &value, rpdata.object_type,
rpdata.object_property);
if (len != test_len) { if (len != test_len) {
printf("property '%s': failed to decode!\n", printf(
"property '%s': failed to decode!\n",
bactext_property_name(rpdata.object_property)); bactext_property_name(rpdata.object_property));
} }
if (rpdata.object_property == PROP_PRIORITY_ARRAY) { if (rpdata.object_property == PROP_PRIORITY_ARRAY) {
@@ -64,15 +66,12 @@ static void testPositiveInteger_Value(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(piv_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(piv_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(piv_tests, ztest_test_suite(piv_tests, ztest_unit_test(testPositiveInteger_Value));
ztest_unit_test(testPositiveInteger_Value)
);
ztest_run_test_suite(piv_tests); ztest_run_test_suite(piv_tests);
} }
+19 -13
View File
@@ -21,7 +21,8 @@
* are known to fail to decode after reading * are known to fail to decode after reading
* @return true if the property was written successfully, false if not * @return true if the property was written successfully, false if not
*/ */
bool bacnet_object_property_write_test(BACNET_WRITE_PROPERTY_DATA *wpdata, bool bacnet_object_property_write_test(
BACNET_WRITE_PROPERTY_DATA *wpdata,
write_property_function write_property, write_property_function write_property,
const int *skip_fail_property_list) const int *skip_fail_property_list)
{ {
@@ -34,7 +35,8 @@ bool bacnet_object_property_write_test(BACNET_WRITE_PROPERTY_DATA *wpdata,
status = write_property(wpdata); status = write_property(wpdata);
if (!status) { if (!status) {
/* verify WriteProperty property is known */ /* verify WriteProperty property is known */
zassert_not_equal(wpdata->error_code, ERROR_CODE_UNKNOWN_PROPERTY, zassert_not_equal(
wpdata->error_code, ERROR_CODE_UNKNOWN_PROPERTY,
"property '%s': WriteProperty Unknown!\n", "property '%s': WriteProperty Unknown!\n",
bactext_property_name(wpdata->object_property)); bactext_property_name(wpdata->object_property));
} }
@@ -75,7 +77,8 @@ void bacnet_object_property_write_parameter_init(
* are known to fail to decode after reading * are known to fail to decode after reading
* @return length of the property value that was read * @return length of the property value that was read
*/ */
int bacnet_object_property_read_test(BACNET_READ_PROPERTY_DATA *rpdata, int bacnet_object_property_read_test(
BACNET_READ_PROPERTY_DATA *rpdata,
read_property_function read_property, read_property_function read_property,
const int *skip_fail_property_list) const int *skip_fail_property_list)
{ {
@@ -99,8 +102,9 @@ int bacnet_object_property_read_test(BACNET_READ_PROPERTY_DATA *rpdata,
apdu = rpdata->application_data; apdu = rpdata->application_data;
apdu_len = read_len; apdu_len = read_len;
while (apdu_len) { while (apdu_len) {
len = bacapp_decode_known_property(apdu, apdu_len, &value, len = bacapp_decode_known_property(
rpdata->object_type, rpdata->object_property); apdu, apdu_len, &value, rpdata->object_type,
rpdata->object_property);
if (len > 0) { if (len > 0) {
test_len += len; test_len += len;
if ((len < apdu_len) && if ((len < apdu_len) &&
@@ -116,15 +120,16 @@ int bacnet_object_property_read_test(BACNET_READ_PROPERTY_DATA *rpdata,
break; break;
} }
} else { } else {
printf("property '%s': failed to decode! len=%d\n", printf(
bactext_property_name(rpdata->object_property), "property '%s': failed to decode! len=%d\n",
len); bactext_property_name(rpdata->object_property), len);
break; break;
} }
} }
if (read_len != test_len) { if (read_len != test_len) {
printf("property '%s': failed to decode! %d!=%d\n", printf(
bactext_property_name(rpdata->object_property), test_len, "property '%s': failed to decode! %d!=%d\n",
bactext_property_name(rpdata->object_property), test_len,
read_len); read_len);
} }
if (property_list_member( if (property_list_member(
@@ -136,8 +141,8 @@ int bacnet_object_property_read_test(BACNET_READ_PROPERTY_DATA *rpdata,
} else if (read_len == 0) { } else if (read_len == 0) {
/* empty response is valid for some properties */ /* empty response is valid for some properties */
} else { } else {
zassert_not_equal(read_len, BACNET_STATUS_ERROR, zassert_not_equal(
"property '%s': failed to read!\n", read_len, BACNET_STATUS_ERROR, "property '%s': failed to read!\n",
bactext_property_name(rpdata->object_property)); bactext_property_name(rpdata->object_property));
} }
@@ -155,7 +160,8 @@ int bacnet_object_property_read_test(BACNET_READ_PROPERTY_DATA *rpdata,
* @param skip_fail_property_list The list of properties that * @param skip_fail_property_list The list of properties that
* are known to fail to decode after reading * are known to fail to decode after reading
*/ */
void bacnet_object_properties_read_write_test(BACNET_OBJECT_TYPE object_type, void bacnet_object_properties_read_write_test(
BACNET_OBJECT_TYPE object_type,
uint32_t object_instance, uint32_t object_instance,
rpm_property_lists_function property_list, rpm_property_lists_function property_list,
read_property_function read_property, read_property_function read_property,
+6 -11
View File
@@ -27,34 +27,29 @@ static void testSchedule(void)
{ {
unsigned count = 0; unsigned count = 0;
uint32_t object_instance = 0; uint32_t object_instance = 0;
const int skip_fail_property_list[] = { const int skip_fail_property_list[] = {
PROP_LIST_OF_OBJECT_PROPERTY_REFERENCES, -1 }; PROP_LIST_OF_OBJECT_PROPERTY_REFERENCES, -1
};
Schedule_Init(); Schedule_Init();
count = Schedule_Count(); count = Schedule_Count();
zassert_true(count > 0, NULL); zassert_true(count > 0, NULL);
object_instance = Schedule_Index_To_Instance(0); object_instance = Schedule_Index_To_Instance(0);
bacnet_object_properties_read_write_test( bacnet_object_properties_read_write_test(
OBJECT_SCHEDULE, OBJECT_SCHEDULE, object_instance, Schedule_Property_Lists,
object_instance, Schedule_Read_Property, Schedule_Write_Property,
Schedule_Property_Lists,
Schedule_Read_Property,
Schedule_Write_Property,
skip_fail_property_list); skip_fail_property_list);
} }
/** /**
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(schedule_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(schedule_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(schedule_tests, ztest_test_suite(schedule_tests, ztest_unit_test(testSchedule));
ztest_unit_test(testSchedule)
);
ztest_run_test_suite(schedule_tests); ztest_run_test_suite(schedule_tests);
} }
@@ -37,11 +37,8 @@ static void testTimeValue(void)
zassert_true(count > 0, NULL); zassert_true(count > 0, NULL);
object_instance = Time_Value_Index_To_Instance(0); object_instance = Time_Value_Index_To_Instance(0);
bacnet_object_properties_read_write_test( bacnet_object_properties_read_write_test(
OBJECT_TIME_VALUE, OBJECT_TIME_VALUE, object_instance, Time_Value_Property_Lists,
object_instance, Time_Value_Read_Property, Time_Value_Write_Property,
Time_Value_Property_Lists,
Time_Value_Read_Property,
Time_Value_Write_Property,
skip_fail_property_list); skip_fail_property_list);
/* check the delete function */ /* check the delete function */
status = Time_Value_Delete(object_instance); status = Time_Value_Delete(object_instance);
@@ -56,9 +53,7 @@ ZTEST_SUITE(bacnet_tv, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(tv_tests, ztest_test_suite(tv_tests, ztest_unit_test(testTimeValue));
ztest_unit_test(testTimeValue)
);
ztest_run_test_suite(tv_tests); ztest_run_test_suite(tv_tests);
} }
+4 -4
View File
@@ -11,10 +11,10 @@
#include "bacnet/datetime.h" #include "bacnet/datetime.h"
bool datetime_local( bool datetime_local(
BACNET_DATE * bdate, BACNET_DATE *bdate,
BACNET_TIME * btime, BACNET_TIME *btime,
int16_t * utc_offset_minutes, int16_t *utc_offset_minutes,
bool * dst_active) bool *dst_active)
{ {
bdate->year = 2023; bdate->year = 2023;
bdate->month = 6; bdate->month = 6;
+4 -7
View File
@@ -33,11 +33,8 @@ static void test_Trend_Log_ReadProperty(void)
status = Trend_Log_Valid_Instance(object_instance); status = Trend_Log_Valid_Instance(object_instance);
zassert_true(status, NULL); zassert_true(status, NULL);
bacnet_object_properties_read_write_test( bacnet_object_properties_read_write_test(
OBJECT_TRENDLOG, OBJECT_TRENDLOG, object_instance, Trend_Log_Property_Lists,
object_instance, Trend_Log_Read_Property, Trend_Log_Write_Property,
Trend_Log_Property_Lists,
Trend_Log_Read_Property,
Trend_Log_Write_Property,
known_fail_property_list); known_fail_property_list);
} }
/** /**
@@ -46,8 +43,8 @@ static void test_Trend_Log_ReadProperty(void)
void test_main(void) void test_main(void)
{ {
ztest_test_suite(trendlog_tests, ztest_test_suite(
ztest_unit_test(test_Trend_Log_ReadProperty)); trendlog_tests, ztest_unit_test(test_Trend_Log_ReadProperty));
ztest_run_test_suite(trendlog_tests); ztest_run_test_suite(trendlog_tests);
} }
+34 -21
View File
@@ -21,7 +21,7 @@
/** /**
* @brief compare two floating point values to 3 decimal places * @brief compare two floating point values to 3 decimal places
* *
* @param x1 - first comparison value * @param x1 - first comparison value
* @param x2 - second comparison value * @param x2 - second comparison value
* @return true if the value is the same to 3 decimal points * @return true if the value is the same to 3 decimal points
@@ -34,7 +34,8 @@ static bool is_float_equal(float x1, float x2)
/** /**
* Unit Test for sRGB to CIE xy * Unit Test for sRGB to CIE xy
*/ */
static void test_color_rgb_xy_gamma_unit(uint8_t red, static void test_color_rgb_xy_gamma_unit(
uint8_t red,
uint8_t green, uint8_t green,
uint8_t blue, uint8_t blue,
float x_coordinate, float x_coordinate,
@@ -46,22 +47,28 @@ static void test_color_rgb_xy_gamma_unit(uint8_t red,
uint8_t test_red = 0, test_green = 0, test_blue = 0; uint8_t test_red = 0, test_green = 0, test_blue = 0;
/* functions with gamma correction */ /* functions with gamma correction */
color_rgb_to_xy_gamma(red, green, blue, &test_x_coordinate, color_rgb_to_xy_gamma(
&test_y_coordinate, &test_brightness); red, green, blue, &test_x_coordinate, &test_y_coordinate,
color_rgb_from_xy_gamma(&test_red, &test_green, &test_blue, x_coordinate, &test_brightness);
y_coordinate, brightness); color_rgb_from_xy_gamma(
zassert_true(is_float_equal(x_coordinate, test_x_coordinate), &test_red, &test_green, &test_blue, x_coordinate, y_coordinate,
"(x=%.3f,test_x=%.3f)", x_coordinate, test_x_coordinate); brightness);
zassert_true(is_float_equal(y_coordinate, test_y_coordinate), zassert_true(
"(y=%.3f,test_y=%.3f)", y_coordinate, test_y_coordinate); is_float_equal(x_coordinate, test_x_coordinate), "(x=%.3f,test_x=%.3f)",
zassert_equal(brightness, test_brightness, "b=%u, test_b=%u", brightness, x_coordinate, test_x_coordinate);
zassert_true(
is_float_equal(y_coordinate, test_y_coordinate), "(y=%.3f,test_y=%.3f)",
y_coordinate, test_y_coordinate);
zassert_equal(
brightness, test_brightness, "b=%u, test_b=%u", brightness,
test_brightness); test_brightness);
} }
/** /**
* Unit Test for sRGB to CIE xy * Unit Test for sRGB to CIE xy
*/ */
static void test_color_rgb_xy_unit(uint8_t red, static void test_color_rgb_xy_unit(
uint8_t red,
uint8_t green, uint8_t green,
uint8_t blue, uint8_t blue,
float x_coordinate, float x_coordinate,
@@ -72,15 +79,20 @@ static void test_color_rgb_xy_unit(uint8_t red,
uint8_t test_brightness = 0; uint8_t test_brightness = 0;
uint8_t test_red = 0, test_green = 0, test_blue = 0; uint8_t test_red = 0, test_green = 0, test_blue = 0;
color_rgb_to_xy(red, green, blue, &test_x_coordinate, &test_y_coordinate, color_rgb_to_xy(
red, green, blue, &test_x_coordinate, &test_y_coordinate,
&test_brightness); &test_brightness);
color_rgb_from_xy(&test_red, &test_green, &test_blue, x_coordinate, color_rgb_from_xy(
y_coordinate, brightness); &test_red, &test_green, &test_blue, x_coordinate, y_coordinate,
zassert_true(is_float_equal(x_coordinate, test_x_coordinate), brightness);
"(x=%.3f,test_x=%.3f)", x_coordinate, test_x_coordinate); zassert_true(
zassert_true(is_float_equal(y_coordinate, test_y_coordinate), is_float_equal(x_coordinate, test_x_coordinate), "(x=%.3f,test_x=%.3f)",
"(y=%.3f,test_y=%.3f)", y_coordinate, test_y_coordinate); x_coordinate, test_x_coordinate);
zassert_equal(brightness, test_brightness, "b=%u, test_b=%u", brightness, zassert_true(
is_float_equal(y_coordinate, test_y_coordinate), "(y=%.3f,test_y=%.3f)",
y_coordinate, test_y_coordinate);
zassert_equal(
brightness, test_brightness, "b=%u, test_b=%u", brightness,
test_brightness); test_brightness);
} }
@@ -166,7 +178,8 @@ ZTEST_SUITE(color_rgb_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(color_rgb_tests, ztest_unit_test(test_color_rgb_ascii), ztest_test_suite(
color_rgb_tests, ztest_unit_test(test_color_rgb_ascii),
ztest_unit_test(test_color_rgb_xy)); ztest_unit_test(test_color_rgb_xy));
ztest_run_test_suite(color_rgb_tests); ztest_run_test_suite(color_rgb_tests);
+19 -29
View File
@@ -17,13 +17,10 @@
*/ */
/** /**
* Unit Test for the days, checking the epoch conversion * Unit Test for the days, checking the epoch conversion
*/ */
static void test_epoch_conversion_date( static void test_epoch_conversion_date(
uint16_t epoch_year, uint16_t epoch_year, uint16_t year, uint8_t month, uint8_t day)
uint16_t year,
uint8_t month,
uint8_t day)
{ {
uint32_t days; uint32_t days;
uint16_t test_year; uint16_t test_year;
@@ -32,8 +29,8 @@ static void test_epoch_conversion_date(
/* conversions of day and date */ /* conversions of day and date */
days = days_since_epoch(epoch_year, year, month, day); days = days_since_epoch(epoch_year, year, month, day);
days_since_epoch_to_date(epoch_year, days, &test_year, &test_month, days_since_epoch_to_date(
&test_day); epoch_year, days, &test_year, &test_month, &test_day);
zassert_equal(year, test_year, NULL); zassert_equal(year, test_year, NULL);
zassert_equal(month, test_month, NULL); zassert_equal(month, test_month, NULL);
zassert_equal(day, test_day, NULL); zassert_equal(day, test_day, NULL);
@@ -61,15 +58,12 @@ static void test_days_epoch_conversion(void)
* Unit Test for the days and year to month date year * Unit Test for the days and year to month date year
*/ */
static void test_days_of_year_to_month_day_date( static void test_days_of_year_to_month_day_date(
uint16_t year, uint16_t year, uint16_t days, uint8_t month, uint8_t day)
uint16_t days,
uint8_t month,
uint8_t day)
{ {
uint8_t test_month = 0; uint8_t test_month = 0;
uint8_t test_day = 0; uint8_t test_day = 0;
/* conversions of days and year */ /* conversions of days and year */
days_of_year_to_month_day(days , year, &test_month, &test_day); days_of_year_to_month_day(days, year, &test_month, &test_day);
zassert_equal(month, test_month, NULL); zassert_equal(month, test_month, NULL);
zassert_equal(day, test_day, NULL); zassert_equal(day, test_day, NULL);
} }
@@ -91,11 +85,9 @@ static void test_days_of_year_to_md(void)
} }
/** /**
* Unit Test for the days, checking the date to see if it is a valid day * Unit Test for the days, checking the date to see if it is a valid day
*/ */
static void test_date_is_valid_day( static void test_date_is_valid_day(uint16_t year, uint8_t month)
uint16_t year,
uint8_t month)
{ {
uint8_t last_day = days_per_month(year, month); uint8_t last_day = days_per_month(year, month);
@@ -107,8 +99,8 @@ static void test_date_is_valid_day(
} }
/** /**
* Unit Test for the days, checking the date to see if it is a valid date * Unit Test for the days, checking the date to see if it is a valid date
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST(days_tests, test_days_date_is_valid) ZTEST(days_tests, test_days_date_is_valid)
#else #else
@@ -143,8 +135,8 @@ static void test_days_date_is_valid(void)
} }
/** /**
* Unit Test for days apart, checking the dates to see how many days apart * Unit Test for days apart, checking the dates to see how many days apart
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST(days_tests, test_days_apart) ZTEST(days_tests, test_days_apart)
#else #else
@@ -163,18 +155,16 @@ static void test_days_apart(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(days_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(days_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(days_tests, ztest_test_suite(
ztest_unit_test(test_days_epoch_conversion), days_tests, ztest_unit_test(test_days_epoch_conversion),
ztest_unit_test(test_days_of_year_to_md), ztest_unit_test(test_days_of_year_to_md),
ztest_unit_test(test_days_date_is_valid), ztest_unit_test(test_days_date_is_valid),
ztest_unit_test(test_days_apart) ztest_unit_test(test_days_apart));
);
ztest_run_test_suite(days_tests); ztest_run_test_suite(days_tests);
} }
+3 -6
View File
@@ -138,8 +138,8 @@ static void testFIFOBuffer(void)
status = FIFO_Add(&test_buffer, add_data, sizeof(add_data)); status = FIFO_Add(&test_buffer, add_data, sizeof(add_data));
zassert_true(status, NULL); zassert_true(status, NULL);
count = FIFO_Count(&test_buffer); count = FIFO_Count(&test_buffer);
test_count = FIFO_Peek_Ahead(&test_buffer, &test_add_data[0], count-1); test_count = FIFO_Peek_Ahead(&test_buffer, &test_add_data[0], count - 1);
zassert_equal(count-1, test_count, NULL); zassert_equal(count - 1, test_count, NULL);
for (index = 0; index < test_count; index++) { for (index = 0; index < test_count; index++) {
zassert_equal(test_add_data[index], add_data[index], NULL); zassert_equal(test_add_data[index], add_data[index], NULL);
} }
@@ -150,15 +150,12 @@ static void testFIFOBuffer(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(fifo_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(fifo_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(fifo_tests, ztest_test_suite(fifo_tests, ztest_unit_test(testFIFOBuffer));
ztest_unit_test(testFIFOBuffer)
);
ztest_run_test_suite(fifo_tests); ztest_run_test_suite(fifo_tests);
} }
+1 -4
View File
@@ -49,15 +49,12 @@ static void testFilename(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(filename_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(filename_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(filename_tests, ztest_test_suite(filename_tests, ztest_unit_test(testFilename));
ztest_unit_test(testFilename)
);
ztest_run_test_suite(filename_tests); ztest_run_test_suite(filename_tests);
} }
+5 -9
View File
@@ -349,20 +349,16 @@ static void testKeySample(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(keylist_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(keylist_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(keylist_tests, ztest_test_suite(
ztest_unit_test(testKeyListFIFO), keylist_tests, ztest_unit_test(testKeyListFIFO),
ztest_unit_test(testKeyListFILO), ztest_unit_test(testKeyListFILO), ztest_unit_test(testKeyListDataKey),
ztest_unit_test(testKeyListDataKey), ztest_unit_test(testKeyListDataIndex),
ztest_unit_test(testKeyListDataIndex), ztest_unit_test(testKeyListLarge), ztest_unit_test(testKeySample));
ztest_unit_test(testKeyListLarge),
ztest_unit_test(testKeySample)
);
ztest_run_test_suite(keylist_tests); ztest_run_test_suite(keylist_tests);
} }
+8 -9
View File
@@ -17,8 +17,8 @@
*/ */
/** /**
* Unit Test for linear interpolation of floating point values, rounded * Unit Test for linear interpolation of floating point values, rounded
*/ */
void testLinearInterpolateRound(void) void testLinearInterpolateRound(void)
{ {
uint16_t x2 = 0; uint16_t x2 = 0;
@@ -82,8 +82,8 @@ void testLinearInterpolateRound(void)
} }
/** /**
* Unit Test for linear interpolation of integers * Unit Test for linear interpolation of integers
*/ */
void testLinearInterpolateInt(void) void testLinearInterpolateInt(void)
{ {
uint16_t y2 = 0; uint16_t y2 = 0;
@@ -103,7 +103,7 @@ void testLinearInterpolateInt(void)
y2 = linear_interpolate_int(1, (65535 / 2), 65535, 1, 100); y2 = linear_interpolate_int(1, (65535 / 2), 65535, 1, 100);
zassert_equal(y2, 50, NULL); zassert_equal(y2, 50, NULL);
y2 = linear_interpolate_int(1, ((65535 * 3) / 4), 65535, 1, 100); y2 = linear_interpolate_int(1, ((65535 * 3) / 4), 65535, 1, 100);
zassert_equal(y2, 75, NULL); zassert_equal(y2, 75, NULL);
@@ -126,10 +126,9 @@ ZTEST_SUITE(Linear_Interpolate, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(Linear_Interpolate, ztest_test_suite(
ztest_unit_test(testLinearInterpolateRound), Linear_Interpolate, ztest_unit_test(testLinearInterpolateRound),
ztest_unit_test(testLinearInterpolateInt) ztest_unit_test(testLinearInterpolateInt));
);
ztest_run_test_suite(Linear_Interpolate); ztest_run_test_suite(Linear_Interpolate);
} }
+18 -16
View File
@@ -175,7 +175,8 @@ static void testRingBufSizeSmall(void)
uint8_t data_element[5]; uint8_t data_element[5];
uint8_t data_store[sizeof(data_element) * NEXT_POWER_OF_2(16)]; uint8_t data_store[sizeof(data_element) * NEXT_POWER_OF_2(16)];
testRingBuf(data_store, data_element, sizeof(data_element), testRingBuf(
data_store, data_element, sizeof(data_element),
sizeof(data_store) / sizeof(data_element)); sizeof(data_store) / sizeof(data_element));
} }
@@ -191,7 +192,8 @@ static void testRingBufSizeLarge(void)
uint8_t data_element[16]; uint8_t data_element[16];
uint8_t data_store[sizeof(data_element) * NEXT_POWER_OF_2(99)]; uint8_t data_store[sizeof(data_element) * NEXT_POWER_OF_2(99)];
testRingBuf(data_store, data_element, sizeof(data_element), testRingBuf(
data_store, data_element, sizeof(data_element),
sizeof(data_store) / sizeof(data_element)); sizeof(data_store) / sizeof(data_element));
} }
@@ -208,10 +210,11 @@ static void testRingBufSizeInvalid(void)
uint8_t data_element[16]; uint8_t data_element[16];
uint8_t data_store[sizeof(data_element) * 99]; uint8_t data_store[sizeof(data_element) * 99];
zassert_false(Ringbuf_Init(&test_buffer, zassert_false(
data_store, sizeof(data_element), Ringbuf_Init(
sizeof(data_store) / sizeof(data_element)), &test_buffer, data_store, sizeof(data_element),
NULL); sizeof(data_store) / sizeof(data_element)),
NULL);
} }
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
@@ -344,27 +347,26 @@ static void testRingBufNextElementSizeSmall(void)
uint8_t data_element[5]; uint8_t data_element[5];
uint8_t data_store[sizeof(data_element) * NEXT_POWER_OF_2(16)]; uint8_t data_store[sizeof(data_element) * NEXT_POWER_OF_2(16)];
status = testRingBufNextElement(data_store, data_element, status = testRingBufNextElement(
sizeof(data_element), sizeof(data_store) / sizeof(data_element)); data_store, data_element, sizeof(data_element),
sizeof(data_store) / sizeof(data_element));
zassert_true(status, NULL); zassert_true(status, NULL);
} }
/** /**
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(ringbuf_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(ringbuf_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(ringbuf_tests, ztest_test_suite(
ztest_unit_test(testRingBufPowerOfTwo), ringbuf_tests, ztest_unit_test(testRingBufPowerOfTwo),
ztest_unit_test(testRingBufSizeSmall), ztest_unit_test(testRingBufSizeSmall),
ztest_unit_test(testRingBufSizeLarge), ztest_unit_test(testRingBufSizeLarge),
ztest_unit_test(testRingBufSizeInvalid), ztest_unit_test(testRingBufSizeInvalid),
ztest_unit_test(testRingBufNextElementSizeSmall) ztest_unit_test(testRingBufNextElementSizeSmall));
);
ztest_run_test_suite(ringbuf_tests); ztest_run_test_suite(ringbuf_tests);
} }
+1 -4
View File
@@ -78,15 +78,12 @@ static void testStaticBuffer(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(sbuf_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(sbuf_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(sbuf_tests, ztest_test_suite(sbuf_tests, ztest_unit_test(testStaticBuffer));
ztest_unit_test(testStaticBuffer)
);
ztest_run_test_suite(sbuf_tests); ztest_run_test_suite(sbuf_tests);
} }
+37 -22
View File
@@ -70,7 +70,8 @@ int ucov_notify_decode_apdu(
return len; return len;
} }
static int cov_subscribe_decode_apdu(uint8_t *apdu, static int cov_subscribe_decode_apdu(
uint8_t *apdu,
unsigned apdu_len, unsigned apdu_len,
uint8_t *invoke_id, uint8_t *invoke_id,
BACNET_SUBSCRIBE_COV_DATA *data) BACNET_SUBSCRIBE_COV_DATA *data)
@@ -98,7 +99,8 @@ static int cov_subscribe_decode_apdu(uint8_t *apdu,
return len; return len;
} }
static int cov_subscribe_property_decode_apdu(uint8_t *apdu, static int cov_subscribe_property_decode_apdu(
uint8_t *apdu,
unsigned apdu_len, unsigned apdu_len,
uint8_t *invoke_id, uint8_t *invoke_id,
BACNET_SUBSCRIBE_COV_DATA *data) BACNET_SUBSCRIBE_COV_DATA *data)
@@ -132,13 +134,17 @@ static void testCOVNotifyData(BACNET_COV_DATA *data, BACNET_COV_DATA *test_data)
BACNET_PROPERTY_VALUE *value = NULL; BACNET_PROPERTY_VALUE *value = NULL;
BACNET_PROPERTY_VALUE *test_value = NULL; BACNET_PROPERTY_VALUE *test_value = NULL;
zassert_equal(test_data->subscriberProcessIdentifier, zassert_equal(
test_data->subscriberProcessIdentifier,
data->subscriberProcessIdentifier, NULL); data->subscriberProcessIdentifier, NULL);
zassert_equal(test_data->initiatingDeviceIdentifier, zassert_equal(
data->initiatingDeviceIdentifier, NULL); test_data->initiatingDeviceIdentifier, data->initiatingDeviceIdentifier,
zassert_equal(test_data->monitoredObjectIdentifier.type, NULL);
zassert_equal(
test_data->monitoredObjectIdentifier.type,
data->monitoredObjectIdentifier.type, NULL); data->monitoredObjectIdentifier.type, NULL);
zassert_equal(test_data->monitoredObjectIdentifier.instance, zassert_equal(
test_data->monitoredObjectIdentifier.instance,
data->monitoredObjectIdentifier.instance, NULL); data->monitoredObjectIdentifier.instance, NULL);
zassert_equal(test_data->timeRemaining, data->timeRemaining, NULL); zassert_equal(test_data->timeRemaining, data->timeRemaining, NULL);
/* test the listOfValues in some clever manner */ /* test the listOfValues in some clever manner */
@@ -147,12 +153,14 @@ static void testCOVNotifyData(BACNET_COV_DATA *data, BACNET_COV_DATA *test_data)
while (value) { while (value) {
zassert_not_null(test_value, NULL); zassert_not_null(test_value, NULL);
if (test_value) { if (test_value) {
zassert_equal(test_value->propertyIdentifier, zassert_equal(
value->propertyIdentifier, "property=%u test_property=%u", test_value->propertyIdentifier, value->propertyIdentifier,
"property=%u test_property=%u",
(unsigned)value->propertyIdentifier, (unsigned)value->propertyIdentifier,
(unsigned)test_value->propertyIdentifier); (unsigned)test_value->propertyIdentifier);
zassert_equal(test_value->propertyArrayIndex, zassert_equal(
value->propertyArrayIndex, NULL); test_value->propertyArrayIndex, value->propertyArrayIndex,
NULL);
zassert_equal(test_value->priority, value->priority, NULL); zassert_equal(test_value->priority, value->priority, NULL);
zassert_true( zassert_true(
bacapp_same_value(&test_value->value, &value->value), NULL); bacapp_same_value(&test_value->value, &value->value), NULL);
@@ -241,11 +249,14 @@ static void testCOVNotify(void)
static void testCOVSubscribeData( static void testCOVSubscribeData(
BACNET_SUBSCRIBE_COV_DATA *data, BACNET_SUBSCRIBE_COV_DATA *test_data) BACNET_SUBSCRIBE_COV_DATA *data, BACNET_SUBSCRIBE_COV_DATA *test_data)
{ {
zassert_equal(test_data->subscriberProcessIdentifier, zassert_equal(
test_data->subscriberProcessIdentifier,
data->subscriberProcessIdentifier, NULL); data->subscriberProcessIdentifier, NULL);
zassert_equal(test_data->monitoredObjectIdentifier.type, zassert_equal(
test_data->monitoredObjectIdentifier.type,
data->monitoredObjectIdentifier.type, NULL); data->monitoredObjectIdentifier.type, NULL);
zassert_equal(test_data->monitoredObjectIdentifier.instance, zassert_equal(
test_data->monitoredObjectIdentifier.instance,
data->monitoredObjectIdentifier.instance, NULL); data->monitoredObjectIdentifier.instance, NULL);
zassert_equal( zassert_equal(
test_data->cancellationRequest, data->cancellationRequest, NULL); test_data->cancellationRequest, data->cancellationRequest, NULL);
@@ -253,7 +264,8 @@ static void testCOVSubscribeData(
printf("cancellation request failed!\n"); printf("cancellation request failed!\n");
} }
if (!test_data->cancellationRequest) { if (!test_data->cancellationRequest) {
zassert_equal(test_data->issueConfirmedNotifications, zassert_equal(
test_data->issueConfirmedNotifications,
data->issueConfirmedNotifications, NULL); data->issueConfirmedNotifications, NULL);
zassert_equal(test_data->lifetime, data->lifetime, NULL); zassert_equal(test_data->lifetime, data->lifetime, NULL);
} }
@@ -263,20 +275,22 @@ static void testCOVSubscribePropertyData(
BACNET_SUBSCRIBE_COV_DATA *data, BACNET_SUBSCRIBE_COV_DATA *test_data) BACNET_SUBSCRIBE_COV_DATA *data, BACNET_SUBSCRIBE_COV_DATA *test_data)
{ {
testCOVSubscribeData(data, test_data); testCOVSubscribeData(data, test_data);
zassert_equal(test_data->monitoredProperty.propertyIdentifier, zassert_equal(
test_data->monitoredProperty.propertyIdentifier,
data->monitoredProperty.propertyIdentifier, NULL); data->monitoredProperty.propertyIdentifier, NULL);
zassert_equal(test_data->monitoredProperty.propertyArrayIndex, zassert_equal(
test_data->monitoredProperty.propertyArrayIndex,
data->monitoredProperty.propertyArrayIndex, NULL); data->monitoredProperty.propertyArrayIndex, NULL);
zassert_equal( zassert_equal(
test_data->covIncrementPresent, data->covIncrementPresent, NULL); test_data->covIncrementPresent, data->covIncrementPresent, NULL);
if (test_data->covIncrementPresent) { if (test_data->covIncrementPresent) {
zassert_false(islessgreater(test_data->covIncrement, zassert_false(
data->covIncrement), NULL); islessgreater(test_data->covIncrement, data->covIncrement), NULL);
} }
} }
static void testCOVSubscribeEncoding( static void
uint8_t invoke_id, BACNET_SUBSCRIBE_COV_DATA *data) testCOVSubscribeEncoding(uint8_t invoke_id, BACNET_SUBSCRIBE_COV_DATA *data)
{ {
uint8_t apdu[480] = { 0 }; uint8_t apdu[480] = { 0 };
int len = 0; int len = 0;
@@ -375,7 +389,8 @@ ZTEST_SUITE(cov_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(cov_tests, ztest_unit_test(testCOVNotify), ztest_test_suite(
cov_tests, ztest_unit_test(testCOVNotify),
ztest_unit_test(testCOVSubscribe), ztest_unit_test(testCOVSubscribe),
ztest_unit_test(testCOVSubscribeProperty)); ztest_unit_test(testCOVSubscribeProperty));
+9 -5
View File
@@ -107,15 +107,18 @@ static void test_CreateObjectError(void)
null_len = create_object_error_ack_service_encode(NULL, &data); null_len = create_object_error_ack_service_encode(NULL, &data);
apdu_len = create_object_error_ack_service_encode(apdu, &data); apdu_len = create_object_error_ack_service_encode(apdu, &data);
zassert_equal(apdu_len, null_len, NULL); zassert_equal(apdu_len, null_len, NULL);
test_len = create_object_error_ack_service_decode(apdu, apdu_len, &test_data); test_len =
create_object_error_ack_service_decode(apdu, apdu_len, &test_data);
zassert_equal(apdu_len, test_len, NULL); zassert_equal(apdu_len, test_len, NULL);
zassert_equal(test_data.error_class, data.error_class, NULL); zassert_equal(test_data.error_class, data.error_class, NULL);
zassert_equal(test_data.error_code, data.error_code, NULL); zassert_equal(test_data.error_code, data.error_code, NULL);
zassert_equal(test_data.first_failed_element_number, zassert_equal(
data.first_failed_element_number, NULL); test_data.first_failed_element_number, data.first_failed_element_number,
NULL);
while (test_len) { while (test_len) {
test_len--; test_len--;
len = create_object_error_ack_service_decode(apdu, test_len, &test_data); len =
create_object_error_ack_service_decode(apdu, test_len, &test_data);
zassert_equal( zassert_equal(
len, BACNET_STATUS_REJECT, "len=%d test_len=%d", len, test_len); len, BACNET_STATUS_REJECT, "len=%d test_len=%d", len, test_len);
} }
@@ -130,7 +133,8 @@ ZTEST_SUITE(create_object_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(create_object_tests, ztest_unit_test(test_CreateObject), ztest_test_suite(
create_object_tests, ztest_unit_test(test_CreateObject),
ztest_unit_test(test_CreateObjectACK), ztest_unit_test(test_CreateObjectACK),
ztest_unit_test(test_CreateObjectError)); ztest_unit_test(test_CreateObjectError));
+3 -4
View File
@@ -59,7 +59,7 @@ static void test_automac_init(void)
mac = automac_free_address_mac(1); mac = automac_free_address_mac(1);
zassert_equal(mac, (MSTP_MAC_SLOTS_OFFSET + 2), NULL); zassert_equal(mac, (MSTP_MAC_SLOTS_OFFSET + 2), NULL);
mac = automac_free_address_random(); mac = automac_free_address_random();
options = (mac == (MSTP_MAC_SLOTS_OFFSET + 1)) || options = (mac == (MSTP_MAC_SLOTS_OFFSET + 1)) ||
(mac == (MSTP_MAC_SLOTS_OFFSET + 2)); (mac == (MSTP_MAC_SLOTS_OFFSET + 2));
zassert_true(options, NULL); zassert_true(options, NULL);
/* test 3 free addresses */ /* test 3 free addresses */
@@ -71,9 +71,8 @@ static void test_automac_init(void)
mac = automac_free_address_mac(2); mac = automac_free_address_mac(2);
zassert_equal(mac, 126, NULL); zassert_equal(mac, 126, NULL);
mac = automac_free_address_random(); mac = automac_free_address_random();
options = (mac == (MSTP_MAC_SLOTS_OFFSET + 1)) || options = (mac == (MSTP_MAC_SLOTS_OFFSET + 1)) ||
(mac == (MSTP_MAC_SLOTS_OFFSET + 2)) || (mac == (MSTP_MAC_SLOTS_OFFSET + 2)) || (mac == 126);
(mac == 126);
zassert_true(options, NULL); zassert_true(options, NULL);
/* test the stored address */ /* test the stored address */
mac = automac_address(); mac = automac_address();
+53 -61
View File
@@ -8,7 +8,7 @@
* @brief test BACnet integer encode/decode APIs * @brief test BACnet integer encode/decode APIs
*/ */
#include <stdlib.h> /* For calloc() */ #include <stdlib.h> /* For calloc() */
#include <zephyr/ztest.h> #include <zephyr/ztest.h>
#include <bacnet/bactext.h> #include <bacnet/bactext.h>
#include <bacnet/datalink/bvlc.h> #include <bacnet/datalink/bvlc.h>
@@ -22,8 +22,7 @@
* @brief Test * @brief Test
*/ */
static void test_BVLC_Address( static void test_BVLC_Address(
BACNET_IP_ADDRESS *bip_address_1, BACNET_IP_ADDRESS *bip_address_1, BACNET_IP_ADDRESS *bip_address_2)
BACNET_IP_ADDRESS *bip_address_2)
{ {
zassert_false(bvlc_address_different(bip_address_1, bip_address_2), NULL); zassert_false(bvlc_address_different(bip_address_1, bip_address_2), NULL);
} }
@@ -62,7 +61,7 @@ static void test_BVLC_Foreign_Device_Table_Entry(
zassert_equal(fdt_entry_1->ttl_seconds, fdt_entry_2->ttl_seconds, NULL); zassert_equal(fdt_entry_1->ttl_seconds, fdt_entry_2->ttl_seconds, NULL);
zassert_equal( zassert_equal(
fdt_entry_1->ttl_seconds_remaining, fdt_entry_1->ttl_seconds_remaining,
fdt_entry_2->ttl_seconds_remaining, NULL); fdt_entry_2->ttl_seconds_remaining, NULL);
} }
return; return;
@@ -112,13 +111,15 @@ ZTEST(bvlc_tests, test_BVLC_Result)
static void test_BVLC_Result(void) static void test_BVLC_Result(void)
#endif #endif
{ {
uint16_t result_code[] = { BVLC_RESULT_SUCCESSFUL_COMPLETION, uint16_t result_code[] = {
BVLC_RESULT_SUCCESSFUL_COMPLETION,
BVLC_RESULT_WRITE_BROADCAST_DISTRIBUTION_TABLE_NAK, BVLC_RESULT_WRITE_BROADCAST_DISTRIBUTION_TABLE_NAK,
BVLC_RESULT_READ_BROADCAST_DISTRIBUTION_TABLE_NAK, BVLC_RESULT_READ_BROADCAST_DISTRIBUTION_TABLE_NAK,
BVLC_RESULT_REGISTER_FOREIGN_DEVICE_NAK, BVLC_RESULT_REGISTER_FOREIGN_DEVICE_NAK,
BVLC_RESULT_READ_FOREIGN_DEVICE_TABLE_NAK, BVLC_RESULT_READ_FOREIGN_DEVICE_TABLE_NAK,
BVLC_RESULT_DELETE_FOREIGN_DEVICE_TABLE_ENTRY_NAK, BVLC_RESULT_DELETE_FOREIGN_DEVICE_TABLE_ENTRY_NAK,
BVLC_RESULT_DISTRIBUTE_BROADCAST_TO_NETWORK_NAK }; BVLC_RESULT_DISTRIBUTE_BROADCAST_TO_NETWORK_NAK
};
unsigned int i = 0; unsigned int i = 0;
size_t result_code_max = sizeof(result_code) / sizeof(result_code[0]); size_t result_code_max = sizeof(result_code) / sizeof(result_code[0]);
@@ -127,8 +128,8 @@ static void test_BVLC_Result(void)
} }
} }
static void test_BVLC_Original_Unicast_NPDU_Message( static void
uint8_t *npdu, uint16_t npdu_len) test_BVLC_Original_Unicast_NPDU_Message(uint8_t *npdu, uint16_t npdu_len)
{ {
uint8_t test_npdu[50] = { 0 }; uint8_t test_npdu[50] = { 0 };
uint8_t pdu[60] = { 0 }; uint8_t pdu[60] = { 0 };
@@ -174,8 +175,8 @@ static void test_BVLC_Original_Unicast_NPDU(void)
test_BVLC_Original_Unicast_NPDU_Message(npdu, npdu_len); test_BVLC_Original_Unicast_NPDU_Message(npdu, npdu_len);
} }
static void test_BVLC_Original_Broadcast_NPDU_Message( static void
uint8_t *npdu, uint16_t npdu_len) test_BVLC_Original_Broadcast_NPDU_Message(uint8_t *npdu, uint16_t npdu_len)
{ {
uint8_t test_npdu[50] = { 0 }; uint8_t test_npdu[50] = { 0 };
uint8_t pdu[60] = { 0 }; uint8_t pdu[60] = { 0 };
@@ -222,9 +223,7 @@ static void test_BVLC_Original_Broadcast_NPDU(void)
} }
static void test_BVLC_Forwarded_NPDU_Message( static void test_BVLC_Forwarded_NPDU_Message(
uint8_t *npdu, uint8_t *npdu, uint16_t npdu_len, BACNET_IP_ADDRESS *bip_address)
uint16_t npdu_len,
BACNET_IP_ADDRESS *bip_address)
{ {
uint8_t test_npdu[50] = { 0 }; uint8_t test_npdu[50] = { 0 };
uint8_t pdu[75] = { 0 }; uint8_t pdu[75] = { 0 };
@@ -243,8 +242,9 @@ static void test_BVLC_Forwarded_NPDU_Message(
zassert_equal(test_len, 4, NULL); zassert_equal(test_len, 4, NULL);
zassert_equal(message_type, BVLC_FORWARDED_NPDU, NULL); zassert_equal(message_type, BVLC_FORWARDED_NPDU, NULL);
zassert_equal(length, msg_len, NULL); zassert_equal(length, msg_len, NULL);
test_len += bvlc_decode_forwarded_npdu(&pdu[4], length - 4, test_len += bvlc_decode_forwarded_npdu(
&test_bip_address, test_npdu, sizeof(test_npdu), &test_npdu_len); &pdu[4], length - 4, &test_bip_address, test_npdu, sizeof(test_npdu),
&test_npdu_len);
zassert_equal(len, test_len, NULL); zassert_equal(len, test_len, NULL);
zassert_equal(msg_len, test_len, NULL); zassert_equal(msg_len, test_len, NULL);
test_BVLC_Address(bip_address, &test_bip_address); test_BVLC_Address(bip_address, &test_bip_address);
@@ -278,8 +278,7 @@ static void test_BVLC_Forwarded_NPDU(void)
test_BVLC_Forwarded_NPDU_Message(npdu, npdu_len, &bip_address); test_BVLC_Forwarded_NPDU_Message(npdu, npdu_len, &bip_address);
} }
static void test_BVLC_Register_Foreign_Device_Message( static void test_BVLC_Register_Foreign_Device_Message(uint16_t ttl_seconds)
uint16_t ttl_seconds)
{ {
uint8_t pdu[60] = { 0 }; uint8_t pdu[60] = { 0 };
uint16_t test_ttl_seconds = 0; uint16_t test_ttl_seconds = 0;
@@ -338,8 +337,7 @@ static void test_BVLC_Delete_Foreign_Device_Message(
if (msg_len != test_len) { if (msg_len != test_len) {
printf("msg:%u test:%u\n", msg_len, test_len); printf("msg:%u test:%u\n", msg_len, test_len);
} }
test_BVLC_Address( test_BVLC_Address(&fdt_entry->dest_address, &test_fdt_entry.dest_address);
&fdt_entry->dest_address, &test_fdt_entry.dest_address);
} }
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
@@ -364,8 +362,7 @@ static void test_BVLC_Delete_Foreign_Device(void)
test_BVLC_Delete_Foreign_Device_Message(&fdt_entry); test_BVLC_Delete_Foreign_Device_Message(&fdt_entry);
} }
static void test_BVLC_Secure_BVLL_Message( static void test_BVLC_Secure_BVLL_Message(uint8_t *sbuf, uint16_t sbuf_len)
uint8_t *sbuf, uint16_t sbuf_len)
{ {
uint8_t test_sbuf[50] = { 0 }; uint8_t test_sbuf[50] = { 0 };
uint8_t pdu[60] = { 0 }; uint8_t pdu[60] = { 0 };
@@ -524,12 +521,12 @@ static void test_BVLC_Broadcast_Distribution_Table_Encode(void)
} }
zassert_equal(test_count, count, NULL); zassert_equal(test_count, count, NULL);
/* test the encode/decode pair */ /* test the encode/decode pair */
apdu_len = bvlc_broadcast_distribution_table_encode(&apdu[0], apdu_len = bvlc_broadcast_distribution_table_encode(
sizeof(apdu), &bdt_list[0]); &apdu[0], sizeof(apdu), &bdt_list[0]);
test_count = sizeof(test_bdt_list) / sizeof(test_bdt_list[0]); test_count = sizeof(test_bdt_list) / sizeof(test_bdt_list[0]);
bvlc_broadcast_distribution_table_link_array(&test_bdt_list[0], test_count); bvlc_broadcast_distribution_table_link_array(&test_bdt_list[0], test_count);
test_apdu_len = bvlc_broadcast_distribution_table_decode(&apdu[0], test_apdu_len = bvlc_broadcast_distribution_table_decode(
apdu_len, &error_code, &test_bdt_list[0]); &apdu[0], apdu_len, &error_code, &test_bdt_list[0]);
zassert_equal(test_apdu_len, apdu_len, NULL); zassert_equal(test_apdu_len, apdu_len, NULL);
count = bvlc_broadcast_distribution_table_count(&test_bdt_list[0]); count = bvlc_broadcast_distribution_table_count(&test_bdt_list[0]);
zassert_equal(test_count, count, NULL); zassert_equal(test_count, count, NULL);
@@ -662,8 +659,7 @@ static void test_BVLC_Read_Foreign_Device_Table_Ack_Message(
&pdu[4], length - 4, test_fdt_list); &pdu[4], length - 4, test_fdt_list);
zassert_equal(msg_len, test_len, NULL); zassert_equal(msg_len, test_len, NULL);
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
test_BVLC_Foreign_Device_Table_Entry( test_BVLC_Foreign_Device_Table_Entry(&fdt_list[i], &test_fdt_list[i]);
&fdt_list[i], &test_fdt_list[i]);
} }
} }
@@ -705,15 +701,13 @@ static void test_BVLC_Read_Foreign_Device_Table_Ack(void)
} }
test_count = bvlc_foreign_device_table_valid_count(fdt_list); test_count = bvlc_foreign_device_table_valid_count(fdt_list);
zassert_equal(test_count, count, NULL); zassert_equal(test_count, count, NULL);
test_BVLC_Read_Foreign_Device_Table_Ack_Message( test_BVLC_Read_Foreign_Device_Table_Ack_Message(npdu, npdu_len, fdt_list);
npdu, npdu_len, fdt_list);
/* now with some NPDU data */ /* now with some NPDU data */
for (i = 0; i < sizeof(npdu); i++) { for (i = 0; i < sizeof(npdu); i++) {
npdu[i] = i; npdu[i] = i;
} }
npdu_len = sizeof(npdu); npdu_len = sizeof(npdu);
test_BVLC_Read_Foreign_Device_Table_Ack_Message( test_BVLC_Read_Foreign_Device_Table_Ack_Message(npdu, npdu_len, fdt_list);
npdu, npdu_len, fdt_list);
/* cleanup */ /* cleanup */
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
dest_address.port = test_port_start + i; dest_address.port = test_port_start + i;
@@ -824,14 +818,14 @@ static void test_BVLC_Address_Get_Set(void)
if (status) { if (status) {
status = bvlc_address_get( status = bvlc_address_get(
&src, &test_octet0, &test_octet1, &test_octet2, &test_octet3); &src, &test_octet0, &test_octet1, &test_octet2, &test_octet3);
printf("src:%u.%u.%u.%u\n", (unsigned)test_octet0, printf(
(unsigned)test_octet1, (unsigned)test_octet2, "src:%u.%u.%u.%u\n", (unsigned)test_octet0, (unsigned)test_octet1,
(unsigned)test_octet3); (unsigned)test_octet2, (unsigned)test_octet3);
status = bvlc_address_get( status = bvlc_address_get(
&dst, &test_octet0, &test_octet1, &test_octet2, &test_octet3); &dst, &test_octet0, &test_octet1, &test_octet2, &test_octet3);
printf("dst:%u.%u.%u.%u\n", (unsigned)test_octet0, printf(
(unsigned)test_octet1, (unsigned)test_octet2, "dst:%u.%u.%u.%u\n", (unsigned)test_octet0, (unsigned)test_octet1,
(unsigned)test_octet3); (unsigned)test_octet2, (unsigned)test_octet3);
} }
zassert_false(status, NULL); zassert_false(status, NULL);
/* BACnet to IPv4 address conversions */ /* BACnet to IPv4 address conversions */
@@ -887,14 +881,14 @@ static void test_BVLC_BBMD_Address(void)
BACNET_ERROR_CODE error_code = ERROR_CODE_SUCCESS; BACNET_ERROR_CODE error_code = ERROR_CODE_SUCCESS;
bool status = false; bool status = false;
status = bvlc_address_port_from_ascii( status =
&bbmd_address, "192.168.0.255", "0xBAC0"); bvlc_address_port_from_ascii(&bbmd_address, "192.168.0.255", "0xBAC0");
zassert_true(status, NULL); zassert_true(status, NULL);
apdu_len = bvlc_foreign_device_bbmd_host_address_encode(apdu, sizeof(apdu), apdu_len = bvlc_foreign_device_bbmd_host_address_encode(
&bbmd_address); apdu, sizeof(apdu), &bbmd_address);
zassert_not_equal(apdu_len, 0, NULL); zassert_not_equal(apdu_len, 0, NULL);
test_apdu_len = bvlc_foreign_device_bbmd_host_address_decode(apdu, test_apdu_len = bvlc_foreign_device_bbmd_host_address_decode(
apdu_len, &error_code, &test_bbmd_address); apdu, apdu_len, &error_code, &test_bbmd_address);
if (test_apdu_len < 0) { if (test_apdu_len < 0) {
printf("BVLC: error-code=%s\n", bactext_error_code_name(error_code)); printf("BVLC: error-code=%s\n", bactext_error_code_name(error_code));
} }
@@ -910,29 +904,27 @@ static void test_BVLC_BBMD_Address(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(bvlc_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(bvlc_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(bvlc_tests, ztest_test_suite(
ztest_unit_test(test_BVLC_Result), bvlc_tests, ztest_unit_test(test_BVLC_Result),
ztest_unit_test(test_BVLC_Write_Broadcast_Distribution_Table), ztest_unit_test(test_BVLC_Write_Broadcast_Distribution_Table),
ztest_unit_test(test_BVLC_Read_Broadcast_Distribution_Table_Message), ztest_unit_test(test_BVLC_Read_Broadcast_Distribution_Table_Message),
ztest_unit_test(test_BVLC_Forwarded_NPDU), ztest_unit_test(test_BVLC_Forwarded_NPDU),
ztest_unit_test(test_BVLC_Register_Foreign_Device), ztest_unit_test(test_BVLC_Register_Foreign_Device),
ztest_unit_test(test_BVLC_Read_Foreign_Device_Table_Ack), ztest_unit_test(test_BVLC_Read_Foreign_Device_Table_Ack),
ztest_unit_test(test_BVLC_Delete_Foreign_Device), ztest_unit_test(test_BVLC_Delete_Foreign_Device),
ztest_unit_test(test_BVLC_Distribute_Broadcast_To_Network), ztest_unit_test(test_BVLC_Distribute_Broadcast_To_Network),
ztest_unit_test(test_BVLC_Broadcast_Distribution_Table_Encode), ztest_unit_test(test_BVLC_Broadcast_Distribution_Table_Encode),
ztest_unit_test(test_BVLC_Original_Unicast_NPDU), ztest_unit_test(test_BVLC_Original_Unicast_NPDU),
ztest_unit_test(test_BVLC_Original_Broadcast_NPDU), ztest_unit_test(test_BVLC_Original_Broadcast_NPDU),
ztest_unit_test(test_BVLC_Secure_BVLL), ztest_unit_test(test_BVLC_Secure_BVLL),
ztest_unit_test(test_BVLC_Address_Copy), ztest_unit_test(test_BVLC_Address_Copy),
ztest_unit_test(test_BVLC_Address_Get_Set), ztest_unit_test(test_BVLC_Address_Get_Set),
ztest_unit_test(test_BVLC_BBMD_Address) ztest_unit_test(test_BVLC_BBMD_Address));
);
ztest_run_test_suite(bvlc_tests); ztest_run_test_suite(bvlc_tests);
} }
+16 -18
View File
@@ -28,42 +28,40 @@ static void test_COBS_Encode_Decode(void)
#endif #endif
{ {
uint8_t buffer[MAX_APDU] = { 0x55, 0xff, 0 }; uint8_t buffer[MAX_APDU] = { 0x55, 0xff, 0 };
uint8_t encoded_buffer[COBS_ENCODED_SIZE(MAX_APDU)+ uint8_t
COBS_ENCODED_CRC_SIZE] = { 0 }; encoded_buffer[COBS_ENCODED_SIZE(MAX_APDU) + COBS_ENCODED_CRC_SIZE] = {
//uint8_t encoded_buffer[MAX_APDU*2] = { 0 }; 0
};
// uint8_t encoded_buffer[MAX_APDU*2] = { 0 };
uint8_t test_buffer[MAX_APDU] = { 0 }; uint8_t test_buffer[MAX_APDU] = { 0 };
unsigned i; unsigned i;
size_t encoded_buffer_length, test_buffer_length; size_t encoded_buffer_length, test_buffer_length;
for (i = 2; i < sizeof(buffer); i++) { for (i = 2; i < sizeof(buffer); i++) {
buffer[i] = i%0xff; buffer[i] = i % 0xff;
} }
encoded_buffer_length = cobs_frame_encode(encoded_buffer, encoded_buffer_length = cobs_frame_encode(
sizeof(encoded_buffer), buffer, sizeof(buffer)); encoded_buffer, sizeof(encoded_buffer), buffer, sizeof(buffer));
zassert_true(encoded_buffer_length > 0, zassert_true(encoded_buffer_length > 0, "COBS encoded buffer empty!");
"COBS encoded buffer empty!"); test_buffer_length = cobs_frame_decode(
test_buffer_length = cobs_frame_decode(test_buffer, sizeof(test_buffer), test_buffer, sizeof(test_buffer), encoded_buffer,
encoded_buffer, encoded_buffer_length); encoded_buffer_length);
for (i = 0; i < sizeof(buffer); i++) { for (i = 0; i < sizeof(buffer); i++) {
zassert_true(buffer[i] == test_buffer[i], zassert_true(buffer[i] == test_buffer[i], "COBS encode/decode fail");
"COBS encode/decode fail");
} }
zassert_true(test_buffer_length == sizeof(buffer), zassert_true(
"COBS encode/decode length fail"); test_buffer_length == sizeof(buffer), "COBS encode/decode length fail");
} }
/** /**
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(cobs_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(cobs_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(cobs_tests, ztest_test_suite(cobs_tests, ztest_unit_test(test_COBS_Encode_Decode));
ztest_unit_test(test_COBS_Encode_Decode)
);
ztest_run_test_suite(cobs_tests); ztest_run_test_suite(cobs_tests);
} }
+4 -7
View File
@@ -135,18 +135,15 @@ static void testCRC16CreateTable(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(crc_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(crc_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(crc_tests, ztest_test_suite(
ztest_unit_test(testCRC8), crc_tests, ztest_unit_test(testCRC8), ztest_unit_test(testCRC16),
ztest_unit_test(testCRC16), ztest_unit_test(testCRC8CreateTable),
ztest_unit_test(testCRC8CreateTable), ztest_unit_test(testCRC16CreateTable));
ztest_unit_test(testCRC16CreateTable)
);
ztest_run_test_suite(crc_tests); ztest_run_test_suite(crc_tests);
} }
+7 -4
View File
@@ -23,8 +23,11 @@ bool arcnet_init(char *interface_name)
return ztest_get_return_value(); return ztest_get_return_value();
} }
int arcnet_send_pdu(BACNET_ADDRESS *dest, BACNET_NPDU_DATA *npdu_data, int arcnet_send_pdu(
uint8_t *pdu, unsigned pdu_len) BACNET_ADDRESS *dest,
BACNET_NPDU_DATA *npdu_data,
uint8_t *pdu,
unsigned pdu_len)
{ {
ztest_check_expected_value(dest); ztest_check_expected_value(dest);
ztest_check_expected_value(npdu_data); ztest_check_expected_value(npdu_data);
@@ -32,8 +35,8 @@ int arcnet_send_pdu(BACNET_ADDRESS *dest, BACNET_NPDU_DATA *npdu_data,
return ztest_get_return_value(); return ztest_get_return_value();
} }
uint16_t arcnet_receive(BACNET_ADDRESS *src, uint8_t *pdu, uint16_t max_pdu, uint16_t arcnet_receive(
unsigned timeout) BACNET_ADDRESS *src, uint8_t *pdu, uint16_t max_pdu, unsigned timeout)
{ {
ztest_check_expected_value(src); ztest_check_expected_value(src);
ztest_check_expected_value(timeout); ztest_check_expected_value(timeout);
+4 -3
View File
@@ -44,7 +44,8 @@ void bip_get_my_address(BACNET_ADDRESS *my_address)
ztest_copy_return_data(my_address, sizeof(BACNET_ADDRESS)); ztest_copy_return_data(my_address, sizeof(BACNET_ADDRESS));
} }
int bip_send_pdu(BACNET_ADDRESS *dest, int bip_send_pdu(
BACNET_ADDRESS *dest,
BACNET_NPDU_DATA *npdu_data, BACNET_NPDU_DATA *npdu_data,
uint8_t *pdu, uint8_t *pdu,
unsigned pdu_len) unsigned pdu_len)
@@ -62,8 +63,8 @@ int bip_send_mpdu(BACNET_IP_ADDRESS *dest, uint8_t *mtu, uint16_t mtu_len)
return ztest_get_return_value(); return ztest_get_return_value();
} }
uint16_t bip_receive(BACNET_ADDRESS *src, uint8_t *pdu, uint16_t max_pdu, uint16_t bip_receive(
unsigned timeout) BACNET_ADDRESS *src, uint8_t *pdu, uint16_t max_pdu, unsigned timeout)
{ {
ztest_check_expected_value(src); ztest_check_expected_value(src);
ztest_check_expected_value(timeout); ztest_check_expected_value(timeout);
+2 -1
View File
@@ -32,7 +32,8 @@ void bip6_get_my_address(BACNET_ADDRESS *my_address)
ztest_copy_return_data(my_address, sizeof(BACNET_ADDRESS)); ztest_copy_return_data(my_address, sizeof(BACNET_ADDRESS));
} }
int bip6_send_pdu(BACNET_ADDRESS *dest, int bip6_send_pdu(
BACNET_ADDRESS *dest,
BACNET_NPDU_DATA *npdu_data, BACNET_NPDU_DATA *npdu_data,
uint8_t *pdu, uint8_t *pdu,
unsigned pdu_len) unsigned pdu_len)
+9 -7
View File
@@ -16,15 +16,18 @@ bool dlmstp_init(char *ifname)
} }
void dlmstp_reset(void) void dlmstp_reset(void)
{ {
} }
void dlmstp_cleanup(void) void dlmstp_cleanup(void)
{ {
} }
int dlmstp_send_pdu(BACNET_ADDRESS *dest, BACNET_NPDU_DATA *npdu_data, int dlmstp_send_pdu(
uint8_t * pdu, unsigned pdu_len) BACNET_ADDRESS *dest,
BACNET_NPDU_DATA *npdu_data,
uint8_t *pdu,
unsigned pdu_len)
{ {
ztest_check_expected_value(dest); ztest_check_expected_value(dest);
ztest_check_expected_value(npdu_data); ztest_check_expected_value(npdu_data);
@@ -32,8 +35,8 @@ int dlmstp_send_pdu(BACNET_ADDRESS *dest, BACNET_NPDU_DATA *npdu_data,
return ztest_get_return_value(); return ztest_get_return_value();
} }
uint16_t dlmstp_receive(BACNET_ADDRESS *src, uint8_t *pdu, uint16_t max_pdu, uint16_t dlmstp_receive(
unsigned timeout) BACNET_ADDRESS *src, uint8_t *pdu, uint16_t max_pdu, unsigned timeout)
{ {
ztest_check_expected_value(src); ztest_check_expected_value(src);
ztest_check_expected_value(timeout); ztest_check_expected_value(timeout);
@@ -128,8 +131,7 @@ void dlmstp_set_frame_rx_complete_callback(
ztest_check_expected_value(cb_func); ztest_check_expected_value(cb_func);
} }
void dlmstp_set_frame_rx_start_callback( void dlmstp_set_frame_rx_start_callback(dlmstp_hook_frame_rx_start_cb cb_func)
dlmstp_hook_frame_rx_start_cb cb_func)
{ {
ztest_check_expected_value(cb_func); ztest_check_expected_value(cb_func);
} }
@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2020 Legrand North America, LLC. * Copyright (c) 2020 Legrand North America, LLC.
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
@@ -24,8 +24,11 @@ bool ethernet_init(char *interface_name)
return ztest_get_return_value(); return ztest_get_return_value();
} }
int ethernet_send_pdu(BACNET_ADDRESS *dest, BACNET_NPDU_DATA *npdu_data, int ethernet_send_pdu(
uint8_t *pdu, unsigned pdu_len) BACNET_ADDRESS *dest,
BACNET_NPDU_DATA *npdu_data,
uint8_t *pdu,
unsigned pdu_len)
{ {
ztest_check_expected_value(dest); ztest_check_expected_value(dest);
ztest_check_expected_value(npdu_data); ztest_check_expected_value(npdu_data);
@@ -33,8 +36,8 @@ int ethernet_send_pdu(BACNET_ADDRESS *dest, BACNET_NPDU_DATA *npdu_data,
return ztest_get_return_value(); return ztest_get_return_value();
} }
uint16_t ethernet_receive(BACNET_ADDRESS *src, uint8_t *pdu, uint16_t max_pdu, uint16_t ethernet_receive(
unsigned timeout) BACNET_ADDRESS *src, uint8_t *pdu, uint16_t max_pdu, unsigned timeout)
{ {
ztest_check_expected_value(src); ztest_check_expected_value(src);
ztest_check_expected_value(timeout); ztest_check_expected_value(timeout);
@@ -42,7 +45,6 @@ uint16_t ethernet_receive(BACNET_ADDRESS *src, uint8_t *pdu, uint16_t max_pdu,
return ztest_get_return_value(); return ztest_get_return_value();
} }
void ethernet_set_my_address(BACNET_ADDRESS *my_address) void ethernet_set_my_address(BACNET_ADDRESS *my_address)
{ {
ztest_check_expected_data(my_address, sizeof(BACNET_ADDRESS)); ztest_check_expected_data(my_address, sizeof(BACNET_ADDRESS));
+61 -64
View File
@@ -8,7 +8,7 @@
* @brief test BACnet datalink return codes * @brief test BACnet datalink return codes
*/ */
#include <stdlib.h> /* For calloc() */ #include <stdlib.h> /* For calloc() */
#include <zephyr/ztest.h> #include <zephyr/ztest.h>
#include <bacnet/datalink/datalink.h> #include <bacnet/datalink/datalink.h>
#include "bacnet/apdu.h" #include "bacnet/apdu.h"
@@ -42,15 +42,14 @@ static void test_datalink_arcnet(void)
char *iface2 = "bla-bla-bla2"; char *iface2 = "bla-bla-bla2";
uint8_t expected_data[] = { 0x5A, 0xA5, 0xDE, 0xAD }; uint8_t expected_data[] = { 0x5A, 0xA5, 0xDE, 0xAD };
uint8_t data[] = { 0xFF, 0xFF, 0xFF, 0xFF }; uint8_t data[] = { 0xFF, 0xFF, 0xFF, 0xFF };
BACNET_ADDRESS addr = { BACNET_ADDRESS addr = { .mac_len = 6,
.mac_len = 6, .mac = { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE },
.mac = { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE }, .net = 54,
.net = 54, .len = 7,
.len = 7, .adr = { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54,
.adr = { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32 } 0x32 } };
}; BACNET_ADDRESS addr2 = { 0 };
BACNET_ADDRESS addr2 = {0}; BACNET_NPDU_DATA npdu = { 0 };
BACNET_NPDU_DATA npdu = {0};
zassert_equal(z_cleanup_mock(), 0, NULL); zassert_equal(z_cleanup_mock(), 0, NULL);
datalink_set("arcnet"); datalink_set("arcnet");
@@ -71,8 +70,9 @@ static void test_datalink_arcnet(void)
ztest_expect_value(arcnet_send_pdu, npdu_data, &npdu); ztest_expect_value(arcnet_send_pdu, npdu_data, &npdu);
ztest_expect_data(arcnet_send_pdu, pdu, expected_data); ztest_expect_data(arcnet_send_pdu, pdu, expected_data);
ztest_returns_value(arcnet_send_pdu, 4); ztest_returns_value(arcnet_send_pdu, 4);
zassert_equal(datalink_send_pdu(&addr, &npdu, expected_data, zassert_equal(
sizeof(expected_data)), 4, NULL); datalink_send_pdu(&addr, &npdu, expected_data, sizeof(expected_data)),
4, NULL);
zassert_equal(z_cleanup_mock(), 0, NULL); zassert_equal(z_cleanup_mock(), 0, NULL);
// receive // receive
@@ -123,15 +123,14 @@ static void test_datalink_bip(void)
char *iface2 = "bla-bla-bla2"; char *iface2 = "bla-bla-bla2";
uint8_t expected_data[] = { 0x5A, 0xA5, 0xDE, 0xAD }; uint8_t expected_data[] = { 0x5A, 0xA5, 0xDE, 0xAD };
uint8_t data[] = { 0xFF, 0xFF, 0xFF, 0xFF }; uint8_t data[] = { 0xFF, 0xFF, 0xFF, 0xFF };
BACNET_ADDRESS addr = { BACNET_ADDRESS addr = { .mac_len = 6,
.mac_len = 6, .mac = { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE },
.mac = { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE }, .net = 54,
.net = 54, .len = 7,
.len = 7, .adr = { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54,
.adr = { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32 } 0x32 } };
}; BACNET_ADDRESS addr2 = { 0 };
BACNET_ADDRESS addr2 = {0}; BACNET_NPDU_DATA npdu = { 0 };
BACNET_NPDU_DATA npdu = {0};
zassert_equal(z_cleanup_mock(), 0, NULL); zassert_equal(z_cleanup_mock(), 0, NULL);
datalink_set("bip"); datalink_set("bip");
@@ -152,8 +151,9 @@ static void test_datalink_bip(void)
ztest_expect_value(bip_send_pdu, npdu_data, &npdu); ztest_expect_value(bip_send_pdu, npdu_data, &npdu);
ztest_expect_data(bip_send_pdu, pdu, expected_data); ztest_expect_data(bip_send_pdu, pdu, expected_data);
ztest_returns_value(bip_send_pdu, 4); ztest_returns_value(bip_send_pdu, 4);
zassert_equal(datalink_send_pdu(&addr, &npdu, expected_data, zassert_equal(
sizeof(expected_data)), 4, NULL); datalink_send_pdu(&addr, &npdu, expected_data, sizeof(expected_data)),
4, NULL);
zassert_equal(z_cleanup_mock(), 0, NULL); zassert_equal(z_cleanup_mock(), 0, NULL);
// receive // receive
@@ -207,15 +207,14 @@ static void test_datalink_bip6(void)
char *iface2 = "bla-bla-bla2"; char *iface2 = "bla-bla-bla2";
uint8_t expected_data[] = { 0x5A, 0xA5, 0xDE, 0xAD }; uint8_t expected_data[] = { 0x5A, 0xA5, 0xDE, 0xAD };
uint8_t data[] = { 0xFF, 0xFF, 0xFF, 0xFF }; uint8_t data[] = { 0xFF, 0xFF, 0xFF, 0xFF };
BACNET_ADDRESS addr = { BACNET_ADDRESS addr = { .mac_len = 6,
.mac_len = 6, .mac = { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE },
.mac = { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE }, .net = 54,
.net = 54, .len = 7,
.len = 7, .adr = { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54,
.adr = { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32 } 0x32 } };
}; BACNET_ADDRESS addr2 = { 0 };
BACNET_ADDRESS addr2 = {0}; BACNET_NPDU_DATA npdu = { 0 };
BACNET_NPDU_DATA npdu = {0};
zassert_equal(z_cleanup_mock(), 0, NULL); zassert_equal(z_cleanup_mock(), 0, NULL);
datalink_set("bip6"); datalink_set("bip6");
@@ -236,8 +235,9 @@ static void test_datalink_bip6(void)
ztest_expect_value(bip6_send_pdu, npdu_data, &npdu); ztest_expect_value(bip6_send_pdu, npdu_data, &npdu);
ztest_expect_data(bip6_send_pdu, pdu, expected_data); ztest_expect_data(bip6_send_pdu, pdu, expected_data);
ztest_returns_value(bip6_send_pdu, 4); ztest_returns_value(bip6_send_pdu, 4);
zassert_equal(datalink_send_pdu(&addr, &npdu, expected_data, zassert_equal(
sizeof(expected_data)), 4, NULL); datalink_send_pdu(&addr, &npdu, expected_data, sizeof(expected_data)),
4, NULL);
zassert_equal(z_cleanup_mock(), 0, NULL); zassert_equal(z_cleanup_mock(), 0, NULL);
// receive // receive
@@ -290,15 +290,14 @@ static void test_datalink_dlmstp(void)
char *iface2 = "bla-bla-bla2"; char *iface2 = "bla-bla-bla2";
uint8_t expected_data[] = { 0x5A, 0xA5, 0xDE, 0xAD }; uint8_t expected_data[] = { 0x5A, 0xA5, 0xDE, 0xAD };
uint8_t data[] = { 0xFF, 0xFF, 0xFF, 0xFF }; uint8_t data[] = { 0xFF, 0xFF, 0xFF, 0xFF };
BACNET_ADDRESS addr = { BACNET_ADDRESS addr = { .mac_len = 6,
.mac_len = 6, .mac = { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE },
.mac = { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE }, .net = 54,
.net = 54, .len = 7,
.len = 7, .adr = { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54,
.adr = { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32 } 0x32 } };
}; BACNET_ADDRESS addr2 = { 0 };
BACNET_ADDRESS addr2 = {0}; BACNET_NPDU_DATA npdu = { 0 };
BACNET_NPDU_DATA npdu = {0};
zassert_equal(z_cleanup_mock(), 0, NULL); zassert_equal(z_cleanup_mock(), 0, NULL);
datalink_set("mstp"); datalink_set("mstp");
@@ -319,8 +318,9 @@ static void test_datalink_dlmstp(void)
ztest_expect_value(dlmstp_send_pdu, npdu_data, &npdu); ztest_expect_value(dlmstp_send_pdu, npdu_data, &npdu);
ztest_expect_data(dlmstp_send_pdu, pdu, expected_data); ztest_expect_data(dlmstp_send_pdu, pdu, expected_data);
ztest_returns_value(dlmstp_send_pdu, 4); ztest_returns_value(dlmstp_send_pdu, 4);
zassert_equal(datalink_send_pdu(&addr, &npdu, expected_data, zassert_equal(
sizeof(expected_data)), 4, NULL); datalink_send_pdu(&addr, &npdu, expected_data, sizeof(expected_data)),
4, NULL);
zassert_equal(z_cleanup_mock(), 0, NULL); zassert_equal(z_cleanup_mock(), 0, NULL);
// receive // receive
@@ -371,15 +371,14 @@ static void test_datalink_ethernet(void)
char *iface2 = "bla-bla-bla2"; char *iface2 = "bla-bla-bla2";
uint8_t expected_data[] = { 0x5A, 0xA5, 0xDE, 0xAD }; uint8_t expected_data[] = { 0x5A, 0xA5, 0xDE, 0xAD };
uint8_t data[] = { 0xFF, 0xFF, 0xFF, 0xFF }; uint8_t data[] = { 0xFF, 0xFF, 0xFF, 0xFF };
BACNET_ADDRESS addr = { BACNET_ADDRESS addr = { .mac_len = 6,
.mac_len = 6, .mac = { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE },
.mac = { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE }, .net = 54,
.net = 54, .len = 7,
.len = 7, .adr = { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54,
.adr = { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32 } 0x32 } };
}; BACNET_ADDRESS addr2 = { 0 };
BACNET_ADDRESS addr2 = {0}; BACNET_NPDU_DATA npdu = { 0 };
BACNET_NPDU_DATA npdu = {0};
zassert_equal(z_cleanup_mock(), 0, NULL); zassert_equal(z_cleanup_mock(), 0, NULL);
datalink_set("ethernet"); datalink_set("ethernet");
@@ -400,8 +399,9 @@ static void test_datalink_ethernet(void)
ztest_expect_value(ethernet_send_pdu, npdu_data, &npdu); ztest_expect_value(ethernet_send_pdu, npdu_data, &npdu);
ztest_expect_data(ethernet_send_pdu, pdu, expected_data); ztest_expect_data(ethernet_send_pdu, pdu, expected_data);
ztest_returns_value(ethernet_send_pdu, 4); ztest_returns_value(ethernet_send_pdu, 4);
zassert_equal(datalink_send_pdu(&addr, &npdu, expected_data, zassert_equal(
sizeof(expected_data)), 4, NULL); datalink_send_pdu(&addr, &npdu, expected_data, sizeof(expected_data)),
4, NULL);
zassert_equal(z_cleanup_mock(), 0, NULL); zassert_equal(z_cleanup_mock(), 0, NULL);
// receive // receive
@@ -442,7 +442,6 @@ static void test_datalink_ethernet(void)
datalink_maintenance_timer(42); datalink_maintenance_timer(42);
} }
/** /**
* @} * @}
*/ */
@@ -452,13 +451,11 @@ ZTEST_SUITE(datalink_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(datalink_tests, ztest_test_suite(
ztest_unit_test(test_datalink_arcnet), datalink_tests, ztest_unit_test(test_datalink_arcnet),
ztest_unit_test(test_datalink_bip), ztest_unit_test(test_datalink_bip), ztest_unit_test(test_datalink_bip6),
ztest_unit_test(test_datalink_bip6), ztest_unit_test(test_datalink_dlmstp),
ztest_unit_test(test_datalink_dlmstp), ztest_unit_test(test_datalink_ethernet));
ztest_unit_test(test_datalink_ethernet)
);
ztest_run_test_suite(datalink_tests); ztest_run_test_suite(datalink_tests);
} }
+69 -50
View File
@@ -429,8 +429,8 @@ static void testReceiveNodeFSM(void)
/* BadCRC in header check */ /* BadCRC in header check */
mstp_port.ReceivedInvalidFrame = false; mstp_port.ReceivedInvalidFrame = false;
mstp_port.ReceivedValidFrame = false; mstp_port.ReceivedValidFrame = false;
len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_TOKEN, len = MSTP_Create_Frame(
0x10, /* destination */ buffer, sizeof(buffer), FRAME_TYPE_TOKEN, 0x10, /* destination */
my_mac, /* source */ my_mac, /* source */
NULL, /* data */ NULL, /* data */
0); /* data size */ 0); /* data size */
@@ -444,8 +444,9 @@ static void testReceiveNodeFSM(void)
MSTP_Receive_Frame_FSM(&mstp_port); MSTP_Receive_Frame_FSM(&mstp_port);
zassert_true(mstp_port.DataAvailable == false, NULL); zassert_true(mstp_port.DataAvailable == false, NULL);
zassert_true(mstp_port.SilenceTimer(&mstp_port) == 0, NULL); zassert_true(mstp_port.SilenceTimer(&mstp_port) == 0, NULL);
zassert_true(mstp_port.EventCount == EventCount, "i=%u %u!=%u len=%u", zassert_true(
i, mstp_port.EventCount, EventCount, len); mstp_port.EventCount == EventCount, "i=%u %u!=%u len=%u", i,
mstp_port.EventCount, EventCount, len);
} }
zassert_true(mstp_port.ReceivedInvalidFrame == true, NULL); zassert_true(mstp_port.ReceivedInvalidFrame == true, NULL);
zassert_true(mstp_port.ReceivedValidFrame == false, NULL); zassert_true(mstp_port.ReceivedValidFrame == false, NULL);
@@ -453,8 +454,8 @@ static void testReceiveNodeFSM(void)
/* NoData for us */ /* NoData for us */
mstp_port.ReceivedInvalidFrame = false; mstp_port.ReceivedInvalidFrame = false;
mstp_port.ReceivedValidFrame = false; mstp_port.ReceivedValidFrame = false;
len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_TOKEN, len = MSTP_Create_Frame(
my_mac, /* destination */ buffer, sizeof(buffer), FRAME_TYPE_TOKEN, my_mac, /* destination */
my_mac, /* source */ my_mac, /* source */
NULL, /* data */ NULL, /* data */
0); /* data size */ 0); /* data size */
@@ -474,8 +475,8 @@ static void testReceiveNodeFSM(void)
/* FrameTooLong */ /* FrameTooLong */
mstp_port.ReceivedInvalidFrame = false; mstp_port.ReceivedInvalidFrame = false;
mstp_port.ReceivedValidFrame = false; mstp_port.ReceivedValidFrame = false;
len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_TOKEN, len = MSTP_Create_Frame(
my_mac, /* destination */ buffer, sizeof(buffer), FRAME_TYPE_TOKEN, my_mac, /* destination */
my_mac, /* source */ my_mac, /* source */
NULL, /* data */ NULL, /* data */
0); /* data size */ 0); /* data size */
@@ -498,8 +499,9 @@ static void testReceiveNodeFSM(void)
mstp_port.ReceivedInvalidFrame = false; mstp_port.ReceivedInvalidFrame = false;
mstp_port.ReceivedValidFrame = false; mstp_port.ReceivedValidFrame = false;
memset(data_proprietary, 0, sizeof(data_proprietary)); memset(data_proprietary, 0, sizeof(data_proprietary));
len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_PROPRIETARY_MIN, len = MSTP_Create_Frame(
my_mac, my_mac, data_proprietary, sizeof(data_proprietary)); buffer, sizeof(buffer), FRAME_TYPE_PROPRIETARY_MIN, my_mac, my_mac,
data_proprietary, sizeof(data_proprietary));
zassert_true(len > 0, NULL); zassert_true(len > 0, NULL);
Load_Input_Buffer(buffer, len); Load_Input_Buffer(buffer, len);
RS485_Check_UART_Data(&mstp_port); RS485_Check_UART_Data(&mstp_port);
@@ -517,8 +519,8 @@ static void testReceiveNodeFSM(void)
mstp_port.ReceivedInvalidFrame = false; mstp_port.ReceivedInvalidFrame = false;
mstp_port.ReceivedValidFrame = false; mstp_port.ReceivedValidFrame = false;
memset(data, 0, sizeof(data)); memset(data, 0, sizeof(data));
len = MSTP_Create_Frame(buffer, sizeof(buffer), len = MSTP_Create_Frame(
FRAME_TYPE_BACNET_EXTENDED_DATA_EXPECTING_REPLY, buffer, sizeof(buffer), FRAME_TYPE_BACNET_EXTENDED_DATA_EXPECTING_REPLY,
my_mac, my_mac, data, Nmin_COBS_length_BACnet); my_mac, my_mac, data, Nmin_COBS_length_BACnet);
zassert_true(len > 0, NULL); zassert_true(len > 0, NULL);
Load_Input_Buffer(buffer, len); Load_Input_Buffer(buffer, len);
@@ -532,15 +534,17 @@ static void testReceiveNodeFSM(void)
zassert_true(mstp_port.ReceivedInvalidFrame == false, NULL); zassert_true(mstp_port.ReceivedInvalidFrame == false, NULL);
zassert_true(mstp_port.ReceivedValidFrame == true, NULL); zassert_true(mstp_port.ReceivedValidFrame == true, NULL);
zassert_true(mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE, NULL); zassert_true(mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE, NULL);
zassert_true(mstp_port.FrameType == zassert_true(
FRAME_TYPE_BACNET_EXTENDED_DATA_EXPECTING_REPLY, NULL); mstp_port.FrameType == FRAME_TYPE_BACNET_EXTENDED_DATA_EXPECTING_REPLY,
NULL);
/* Extended-Data-Not-Expecting-Reply */ /* Extended-Data-Not-Expecting-Reply */
mstp_port.ReceivedInvalidFrame = false; mstp_port.ReceivedInvalidFrame = false;
mstp_port.ReceivedValidFrame = false; mstp_port.ReceivedValidFrame = false;
memset(data, 0, sizeof(data)); memset(data, 0, sizeof(data));
len = MSTP_Create_Frame(buffer, sizeof(buffer), len = MSTP_Create_Frame(
FRAME_TYPE_BACNET_EXTENDED_DATA_NOT_EXPECTING_REPLY, buffer, sizeof(buffer),
my_mac, my_mac, data, Nmin_COBS_length_BACnet); FRAME_TYPE_BACNET_EXTENDED_DATA_NOT_EXPECTING_REPLY, my_mac, my_mac,
data, Nmin_COBS_length_BACnet);
zassert_true(len > 0, NULL); zassert_true(len > 0, NULL);
Load_Input_Buffer(buffer, len); Load_Input_Buffer(buffer, len);
RS485_Check_UART_Data(&mstp_port); RS485_Check_UART_Data(&mstp_port);
@@ -553,8 +557,10 @@ static void testReceiveNodeFSM(void)
zassert_true(mstp_port.ReceivedInvalidFrame == false, NULL); zassert_true(mstp_port.ReceivedInvalidFrame == false, NULL);
zassert_true(mstp_port.ReceivedValidFrame == true, NULL); zassert_true(mstp_port.ReceivedValidFrame == true, NULL);
zassert_true(mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE, NULL); zassert_true(mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE, NULL);
zassert_true(mstp_port.FrameType == zassert_true(
FRAME_TYPE_BACNET_EXTENDED_DATA_NOT_EXPECTING_REPLY, NULL); mstp_port.FrameType ==
FRAME_TYPE_BACNET_EXTENDED_DATA_NOT_EXPECTING_REPLY,
NULL);
} }
static void testMasterNodeFSM(void) static void testMasterNodeFSM(void)
@@ -667,8 +673,8 @@ static void testZeroConfigNode_Init(struct mstp_port_struct_t *mstp_port)
zassert_true(mstp_port->Zero_Config_Max_Master == 0, NULL); zassert_true(mstp_port->Zero_Config_Max_Master == 0, NULL);
} }
static void testZeroConfigNode_No_Events_Timeout( static void
struct mstp_port_struct_t *mstp_port) testZeroConfigNode_No_Events_Timeout(struct mstp_port_struct_t *mstp_port)
{ {
bool transition_now, non_zero; bool transition_now, non_zero;
unsigned slots, silence, i; unsigned slots, silence, i;
@@ -696,8 +702,8 @@ static void testZeroConfigNode_Test_Request_Unsupported(
mstp_port->This_Station == mstp_port->Zero_Config_Station, NULL); mstp_port->This_Station == mstp_port->Zero_Config_Station, NULL);
} }
static void testZeroConfigNode_Test_Request_Supported( static void
struct mstp_port_struct_t *mstp_port) testZeroConfigNode_Test_Request_Supported(struct mstp_port_struct_t *mstp_port)
{ {
bool transition_now, non_zero; bool transition_now, non_zero;
unsigned slots, silence, i; unsigned slots, silence, i;
@@ -716,8 +722,8 @@ static void testZeroConfigNode_Test_Request_Supported(
mstp_port->This_Station == mstp_port->Zero_Config_Station, NULL); mstp_port->This_Station == mstp_port->Zero_Config_Station, NULL);
} }
static void testZeroConfigNode_Test_IDLE_InvalidFrame( static void
struct mstp_port_struct_t *mstp_port) testZeroConfigNode_Test_IDLE_InvalidFrame(struct mstp_port_struct_t *mstp_port)
{ {
bool transition_now, non_zero; bool transition_now, non_zero;
unsigned slots, silence, i; unsigned slots, silence, i;
@@ -765,8 +771,8 @@ static void testZeroConfigNode_Test_IDLE_ValidFrameTimeout(
mstp_port->Zero_Config_State == MSTP_ZERO_CONFIG_STATE_IDLE, NULL); mstp_port->Zero_Config_State == MSTP_ZERO_CONFIG_STATE_IDLE, NULL);
} }
static void testZeroConfigNode_Test_IDLE_ValidFrame( static void
struct mstp_port_struct_t *mstp_port) testZeroConfigNode_Test_IDLE_ValidFrame(struct mstp_port_struct_t *mstp_port)
{ {
bool transition_now, non_zero; bool transition_now, non_zero;
unsigned slots, silence, i; unsigned slots, silence, i;
@@ -783,8 +789,8 @@ static void testZeroConfigNode_Test_IDLE_ValidFrame(
zassert_true(mstp_port->ReceivedValidFrame == true, NULL); zassert_true(mstp_port->ReceivedValidFrame == true, NULL);
} }
static void testZeroConfigNode_Test_LURK_AddressInUse( static void
struct mstp_port_struct_t *mstp_port) testZeroConfigNode_Test_LURK_AddressInUse(struct mstp_port_struct_t *mstp_port)
{ {
bool transition_now, non_zero; bool transition_now, non_zero;
unsigned slots, silence, i; unsigned slots, silence, i;
@@ -804,7 +810,8 @@ static void testZeroConfigNode_Test_LURK_AddressInUse(
zassert_true( zassert_true(
mstp_port->Zero_Config_State == MSTP_ZERO_CONFIG_STATE_LURK, NULL); mstp_port->Zero_Config_State == MSTP_ZERO_CONFIG_STATE_LURK, NULL);
zassert_true(mstp_port->ReceivedValidFrame == false, NULL); zassert_true(mstp_port->ReceivedValidFrame == false, NULL);
zassert_true(mstp_port->Zero_Config_Station != src, "src=%u zc=%u", src, zassert_true(
mstp_port->Zero_Config_Station != src, "src=%u zc=%u", src,
mstp_port->Zero_Config_Station); mstp_port->Zero_Config_Station);
} }
} }
@@ -832,8 +839,8 @@ static void testZeroConfigNode_Test_LURK_LearnMaxMaster(
} }
} }
static void testZeroConfigNode_Test_LURK_Claim( static void
struct mstp_port_struct_t *mstp_port) testZeroConfigNode_Test_LURK_Claim(struct mstp_port_struct_t *mstp_port)
{ {
bool transition_now, non_zero; bool transition_now, non_zero;
unsigned slots, silence, i; unsigned slots, silence, i;
@@ -858,8 +865,8 @@ static void testZeroConfigNode_Test_LURK_Claim(
zassert_true( zassert_true(
mstp_port->Zero_Config_State == MSTP_ZERO_CONFIG_STATE_CLAIM, mstp_port->Zero_Config_State == MSTP_ZERO_CONFIG_STATE_CLAIM,
NULL); NULL);
} else if (mstp_port->Zero_Config_State == } else if (
MSTP_ZERO_CONFIG_STATE_LURK) { mstp_port->Zero_Config_State == MSTP_ZERO_CONFIG_STATE_LURK) {
zassert_true( zassert_true(
mstp_port->Poll_Count == (count + 1), "count=%u", count); mstp_port->Poll_Count == (count + 1), "count=%u", count);
zassert_true( zassert_true(
@@ -870,9 +877,11 @@ static void testZeroConfigNode_Test_LURK_Claim(
} }
} }
/* verify the Reply To Poll For Master was sent for confirmation */ /* verify the Reply To Poll For Master was sent for confirmation */
zassert_equal(mstp_port->OutputBuffer[2], FRAME_TYPE_REPLY_TO_POLL_FOR_MASTER, NULL); zassert_equal(
mstp_port->OutputBuffer[2], FRAME_TYPE_REPLY_TO_POLL_FOR_MASTER, NULL);
zassert_equal(mstp_port->OutputBuffer[3], mstp_port->SourceAddress, NULL); zassert_equal(mstp_port->OutputBuffer[3], mstp_port->SourceAddress, NULL);
zassert_equal(mstp_port->OutputBuffer[4], mstp_port->Zero_Config_Station, NULL); zassert_equal(
mstp_port->OutputBuffer[4], mstp_port->Zero_Config_Station, NULL);
} }
static void testZeroConfigNode_Test_LURK_ClaimTokenForUs( static void testZeroConfigNode_Test_LURK_ClaimTokenForUs(
@@ -890,11 +899,13 @@ static void testZeroConfigNode_Test_LURK_ClaimTokenForUs(
transition_now = MSTP_Master_Node_FSM(mstp_port); transition_now = MSTP_Master_Node_FSM(mstp_port);
zassert_false(transition_now, NULL); zassert_false(transition_now, NULL);
zassert_true(mstp_port->ReceivedValidFrame == false, NULL); zassert_true(mstp_port->ReceivedValidFrame == false, NULL);
zassert_equal(mstp_port->Zero_Config_State, MSTP_ZERO_CONFIG_STATE_CONFIRM, NULL); zassert_equal(
mstp_port->Zero_Config_State, MSTP_ZERO_CONFIG_STATE_CONFIRM, NULL);
/* verify the Test Request Frame was sent for confirmation */ /* verify the Test Request Frame was sent for confirmation */
zassert_equal(mstp_port->OutputBuffer[2], FRAME_TYPE_TEST_REQUEST, NULL); zassert_equal(mstp_port->OutputBuffer[2], FRAME_TYPE_TEST_REQUEST, NULL);
zassert_equal(mstp_port->OutputBuffer[3], mstp_port->SourceAddress, NULL); zassert_equal(mstp_port->OutputBuffer[3], mstp_port->SourceAddress, NULL);
zassert_equal(mstp_port->OutputBuffer[4], mstp_port->Zero_Config_Station, NULL); zassert_equal(
mstp_port->OutputBuffer[4], mstp_port->Zero_Config_Station, NULL);
} }
static void testZeroConfigNode_Test_LURK_ConfirmationSuccessful( static void testZeroConfigNode_Test_LURK_ConfirmationSuccessful(
@@ -914,8 +925,10 @@ static void testZeroConfigNode_Test_LURK_ConfirmationSuccessful(
transition_now = MSTP_Master_Node_FSM(mstp_port); transition_now = MSTP_Master_Node_FSM(mstp_port);
zassert_true(transition_now, NULL); zassert_true(transition_now, NULL);
zassert_true(mstp_port->ReceivedValidFrame == false, NULL); zassert_true(mstp_port->ReceivedValidFrame == false, NULL);
zassert_equal(mstp_port->This_Station, mstp_port->Zero_Config_Station, NULL); zassert_equal(
zassert_equal(mstp_port->Zero_Config_State, MSTP_ZERO_CONFIG_STATE_USE, NULL); mstp_port->This_Station, mstp_port->Zero_Config_Station, NULL);
zassert_equal(
mstp_port->Zero_Config_State, MSTP_ZERO_CONFIG_STATE_USE, NULL);
} }
static void testZeroConfigNode_Test_LURK_ConfirmationAddressInUse( static void testZeroConfigNode_Test_LURK_ConfirmationAddressInUse(
@@ -932,7 +945,7 @@ static void testZeroConfigNode_Test_LURK_ConfirmationAddressInUse(
mstp_port->FrameType = FRAME_TYPE_PROPRIETARY_MIN; mstp_port->FrameType = FRAME_TYPE_PROPRIETARY_MIN;
encode_unsigned16(&mstp_port->InputBuffer[0], BACNET_VENDOR_ID); encode_unsigned16(&mstp_port->InputBuffer[0], BACNET_VENDOR_ID);
memcpy(&mstp_port->InputBuffer[2], mstp_port->UUID, MSTP_UUID_SIZE); memcpy(&mstp_port->InputBuffer[2], mstp_port->UUID, MSTP_UUID_SIZE);
mstp_port->DataLength = MSTP_UUID_SIZE+2; mstp_port->DataLength = MSTP_UUID_SIZE + 2;
mstp_port->ReceivedValidFrame = true; mstp_port->ReceivedValidFrame = true;
test_station = mstp_port->Zero_Config_Station + 1; test_station = mstp_port->Zero_Config_Station + 1;
@@ -940,7 +953,8 @@ static void testZeroConfigNode_Test_LURK_ConfirmationAddressInUse(
zassert_false(transition_now, NULL); zassert_false(transition_now, NULL);
zassert_true(mstp_port->ReceivedValidFrame == false, NULL); zassert_true(mstp_port->ReceivedValidFrame == false, NULL);
zassert_equal(test_station, mstp_port->Zero_Config_Station, NULL); zassert_equal(test_station, mstp_port->Zero_Config_Station, NULL);
zassert_equal(mstp_port->Zero_Config_State, MSTP_ZERO_CONFIG_STATE_LURK, NULL); zassert_equal(
mstp_port->Zero_Config_State, MSTP_ZERO_CONFIG_STATE_LURK, NULL);
} }
static void testZeroConfigNode_Test_LURK_ConfirmationUnuccessful_UUID_Size( static void testZeroConfigNode_Test_LURK_ConfirmationUnuccessful_UUID_Size(
@@ -956,12 +970,13 @@ static void testZeroConfigNode_Test_LURK_ConfirmationUnuccessful_UUID_Size(
mstp_port->FrameType = FRAME_TYPE_TEST_RESPONSE; mstp_port->FrameType = FRAME_TYPE_TEST_RESPONSE;
memcpy(mstp_port->InputBuffer, mstp_port->UUID, MSTP_UUID_SIZE); memcpy(mstp_port->InputBuffer, mstp_port->UUID, MSTP_UUID_SIZE);
/* set to an invalid size */ /* set to an invalid size */
mstp_port->DataLength = MSTP_UUID_SIZE-1; mstp_port->DataLength = MSTP_UUID_SIZE - 1;
mstp_port->ReceivedValidFrame = true; mstp_port->ReceivedValidFrame = true;
transition_now = MSTP_Master_Node_FSM(mstp_port); transition_now = MSTP_Master_Node_FSM(mstp_port);
zassert_false(transition_now, NULL); zassert_false(transition_now, NULL);
zassert_true(mstp_port->ReceivedValidFrame == false, NULL); zassert_true(mstp_port->ReceivedValidFrame == false, NULL);
zassert_equal(mstp_port->Zero_Config_State, MSTP_ZERO_CONFIG_STATE_IDLE, NULL); zassert_equal(
mstp_port->Zero_Config_State, MSTP_ZERO_CONFIG_STATE_IDLE, NULL);
} }
static void testZeroConfigNode_Test_LURK_ConfirmationUnuccessful_UUID( static void testZeroConfigNode_Test_LURK_ConfirmationUnuccessful_UUID(
@@ -983,7 +998,8 @@ static void testZeroConfigNode_Test_LURK_ConfirmationUnuccessful_UUID(
transition_now = MSTP_Master_Node_FSM(mstp_port); transition_now = MSTP_Master_Node_FSM(mstp_port);
zassert_false(transition_now, NULL); zassert_false(transition_now, NULL);
zassert_true(mstp_port->ReceivedValidFrame == false, NULL); zassert_true(mstp_port->ReceivedValidFrame == false, NULL);
zassert_equal(mstp_port->Zero_Config_State, MSTP_ZERO_CONFIG_STATE_IDLE, NULL); zassert_equal(
mstp_port->Zero_Config_State, MSTP_ZERO_CONFIG_STATE_IDLE, NULL);
} }
static void testZeroConfigNode_Test_LURK_ClaimAddressInUse( static void testZeroConfigNode_Test_LURK_ClaimAddressInUse(
@@ -1001,7 +1017,8 @@ static void testZeroConfigNode_Test_LURK_ClaimAddressInUse(
transition_now = MSTP_Master_Node_FSM(mstp_port); transition_now = MSTP_Master_Node_FSM(mstp_port);
zassert_false(transition_now, NULL); zassert_false(transition_now, NULL);
zassert_true(mstp_port->ReceivedValidFrame == false, NULL); zassert_true(mstp_port->ReceivedValidFrame == false, NULL);
zassert_equal(mstp_port->Zero_Config_State, MSTP_ZERO_CONFIG_STATE_LURK, NULL); zassert_equal(
mstp_port->Zero_Config_State, MSTP_ZERO_CONFIG_STATE_LURK, NULL);
zassert_equal(mstp_port->Zero_Config_Station, station + 1, NULL); zassert_equal(mstp_port->Zero_Config_Station, station + 1, NULL);
} }
@@ -1016,7 +1033,8 @@ static void testZeroConfigNode_Test_LURK_ClaimInvalidFrame(
transition_now = MSTP_Master_Node_FSM(mstp_port); transition_now = MSTP_Master_Node_FSM(mstp_port);
zassert_false(transition_now, NULL); zassert_false(transition_now, NULL);
zassert_true(mstp_port->ReceivedInvalidFrame == false, NULL); zassert_true(mstp_port->ReceivedInvalidFrame == false, NULL);
zassert_equal(mstp_port->Zero_Config_State, MSTP_ZERO_CONFIG_STATE_CLAIM, NULL); zassert_equal(
mstp_port->Zero_Config_State, MSTP_ZERO_CONFIG_STATE_CLAIM, NULL);
} }
static void testZeroConfigNode_Test_LURK_ClaimLostToken( static void testZeroConfigNode_Test_LURK_ClaimLostToken(
@@ -1030,10 +1048,10 @@ static void testZeroConfigNode_Test_LURK_ClaimLostToken(
SilenceTime = mstp_port->Zero_Config_Silence + 1; SilenceTime = mstp_port->Zero_Config_Silence + 1;
transition_now = MSTP_Master_Node_FSM(mstp_port); transition_now = MSTP_Master_Node_FSM(mstp_port);
zassert_false(transition_now, NULL); zassert_false(transition_now, NULL);
zassert_equal(mstp_port->Zero_Config_State, MSTP_ZERO_CONFIG_STATE_IDLE, NULL); zassert_equal(
mstp_port->Zero_Config_State, MSTP_ZERO_CONFIG_STATE_IDLE, NULL);
} }
static void testZeroConfigNodeFSM(void) static void testZeroConfigNodeFSM(void)
{ {
struct mstp_port_struct_t MSTP_Port = { 0 }; /* port data */ struct mstp_port_struct_t MSTP_Port = { 0 }; /* port data */
@@ -1107,7 +1125,8 @@ static void testZeroConfigNodeFSM(void)
void test_main(void) void test_main(void)
{ {
ztest_test_suite(crc_tests, ztest_unit_test(testReceiveNodeFSM), ztest_test_suite(
crc_tests, ztest_unit_test(testReceiveNodeFSM),
ztest_unit_test(testMasterNodeFSM), ztest_unit_test(testSlaveNodeFSM), ztest_unit_test(testMasterNodeFSM), ztest_unit_test(testSlaveNodeFSM),
ztest_unit_test(testZeroConfigNodeFSM)); ztest_unit_test(testZeroConfigNodeFSM));
+16 -12
View File
@@ -62,7 +62,8 @@
*/ */
static void datetime_print(const char *title, BACNET_DATE_TIME *bdatetime) static void datetime_print(const char *title, BACNET_DATE_TIME *bdatetime)
{ {
printf("%s: %04u/%02u/%02u %02u:%02u:%02u.%03u\n", title, printf(
"%s: %04u/%02u/%02u %02u:%02u:%02u.%03u\n", title,
(unsigned int)bdatetime->date.year, (unsigned int)bdatetime->date.month, (unsigned int)bdatetime->date.year, (unsigned int)bdatetime->date.month,
(unsigned int)bdatetime->date.wday, (unsigned int)bdatetime->time.hour, (unsigned int)bdatetime->date.wday, (unsigned int)bdatetime->time.hour,
(unsigned int)bdatetime->time.min, (unsigned int)bdatetime->time.sec, (unsigned int)bdatetime->time.min, (unsigned int)bdatetime->time.sec,
@@ -400,14 +401,16 @@ static void testDayOfYear(void)
datetime_set_date(&bdate, year, month, day); datetime_set_date(&bdate, year, month, day);
days = datetime_day_of_year(&bdate); days = datetime_day_of_year(&bdate);
datetime_day_of_year_into_date(days, year, &test_bdate); datetime_day_of_year_into_date(days, year, &test_bdate);
zassert_equal(datetime_compare_date(&bdate, &test_bdate), 0, zassert_equal(
datetime_compare_date(&bdate, &test_bdate), 0,
"year=%u month=%u day=%u", year, month, day); "year=%u month=%u day=%u", year, month, day);
} }
} }
} }
} }
static void testDateEpochConversionCompare(uint16_t year, static void testDateEpochConversionCompare(
uint16_t year,
uint8_t month, uint8_t month,
uint8_t day, uint8_t day,
uint8_t hour, uint8_t hour,
@@ -465,8 +468,9 @@ static void testDateEpoch(void)
for (month = 1; month <= 12; month++) { for (month = 1; month <= 12; month++) {
for (day = 1; day <= days_per_month(year, month); day++) { for (day = 1; day <= days_per_month(year, month); day++) {
days = days_since_epoch(BACNET_EPOCH_YEAR, year, month, day); days = days_since_epoch(BACNET_EPOCH_YEAR, year, month, day);
days_since_epoch_to_date(BACNET_EPOCH_YEAR, days, &test_year, days_since_epoch_to_date(
&test_month, &test_day); BACNET_EPOCH_YEAR, days, &test_year, &test_month,
&test_day);
zassert_equal(year, test_year, NULL); zassert_equal(year, test_year, NULL);
zassert_equal(month, test_month, NULL); zassert_equal(month, test_month, NULL);
zassert_equal(day, test_day, NULL); zassert_equal(day, test_day, NULL);
@@ -559,12 +563,12 @@ static void testDatetimeCodec(void)
zassert_equal(diff, 0, NULL); zassert_equal(diff, 0, NULL);
/* test for invalid date tag */ /* test for invalid date tag */
apdu_len = bacapp_encode_datetime(apdu, &datetimeIn); apdu_len = bacapp_encode_datetime(apdu, &datetimeIn);
encode_tag(apdu, BACNET_APPLICATION_TAG_REAL, false, 4); encode_tag(apdu, BACNET_APPLICATION_TAG_REAL, false, 4);
test_len = bacnet_datetime_decode(&apdu[0], apdu_len, &datetimeOut); test_len = bacnet_datetime_decode(&apdu[0], apdu_len, &datetimeOut);
zassert_equal(test_len, BACNET_STATUS_ERROR, NULL); zassert_equal(test_len, BACNET_STATUS_ERROR, NULL);
/* test for invalid time tag */ /* test for invalid time tag */
apdu_len = bacapp_encode_datetime(apdu, &datetimeIn); apdu_len = bacapp_encode_datetime(apdu, &datetimeIn);
encode_tag(&apdu[5], BACNET_APPLICATION_TAG_REAL, false, 4); encode_tag(&apdu[5], BACNET_APPLICATION_TAG_REAL, false, 4);
test_len = bacnet_datetime_decode(apdu, apdu_len, &datetimeOut); test_len = bacnet_datetime_decode(apdu, apdu_len, &datetimeOut);
zassert_equal(test_len, BACNET_STATUS_ERROR, NULL); zassert_equal(test_len, BACNET_STATUS_ERROR, NULL);
/* ERROR too short APDU */ /* ERROR too short APDU */
@@ -601,7 +605,8 @@ static void testDatetimeCodec(void)
zassert_equal(diff, 0, NULL); zassert_equal(diff, 0, NULL);
} }
static void testDatetimeConvertUTCSpecific(BACNET_DATE_TIME *utc_time, static void testDatetimeConvertUTCSpecific(
BACNET_DATE_TIME *utc_time,
BACNET_DATE_TIME *local_time, BACNET_DATE_TIME *local_time,
int16_t utc_offset_minutes, int16_t utc_offset_minutes,
int8_t dst_adjust_minutes) int8_t dst_adjust_minutes)
@@ -668,10 +673,9 @@ void test_main(void)
ztest_unit_test(testBACnetDateTimeSeconds), ztest_unit_test(testBACnetDateTimeSeconds),
ztest_unit_test(testDayOfYear), ztest_unit_test(testDayOfYear),
#endif #endif
ztest_test_suite(bacnet_datetime, ztest_test_suite(
ztest_unit_test(testBACnetDate), bacnet_datetime, ztest_unit_test(testBACnetDate),
ztest_unit_test(testBACnetTime), ztest_unit_test(testBACnetTime), ztest_unit_test(testBACnetDateTime),
ztest_unit_test(testBACnetDateTime),
ztest_unit_test(testBACnetDayOfWeek), ztest_unit_test(testBACnetDayOfWeek),
ztest_unit_test(testDateEpochConversion), ztest_unit_test(testDateEpochConversion),
ztest_unit_test(testBACnetDateTimeAdd), ztest_unit_test(testBACnetDateTimeAdd),
+40 -30
View File
@@ -19,7 +19,8 @@
/** /**
* @brief Test * @brief Test
*/ */
static int dcc_decode_apdu(uint8_t *apdu, static int dcc_decode_apdu(
uint8_t *apdu,
unsigned apdu_size, unsigned apdu_size,
uint8_t *invoke_id, uint8_t *invoke_id,
uint16_t *timeDuration, uint16_t *timeDuration,
@@ -46,8 +47,9 @@ static int dcc_decode_apdu(uint8_t *apdu,
return BACNET_STATUS_ERROR; return BACNET_STATUS_ERROR;
} }
if (apdu_size > apdu_len) { if (apdu_size > apdu_len) {
len = dcc_decode_service_request(&apdu[apdu_len], apdu_size - apdu_len, len = dcc_decode_service_request(
timeDuration, enable_disable, password); &apdu[apdu_len], apdu_size - apdu_len, timeDuration, enable_disable,
password);
if (len > 0) { if (len > 0) {
apdu_len += len; apdu_len += len;
} else { } else {
@@ -58,7 +60,8 @@ static int dcc_decode_apdu(uint8_t *apdu,
return apdu_len; return apdu_len;
} }
static void test_DeviceCommunicationControlData(uint8_t invoke_id, static void test_DeviceCommunicationControlData(
uint8_t invoke_id,
uint16_t timeDuration, uint16_t timeDuration,
BACNET_COMMUNICATION_ENABLE_DISABLE enable_disable, BACNET_COMMUNICATION_ENABLE_DISABLE enable_disable,
BACNET_CHARACTER_STRING *password) BACNET_CHARACTER_STRING *password)
@@ -77,17 +80,18 @@ static void test_DeviceCommunicationControlData(uint8_t invoke_id,
zassert_equal(apdu_size, null_len, NULL); zassert_equal(apdu_size, null_len, NULL);
zassert_not_equal(apdu_size, 0, NULL); zassert_not_equal(apdu_size, 0, NULL);
test_len = dcc_decode_apdu(&apdu[0], apdu_size, &test_invoke_id, test_len = dcc_decode_apdu(
&test_timeDuration, &test_enable_disable, &test_password); &apdu[0], apdu_size, &test_invoke_id, &test_timeDuration,
&test_enable_disable, &test_password);
zassert_not_equal(test_len, -1, NULL); zassert_not_equal(test_len, -1, NULL);
zassert_equal(test_invoke_id, invoke_id, NULL); zassert_equal(test_invoke_id, invoke_id, NULL);
zassert_equal(test_timeDuration, timeDuration, NULL); zassert_equal(test_timeDuration, timeDuration, NULL);
zassert_equal(test_enable_disable, enable_disable, NULL); zassert_equal(test_enable_disable, enable_disable, NULL);
zassert_true(characterstring_same(&test_password, password), NULL); zassert_true(characterstring_same(&test_password, password), NULL);
test_len = dcc_decode_apdu(apdu, 4, &test_invoke_id, test_len = dcc_decode_apdu(
&test_timeDuration, &test_enable_disable, &test_password); apdu, 4, &test_invoke_id, &test_timeDuration, &test_enable_disable,
zassert_true(test_len < 0, "apdu_size=%d test_len=%d", &test_password);
apdu_size, test_len); zassert_true(test_len < 0, "apdu_size=%d test_len=%d", apdu_size, test_len);
} }
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
@@ -126,37 +130,43 @@ static void test_DeviceCommunicationControlMalformedData(void)
uint8_t payload_1[] = { 0x19, 0x00, 0x2a, 0x00, 0x41 }; uint8_t payload_1[] = { 0x19, 0x00, 0x2a, 0x00, 0x41 };
/* payload with enable-disable, and password with wrong characterstring /* payload with enable-disable, and password with wrong characterstring
* length */ * length */
uint8_t payload_2[] = { 0x19, 0x00, 0x2d, 0x55, 0x00, 0x66, 0x69, 0x73, uint8_t payload_2[] = { 0x19, 0x00, 0x2d, 0x55, 0x00, 0x66,
0x74, 0x65, 0x72 }; 0x69, 0x73, 0x74, 0x65, 0x72 };
/* payload with enable-disable - wrong context tag number for password */ /* payload with enable-disable - wrong context tag number for password */
uint8_t payload_3[] = { 0x19, 0x01, 0x3d, 0x09, 0x00, 0x66, 0x69, 0x73, uint8_t payload_3[] = { 0x19, 0x01, 0x3d, 0x09, 0x00, 0x66,
0x74, 0x65, 0x72 }; 0x69, 0x73, 0x74, 0x65, 0x72 };
/* payload with duration, enable-disable, and password */ /* payload with duration, enable-disable, and password */
uint8_t payload_4[] = { 0x00, 0x05, 0xf1, 0x11, 0x0a, 0x00, 0x19, 0x00, uint8_t payload_4[] = { 0x00, 0x05, 0xf1, 0x11, 0x0a, 0x00,
0x2d, 0x09, 0x00, 0x66, 0x69, 0x73, 0x74, 0x65, 0x72 }; 0x19, 0x00, 0x2d, 0x09, 0x00, 0x66,
0x69, 0x73, 0x74, 0x65, 0x72 };
/* payload submitted with bug report */ /* payload submitted with bug report */
uint8_t payload_5[] = { 0x0d, 0xff, 0x80, 0x00, 0x03, 0x1a, 0x0a, 0x19, uint8_t payload_5[] = { 0x0d, 0xff, 0x80, 0x00, 0x03, 0x1a,
0x00, 0x2a, 0x00, 0x41 }; 0x0a, 0x19, 0x00, 0x2a, 0x00, 0x41 };
int len = 0; int len = 0;
uint8_t test_invoke_id = 0; uint8_t test_invoke_id = 0;
uint16_t test_timeDuration = 0; uint16_t test_timeDuration = 0;
BACNET_COMMUNICATION_ENABLE_DISABLE test_enable_disable; BACNET_COMMUNICATION_ENABLE_DISABLE test_enable_disable;
BACNET_CHARACTER_STRING test_password; BACNET_CHARACTER_STRING test_password;
len = dcc_decode_apdu(&payload_1[0], sizeof(payload_1), &test_invoke_id, len = dcc_decode_apdu(
&test_timeDuration, &test_enable_disable, &test_password); &payload_1[0], sizeof(payload_1), &test_invoke_id, &test_timeDuration,
&test_enable_disable, &test_password);
zassert_equal(len, BACNET_STATUS_ERROR, NULL); zassert_equal(len, BACNET_STATUS_ERROR, NULL);
len = dcc_decode_apdu(&payload_2[0], sizeof(payload_2), &test_invoke_id, len = dcc_decode_apdu(
&test_timeDuration, &test_enable_disable, &test_password); &payload_2[0], sizeof(payload_2), &test_invoke_id, &test_timeDuration,
&test_enable_disable, &test_password);
zassert_equal(len, BACNET_STATUS_ERROR, NULL); zassert_equal(len, BACNET_STATUS_ERROR, NULL);
len = dcc_decode_apdu(&payload_3[0], sizeof(payload_3), &test_invoke_id, len = dcc_decode_apdu(
&test_timeDuration, &test_enable_disable, &test_password); &payload_3[0], sizeof(payload_3), &test_invoke_id, &test_timeDuration,
&test_enable_disable, &test_password);
zassert_equal(len, BACNET_STATUS_ERROR, NULL); zassert_equal(len, BACNET_STATUS_ERROR, NULL);
len = dcc_decode_apdu(&payload_4[0], sizeof(payload_4), &test_invoke_id, len = dcc_decode_apdu(
&test_timeDuration, &test_enable_disable, &test_password); &payload_4[0], sizeof(payload_4), &test_invoke_id, &test_timeDuration,
&test_enable_disable, &test_password);
zassert_equal(len, BACNET_STATUS_ABORT, NULL); zassert_equal(len, BACNET_STATUS_ABORT, NULL);
len = dcc_decode_apdu(&payload_5[0], sizeof(payload_5), &test_invoke_id, len = dcc_decode_apdu(
&test_timeDuration, &test_enable_disable, &test_password); &payload_5[0], sizeof(payload_5), &test_invoke_id, &test_timeDuration,
&test_enable_disable, &test_password);
zassert_equal(len, BACNET_STATUS_ERROR, NULL); zassert_equal(len, BACNET_STATUS_ERROR, NULL);
} }
/** /**
@@ -168,8 +178,8 @@ ZTEST_SUITE(dcc_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(dcc_tests, ztest_test_suite(
ztest_unit_test(test_DeviceCommunicationControl), dcc_tests, ztest_unit_test(test_DeviceCommunicationControl),
ztest_unit_test(test_DeviceCommunicationControlMalformedData)); ztest_unit_test(test_DeviceCommunicationControlMalformedData));
ztest_run_test_suite(dcc_tests); ztest_run_test_suite(dcc_tests);
+276 -155
View File
@@ -25,14 +25,18 @@ static BACNET_EVENT_NOTIFICATION_DATA data2;
static void verifyBaseEventState(void) static void verifyBaseEventState(void)
{ {
zassert_equal(data.processIdentifier, data2.processIdentifier, NULL); zassert_equal(data.processIdentifier, data2.processIdentifier, NULL);
zassert_equal(data.initiatingObjectIdentifier.instance, zassert_equal(
data.initiatingObjectIdentifier.instance,
data2.initiatingObjectIdentifier.instance, NULL); data2.initiatingObjectIdentifier.instance, NULL);
zassert_equal(data.initiatingObjectIdentifier.type, zassert_equal(
data.initiatingObjectIdentifier.type,
data2.initiatingObjectIdentifier.type, NULL); data2.initiatingObjectIdentifier.type, NULL);
zassert_equal(data.eventObjectIdentifier.instance, zassert_equal(
data.eventObjectIdentifier.instance,
data2.eventObjectIdentifier.instance, NULL); data2.eventObjectIdentifier.instance, NULL);
zassert_equal(data.eventObjectIdentifier.type, zassert_equal(
data2.eventObjectIdentifier.type, NULL); data.eventObjectIdentifier.type, data2.eventObjectIdentifier.type,
NULL);
zassert_equal(data.notificationClass, data2.notificationClass, NULL); zassert_equal(data.notificationClass, data2.notificationClass, NULL);
zassert_equal(data.priority, data2.priority, NULL); zassert_equal(data.priority, data2.priority, NULL);
zassert_equal(data.notifyType, data2.notifyType, NULL); zassert_equal(data.notifyType, data2.notifyType, NULL);
@@ -53,38 +57,51 @@ static void verifyBaseEventState(void)
switch (data.timeStamp.tag) { switch (data.timeStamp.tag) {
case TIME_STAMP_SEQUENCE: case TIME_STAMP_SEQUENCE:
zassert_equal(data.timeStamp.value.sequenceNum, zassert_equal(
data.timeStamp.value.sequenceNum,
data2.timeStamp.value.sequenceNum, NULL); data2.timeStamp.value.sequenceNum, NULL);
break; break;
case TIME_STAMP_DATETIME: case TIME_STAMP_DATETIME:
zassert_equal(data.timeStamp.value.dateTime.time.hour, zassert_equal(
data.timeStamp.value.dateTime.time.hour,
data2.timeStamp.value.dateTime.time.hour, NULL); data2.timeStamp.value.dateTime.time.hour, NULL);
zassert_equal(data.timeStamp.value.dateTime.time.min, zassert_equal(
data.timeStamp.value.dateTime.time.min,
data2.timeStamp.value.dateTime.time.min, NULL); data2.timeStamp.value.dateTime.time.min, NULL);
zassert_equal(data.timeStamp.value.dateTime.time.sec, zassert_equal(
data.timeStamp.value.dateTime.time.sec,
data2.timeStamp.value.dateTime.time.sec, NULL); data2.timeStamp.value.dateTime.time.sec, NULL);
zassert_equal(data.timeStamp.value.dateTime.time.hundredths, zassert_equal(
data.timeStamp.value.dateTime.time.hundredths,
data2.timeStamp.value.dateTime.time.hundredths, NULL); data2.timeStamp.value.dateTime.time.hundredths, NULL);
zassert_equal(data.timeStamp.value.dateTime.date.day, zassert_equal(
data.timeStamp.value.dateTime.date.day,
data2.timeStamp.value.dateTime.date.day, NULL); data2.timeStamp.value.dateTime.date.day, NULL);
zassert_equal(data.timeStamp.value.dateTime.date.month, zassert_equal(
data.timeStamp.value.dateTime.date.month,
data2.timeStamp.value.dateTime.date.month, NULL); data2.timeStamp.value.dateTime.date.month, NULL);
zassert_equal(data.timeStamp.value.dateTime.date.wday, zassert_equal(
data.timeStamp.value.dateTime.date.wday,
data2.timeStamp.value.dateTime.date.wday, NULL); data2.timeStamp.value.dateTime.date.wday, NULL);
zassert_equal(data.timeStamp.value.dateTime.date.year, zassert_equal(
data.timeStamp.value.dateTime.date.year,
data2.timeStamp.value.dateTime.date.year, NULL); data2.timeStamp.value.dateTime.date.year, NULL);
break; break;
case TIME_STAMP_TIME: case TIME_STAMP_TIME:
zassert_equal(data.timeStamp.value.time.hour, zassert_equal(
data2.timeStamp.value.time.hour, NULL); data.timeStamp.value.time.hour, data2.timeStamp.value.time.hour,
zassert_equal(data.timeStamp.value.time.min, NULL);
data2.timeStamp.value.time.min, NULL); zassert_equal(
zassert_equal(data.timeStamp.value.time.sec, data.timeStamp.value.time.min, data2.timeStamp.value.time.min,
data2.timeStamp.value.time.sec, NULL); NULL);
zassert_equal(data.timeStamp.value.time.hundredths, zassert_equal(
data.timeStamp.value.time.sec, data2.timeStamp.value.time.sec,
NULL);
zassert_equal(
data.timeStamp.value.time.hundredths,
data2.timeStamp.value.time.hundredths, NULL); data2.timeStamp.value.time.hundredths, NULL);
break; break;
@@ -132,13 +149,17 @@ static void testEventEventState(void)
UNITS_SQUARE_METERS; UNITS_SQUARE_METERS;
bitstring_init(&data.notificationParams.changeOfState.statusFlags); bitstring_init(&data.notificationParams.changeOfState.statusFlags);
bitstring_set_bit(&data.notificationParams.changeOfState.statusFlags, bitstring_set_bit(
&data.notificationParams.changeOfState.statusFlags,
STATUS_FLAG_IN_ALARM, true); STATUS_FLAG_IN_ALARM, true);
bitstring_set_bit(&data.notificationParams.changeOfState.statusFlags, bitstring_set_bit(
STATUS_FLAG_FAULT, false); &data.notificationParams.changeOfState.statusFlags, STATUS_FLAG_FAULT,
bitstring_set_bit(&data.notificationParams.changeOfState.statusFlags, false);
bitstring_set_bit(
&data.notificationParams.changeOfState.statusFlags,
STATUS_FLAG_OVERRIDDEN, false); STATUS_FLAG_OVERRIDDEN, false);
bitstring_set_bit(&data.notificationParams.changeOfState.statusFlags, bitstring_set_bit(
&data.notificationParams.changeOfState.statusFlags,
STATUS_FLAG_OUT_OF_SERVICE, false); STATUS_FLAG_OUT_OF_SERVICE, false);
null_len = event_notify_encode_service_request(NULL, &data); null_len = event_notify_encode_service_request(NULL, &data);
@@ -151,13 +172,16 @@ static void testEventEventState(void)
apdu_len, test_len, "apdu_len=%d test_len=%d", apdu_len, test_len); apdu_len, test_len, "apdu_len=%d test_len=%d", apdu_len, test_len);
verifyBaseEventState(); verifyBaseEventState();
zassert_equal(data.notificationParams.changeOfState.newState.tag, zassert_equal(
data.notificationParams.changeOfState.newState.tag,
data2.notificationParams.changeOfState.newState.tag, NULL); data2.notificationParams.changeOfState.newState.tag, NULL);
zassert_equal(data.notificationParams.changeOfState.newState.state.units, zassert_equal(
data.notificationParams.changeOfState.newState.state.units,
data2.notificationParams.changeOfState.newState.state.units, NULL); data2.notificationParams.changeOfState.newState.state.units, NULL);
zassert_true( zassert_true(
bitstring_same(&data.notificationParams.changeOfState.statusFlags, bitstring_same(
&data.notificationParams.changeOfState.statusFlags,
&data2.notificationParams.changeOfState.statusFlags), &data2.notificationParams.changeOfState.statusFlags),
NULL); NULL);
@@ -188,9 +212,11 @@ static void testEventEventState(void)
zassert_equal(apdu_len, test_len, NULL); zassert_equal(apdu_len, test_len, NULL);
verifyBaseEventState(); verifyBaseEventState();
zassert_equal(data.notificationParams.changeOfState.newState.tag, zassert_equal(
data.notificationParams.changeOfState.newState.tag,
data2.notificationParams.changeOfState.newState.tag, NULL); data2.notificationParams.changeOfState.newState.tag, NULL);
zassert_equal(data.notificationParams.changeOfState.newState.state.units, zassert_equal(
data.notificationParams.changeOfState.newState.state.units,
data2.notificationParams.changeOfState.newState.state.units, NULL); data2.notificationParams.changeOfState.newState.state.units, NULL);
/* /*
** Event Type = EVENT_CHANGE_OF_BITSTRING ** Event Type = EVENT_CHANGE_OF_BITSTRING
@@ -217,13 +243,17 @@ static void testEventEventState(void)
bitstring_init(&data.notificationParams.changeOfBitstring.statusFlags); bitstring_init(&data.notificationParams.changeOfBitstring.statusFlags);
bitstring_set_bit(&data.notificationParams.changeOfBitstring.statusFlags, bitstring_set_bit(
&data.notificationParams.changeOfBitstring.statusFlags,
STATUS_FLAG_IN_ALARM, true); STATUS_FLAG_IN_ALARM, true);
bitstring_set_bit(&data.notificationParams.changeOfBitstring.statusFlags, bitstring_set_bit(
&data.notificationParams.changeOfBitstring.statusFlags,
STATUS_FLAG_FAULT, false); STATUS_FLAG_FAULT, false);
bitstring_set_bit(&data.notificationParams.changeOfBitstring.statusFlags, bitstring_set_bit(
&data.notificationParams.changeOfBitstring.statusFlags,
STATUS_FLAG_OVERRIDDEN, false); STATUS_FLAG_OVERRIDDEN, false);
bitstring_set_bit(&data.notificationParams.changeOfBitstring.statusFlags, bitstring_set_bit(
&data.notificationParams.changeOfBitstring.statusFlags,
STATUS_FLAG_OUT_OF_SERVICE, false); STATUS_FLAG_OUT_OF_SERVICE, false);
memset(buffer, 0, MAX_APDU); memset(buffer, 0, MAX_APDU);
@@ -247,7 +277,8 @@ static void testEventEventState(void)
NULL); NULL);
zassert_true( zassert_true(
bitstring_same(&data.notificationParams.changeOfBitstring.statusFlags, bitstring_same(
&data.notificationParams.changeOfBitstring.statusFlags,
&data2.notificationParams.changeOfBitstring.statusFlags), &data2.notificationParams.changeOfBitstring.statusFlags),
NULL); NULL);
@@ -260,13 +291,17 @@ static void testEventEventState(void)
bitstring_init(&data.notificationParams.changeOfValue.statusFlags); bitstring_init(&data.notificationParams.changeOfValue.statusFlags);
bitstring_set_bit(&data.notificationParams.changeOfValue.statusFlags, bitstring_set_bit(
&data.notificationParams.changeOfValue.statusFlags,
STATUS_FLAG_IN_ALARM, true); STATUS_FLAG_IN_ALARM, true);
bitstring_set_bit(&data.notificationParams.changeOfValue.statusFlags, bitstring_set_bit(
STATUS_FLAG_FAULT, false); &data.notificationParams.changeOfValue.statusFlags, STATUS_FLAG_FAULT,
bitstring_set_bit(&data.notificationParams.changeOfValue.statusFlags, false);
bitstring_set_bit(
&data.notificationParams.changeOfValue.statusFlags,
STATUS_FLAG_OVERRIDDEN, false); STATUS_FLAG_OVERRIDDEN, false);
bitstring_set_bit(&data.notificationParams.changeOfValue.statusFlags, bitstring_set_bit(
&data.notificationParams.changeOfValue.statusFlags,
STATUS_FLAG_OUT_OF_SERVICE, false); STATUS_FLAG_OUT_OF_SERVICE, false);
memset(buffer, 0, MAX_APDU); memset(buffer, 0, MAX_APDU);
@@ -284,16 +319,20 @@ static void testEventEventState(void)
verifyBaseEventState(); verifyBaseEventState();
zassert_true( zassert_true(
bitstring_same(&data.notificationParams.changeOfValue.statusFlags, bitstring_same(
&data.notificationParams.changeOfValue.statusFlags,
&data2.notificationParams.changeOfValue.statusFlags), &data2.notificationParams.changeOfValue.statusFlags),
NULL); NULL);
zassert_equal(data.notificationParams.changeOfValue.tag, zassert_equal(
data.notificationParams.changeOfValue.tag,
data2.notificationParams.changeOfValue.tag, NULL); data2.notificationParams.changeOfValue.tag, NULL);
zassert_false(islessgreater( zassert_false(
data.notificationParams.changeOfValue.newValue.changeValue, islessgreater(
data2.notificationParams.changeOfValue.newValue.changeValue), NULL); data.notificationParams.changeOfValue.newValue.changeValue,
data2.notificationParams.changeOfValue.newValue.changeValue),
NULL);
/* /*
** Event Type = EVENT_CHANGE_OF_VALUE - bitstring value ** Event Type = EVENT_CHANGE_OF_VALUE - bitstring value
@@ -322,10 +361,12 @@ static void testEventEventState(void)
verifyBaseEventState(); verifyBaseEventState();
zassert_true( zassert_true(
bitstring_same(&data.notificationParams.changeOfValue.statusFlags, bitstring_same(
&data.notificationParams.changeOfValue.statusFlags,
&data2.notificationParams.changeOfValue.statusFlags), &data2.notificationParams.changeOfValue.statusFlags),
NULL); NULL);
zassert_equal(data.notificationParams.changeOfValue.tag, zassert_equal(
data.notificationParams.changeOfValue.tag,
data2.notificationParams.changeOfValue.tag, NULL); data2.notificationParams.changeOfValue.tag, NULL);
zassert_true( zassert_true(
bitstring_same( bitstring_same(
@@ -347,13 +388,17 @@ static void testEventEventState(void)
data.notificationParams.commandFailure.feedbackValue.binaryValue = data.notificationParams.commandFailure.feedbackValue.binaryValue =
BINARY_ACTIVE; BINARY_ACTIVE;
bitstring_init(&data.notificationParams.commandFailure.statusFlags); bitstring_init(&data.notificationParams.commandFailure.statusFlags);
bitstring_set_bit(&data.notificationParams.commandFailure.statusFlags, bitstring_set_bit(
&data.notificationParams.commandFailure.statusFlags,
STATUS_FLAG_IN_ALARM, true); STATUS_FLAG_IN_ALARM, true);
bitstring_set_bit(&data.notificationParams.commandFailure.statusFlags, bitstring_set_bit(
STATUS_FLAG_FAULT, false); &data.notificationParams.commandFailure.statusFlags, STATUS_FLAG_FAULT,
bitstring_set_bit(&data.notificationParams.commandFailure.statusFlags, false);
bitstring_set_bit(
&data.notificationParams.commandFailure.statusFlags,
STATUS_FLAG_OVERRIDDEN, false); STATUS_FLAG_OVERRIDDEN, false);
bitstring_set_bit(&data.notificationParams.commandFailure.statusFlags, bitstring_set_bit(
&data.notificationParams.commandFailure.statusFlags,
STATUS_FLAG_OUT_OF_SERVICE, false); STATUS_FLAG_OUT_OF_SERVICE, false);
memset(buffer, 0, MAX_APDU); memset(buffer, 0, MAX_APDU);
null_len = event_notify_encode_service_request(NULL, &data); null_len = event_notify_encode_service_request(NULL, &data);
@@ -379,7 +424,8 @@ static void testEventEventState(void)
NULL); NULL);
zassert_true( zassert_true(
bitstring_same(&data.notificationParams.commandFailure.statusFlags, bitstring_same(
&data.notificationParams.commandFailure.statusFlags,
&data2.notificationParams.commandFailure.statusFlags), &data2.notificationParams.commandFailure.statusFlags),
NULL); NULL);
@@ -393,13 +439,17 @@ static void testEventEventState(void)
bitstring_init(&data.notificationParams.commandFailure.statusFlags); bitstring_init(&data.notificationParams.commandFailure.statusFlags);
bitstring_set_bit(&data.notificationParams.commandFailure.statusFlags, bitstring_set_bit(
&data.notificationParams.commandFailure.statusFlags,
STATUS_FLAG_IN_ALARM, true); STATUS_FLAG_IN_ALARM, true);
bitstring_set_bit(&data.notificationParams.commandFailure.statusFlags, bitstring_set_bit(
STATUS_FLAG_FAULT, false); &data.notificationParams.commandFailure.statusFlags, STATUS_FLAG_FAULT,
bitstring_set_bit(&data.notificationParams.commandFailure.statusFlags, false);
bitstring_set_bit(
&data.notificationParams.commandFailure.statusFlags,
STATUS_FLAG_OVERRIDDEN, false); STATUS_FLAG_OVERRIDDEN, false);
bitstring_set_bit(&data.notificationParams.commandFailure.statusFlags, bitstring_set_bit(
&data.notificationParams.commandFailure.statusFlags,
STATUS_FLAG_OUT_OF_SERVICE, false); STATUS_FLAG_OUT_OF_SERVICE, false);
memset(buffer, 0, MAX_APDU); memset(buffer, 0, MAX_APDU);
@@ -427,7 +477,8 @@ static void testEventEventState(void)
NULL); NULL);
zassert_true( zassert_true(
bitstring_same(&data.notificationParams.commandFailure.statusFlags, bitstring_same(
&data.notificationParams.commandFailure.statusFlags,
&data2.notificationParams.commandFailure.statusFlags), &data2.notificationParams.commandFailure.statusFlags),
NULL); NULL);
@@ -441,13 +492,17 @@ static void testEventEventState(void)
bitstring_init(&data.notificationParams.floatingLimit.statusFlags); bitstring_init(&data.notificationParams.floatingLimit.statusFlags);
bitstring_set_bit(&data.notificationParams.floatingLimit.statusFlags, bitstring_set_bit(
&data.notificationParams.floatingLimit.statusFlags,
STATUS_FLAG_IN_ALARM, true); STATUS_FLAG_IN_ALARM, true);
bitstring_set_bit(&data.notificationParams.floatingLimit.statusFlags, bitstring_set_bit(
STATUS_FLAG_FAULT, false); &data.notificationParams.floatingLimit.statusFlags, STATUS_FLAG_FAULT,
bitstring_set_bit(&data.notificationParams.floatingLimit.statusFlags, false);
bitstring_set_bit(
&data.notificationParams.floatingLimit.statusFlags,
STATUS_FLAG_OVERRIDDEN, false); STATUS_FLAG_OVERRIDDEN, false);
bitstring_set_bit(&data.notificationParams.floatingLimit.statusFlags, bitstring_set_bit(
&data.notificationParams.floatingLimit.statusFlags,
STATUS_FLAG_OUT_OF_SERVICE, false); STATUS_FLAG_OUT_OF_SERVICE, false);
memset(buffer, 0, MAX_APDU); memset(buffer, 0, MAX_APDU);
@@ -463,17 +518,24 @@ static void testEventEventState(void)
apdu_len, test_len, "apdu_len=%d test_len=%d", apdu_len, test_len); apdu_len, test_len, "apdu_len=%d test_len=%d", apdu_len, test_len);
verifyBaseEventState(); verifyBaseEventState();
zassert_false(islessgreater( zassert_false(
data.notificationParams.floatingLimit.referenceValue, islessgreater(
data2.notificationParams.floatingLimit.referenceValue), NULL); data.notificationParams.floatingLimit.referenceValue,
zassert_false(islessgreater( data2.notificationParams.floatingLimit.referenceValue),
data.notificationParams.floatingLimit.setPointValue, NULL);
data2.notificationParams.floatingLimit.setPointValue), NULL); zassert_false(
zassert_false(islessgreater( islessgreater(
data.notificationParams.floatingLimit.errorLimit, data.notificationParams.floatingLimit.setPointValue,
data2.notificationParams.floatingLimit.errorLimit), NULL); data2.notificationParams.floatingLimit.setPointValue),
NULL);
zassert_false(
islessgreater(
data.notificationParams.floatingLimit.errorLimit,
data2.notificationParams.floatingLimit.errorLimit),
NULL);
zassert_true( zassert_true(
bitstring_same(&data.notificationParams.floatingLimit.statusFlags, bitstring_same(
&data.notificationParams.floatingLimit.statusFlags,
&data2.notificationParams.floatingLimit.statusFlags), &data2.notificationParams.floatingLimit.statusFlags),
NULL); NULL);
@@ -487,13 +549,17 @@ static void testEventEventState(void)
bitstring_init(&data.notificationParams.outOfRange.statusFlags); bitstring_init(&data.notificationParams.outOfRange.statusFlags);
bitstring_set_bit(&data.notificationParams.outOfRange.statusFlags, bitstring_set_bit(
STATUS_FLAG_IN_ALARM, true); &data.notificationParams.outOfRange.statusFlags, STATUS_FLAG_IN_ALARM,
bitstring_set_bit(&data.notificationParams.outOfRange.statusFlags, true);
STATUS_FLAG_FAULT, false); bitstring_set_bit(
bitstring_set_bit(&data.notificationParams.outOfRange.statusFlags, &data.notificationParams.outOfRange.statusFlags, STATUS_FLAG_FAULT,
STATUS_FLAG_OVERRIDDEN, false); false);
bitstring_set_bit(&data.notificationParams.outOfRange.statusFlags, bitstring_set_bit(
&data.notificationParams.outOfRange.statusFlags, STATUS_FLAG_OVERRIDDEN,
false);
bitstring_set_bit(
&data.notificationParams.outOfRange.statusFlags,
STATUS_FLAG_OUT_OF_SERVICE, false); STATUS_FLAG_OUT_OF_SERVICE, false);
memset(buffer, 0, MAX_APDU); memset(buffer, 0, MAX_APDU);
@@ -510,18 +576,27 @@ static void testEventEventState(void)
zassert_equal(apdu_len, test_len, NULL); zassert_equal(apdu_len, test_len, NULL);
verifyBaseEventState(); verifyBaseEventState();
zassert_false(islessgreater(data.notificationParams.outOfRange.deadband, zassert_false(
data2.notificationParams.outOfRange.deadband), NULL); islessgreater(
data.notificationParams.outOfRange.deadband,
data2.notificationParams.outOfRange.deadband),
NULL);
zassert_false(islessgreater( zassert_false(
data.notificationParams.outOfRange.exceededLimit, islessgreater(
data2.notificationParams.outOfRange.exceededLimit), NULL); data.notificationParams.outOfRange.exceededLimit,
data2.notificationParams.outOfRange.exceededLimit),
NULL);
zassert_false(islessgreater( zassert_false(
data.notificationParams.outOfRange.exceedingValue, islessgreater(
data2.notificationParams.outOfRange.exceedingValue), NULL); data.notificationParams.outOfRange.exceedingValue,
zassert_true(bitstring_same(&data.notificationParams.outOfRange.statusFlags, data2.notificationParams.outOfRange.exceedingValue),
&data2.notificationParams.outOfRange.statusFlags), NULL);
zassert_true(
bitstring_same(
&data.notificationParams.outOfRange.statusFlags,
&data2.notificationParams.outOfRange.statusFlags),
NULL); NULL);
/* /*
@@ -536,13 +611,17 @@ static void testEventEventState(void)
bitstring_init(&data.notificationParams.changeOfLifeSafety.statusFlags); bitstring_init(&data.notificationParams.changeOfLifeSafety.statusFlags);
bitstring_set_bit(&data.notificationParams.changeOfLifeSafety.statusFlags, bitstring_set_bit(
&data.notificationParams.changeOfLifeSafety.statusFlags,
STATUS_FLAG_IN_ALARM, true); STATUS_FLAG_IN_ALARM, true);
bitstring_set_bit(&data.notificationParams.changeOfLifeSafety.statusFlags, bitstring_set_bit(
&data.notificationParams.changeOfLifeSafety.statusFlags,
STATUS_FLAG_FAULT, false); STATUS_FLAG_FAULT, false);
bitstring_set_bit(&data.notificationParams.changeOfLifeSafety.statusFlags, bitstring_set_bit(
&data.notificationParams.changeOfLifeSafety.statusFlags,
STATUS_FLAG_OVERRIDDEN, false); STATUS_FLAG_OVERRIDDEN, false);
bitstring_set_bit(&data.notificationParams.changeOfLifeSafety.statusFlags, bitstring_set_bit(
&data.notificationParams.changeOfLifeSafety.statusFlags,
STATUS_FLAG_OUT_OF_SERVICE, false); STATUS_FLAG_OUT_OF_SERVICE, false);
memset(buffer, 0, MAX_APDU); memset(buffer, 0, MAX_APDU);
@@ -559,17 +638,21 @@ static void testEventEventState(void)
zassert_equal(apdu_len, test_len, NULL); zassert_equal(apdu_len, test_len, NULL);
verifyBaseEventState(); verifyBaseEventState();
zassert_equal(data.notificationParams.changeOfLifeSafety.newMode, zassert_equal(
data.notificationParams.changeOfLifeSafety.newMode,
data2.notificationParams.changeOfLifeSafety.newMode, NULL); data2.notificationParams.changeOfLifeSafety.newMode, NULL);
zassert_equal(data.notificationParams.changeOfLifeSafety.newState, zassert_equal(
data.notificationParams.changeOfLifeSafety.newState,
data2.notificationParams.changeOfLifeSafety.newState, NULL); data2.notificationParams.changeOfLifeSafety.newState, NULL);
zassert_equal(data.notificationParams.changeOfLifeSafety.operationExpected, zassert_equal(
data.notificationParams.changeOfLifeSafety.operationExpected,
data2.notificationParams.changeOfLifeSafety.operationExpected, NULL); data2.notificationParams.changeOfLifeSafety.operationExpected, NULL);
zassert_true( zassert_true(
bitstring_same(&data.notificationParams.changeOfLifeSafety.statusFlags, bitstring_same(
&data.notificationParams.changeOfLifeSafety.statusFlags,
&data2.notificationParams.changeOfLifeSafety.statusFlags), &data2.notificationParams.changeOfLifeSafety.statusFlags),
NULL); NULL);
@@ -582,13 +665,17 @@ static void testEventEventState(void)
bitstring_init(&data.notificationParams.unsignedRange.statusFlags); bitstring_init(&data.notificationParams.unsignedRange.statusFlags);
bitstring_set_bit(&data.notificationParams.unsignedRange.statusFlags, bitstring_set_bit(
&data.notificationParams.unsignedRange.statusFlags,
STATUS_FLAG_IN_ALARM, true); STATUS_FLAG_IN_ALARM, true);
bitstring_set_bit(&data.notificationParams.unsignedRange.statusFlags, bitstring_set_bit(
STATUS_FLAG_FAULT, false); &data.notificationParams.unsignedRange.statusFlags, STATUS_FLAG_FAULT,
bitstring_set_bit(&data.notificationParams.unsignedRange.statusFlags, false);
bitstring_set_bit(
&data.notificationParams.unsignedRange.statusFlags,
STATUS_FLAG_OVERRIDDEN, false); STATUS_FLAG_OVERRIDDEN, false);
bitstring_set_bit(&data.notificationParams.unsignedRange.statusFlags, bitstring_set_bit(
&data.notificationParams.unsignedRange.statusFlags,
STATUS_FLAG_OUT_OF_SERVICE, false); STATUS_FLAG_OUT_OF_SERVICE, false);
memset(buffer, 0, MAX_APDU); memset(buffer, 0, MAX_APDU);
@@ -605,14 +692,17 @@ static void testEventEventState(void)
zassert_equal(apdu_len, test_len, NULL); zassert_equal(apdu_len, test_len, NULL);
verifyBaseEventState(); verifyBaseEventState();
zassert_equal(data.notificationParams.unsignedRange.exceedingValue, zassert_equal(
data.notificationParams.unsignedRange.exceedingValue,
data2.notificationParams.unsignedRange.exceedingValue, NULL); data2.notificationParams.unsignedRange.exceedingValue, NULL);
zassert_equal(data.notificationParams.unsignedRange.exceededLimit, zassert_equal(
data.notificationParams.unsignedRange.exceededLimit,
data2.notificationParams.unsignedRange.exceededLimit, NULL); data2.notificationParams.unsignedRange.exceededLimit, NULL);
zassert_true( zassert_true(
bitstring_same(&data.notificationParams.unsignedRange.statusFlags, bitstring_same(
&data.notificationParams.unsignedRange.statusFlags,
&data2.notificationParams.unsignedRange.statusFlags), &data2.notificationParams.unsignedRange.statusFlags),
NULL); NULL);
@@ -648,32 +738,38 @@ static void testEventEventState(void)
zassert_equal(apdu_len, test_len, NULL); zassert_equal(apdu_len, test_len, NULL);
verifyBaseEventState(); verifyBaseEventState();
zassert_equal(data.notificationParams.bufferReady.previousNotification, zassert_equal(
data.notificationParams.bufferReady.previousNotification,
data2.notificationParams.bufferReady.previousNotification, NULL); data2.notificationParams.bufferReady.previousNotification, NULL);
zassert_equal(data.notificationParams.bufferReady.currentNotification, zassert_equal(
data.notificationParams.bufferReady.currentNotification,
data2.notificationParams.bufferReady.currentNotification, NULL); data2.notificationParams.bufferReady.currentNotification, NULL);
zassert_equal(data.notificationParams.bufferReady.bufferProperty zassert_equal(
.deviceIdentifier.type, data.notificationParams.bufferReady.bufferProperty.deviceIdentifier
.type,
data2.notificationParams.bufferReady.bufferProperty.deviceIdentifier data2.notificationParams.bufferReady.bufferProperty.deviceIdentifier
.type, .type,
NULL); NULL);
zassert_equal(data.notificationParams.bufferReady.bufferProperty zassert_equal(
.deviceIdentifier.instance, data.notificationParams.bufferReady.bufferProperty.deviceIdentifier
.instance,
data2.notificationParams.bufferReady.bufferProperty.deviceIdentifier data2.notificationParams.bufferReady.bufferProperty.deviceIdentifier
.instance, .instance,
NULL); NULL);
zassert_equal(data.notificationParams.bufferReady.bufferProperty zassert_equal(
.objectIdentifier.instance, data.notificationParams.bufferReady.bufferProperty.objectIdentifier
.instance,
data2.notificationParams.bufferReady.bufferProperty.objectIdentifier data2.notificationParams.bufferReady.bufferProperty.objectIdentifier
.instance, .instance,
NULL); NULL);
zassert_equal(data.notificationParams.bufferReady.bufferProperty zassert_equal(
.objectIdentifier.type, data.notificationParams.bufferReady.bufferProperty.objectIdentifier
.type,
data2.notificationParams.bufferReady.bufferProperty.objectIdentifier data2.notificationParams.bufferReady.bufferProperty.objectIdentifier
.type, .type,
NULL); NULL);
@@ -683,7 +779,8 @@ static void testEventEventState(void)
data2.notificationParams.bufferReady.bufferProperty.propertyIdentifier, data2.notificationParams.bufferReady.bufferProperty.propertyIdentifier,
NULL); NULL);
zassert_equal(data.notificationParams.bufferReady.bufferProperty.arrayIndex, zassert_equal(
data.notificationParams.bufferReady.bufferProperty.arrayIndex,
data2.notificationParams.bufferReady.bufferProperty.arrayIndex, NULL); data2.notificationParams.bufferReady.bufferProperty.arrayIndex, NULL);
/* /*
@@ -710,13 +807,17 @@ static void testEventEventState(void)
AUTHENTICATION_FACTOR_MAX; // omit authenticationFactor AUTHENTICATION_FACTOR_MAX; // omit authenticationFactor
bitstring_init(&data.notificationParams.accessEvent.statusFlags); bitstring_init(&data.notificationParams.accessEvent.statusFlags);
bitstring_set_bit(&data.notificationParams.accessEvent.statusFlags, bitstring_set_bit(
STATUS_FLAG_IN_ALARM, true); &data.notificationParams.accessEvent.statusFlags, STATUS_FLAG_IN_ALARM,
bitstring_set_bit(&data.notificationParams.accessEvent.statusFlags, true);
STATUS_FLAG_FAULT, false); bitstring_set_bit(
bitstring_set_bit(&data.notificationParams.accessEvent.statusFlags, &data.notificationParams.accessEvent.statusFlags, STATUS_FLAG_FAULT,
false);
bitstring_set_bit(
&data.notificationParams.accessEvent.statusFlags,
STATUS_FLAG_OVERRIDDEN, false); STATUS_FLAG_OVERRIDDEN, false);
bitstring_set_bit(&data.notificationParams.accessEvent.statusFlags, bitstring_set_bit(
&data.notificationParams.accessEvent.statusFlags,
STATUS_FLAG_OUT_OF_SERVICE, false); STATUS_FLAG_OUT_OF_SERVICE, false);
memset(buffer, 0, MAX_APDU); memset(buffer, 0, MAX_APDU);
@@ -733,18 +834,22 @@ static void testEventEventState(void)
zassert_equal(apdu_len, test_len, NULL); zassert_equal(apdu_len, test_len, NULL);
verifyBaseEventState(); verifyBaseEventState();
zassert_equal(data.notificationParams.accessEvent.accessEvent, zassert_equal(
data.notificationParams.accessEvent.accessEvent,
data2.notificationParams.accessEvent.accessEvent, NULL); data2.notificationParams.accessEvent.accessEvent, NULL);
zassert_true( zassert_true(
bitstring_same(&data.notificationParams.accessEvent.statusFlags, bitstring_same(
&data.notificationParams.accessEvent.statusFlags,
&data2.notificationParams.accessEvent.statusFlags), &data2.notificationParams.accessEvent.statusFlags),
NULL); NULL);
zassert_equal(data.notificationParams.accessEvent.accessEventTag, zassert_equal(
data.notificationParams.accessEvent.accessEventTag,
data2.notificationParams.accessEvent.accessEventTag, NULL); data2.notificationParams.accessEvent.accessEventTag, NULL);
zassert_equal(data.notificationParams.accessEvent.accessEventTime.tag, zassert_equal(
data.notificationParams.accessEvent.accessEventTime.tag,
data2.notificationParams.accessEvent.accessEventTime.tag, NULL); data2.notificationParams.accessEvent.accessEventTime.tag, NULL);
zassert_equal( zassert_equal(
@@ -752,26 +857,30 @@ static void testEventEventState(void)
data2.notificationParams.accessEvent.accessEventTime.value.sequenceNum, data2.notificationParams.accessEvent.accessEventTime.value.sequenceNum,
NULL); NULL);
zassert_equal(data.notificationParams.accessEvent.accessCredential zassert_equal(
.deviceIdentifier.instance, data.notificationParams.accessEvent.accessCredential.deviceIdentifier
.instance,
data2.notificationParams.accessEvent.accessCredential.deviceIdentifier data2.notificationParams.accessEvent.accessCredential.deviceIdentifier
.instance, .instance,
NULL); NULL);
zassert_equal(data.notificationParams.accessEvent.accessCredential zassert_equal(
.deviceIdentifier.type, data.notificationParams.accessEvent.accessCredential.deviceIdentifier
.type,
data2.notificationParams.accessEvent.accessCredential.deviceIdentifier data2.notificationParams.accessEvent.accessCredential.deviceIdentifier
.type, .type,
NULL); NULL);
zassert_equal(data.notificationParams.accessEvent.accessCredential zassert_equal(
.objectIdentifier.instance, data.notificationParams.accessEvent.accessCredential.objectIdentifier
.instance,
data2.notificationParams.accessEvent.accessCredential.objectIdentifier data2.notificationParams.accessEvent.accessCredential.objectIdentifier
.instance, .instance,
NULL); NULL);
zassert_equal(data.notificationParams.accessEvent.accessCredential zassert_equal(
.objectIdentifier.type, data.notificationParams.accessEvent.accessCredential.objectIdentifier
.type,
data2.notificationParams.accessEvent.accessCredential.objectIdentifier data2.notificationParams.accessEvent.accessCredential.objectIdentifier
.type, .type,
NULL); NULL);
@@ -802,13 +911,17 @@ static void testEventEventState(void)
octetstringValue, 2); octetstringValue, 2);
bitstring_init(&data.notificationParams.accessEvent.statusFlags); bitstring_init(&data.notificationParams.accessEvent.statusFlags);
bitstring_set_bit(&data.notificationParams.accessEvent.statusFlags, bitstring_set_bit(
STATUS_FLAG_IN_ALARM, true); &data.notificationParams.accessEvent.statusFlags, STATUS_FLAG_IN_ALARM,
bitstring_set_bit(&data.notificationParams.accessEvent.statusFlags, true);
STATUS_FLAG_FAULT, false); bitstring_set_bit(
bitstring_set_bit(&data.notificationParams.accessEvent.statusFlags, &data.notificationParams.accessEvent.statusFlags, STATUS_FLAG_FAULT,
false);
bitstring_set_bit(
&data.notificationParams.accessEvent.statusFlags,
STATUS_FLAG_OVERRIDDEN, false); STATUS_FLAG_OVERRIDDEN, false);
bitstring_set_bit(&data.notificationParams.accessEvent.statusFlags, bitstring_set_bit(
&data.notificationParams.accessEvent.statusFlags,
STATUS_FLAG_OUT_OF_SERVICE, false); STATUS_FLAG_OUT_OF_SERVICE, false);
memset(buffer, 0, MAX_APDU); memset(buffer, 0, MAX_APDU);
@@ -825,18 +938,22 @@ static void testEventEventState(void)
zassert_equal(apdu_len, test_len, NULL); zassert_equal(apdu_len, test_len, NULL);
verifyBaseEventState(); verifyBaseEventState();
zassert_equal(data.notificationParams.accessEvent.accessEvent, zassert_equal(
data.notificationParams.accessEvent.accessEvent,
data2.notificationParams.accessEvent.accessEvent, NULL); data2.notificationParams.accessEvent.accessEvent, NULL);
zassert_true( zassert_true(
bitstring_same(&data.notificationParams.accessEvent.statusFlags, bitstring_same(
&data.notificationParams.accessEvent.statusFlags,
&data2.notificationParams.accessEvent.statusFlags), &data2.notificationParams.accessEvent.statusFlags),
NULL); NULL);
zassert_equal(data.notificationParams.accessEvent.accessEventTag, zassert_equal(
data.notificationParams.accessEvent.accessEventTag,
data2.notificationParams.accessEvent.accessEventTag, NULL); data2.notificationParams.accessEvent.accessEventTag, NULL);
zassert_equal(data.notificationParams.accessEvent.accessEventTime.tag, zassert_equal(
data.notificationParams.accessEvent.accessEventTime.tag,
data2.notificationParams.accessEvent.accessEventTime.tag, NULL); data2.notificationParams.accessEvent.accessEventTime.tag, NULL);
zassert_equal( zassert_equal(
@@ -844,26 +961,30 @@ static void testEventEventState(void)
data2.notificationParams.accessEvent.accessEventTime.value.sequenceNum, data2.notificationParams.accessEvent.accessEventTime.value.sequenceNum,
NULL); NULL);
zassert_equal(data.notificationParams.accessEvent.accessCredential zassert_equal(
.deviceIdentifier.instance, data.notificationParams.accessEvent.accessCredential.deviceIdentifier
.instance,
data2.notificationParams.accessEvent.accessCredential.deviceIdentifier data2.notificationParams.accessEvent.accessCredential.deviceIdentifier
.instance, .instance,
NULL); NULL);
zassert_equal(data.notificationParams.accessEvent.accessCredential zassert_equal(
.deviceIdentifier.type, data.notificationParams.accessEvent.accessCredential.deviceIdentifier
.type,
data2.notificationParams.accessEvent.accessCredential.deviceIdentifier data2.notificationParams.accessEvent.accessCredential.deviceIdentifier
.type, .type,
NULL); NULL);
zassert_equal(data.notificationParams.accessEvent.accessCredential zassert_equal(
.objectIdentifier.instance, data.notificationParams.accessEvent.accessCredential.objectIdentifier
.instance,
data2.notificationParams.accessEvent.accessCredential.objectIdentifier data2.notificationParams.accessEvent.accessCredential.objectIdentifier
.instance, .instance,
NULL); NULL);
zassert_equal(data.notificationParams.accessEvent.accessCredential zassert_equal(
.objectIdentifier.type, data.notificationParams.accessEvent.accessCredential.objectIdentifier
.type,
data2.notificationParams.accessEvent.accessCredential.objectIdentifier data2.notificationParams.accessEvent.accessCredential.objectIdentifier
.type, .type,
NULL); NULL);
+13 -16
View File
@@ -23,9 +23,8 @@
* @param invoke_id - unique sequence number sent with the message * @param invoke_id - unique sequence number sent with the message
* @return number of bytes decoded * @return number of bytes decoded
*/ */
static int get_alarm_summary_decode_apdu(uint8_t *apdu, static int get_alarm_summary_decode_apdu(
unsigned apdu_size, uint8_t *apdu, unsigned apdu_size, uint8_t *invoke_id)
uint8_t *invoke_id)
{ {
int len = 0; int len = 0;
@@ -55,7 +54,8 @@ static int get_alarm_summary_decode_apdu(uint8_t *apdu,
* @param invoke_id - unique sequence number sent with the message * @param invoke_id - unique sequence number sent with the message
* @return number of bytes decoded * @return number of bytes decoded
*/ */
static int get_alarm_summary_ack_decode_apdu(uint8_t *apdu, static int get_alarm_summary_ack_decode_apdu(
uint8_t *apdu,
int apdu_len, int apdu_len,
uint8_t *invoke_id, uint8_t *invoke_id,
BACNET_GET_ALARM_SUMMARY_DATA *get_alarm_data) BACNET_GET_ALARM_SUMMARY_DATA *get_alarm_data)
@@ -112,8 +112,7 @@ static void testGetAlarmSummaryAck(void)
bitstring_set_bit( bitstring_set_bit(
&alarm_data.acknowledgedTransitions, TRANSITION_TO_NORMAL, false); &alarm_data.acknowledgedTransitions, TRANSITION_TO_NORMAL, false);
/* encode the initial service */ /* encode the initial service */
len = get_alarm_summary_ack_encode_apdu_init(&apdu[0], len = get_alarm_summary_ack_encode_apdu_init(&apdu[0], invoke_id);
invoke_id);
zassert_not_equal(len, 0, NULL); zassert_not_equal(len, 0, NULL);
zassert_not_equal(len, -1, NULL); zassert_not_equal(len, -1, NULL);
apdu_len = len; apdu_len = len;
@@ -123,18 +122,18 @@ static void testGetAlarmSummaryAck(void)
zassert_not_equal(len, 0, NULL); zassert_not_equal(len, 0, NULL);
zassert_not_equal(len, -1, NULL); zassert_not_equal(len, -1, NULL);
apdu_len += len; apdu_len += len;
len = get_alarm_summary_ack_decode_apdu(&apdu[0], len = get_alarm_summary_ack_decode_apdu(
apdu_len, /* total length of the apdu */ &apdu[0], apdu_len, /* total length of the apdu */
&test_invoke_id, &test_alarm_data); &test_invoke_id, &test_alarm_data);
zassert_not_equal(len, -1, NULL); zassert_not_equal(len, -1, NULL);
zassert_equal(test_invoke_id, invoke_id, NULL); zassert_equal(test_invoke_id, invoke_id, NULL);
zassert_equal( zassert_equal(
alarm_data.objectIdentifier.type, alarm_data.objectIdentifier.type, test_alarm_data.objectIdentifier.type,
test_alarm_data.objectIdentifier.type, NULL); NULL);
zassert_equal( zassert_equal(
alarm_data.objectIdentifier.instance, alarm_data.objectIdentifier.instance,
test_alarm_data.objectIdentifier.instance, NULL); test_alarm_data.objectIdentifier.instance, NULL);
zassert_equal(alarm_data.alarmState, test_alarm_data.alarmState, NULL); zassert_equal(alarm_data.alarmState, test_alarm_data.alarmState, NULL);
} }
@@ -162,7 +161,6 @@ static void testGetAlarmSummary(void)
return; return;
} }
/** /**
* Main entry point for testing * Main entry point for testing
*/ */
@@ -171,10 +169,9 @@ ZTEST_SUITE(getalarm_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(getalarm_tests, ztest_test_suite(
ztest_unit_test(testGetAlarmSummary), getalarm_tests, ztest_unit_test(testGetAlarmSummary),
ztest_unit_test(testGetAlarmSummaryAck) ztest_unit_test(testGetAlarmSummaryAck));
);
ztest_run_test_suite(getalarm_tests); ztest_run_test_suite(getalarm_tests);
} }
+20 -18
View File
@@ -19,7 +19,8 @@
/** /**
* @brief Test * @brief Test
*/ */
static int getevent_decode_apdu(uint8_t *apdu, static int getevent_decode_apdu(
uint8_t *apdu,
unsigned apdu_size, unsigned apdu_size,
uint8_t *invoke_id, uint8_t *invoke_id,
BACNET_OBJECT_ID *lastReceivedObjectIdentifier) BACNET_OBJECT_ID *lastReceivedObjectIdentifier)
@@ -44,7 +45,8 @@ static int getevent_decode_apdu(uint8_t *apdu,
if (apdu_size > apdu_len) { if (apdu_size > apdu_len) {
len = getevent_decode_service_request( len = getevent_decode_service_request(
&apdu[apdu_len], apdu_size - apdu_len, lastReceivedObjectIdentifier); &apdu[apdu_len], apdu_size - apdu_len,
lastReceivedObjectIdentifier);
if (len > 0) { if (len > 0) {
apdu_len += len; apdu_len += len;
} else { } else {
@@ -55,7 +57,8 @@ static int getevent_decode_apdu(uint8_t *apdu,
return apdu_len; return apdu_len;
} }
static int getevent_ack_decode_apdu(uint8_t *apdu, static int getevent_ack_decode_apdu(
uint8_t *apdu,
int apdu_len, /* total length of the apdu */ int apdu_len, /* total length of the apdu */
uint8_t *invoke_id, uint8_t *invoke_id,
BACNET_GET_EVENT_INFORMATION_DATA *get_event_data, BACNET_GET_EVENT_INFORMATION_DATA *get_event_data,
@@ -136,18 +139,18 @@ static void testGetEventInformationAck(void)
zassert_not_equal(len, 0, NULL); zassert_not_equal(len, 0, NULL);
zassert_not_equal(len, -1, NULL); zassert_not_equal(len, -1, NULL);
apdu_len += len; apdu_len += len;
len = getevent_ack_decode_apdu(&apdu[0], len = getevent_ack_decode_apdu(
apdu_len, /* total length of the apdu */ &apdu[0], apdu_len, /* total length of the apdu */
&test_invoke_id, &test_event_data, &test_moreEvents); &test_invoke_id, &test_event_data, &test_moreEvents);
zassert_not_equal(len, -1, NULL); zassert_not_equal(len, -1, NULL);
zassert_equal(test_invoke_id, invoke_id, NULL); zassert_equal(test_invoke_id, invoke_id, NULL);
zassert_equal( zassert_equal(
event_data.objectIdentifier.type, event_data.objectIdentifier.type, test_event_data.objectIdentifier.type,
test_event_data.objectIdentifier.type, NULL); NULL);
zassert_equal( zassert_equal(
event_data.objectIdentifier.instance, event_data.objectIdentifier.instance,
test_event_data.objectIdentifier.instance, NULL); test_event_data.objectIdentifier.instance, NULL);
zassert_equal(event_data.eventState, test_event_data.eventState, NULL); zassert_equal(event_data.eventState, test_event_data.eventState, NULL);
} }
@@ -167,14 +170,15 @@ static void testGetEventInformation(void)
lastReceivedObjectIdentifier.type = OBJECT_BINARY_INPUT; lastReceivedObjectIdentifier.type = OBJECT_BINARY_INPUT;
lastReceivedObjectIdentifier.instance = 12345; lastReceivedObjectIdentifier.instance = 12345;
null_len = getevent_encode_apdu( null_len =
NULL, invoke_id, &lastReceivedObjectIdentifier); getevent_encode_apdu(NULL, invoke_id, &lastReceivedObjectIdentifier);
apdu_len = getevent_encode_apdu( apdu_len = getevent_encode_apdu(
&apdu[0], invoke_id, &lastReceivedObjectIdentifier); &apdu[0], invoke_id, &lastReceivedObjectIdentifier);
zassert_equal(apdu_len, null_len, NULL); zassert_equal(apdu_len, null_len, NULL);
zassert_not_equal(apdu_len, 0, NULL); zassert_not_equal(apdu_len, 0, NULL);
test_len = getevent_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, test_len = getevent_decode_apdu(
&apdu[0], apdu_len, &test_invoke_id,
&test_lastReceivedObjectIdentifier); &test_lastReceivedObjectIdentifier);
zassert_equal( zassert_equal(
apdu_len, test_len, "apdu_len=%d test_len=%d", apdu_len, test_len); apdu_len, test_len, "apdu_len=%d test_len=%d", apdu_len, test_len);
@@ -182,10 +186,10 @@ static void testGetEventInformation(void)
zassert_equal(test_invoke_id, invoke_id, NULL); zassert_equal(test_invoke_id, invoke_id, NULL);
zassert_equal( zassert_equal(
test_lastReceivedObjectIdentifier.type, test_lastReceivedObjectIdentifier.type,
lastReceivedObjectIdentifier.type, NULL); lastReceivedObjectIdentifier.type, NULL);
zassert_equal( zassert_equal(
test_lastReceivedObjectIdentifier.instance, test_lastReceivedObjectIdentifier.instance,
lastReceivedObjectIdentifier.instance, NULL); lastReceivedObjectIdentifier.instance, NULL);
return; return;
} }
@@ -193,16 +197,14 @@ static void testGetEventInformation(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(getevent_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(getevent_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(getevent_tests, ztest_test_suite(
ztest_unit_test(testGetEventInformation), getevent_tests, ztest_unit_test(testGetEventInformation),
ztest_unit_test(testGetEventInformationAck) ztest_unit_test(testGetEventInformationAck));
);
ztest_run_test_suite(getevent_tests); ztest_run_test_suite(getevent_tests);
} }
+4 -4
View File
@@ -41,10 +41,10 @@ static void test_HostNPortCodec(BACNET_HOST_N_PORT *data)
zassert_equal(apdu_len, null_len, NULL); zassert_equal(apdu_len, null_len, NULL);
zassert_true(apdu_len != BACNET_STATUS_ERROR, NULL); zassert_true(apdu_len != BACNET_STATUS_ERROR, NULL);
null_len = host_n_port_context_decode(apdu, apdu_len, tag_number, null_len = host_n_port_context_decode(
&error_code, NULL); apdu, apdu_len, tag_number, &error_code, NULL);
test_len = host_n_port_context_decode(apdu, apdu_len, tag_number, test_len = host_n_port_context_decode(
&error_code, &test_data); apdu, apdu_len, tag_number, &error_code, &test_data);
zassert_equal(test_len, null_len, NULL); zassert_equal(test_len, null_len, NULL);
zassert_true(test_len > 0, "test_len=%d", len); zassert_true(test_len > 0, "test_len=%d", len);
status = host_n_port_same(&test_data, data); status = host_n_port_same(&test_data, data);
+6 -7
View File
@@ -19,7 +19,8 @@
/** /**
* @brief Test * @brief Test
*/ */
static int iam_decode_apdu(uint8_t *apdu, static int iam_decode_apdu(
uint8_t *apdu,
uint32_t *pDevice_id, uint32_t *pDevice_id,
unsigned *pMax_apdu, unsigned *pMax_apdu,
int *pSegmentation, int *pSegmentation,
@@ -62,8 +63,9 @@ static void testIAm(void)
iam_encode_apdu(&apdu[0], device_id, max_apdu, segmentation, vendor_id); iam_encode_apdu(&apdu[0], device_id, max_apdu, segmentation, vendor_id);
zassert_not_equal(len, 0, NULL); zassert_not_equal(len, 0, NULL);
len = iam_decode_apdu(&apdu[0], &test_device_id, &test_max_apdu, len = iam_decode_apdu(
&test_segmentation, &test_vendor_id); &apdu[0], &test_device_id, &test_max_apdu, &test_segmentation,
&test_vendor_id);
zassert_not_equal(len, -1, NULL); zassert_not_equal(len, -1, NULL);
zassert_equal(test_device_id, device_id, NULL); zassert_equal(test_device_id, device_id, NULL);
@@ -75,15 +77,12 @@ static void testIAm(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(iam_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(iam_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(iam_tests, ztest_test_suite(iam_tests, ztest_unit_test(testIAm));
ztest_unit_test(testIAm)
);
ztest_run_test_suite(iam_tests); ztest_run_test_suite(iam_tests);
} }
+1 -4
View File
@@ -68,15 +68,12 @@ static void testIHave(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(ihave_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(ihave_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(ihave_tests, ztest_test_suite(ihave_tests, ztest_unit_test(testIHave));
ztest_unit_test(testIHave)
);
ztest_run_test_suite(ihave_tests); ztest_run_test_suite(ihave_tests);
} }
+6 -7
View File
@@ -19,8 +19,9 @@
/** /**
* @brief Test * @brief Test
*/ */
static INDTEXT_DATA data_list[] = { { 1, "Joshua" }, { 2, "Mary" }, static INDTEXT_DATA data_list[] = { { 1, "Joshua" }, { 2, "Mary" },
{ 3, "Anna" }, { 4, "Christopher" }, { 5, "Patricia" }, { 0, NULL } }; { 3, "Anna" }, { 4, "Christopher" },
{ 5, "Patricia" }, { 0, NULL } };
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST(indtext_tests, testIndexText) ZTEST(indtext_tests, testIndexText)
@@ -42,7 +43,8 @@ static void testIndexText(void)
zassert_true(valid, NULL); zassert_true(valid, NULL);
zassert_equal(index, i, NULL); zassert_equal(index, i, NULL);
zassert_equal( zassert_equal(
index, indtext_by_string_default(data_list, pString, index), NULL); index, indtext_by_string_default(data_list, pString, index),
NULL);
} }
} }
zassert_equal(indtext_count(data_list), count, NULL); zassert_equal(indtext_count(data_list), count, NULL);
@@ -63,15 +65,12 @@ static void testIndexText(void)
* @} * @}
*/ */
#if defined(CONFIG_ZTEST_NEW_API) #if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(indtext_tests, NULL, NULL, NULL, NULL, NULL); ZTEST_SUITE(indtext_tests, NULL, NULL, NULL, NULL, NULL);
#else #else
void test_main(void) void test_main(void)
{ {
ztest_test_suite(indtext_tests, ztest_test_suite(indtext_tests, ztest_unit_test(testIndexText));
ztest_unit_test(testIndexText)
);
ztest_run_test_suite(indtext_tests); ztest_run_test_suite(indtext_tests);
} }

Some files were not shown because too many files have changed in this diff Show More