/** * 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 "utilpvt.h" #include "pvaproto.h" #include "dataimpl.h" #include "pvrequest.h" using namespace pvxs; namespace { void testTraverse() { testDiag("%s", __func__); auto top = nt::NTScalar{TypeCode::Int32, true}.create(); testOk1(!top["<"].valid()); { auto top2 = top["value<"]; testOk1(top.compareType(top2)); testOk1(top.compareInst(top2)); } { auto sevr1 = top["alarm.severity"]; auto sevr2 = top["value([&val]() { val.nameOf(val); }); } void testIter() { testDiag("%s", __func__); auto def = nt::NTScalar{TypeCode::String}.build(); auto val = def.create(); unsigned i=0; for(auto fld : val.iall()) { testDiag("field %s", val.nameOf(fld).c_str()); i++; } testEq(i, 9u)<<"# of decendent fields"; i=0; for(auto fld : val.ichildren()) { testDiag("field %s", val.nameOf(fld).c_str()); i++; } testEq(i, 3u)<<"# of child fields"; auto testMarked = [&val](unsigned expect) -> testCase { unsigned i=0; for(auto fld : val.imarked()) { testDiag("field %s", val.nameOf(fld).c_str()); i++; } return testEq(i, expect); }; testMarked(0u)<<"no decendent fields"; val["alarm.status"].mark(); testMarked(1u)<<"mark one field"; val.unmark(); val["alarm"].mark(); testMarked(4u)<<"mark sub-struct"; val.unmark(); val["value"].mark(); val["alarm.status"].mark(); val["timeStamp"].mark(); testMarked(6u)<<"mark sub-struct"; } void testPvRequest() { namespace M = members; testDiag("%s", __func__); auto def = nt::NTScalar{TypeCode::String}.build(); auto val = def.create(); testShow()< void testConvertScalar(const Store& store, const Inout& inout) { testShow()<<__func__<<"("< store_t; auto cont = TypeDef(store_t::code).create(); try { cont.from(inout); }catch(std::exception& e){ testCase(false)<<"Error storing as "<())<())<"<(), 4.0); val1.unmark(); val2["display.description"] = "blah"; testThrows([&val1, &val2]() { val1.assign(val2); }); } } } // namespace MAIN(testdata) { testPlan(78); testSetup(); testTraverse(); testAssign(); testName(); testIter(); testPvRequest(); testConvertScalar(1.0, true); testConvertScalar(0.0, false); testConvertScalar(5.0, 5); testConvertScalar(5.0, 5); testConvertScalar(-5.0, -5); testConvertScalar(-5.0, -5.0); testConvertScalar(-5.0, "-5"); testConvertScalar(1, true); testConvertScalar(0, false); testConvertScalar(5, 5); testConvertScalar(5, 5); testConvertScalar(-5, -5); testConvertScalar(-5, -5.0); testConvertScalar(-5, "-5"); testConvertScalar("true", true); testConvertScalar("false", false); testConvertScalar("5", 5); testConvertScalar("5", 5); testConvertScalar("-5", -5); testConvertScalar("-5", -5.0); testConvertScalar("-5", "-5"); testAssignSimilar(); cleanup_for_valgrind(); return testDone(); }