dbPutLinkTest: test link string parsing

Test parsing to CONTANT and DB_LINK.
dbCa isn't initialized, so no test for CA_LINK.
This commit is contained in:
Michael Davidsaver
2014-07-11 16:51:32 -04:00
parent f14bfaab24
commit fd7a934ce3
5 changed files with 122 additions and 0 deletions
+6
View File
@@ -30,6 +30,12 @@ dbShutdownTest_SRCS += dbTestIoc_registerRecordDeviceDriver.cpp
testHarness_SRCS += dbShutdownTest.c
TESTS += dbShutdownTest
TESTPROD_HOST += dbPutLinkTest
dbPutLinkTest_SRCS += dbPutLinkTest.c
dbPutLinkTest_SRCS += dbTestIoc_registerRecordDeviceDriver.cpp
testHarness_SRCS += dbPutLinkTest.c
TESTS += dbPutLinkTest
TESTPROD_HOST += callbackTest
callbackTest_SRCS += callbackTest.c
testHarness_SRCS += callbackTest.c
+107
View File
@@ -0,0 +1,107 @@
/*************************************************************************\
* Copyright (c) 2014 Brookhaven Science Assoc. as operator of Brookhaven
* National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Author: Michael Davidsaver <mdavidsaver@bnl.gov>
*/
#include "string.h"
#include "epicsString.h"
#include "dbUnitTest.h"
#include "epicsThread.h"
#include "iocInit.h"
#include "dbBase.h"
#include "link.h"
#include "dbAccess.h"
#include "registry.h"
#include "dbStaticLib.h"
#include "osiFileName.h"
#include "dbmf.h"
#include "xRecord.h"
#include "testMain.h"
void dbTestIoc_registerRecordDeviceDriver(struct dbBase *);
static const struct testDataT {
const char *linkstring;
short linkType;
unsigned int pvlMask;
const char *linkback;
} testSetData[] = {
{"", CONSTANT, 0},
{"0", CONSTANT, 0},
{"42", CONSTANT, 0},
{"x1", DB_LINK, 0, "x1 NPP NMS"},
{"x1.VAL", DB_LINK, 0, "x1.VAL NPP NMS"},
{"x1.TIME", DB_LINK, 0, "x1.TIME NPP NMS"},
{"x1 PP", DB_LINK, pvlOptPP, "x1 PP NMS"},
{"x1 PP MSS", DB_LINK, pvlOptPP|pvlOptMSS, "x1 PP MSS"},
{"x1 PPMSS", DB_LINK, pvlOptPP|pvlOptMSS, "x1 PP MSS"},
{"x1 PPMSI", DB_LINK, pvlOptPP|pvlOptMSI, "x1 PP MSI"},
/*TODO: testing doesn't support CA_LINK yet */
{NULL}
};
static void testSet(void)
{
const struct testDataT *td = testSetData;
xRecord *prec;
DBLINK *plink;
testdbPrepare();
testdbReadDatabase("dbTestIoc.dbd", NULL, NULL);
dbTestIoc_registerRecordDeviceDriver(pdbbase);
testdbReadDatabase("dbPutLinkTest.db", NULL, NULL);
testIocInitOk();
prec = (xRecord*)testdbRecordPtr("x1");
plink = &prec->lnk;
for(;td->linkstring;td++) {
testdbPutFieldOk("x1.LNK", DBF_STRING, td->linkstring);
if(td->linkback)
testdbGetFieldEqual("x1.LNK", DBF_STRING, td->linkback);
else
testdbGetFieldEqual("x1.LNK", DBF_STRING, td->linkstring);
testOk1(plink->type==td->linkType);
if(plink->type==td->linkType) {
switch(td->linkType) {
case CONSTANT:
if(plink->value.constantStr)
testOk1(strcmp(plink->value.constantStr,td->linkstring)==0);
else if(td->linkstring[0]=='\0')
testPass("Empty String");
else
testFail("oops");
break;
case DB_LINK:
testOk1(plink->value.pv_link.pvlMask==td->pvlMask);
break;
}
}
}
testIocShutdownOk();
testdbCleanup();
}
MAIN(dbPutLinkTest)
{
testPlan(0);
testSet();
return testDone();
}
+4
View File
@@ -0,0 +1,4 @@
record(x, "x1") {}
record(x, "x2") {}
record(x, "x3") {}
record(x, "x4") {}
+2
View File
@@ -19,6 +19,7 @@
int callbackTest(void);
int dbStateTest(void);
int dbShutdownTest(void);
int dbPutLinkTest(void);
int testDbChannel(void);
int chfPluginTest(void);
int arrShorthandTest(void);
@@ -30,6 +31,7 @@ void epicsRunDbTests(void)
runTest(callbackTest);
runTest(dbStateTest);
runTest(dbShutdownTest);
runTest(dbPutLinkTest);
runTest(testDbChannel);
runTest(arrShorthandTest);
runTest(chfPluginTest);
+3
View File
@@ -5,4 +5,7 @@ recordtype(x) {
field(VAL, DBF_LONG) {
prompt("Value")
}
field(LNK, DBF_INLINK) {
prompt("Link")
}
}