dbStatic: dbPutStringNum(, "") not an error
Restore previous behavour that empty string is equivalent to numeric zero. epicsParse*() returns S_stdlib_noConversion where previously strtoul() did not. Conflicts: src/ioc/db/test/Makefile
This commit is contained in:
committed by
Andrew Johnson
parent
d33c402b00
commit
0821c8c4ff
@@ -152,7 +152,13 @@ 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
|
||||
TESTS += testPutGetTest
|
||||
|
||||
# This runs all the test programs in a known working order:
|
||||
testHarness_SRCS += epicsRunDbTests.c
|
||||
|
||||
dbTestHarness_SRCS += $(testHarness_SRCS)
|
||||
|
||||
69
src/ioc/db/test/dbPutGetTest.c
Normal file
69
src/ioc/db/test/dbPutGetTest.c
Normal file
@@ -0,0 +1,69 @@
|
||||
|
||||
#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");
|
||||
}
|
||||
|
||||
void dbTestIoc_registerRecordDeviceDriver(struct dbBase *);
|
||||
|
||||
MAIN(dbPutGet)
|
||||
{
|
||||
testPlan(0);
|
||||
testdbPrepare();
|
||||
|
||||
testdbReadDatabase("dbTestIoc.dbd", NULL, NULL);
|
||||
dbTestIoc_registerRecordDeviceDriver(pdbbase);
|
||||
testdbReadDatabase("dbPutGetTest.db", NULL, NULL);
|
||||
|
||||
testGetString();
|
||||
|
||||
testdbCleanup();
|
||||
|
||||
return testDone();
|
||||
}
|
||||
31
src/ioc/db/test/dbPutGetTest.db
Normal file
31
src/ioc/db/test/dbPutGetTest.db
Normal file
@@ -0,0 +1,31 @@
|
||||
|
||||
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, "")
|
||||
}
|
||||
@@ -376,6 +376,10 @@ long dbPutStringNum(DBENTRY *pdbentry, const char *pstring)
|
||||
if (!pfield)
|
||||
return S_dbLib_fieldNotFound;
|
||||
|
||||
/* empty string is the same as writing numeric zero */
|
||||
if(pstring[0]=='\0')
|
||||
pstring = "0";
|
||||
|
||||
switch (pflddes->field_type) {
|
||||
case DBF_CHAR:
|
||||
return epicsParseInt8(pstring, pfield, 0, NULL);
|
||||
|
||||
Reference in New Issue
Block a user