fix TypeDef amend

This commit is contained in:
Michael Davidsaver
2020-07-21 10:39:41 -07:00
parent 90203c9b86
commit 5210b7041d
2 changed files with 28 additions and 2 deletions
+2 -1
View File
@@ -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<Member>(val.desc->code, val.desc->id));
auto root(std::make_shared<Member>(val.desc->code, ""));
root->id = val.desc->id;
Member::Helper::copy_tree(val.desc, *root);
+26 -1
View File
@@ -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();