Issue 87 execute tests with GitHub ci (#234)
* Enable lcov coverage in unit testing via cmake. * fix pipeline build error * add compile options for unit test to silence some warnings * remove all BAC_TEST unit tests in src/bacnet/ folder. They are now in test/bacnet/ folders using ztest. * removed key.c - only used for unit test. * produce XML test result output for parsing * produce junit XML test result output * change lint workflow to quality * update readme badge for quality results Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
@@ -332,324 +332,3 @@ int ptransfer_ack_encode_apdu(uint8_t *apdu,
|
||||
|
||||
/* ptransfer_ack_decode_service_request() is the same as
|
||||
ptransfer_decode_service_request */
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
#include "bacnet/bacapp.h"
|
||||
|
||||
int ptransfer_decode_apdu(uint8_t *apdu,
|
||||
unsigned apdu_len,
|
||||
uint8_t *invoke_id,
|
||||
BACNET_PRIVATE_TRANSFER_DATA *private_data)
|
||||
{
|
||||
int len = 0;
|
||||
unsigned offset = 0;
|
||||
|
||||
if (!apdu)
|
||||
return -1;
|
||||
/* optional checking - most likely was already done prior to this call */
|
||||
if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST)
|
||||
return -1;
|
||||
/* apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); */
|
||||
/* invoke id - filled in by net layer */
|
||||
*invoke_id = apdu[2];
|
||||
if (apdu[3] != SERVICE_CONFIRMED_PRIVATE_TRANSFER)
|
||||
return -1;
|
||||
offset = 4;
|
||||
|
||||
if (apdu_len > offset) {
|
||||
len = ptransfer_decode_service_request(
|
||||
&apdu[offset], apdu_len - offset, private_data);
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int uptransfer_decode_apdu(uint8_t *apdu,
|
||||
unsigned apdu_len,
|
||||
BACNET_PRIVATE_TRANSFER_DATA *private_data)
|
||||
{
|
||||
int len = 0;
|
||||
unsigned offset = 0;
|
||||
|
||||
if (!apdu) {
|
||||
return -1;
|
||||
}
|
||||
/* optional checking - most likely was already done prior to this call */
|
||||
if (apdu[0] != PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST) {
|
||||
return -1;
|
||||
}
|
||||
if (apdu[1] != SERVICE_UNCONFIRMED_PRIVATE_TRANSFER) {
|
||||
return -1;
|
||||
}
|
||||
offset = 2;
|
||||
if (apdu_len > offset) {
|
||||
len = ptransfer_decode_service_request(
|
||||
&apdu[offset], apdu_len - offset, private_data);
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int ptransfer_ack_decode_apdu(uint8_t *apdu,
|
||||
int apdu_len, /* total length of the apdu */
|
||||
uint8_t *invoke_id,
|
||||
BACNET_PRIVATE_TRANSFER_DATA *private_data)
|
||||
{
|
||||
int len = 0;
|
||||
int offset = 0;
|
||||
|
||||
if (!apdu)
|
||||
return -1;
|
||||
/* optional checking - most likely was already done prior to this call */
|
||||
if (apdu[0] != PDU_TYPE_COMPLEX_ACK)
|
||||
return -1;
|
||||
*invoke_id = apdu[1];
|
||||
if (apdu[2] != SERVICE_CONFIRMED_PRIVATE_TRANSFER)
|
||||
return -1;
|
||||
offset = 3;
|
||||
if (apdu_len > offset) {
|
||||
len = ptransfer_decode_service_request(
|
||||
&apdu[offset], apdu_len - offset, private_data);
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int ptransfer_error_decode_apdu(uint8_t *apdu,
|
||||
int apdu_len, /* total length of the apdu */
|
||||
uint8_t *invoke_id,
|
||||
BACNET_ERROR_CLASS *error_class,
|
||||
BACNET_ERROR_CODE *error_code,
|
||||
BACNET_PRIVATE_TRANSFER_DATA *private_data)
|
||||
{
|
||||
int len = 0;
|
||||
int offset = 0;
|
||||
|
||||
if (!apdu)
|
||||
return -1;
|
||||
/* optional checking - most likely was already done prior to this call */
|
||||
if (apdu[0] != PDU_TYPE_ERROR)
|
||||
return -1;
|
||||
*invoke_id = apdu[1];
|
||||
if (apdu[2] != SERVICE_CONFIRMED_PRIVATE_TRANSFER)
|
||||
return -1;
|
||||
offset = 3;
|
||||
if (apdu_len > offset) {
|
||||
len = ptransfer_error_decode_service_request(&apdu[offset],
|
||||
apdu_len - offset, error_class, error_code, private_data);
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
void test_Private_Transfer_Ack(Test *pTest)
|
||||
{
|
||||
uint8_t apdu[480] = { 0 };
|
||||
int len = 0;
|
||||
int apdu_len = 0;
|
||||
uint8_t invoke_id = 128;
|
||||
uint8_t test_invoke_id = 0;
|
||||
BACNET_PRIVATE_TRANSFER_DATA private_data;
|
||||
BACNET_PRIVATE_TRANSFER_DATA test_data;
|
||||
uint8_t test_value[480] = { 0 };
|
||||
int private_data_len = 0;
|
||||
char private_data_chunk[33] = { "00112233445566778899AABBCCDDEEFF" };
|
||||
BACNET_APPLICATION_DATA_VALUE data_value;
|
||||
BACNET_APPLICATION_DATA_VALUE test_data_value;
|
||||
bool status = false;
|
||||
|
||||
private_data.vendorID = BACNET_VENDOR_ID;
|
||||
private_data.serviceNumber = 1;
|
||||
|
||||
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING,
|
||||
&private_data_chunk[0], &data_value);
|
||||
ct_test(pTest, status == true);
|
||||
private_data_len =
|
||||
bacapp_encode_application_data(&test_value[0], &data_value);
|
||||
|
||||
private_data.serviceParameters = &test_value[0];
|
||||
private_data.serviceParametersLen = private_data_len;
|
||||
|
||||
len = ptransfer_ack_encode_apdu(&apdu[0], invoke_id, &private_data);
|
||||
ct_test(pTest, len != 0);
|
||||
ct_test(pTest, len != -1);
|
||||
apdu_len = len;
|
||||
len = ptransfer_ack_decode_apdu(
|
||||
&apdu[0], apdu_len, &test_invoke_id, &test_data);
|
||||
ct_test(pTest, len != -1);
|
||||
ct_test(pTest, test_invoke_id == invoke_id);
|
||||
ct_test(pTest, test_data.vendorID == private_data.vendorID);
|
||||
ct_test(pTest, test_data.serviceNumber == private_data.serviceNumber);
|
||||
ct_test(pTest,
|
||||
test_data.serviceParametersLen == private_data.serviceParametersLen);
|
||||
len = bacapp_decode_application_data(test_data.serviceParameters,
|
||||
test_data.serviceParametersLen, &test_data_value);
|
||||
ct_test(pTest, bacapp_same_value(&data_value, &test_data_value) == true);
|
||||
}
|
||||
|
||||
void test_Private_Transfer_Error(Test *pTest)
|
||||
{
|
||||
uint8_t apdu[480] = { 0 };
|
||||
int len = 0;
|
||||
int apdu_len = 0;
|
||||
uint8_t invoke_id = 128;
|
||||
uint8_t test_invoke_id = 0;
|
||||
BACNET_ERROR_CLASS error_class = ERROR_CLASS_RESOURCES;
|
||||
BACNET_ERROR_CODE error_code = ERROR_CODE_OPERATIONAL_PROBLEM;
|
||||
BACNET_ERROR_CLASS test_error_class = 0;
|
||||
BACNET_ERROR_CODE test_error_code = 0;
|
||||
BACNET_PRIVATE_TRANSFER_DATA private_data;
|
||||
BACNET_PRIVATE_TRANSFER_DATA test_data;
|
||||
uint8_t test_value[480] = { 0 };
|
||||
int private_data_len = 0;
|
||||
char private_data_chunk[33] = { "00112233445566778899AABBCCDDEEFF" };
|
||||
BACNET_APPLICATION_DATA_VALUE data_value;
|
||||
BACNET_APPLICATION_DATA_VALUE test_data_value;
|
||||
bool status = false;
|
||||
|
||||
private_data.vendorID = BACNET_VENDOR_ID;
|
||||
private_data.serviceNumber = 1;
|
||||
|
||||
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING,
|
||||
&private_data_chunk[0], &data_value);
|
||||
ct_test(pTest, status == true);
|
||||
private_data_len =
|
||||
bacapp_encode_application_data(&test_value[0], &data_value);
|
||||
private_data.serviceParameters = &test_value[0];
|
||||
private_data.serviceParametersLen = private_data_len;
|
||||
|
||||
len = ptransfer_error_encode_apdu(
|
||||
&apdu[0], invoke_id, error_class, error_code, &private_data);
|
||||
ct_test(pTest, len != 0);
|
||||
ct_test(pTest, len != -1);
|
||||
apdu_len = len;
|
||||
len = ptransfer_error_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
|
||||
&test_error_class, &test_error_code, &test_data);
|
||||
ct_test(pTest, len != -1);
|
||||
ct_test(pTest, test_invoke_id == invoke_id);
|
||||
ct_test(pTest, test_data.vendorID == private_data.vendorID);
|
||||
ct_test(pTest, test_data.serviceNumber == private_data.serviceNumber);
|
||||
ct_test(pTest, test_error_class == error_class);
|
||||
ct_test(pTest, test_error_code == error_code);
|
||||
ct_test(pTest,
|
||||
test_data.serviceParametersLen == private_data.serviceParametersLen);
|
||||
len = bacapp_decode_application_data(test_data.serviceParameters,
|
||||
test_data.serviceParametersLen, &test_data_value);
|
||||
ct_test(pTest, bacapp_same_value(&data_value, &test_data_value) == true);
|
||||
}
|
||||
|
||||
void test_Private_Transfer_Request(Test *pTest)
|
||||
{
|
||||
uint8_t apdu[480] = { 0 };
|
||||
uint8_t test_value[480] = { 0 };
|
||||
int len = 0;
|
||||
int apdu_len = 0;
|
||||
uint8_t invoke_id = 128;
|
||||
uint8_t test_invoke_id = 0;
|
||||
int private_data_len = 0;
|
||||
char private_data_chunk[33] = { "00112233445566778899AABBCCDDEEFF" };
|
||||
BACNET_APPLICATION_DATA_VALUE data_value = { 0 };
|
||||
BACNET_APPLICATION_DATA_VALUE test_data_value = { 0 };
|
||||
BACNET_PRIVATE_TRANSFER_DATA private_data = { 0 };
|
||||
BACNET_PRIVATE_TRANSFER_DATA test_data = { 0 };
|
||||
bool status = false;
|
||||
|
||||
private_data.vendorID = BACNET_VENDOR_ID;
|
||||
private_data.serviceNumber = 1;
|
||||
|
||||
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING,
|
||||
&private_data_chunk[0], &data_value);
|
||||
ct_test(pTest, status == true);
|
||||
private_data_len =
|
||||
bacapp_encode_application_data(&test_value[0], &data_value);
|
||||
private_data.serviceParameters = &test_value[0];
|
||||
private_data.serviceParametersLen = private_data_len;
|
||||
|
||||
len = ptransfer_encode_apdu(&apdu[0], invoke_id, &private_data);
|
||||
ct_test(pTest, len != 0);
|
||||
apdu_len = len;
|
||||
len =
|
||||
ptransfer_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &test_data);
|
||||
ct_test(pTest, len != -1);
|
||||
ct_test(pTest, test_data.vendorID == private_data.vendorID);
|
||||
ct_test(pTest, test_data.serviceNumber == private_data.serviceNumber);
|
||||
ct_test(pTest,
|
||||
test_data.serviceParametersLen == private_data.serviceParametersLen);
|
||||
len = bacapp_decode_application_data(test_data.serviceParameters,
|
||||
test_data.serviceParametersLen, &test_data_value);
|
||||
ct_test(pTest, bacapp_same_value(&data_value, &test_data_value) == true);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void test_Unconfirmed_Private_Transfer_Request(Test *pTest)
|
||||
{
|
||||
uint8_t apdu[480] = { 0 };
|
||||
uint8_t test_value[480] = { 0 };
|
||||
int len = 0;
|
||||
int apdu_len = 0;
|
||||
int private_data_len = 0;
|
||||
char private_data_chunk[32] = { "I Love You, Patricia!" };
|
||||
BACNET_APPLICATION_DATA_VALUE data_value;
|
||||
BACNET_APPLICATION_DATA_VALUE test_data_value;
|
||||
BACNET_PRIVATE_TRANSFER_DATA private_data;
|
||||
BACNET_PRIVATE_TRANSFER_DATA test_data;
|
||||
bool status = false;
|
||||
|
||||
private_data.vendorID = BACNET_VENDOR_ID;
|
||||
private_data.serviceNumber = 1;
|
||||
|
||||
status =
|
||||
bacapp_parse_application_data(BACNET_APPLICATION_TAG_CHARACTER_STRING,
|
||||
&private_data_chunk[0], &data_value);
|
||||
ct_test(pTest, status == true);
|
||||
private_data_len =
|
||||
bacapp_encode_application_data(&test_value[0], &data_value);
|
||||
private_data.serviceParameters = &test_value[0];
|
||||
private_data.serviceParametersLen = private_data_len;
|
||||
|
||||
len = uptransfer_encode_apdu(&apdu[0], &private_data);
|
||||
ct_test(pTest, len != 0);
|
||||
apdu_len = len;
|
||||
len = uptransfer_decode_apdu(&apdu[0], apdu_len, &test_data);
|
||||
ct_test(pTest, len != -1);
|
||||
ct_test(pTest, test_data.vendorID == private_data.vendorID);
|
||||
ct_test(pTest, test_data.serviceNumber == private_data.serviceNumber);
|
||||
ct_test(pTest,
|
||||
test_data.serviceParametersLen == private_data.serviceParametersLen);
|
||||
len = bacapp_decode_application_data(test_data.serviceParameters,
|
||||
test_data.serviceParametersLen, &test_data_value);
|
||||
ct_test(pTest, bacapp_same_value(&data_value, &test_data_value) == true);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef TEST_PRIVATE_TRANSFER
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
|
||||
pTest = ct_create("BACnet PrivateTransfer", NULL);
|
||||
/* individual tests */
|
||||
rc = ct_addTestFunction(pTest, test_Private_Transfer_Request);
|
||||
assert(rc);
|
||||
rc = ct_addTestFunction(pTest, test_Private_Transfer_Ack);
|
||||
assert(rc);
|
||||
rc = ct_addTestFunction(pTest, test_Private_Transfer_Error);
|
||||
assert(rc);
|
||||
rc = ct_addTestFunction(pTest, test_Unconfirmed_Private_Transfer_Request);
|
||||
assert(rc);
|
||||
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void)ct_report(pTest);
|
||||
ct_destroy(pTest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_READ_PROPERTY */
|
||||
#endif /* BAC_TEST */
|
||||
|
||||
Reference in New Issue
Block a user