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:
@@ -289,63 +289,3 @@ void VMAC_Init(void)
|
||||
PRINTF("VMAC List initialized.\n");
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
void testVMAC(Test *pTest)
|
||||
{
|
||||
uint32_t device_id = 123;
|
||||
uint32_t test_device_id = 0;
|
||||
struct vmac_data test_vmac_data;
|
||||
struct vmac_data *pVMAC;
|
||||
unsigned int i = 0;
|
||||
bool status = false;
|
||||
|
||||
VMAC_Init();
|
||||
for (i = 0; i < VMAC_MAC_MAX; i++) {
|
||||
test_vmac_data.mac[i] = 1 + i;
|
||||
}
|
||||
test_vmac_data.mac_len = VMAC_MAC_MAX;
|
||||
status = VMAC_Add(device_id, &test_vmac_data);
|
||||
ct_test(pTest, status);
|
||||
pVMAC = VMAC_Find_By_Key(0);
|
||||
ct_test(pTest, pVMAC == NULL);
|
||||
pVMAC = VMAC_Find_By_Key(device_id);
|
||||
ct_test(pTest, pVMAC);
|
||||
status = VMAC_Different(pVMAC, &test_vmac_data);
|
||||
ct_test(pTest, !status);
|
||||
status = VMAC_Match(pVMAC, &test_vmac_data);
|
||||
ct_test(pTest, status);
|
||||
status = VMAC_Find_By_Data(&test_vmac_data, &test_device_id);
|
||||
ct_test(pTest, status);
|
||||
ct_test(pTest, test_device_id == device_id);
|
||||
status = VMAC_Delete(device_id);
|
||||
ct_test(pTest, status);
|
||||
pVMAC = VMAC_Find_By_Key(device_id);
|
||||
ct_test(pTest, pVMAC == NULL);
|
||||
VMAC_Cleanup();
|
||||
}
|
||||
|
||||
#ifdef TEST_VMAC
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
|
||||
pTest = ct_create("BACnet VMAC", NULL);
|
||||
/* individual tests */
|
||||
rc = ct_addTestFunction(pTest, testVMAC);
|
||||
assert(rc);
|
||||
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void)ct_report(pTest);
|
||||
ct_destroy(pTest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -52,13 +52,6 @@ extern "C" {
|
||||
BACNET_STACK_EXPORT
|
||||
void VMAC_Debug_Enable(void);
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include "ctest.h"
|
||||
BACNET_STACK_EXPORT
|
||||
void testVMAC(
|
||||
Test * pTest);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -229,7 +229,7 @@ static struct Address_Cache_Entry *address_remove_oldest(void)
|
||||
if ((pMatch->Flags &
|
||||
(BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ | BAC_ADDR_STATIC)) ==
|
||||
BAC_ADDR_IN_USE) {
|
||||
if (pMatch->TimeToLive <= ulTime) {
|
||||
if (pMatch->TimeToLive <= ulTime) {
|
||||
/* Shorter lived entry found */
|
||||
ulTime = pMatch->TimeToLive;
|
||||
pCandidate = pMatch;
|
||||
@@ -237,11 +237,11 @@ static struct Address_Cache_Entry *address_remove_oldest(void)
|
||||
}
|
||||
}
|
||||
|
||||
if (pCandidate != NULL) {
|
||||
if (pCandidate != NULL) {
|
||||
/* Found something to free up */
|
||||
pCandidate->Flags = BAC_ADDR_RESERVED;
|
||||
/* only reserve it for a short while */
|
||||
pCandidate->TimeToLive = BAC_ADDR_SHORT_TIME;
|
||||
pCandidate->TimeToLive = BAC_ADDR_SHORT_TIME;
|
||||
return (pCandidate);
|
||||
}
|
||||
|
||||
@@ -258,7 +258,7 @@ static struct Address_Cache_Entry *address_remove_oldest(void)
|
||||
}
|
||||
}
|
||||
|
||||
if (pCandidate != NULL) {
|
||||
if (pCandidate != NULL) {
|
||||
/* Found something to free up */
|
||||
pCandidate->Flags = BAC_ADDR_RESERVED;
|
||||
/* only reserve it for a short while */
|
||||
@@ -442,7 +442,7 @@ void address_init_partial(void)
|
||||
|
||||
for (index = 0; index < MAX_ADDRESS_CACHE; index++) {
|
||||
pMatch = &Address_Cache[index];
|
||||
if ((pMatch->Flags & BAC_ADDR_IN_USE) != 0) {
|
||||
if ((pMatch->Flags & BAC_ADDR_IN_USE) != 0) {
|
||||
/* It's in use so let's check further */
|
||||
if (((pMatch->Flags & BAC_ADDR_BIND_REQ) != 0) ||
|
||||
(pMatch->TimeToLive == 0)) {
|
||||
@@ -450,7 +450,7 @@ void address_init_partial(void)
|
||||
}
|
||||
}
|
||||
|
||||
if ((pMatch->Flags & BAC_ADDR_RESERVED) != 0) {
|
||||
if ((pMatch->Flags & BAC_ADDR_RESERVED) != 0) {
|
||||
/* Reserved entries should be cleared */
|
||||
pMatch->Flags = 0;
|
||||
}
|
||||
@@ -482,7 +482,7 @@ void address_set_device_TTL(
|
||||
pMatch = &Address_Cache[index];
|
||||
if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) &&
|
||||
(pMatch->device_id == device_id)) {
|
||||
if ((pMatch->Flags & BAC_ADDR_BIND_REQ) == 0) {
|
||||
if ((pMatch->Flags & BAC_ADDR_BIND_REQ) == 0) {
|
||||
/* If bound then we have either static or normaal */
|
||||
if (StaticFlag) {
|
||||
pMatch->Flags |= BAC_ADDR_STATIC;
|
||||
@@ -493,7 +493,7 @@ void address_set_device_TTL(
|
||||
}
|
||||
} else {
|
||||
/* For unbound we can only set the time to live */
|
||||
pMatch->TimeToLive = TimeOut;
|
||||
pMatch->TimeToLive = TimeOut;
|
||||
}
|
||||
break; /* Exit now if found at all - bound or unbound */
|
||||
}
|
||||
@@ -518,15 +518,15 @@ bool address_get_by_device(
|
||||
pMatch = &Address_Cache[index];
|
||||
if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) &&
|
||||
(pMatch->device_id == device_id)) {
|
||||
if ((pMatch->Flags & BAC_ADDR_BIND_REQ) == 0) {
|
||||
if ((pMatch->Flags & BAC_ADDR_BIND_REQ) == 0) {
|
||||
/* If bound then fetch data */
|
||||
bacnet_address_copy(src, &pMatch->address);
|
||||
*max_apdu = pMatch->max_apdu;
|
||||
/* Prove we found it */
|
||||
found = true;
|
||||
found = true;
|
||||
}
|
||||
/* Exit now if found at all - bound or unbound */
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -549,8 +549,8 @@ bool address_get_device_id(BACNET_ADDRESS *src, uint32_t *device_id)
|
||||
|
||||
for (index = 0; index < MAX_ADDRESS_CACHE; index++) {
|
||||
pMatch = &Address_Cache[index];
|
||||
if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) ==
|
||||
BAC_ADDR_IN_USE) {
|
||||
if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) ==
|
||||
BAC_ADDR_IN_USE) {
|
||||
/* If bound */
|
||||
if (bacnet_address_same(&pMatch->address, src)) {
|
||||
if (device_id) {
|
||||
@@ -597,21 +597,21 @@ void address_add(uint32_t device_id, unsigned max_apdu, BACNET_ADDRESS *src)
|
||||
bacnet_address_copy(&pMatch->address, src);
|
||||
pMatch->max_apdu = max_apdu;
|
||||
/* Pick the right time to live */
|
||||
if ((pMatch->Flags & BAC_ADDR_BIND_REQ) != 0) {
|
||||
if ((pMatch->Flags & BAC_ADDR_BIND_REQ) != 0) {
|
||||
/* Bind requested so long time */
|
||||
pMatch->TimeToLive = BAC_ADDR_LONG_TIME;
|
||||
} else if ((pMatch->Flags & BAC_ADDR_STATIC) != 0) {
|
||||
} else if ((pMatch->Flags & BAC_ADDR_STATIC) != 0) {
|
||||
/* Static already so make sure it never expires */
|
||||
pMatch->TimeToLive = BAC_ADDR_FOREVER;
|
||||
} else if ((pMatch->Flags & BAC_ADDR_SHORT_TTL) != 0) {
|
||||
} else if ((pMatch->Flags & BAC_ADDR_SHORT_TTL) != 0) {
|
||||
/* Opportunistic entry so leave on short fuse */
|
||||
pMatch->TimeToLive = BAC_ADDR_SHORT_TIME;
|
||||
} else {
|
||||
/* Renewing existing entry */
|
||||
pMatch->TimeToLive = BAC_ADDR_LONG_TIME;
|
||||
pMatch->TimeToLive = BAC_ADDR_LONG_TIME;
|
||||
}
|
||||
/* Clear bind request flag just in case */
|
||||
pMatch->Flags &= ~BAC_ADDR_BIND_REQ;
|
||||
pMatch->Flags &= ~BAC_ADDR_BIND_REQ;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
@@ -626,7 +626,7 @@ void address_add(uint32_t device_id, unsigned max_apdu, BACNET_ADDRESS *src)
|
||||
pMatch->max_apdu = max_apdu;
|
||||
bacnet_address_copy(&pMatch->address, src);
|
||||
/* Opportunistic entry so leave on short fuse */
|
||||
pMatch->TimeToLive = BAC_ADDR_SHORT_TIME;
|
||||
pMatch->TimeToLive = BAC_ADDR_SHORT_TIME;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
@@ -642,7 +642,7 @@ void address_add(uint32_t device_id, unsigned max_apdu, BACNET_ADDRESS *src)
|
||||
pMatch->max_apdu = max_apdu;
|
||||
bacnet_address_copy(&pMatch->address, src);
|
||||
/* Opportunistic entry so leave on short fuse */
|
||||
pMatch->TimeToLive = BAC_ADDR_SHORT_TIME;
|
||||
pMatch->TimeToLive = BAC_ADDR_SHORT_TIME;
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -675,7 +675,7 @@ bool address_device_bind_request(uint32_t device_id,
|
||||
pMatch = &Address_Cache[index];
|
||||
if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) &&
|
||||
(pMatch->device_id == device_id)) {
|
||||
if ((pMatch->Flags & BAC_ADDR_BIND_REQ) == 0) {
|
||||
if ((pMatch->Flags & BAC_ADDR_BIND_REQ) == 0) {
|
||||
/* Already bound */
|
||||
found = true;
|
||||
if (src) {
|
||||
@@ -687,7 +687,7 @@ bool address_device_bind_request(uint32_t device_id,
|
||||
if (device_ttl) {
|
||||
*device_ttl = pMatch->TimeToLive;
|
||||
}
|
||||
if ((pMatch->Flags & BAC_ADDR_SHORT_TTL) != 0) {
|
||||
if ((pMatch->Flags & BAC_ADDR_SHORT_TTL) != 0) {
|
||||
/* Was picked up opportunistacilly */
|
||||
/* Convert to normal entry */
|
||||
pMatch->Flags &= ~BAC_ADDR_SHORT_TTL;
|
||||
@@ -696,7 +696,7 @@ bool address_device_bind_request(uint32_t device_id,
|
||||
}
|
||||
}
|
||||
/* True if bound, false if bind request outstanding */
|
||||
return (found);
|
||||
return (found);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1025,12 +1025,12 @@ int rr_address_list_encode(uint8_t *apdu, BACNET_READ_RANGE_DATA *pRequest)
|
||||
|
||||
/* From here on in we only have a starting point and a positive count */
|
||||
|
||||
if (pRequest->Range.RefIndex > uiTotal) {
|
||||
if (pRequest->Range.RefIndex > uiTotal) {
|
||||
/* Nothing to return as we are past the end of the list */
|
||||
return (0);
|
||||
}
|
||||
/* Index of last required entry */
|
||||
uiTarget = pRequest->Range.RefIndex + pRequest->Count - 1;
|
||||
uiTarget = pRequest->Range.RefIndex + pRequest->Count - 1;
|
||||
if (uiTarget > uiTotal) { /* Capped at end of list if necessary */
|
||||
uiTarget = uiTotal;
|
||||
}
|
||||
@@ -1043,14 +1043,14 @@ int rr_address_list_encode(uint8_t *apdu, BACNET_READ_RANGE_DATA *pRequest)
|
||||
/* Shall not happen as the count has been checked first. */
|
||||
if (pMatch > &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
/* Issue with the table. */
|
||||
return (0);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
/* Seek to start position */
|
||||
while (uiIndex != pRequest->Range.RefIndex) {
|
||||
if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) ==
|
||||
BAC_ADDR_IN_USE) {
|
||||
BAC_ADDR_IN_USE) {
|
||||
/* Only count bound entries */
|
||||
pMatch++;
|
||||
uiIndex++;
|
||||
@@ -1060,7 +1060,7 @@ int rr_address_list_encode(uint8_t *apdu, BACNET_READ_RANGE_DATA *pRequest)
|
||||
/* Shall not happen as the count has been checked first. */
|
||||
if (pMatch > &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
/* Issue with the table. */
|
||||
return (0);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1093,25 +1093,25 @@ int rr_address_list_encode(uint8_t *apdu, BACNET_READ_RANGE_DATA *pRequest)
|
||||
&apdu[iLen + iTemp], &MAC_Address);
|
||||
}
|
||||
/* Reduce the remaining space */
|
||||
uiRemaining -= iTemp;
|
||||
uiRemaining -= iTemp;
|
||||
/* and increase the length consumed */
|
||||
iLen += iTemp;
|
||||
iLen += iTemp;
|
||||
/* Record the last entry encoded */
|
||||
uiLast = uiIndex;
|
||||
uiLast = uiIndex;
|
||||
/* and get ready for next one */
|
||||
uiIndex++;
|
||||
uiIndex++;
|
||||
pMatch++;
|
||||
/* Chalk up another one for the response count */
|
||||
pRequest->ItemCount++;
|
||||
pRequest->ItemCount++;
|
||||
|
||||
while ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) !=
|
||||
BAC_ADDR_IN_USE) {
|
||||
BAC_ADDR_IN_USE) {
|
||||
/* Find next bound entry */
|
||||
pMatch++;
|
||||
/* Can normally not happen. */
|
||||
if (pMatch > &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
/* Issue with the table. */
|
||||
return (0);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1140,7 +1140,7 @@ void address_cache_timer(uint16_t uSeconds)
|
||||
{
|
||||
struct Address_Cache_Entry *pMatch;
|
||||
unsigned index;
|
||||
|
||||
|
||||
for (index = 0; index < MAX_ADDRESS_CACHE; index++) {
|
||||
pMatch = &Address_Cache[index];
|
||||
if (((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_RESERVED)) != 0) &&
|
||||
@@ -1155,178 +1155,3 @@ void address_cache_timer(uint16_t uSeconds)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
static void set_address(unsigned index, BACNET_ADDRESS *dest)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < MAX_MAC_LEN; i++) {
|
||||
dest->mac[i] = index;
|
||||
}
|
||||
dest->mac_len = MAX_MAC_LEN;
|
||||
dest->net = 7;
|
||||
dest->len = MAX_MAC_LEN;
|
||||
for (i = 0; i < MAX_MAC_LEN; i++) {
|
||||
dest->adr[i] = index;
|
||||
}
|
||||
}
|
||||
|
||||
static void set_file_address(const char *pFilename,
|
||||
uint32_t device_id,
|
||||
BACNET_ADDRESS *dest,
|
||||
uint16_t max_apdu)
|
||||
{
|
||||
unsigned i;
|
||||
FILE *pFile = NULL;
|
||||
|
||||
pFile = fopen(pFilename, "w");
|
||||
|
||||
if (pFile) {
|
||||
fprintf(pFile, "%lu ", (long unsigned int)device_id);
|
||||
for (i = 0; i < dest->mac_len; i++) {
|
||||
fprintf(pFile, "%02x", dest->mac[i]);
|
||||
if ((i + 1) < dest->mac_len) {
|
||||
fprintf(pFile, ":");
|
||||
}
|
||||
}
|
||||
fprintf(pFile, " %hu ", dest->net);
|
||||
if (dest->net) {
|
||||
for (i = 0; i < dest->len; i++) {
|
||||
fprintf(pFile, "%02x", dest->adr[i]);
|
||||
if ((i + 1) < dest->len) {
|
||||
fprintf(pFile, ":");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fprintf(pFile, "0");
|
||||
}
|
||||
fprintf(pFile, " %hu\n", max_apdu);
|
||||
fclose(pFile);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef BACNET_ADDRESS_CACHE_FILE
|
||||
void testAddressFile(Test *pTest)
|
||||
{
|
||||
BACNET_ADDRESS src = { 0 };
|
||||
uint32_t device_id = 0;
|
||||
unsigned max_apdu = 480;
|
||||
BACNET_ADDRESS test_address = { 0 };
|
||||
unsigned test_max_apdu = 0;
|
||||
|
||||
/* create a fake address */
|
||||
device_id = 55555;
|
||||
src.mac_len = 1;
|
||||
src.mac[0] = 25;
|
||||
src.net = 0;
|
||||
src.adr[0] = 0;
|
||||
max_apdu = 50;
|
||||
set_file_address(Address_Cache_Filename, device_id, &src, max_apdu);
|
||||
/* retrieve it from the file, and see if we can find it */
|
||||
address_file_init(Address_Cache_Filename);
|
||||
ct_test(
|
||||
pTest, address_get_by_device(device_id, &test_max_apdu, &test_address));
|
||||
ct_test(pTest, test_max_apdu == max_apdu);
|
||||
ct_test(pTest, bacnet_address_same(&test_address, &src));
|
||||
|
||||
/* create a fake address */
|
||||
device_id = 55555;
|
||||
src.mac_len = 6;
|
||||
src.mac[0] = 0xC0;
|
||||
src.mac[1] = 0xA8;
|
||||
src.mac[2] = 0x00;
|
||||
src.mac[3] = 0x18;
|
||||
src.mac[4] = 0xBA;
|
||||
src.mac[5] = 0xC0;
|
||||
src.net = 26001;
|
||||
src.len = 1;
|
||||
src.adr[0] = 25;
|
||||
max_apdu = 50;
|
||||
set_file_address(Address_Cache_Filename, device_id, &src, max_apdu);
|
||||
/* retrieve it from the file, and see if we can find it */
|
||||
address_file_init(Address_Cache_Filename);
|
||||
ct_test(
|
||||
pTest, address_get_by_device(device_id, &test_max_apdu, &test_address));
|
||||
ct_test(pTest, test_max_apdu == max_apdu);
|
||||
ct_test(pTest, bacnet_address_same(&test_address, &src));
|
||||
}
|
||||
#endif
|
||||
|
||||
void testAddress(Test *pTest)
|
||||
{
|
||||
unsigned i, count;
|
||||
BACNET_ADDRESS src;
|
||||
uint32_t device_id = 0;
|
||||
unsigned max_apdu = 480;
|
||||
BACNET_ADDRESS test_address;
|
||||
uint32_t test_device_id = 0;
|
||||
unsigned test_max_apdu = 0;
|
||||
|
||||
/* create a fake address database */
|
||||
for (i = 0; i < MAX_ADDRESS_CACHE; i++) {
|
||||
set_address(i, &src);
|
||||
device_id = i * 255;
|
||||
address_add(device_id, max_apdu, &src);
|
||||
count = address_count();
|
||||
ct_test(pTest, count == (i + 1));
|
||||
}
|
||||
|
||||
for (i = 0; i < MAX_ADDRESS_CACHE; i++) {
|
||||
device_id = i * 255;
|
||||
set_address(i, &src);
|
||||
/* test the lookup by device id */
|
||||
ct_test(pTest,
|
||||
address_get_by_device(device_id, &test_max_apdu, &test_address));
|
||||
ct_test(pTest, test_max_apdu == max_apdu);
|
||||
ct_test(pTest, bacnet_address_same(&test_address, &src));
|
||||
ct_test(pTest,
|
||||
address_get_by_index(
|
||||
i, &test_device_id, &test_max_apdu, &test_address));
|
||||
ct_test(pTest, test_device_id == device_id);
|
||||
ct_test(pTest, test_max_apdu == max_apdu);
|
||||
ct_test(pTest, bacnet_address_same(&test_address, &src));
|
||||
ct_test(pTest, address_count() == MAX_ADDRESS_CACHE);
|
||||
/* test the lookup by MAC */
|
||||
ct_test(pTest, address_get_device_id(&src, &test_device_id));
|
||||
ct_test(pTest, test_device_id == device_id);
|
||||
}
|
||||
|
||||
for (i = 0; i < MAX_ADDRESS_CACHE; i++) {
|
||||
device_id = i * 255;
|
||||
address_remove_device(device_id);
|
||||
ct_test(pTest,
|
||||
!address_get_by_device(device_id, &test_max_apdu, &test_address));
|
||||
count = address_count();
|
||||
ct_test(pTest, count == (MAX_ADDRESS_CACHE - i - 1));
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TEST_ADDRESS
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
|
||||
pTest = ct_create("BACnet Address", NULL);
|
||||
/* individual tests */
|
||||
rc = ct_addTestFunction(pTest, testAddress);
|
||||
assert(rc);
|
||||
#ifdef BACNET_ADDRESS_CACHE_FILE
|
||||
rc = ct_addTestFunction(pTest, testAddressFile);
|
||||
assert(rc);
|
||||
#endif
|
||||
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void)ct_report(pTest);
|
||||
ct_destroy(pTest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_ADDRESS */
|
||||
#endif /* BAC_TEST */
|
||||
|
||||
@@ -127,13 +127,6 @@ extern "C" {
|
||||
void Access_Credential_Init(
|
||||
void);
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include "ctest.h"
|
||||
BACNET_STACK_EXPORT
|
||||
void testAccessCredential(
|
||||
Test * pTest);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -163,13 +163,6 @@ extern "C" {
|
||||
void Binary_Output_Cleanup(
|
||||
void);
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include "ctest.h"
|
||||
BACNET_STACK_EXPORT
|
||||
void testBinaryOutput(
|
||||
Test * pTest);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -538,57 +538,3 @@ bool Binary_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
void testBinary_Value(Test *pTest)
|
||||
{
|
||||
uint8_t apdu[MAX_APDU] = { 0 };
|
||||
int len = 0;
|
||||
uint32_t len_value = 0;
|
||||
uint8_t tag_number = 0;
|
||||
uint16_t decoded_type = 0;
|
||||
uint32_t decoded_instance = 0;
|
||||
BACNET_READ_PROPERTY_DATA rpdata;
|
||||
|
||||
Binary_Value_Init();
|
||||
rpdata.application_data = &apdu[0];
|
||||
rpdata.application_data_len = sizeof(apdu);
|
||||
rpdata.object_type = OBJECT_BINARY_VALUE;
|
||||
rpdata.object_instance = 1;
|
||||
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
|
||||
rpdata.array_index = BACNET_ARRAY_ALL;
|
||||
len = Binary_Value_Read_Property(&rpdata);
|
||||
ct_test(pTest, len != 0);
|
||||
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
|
||||
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
|
||||
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
|
||||
ct_test(pTest, decoded_type == rpdata.object_type);
|
||||
ct_test(pTest, decoded_instance == rpdata.object_instance);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef TEST_BINARY_VALUE
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
|
||||
pTest = ct_create("BACnet Binary_Value", NULL);
|
||||
/* individual tests */
|
||||
rc = ct_addTestFunction(pTest, testBinary_Value);
|
||||
assert(rc);
|
||||
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void)ct_report(pTest);
|
||||
ct_destroy(pTest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_BINARY_VALUE */
|
||||
#endif /* BAC_TEST */
|
||||
|
||||
@@ -181,13 +181,6 @@ extern "C" {
|
||||
void Binary_Value_Cleanup(
|
||||
void);
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include "ctest.h"
|
||||
BACNET_STACK_EXPORT
|
||||
void testBinary_Value(
|
||||
Test * pTest);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -222,12 +222,6 @@ extern "C" {
|
||||
BACNET_STACK_EXPORT
|
||||
void Channel_Init(void);
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include "ctest.h"
|
||||
BACNET_STACK_EXPORT
|
||||
void testChannelObject(Test * pTest);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -820,88 +820,3 @@ bool Command_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
void Command_Intrinsic_Reporting(uint32_t object_instance)
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
void testCommand(Test *pTest)
|
||||
{
|
||||
uint8_t apdu[MAX_APDU] = { 0 };
|
||||
int len = 0;
|
||||
uint32_t len_value = 0;
|
||||
uint8_t tag_number = 0;
|
||||
uint32_t decoded_instance = 0;
|
||||
uint16_t decoded_type = 0;
|
||||
BACNET_READ_PROPERTY_DATA rpdata;
|
||||
BACNET_ACTION_LIST clist, clist_test;
|
||||
Command_Init();
|
||||
rpdata.application_data = &apdu[0];
|
||||
rpdata.application_data_len = sizeof(apdu);
|
||||
rpdata.object_type = OBJECT_COMMAND;
|
||||
rpdata.object_instance = 1;
|
||||
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
|
||||
rpdata.array_index = BACNET_ARRAY_ALL;
|
||||
len = Command_Read_Property(&rpdata);
|
||||
ct_test(pTest, len != 0);
|
||||
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
|
||||
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
|
||||
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
|
||||
ct_test(pTest, decoded_type == rpdata.object_type);
|
||||
ct_test(pTest, decoded_instance == rpdata.object_instance);
|
||||
memset(&clist, 0, sizeof(BACNET_ACTION_LIST));
|
||||
memset(&clist_test, 0, sizeof(BACNET_ACTION_LIST));
|
||||
clist.Device_Id.type = OBJECT_DEVICE;
|
||||
clist.Device_Id.instance = 3389;
|
||||
clist.Object_Id.type = OBJECT_ANALOG_VALUE;
|
||||
clist.Object_Id.instance = 42;
|
||||
clist.Property_Identifier = PROP_PRESENT_VALUE;
|
||||
clist.Property_Array_Index = BACNET_ARRAY_ALL;
|
||||
clist.Value.tag = BACNET_APPLICATION_TAG_REAL;
|
||||
clist.Value.type.Real = 39.0f;
|
||||
clist.Priority = 4;
|
||||
clist.Post_Delay = 0xFFFFFFFFU;
|
||||
clist.Quit_On_Failure = true;
|
||||
clist.Write_Successful = false;
|
||||
clist.next = NULL;
|
||||
len = cl_encode_apdu(apdu, &clist);
|
||||
ct_test(pTest, len > 0);
|
||||
len = cl_decode_apdu(apdu, len, BACNET_APPLICATION_TAG_REAL, &clist_test);
|
||||
ct_test(pTest, len > 0);
|
||||
ct_test(pTest, clist.Device_Id.type == clist_test.Device_Id.type);
|
||||
ct_test(pTest, clist.Device_Id.instance == clist_test.Device_Id.instance);
|
||||
ct_test(pTest, clist.Object_Id.type == clist_test.Object_Id.type);
|
||||
ct_test(pTest, clist.Object_Id.instance == clist_test.Object_Id.instance);
|
||||
ct_test(pTest, clist.Property_Identifier == clist_test.Property_Identifier);
|
||||
ct_test(
|
||||
pTest, clist.Property_Array_Index == clist_test.Property_Array_Index);
|
||||
ct_test(pTest, clist.Value.tag == clist_test.Value.tag);
|
||||
ct_test(pTest, clist.Value.type.Real == clist_test.Value.type.Real);
|
||||
ct_test(pTest, clist.Priority == clist_test.Priority);
|
||||
ct_test(pTest, clist.Post_Delay == clist_test.Post_Delay);
|
||||
ct_test(pTest, clist.Quit_On_Failure == clist_test.Quit_On_Failure);
|
||||
ct_test(pTest, clist.Write_Successful == clist_test.Write_Successful);
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef TEST_COMMAND
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
|
||||
pTest = ct_create("BACnet Command", NULL);
|
||||
/* individual tests */
|
||||
rc = ct_addTestFunction(pTest, testCommand);
|
||||
assert(rc);
|
||||
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void)ct_report(pTest);
|
||||
ct_destroy(pTest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_COMMAND */
|
||||
#endif /* BAC_TEST */
|
||||
|
||||
@@ -188,13 +188,6 @@ extern "C" {
|
||||
void Command_Init(
|
||||
void);
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include "ctest.h"
|
||||
BACNET_STACK_EXPORT
|
||||
void testCommand(
|
||||
Test * pTest);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -362,57 +362,3 @@ bool Credential_Data_Input_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
void testCredentialDataInput(Test *pTest)
|
||||
{
|
||||
uint8_t apdu[MAX_APDU] = { 0 };
|
||||
int len = 0;
|
||||
uint32_t len_value = 0;
|
||||
uint8_t tag_number = 0;
|
||||
uint32_t decoded_instance = 0;
|
||||
uint16_t decoded_type = 0;
|
||||
BACNET_READ_PROPERTY_DATA rpdata;
|
||||
|
||||
Credential_Data_Input_Init();
|
||||
rpdata.application_data = &apdu[0];
|
||||
rpdata.application_data_len = sizeof(apdu);
|
||||
rpdata.object_type = OBJECT_CREDENTIAL_DATA_INPUT;
|
||||
rpdata.object_instance = 1;
|
||||
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
|
||||
rpdata.array_index = BACNET_ARRAY_ALL;
|
||||
len = Credential_Data_Input_Read_Property(&rpdata);
|
||||
ct_test(pTest, len != 0);
|
||||
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
|
||||
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
|
||||
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
|
||||
ct_test(pTest, decoded_type == rpdata.object_type);
|
||||
ct_test(pTest, decoded_instance == rpdata.object_instance);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef TEST_CREDENTIAL_DATA_INPUT
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
|
||||
pTest = ct_create("BACnet Credential Data Input", NULL);
|
||||
/* individual tests */
|
||||
rc = ct_addTestFunction(pTest, testCredentialDataInput);
|
||||
assert(rc);
|
||||
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void)ct_report(pTest);
|
||||
ct_destroy(pTest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_CREDENTIAL_DATA_INPUT */
|
||||
#endif /* BAC_TEST */
|
||||
|
||||
@@ -121,13 +121,6 @@ extern "C" {
|
||||
void Credential_Data_Input_Init(
|
||||
void);
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include "ctest.h"
|
||||
BACNET_STACK_EXPORT
|
||||
void testCredentialDataInput(
|
||||
Test * pTest);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -625,57 +625,3 @@ bool CharacterString_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
void testCharacterStringValue(Test *pTest)
|
||||
{
|
||||
uint8_t apdu[MAX_APDU] = { 0 };
|
||||
int len = 0;
|
||||
uint32_t len_value = 0;
|
||||
uint8_t tag_number = 0;
|
||||
uint16_t decoded_type = 0;
|
||||
uint32_t decoded_instance = 0;
|
||||
BACNET_READ_PROPERTY_DATA rpdata;
|
||||
|
||||
CharacterString_Value_Init();
|
||||
rpdata.application_data = &apdu[0];
|
||||
rpdata.application_data_len = sizeof(apdu);
|
||||
rpdata.object_type = OBJECT_CHARACTERSTRING_VALUE;
|
||||
rpdata.object_instance = 1;
|
||||
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
|
||||
rpdata.array_index = BACNET_ARRAY_ALL;
|
||||
len = CharacterString_Value_Read_Property(&rpdata);
|
||||
ct_test(pTest, len != 0);
|
||||
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
|
||||
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
|
||||
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
|
||||
ct_test(pTest, decoded_type == rpdata.object_type);
|
||||
ct_test(pTest, decoded_instance == rpdata.object_instance);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef TEST_CHARACTERSTRING_VALUE
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
|
||||
pTest = ct_create("BACnet CharacterString Value", NULL);
|
||||
/* individual tests */
|
||||
rc = ct_addTestFunction(pTest, testCharacterStringValue);
|
||||
assert(rc);
|
||||
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void)ct_report(pTest);
|
||||
ct_destroy(pTest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#endif /* BAC_TEST */
|
||||
|
||||
@@ -109,14 +109,6 @@ extern "C" {
|
||||
void CharacterString_Value_Init(
|
||||
void);
|
||||
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include "ctest.h"
|
||||
BACNET_STACK_EXPORT
|
||||
void testCharacterStringValue(
|
||||
Test * pTest);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -1890,104 +1890,3 @@ void Routing_Device_Init(uint32_t first_object_instance)
|
||||
}
|
||||
|
||||
#endif /* BAC_ROUTING */
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
bool write_property_type_valid(
|
||||
BACNET_WRITE_PROPERTY_DATA * wp_data,
|
||||
BACNET_APPLICATION_DATA_VALUE * value,
|
||||
uint8_t expected_tag)
|
||||
{
|
||||
(void)wp_data;
|
||||
(void)value;
|
||||
(void)expected_tag;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool write_property_string_valid(
|
||||
BACNET_WRITE_PROPERTY_DATA * wp_data,
|
||||
BACNET_APPLICATION_DATA_VALUE * value,
|
||||
int len_max)
|
||||
{
|
||||
(void)wp_data;
|
||||
(void)value;
|
||||
(void)len_max;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool write_property_empty_string_valid(
|
||||
BACNET_WRITE_PROPERTY_DATA * wp_data,
|
||||
BACNET_APPLICATION_DATA_VALUE * value,
|
||||
int len_max)
|
||||
{
|
||||
(void)wp_data;
|
||||
(void)value;
|
||||
(void)len_max;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int handler_cov_encode_subscriptions(uint8_t *apdu, int max_apdu)
|
||||
{
|
||||
apdu = apdu;
|
||||
max_apdu = max_apdu;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void testDevice(Test *pTest)
|
||||
{
|
||||
bool status = false;
|
||||
const char *name = "Patricia";
|
||||
|
||||
status = Device_Set_Object_Instance_Number(0);
|
||||
ct_test(pTest, Device_Object_Instance_Number() == 0);
|
||||
ct_test(pTest, status == true);
|
||||
status = Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE);
|
||||
ct_test(pTest, Device_Object_Instance_Number() == BACNET_MAX_INSTANCE);
|
||||
ct_test(pTest, status == true);
|
||||
status = Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE / 2);
|
||||
ct_test(
|
||||
pTest, Device_Object_Instance_Number() == (BACNET_MAX_INSTANCE / 2));
|
||||
ct_test(pTest, status == true);
|
||||
status = Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE + 1);
|
||||
ct_test(
|
||||
pTest, Device_Object_Instance_Number() != (BACNET_MAX_INSTANCE + 1));
|
||||
ct_test(pTest, status == false);
|
||||
|
||||
Device_Set_System_Status(STATUS_NON_OPERATIONAL, true);
|
||||
ct_test(pTest, Device_System_Status() == STATUS_NON_OPERATIONAL);
|
||||
|
||||
ct_test(pTest, Device_Vendor_Identifier() == BACNET_VENDOR_ID);
|
||||
|
||||
Device_Set_Model_Name(name, strlen(name));
|
||||
ct_test(pTest, strcmp(Device_Model_Name(), name) == 0);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef TEST_DEVICE
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
|
||||
pTest = ct_create("BACnet Device", NULL);
|
||||
/* individual tests */
|
||||
rc = ct_addTestFunction(pTest, testDevice);
|
||||
assert(rc);
|
||||
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void)ct_report(pTest);
|
||||
ct_destroy(pTest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_DEVICE */
|
||||
#endif /* BAC_TEST */
|
||||
|
||||
@@ -131,13 +131,6 @@ extern "C" {
|
||||
void Integer_Value_Init(
|
||||
void);
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include "ctest.h"
|
||||
BACNET_STACK_EXPORT
|
||||
void testInteger_Value(
|
||||
Test * pTest);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -868,7 +868,7 @@ bool Load_Control_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
int len = 0;
|
||||
BACNET_APPLICATION_DATA_VALUE value;
|
||||
/* build here in case of error in time half of datetime */
|
||||
BACNET_DATE start_date;
|
||||
BACNET_DATE start_date;
|
||||
|
||||
PRINTF("Load_Control_Write_Property(wp_data=%p)\n", wp_data);
|
||||
if (wp_data == NULL) {
|
||||
@@ -1036,417 +1036,3 @@ bool Load_Control_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
PRINTF("Load_Control_Write_Property() returning status=%d\n", status);
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
#if 0
|
||||
static void Load_Control_WriteProperty_Request_Shed_Percent(
|
||||
Test * pTest,
|
||||
int instance,
|
||||
unsigned percent)
|
||||
{
|
||||
bool status = false;
|
||||
BACNET_APPLICATION_DATA_VALUE value;
|
||||
BACNET_WRITE_PROPERTY_DATA wp_data;
|
||||
|
||||
wp_data.object_type = OBJECT_LOAD_CONTROL;
|
||||
wp_data.object_instance = instance;
|
||||
wp_data.array_index = BACNET_ARRAY_ALL;
|
||||
wp_data.priority = BACNET_NO_PRIORITY;
|
||||
wp_data.object_property = PROP_REQUESTED_SHED_LEVEL;
|
||||
wp_data.error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data.error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
|
||||
value.context_specific = true;
|
||||
value.context_tag = 0;
|
||||
value.tag = BACNET_APPLICATION_TAG_UNSIGNED_INT;
|
||||
value.type.Unsigned_Int = percent;
|
||||
wp_data.application_data_len =
|
||||
bacapp_encode_data(&wp_data.application_data[0], &value);
|
||||
ct_test(pTest, wp_data.application_data_len > 0);
|
||||
status = Load_Control_Write_Property(&wp_data);
|
||||
ct_test(pTest, status == true);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void Load_Control_WriteProperty_Request_Shed_Level(
|
||||
Test *pTest, int instance, unsigned level)
|
||||
{
|
||||
bool status = false;
|
||||
BACNET_APPLICATION_DATA_VALUE value;
|
||||
BACNET_WRITE_PROPERTY_DATA wp_data;
|
||||
|
||||
wp_data.object_type = OBJECT_LOAD_CONTROL;
|
||||
wp_data.object_instance = instance;
|
||||
wp_data.array_index = BACNET_ARRAY_ALL;
|
||||
wp_data.priority = BACNET_NO_PRIORITY;
|
||||
wp_data.object_property = PROP_REQUESTED_SHED_LEVEL;
|
||||
value.context_specific = true;
|
||||
value.context_tag = 1;
|
||||
value.tag = BACNET_APPLICATION_TAG_UNSIGNED_INT;
|
||||
value.type.Unsigned_Int = level;
|
||||
wp_data.application_data_len =
|
||||
bacapp_encode_data(&wp_data.application_data[0], &value);
|
||||
ct_test(pTest, wp_data.application_data_len > 0);
|
||||
status = Load_Control_Write_Property(&wp_data);
|
||||
ct_test(pTest, status == true);
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void Load_Control_WriteProperty_Request_Shed_Amount(
|
||||
Test * pTest,
|
||||
int instance,
|
||||
float amount)
|
||||
{
|
||||
bool status = false;
|
||||
BACNET_APPLICATION_DATA_VALUE value;
|
||||
BACNET_WRITE_PROPERTY_DATA wp_data;
|
||||
|
||||
wp_data.object_type = OBJECT_LOAD_CONTROL;
|
||||
wp_data.object_instance = instance;
|
||||
wp_data.array_index = BACNET_ARRAY_ALL;
|
||||
wp_data.priority = BACNET_NO_PRIORITY;
|
||||
wp_data.object_property = PROP_REQUESTED_SHED_LEVEL;
|
||||
value.context_specific = true;
|
||||
value.context_tag = 2;
|
||||
value.tag = BACNET_APPLICATION_TAG_REAL;
|
||||
value.type.Real = amount;
|
||||
wp_data.application_data_len =
|
||||
bacapp_encode_data(&wp_data.application_data[0], &value);
|
||||
ct_test(pTest, wp_data.application_data_len > 0);
|
||||
status = Load_Control_Write_Property(&wp_data);
|
||||
ct_test(pTest, status == true);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void Load_Control_WriteProperty_Enable(
|
||||
Test *pTest, int instance, bool enable)
|
||||
{
|
||||
bool status = false;
|
||||
BACNET_APPLICATION_DATA_VALUE value;
|
||||
BACNET_WRITE_PROPERTY_DATA wp_data;
|
||||
|
||||
wp_data.object_type = OBJECT_LOAD_CONTROL;
|
||||
wp_data.object_instance = instance;
|
||||
wp_data.array_index = BACNET_ARRAY_ALL;
|
||||
wp_data.priority = BACNET_NO_PRIORITY;
|
||||
/* Set Enable=TRUE */
|
||||
wp_data.object_property = PROP_ENABLE;
|
||||
value.context_specific = false;
|
||||
value.context_tag = 0;
|
||||
value.tag = BACNET_APPLICATION_TAG_BOOLEAN;
|
||||
value.type.Boolean = enable;
|
||||
wp_data.application_data_len =
|
||||
bacapp_encode_data(&wp_data.application_data[0], &value);
|
||||
ct_test(pTest, wp_data.application_data_len > 0);
|
||||
status = Load_Control_Write_Property(&wp_data);
|
||||
ct_test(pTest, status == true);
|
||||
}
|
||||
|
||||
static void Load_Control_WriteProperty_Shed_Duration(
|
||||
Test *pTest, int instance, unsigned duration)
|
||||
{
|
||||
bool status = false;
|
||||
BACNET_APPLICATION_DATA_VALUE value;
|
||||
BACNET_WRITE_PROPERTY_DATA wp_data;
|
||||
|
||||
wp_data.object_type = OBJECT_LOAD_CONTROL;
|
||||
wp_data.object_instance = instance;
|
||||
wp_data.array_index = BACNET_ARRAY_ALL;
|
||||
wp_data.priority = BACNET_NO_PRIORITY;
|
||||
wp_data.object_property = PROP_SHED_DURATION;
|
||||
value.context_specific = false;
|
||||
value.context_tag = 0;
|
||||
value.tag = BACNET_APPLICATION_TAG_UNSIGNED_INT;
|
||||
value.type.Unsigned_Int = duration;
|
||||
wp_data.application_data_len =
|
||||
bacapp_encode_data(&wp_data.application_data[0], &value);
|
||||
ct_test(pTest, wp_data.application_data_len > 0);
|
||||
status = Load_Control_Write_Property(&wp_data);
|
||||
ct_test(pTest, status == true);
|
||||
}
|
||||
|
||||
static void Load_Control_WriteProperty_Duty_Window(
|
||||
Test *pTest, int instance, unsigned duration)
|
||||
{
|
||||
bool status = false;
|
||||
BACNET_APPLICATION_DATA_VALUE value;
|
||||
BACNET_WRITE_PROPERTY_DATA wp_data;
|
||||
|
||||
wp_data.object_type = OBJECT_LOAD_CONTROL;
|
||||
wp_data.object_instance = instance;
|
||||
wp_data.array_index = BACNET_ARRAY_ALL;
|
||||
wp_data.priority = BACNET_NO_PRIORITY;
|
||||
wp_data.object_property = PROP_DUTY_WINDOW;
|
||||
value.context_specific = false;
|
||||
value.context_tag = 0;
|
||||
value.tag = BACNET_APPLICATION_TAG_UNSIGNED_INT;
|
||||
value.type.Unsigned_Int = duration;
|
||||
wp_data.application_data_len =
|
||||
bacapp_encode_data(&wp_data.application_data[0], &value);
|
||||
ct_test(pTest, wp_data.application_data_len > 0);
|
||||
status = Load_Control_Write_Property(&wp_data);
|
||||
ct_test(pTest, status == true);
|
||||
}
|
||||
|
||||
static void Load_Control_WriteProperty_Start_Time_Wildcards(
|
||||
Test *pTest, int instance)
|
||||
{
|
||||
int len = 0;
|
||||
bool status = false;
|
||||
BACNET_APPLICATION_DATA_VALUE value;
|
||||
BACNET_WRITE_PROPERTY_DATA wp_data;
|
||||
|
||||
wp_data.object_type = OBJECT_LOAD_CONTROL;
|
||||
wp_data.object_instance = instance;
|
||||
wp_data.array_index = BACNET_ARRAY_ALL;
|
||||
wp_data.priority = BACNET_NO_PRIORITY;
|
||||
wp_data.object_property = PROP_START_TIME;
|
||||
value.context_specific = false;
|
||||
value.context_tag = 0;
|
||||
value.tag = BACNET_APPLICATION_TAG_DATE;
|
||||
datetime_date_wildcard_set(&value.type.Date);
|
||||
wp_data.application_data_len =
|
||||
bacapp_encode_data(&wp_data.application_data[0], &value);
|
||||
ct_test(pTest, wp_data.application_data_len > 0);
|
||||
len = wp_data.application_data_len;
|
||||
value.tag = BACNET_APPLICATION_TAG_TIME;
|
||||
datetime_time_wildcard_set(&value.type.Time);
|
||||
wp_data.application_data_len =
|
||||
bacapp_encode_data(&wp_data.application_data[len], &value);
|
||||
ct_test(pTest, wp_data.application_data_len > 0);
|
||||
wp_data.application_data_len += len;
|
||||
status = Load_Control_Write_Property(&wp_data);
|
||||
ct_test(pTest, status == true);
|
||||
}
|
||||
|
||||
static void Load_Control_WriteProperty_Start_Time(Test *pTest,
|
||||
int instance,
|
||||
uint16_t year,
|
||||
uint8_t month,
|
||||
uint8_t day,
|
||||
uint8_t hour,
|
||||
uint8_t minute,
|
||||
uint8_t seconds,
|
||||
uint8_t hundredths)
|
||||
{
|
||||
int len = 0;
|
||||
bool status = false;
|
||||
BACNET_APPLICATION_DATA_VALUE value;
|
||||
BACNET_WRITE_PROPERTY_DATA wp_data;
|
||||
|
||||
wp_data.object_type = OBJECT_LOAD_CONTROL;
|
||||
wp_data.object_instance = instance;
|
||||
wp_data.array_index = BACNET_ARRAY_ALL;
|
||||
wp_data.priority = BACNET_NO_PRIORITY;
|
||||
wp_data.object_property = PROP_START_TIME;
|
||||
value.context_specific = false;
|
||||
value.context_tag = 0;
|
||||
value.tag = BACNET_APPLICATION_TAG_DATE;
|
||||
datetime_set_date(&value.type.Date, year, month, day);
|
||||
wp_data.application_data_len =
|
||||
bacapp_encode_data(&wp_data.application_data[0], &value);
|
||||
ct_test(pTest, wp_data.application_data_len > 0);
|
||||
len = wp_data.application_data_len;
|
||||
value.tag = BACNET_APPLICATION_TAG_TIME;
|
||||
datetime_set_time(&value.type.Time, hour, minute, seconds, hundredths);
|
||||
wp_data.application_data_len =
|
||||
bacapp_encode_data(&wp_data.application_data[len], &value);
|
||||
ct_test(pTest, wp_data.application_data_len > 0);
|
||||
wp_data.application_data_len += len;
|
||||
status = Load_Control_Write_Property(&wp_data);
|
||||
ct_test(pTest, status == true);
|
||||
}
|
||||
|
||||
void testLoadControlStateMachine(Test *pTest)
|
||||
{
|
||||
unsigned i = 0, j = 0;
|
||||
uint8_t level = 0;
|
||||
|
||||
Load_Control_Init();
|
||||
/* validate the triggers for each state change */
|
||||
for (j = 0; j < 20; j++) {
|
||||
Load_Control_State_Machine(0);
|
||||
for (i = 0; i < MAX_LOAD_CONTROLS; i++) {
|
||||
ct_test(pTest, Load_Control_State[i] == SHED_INACTIVE);
|
||||
}
|
||||
}
|
||||
/* SHED_REQUEST_PENDING */
|
||||
/* CancelShed - Start time has wildcards */
|
||||
Load_Control_WriteProperty_Enable(pTest, 0, true);
|
||||
Load_Control_WriteProperty_Shed_Duration(pTest, 0, 60);
|
||||
Load_Control_WriteProperty_Start_Time_Wildcards(pTest, 0);
|
||||
Load_Control_State_Machine(0);
|
||||
ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING);
|
||||
Load_Control_State_Machine(0);
|
||||
ct_test(pTest, Load_Control_State[0] == SHED_INACTIVE);
|
||||
|
||||
/* CancelShed - Requested_Shed_Level equal to default value */
|
||||
Load_Control_Init();
|
||||
Load_Control_WriteProperty_Request_Shed_Level(pTest, 0, 0);
|
||||
Load_Control_WriteProperty_Start_Time(pTest, 0, 2007, 2, 27, 15, 0, 0, 0);
|
||||
Load_Control_WriteProperty_Shed_Duration(pTest, 0, 5);
|
||||
datetime_set_values(&Current_Time, 2007, 2, 27, 15, 0, 0, 0);
|
||||
Load_Control_State_Machine(0);
|
||||
ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING);
|
||||
Load_Control_State_Machine(0);
|
||||
ct_test(pTest, Load_Control_State[0] == SHED_INACTIVE);
|
||||
|
||||
/* CancelShed - Non-default values, but Start time is passed */
|
||||
Load_Control_Init();
|
||||
Load_Control_WriteProperty_Enable(pTest, 0, true);
|
||||
Load_Control_WriteProperty_Request_Shed_Level(pTest, 0, 1);
|
||||
Load_Control_WriteProperty_Shed_Duration(pTest, 0, 5);
|
||||
Load_Control_WriteProperty_Start_Time(pTest, 0, 2007, 2, 27, 15, 0, 0, 0);
|
||||
datetime_set_values(&Current_Time, 2007, 2, 28, 15, 0, 0, 0);
|
||||
Load_Control_State_Machine(0);
|
||||
ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING);
|
||||
Load_Control_State_Machine(0);
|
||||
ct_test(pTest, Load_Control_State[0] == SHED_INACTIVE);
|
||||
|
||||
/* ReconfigurePending - new write received while pending */
|
||||
Load_Control_Init();
|
||||
Load_Control_WriteProperty_Enable(pTest, 0, true);
|
||||
Load_Control_WriteProperty_Request_Shed_Level(pTest, 0, 1);
|
||||
Load_Control_WriteProperty_Shed_Duration(pTest, 0, 5);
|
||||
Load_Control_WriteProperty_Start_Time(pTest, 0, 2007, 2, 27, 15, 0, 0, 0);
|
||||
datetime_set_values(&Current_Time, 2007, 2, 27, 5, 0, 0, 0);
|
||||
Load_Control_State_Machine(0);
|
||||
ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING);
|
||||
Load_Control_State_Machine(0);
|
||||
ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING);
|
||||
Load_Control_WriteProperty_Request_Shed_Level(pTest, 0, 2);
|
||||
Load_Control_State_Machine(0);
|
||||
ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING);
|
||||
Load_Control_WriteProperty_Shed_Duration(pTest, 0, 6);
|
||||
Load_Control_State_Machine(0);
|
||||
ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING);
|
||||
Load_Control_WriteProperty_Duty_Window(pTest, 0, 60);
|
||||
Load_Control_State_Machine(0);
|
||||
ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING);
|
||||
Load_Control_WriteProperty_Start_Time(pTest, 0, 2007, 2, 27, 15, 0, 0, 1);
|
||||
Load_Control_State_Machine(0);
|
||||
ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING);
|
||||
Load_Control_State_Machine(0);
|
||||
ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING);
|
||||
Load_Control_State_Machine(0);
|
||||
ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING);
|
||||
|
||||
/* CannotMeetShed -> FinishedUnsuccessfulShed */
|
||||
Load_Control_Init();
|
||||
Load_Control_WriteProperty_Enable(pTest, 0, true);
|
||||
Load_Control_WriteProperty_Request_Shed_Level(pTest, 0, 1);
|
||||
Load_Control_WriteProperty_Shed_Duration(pTest, 0, 120);
|
||||
Load_Control_WriteProperty_Start_Time(pTest, 0, 2007, 2, 27, 15, 0, 0, 0);
|
||||
datetime_set_values(&Current_Time, 2007, 2, 27, 5, 0, 0, 0);
|
||||
Load_Control_State_Machine(0);
|
||||
ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING);
|
||||
Load_Control_State_Machine(0);
|
||||
ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING);
|
||||
/* set to lowest value so we cannot meet the shed level */
|
||||
datetime_set_values(&Current_Time, 2007, 2, 27, 16, 0, 0, 0);
|
||||
Analog_Output_Present_Value_Set(0, 0, 16);
|
||||
Load_Control_State_Machine(0);
|
||||
ct_test(pTest, Load_Control_State[0] == SHED_NON_COMPLIANT);
|
||||
Load_Control_State_Machine(0);
|
||||
ct_test(pTest, Load_Control_State[0] == SHED_NON_COMPLIANT);
|
||||
/* FinishedUnsuccessfulShed */
|
||||
datetime_set_values(&Current_Time, 2007, 2, 27, 23, 0, 0, 0);
|
||||
Load_Control_State_Machine(0);
|
||||
ct_test(pTest, Load_Control_State[0] == SHED_INACTIVE);
|
||||
|
||||
/* CannotMeetShed -> UnsuccessfulShedReconfigured */
|
||||
Load_Control_Init();
|
||||
Load_Control_WriteProperty_Enable(pTest, 0, true);
|
||||
Load_Control_WriteProperty_Request_Shed_Level(pTest, 0, 1);
|
||||
Load_Control_WriteProperty_Shed_Duration(pTest, 0, 120);
|
||||
Load_Control_WriteProperty_Start_Time(pTest, 0, 2007, 2, 27, 15, 0, 0, 0);
|
||||
datetime_set_values(&Current_Time, 2007, 2, 27, 5, 0, 0, 0);
|
||||
Load_Control_State_Machine(0);
|
||||
ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING);
|
||||
Load_Control_State_Machine(0);
|
||||
ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING);
|
||||
/* set to lowest value so we cannot meet the shed level */
|
||||
datetime_set_values(&Current_Time, 2007, 2, 27, 16, 0, 0, 0);
|
||||
Analog_Output_Present_Value_Set(0, 0, 16);
|
||||
Load_Control_State_Machine(0);
|
||||
ct_test(pTest, Load_Control_State[0] == SHED_NON_COMPLIANT);
|
||||
Load_Control_State_Machine(0);
|
||||
ct_test(pTest, Load_Control_State[0] == SHED_NON_COMPLIANT);
|
||||
/* FinishedUnsuccessfulShed */
|
||||
Load_Control_WriteProperty_Start_Time(pTest, 0, 2007, 2, 27, 16, 0, 0, 0);
|
||||
Load_Control_State_Machine(0);
|
||||
ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING);
|
||||
Load_Control_State_Machine(0);
|
||||
ct_test(pTest, Load_Control_State[0] == SHED_REQUEST_PENDING);
|
||||
datetime_set_values(&Current_Time, 2007, 2, 27, 16, 0, 1, 0);
|
||||
Load_Control_State_Machine(0);
|
||||
ct_test(pTest, Load_Control_State[0] == SHED_NON_COMPLIANT);
|
||||
/* CanNowComplyWithShed */
|
||||
Analog_Output_Present_Value_Set(0, 100, 16);
|
||||
datetime_set_values(&Current_Time, 2007, 2, 27, 16, 0, 2, 0);
|
||||
Load_Control_State_Machine(0);
|
||||
ct_test(pTest, Load_Control_State[0] == SHED_COMPLIANT);
|
||||
level = Analog_Output_Present_Value(0);
|
||||
ct_test(pTest, level == 90);
|
||||
/* FinishedSuccessfulShed */
|
||||
datetime_set_values(&Current_Time, 2007, 2, 27, 23, 0, 0, 0);
|
||||
Load_Control_State_Machine(0);
|
||||
ct_test(pTest, Load_Control_State[0] == SHED_INACTIVE);
|
||||
level = Analog_Output_Present_Value(0);
|
||||
ct_test(pTest, level == 100);
|
||||
}
|
||||
|
||||
void testLoadControl(Test *pTest)
|
||||
{
|
||||
uint8_t apdu[MAX_APDU] = { 0 };
|
||||
int len = 0;
|
||||
uint32_t len_value = 0;
|
||||
uint8_t tag_number = 0;
|
||||
uint16_t decoded_type = 0;
|
||||
uint32_t decoded_instance = 0;
|
||||
BACNET_READ_PROPERTY_DATA rpdata;
|
||||
|
||||
Analog_Output_Init();
|
||||
Load_Control_Init();
|
||||
rpdata.application_data = &apdu[0];
|
||||
rpdata.application_data_len = sizeof(apdu);
|
||||
rpdata.object_type = OBJECT_LOAD_CONTROL;
|
||||
rpdata.object_instance = 1;
|
||||
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
|
||||
rpdata.array_index = BACNET_ARRAY_ALL;
|
||||
len = Load_Control_Read_Property(&rpdata);
|
||||
ct_test(pTest, len != 0);
|
||||
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
|
||||
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
|
||||
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
|
||||
ct_test(pTest, decoded_type == rpdata.object_type);
|
||||
ct_test(pTest, decoded_instance == rpdata.object_instance);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef TEST_LOAD_CONTROL
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
|
||||
pTest = ct_create("BACnet Load Control", NULL);
|
||||
/* individual tests */
|
||||
rc = ct_addTestFunction(pTest, testLoadControl);
|
||||
assert(rc);
|
||||
rc = ct_addTestFunction(pTest, testLoadControlStateMachine);
|
||||
assert(rc);
|
||||
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void)ct_report(pTest);
|
||||
ct_destroy(pTest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_LOAD_CONTROL */
|
||||
#endif /* BAC_TEST */
|
||||
|
||||
@@ -79,13 +79,6 @@ extern "C" {
|
||||
bool Load_Control_Write_Property(
|
||||
BACNET_WRITE_PROPERTY_DATA * wp_data);
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include "ctest.h"
|
||||
BACNET_STACK_EXPORT
|
||||
void testLoadControl(
|
||||
Test * pTest);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -1331,57 +1331,3 @@ void Lighting_Output_Init(void)
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
void testLightingOutput(Test *pTest)
|
||||
{
|
||||
uint8_t apdu[MAX_APDU] = { 0 };
|
||||
int len = 0;
|
||||
uint32_t len_value = 0;
|
||||
uint8_t tag_number = 0;
|
||||
uint16_t decoded_type = 0;
|
||||
uint32_t decoded_instance = 0;
|
||||
BACNET_READ_PROPERTY_DATA rpdata;
|
||||
|
||||
Lighting_Output_Init();
|
||||
rpdata.application_data = &apdu[0];
|
||||
rpdata.application_data_len = sizeof(apdu);
|
||||
rpdata.object_type = OBJECT_LIGHTING_OUTPUT;
|
||||
rpdata.object_instance = 1;
|
||||
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
|
||||
rpdata.array_index = BACNET_ARRAY_ALL;
|
||||
len = Lighting_Output_Read_Property(&rpdata);
|
||||
ct_test(pTest, len != 0);
|
||||
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
|
||||
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
|
||||
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
|
||||
ct_test(pTest, decoded_type == rpdata.object_type);
|
||||
ct_test(pTest, decoded_instance == rpdata.object_instance);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef TEST_LIGHTING_OUTPUT
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
|
||||
pTest = ct_create("BACnet Lighting Output", NULL);
|
||||
/* individual tests */
|
||||
rc = ct_addTestFunction(pTest, testLightingOutput);
|
||||
assert(rc);
|
||||
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void)ct_report(pTest);
|
||||
ct_destroy(pTest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_LIGHTING_INPUT */
|
||||
#endif /* BAC_TEST */
|
||||
|
||||
@@ -216,13 +216,6 @@ extern "C" {
|
||||
bool Lighting_Output_Write_Property(
|
||||
BACNET_WRITE_PROPERTY_DATA * wp_data);
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include "ctest.h"
|
||||
BACNET_STACK_EXPORT
|
||||
void testLightingOutput(
|
||||
Test * pTest);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -371,57 +371,3 @@ bool Life_Safety_Point_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
void testLifeSafetyPoint(Test *pTest)
|
||||
{
|
||||
uint8_t apdu[MAX_APDU] = { 0 };
|
||||
int len = 0;
|
||||
uint32_t len_value = 0;
|
||||
uint8_t tag_number = 0;
|
||||
uint16_t decoded_type = 0;
|
||||
uint32_t decoded_instance = 0;
|
||||
BACNET_READ_PROPERTY_DATA rpdata;
|
||||
|
||||
Life_Safety_Point_Init();
|
||||
rpdata.application_data = &apdu[0];
|
||||
rpdata.application_data_len = sizeof(apdu);
|
||||
rpdata.object_type = OBJECT_LIFE_SAFETY_POINT;
|
||||
rpdata.object_instance = 1;
|
||||
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
|
||||
rpdata.array_index = BACNET_ARRAY_ALL;
|
||||
len = Life_Safety_Point_Read_Property(&rpdata);
|
||||
ct_test(pTest, len != 0);
|
||||
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
|
||||
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
|
||||
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
|
||||
ct_test(pTest, decoded_type == rpdata.object_type);
|
||||
ct_test(pTest, decoded_instance == rpdata.object_instance);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef TEST_LIFE_SAFETY_POINT
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
|
||||
pTest = ct_create("BACnet Life Safety Point", NULL);
|
||||
/* individual tests */
|
||||
rc = ct_addTestFunction(pTest, testLifeSafetyPoint);
|
||||
assert(rc);
|
||||
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void)ct_report(pTest);
|
||||
ct_destroy(pTest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_LIFE_SAFETY_POINT */
|
||||
#endif /* BAC_TEST */
|
||||
|
||||
@@ -70,13 +70,6 @@ extern "C" {
|
||||
bool Life_Safety_Point_Write_Property(
|
||||
BACNET_WRITE_PROPERTY_DATA * wp_data);
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include "ctest.h"
|
||||
BACNET_STACK_EXPORT
|
||||
void testLifeSafetyPoint(
|
||||
Test * pTest);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -727,64 +727,3 @@ bool Multistate_Input_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
bool Device_Valid_Object_Name(BACNET_CHARACTER_STRING *object_name,
|
||||
int *object_type,
|
||||
uint32_t *object_instance)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void testMultistateInput(Test *pTest)
|
||||
{
|
||||
uint8_t apdu[MAX_APDU] = { 0 };
|
||||
int len = 0;
|
||||
uint32_t len_value = 0;
|
||||
uint8_t tag_number = 0;
|
||||
uint16_t decoded_type = 0;
|
||||
uint32_t decoded_instance = 0;
|
||||
BACNET_READ_PROPERTY_DATA rpdata;
|
||||
|
||||
Multistate_Input_Init();
|
||||
rpdata.application_data = &apdu[0];
|
||||
rpdata.application_data_len = sizeof(apdu);
|
||||
rpdata.object_type = OBJECT_MULTI_STATE_INPUT;
|
||||
rpdata.object_instance = 1;
|
||||
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
|
||||
rpdata.array_index = BACNET_ARRAY_ALL;
|
||||
len = Multistate_Input_Read_Property(&rpdata);
|
||||
ct_test(pTest, len != 0);
|
||||
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
|
||||
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
|
||||
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
|
||||
ct_test(pTest, decoded_type == rpdata.object_type);
|
||||
ct_test(pTest, decoded_instance == rpdata.object_instance);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef TEST_MULTISTATE_INPUT
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
|
||||
pTest = ct_create("BACnet Multi-state Input", NULL);
|
||||
/* individual tests */
|
||||
rc = ct_addTestFunction(pTest, testMultistateInput);
|
||||
assert(rc);
|
||||
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void)ct_report(pTest);
|
||||
ct_destroy(pTest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#endif /* BAC_TEST */
|
||||
|
||||
@@ -149,14 +149,6 @@ extern "C" {
|
||||
void Multistate_Input_Init(
|
||||
void);
|
||||
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include "ctest.h"
|
||||
BACNET_STACK_EXPORT
|
||||
void testMultistateInput(
|
||||
Test * pTest);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -464,57 +464,3 @@ bool Multistate_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
void testMultistateOutput(Test *pTest)
|
||||
{
|
||||
uint8_t apdu[MAX_APDU] = { 0 };
|
||||
int len = 0;
|
||||
uint32_t len_value = 0;
|
||||
uint8_t tag_number = 0;
|
||||
uint16_t decoded_type = 0;
|
||||
uint32_t decoded_instance = 0;
|
||||
BACNET_READ_PROPERTY_DATA rpdata;
|
||||
|
||||
Multistate_Output_Init();
|
||||
rpdata.application_data = &apdu[0];
|
||||
rpdata.application_data_len = sizeof(apdu);
|
||||
rpdata.object_type = OBJECT_MULTI_STATE_OUTPUT;
|
||||
rpdata.object_instance = 1;
|
||||
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
|
||||
rpdata.array_index = BACNET_ARRAY_ALL;
|
||||
len = Multistate_Output_Read_Property(&rpdata);
|
||||
ct_test(pTest, len != 0);
|
||||
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
|
||||
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
|
||||
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
|
||||
ct_test(pTest, decoded_type == rpdata.object_type);
|
||||
ct_test(pTest, decoded_instance == rpdata.object_instance);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef TEST_MULTISTATE_OUTPUT
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
|
||||
pTest = ct_create("BACnet Multi-state Output", NULL);
|
||||
/* individual tests */
|
||||
rc = ct_addTestFunction(pTest, testMultistateOutput);
|
||||
assert(rc);
|
||||
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void)ct_report(pTest);
|
||||
ct_destroy(pTest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_BINARY_INPUT */
|
||||
#endif /* BAC_TEST */
|
||||
|
||||
@@ -126,14 +126,6 @@ extern "C" {
|
||||
uint32_t object_instance,
|
||||
uint32_t state_index);
|
||||
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include "ctest.h"
|
||||
BACNET_STACK_EXPORT
|
||||
void testMultistateOutput(
|
||||
Test * pTest);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -576,57 +576,3 @@ bool Multistate_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
void testMultistateInput(Test *pTest)
|
||||
{
|
||||
uint8_t apdu[MAX_APDU] = { 0 };
|
||||
int len = 0;
|
||||
uint32_t len_value = 0;
|
||||
uint8_t tag_number = 0;
|
||||
uint16_t decoded_type = 0;
|
||||
uint32_t decoded_instance = 0;
|
||||
BACNET_READ_PROPERTY_DATA rpdata;
|
||||
|
||||
Multistate_Value_Init();
|
||||
rpdata.application_data = &apdu[0];
|
||||
rpdata.application_data_len = sizeof(apdu);
|
||||
rpdata.object_type = OBJECT_MULTI_STATE_VALUE;
|
||||
rpdata.object_instance = 1;
|
||||
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
|
||||
rpdata.array_index = BACNET_ARRAY_ALL;
|
||||
len = Multistate_Value_Read_Property(&rpdata);
|
||||
ct_test(pTest, len != 0);
|
||||
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
|
||||
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
|
||||
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
|
||||
ct_test(pTest, decoded_type == rpdata.object_type);
|
||||
ct_test(pTest, decoded_instance == rpdata.object_instance);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef TEST_MULTISTATE_VALUE
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
|
||||
pTest = ct_create("BACnet Multi-state Input", NULL);
|
||||
/* individual tests */
|
||||
rc = ct_addTestFunction(pTest, testMultistateInput);
|
||||
assert(rc);
|
||||
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void)ct_report(pTest);
|
||||
ct_destroy(pTest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#endif /* BAC_TEST */
|
||||
|
||||
@@ -140,14 +140,6 @@ extern "C" {
|
||||
void Multistate_Value_Init(
|
||||
void);
|
||||
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include "ctest.h"
|
||||
BACNET_STACK_EXPORT
|
||||
void testMultistateValue(
|
||||
Test * pTest);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -2427,95 +2427,3 @@ void Network_Port_Init(void)
|
||||
{
|
||||
/* do something interesting */
|
||||
}
|
||||
|
||||
#ifdef BACNET_UNIT_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
void test_network_port(Test *pTest)
|
||||
{
|
||||
uint8_t apdu[MAX_APDU] = { 0 };
|
||||
int len = 0;
|
||||
int test_len = 0;
|
||||
BACNET_READ_PROPERTY_DATA rpdata;
|
||||
/* for decode value data */
|
||||
BACNET_APPLICATION_DATA_VALUE value;
|
||||
const int *pRequired = NULL;
|
||||
const int *pOptional = NULL;
|
||||
const int *pProprietary = NULL;
|
||||
unsigned port = 0;
|
||||
unsigned count = 0;
|
||||
uint32_t object_instance = 0;
|
||||
bool status = false;
|
||||
uint8_t port_type[] = { PORT_TYPE_ETHERNET, PORT_TYPE_ARCNET,
|
||||
PORT_TYPE_MSTP, PORT_TYPE_PTP, PORT_TYPE_LONTALK, PORT_TYPE_BIP,
|
||||
PORT_TYPE_ZIGBEE, PORT_TYPE_VIRTUAL, PORT_TYPE_NON_BACNET,
|
||||
PORT_TYPE_BIP6, PORT_TYPE_MAX };
|
||||
|
||||
while (port_type[port] != PORT_TYPE_MAX) {
|
||||
object_instance = 1234;
|
||||
status = Network_Port_Object_Instance_Number_Set(0, object_instance);
|
||||
ct_test(pTest, status);
|
||||
status = Network_Port_Type_Set(object_instance, port_type[port]);
|
||||
ct_test(pTest, status);
|
||||
Network_Port_Init();
|
||||
count = Network_Port_Count();
|
||||
ct_test(pTest, count > 0);
|
||||
rpdata.application_data = &apdu[0];
|
||||
rpdata.application_data_len = sizeof(apdu);
|
||||
rpdata.object_type = OBJECT_NETWORK_PORT;
|
||||
rpdata.object_instance = object_instance;
|
||||
Network_Port_Property_Lists(&pRequired, &pOptional, &pProprietary);
|
||||
while ((*pRequired) != -1) {
|
||||
rpdata.object_property = *pRequired;
|
||||
rpdata.array_index = BACNET_ARRAY_ALL;
|
||||
len = Network_Port_Read_Property(&rpdata);
|
||||
ct_test(pTest, len != 0);
|
||||
test_len = bacapp_decode_application_data(rpdata.application_data,
|
||||
(uint8_t)rpdata.application_data_len, &value);
|
||||
ct_test(pTest, test_len >= 0);
|
||||
if (test_len < 0) {
|
||||
printf("<decode failed!>\n");
|
||||
}
|
||||
pRequired++;
|
||||
}
|
||||
while ((*pOptional) != -1) {
|
||||
rpdata.object_property = *pOptional;
|
||||
rpdata.array_index = BACNET_ARRAY_ALL;
|
||||
len = Network_Port_Read_Property(&rpdata);
|
||||
ct_test(pTest, len != 0);
|
||||
test_len = bacapp_decode_application_data(rpdata.application_data,
|
||||
(uint8_t)rpdata.application_data_len, &value);
|
||||
ct_test(pTest, test_len >= 0);
|
||||
if (test_len < 0) {
|
||||
printf("<decode failed!>\n");
|
||||
}
|
||||
pOptional++;
|
||||
}
|
||||
port++;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef TEST_NETWORK_PORT
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
|
||||
pTest = ct_create("BACnet Network Port", NULL);
|
||||
/* individual tests */
|
||||
rc = ct_addTestFunction(pTest, test_network_port);
|
||||
assert(rc);
|
||||
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void)ct_report(pTest);
|
||||
ct_destroy(pTest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#endif /* BAC_TEST */
|
||||
|
||||
@@ -355,57 +355,3 @@ bool OctetString_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
void OctetString_Value_Intrinsic_Reporting(uint32_t object_instance)
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
void testOctetString_Value(Test *pTest)
|
||||
{
|
||||
BACNET_READ_PROPERTY_DATA rpdata;
|
||||
uint8_t apdu[MAX_APDU] = { 0 };
|
||||
int len = 0;
|
||||
uint32_t len_value = 0;
|
||||
uint8_t tag_number = 0;
|
||||
uint16_t decoded_type = 0;
|
||||
uint32_t decoded_instance = 0;
|
||||
|
||||
OctetString_Value_Init();
|
||||
rpdata.application_data = &apdu[0];
|
||||
rpdata.application_data_len = sizeof(apdu);
|
||||
rpdata.object_type = OBJECT_OCTETSTRING_VALUE;
|
||||
rpdata.object_instance = 1;
|
||||
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
|
||||
rpdata.array_index = BACNET_ARRAY_ALL;
|
||||
len = OctetString_Value_Read_Property(&rpdata);
|
||||
ct_test(pTest, len != 0);
|
||||
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
|
||||
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
|
||||
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
|
||||
ct_test(pTest, decoded_type == rpdata.object_type);
|
||||
ct_test(pTest, decoded_instance == rpdata.object_instance);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef TEST_OCTETSTRING_VALUE
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
|
||||
pTest = ct_create("BACnet OctetString Value", NULL);
|
||||
/* individual tests */
|
||||
rc = ct_addTestFunction(pTest, testOctetString_Value);
|
||||
assert(rc);
|
||||
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void)ct_report(pTest);
|
||||
ct_destroy(pTest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_OCTETSTRING_VALUE */
|
||||
#endif /* BAC_TEST */
|
||||
|
||||
@@ -104,12 +104,6 @@ extern "C" {
|
||||
BACNET_STACK_EXPORT
|
||||
void OctetString_Value_Init(void);
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include "ctest.h"
|
||||
BACNET_STACK_EXPORT
|
||||
void testOctetString_Value(Test * pTest);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -360,57 +360,3 @@ bool PositiveInteger_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
void PositiveInteger_Value_Intrinsic_Reporting(uint32_t object_instance)
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
void testPositiveInteger_Value(Test *pTest)
|
||||
{
|
||||
BACNET_READ_PROPERTY_DATA rpdata;
|
||||
uint8_t apdu[MAX_APDU] = { 0 };
|
||||
int len = 0;
|
||||
uint32_t len_value = 0;
|
||||
uint8_t tag_number = 0;
|
||||
uint16_t decoded_type = 0;
|
||||
uint32_t decoded_instance = 0;
|
||||
|
||||
PositiveInteger_Value_Init();
|
||||
rpdata.application_data = &apdu[0];
|
||||
rpdata.application_data_len = sizeof(apdu);
|
||||
rpdata.object_type = OBJECT_POSITIVE_INTEGER_VALUE;
|
||||
rpdata.object_instance = 1;
|
||||
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
|
||||
rpdata.array_index = BACNET_ARRAY_ALL;
|
||||
len = PositiveInteger_Value_Read_Property(&rpdata);
|
||||
ct_test(pTest, len != 0);
|
||||
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
|
||||
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
|
||||
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
|
||||
ct_test(pTest, decoded_type == rpdata.object_type);
|
||||
ct_test(pTest, decoded_instance == rpdata.object_instance);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef TEST_POSITIVEINTEGER_VALUE
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
|
||||
pTest = ct_create("BACnet PositiveInteger Value", NULL);
|
||||
/* individual tests */
|
||||
rc = ct_addTestFunction(pTest, testPositiveInteger_Value);
|
||||
assert(rc);
|
||||
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void)ct_report(pTest);
|
||||
ct_destroy(pTest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_POSITIVEINTEGER_VALUE */
|
||||
#endif /* BAC_TEST */
|
||||
|
||||
@@ -103,12 +103,6 @@ extern "C" {
|
||||
BACNET_STACK_EXPORT
|
||||
void PositiveInteger_Value_Init(void);
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include "ctest.h"
|
||||
BACNET_STACK_EXPORT
|
||||
void testPositiveInteger_Value(Test * pTest);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -424,59 +424,3 @@ void Schedule_Recalculate_PV(
|
||||
desc->Present_Value = &desc->Schedule_Default;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
void testSchedule(Test *pTest)
|
||||
{
|
||||
BACNET_READ_PROPERTY_DATA rpdata;
|
||||
uint8_t apdu[MAX_APDU] = { 0 };
|
||||
int len = 0;
|
||||
uint32_t len_value = 0;
|
||||
uint8_t tag_number = 0;
|
||||
uint16_t decoded_type = 0;
|
||||
uint32_t decoded_instance = 0;
|
||||
|
||||
Schedule_Init();
|
||||
rpdata.application_data = &apdu[0];
|
||||
rpdata.application_data_len = sizeof(apdu);
|
||||
rpdata.object_type = OBJECT_SCHEDULE;
|
||||
rpdata.object_instance = 1;
|
||||
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
|
||||
rpdata.array_index = BACNET_ARRAY_ALL;
|
||||
len = Schedule_Read_Property(&rpdata);
|
||||
ct_test(pTest, len != 0);
|
||||
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
|
||||
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
|
||||
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
|
||||
ct_test(pTest, decoded_type == rpdata.object_type);
|
||||
ct_test(pTest, decoded_instance == rpdata.object_instance);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef TEST_SCHEDULE
|
||||
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
|
||||
pTest = ct_create("BACnet Schedule", NULL);
|
||||
/* individual tests */
|
||||
rc = ct_addTestFunction(pTest, testSchedule);
|
||||
assert(rc);
|
||||
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void)ct_report(pTest);
|
||||
ct_destroy(pTest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* TEST_SCHEDULE */
|
||||
#endif /* BAC_TEST */
|
||||
|
||||
@@ -327,155 +327,3 @@ void FIFO_Init(FIFO_BUFFER *b, volatile uint8_t *buffer, unsigned buffer_len)
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "ctest.h"
|
||||
|
||||
/**
|
||||
* Unit Test for the FIFO buffer
|
||||
*
|
||||
* @param pTest - test tracking pointer
|
||||
*/
|
||||
void testFIFOBuffer(Test *pTest)
|
||||
{
|
||||
/* FIFO data structure */
|
||||
FIFO_BUFFER test_buffer = { 0 };
|
||||
volatile FIFO_DATA_STORE(data_store, 60) = { 0 };
|
||||
uint8_t add_data[40] = { "RoseSteveLouPatRachelJessicaDaniAmyHerb" };
|
||||
uint8_t test_add_data[40] = { 0 };
|
||||
uint8_t test_data = 0;
|
||||
unsigned index = 0;
|
||||
unsigned count = 0;
|
||||
bool status = 0;
|
||||
|
||||
ct_test(pTest, sizeof(data_store) == 64);
|
||||
FIFO_Init(&test_buffer, data_store, sizeof(data_store));
|
||||
ct_test(pTest, FIFO_Empty(&test_buffer));
|
||||
|
||||
/* load the buffer */
|
||||
for (test_data = 0; test_data < sizeof(data_store); test_data++) {
|
||||
ct_test(pTest, !FIFO_Full(&test_buffer));
|
||||
ct_test(pTest, FIFO_Available(&test_buffer, 1));
|
||||
status = FIFO_Put(&test_buffer, test_data);
|
||||
ct_test(pTest, status == true);
|
||||
ct_test(pTest, !FIFO_Empty(&test_buffer));
|
||||
}
|
||||
/* not able to put any more */
|
||||
ct_test(pTest, FIFO_Full(&test_buffer));
|
||||
ct_test(pTest, !FIFO_Available(&test_buffer, 1));
|
||||
status = FIFO_Put(&test_buffer, 42);
|
||||
ct_test(pTest, status == false);
|
||||
/* unload the buffer */
|
||||
for (index = 0; index < sizeof(data_store); index++) {
|
||||
ct_test(pTest, !FIFO_Empty(&test_buffer));
|
||||
test_data = FIFO_Peek(&test_buffer);
|
||||
ct_test(pTest, test_data == index);
|
||||
test_data = FIFO_Get(&test_buffer);
|
||||
ct_test(pTest, test_data == index);
|
||||
ct_test(pTest, FIFO_Available(&test_buffer, 1));
|
||||
ct_test(pTest, !FIFO_Full(&test_buffer));
|
||||
}
|
||||
ct_test(pTest, FIFO_Empty(&test_buffer));
|
||||
test_data = FIFO_Get(&test_buffer);
|
||||
ct_test(pTest, test_data == 0);
|
||||
test_data = FIFO_Peek(&test_buffer);
|
||||
ct_test(pTest, test_data == 0);
|
||||
ct_test(pTest, FIFO_Empty(&test_buffer));
|
||||
/* test the ring around the buffer */
|
||||
for (index = 0; index < sizeof(data_store); index++) {
|
||||
ct_test(pTest, FIFO_Empty(&test_buffer));
|
||||
ct_test(pTest, FIFO_Available(&test_buffer, 4));
|
||||
for (count = 1; count < 4; count++) {
|
||||
test_data = count;
|
||||
status = FIFO_Put(&test_buffer, test_data);
|
||||
ct_test(pTest, status == true);
|
||||
ct_test(pTest, !FIFO_Empty(&test_buffer));
|
||||
}
|
||||
for (count = 1; count < 4; count++) {
|
||||
ct_test(pTest, !FIFO_Empty(&test_buffer));
|
||||
test_data = FIFO_Peek(&test_buffer);
|
||||
ct_test(pTest, test_data == count);
|
||||
test_data = FIFO_Get(&test_buffer);
|
||||
ct_test(pTest, test_data == count);
|
||||
}
|
||||
}
|
||||
ct_test(pTest, FIFO_Empty(&test_buffer));
|
||||
/* test Add */
|
||||
ct_test(pTest, FIFO_Available(&test_buffer, sizeof(add_data)));
|
||||
status = FIFO_Add(&test_buffer, add_data, sizeof(add_data));
|
||||
ct_test(pTest, status == true);
|
||||
count = FIFO_Count(&test_buffer);
|
||||
ct_test(pTest, count == sizeof(add_data));
|
||||
ct_test(pTest, !FIFO_Empty(&test_buffer));
|
||||
for (index = 0; index < sizeof(add_data); index++) {
|
||||
/* unload the buffer */
|
||||
ct_test(pTest, !FIFO_Empty(&test_buffer));
|
||||
test_data = FIFO_Peek(&test_buffer);
|
||||
ct_test(pTest, test_data == add_data[index]);
|
||||
test_data = FIFO_Get(&test_buffer);
|
||||
ct_test(pTest, test_data == add_data[index]);
|
||||
}
|
||||
ct_test(pTest, FIFO_Empty(&test_buffer));
|
||||
/* test Pull */
|
||||
ct_test(pTest, FIFO_Available(&test_buffer, sizeof(add_data)));
|
||||
status = FIFO_Add(&test_buffer, add_data, sizeof(add_data));
|
||||
ct_test(pTest, status == true);
|
||||
count = FIFO_Count(&test_buffer);
|
||||
ct_test(pTest, count == sizeof(add_data));
|
||||
ct_test(pTest, !FIFO_Empty(&test_buffer));
|
||||
count = FIFO_Pull(&test_buffer, &test_add_data[0], sizeof(test_add_data));
|
||||
ct_test(pTest, FIFO_Empty(&test_buffer));
|
||||
ct_test(pTest, count == sizeof(test_add_data));
|
||||
for (index = 0; index < sizeof(add_data); index++) {
|
||||
ct_test(pTest, test_add_data[index] == add_data[index]);
|
||||
}
|
||||
ct_test(pTest, FIFO_Available(&test_buffer, sizeof(add_data)));
|
||||
status = FIFO_Add(&test_buffer, test_add_data, sizeof(add_data));
|
||||
ct_test(pTest, status == true);
|
||||
ct_test(pTest, !FIFO_Empty(&test_buffer));
|
||||
for (index = 0; index < sizeof(add_data); index++) {
|
||||
count = FIFO_Pull(&test_buffer, &test_add_data[0], 1);
|
||||
ct_test(pTest, count == 1);
|
||||
ct_test(pTest, test_add_data[0] == add_data[index]);
|
||||
}
|
||||
ct_test(pTest, FIFO_Empty(&test_buffer));
|
||||
/* test flush */
|
||||
status = FIFO_Add(&test_buffer, test_add_data, sizeof(test_add_data));
|
||||
ct_test(pTest, status == true);
|
||||
ct_test(pTest, !FIFO_Empty(&test_buffer));
|
||||
FIFO_Flush(&test_buffer);
|
||||
ct_test(pTest, FIFO_Empty(&test_buffer));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef TEST_FIFO_BUFFER
|
||||
/**
|
||||
* Main program entry for Unit Test
|
||||
*
|
||||
* @return returns 0 on success, and non-zero on fail.
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
|
||||
pTest = ct_create("FIFO Buffer", NULL);
|
||||
|
||||
/* individual tests */
|
||||
rc = ct_addTestFunction(pTest, testFIFOBuffer);
|
||||
assert(rc);
|
||||
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void)ct_report(pTest);
|
||||
|
||||
ct_destroy(pTest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -108,13 +108,6 @@ extern "C" {
|
||||
volatile uint8_t * buffer,
|
||||
unsigned buffer_len);
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include "ctest.h"
|
||||
BACNET_STACK_EXPORT
|
||||
void testFIFOBuffer(
|
||||
Test * pTest);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -58,55 +58,3 @@ char *filename_remove_path(const char *filename_in)
|
||||
|
||||
return filename_out;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ctest.h"
|
||||
|
||||
void testFilename(Test *pTest)
|
||||
{
|
||||
char *data1 = "c:\\Joshua\\run";
|
||||
char *data2 = "/home/Anna/run";
|
||||
char *data3 = "c:\\Program Files\\Christopher\\run.exe";
|
||||
char *data4 = "//Mary/data/run";
|
||||
char *data5 = "bin\\run";
|
||||
char *filename = NULL;
|
||||
|
||||
filename = filename_remove_path(data1);
|
||||
ct_test(pTest, strcmp("run", filename) == 0);
|
||||
filename = filename_remove_path(data2);
|
||||
ct_test(pTest, strcmp("run", filename) == 0);
|
||||
filename = filename_remove_path(data3);
|
||||
ct_test(pTest, strcmp("run.exe", filename) == 0);
|
||||
filename = filename_remove_path(data4);
|
||||
ct_test(pTest, strcmp("run", filename) == 0);
|
||||
filename = filename_remove_path(data5);
|
||||
ct_test(pTest, strcmp("run", filename) == 0);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef TEST_FILENAME
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
|
||||
pTest = ct_create("filename remove path", NULL);
|
||||
|
||||
/* individual tests */
|
||||
rc = ct_addTestFunction(pTest, testFilename);
|
||||
assert(rc);
|
||||
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void)ct_report(pTest);
|
||||
|
||||
ct_destroy(pTest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_FILENAME */
|
||||
#endif /* BAC_TEST */
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
/*####COPYRIGHTBEGIN####
|
||||
-------------------------------------------
|
||||
Copyright (C) 2003 Steve Karg
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to
|
||||
The Free Software Foundation, Inc.
|
||||
59 Temple Place - Suite 330
|
||||
Boston, MA 02111-1307, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or
|
||||
use macros or inline functions from this file, or you compile
|
||||
this file and link it with other works to produce a work based
|
||||
on this file, this file does not by itself cause the resulting
|
||||
work to be covered by the GNU General Public License. However
|
||||
the source code for this file must still be made available in
|
||||
accordance with section (3) of the GNU General Public License.
|
||||
|
||||
This exception does not invalidate any other reasons why a work
|
||||
based on this file might be covered by the GNU General Public
|
||||
License.
|
||||
-------------------------------------------
|
||||
####COPYRIGHTEND####*/
|
||||
/*#define BAC_TEST */
|
||||
/*#define TEST_KEY */
|
||||
#include "key.h"
|
||||
|
||||
/** @file key.c Tests (only) of key encoding/decoding. */
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ctest.h"
|
||||
|
||||
/* test the encode and decode macros */
|
||||
void testKeys(Test *pTest)
|
||||
{
|
||||
int type, id;
|
||||
int decoded_type, decoded_id;
|
||||
KEY key;
|
||||
|
||||
for (type = 0; type < KEY_TYPE_MAX; type++) {
|
||||
for (id = 0; id < KEY_ID_MAX; id++) {
|
||||
key = KEY_ENCODE(type, id);
|
||||
decoded_type = KEY_DECODE_TYPE(key);
|
||||
decoded_id = KEY_DECODE_ID(key);
|
||||
ct_test(pTest, decoded_type == type);
|
||||
ct_test(pTest, decoded_id == id);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* test the encode and decode macros */
|
||||
void testKeySample(Test *pTest)
|
||||
{
|
||||
int type, id;
|
||||
int type_list[] = { 0, 1, KEY_TYPE_MAX / 2, KEY_TYPE_MAX - 1, -1 };
|
||||
int id_list[] = { 0, 1, KEY_ID_MAX / 2, KEY_ID_MAX - 1, -1 };
|
||||
int type_index = 0;
|
||||
int id_index = 0;
|
||||
int decoded_type, decoded_id;
|
||||
KEY key;
|
||||
|
||||
while (type_list[type_index] != -1) {
|
||||
while (id_list[id_index] != -1) {
|
||||
type = type_list[type_index];
|
||||
id = id_list[id_index];
|
||||
key = KEY_ENCODE(type, id);
|
||||
decoded_type = KEY_DECODE_TYPE(key);
|
||||
decoded_id = KEY_DECODE_ID(key);
|
||||
ct_test(pTest, decoded_type == type);
|
||||
ct_test(pTest, decoded_id == id);
|
||||
|
||||
id_index++;
|
||||
}
|
||||
id_index = 0;
|
||||
type_index++;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef TEST_KEY
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
|
||||
pTest = ct_create("key", NULL);
|
||||
/* add the individual tests */
|
||||
/* rc = ct_addTestFunction(pTest, testKeys); */
|
||||
/* assert(rc); */
|
||||
rc = ct_addTestFunction(pTest, testKeySample);
|
||||
assert(rc);
|
||||
/* run all the tests */
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void)ct_report(pTest);
|
||||
/* completed testing - cleanup */
|
||||
ct_destroy(pTest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* LOCAL_TEST */
|
||||
#endif
|
||||
@@ -497,312 +497,3 @@ void Keylist_Delete(OS_Keylist list)
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ctest.h"
|
||||
|
||||
/* test the FIFO */
|
||||
static void testKeyListFIFO(Test *pTest)
|
||||
{
|
||||
OS_Keylist list;
|
||||
KEY key;
|
||||
int index;
|
||||
char *data1 = "Joshua";
|
||||
char *data2 = "Anna";
|
||||
char *data3 = "Mary";
|
||||
char *data;
|
||||
|
||||
list = Keylist_Create();
|
||||
ct_test(pTest, list != NULL);
|
||||
|
||||
key = 0;
|
||||
index = Keylist_Data_Add(list, key, data1);
|
||||
ct_test(pTest, index == 0);
|
||||
index = Keylist_Data_Add(list, key, data2);
|
||||
ct_test(pTest, index == 0);
|
||||
index = Keylist_Data_Add(list, key, data3);
|
||||
ct_test(pTest, index == 0);
|
||||
|
||||
ct_test(pTest, Keylist_Count(list) == 3);
|
||||
|
||||
data = Keylist_Data_Pop(list);
|
||||
ct_test(pTest, data != NULL);
|
||||
ct_test(pTest, strcmp(data, data1) == 0);
|
||||
data = Keylist_Data_Pop(list);
|
||||
ct_test(pTest, data != NULL);
|
||||
ct_test(pTest, strcmp(data, data2) == 0);
|
||||
data = Keylist_Data_Pop(list);
|
||||
ct_test(pTest, data != NULL);
|
||||
ct_test(pTest, strcmp(data, data3) == 0);
|
||||
data = Keylist_Data_Pop(list);
|
||||
ct_test(pTest, data == NULL);
|
||||
data = Keylist_Data_Pop(list);
|
||||
ct_test(pTest, data == NULL);
|
||||
|
||||
Keylist_Delete(list);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* test the FILO */
|
||||
static void testKeyListFILO(Test *pTest)
|
||||
{
|
||||
OS_Keylist list;
|
||||
KEY key;
|
||||
int index;
|
||||
char *data1 = "Joshua";
|
||||
char *data2 = "Anna";
|
||||
char *data3 = "Mary";
|
||||
char *data;
|
||||
|
||||
list = Keylist_Create();
|
||||
ct_test(pTest, list != NULL);
|
||||
|
||||
key = 0;
|
||||
index = Keylist_Data_Add(list, key, data1);
|
||||
ct_test(pTest, index == 0);
|
||||
index = Keylist_Data_Add(list, key, data2);
|
||||
ct_test(pTest, index == 0);
|
||||
index = Keylist_Data_Add(list, key, data3);
|
||||
ct_test(pTest, index == 0);
|
||||
|
||||
ct_test(pTest, Keylist_Count(list) == 3);
|
||||
|
||||
data = Keylist_Data_Delete_By_Index(list, 0);
|
||||
ct_test(pTest, data != NULL);
|
||||
ct_test(pTest, strcmp(data, data3) == 0);
|
||||
|
||||
data = Keylist_Data_Delete_By_Index(list, 0);
|
||||
ct_test(pTest, data != NULL);
|
||||
ct_test(pTest, strcmp(data, data2) == 0);
|
||||
|
||||
data = Keylist_Data_Delete_By_Index(list, 0);
|
||||
ct_test(pTest, data != NULL);
|
||||
ct_test(pTest, strcmp(data, data1) == 0);
|
||||
|
||||
data = Keylist_Data_Delete_By_Index(list, 0);
|
||||
ct_test(pTest, data == NULL);
|
||||
|
||||
data = Keylist_Data_Delete_By_Index(list, 0);
|
||||
ct_test(pTest, data == NULL);
|
||||
|
||||
Keylist_Delete(list);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void testKeyListDataKey(Test *pTest)
|
||||
{
|
||||
OS_Keylist list;
|
||||
KEY key;
|
||||
KEY test_key;
|
||||
int index;
|
||||
char *data1 = "Joshua";
|
||||
char *data2 = "Anna";
|
||||
char *data3 = "Mary";
|
||||
char *data;
|
||||
|
||||
list = Keylist_Create();
|
||||
ct_test(pTest, list != NULL);
|
||||
|
||||
key = 1;
|
||||
index = Keylist_Data_Add(list, key, data1);
|
||||
ct_test(pTest, index == 0);
|
||||
test_key = Keylist_Key(list, index);
|
||||
ct_test(pTest, test_key == key);
|
||||
|
||||
key = 2;
|
||||
index = Keylist_Data_Add(list, key, data2);
|
||||
ct_test(pTest, index == 1);
|
||||
test_key = Keylist_Key(list, index);
|
||||
ct_test(pTest, test_key == key);
|
||||
|
||||
key = 3;
|
||||
index = Keylist_Data_Add(list, key, data3);
|
||||
ct_test(pTest, index == 2);
|
||||
test_key = Keylist_Key(list, index);
|
||||
ct_test(pTest, test_key == key);
|
||||
|
||||
ct_test(pTest, Keylist_Count(list) == 3);
|
||||
|
||||
/* look at the data */
|
||||
key = 2;
|
||||
data = Keylist_Data(list, key);
|
||||
ct_test(pTest, data != NULL);
|
||||
ct_test(pTest, strcmp(data, data2) == 0);
|
||||
|
||||
key = 1;
|
||||
data = Keylist_Data(list, key);
|
||||
ct_test(pTest, data != NULL);
|
||||
ct_test(pTest, strcmp(data, data1) == 0);
|
||||
|
||||
key = 3;
|
||||
data = Keylist_Data(list, key);
|
||||
ct_test(pTest, data != NULL);
|
||||
ct_test(pTest, strcmp(data, data3) == 0);
|
||||
|
||||
/* work the data */
|
||||
key = 2;
|
||||
data = Keylist_Data_Delete(list, key);
|
||||
ct_test(pTest, data != NULL);
|
||||
ct_test(pTest, strcmp(data, data2) == 0);
|
||||
data = Keylist_Data_Delete(list, key);
|
||||
ct_test(pTest, data == NULL);
|
||||
ct_test(pTest, Keylist_Count(list) == 2);
|
||||
|
||||
key = 1;
|
||||
data = Keylist_Data(list, key);
|
||||
ct_test(pTest, data != NULL);
|
||||
ct_test(pTest, strcmp(data, data1) == 0);
|
||||
|
||||
key = 3;
|
||||
data = Keylist_Data(list, key);
|
||||
ct_test(pTest, data != NULL);
|
||||
ct_test(pTest, strcmp(data, data3) == 0);
|
||||
|
||||
/* cleanup */
|
||||
do {
|
||||
data = Keylist_Data_Pop(list);
|
||||
} while (data);
|
||||
|
||||
Keylist_Delete(list);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void testKeyListDataIndex(Test *pTest)
|
||||
{
|
||||
OS_Keylist list;
|
||||
KEY key;
|
||||
int index;
|
||||
char *data1 = "Joshua";
|
||||
char *data2 = "Anna";
|
||||
char *data3 = "Mary";
|
||||
char *data;
|
||||
|
||||
list = Keylist_Create();
|
||||
ct_test(pTest, list != NULL);
|
||||
|
||||
key = 0;
|
||||
index = Keylist_Data_Add(list, key, data1);
|
||||
ct_test(pTest, index == 0);
|
||||
index = Keylist_Data_Add(list, key, data2);
|
||||
ct_test(pTest, index == 0);
|
||||
index = Keylist_Data_Add(list, key, data3);
|
||||
ct_test(pTest, index == 0);
|
||||
|
||||
ct_test(pTest, Keylist_Count(list) == 3);
|
||||
|
||||
/* look at the data */
|
||||
data = Keylist_Data_Index(list, 0);
|
||||
ct_test(pTest, data != NULL);
|
||||
ct_test(pTest, strcmp(data, data3) == 0);
|
||||
|
||||
data = Keylist_Data_Index(list, 1);
|
||||
ct_test(pTest, data != NULL);
|
||||
ct_test(pTest, strcmp(data, data2) == 0);
|
||||
|
||||
data = Keylist_Data_Index(list, 2);
|
||||
ct_test(pTest, data != NULL);
|
||||
ct_test(pTest, strcmp(data, data1) == 0);
|
||||
|
||||
/* work the data */
|
||||
data = Keylist_Data_Delete_By_Index(list, 1);
|
||||
ct_test(pTest, data != NULL);
|
||||
ct_test(pTest, strcmp(data, data2) == 0);
|
||||
|
||||
ct_test(pTest, Keylist_Count(list) == 2);
|
||||
|
||||
data = Keylist_Data_Index(list, 0);
|
||||
ct_test(pTest, data != NULL);
|
||||
ct_test(pTest, strcmp(data, data3) == 0);
|
||||
|
||||
data = Keylist_Data_Index(list, 1);
|
||||
ct_test(pTest, data != NULL);
|
||||
ct_test(pTest, strcmp(data, data1) == 0);
|
||||
|
||||
data = Keylist_Data_Delete_By_Index(list, 1);
|
||||
ct_test(pTest, data != NULL);
|
||||
ct_test(pTest, strcmp(data, data1) == 0);
|
||||
|
||||
data = Keylist_Data_Delete_By_Index(list, 1);
|
||||
ct_test(pTest, data == NULL);
|
||||
|
||||
/* cleanup */
|
||||
do {
|
||||
data = Keylist_Data_Pop(list);
|
||||
} while (data);
|
||||
|
||||
Keylist_Delete(list);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* test access of a lot of entries */
|
||||
static void testKeyListLarge(Test *pTest)
|
||||
{
|
||||
int data1 = 42;
|
||||
int *data;
|
||||
OS_Keylist list;
|
||||
KEY key;
|
||||
int index;
|
||||
const unsigned num_keys = 1024 * 16;
|
||||
|
||||
list = Keylist_Create();
|
||||
if (!list)
|
||||
return;
|
||||
|
||||
for (key = 0; key < num_keys; key++) {
|
||||
index = Keylist_Data_Add(list, key, &data1);
|
||||
}
|
||||
for (key = 0; key < num_keys; key++) {
|
||||
data = Keylist_Data(list, key);
|
||||
ct_test(pTest, *data == data1);
|
||||
}
|
||||
for (index = 0; index < num_keys; index++) {
|
||||
data = Keylist_Data_Index(list, index);
|
||||
ct_test(pTest, *data == data1);
|
||||
}
|
||||
Keylist_Delete(list);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* test access of a lot of entries */
|
||||
void testKeyList(Test *pTest)
|
||||
{
|
||||
bool rc;
|
||||
|
||||
/* individual tests */
|
||||
rc = ct_addTestFunction(pTest, testKeyListFIFO);
|
||||
assert(rc);
|
||||
rc = ct_addTestFunction(pTest, testKeyListFILO);
|
||||
assert(rc);
|
||||
rc = ct_addTestFunction(pTest, testKeyListDataKey);
|
||||
assert(rc);
|
||||
rc = ct_addTestFunction(pTest, testKeyListDataIndex);
|
||||
assert(rc);
|
||||
rc = ct_addTestFunction(pTest, testKeyListLarge);
|
||||
assert(rc);
|
||||
}
|
||||
|
||||
#ifdef TEST_KEYLIST
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
|
||||
pTest = ct_create("keylist", NULL);
|
||||
testKeyList(pTest);
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void)ct_report(pTest);
|
||||
|
||||
ct_destroy(pTest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_KEYLIST */
|
||||
#endif /* BAC_TEST */
|
||||
|
||||
@@ -121,13 +121,6 @@ extern "C" {
|
||||
int Keylist_Count(
|
||||
OS_Keylist list);
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include "ctest.h"
|
||||
BACNET_STACK_EXPORT
|
||||
void testKeyList(
|
||||
Test * pTest);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -454,370 +454,3 @@ bool Ringbuf_Init(RING_BUFFER *b,
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include "ctest.h"
|
||||
|
||||
/**
|
||||
* Unit Test for the ring buffer
|
||||
*
|
||||
* @param pTest - test tracking pointer
|
||||
* @param test_buffer - pointer to RING_BUFFER structure
|
||||
* @param data_element - one data element
|
||||
* @param element_size - size of one data element
|
||||
* @param element_count - number of data elements in the store
|
||||
*/
|
||||
static void testRingAroundBuffer(Test *pTest,
|
||||
RING_BUFFER *test_buffer,
|
||||
uint8_t *data_element,
|
||||
unsigned element_size,
|
||||
unsigned element_count)
|
||||
{
|
||||
volatile uint8_t *test_data;
|
||||
unsigned index;
|
||||
unsigned data_index;
|
||||
unsigned count;
|
||||
uint8_t value;
|
||||
bool status;
|
||||
|
||||
ct_test(pTest, Ringbuf_Empty(test_buffer));
|
||||
/* test the ring around the buffer */
|
||||
for (index = 0; index < element_count; index++) {
|
||||
for (count = 1; count < 4; count++) {
|
||||
value = (index * count) % 255;
|
||||
for (data_index = 0; data_index < element_size; data_index++) {
|
||||
data_element[data_index] = value;
|
||||
}
|
||||
status = Ringbuf_Put(test_buffer, data_element);
|
||||
ct_test(pTest, status == true);
|
||||
ct_test(pTest, Ringbuf_Count(test_buffer) == count);
|
||||
}
|
||||
for (count = 1; count < 4; count++) {
|
||||
value = (index * count) % 255;
|
||||
test_data = Ringbuf_Peek(test_buffer);
|
||||
ct_test(pTest, test_data);
|
||||
if (test_data) {
|
||||
for (data_index = 0; data_index < element_size; data_index++) {
|
||||
ct_test(pTest, test_data[data_index] == value);
|
||||
}
|
||||
}
|
||||
status = Ringbuf_Pop(test_buffer, NULL);
|
||||
ct_test(pTest, status == true);
|
||||
}
|
||||
}
|
||||
ct_test(pTest, Ringbuf_Empty(test_buffer));
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit Test for the ring buffer
|
||||
*
|
||||
* @param pTest - test tracking pointer
|
||||
* @param data_store - buffer to store elements
|
||||
* @param data_element - one data element
|
||||
* @param element_size - size of one data element
|
||||
* @param element_count - number of data elements in the store
|
||||
*/
|
||||
static bool testRingBuf(Test *pTest,
|
||||
uint8_t *data_store,
|
||||
uint8_t *data_element,
|
||||
unsigned element_size,
|
||||
unsigned element_count)
|
||||
{
|
||||
RING_BUFFER test_buffer;
|
||||
volatile uint8_t *test_data;
|
||||
unsigned index;
|
||||
unsigned data_index;
|
||||
bool status;
|
||||
|
||||
status =
|
||||
Ringbuf_Init(&test_buffer, data_store, element_size, element_count);
|
||||
if (!status) {
|
||||
return false;
|
||||
}
|
||||
ct_test(pTest, Ringbuf_Empty(&test_buffer));
|
||||
ct_test(pTest, Ringbuf_Depth(&test_buffer) == 0);
|
||||
|
||||
for (data_index = 0; data_index < element_size; data_index++) {
|
||||
data_element[data_index] = data_index;
|
||||
}
|
||||
status = Ringbuf_Put(&test_buffer, data_element);
|
||||
ct_test(pTest, status == true);
|
||||
ct_test(pTest, !Ringbuf_Empty(&test_buffer));
|
||||
ct_test(pTest, Ringbuf_Depth(&test_buffer) == 1);
|
||||
|
||||
test_data = Ringbuf_Peek(&test_buffer);
|
||||
for (data_index = 0; data_index < element_size; data_index++) {
|
||||
ct_test(pTest, test_data[data_index] == data_element[data_index]);
|
||||
}
|
||||
ct_test(pTest, !Ringbuf_Empty(&test_buffer));
|
||||
(void)Ringbuf_Pop(&test_buffer, NULL);
|
||||
ct_test(pTest, Ringbuf_Empty(&test_buffer));
|
||||
ct_test(pTest, Ringbuf_Depth(&test_buffer) == 1);
|
||||
|
||||
/* fill to max */
|
||||
for (index = 0; index < element_count; index++) {
|
||||
for (data_index = 0; data_index < element_size; data_index++) {
|
||||
data_element[data_index] = index;
|
||||
}
|
||||
status = Ringbuf_Put(&test_buffer, data_element);
|
||||
ct_test(pTest, status == true);
|
||||
ct_test(pTest, !Ringbuf_Empty(&test_buffer));
|
||||
ct_test(pTest, Ringbuf_Depth(&test_buffer) == (index + 1));
|
||||
}
|
||||
ct_test(pTest, Ringbuf_Depth(&test_buffer) == element_count);
|
||||
/* verify actions on full buffer */
|
||||
for (index = 0; index < element_count; index++) {
|
||||
for (data_index = 0; data_index < element_size; data_index++) {
|
||||
data_element[data_index] = index;
|
||||
}
|
||||
status = Ringbuf_Put(&test_buffer, data_element);
|
||||
ct_test(pTest, status == false);
|
||||
ct_test(pTest, !Ringbuf_Empty(&test_buffer));
|
||||
ct_test(pTest, Ringbuf_Depth(&test_buffer) == element_count);
|
||||
}
|
||||
|
||||
/* check buffer full */
|
||||
for (index = 0; index < element_count; index++) {
|
||||
test_data = Ringbuf_Peek(&test_buffer);
|
||||
ct_test(pTest, test_data);
|
||||
if (test_data) {
|
||||
for (data_index = 0; data_index < element_size; data_index++) {
|
||||
ct_test(pTest, test_data[data_index] == index);
|
||||
}
|
||||
}
|
||||
(void)Ringbuf_Pop(&test_buffer, NULL);
|
||||
}
|
||||
ct_test(pTest, Ringbuf_Empty(&test_buffer));
|
||||
ct_test(pTest, Ringbuf_Depth(&test_buffer) == element_count);
|
||||
Ringbuf_Depth_Reset(&test_buffer);
|
||||
ct_test(pTest, Ringbuf_Depth(&test_buffer) == 0);
|
||||
|
||||
testRingAroundBuffer(
|
||||
pTest, &test_buffer, data_element, element_size, element_count);
|
||||
|
||||
/* adjust the internal index of Ringbuf to test unsigned wrapping */
|
||||
test_buffer.head = UINT_MAX - 1;
|
||||
test_buffer.tail = UINT_MAX - 1;
|
||||
|
||||
testRingAroundBuffer(
|
||||
pTest, &test_buffer, data_element, element_size, element_count);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit Test for the ring buffer with 16 data elements
|
||||
*
|
||||
* @param pTest - test tracking pointer
|
||||
*/
|
||||
void testRingBufSizeSmall(Test *pTest)
|
||||
{
|
||||
bool status;
|
||||
uint8_t data_element[5];
|
||||
uint8_t data_store[sizeof(data_element) * NEXT_POWER_OF_2(16)];
|
||||
|
||||
status = testRingBuf(pTest, data_store, data_element, sizeof(data_element),
|
||||
sizeof(data_store) / sizeof(data_element));
|
||||
ct_test(pTest, status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit Test for the ring buffer with 32 data elements
|
||||
*
|
||||
* @param pTest - test tracking pointer
|
||||
*/
|
||||
void testRingBufSizeLarge(Test *pTest)
|
||||
{
|
||||
bool status;
|
||||
uint8_t data_element[16];
|
||||
uint8_t data_store[sizeof(data_element) * NEXT_POWER_OF_2(99)];
|
||||
|
||||
status = testRingBuf(pTest, data_store, data_element, sizeof(data_element),
|
||||
sizeof(data_store) / sizeof(data_element));
|
||||
ct_test(pTest, status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit Test for the ring buffer with 32 data elements
|
||||
*
|
||||
* @param pTest - test tracking pointer
|
||||
*/
|
||||
void testRingBufSizeInvalid(Test *pTest)
|
||||
{
|
||||
bool status;
|
||||
uint8_t data_element[16];
|
||||
uint8_t data_store[sizeof(data_element) * 99];
|
||||
|
||||
status = testRingBuf(pTest, data_store, data_element, sizeof(data_element),
|
||||
sizeof(data_store) / sizeof(data_element));
|
||||
ct_test(pTest, status == false);
|
||||
}
|
||||
|
||||
void testRingBufPowerOfTwo(Test *pTest)
|
||||
{
|
||||
ct_test(pTest, NEXT_POWER_OF_2(3) == 4);
|
||||
ct_test(pTest, NEXT_POWER_OF_2(100) == 128);
|
||||
ct_test(pTest, NEXT_POWER_OF_2(127) == 128);
|
||||
ct_test(pTest, NEXT_POWER_OF_2(128) == 128);
|
||||
ct_test(pTest, NEXT_POWER_OF_2(129) == 256);
|
||||
ct_test(pTest, NEXT_POWER_OF_2(300) == 512);
|
||||
ct_test(pTest, NEXT_POWER_OF_2(500) == 512);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit Test for the ring buffer peek/pop next element
|
||||
*
|
||||
* @param pTest - test tracking pointer
|
||||
* @param data_store - buffer to store elements
|
||||
* @param data_element - one data element
|
||||
* @param element_size - size of one data element
|
||||
* @param element_count - number of data elements in the store
|
||||
*/
|
||||
static bool testRingBufNextElement(Test *pTest,
|
||||
uint8_t *data_store,
|
||||
uint8_t *data_element,
|
||||
unsigned element_size,
|
||||
unsigned element_count)
|
||||
{
|
||||
RING_BUFFER test_buffer;
|
||||
volatile uint8_t *test_data;
|
||||
unsigned index;
|
||||
unsigned data_index;
|
||||
bool status;
|
||||
status =
|
||||
Ringbuf_Init(&test_buffer, data_store, element_size, element_count);
|
||||
if (!status) {
|
||||
return false;
|
||||
}
|
||||
ct_test(pTest, Ringbuf_Empty(&test_buffer));
|
||||
ct_test(pTest, Ringbuf_Depth(&test_buffer) == 0);
|
||||
|
||||
for (data_index = 0; data_index < element_size; data_index++) {
|
||||
data_element[data_index] = data_index;
|
||||
}
|
||||
status = Ringbuf_Put(&test_buffer, data_element);
|
||||
ct_test(pTest, status == true);
|
||||
ct_test(pTest, !Ringbuf_Empty(&test_buffer));
|
||||
ct_test(pTest, Ringbuf_Depth(&test_buffer) == 1);
|
||||
|
||||
test_data = Ringbuf_Peek(&test_buffer);
|
||||
for (data_index = 0; data_index < element_size; data_index++) {
|
||||
ct_test(pTest, test_data[data_index] == data_element[data_index]);
|
||||
}
|
||||
ct_test(pTest, !Ringbuf_Empty(&test_buffer));
|
||||
(void)Ringbuf_Pop(&test_buffer, NULL);
|
||||
ct_test(pTest, Ringbuf_Empty(&test_buffer));
|
||||
ct_test(pTest, Ringbuf_Depth(&test_buffer) == 1);
|
||||
|
||||
/* fill to max */
|
||||
for (index = 0; index < element_count; index++) {
|
||||
for (data_index = 0; data_index < element_size; data_index++) {
|
||||
data_element[data_index] = index;
|
||||
}
|
||||
status = Ringbuf_Put(&test_buffer, data_element);
|
||||
ct_test(pTest, status == true);
|
||||
ct_test(pTest, !Ringbuf_Empty(&test_buffer));
|
||||
ct_test(pTest, Ringbuf_Depth(&test_buffer) == (index + 1));
|
||||
}
|
||||
ct_test(pTest, Ringbuf_Depth(&test_buffer) == element_count);
|
||||
ct_test(pTest, Ringbuf_Count(&test_buffer) == element_count);
|
||||
|
||||
/* Walk through ring buffer */
|
||||
test_data = Ringbuf_Peek(&test_buffer);
|
||||
ct_test(pTest, test_data);
|
||||
for (index = 1; index < element_count; index++) {
|
||||
test_data = Ringbuf_Peek_Next(&test_buffer, (uint8_t *)test_data);
|
||||
ct_test(pTest, test_data);
|
||||
if (test_data) {
|
||||
for (data_index = 0; data_index < element_size; data_index++) {
|
||||
ct_test(pTest, test_data[data_index] == index);
|
||||
}
|
||||
}
|
||||
}
|
||||
ct_test(pTest, Ringbuf_Count(&test_buffer) == element_count);
|
||||
/* Try to walk off end of buffer - should return NULL */
|
||||
test_data = Ringbuf_Peek_Next(&test_buffer, (uint8_t *)test_data);
|
||||
ct_test(pTest, (test_data == NULL));
|
||||
|
||||
/* Walk through ring buffer and pop alternate elements */
|
||||
test_data = Ringbuf_Peek(&test_buffer);
|
||||
ct_test(pTest, test_data);
|
||||
for (index = 1; index < element_count / 2; index++) {
|
||||
test_data = Ringbuf_Peek_Next(&test_buffer, (uint8_t *)test_data);
|
||||
ct_test(pTest, test_data);
|
||||
(void)Ringbuf_Pop_Element(&test_buffer, (uint8_t *)test_data, NULL);
|
||||
test_data = Ringbuf_Peek_Next(&test_buffer, (uint8_t *)test_data);
|
||||
}
|
||||
ct_test(pTest, Ringbuf_Count(&test_buffer) == element_count / 2 + 1);
|
||||
|
||||
/* Walk through ring buffer and check data */
|
||||
test_data = Ringbuf_Peek(&test_buffer);
|
||||
ct_test(pTest, test_data);
|
||||
for (index = 0; index < element_count / 2; index++) {
|
||||
if (test_data) {
|
||||
for (data_index = 0; data_index < element_size; data_index++) {
|
||||
ct_test(pTest, test_data[data_index] == index * 2);
|
||||
}
|
||||
}
|
||||
test_data = Ringbuf_Peek_Next(&test_buffer, (uint8_t *)test_data);
|
||||
ct_test(pTest, test_data);
|
||||
}
|
||||
ct_test(pTest, Ringbuf_Count(&test_buffer) == element_count / 2 + 1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit Test for the ring buffer with 16 data elements
|
||||
*
|
||||
* @param pTest - test tracking pointer
|
||||
*/
|
||||
void testRingBufNextElementSizeSmall(Test *pTest)
|
||||
{
|
||||
bool status;
|
||||
uint8_t data_element[5];
|
||||
uint8_t data_store[sizeof(data_element) * NEXT_POWER_OF_2(16)];
|
||||
|
||||
status = testRingBufNextElement(pTest, data_store, data_element,
|
||||
sizeof(data_element), sizeof(data_store) / sizeof(data_element));
|
||||
ct_test(pTest, status);
|
||||
}
|
||||
|
||||
#ifdef TEST_RING_BUFFER
|
||||
/**
|
||||
* Main program entry for Unit Test
|
||||
*
|
||||
* @return returns 0 on success, and non-zero on fail.
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
|
||||
pTest = ct_create("Ring Buffer", NULL);
|
||||
|
||||
/* individual tests */
|
||||
rc = ct_addTestFunction(pTest, testRingBufPowerOfTwo);
|
||||
assert(rc);
|
||||
rc = ct_addTestFunction(pTest, testRingBufSizeSmall);
|
||||
assert(rc);
|
||||
rc = ct_addTestFunction(pTest, testRingBufSizeLarge);
|
||||
assert(rc);
|
||||
rc = ct_addTestFunction(pTest, testRingBufSizeInvalid);
|
||||
assert(rc);
|
||||
rc = ct_addTestFunction(pTest, testRingBufNextElementSizeSmall);
|
||||
assert(rc);
|
||||
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void)ct_report(pTest);
|
||||
|
||||
ct_destroy(pTest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -96,18 +96,6 @@ extern "C" {
|
||||
unsigned element_size,
|
||||
unsigned element_count);
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include "ctest.h"
|
||||
BACNET_STACK_EXPORT
|
||||
void testRingBufPowerOfTwo(Test * pTest);
|
||||
BACNET_STACK_EXPORT
|
||||
void testRingBufSizeSmall(Test * pTest);
|
||||
BACNET_STACK_EXPORT
|
||||
void testRingBufSizeLarge(Test * pTest);
|
||||
BACNET_STACK_EXPORT
|
||||
void testRingBufSizeInvalid(Test * pTest);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -129,84 +129,3 @@ bool sbuf_truncate(STATIC_BUFFER *b, /* static buffer structure */
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ctest.h"
|
||||
|
||||
void testStaticBuffer(Test *pTest)
|
||||
{
|
||||
STATIC_BUFFER sbuffer;
|
||||
char *data1 = "Joshua";
|
||||
char *data2 = "Anna";
|
||||
char *data3 = "Christopher";
|
||||
char *data4 = "Mary";
|
||||
char data_buffer[480] = "";
|
||||
char test_data_buffer[480] = "";
|
||||
char *data;
|
||||
unsigned count;
|
||||
|
||||
sbuf_init(&sbuffer, NULL, 0);
|
||||
ct_test(pTest, sbuf_empty(&sbuffer) == true);
|
||||
ct_test(pTest, sbuf_data(&sbuffer) == NULL);
|
||||
ct_test(pTest, sbuf_size(&sbuffer) == 0);
|
||||
ct_test(pTest, sbuf_count(&sbuffer) == 0);
|
||||
ct_test(pTest, sbuf_append(&sbuffer, data1, strlen(data1)) == false);
|
||||
|
||||
sbuf_init(&sbuffer, data_buffer, sizeof(data_buffer));
|
||||
ct_test(pTest, sbuf_empty(&sbuffer) == true);
|
||||
ct_test(pTest, sbuf_data(&sbuffer) == data_buffer);
|
||||
ct_test(pTest, sbuf_size(&sbuffer) == sizeof(data_buffer));
|
||||
ct_test(pTest, sbuf_count(&sbuffer) == 0);
|
||||
|
||||
ct_test(pTest, sbuf_append(&sbuffer, data1, strlen(data1)) == true);
|
||||
ct_test(pTest, sbuf_append(&sbuffer, data2, strlen(data2)) == true);
|
||||
ct_test(pTest, sbuf_append(&sbuffer, data3, strlen(data3)) == true);
|
||||
ct_test(pTest, sbuf_append(&sbuffer, data4, strlen(data4)) == true);
|
||||
strcat(test_data_buffer, data1);
|
||||
strcat(test_data_buffer, data2);
|
||||
strcat(test_data_buffer, data3);
|
||||
strcat(test_data_buffer, data4);
|
||||
ct_test(pTest, sbuf_count(&sbuffer) == strlen(test_data_buffer));
|
||||
|
||||
data = sbuf_data(&sbuffer);
|
||||
count = sbuf_count(&sbuffer);
|
||||
ct_test(pTest, memcmp(data, test_data_buffer, count) == 0);
|
||||
ct_test(pTest, count == strlen(test_data_buffer));
|
||||
|
||||
ct_test(pTest, sbuf_truncate(&sbuffer, 0) == true);
|
||||
ct_test(pTest, sbuf_count(&sbuffer) == 0);
|
||||
ct_test(pTest, sbuf_size(&sbuffer) == sizeof(data_buffer));
|
||||
ct_test(pTest, sbuf_append(&sbuffer, data4, strlen(data4)) == true);
|
||||
data = sbuf_data(&sbuffer);
|
||||
count = sbuf_count(&sbuffer);
|
||||
ct_test(pTest, memcmp(data, data4, count) == 0);
|
||||
ct_test(pTest, count == strlen(data4));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef TEST_STATIC_BUFFER
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
|
||||
pTest = ct_create("static buffer", NULL);
|
||||
|
||||
/* individual tests */
|
||||
rc = ct_addTestFunction(pTest, testStaticBuffer);
|
||||
assert(rc);
|
||||
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void)ct_report(pTest);
|
||||
|
||||
ct_destroy(pTest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_STATIC_BUFFER */
|
||||
#endif /* BAC_TEST */
|
||||
|
||||
@@ -414,59 +414,4 @@ bool tsm_invoke_id_failed(uint8_t invokeID)
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
/* flag to send an I-Am */
|
||||
bool I_Am_Request = true;
|
||||
|
||||
/* dummy function stubs */
|
||||
int datalink_send_pdu(BACNET_ADDRESS *dest,
|
||||
BACNET_NPDU_DATA *npdu_data,
|
||||
uint8_t *pdu,
|
||||
unsigned pdu_len)
|
||||
{
|
||||
(void)dest;
|
||||
(void)npdu_data;
|
||||
(void)pdu;
|
||||
(void)pdu_len;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* dummy function stubs */
|
||||
void datalink_get_broadcast_address(BACNET_ADDRESS *dest)
|
||||
{
|
||||
(void)dest;
|
||||
}
|
||||
|
||||
void testTSM(Test *pTest)
|
||||
{
|
||||
/* FIXME: add some unit testing... */
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef TEST_TSM
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
|
||||
pTest = ct_create("BACnet TSM", NULL);
|
||||
/* individual tests */
|
||||
rc = ct_addTestFunction(pTest, testTSM);
|
||||
assert(rc);
|
||||
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void)ct_report(pTest);
|
||||
ct_destroy(pTest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_TSM */
|
||||
#endif /* BAC_TEST */
|
||||
#endif /* MAX_TSM_TRANSACTIONS */
|
||||
#endif
|
||||
Reference in New Issue
Block a user