some tests for new var len field

This commit is contained in:
Robin Müller 2022-08-03 13:34:49 +02:00
parent cc98512caf
commit 29bcaee196
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
3 changed files with 30 additions and 18 deletions

View File

@ -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 <typename T>
cfdp::VarLenField::VarLenField(UnsignedByteField<T> byteField)
: width(static_cast<WidthInBytes>(sizeof(T))) {
static_assert((sizeof(T) % 2) == 0);
value = byteField.getValue();
}

View File

@ -41,9 +41,16 @@ class VarLenField : public SerializeIF {
Endianness streamEndianness) override;
cfdp::WidthInBytes width;
LengthFieldLen value;
LengthFieldLen value{};
};
template <typename T>
cfdp::VarLenField::VarLenField(UnsignedByteField<T> byteField)
: width(static_cast<WidthInBytes>(sizeof(T))) {
static_assert((sizeof(T) % 2) == 0);
setValue(width, byteField.getValue());
}
} // namespace cfdp
#endif /* FSFW_SRC_FSFW_CFDP_PDU_VARLENFIELD_H_ */

View File

@ -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<uint16_t>(12));
CHECK(fromUnsignedByteField.getWidth() == WidthInBytes::TWO_BYTES);
CHECK(fromUnsignedByteField.getValue() == 12);
}
}