From 5210b7041d604dd71bec036ee9711adda902bbeb Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Tue, 21 Jul 2020 10:39:41 -0700 Subject: [PATCH] fix TypeDef amend --- src/type.cpp | 3 ++- test/testtype.cpp | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/type.cpp b/src/type.cpp index 7022ee2..ba08f00 100644 --- a/src/type.cpp +++ b/src/type.cpp @@ -282,7 +282,8 @@ void Member::Helper::copy_tree(const FieldDesc* desc, Member& node) TypeDef::TypeDef(const Value& val) { if(val.desc) { - auto root(std::make_shared(val.desc->code, val.desc->id)); + auto root(std::make_shared(val.desc->code, "")); + root->id = val.desc->id; Member::Helper::copy_tree(val.desc, *root); diff --git a/test/testtype.cpp b/test/testtype.cpp index 59dc406..758d419 100644 --- a/test/testtype.cpp +++ b/test/testtype.cpp @@ -347,6 +347,30 @@ void testTypeDefDynamic() } } +void testTypeDefAppend() +{ + testDiag("%s()", __func__); + + auto base = TypeDef(TypeCode::Struct, "epics:nt/NTDummy:0.0", { + members::UInt32("A"), + }).create(); + + auto sub = TypeDef(base); + sub += { + members::UInt32("B"), + }; + + auto amend = sub.create(); + + testEq(base.id(), "epics:nt/NTDummy:0.0"); + testEq(base["A"].type(), TypeCode::UInt32); + testEq(base["B"].type(), TypeCode::Null); + + testEq(amend.id(), "epics:nt/NTDummy:0.0"); + testEq(amend["A"].type(), TypeCode::UInt32); + testEq(amend["B"].type(), TypeCode::UInt32); +} + //! Returns the frankenstruct Value neckBolt() { @@ -485,13 +509,14 @@ void testFormat() MAIN(testtype) { - testPlan(45); + testPlan(51); testSetup(); showSize(); testCode(); testBasic(); testTypeDef(); testTypeDefDynamic(); + testTypeDefAppend(); testFormat(); cleanup_for_valgrind(); return testDone();