Skip to content

Commit 1e651c1

Browse files
author
Egor Seredin
committed
[C++] test message length functions
1 parent 2ffaa96 commit 1e651c1

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

sbe-samples/src/main/cpp/GeneratedStubExample.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,9 @@ int main(int argc, const char* argv[])
314314

315315
std::size_t encodeHdrLength = encodeHdr(hdr, car, buffer, 0, sizeof(buffer));
316316
std::size_t encodeMsgLength = encodeCar(car, buffer, hdr.encodedLength(), sizeof(buffer));
317+
std::size_t predictedLength = Car::computeLength({11, 14, 13}, {3, 3}, 5, 9, 8);
317318

318-
cout << "Encoded Lengths are " << encodeHdrLength << " + " << encodeMsgLength << endl;
319+
cout << "Encoded Lengths are " << encodeHdrLength << " + " << encodeMsgLength << " (" << predictedLength << ")" << endl;
319320

320321
std::size_t decodeHdrLength = decodeHdr(hdr, buffer, 0, sizeof(buffer));
321322
std::size_t decodeMsgLength = decodeCar(car, buffer, hdr.encodedLength(), hdr.blockLength(), hdr.version(), sizeof(buffer));

sbe-tool/src/test/cpp/CodeGenTest.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,25 @@ TEST_F(CodeGenTest, shouldBeAbleToEncodeCarCorrectly)
426426
offset += COLOR_LENGTH;
427427

428428
EXPECT_EQ(sz, offset);
429+
430+
std::uint64_t predictedCarSz = Car::computeLength(
431+
{
432+
FUEL_FIGURES_1_USAGE_DESCRIPTION_LENGTH,
433+
FUEL_FIGURES_2_USAGE_DESCRIPTION_LENGTH,
434+
FUEL_FIGURES_3_USAGE_DESCRIPTION_LENGTH
435+
},
436+
{
437+
ACCELERATION_COUNT,
438+
ACCELERATION_COUNT
439+
},
440+
MANUFACTURER_LENGTH,
441+
MODEL_LENGTH,
442+
ACTIVATION_CODE_LENGTH,
443+
COLOR_LENGTH
444+
);
445+
EXPECT_EQ(sz, predictedCarSz);
446+
EXPECT_EQ(Car::isConstLength(), false);
447+
EXPECT_EQ(Car::PerformanceFigures::Acceleration::isConstLength(), true);
429448
}
430449

431450
TEST_F(CodeGenTest, shouldBeAbleToEncodeHeaderPlusCarCorrectly)
@@ -467,6 +486,8 @@ TEST_F(CodeGenTest, shouldbeAbleToEncodeAndDecodeHeaderPlusCarCorrectly)
467486

468487
m_carDecoder.wrapForDecode(buffer, m_hdrDecoder.encodedLength(), Car::sbeBlockLength(), Car::sbeSchemaVersion(), hdrSz + carSz);
469488

489+
EXPECT_EQ(m_carDecoder.decodeLength(), expectedCarSize);
490+
470491
EXPECT_EQ(m_carDecoder.serialNumber(), SERIAL_NUMBER);
471492
EXPECT_EQ(m_carDecoder.modelYear(), MODEL_YEAR);
472493
EXPECT_EQ(m_carDecoder.available(), AVAILABLE);
@@ -578,6 +599,7 @@ TEST_F(CodeGenTest, shouldbeAbleToEncodeAndDecodeHeaderPlusCarCorrectly)
578599
EXPECT_EQ(std::string(m_carDecoder.color(), COLOR_LENGTH), COLOR);
579600

580601
EXPECT_EQ(m_carDecoder.encodedLength(), expectedCarSize);
602+
EXPECT_EQ(m_carDecoder.decodeLength(), expectedCarSize);
581603
}
582604

583605
struct CallbacksForEach

sbe-tool/src/test/cpp/CompositeElementsTest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ TEST_F(CompositeElementsTest, shouldEncodeMsgCorrectly)
210210
std::uint64_t offset = 0;
211211

212212
ASSERT_EQ(sz, 8u + 22u);
213+
ASSERT_EQ(Msg::isConstLength(), true);
214+
EXPECT_EQ(sz, Msg::sbeBlockAndHeaderLength());
213215

214216
EXPECT_EQ(*((std::uint16_t *)(bufferPtr + offset)), Msg::sbeBlockLength());
215217
offset += sizeof(std::uint16_t);

0 commit comments

Comments
 (0)