some tests for new var len field
This commit is contained in:
parent
cc98512caf
commit
29bcaee196
@ -21,27 +21,27 @@ cfdp::VarLenField::VarLenField() : width(cfdp::WidthInBytes::ONE_BYTE) { value.o
|
|||||||
|
|
||||||
cfdp::WidthInBytes cfdp::VarLenField::getWidth() const { return width; }
|
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) {
|
switch (widthInBytes) {
|
||||||
case (cfdp::WidthInBytes::ONE_BYTE): {
|
case (cfdp::WidthInBytes::ONE_BYTE): {
|
||||||
if (value > UINT8_MAX) {
|
if (value_ > UINT8_MAX) {
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
this->value.oneByte = value;
|
this->value.oneByte = value_;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case (cfdp::WidthInBytes::TWO_BYTES): {
|
case (cfdp::WidthInBytes::TWO_BYTES): {
|
||||||
if (value > UINT16_MAX) {
|
if (value_ > UINT16_MAX) {
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
this->value.twoBytes = value;
|
this->value.twoBytes = value_;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case (cfdp::WidthInBytes::FOUR_BYTES): {
|
case (cfdp::WidthInBytes::FOUR_BYTES): {
|
||||||
if (value > UINT32_MAX) {
|
if (value_ > UINT32_MAX) {
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
this->value.fourBytes = value;
|
this->value.fourBytes = value_;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
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; }
|
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) {
|
size_t *size, Endianness streamEndianness) {
|
||||||
this->width = width;
|
this->width = width_;
|
||||||
return deSerialize(buffer, size, streamEndianness);
|
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();
|
|
||||||
}
|
|
||||||
|
@ -41,9 +41,16 @@ class VarLenField : public SerializeIF {
|
|||||||
Endianness streamEndianness) override;
|
Endianness streamEndianness) override;
|
||||||
|
|
||||||
cfdp::WidthInBytes width;
|
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
|
} // namespace cfdp
|
||||||
|
|
||||||
#endif /* FSFW_SRC_FSFW_CFDP_PDU_VARLENFIELD_H_ */
|
#endif /* FSFW_SRC_FSFW_CFDP_PDU_VARLENFIELD_H_ */
|
||||||
|
@ -75,7 +75,7 @@ TEST_CASE("CFDP Base", "[cfdp]") {
|
|||||||
REQUIRE(fdDeser.parseData() == cfdp::INVALID_DIRECTIVE_FIELDS);
|
REQUIRE(fdDeser.parseData() == cfdp::INVALID_DIRECTIVE_FIELDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("FileSize") {
|
SECTION("File Size") {
|
||||||
std::array<uint8_t, 8> fssBuf = {};
|
std::array<uint8_t, 8> fssBuf = {};
|
||||||
uint8_t* buffer = fssBuf.data();
|
uint8_t* buffer = fssBuf.data();
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
@ -90,4 +90,16 @@ TEST_CASE("CFDP Base", "[cfdp]") {
|
|||||||
REQUIRE(result == HasReturnvaluesIF::RETURN_OK);
|
REQUIRE(result == HasReturnvaluesIF::RETURN_OK);
|
||||||
REQUIRE(fileSize == 0x20);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user