dbUnitTest: replace testdbPutField()

add testdbPutFieldOk() and testdbPutFieldFail()
which include calls to testPass() or testFail()

Leave testdbVPutField() as a building block.
This commit is contained in:
Michael Davidsaver
2014-07-11 10:30:31 -04:00
parent ebc3834661
commit 3f11fd1665
2 changed files with 42 additions and 12 deletions

View File

@@ -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;

View File

@@ -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);