/** * Copyright - See the COPYRIGHT that is included with this distribution. * pvxs is distributed subject to a Software License Agreement found * in file LICENSE that is included with this distribution. */ #include #include #include #include #include #include #include #include #include #include "dataimpl.h" #include "pvrequest.h" namespace { using namespace pvxs; void testPvRequest() { namespace M = members; testDiag("%s", __func__); auto def = nt::NTScalar{TypeCode::String}.build(); auto val = def.create(); testShow()< { TestBuilder() :client::detail::CommonBuilder(nullptr, "") {} template TestBuilder& set(const std::string& name, const T& val, bool required=true) { const typename impl::StoreAs::store_t& norm(impl::StoreTransform::in(val)); _set(name, &norm, impl::StoreAs::code, required); return *this; } Value builder(Value&& prototype) { return _builder(std::move(prototype)); } Value uriArgs() { return _uriArgs(); } }; void testEmpty() { testShow()<<__func__; auto req = client::Context::request().build(); testShow()< valid({ "field()", "field(a,b,a.b)field(x)", "a", // short-hand "field(a,b,a.b)field(x)", // should these be valid? "field(,)", "field(foo,)", "record[foo=bar,]", }); for(auto& pvr : valid) { try { testCase(true)< errors({ "field(", "field(value", "field(value,alarm", "field[]", "record()", "field(!@#)", "record[", "record[key", "record[key=", "record[key=]", "record[,]", }); for(auto& pvr : errors) { testThrows([&pvr](){ auto req = client::Context::request() .pvRequest(pvr) .build(); testShow()<(), 14u); testEq(built["alarm.severity"].as(), 3u); } void testArgs() { using namespace pvxs::members; testShow()<<__func__; shared_array iarr({1,2,3}); auto sub = TypeDef(TypeCode::Struct, { Int32("ival") }).create(); sub["ival"] = 123; auto args = TestBuilder() .set("a", "14") .set("b", 3) .set("c", iarr.freeze().castTo()) .set("d", sub) .uriArgs(); testStrEq(std::string(SB()<