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:
Steve Karg
2022-02-28 20:09:46 -06:00
committed by GitHub
parent 585cdb4a7d
commit c3a4c229fe
182 changed files with 231 additions and 16779 deletions
-130
View File
@@ -400,133 +400,3 @@ int bacapp_decode_context_device_obj_ref(
}
return len;
}
#ifdef BAC_TEST
#include <assert.h>
#include <string.h>
#include "ctest.h"
static void testDevObjPropRef(
Test *pTest, BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE *inData)
{
BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE outData;
uint8_t buffer[MAX_APDU] = { 0 };
int inLen = 0;
int outLen = 0;
/* encode */
inLen = bacapp_encode_device_obj_property_ref(buffer, inData);
/* add a closing tag at the end of the buffer to verify proper handling
when that is encountered in real packets */
encode_closing_tag(&buffer[inLen], 3);
/* decode */
outLen = bacapp_decode_device_obj_property_ref(buffer, &outData);
ct_test(pTest, outLen == inLen);
ct_test(pTest,
inData->objectIdentifier.instance == outData.objectIdentifier.instance);
ct_test(
pTest, inData->objectIdentifier.type == outData.objectIdentifier.type);
ct_test(pTest, inData->propertyIdentifier == outData.propertyIdentifier);
if (inData->arrayIndex != BACNET_ARRAY_ALL) {
ct_test(pTest, inData->arrayIndex == outData.arrayIndex);
} else {
ct_test(pTest, outData.arrayIndex == BACNET_ARRAY_ALL);
}
if (inData->deviceIdentifier.type == OBJECT_DEVICE) {
ct_test(pTest,
inData->deviceIdentifier.instance ==
outData.deviceIdentifier.instance);
ct_test(pTest,
inData->deviceIdentifier.type == outData.deviceIdentifier.type);
} else {
ct_test(pTest, outData.deviceIdentifier.instance == BACNET_NO_DEV_ID);
ct_test(pTest, outData.deviceIdentifier.type == BACNET_NO_DEV_TYPE);
}
}
static void testDevIdPropRef(Test *pTest)
{
BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE inData;
/* everything encoded */
inData.objectIdentifier.instance = 0x1234;
inData.objectIdentifier.type = 15;
inData.propertyIdentifier = 25;
inData.arrayIndex = 0x5678;
inData.deviceIdentifier.instance = 0x4343;
inData.deviceIdentifier.type = OBJECT_DEVICE;
testDevObjPropRef(pTest, &inData);
/* optional array */
inData.objectIdentifier.instance = 0x1234;
inData.objectIdentifier.type = 15;
inData.propertyIdentifier = 25;
inData.arrayIndex = BACNET_ARRAY_ALL;
inData.deviceIdentifier.instance = 0x4343;
inData.deviceIdentifier.type = OBJECT_DEVICE;
testDevObjPropRef(pTest, &inData);
/* optional device ID */
inData.objectIdentifier.instance = 0x1234;
inData.objectIdentifier.type = 15;
inData.propertyIdentifier = 25;
inData.arrayIndex = 1;
inData.deviceIdentifier.instance = 0;
inData.deviceIdentifier.type = BACNET_NO_DEV_TYPE;
testDevObjPropRef(pTest, &inData);
/* optional array + optional device ID */
inData.objectIdentifier.instance = 0x1234;
inData.objectIdentifier.type = 15;
inData.propertyIdentifier = 25;
inData.arrayIndex = BACNET_ARRAY_ALL;
inData.deviceIdentifier.instance = 0;
inData.deviceIdentifier.type = BACNET_NO_DEV_TYPE;
testDevObjPropRef(pTest, &inData);
}
static void testDevIdRef(Test *pTest)
{
BACNET_DEVICE_OBJECT_REFERENCE inData;
BACNET_DEVICE_OBJECT_REFERENCE outData;
uint8_t buffer[MAX_APDU];
int inLen;
int outLen;
inData.deviceIdentifier.instance = 0x4343;
inData.deviceIdentifier.type = OBJECT_DEVICE;
inLen = bacapp_encode_device_obj_ref(buffer, &inData);
outLen = bacapp_decode_device_obj_ref(buffer, &outData);
ct_test(pTest, outLen == inLen);
ct_test(pTest,
inData.deviceIdentifier.instance == outData.deviceIdentifier.instance);
ct_test(
pTest, inData.deviceIdentifier.type == outData.deviceIdentifier.type);
}
void testBACnetDeviceObjectPropertyReference(Test *pTest)
{
bool rc;
/* individual tests */
rc = ct_addTestFunction(pTest, testDevIdPropRef);
assert(rc);
rc = ct_addTestFunction(pTest, testDevIdRef);
assert(rc);
}
#ifdef TEST_DEV_ID_PROP_REF
#include <assert.h>
int main(void)
{
Test *pTest;
pTest = ct_create("BACnet Prop Ref", NULL);
testBACnetDeviceObjectPropertyReference(pTest);
ct_setStream(pTest, stdout);
ct_run(pTest);
(void)ct_report(pTest);
ct_destroy(pTest);
return 0;
}
#endif /* TEST_DEV_ID_PROP_REF */
#endif /* BAC_TEST */