From 8edefb9d6330a25f19db6b78249e87fe6f985748 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Thu, 6 Apr 2017 20:27:03 -0400 Subject: [PATCH] dbUnitTest: add testdbGetArrFieldEqual() --- src/ioc/db/dbUnitTest.c | 65 +++++++++++++++++++++++++++++++++++++++++ src/ioc/db/dbUnitTest.h | 17 +++++++++++ 2 files changed, 82 insertions(+) diff --git a/src/ioc/db/dbUnitTest.c b/src/ioc/db/dbUnitTest.c index 48d92a7fd..374a3eb51 100644 --- a/src/ioc/db/dbUnitTest.c +++ b/src/ioc/db/dbUnitTest.c @@ -190,6 +190,71 @@ void testdbVGetFieldEqual(const char* pv, short dbrType, va_list ap) } } +void testdbGetArrFieldEqual(const char* pv, short dbfType, long nRequest, unsigned long cnt, const void *pbuf) +{ + DBADDR addr; + const long vSize = dbValueSize(dbfType); + const long nStore = vSize * nRequest; + long status; + void *gbuf, *gstore; + + if(dbNameToAddr(pv, &addr)) { + testFail("Missing PV \"%s\"", pv); + return; + } + + gbuf = gstore = malloc(nStore); + if(!gbuf && nStore!=0) { /* note that malloc(0) is allowed to return NULL on success */ + testFail("Allocation failed esize=%ld total=%ld", vSize, nStore); + return; + } + + status = dbGetField(&addr, dbfType, gbuf, NULL, &nRequest, NULL); + if (status) { + testFail("dbGetField(\"%s\", %d, ...) -> %#lx", pv, dbfType, status); + + } else { + unsigned match = nRequest==cnt; + long n, N = nRequest < cnt ? nRequest : cnt; + + if(!match) + testDiag("Length mis-match. expected=%lu actual=%lu", cnt, nRequest); + + for(n=0; n pbufcnt will detect truncation. + * nRequest < pbufcnt always fails. + * nRequest ==pbufcnt checks prefix (actual may be longer than expected) + */ +epicsShareFunc void testdbGetArrFieldEqual(const char* pv, short dbfType, long nRequest, unsigned long pbufcnt, const void *pbuf); + epicsShareFunc dbCommon* testdbRecordPtr(const char* pv); #ifdef __cplusplus