-
Notifications
You must be signed in to change notification settings - Fork 526
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[C++] use m_actingBlockLength in decodeLength() (#1045)
- Loading branch information
Showing
5 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2013-2025 Real Logic Limited. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include "versmsg/VersionedMessageV1.h" | ||
#include "versmsg/VersionedMessageV2.h" | ||
|
||
using namespace versmsg; | ||
|
||
static const std::size_t BUFFER_LEN = 2048; | ||
|
||
class VersionedMessageTest : public testing::Test | ||
{ | ||
public: | ||
VersionedMessageV2 m_versionedMessageV2 = {}; | ||
VersionedMessageV1 m_versionedMessageV1Decoder = {}; | ||
}; | ||
|
||
TEST_F(VersionedMessageTest, shouldV1DecodeV2Message) | ||
{ | ||
char buffer[BUFFER_LEN] = {}; | ||
|
||
m_versionedMessageV2.wrapForEncode(buffer, 0, sizeof(buffer)); | ||
m_versionedMessageV2.fieldA1(1); | ||
m_versionedMessageV2.fieldB1(2); | ||
m_versionedMessageV2.fieldC2(3); | ||
m_versionedMessageV2.fieldD2(4); | ||
m_versionedMessageV2.fieldE2(5); | ||
m_versionedMessageV2.putString1("asdf", 4); | ||
|
||
m_versionedMessageV1Decoder.wrapForDecode( | ||
buffer, | ||
0, | ||
VersionedMessageV2::sbeBlockLength(), | ||
VersionedMessageV2::sbeSchemaVersion(), | ||
m_versionedMessageV2.encodedLength()); | ||
|
||
EXPECT_EQ(m_versionedMessageV1Decoder.fieldA1(), (uint32_t)1); | ||
EXPECT_EQ(m_versionedMessageV1Decoder.fieldB1(), (uint32_t)2); | ||
EXPECT_STREQ(m_versionedMessageV1Decoder.string1(), "asdf"); | ||
|
||
EXPECT_EQ(m_versionedMessageV1Decoder.decodeLength(), (uint64_t)26); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<messageSchema package="versmsg" | ||
id="1" | ||
version="1" | ||
semanticVersion="1" | ||
description="Unit Test" | ||
byteOrder="littleEndian"> | ||
<types> | ||
<composite name="messageHeader" description="Message identifiers and length of message root"> | ||
<type name="blockLength" primitiveType="uint16"/> | ||
<type name="templateId" primitiveType="uint16"/> | ||
<type name="schemaId" primitiveType="uint16"/> | ||
<type name="version" primitiveType="uint16"/> | ||
</composite> | ||
<composite name="varStringEncoding"> | ||
<type name="length" primitiveType="uint16"/> | ||
<type name="varData" primitiveType="uint8" length="0" characterEncoding="UTF-8"/> | ||
</composite> | ||
</types> | ||
<message name="VersionedMessageV1" id="50001" description="A versioned message" blockLength="8"> | ||
<field name="FieldA1" id="1" type="uint32" semanticType="int"/> | ||
<field name="FieldB1" id="2" type="uint32" semanticType="int"/> | ||
<data name="String1" id="10" type="varStringEncoding"/> | ||
</message> | ||
</messageSchema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<messageSchema package="versmsg" | ||
id="1" | ||
version="2" | ||
semanticVersion="2" | ||
description="Unit Test" | ||
byteOrder="littleEndian"> | ||
<types> | ||
<composite name="messageHeader" description="Message identifiers and length of message root"> | ||
<type name="blockLength" primitiveType="uint16"/> | ||
<type name="templateId" primitiveType="uint16"/> | ||
<type name="schemaId" primitiveType="uint16"/> | ||
<type name="version" primitiveType="uint16"/> | ||
</composite> | ||
<composite name="varStringEncoding"> | ||
<type name="length" primitiveType="uint16"/> | ||
<type name="varData" primitiveType="uint8" length="0" characterEncoding="UTF-8"/> | ||
</composite> | ||
</types> | ||
<message name="VersionedMessageV2" id="50001" description="A versioned message" blockLength="20"> | ||
<field name="FieldA1" id="1" type="uint32" semanticType="int"/> | ||
<field name="FieldB1" id="2" type="uint32" semanticType="int"/> | ||
<field name="FieldC2" id="3" type="uint32" semanticType="int"/> | ||
<field name="FieldD2" id="4" type="uint32" semanticType="int"/> | ||
<field name="FieldE2" id="5" type="uint32" semanticType="int"/> | ||
<data name="String1" id="10" type="varStringEncoding"/> | ||
</message> | ||
</messageSchema> |