/** * 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 "utilpvt.h" namespace { using namespace pvxs; struct TestBuilder : client::detail::CommonBuilder { TestBuilder() :client::detail::CommonBuilder(nullptr, "") {} Value makeReq() const { return _buildReq(); } 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 = TestBuilder().makeReq(); 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 = TestBuilder() .pvRequest(pvr) .makeReq(); 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()<