db/test: add dbPutGetTest
This commit is contained in:
@@ -131,7 +131,14 @@ recGblCheckDeadbandTest_SRCS += dbTestIoc_registerRecordDeviceDriver.cpp
|
||||
testHarness_SRCS += recGblCheckDeadbandTest.c
|
||||
TESTS += recGblCheckDeadbandTest
|
||||
|
||||
# The testHarness runs all the test programs in a known working order.
|
||||
TESTPROD_HOST += testPutGetTest
|
||||
testPutGetTest_SRCS += dbPutGetTest.c
|
||||
testPutGetTest_SRCS += dbTestIoc_registerRecordDeviceDriver.cpp
|
||||
testHarness_SRCS += dbPutGetTest.db
|
||||
TESTFILES += ../dbPutGetTest.db
|
||||
TESTS += testPutGetTest
|
||||
|
||||
# This runs all the test programs in a known working order:
|
||||
testHarness_SRCS += epicsRunDbTests.c
|
||||
|
||||
dbTestHarness_SRCS += $(testHarness_SRCS)
|
||||
|
||||
79
src/ioc/db/test/dbPutGetTest.c
Normal file
79
src/ioc/db/test/dbPutGetTest.c
Normal file
@@ -0,0 +1,79 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <dbAccess.h>
|
||||
#include <dbStaticLib.h>
|
||||
#include <dbStaticPvt.h>
|
||||
#include <dbUnitTest.h>
|
||||
#include <testMain.h>
|
||||
|
||||
static
|
||||
void testdbGetStringEqual(const char *pv, const char *expected)
|
||||
{
|
||||
const char *actual;
|
||||
int ok;
|
||||
DBENTRY ent;
|
||||
|
||||
dbInitEntry(pdbbase, &ent);
|
||||
|
||||
if(dbFindRecord(&ent, pv)) {
|
||||
testFail("Failed to find record '%s'", pv);
|
||||
return;
|
||||
}
|
||||
|
||||
actual = dbGetString(&ent);
|
||||
ok = (!actual && !expected)
|
||||
|| (actual && expected && strcmp(actual, expected)==0);
|
||||
|
||||
testOk(ok, "dbGetString(\"%s\") -> \"%s\" == \"%s\"", pv, actual, expected);
|
||||
|
||||
dbFinishEntry(&ent);
|
||||
}
|
||||
|
||||
static
|
||||
void testGetString(void)
|
||||
{
|
||||
testDiag("testGetString()");
|
||||
|
||||
testdbGetStringEqual("recempty.DTYP", "Soft Channel");
|
||||
testdbGetStringEqual("recempty.DESC", "");
|
||||
testdbGetStringEqual("recempty.PHAS", "0");
|
||||
testdbGetStringEqual("recempty.TSE" , "0");
|
||||
testdbGetStringEqual("recempty.DISA", "0");
|
||||
testdbGetStringEqual("recempty.DISV", "0");
|
||||
|
||||
testdbGetStringEqual("recoverwrite.DTYP", "Soft Channel");
|
||||
testdbGetStringEqual("recoverwrite.DESC", "");
|
||||
testdbGetStringEqual("recoverwrite.PHAS", "0");
|
||||
testdbGetStringEqual("recoverwrite.TSE" , "0");
|
||||
testdbGetStringEqual("recoverwrite.DISA", "0");
|
||||
testdbGetStringEqual("recoverwrite.DISV", "0");
|
||||
}
|
||||
|
||||
static
|
||||
void testStringMax(void)
|
||||
{
|
||||
testDiag("testStringMax()");
|
||||
|
||||
testdbGetStringEqual("recmax.DISA", "-1");
|
||||
}
|
||||
|
||||
void dbTestIoc_registerRecordDeviceDriver(struct dbBase *);
|
||||
|
||||
MAIN(dbPutGet)
|
||||
{
|
||||
testPlan(13);
|
||||
testdbPrepare();
|
||||
|
||||
testdbReadDatabase("dbTestIoc.dbd", NULL, NULL);
|
||||
dbTestIoc_registerRecordDeviceDriver(pdbbase);
|
||||
testdbReadDatabase("dbPutGetTest.db", NULL, NULL);
|
||||
|
||||
testGetString();
|
||||
|
||||
testStringMax();
|
||||
|
||||
testdbCleanup();
|
||||
|
||||
return testDone();
|
||||
}
|
||||
35
src/ioc/db/test/dbPutGetTest.db
Normal file
35
src/ioc/db/test/dbPutGetTest.db
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
record(x, "recempty") {
|
||||
# empty string is the same "0" for numeric fields
|
||||
field(DTYP, "")
|
||||
field(DESC, "")
|
||||
field(PHAS, "")
|
||||
field(TSE , "")
|
||||
field(DISA, "")
|
||||
field(DISV, "")
|
||||
}
|
||||
|
||||
record(x, "recoverwrite") {
|
||||
# first with non-default values
|
||||
# field(DTYP, "Scan I/O")
|
||||
field(DESC, "hello")
|
||||
field(PHAS, "2")
|
||||
field(TSE , "5")
|
||||
field(DISA, "6")
|
||||
field(DISV, "7")
|
||||
}
|
||||
|
||||
record(x, "recoverwrite") {
|
||||
# now restore default values
|
||||
field(DTYP, "")
|
||||
field(DESC, "")
|
||||
field(PHAS, "")
|
||||
field(TSE , "")
|
||||
field(TSEL, "")
|
||||
field(DISA, "")
|
||||
field(DISV, "")
|
||||
}
|
||||
|
||||
record(x, "recmax") {
|
||||
field(DISA, "0xffffffff")
|
||||
}
|
||||
Reference in New Issue
Block a user