client Add NTURI version of rpc()

and consolidate with similar code for building
pvRequest _options and put() builder.
This commit is contained in:
Michael Davidsaver
2020-03-12 19:49:31 -07:00
parent 6117de2991
commit ad609e420c
6 changed files with 262 additions and 114 deletions
+78 -4
View File
@@ -14,20 +14,38 @@
#include <pvxs/unittest.h>
#include <pvxs/log.h>
#include <pvxs/sharedArray.h>
#include <pvxs/client.h>
#include <pvxs/nt.h>
#include "utilpvt.h"
namespace {
using namespace pvxs;
struct TestBuilder : client::detail::CommonBuilder<TestBuilder>
struct TestBuilder : client::detail::CommonBuilder<TestBuilder, client::detail::PRBase>
{
TestBuilder()
:client::detail::CommonBuilder<TestBuilder>(nullptr, "")
:client::detail::CommonBuilder<TestBuilder, client::detail::PRBase>(nullptr, "")
{}
Value makeReq() const {
return _build();
return _buildReq();
}
template<typename T>
TestBuilder& set(const std::string& name, const T& val, bool required=true) {
typedef impl::StorageMap<typename std::decay<T>::type> map_t;
typename map_t::store_t norm(val);
_set(name, &norm, map_t::code, required);
return *this;
}
Value builder(Value&& prototype) {
return _builder(std::move(prototype));
}
Value uriArgs() {
return _uriArgs();
}
};
@@ -189,11 +207,65 @@ void testError()
}
}
void testBuilder()
{
testShow()<<__func__;
auto builder = TestBuilder()
.set("value", "14")
.set("alarm.severity", 3)
.set("alarm", 42, false)
.set("nonexistant", 42, false);
auto built = builder.builder(nt::NTScalar{TypeCode::UInt32}.create());
testEq(built["value"].as<uint32_t>(), 14u);
testEq(built["alarm.severity"].as<uint32_t>(), 3u);
}
void testArgs()
{
using namespace pvxs::members;
testShow()<<__func__;
shared_array<int32_t> 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<const void>())
.set("d", sub)
.uriArgs();
testEq(std::string(SB()<<"\n"<<args), R"out(
struct "epics:nt/NTURI:1.0" {
string scheme = ""
string authority = ""
string path = ""
struct {
string a = "14"
int64_t b = 3
int32_t[] c = {3}[1, 2, 3]
struct {
int32_t ival = 123
} d
} query
}
)out")<<"\n"<<args;
}
} // namespace
MAIN(testpvreq)
{
testPlan(22);
testPlan(25);
logger_config_env();
testEmpty();
testAssemble();
@@ -201,6 +273,8 @@ MAIN(testpvreq)
testParse2();
testValid();
testError();
testBuilder();
testArgs();
cleanup_for_valgrind();
return testDone();
}