From c159b9da1e3cf0563cc300f0adb4e62045273420 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Tue, 5 Jan 2021 10:42:31 -0800 Subject: [PATCH] test request2mask() w/ non-existant fields --- src/pvrequest.cpp | 2 +- test/testpvreq.cpp | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/pvrequest.cpp b/src/pvrequest.cpp index decee8f..ff256c7 100644 --- a/src/pvrequest.cpp +++ b/src/pvrequest.cpp @@ -59,7 +59,7 @@ BitMask request2mask(const FieldDesc* desc, const Value& pvRequest) } if(!foundrequested) - throw std::runtime_error("pvRequest selects no fields"); + throw std::runtime_error("Empty field selection"); if(ret.findSet(1)==ret.size()) { // empty mask is wildcard diff --git a/test/testpvreq.cpp b/test/testpvreq.cpp index 57c4cec..0672ba9 100644 --- a/test/testpvreq.cpp +++ b/test/testpvreq.cpp @@ -69,6 +69,34 @@ void testPvRequest() testEq(mask, BitMask({0, 2, 4, 6, 7, 8, 9}, 10u)); } + + { + auto rdef = TypeDef(TypeCode::Struct, { + M::Struct("field", { + M::Struct("timeStamp", {}), + M::Struct("nonexistant", {}), + M::Struct("alarm", { + M::Struct("status", {}), + }), + }) + }); + + auto mask = request2mask(Value::Helper::desc(val), rdef.create()); + + testEq(mask, BitMask({0, 2, 4, 6, 7, 8, 9}, 10u))<<" include including non-existant"; + } + + { + auto rdef = TypeDef(TypeCode::Struct, { + M::Struct("field", { + M::Struct("nonexistant", {}), + }) + }); + + testThrows([&val, &rdef](){ + (void)request2mask(Value::Helper::desc(val), rdef.create()); + })<<" empty mask"; + } } void testPvMask() @@ -379,7 +407,7 @@ void testArgs() MAIN(testpvreq) { - testPlan(36); + testPlan(38); testSetup(); logger_config_env(); testPvRequest();