From 3f11fd16658ad97a26eb3cf680971ac4bccc06ab Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Fri, 11 Jul 2014 10:30:31 -0400 Subject: [PATCH] dbUnitTest: replace testdbPutField() add testdbPutFieldOk() and testdbPutFieldFail() which include calls to testPass() or testFail() Leave testdbVPutField() as a building block. --- src/ioc/db/dbUnitTest.c | 41 +++++++++++++++++++++++++++++++---------- src/ioc/db/dbUnitTest.h | 13 +++++++++++-- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/src/ioc/db/dbUnitTest.c b/src/ioc/db/dbUnitTest.c index 2965c436b..432cac852 100644 --- a/src/ioc/db/dbUnitTest.c +++ b/src/ioc/db/dbUnitTest.c @@ -63,16 +63,6 @@ void testdbCleanup(void) dbmfFreeChunks(); } -long testdbPutField(const char* pv, short dbrType, ...) -{ - long ret; - va_list ap; - va_start(ap, dbrType); - ret = testdbVPutField(pv, dbrType, ap); - va_end(ap); - return ret; -} - union anybuf { epicsAny val; char bytes[sizeof(epicsAny)]; @@ -95,6 +85,10 @@ long testdbVPutField(const char* pv, short dbrType, va_list ap) return dbPutField(&addr, dbrType, buffer, 1); } + /* The Type parameter takes into consideration + * the C language rules for promotion of argument types + * in variadic functions. + */ #define OP(DBR,Type,mem) case DBR: {pod.val.mem = va_arg(ap,Type); break;} OP(DBR_CHAR, int, int8); OP(DBR_UCHAR, int, uInt8); @@ -114,6 +108,33 @@ long testdbVPutField(const char* pv, short dbrType, va_list ap) return dbPutField(&addr, dbrType, pod.bytes, 1); } +void testdbPutFieldOk(const char* pv, short dbrType, ...) +{ + long ret; + va_list ap; + + va_start(ap, dbrType); + ret = testdbVPutField(pv, dbrType, ap); + va_end(ap); + + testOk(ret==0, "dbPutField(%s, %d, ...) == %ld", pv, dbrType, ret); +} + +void testdbPutFieldFail(long status, const char* pv, short dbrType, ...) +{ + long ret; + va_list ap; + + va_start(ap, dbrType); + ret = testdbVPutField(pv, dbrType, ap); + va_end(ap); + + if(ret==status) + testPass("dbPutField(%s, %d, ...) == %ld", pv, dbrType, status); + else + testFail("dbPutField(%s, %d, ...) != %ld (%ld)", pv, dbrType, status, ret); +} + dbCommon* testdbRecordPtr(const char* pv) { DBADDR addr; diff --git a/src/ioc/db/dbUnitTest.h b/src/ioc/db/dbUnitTest.h index eccdd8a14..e4a76ec2e 100644 --- a/src/ioc/db/dbUnitTest.h +++ b/src/ioc/db/dbUnitTest.h @@ -35,14 +35,23 @@ epicsShareFunc void testdbCleanup(void); /* Scalar only version. * - * Remember to use the correct argument types! + * Correct argument types must be used with this var-arg function! + * Doing otherwise will result in corruption of argument values! * * int for DBR_UCHAR, DBR_CHAR, DBR_USHORT, DBR_SHORT, DBR_LONG * unsigned int for DBR_ULONG * double for DBR_FLOAT and DBR_DOUBLE * const char* for DBR_STRING + * + * eg. + * testdbPutFieldOk("pvname", DBF_ULONG, (unsigned int)5); + * testdbPutFieldOk("pvname", DBF_FLOAT, (double)4.1); + * testdbPutFieldOk("pvname", DBF_STRING, "hello world"); */ -epicsShareFunc long testdbPutField(const char* pv, short dbrType, ...); +epicsShareFunc void testdbPutFieldOk(const char* pv, short dbrType, ...); +/* the inverse of testdbPutFieldOk(). Tests for put failure */ +epicsShareFunc void testdbPutFieldFail(long status, const char* pv, short dbrType, ...); + epicsShareFunc long testdbVPutField(const char* pv, short dbrType, va_list ap); epicsShareFunc dbCommon* testdbRecordPtr(const char* pv);