From e4689dd3f89255c29f4ab18d7aa1f962ff2b715b Mon Sep 17 00:00:00 2001 From: Dave Hickin Date: Mon, 13 Jul 2015 12:07:54 +0100 Subject: [PATCH] Added unit tests for functions for getting subfields Signed-off-by: Dave Hickin --- testApp/pv/testPVData.cpp | 47 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/testApp/pv/testPVData.cpp b/testApp/pv/testPVData.cpp index 327a9c2..12b4092 100644 --- a/testApp/pv/testPVData.cpp +++ b/testApp/pv/testPVData.cpp @@ -573,6 +573,19 @@ static void testFieldAccess() // whitespace testOk1(fld->getSubField(" test").get()==NULL); + // intermediate field not structure + testOk1(fld->getSubField("hello.world.invalid").get()==NULL); + + // null string + try{ + char * name = NULL; + fld->getAs(name); + testFail("missing required exception"); + }catch(std::invalid_argument& e){ + testPass("caught expected exception: %s", e.what()); + } + + // non-existent try{ fld->getAs("invalid"); testFail("missing required exception"); @@ -580,6 +593,7 @@ static void testFieldAccess() testPass("caught expected exception: %s", e.what()); } + // wrong type try{ fld->getAs("test"); testFail("missing required exception"); @@ -587,6 +601,37 @@ static void testFieldAccess() testPass("caught expected exception: %s", e.what()); } + // empty leaf field name + try{ + fld->getAs("hello."); + testFail("missing required exception"); + }catch(std::runtime_error& e){ + testPass("caught expected exception: %s", e.what()); + } + + // empty field name + try{ + fld->getAs("hello..world"); + testFail("missing required exception"); + }catch(std::runtime_error& e){ + testPass("caught expected exception: %s", e.what()); + } + try{ + fld->getAs("."); + testFail("missing required exception"); + }catch(std::runtime_error& e){ + testPass("caught expected exception: %s", e.what()); + } + + // whitespace + try{ + fld->getAs(" test"); + testFail("missing required exception"); + }catch(std::runtime_error& e){ + testPass("caught expected exception: %s", e.what()); + } + + // intermediate field not structure try{ fld->getAs("hello.world.invalid"); testFail("missing required exception"); @@ -597,7 +642,7 @@ static void testFieldAccess() MAIN(testPVData) { - testPlan(236); + testPlan(242); fieldCreate = getFieldCreate(); pvDataCreate = getPVDataCreate(); standardField = getStandardField();