Skip to content

Commit

Permalink
Added support for "reuseAliases" property for <message> and <interface>.
Browse files Browse the repository at this point in the history
  • Loading branch information
arobenko committed Dec 23, 2024
1 parent 4c4b979 commit 943e307
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/src/parse/InterfaceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ const XmlWrap::NamesList& InterfaceImpl::commonProps()
common::copyFieldsAliasesStr(),
common::reuseStr(),
common::reuseCodeStr(),
common::reuseAliasesStr(),
};

return CommonNames;
Expand Down Expand Up @@ -334,6 +335,19 @@ bool InterfaceImpl::checkReuse()
Base::reuseState(*iFace);
m_state = iFace->m_state;

do {
bool reuseAliases = true;
if (!validateAndUpdateBoolPropValue(common::reuseAliasesStr(), reuseAliases)) {
return false;
}

if (reuseAliases) {
break;
}

m_state.m_aliases.clear();
} while (false);

do {
auto& codeProp = common::reuseCodeStr();
if (!validateSinglePropInstance(codeProp, false)) {
Expand Down
14 changes: 14 additions & 0 deletions lib/src/parse/MessageImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ const XmlWrap::NamesList& MessageImpl::commonProps()
common::failOnInvalidStr(),
common::reuseStr(),
common::reuseCodeStr(),
common::reuseAliasesStr(),
common::copyConstructFromStr(),
common::copyReadCondFromStr(),
common::copyValidCondFromStr(),
Expand Down Expand Up @@ -439,6 +440,19 @@ bool MessageImpl::checkReuse()
Base::reuseState(*msg);
m_state = msg->m_state;

do {
bool reuseAliases = true;
if (!validateAndUpdateBoolPropValue(common::reuseAliasesStr(), reuseAliases)) {
return false;
}

if (reuseAliases) {
break;
}

m_state.m_aliases.clear();
} while (false);

do {
auto& codeProp = common::reuseCodeStr();
if (!validateSinglePropInstance(codeProp, false)) {
Expand Down
15 changes: 15 additions & 0 deletions lib/test/alias/Schema18.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<schema name="Schema18" endian="big">
<description>
Testing reuseAleses property
</description>
<interface name="I1">
<fields>
<int name="F1" type="uint8" />
<int name="F2" type="uint8" />
</fields>
<alias name="A1" field="$F1" />
</interface>

<interface name="I2" reuse="I1" reuseAliases="false" />
</schema>
13 changes: 13 additions & 0 deletions lib/test/alias/Schema19.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<schema name="Schema19" endian="big" version="5">
<message name="Msg1" id="1">
<fields>
<int name="F1" type="uint8" deprecated="4" removed="true"/>
<int name="F2" type="uint8" />
</fields>
<alias name="A1" field="$F1" />
<alias name="A2" field="$F2" />
</message>

<message name="Msg2" id="2" reuse="Msg1" reuseAliases="false" />
</schema>
44 changes: 44 additions & 0 deletions lib/test/alias/aliasTest.th
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public:
void test15();
void test16();
void test17();
void test18();
void test19();
};

void AliasTestSuite::setUp()
Expand Down Expand Up @@ -366,3 +368,45 @@ void AliasTestSuite::test17()
TS_ASSERT_EQUALS(a0.name(), "A2");
TS_ASSERT_EQUALS(a0.fieldName(), "F2");
}

void AliasTestSuite::test18()
{
auto protocol = prepareProtocol(SCHEMAS_DIR "/Schema18.xml");
TS_ASSERT(protocol);

auto namespaces = protocol->lastParsedSchema().namespaces();
TS_ASSERT_EQUALS(namespaces.size(), 1U);

auto& ns = namespaces.front();
TS_ASSERT(ns.name().empty());

auto interfaces = ns.interfaces();
TS_ASSERT_EQUALS(interfaces.size(), 2U);

auto& i2 = interfaces.back();
TS_ASSERT_EQUALS(i2.name(), "I2");

auto aliases = i2.aliases();
TS_ASSERT(aliases.empty());
}

void AliasTestSuite::test19()
{
auto protocol = prepareProtocol(SCHEMAS_DIR "/Schema19.xml");
TS_ASSERT(protocol);

auto namespaces = protocol->lastParsedSchema().namespaces();
TS_ASSERT_EQUALS(namespaces.size(), 1U);

auto& ns = namespaces.front();
TS_ASSERT(ns.name().empty());

auto messages = ns.messages();
TS_ASSERT_EQUALS(messages.size(), 2U);

auto& msg2 = messages.back();
TS_ASSERT_EQUALS(msg2.name(), "Msg2");

auto aliases = msg2.aliases();
TS_ASSERT(aliases.empty());
}

0 comments on commit 943e307

Please sign in to comment.