Skip to content

Commit

Permalink
Allowing replacing of the "construct", "validCond", and "readCond" pr…
Browse files Browse the repository at this point in the history
…operties of the <message> after reuse.
  • Loading branch information
arobenko committed Dec 17, 2024
1 parent 375340d commit cf8fda9
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 20 deletions.
17 changes: 7 additions & 10 deletions lib/src/parse/MessageImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ bool MessageImpl::checkReuse()

m_state.m_copyCodeFrom = valueStr;
} while (false);

return true;
}

Expand Down Expand Up @@ -1297,12 +1298,6 @@ bool MessageImpl::updateSingleCondInternal(const std::string& prop, OptCondImplP
return true;
}

if (cond) {
logError() << XmlWrap::logPrefix(m_node) <<
"Only single \"" << prop << "\" property is supported";
return false;
}

auto newCond = std::make_unique<OptCondExprImpl>();
if (!newCond->parse(iter->second, m_node, m_protocol)) {
return false;
Expand Down Expand Up @@ -1354,7 +1349,8 @@ bool MessageImpl::updateMultiCondInternal(const std::string& prop, OptCondImplPt
return false;
}

if (cond) {
auto iter = props().find(prop);
if (iter != props().end()) {
logError() << XmlWrap::logPrefix(condNodes.front()) <<
"Only single \"" << prop << "\" property is supported";
return false;
Expand Down Expand Up @@ -1384,8 +1380,9 @@ bool MessageImpl::copyCondInternal(
const std::string& copyProp,
const std::string& fromProp,
const OptCondImplPtr& fromCond,
const std::string& toProp,
OptCondImplPtr& toCond)
const std::string& toProp,
OptCondImplPtr& toCond,
bool allowOverride)
{
if (!validateSinglePropInstance(copyProp)) {
return false;
Expand Down Expand Up @@ -1420,7 +1417,7 @@ bool MessageImpl::copyCondInternal(
return false;
}

if (toCond) {
if (toCond && (!allowOverride)) {
logError() << XmlWrap::logPrefix(m_node) <<
"Set of the \"" << copyProp << "\" property overrides existing \"" << toProp << "\" setting.";
return false;
Expand Down
5 changes: 3 additions & 2 deletions lib/src/parse/MessageImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class MessageImpl final : public Object
m_name,
m_displayName,
m_description,
m_id = 0,
m_id,
m_order,
m_validateMinLength,
// m_fields,
Expand Down Expand Up @@ -330,7 +330,8 @@ class MessageImpl final : public Object
const std::string& fromProp,
const OptCondImplPtr& fromCond,
const std::string& toProp,
OptCondImplPtr& toCond);
OptCondImplPtr& toCond,
bool allowOverride = true);

::xmlNodePtr m_node = nullptr;
ProtocolImpl& m_protocol;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/parse/SchemaImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ bool SchemaImpl::validateAllMessages()

if (!allowNonUniquIds) {
logError(m_protocol.logger()) << "Messages \"" << iter->externalRef() << "\" and \"" <<
nextIter->externalRef() << "\" have the same id.";
nextIter->externalRef() << "\" have the same id: " << iter->id();
return false;
}

Expand Down
22 changes: 19 additions & 3 deletions lib/test/message/Schema32.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<schema name="Schema32" endian="Big" dslVersion="7">
<description>
Testing
</description>
<fields>
<string name="Msg1Name" defaultValue="Message 1" />
<string name="Msg2Name" defaultValue="Message 2" />
<string name="Msg3Name" defaultValue="Message 3" />
<string name="Msg4Name" defaultValue="Message 4" />

<enum name="MsgId" type="uint8">
<validValue name="Msg1" val="0" displayName="^Msg1Name" />
<validValue name="Msg2" val="1" displayName="^Msg2Name" />
<validValue name="Msg3" val="2" displayName="^Msg3Name" />
<validValue name="Msg4" val="3" displayName="^Msg4Name" />
</enum>
</fields>

Expand Down Expand Up @@ -40,4 +42,18 @@
<int name="F3" type="uint8" />
</message>

<message name="Msg3" id="MsgId.Msg3" displayName="^Msg3Name" constructAsReadCond="true" constructAsValidCond="true">
<construct>
<and>
<construct value="%Flags.M1.B0" />
<construct value="%Flags.M2 = 1" />
</and>
</construct>
</message>

<message name="Msg4" id="MsgId.Msg4" reuse="Msg3" constructAsValidCond="true">
<construct value="%Flags.M3 = 1" />
<!-- readCond remains copied from Msg3 -->
</message>

</schema>
44 changes: 40 additions & 4 deletions lib/test/message/messageTest.th
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,8 @@ void MessageTestSuite::test32()
auto& msg1 = messages[0];
TS_ASSERT(msg1.isFailOnInvalid());
TS_ASSERT_EQUALS(msg1.fields().size(), 2U);
auto msg1ValidCond = msg1.validCond();
TS_ASSERT_EQUALS(msg1ValidCond.kind(), commsdsl::parse::OptCond::Kind::List);
auto validCond = msg1.validCond();
TS_ASSERT_EQUALS(validCond.kind(), commsdsl::parse::OptCond::Kind::List);
}

{
Expand All @@ -698,7 +698,43 @@ void MessageTestSuite::test32()
TS_ASSERT(msg2.isFailOnInvalid());
TS_ASSERT_EQUALS(msg2.fields().size(), 3U);
TS_ASSERT_EQUALS(msg2.copyCodeFrom(), "Msg1");
auto msg1ValidCond = msg2.validCond();
TS_ASSERT_EQUALS(msg1ValidCond.kind(), commsdsl::parse::OptCond::Kind::List);
auto validCond = msg2.validCond();
TS_ASSERT_EQUALS(validCond.kind(), commsdsl::parse::OptCond::Kind::List);
}

{
TS_ASSERT_LESS_THAN_EQUALS(3U, messages.size());

auto& msg3 = messages[2];
TS_ASSERT_EQUALS(msg3.name(), "Msg3");
auto constructCond = msg3.construct();
TS_ASSERT(constructCond.valid());
TS_ASSERT_EQUALS(constructCond.kind(), commsdsl::parse::OptCond::Kind::List);

auto validCond = msg3.validCond();
TS_ASSERT(validCond.valid());
TS_ASSERT_EQUALS(validCond.kind(), commsdsl::parse::OptCond::Kind::List);

auto readCond = msg3.validCond();
TS_ASSERT(readCond.valid());
TS_ASSERT_EQUALS(readCond.kind(), commsdsl::parse::OptCond::Kind::List);
}

{
TS_ASSERT_LESS_THAN_EQUALS(4U, messages.size());

auto& msg4 = messages[3];
TS_ASSERT_EQUALS(msg4.name(), "Msg4");
auto constructCond = msg4.construct();
TS_ASSERT(constructCond.valid());
TS_ASSERT_EQUALS(constructCond.kind(), commsdsl::parse::OptCond::Kind::Expr);

auto validCond = msg4.validCond();
TS_ASSERT(validCond.valid());
TS_ASSERT_EQUALS(validCond.kind(), commsdsl::parse::OptCond::Kind::Expr);

auto readCond = msg4.readCond();
TS_ASSERT(readCond.valid());
TS_ASSERT_EQUALS(readCond.kind(), commsdsl::parse::OptCond::Kind::List);
}
}

0 comments on commit cf8fda9

Please sign in to comment.