From fd7a934ce359077e8d837fbaf17789d68b233e92 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Fri, 11 Jul 2014 16:51:32 -0400 Subject: [PATCH] dbPutLinkTest: test link string parsing Test parsing to CONTANT and DB_LINK. dbCa isn't initialized, so no test for CA_LINK. --- src/ioc/db/test/Makefile | 6 ++ src/ioc/db/test/dbPutLinkTest.c | 107 ++++++++++++++++++++++++++++++ src/ioc/db/test/dbPutLinkTest.db | 4 ++ src/ioc/db/test/epicsRunDbTests.c | 2 + src/ioc/db/test/xRecord.dbd | 3 + 5 files changed, 122 insertions(+) create mode 100644 src/ioc/db/test/dbPutLinkTest.c create mode 100644 src/ioc/db/test/dbPutLinkTest.db diff --git a/src/ioc/db/test/Makefile b/src/ioc/db/test/Makefile index 4f1bc973b..88e0c105f 100644 --- a/src/ioc/db/test/Makefile +++ b/src/ioc/db/test/Makefile @@ -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 diff --git a/src/ioc/db/test/dbPutLinkTest.c b/src/ioc/db/test/dbPutLinkTest.c new file mode 100644 index 000000000..cab27c637 --- /dev/null +++ b/src/ioc/db/test/dbPutLinkTest.c @@ -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 + */ + +#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(); +} diff --git a/src/ioc/db/test/dbPutLinkTest.db b/src/ioc/db/test/dbPutLinkTest.db new file mode 100644 index 000000000..940ea2e7f --- /dev/null +++ b/src/ioc/db/test/dbPutLinkTest.db @@ -0,0 +1,4 @@ +record(x, "x1") {} +record(x, "x2") {} +record(x, "x3") {} +record(x, "x4") {} diff --git a/src/ioc/db/test/epicsRunDbTests.c b/src/ioc/db/test/epicsRunDbTests.c index ef759d9d7..d13ae545f 100644 --- a/src/ioc/db/test/epicsRunDbTests.c +++ b/src/ioc/db/test/epicsRunDbTests.c @@ -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); diff --git a/src/ioc/db/test/xRecord.dbd b/src/ioc/db/test/xRecord.dbd index 77e67147a..8f4b2156c 100644 --- a/src/ioc/db/test/xRecord.dbd +++ b/src/ioc/db/test/xRecord.dbd @@ -5,4 +5,7 @@ recordtype(x) { field(VAL, DBF_LONG) { prompt("Value") } + field(LNK, DBF_INLINK) { + prompt("Link") + } }