From 29bcaee19653a4e99b763e7877dffabc8ffd44f1 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 3 Aug 2022 13:34:49 +0200 Subject: [PATCH] some tests for new var len field --- src/fsfw/cfdp/pdu/VarLenField.cpp | 25 +++++++++---------------- src/fsfw/cfdp/pdu/VarLenField.h | 9 ++++++++- unittests/cfdp/testCfdp.cpp | 14 +++++++++++++- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/fsfw/cfdp/pdu/VarLenField.cpp b/src/fsfw/cfdp/pdu/VarLenField.cpp index cb72735e..7713ed11 100644 --- a/src/fsfw/cfdp/pdu/VarLenField.cpp +++ b/src/fsfw/cfdp/pdu/VarLenField.cpp @@ -21,27 +21,27 @@ cfdp::VarLenField::VarLenField() : width(cfdp::WidthInBytes::ONE_BYTE) { value.o cfdp::WidthInBytes cfdp::VarLenField::getWidth() const { return width; } -ReturnValue_t cfdp::VarLenField::setValue(cfdp::WidthInBytes widthInBytes, size_t value) { +ReturnValue_t cfdp::VarLenField::setValue(cfdp::WidthInBytes widthInBytes, size_t value_) { switch (widthInBytes) { case (cfdp::WidthInBytes::ONE_BYTE): { - if (value > UINT8_MAX) { + if (value_ > UINT8_MAX) { return HasReturnvaluesIF::RETURN_FAILED; } - this->value.oneByte = value; + this->value.oneByte = value_; break; } case (cfdp::WidthInBytes::TWO_BYTES): { - if (value > UINT16_MAX) { + if (value_ > UINT16_MAX) { return HasReturnvaluesIF::RETURN_FAILED; } - this->value.twoBytes = value; + this->value.twoBytes = value_; break; } case (cfdp::WidthInBytes::FOUR_BYTES): { - if (value > UINT32_MAX) { + if (value_ > UINT32_MAX) { return HasReturnvaluesIF::RETURN_FAILED; } - this->value.fourBytes = value; + this->value.fourBytes = value_; break; } default: { @@ -93,9 +93,9 @@ ReturnValue_t cfdp::VarLenField::serialize(uint8_t **buffer, size_t *size, size_ size_t cfdp::VarLenField::getSerializedSize() const { return width; } -ReturnValue_t cfdp::VarLenField::deSerialize(cfdp::WidthInBytes width, const uint8_t **buffer, +ReturnValue_t cfdp::VarLenField::deSerialize(cfdp::WidthInBytes width_, const uint8_t **buffer, size_t *size, Endianness streamEndianness) { - this->width = width; + this->width = width_; return deSerialize(buffer, size, streamEndianness); } @@ -118,10 +118,3 @@ ReturnValue_t cfdp::VarLenField::deSerialize(const uint8_t **buffer, size_t *siz } } } - -template -cfdp::VarLenField::VarLenField(UnsignedByteField byteField) - : width(static_cast(sizeof(T))) { - static_assert((sizeof(T) % 2) == 0); - value = byteField.getValue(); -} diff --git a/src/fsfw/cfdp/pdu/VarLenField.h b/src/fsfw/cfdp/pdu/VarLenField.h index 3b7ccc5a..dfc6b195 100644 --- a/src/fsfw/cfdp/pdu/VarLenField.h +++ b/src/fsfw/cfdp/pdu/VarLenField.h @@ -41,9 +41,16 @@ class VarLenField : public SerializeIF { Endianness streamEndianness) override; cfdp::WidthInBytes width; - LengthFieldLen value; + LengthFieldLen value{}; }; +template +cfdp::VarLenField::VarLenField(UnsignedByteField byteField) + : width(static_cast(sizeof(T))) { + static_assert((sizeof(T) % 2) == 0); + setValue(width, byteField.getValue()); +} + } // namespace cfdp #endif /* FSFW_SRC_FSFW_CFDP_PDU_VARLENFIELD_H_ */ diff --git a/unittests/cfdp/testCfdp.cpp b/unittests/cfdp/testCfdp.cpp index 8cfdbca4..475322a2 100644 --- a/unittests/cfdp/testCfdp.cpp +++ b/unittests/cfdp/testCfdp.cpp @@ -75,7 +75,7 @@ TEST_CASE("CFDP Base", "[cfdp]") { REQUIRE(fdDeser.parseData() == cfdp::INVALID_DIRECTIVE_FIELDS); } - SECTION("FileSize") { + SECTION("File Size") { std::array fssBuf = {}; uint8_t* buffer = fssBuf.data(); size_t size = 0; @@ -90,4 +90,16 @@ TEST_CASE("CFDP Base", "[cfdp]") { REQUIRE(result == HasReturnvaluesIF::RETURN_OK); REQUIRE(fileSize == 0x20); } + + SECTION("Var Length Field") { + VarLenField defaultField; + CHECK(defaultField.getValue() == 0); + CHECK(defaultField.getWidth() == WidthInBytes::ONE_BYTE); + VarLenField explicitField(WidthInBytes::FOUR_BYTES, 12); + CHECK(explicitField.getWidth() == WidthInBytes::FOUR_BYTES); + CHECK(explicitField.getValue() == 12); + VarLenField fromUnsignedByteField(UnsignedByteField(12)); + CHECK(fromUnsignedByteField.getWidth() == WidthInBytes::TWO_BYTES); + CHECK(fromUnsignedByteField.getValue() == 12); + } }