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:
@@ -156,112 +156,3 @@ int whohas_decode_service_request(
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
int whohas_decode_apdu(
|
||||
uint8_t *apdu, unsigned apdu_len, BACNET_WHO_HAS_DATA *data)
|
||||
{
|
||||
int len = 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_WHO_HAS)
|
||||
return -1;
|
||||
/* optional limits - must be used as a pair */
|
||||
if (apdu_len > 2) {
|
||||
len = whohas_decode_service_request(&apdu[2], apdu_len - 2, data);
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
void testWhoHasData(Test *pTest, BACNET_WHO_HAS_DATA *data)
|
||||
{
|
||||
uint8_t apdu[480] = { 0 };
|
||||
int len = 0;
|
||||
int apdu_len = 0;
|
||||
BACNET_WHO_HAS_DATA test_data;
|
||||
|
||||
len = whohas_encode_apdu(&apdu[0], data);
|
||||
ct_test(pTest, len != 0);
|
||||
apdu_len = len;
|
||||
|
||||
len = whohas_decode_apdu(&apdu[0], apdu_len, &test_data);
|
||||
ct_test(pTest, len != -1);
|
||||
ct_test(pTest, test_data.low_limit == data->low_limit);
|
||||
ct_test(pTest, test_data.high_limit == data->high_limit);
|
||||
ct_test(pTest, test_data.is_object_name == data->is_object_name);
|
||||
/* Object ID */
|
||||
if (data->is_object_name == false) {
|
||||
ct_test(pTest,
|
||||
test_data.object.identifier.type == data->object.identifier.type);
|
||||
ct_test(pTest,
|
||||
test_data.object.identifier.instance ==
|
||||
data->object.identifier.instance);
|
||||
}
|
||||
/* Object Name */
|
||||
else {
|
||||
ct_test(pTest,
|
||||
characterstring_same(&test_data.object.name, &data->object.name));
|
||||
}
|
||||
}
|
||||
|
||||
void testWhoHas(Test *pTest)
|
||||
{
|
||||
BACNET_WHO_HAS_DATA data;
|
||||
|
||||
data.low_limit = -1;
|
||||
data.high_limit = -1;
|
||||
data.is_object_name = false;
|
||||
data.object.identifier.type = OBJECT_ANALOG_INPUT;
|
||||
data.object.identifier.instance = 1;
|
||||
testWhoHasData(pTest, &data);
|
||||
|
||||
for (data.low_limit = 0; data.low_limit <= BACNET_MAX_INSTANCE;
|
||||
data.low_limit += (BACNET_MAX_INSTANCE / 4)) {
|
||||
for (data.high_limit = 0; data.high_limit <= BACNET_MAX_INSTANCE;
|
||||
data.high_limit += (BACNET_MAX_INSTANCE / 4)) {
|
||||
data.is_object_name = false;
|
||||
for (data.object.identifier.type = OBJECT_ANALOG_INPUT;
|
||||
data.object.identifier.type < MAX_BACNET_OBJECT_TYPE;
|
||||
data.object.identifier.type++) {
|
||||
for (data.object.identifier.instance = 1;
|
||||
data.object.identifier.instance <= BACNET_MAX_INSTANCE;
|
||||
data.object.identifier.instance <<= 1) {
|
||||
testWhoHasData(pTest, &data);
|
||||
}
|
||||
}
|
||||
data.is_object_name = true;
|
||||
characterstring_init_ansi(&data.object.name, "patricia");
|
||||
testWhoHasData(pTest, &data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TEST_WHOHAS
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
|
||||
pTest = ct_create("BACnet Who-Has", NULL);
|
||||
/* individual tests */
|
||||
rc = ct_addTestFunction(pTest, testWhoHas);
|
||||
assert(rc);
|
||||
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void)ct_report(pTest);
|
||||
ct_destroy(pTest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_WHOIS */
|
||||
#endif /* BAC_TEST */
|
||||
|
||||
Reference in New Issue
Block a user