test inNull and bool operator

This commit is contained in:
Robin Müller 2022-08-09 10:59:24 +02:00
parent 4f1fe39182
commit 06bea2f621
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
2 changed files with 19 additions and 9 deletions

View File

@ -134,4 +134,4 @@ bool HeaderReader::isNull() const {
return pointers.rawPtr == nullptr or pointers.fixedHeader == nullptr; return pointers.rawPtr == nullptr or pointers.fixedHeader == nullptr;
} }
HeaderReader::operator bool() const { return isNull(); } HeaderReader::operator bool() const { return not isNull(); }

View File

@ -16,9 +16,9 @@ TEST_CASE("CFDP File Directive", "[cfdp]") {
uint8_t* serTarget = serBuf.data(); uint8_t* serTarget = serBuf.data();
const uint8_t* deserTarget = serTarget; const uint8_t* deserTarget = serTarget;
size_t serSize = 0; size_t serSize = 0;
auto fdSer = FileDirectiveCreator(pduConf, FileDirectives::ACK, 4);
SECTION("File Directive") { SECTION("Serialization") {
auto fdSer = FileDirectiveCreator(pduConf, FileDirectives::ACK, 4);
REQUIRE(fdSer.getSerializedSize() == 8); REQUIRE(fdSer.getSerializedSize() == 8);
serTarget = serBuf.data(); serTarget = serBuf.data();
serSize = 0; serSize = 0;
@ -38,24 +38,34 @@ TEST_CASE("CFDP File Directive", "[cfdp]") {
// Dest ID // Dest ID
REQUIRE(serBuf[6] == 1); REQUIRE(serBuf[6] == 1);
REQUIRE(serBuf[7] == FileDirectives::ACK); REQUIRE(serBuf[7] == FileDirectives::ACK);
}
serTarget = serBuf.data(); SECTION("Serialization fails") {
size_t deserSize = 20;
serSize = 0;
REQUIRE(fdSer.deSerialize(&deserTarget, &deserSize, SerializeIF::Endianness::NETWORK) ==
HasReturnvaluesIF::RETURN_FAILED);
REQUIRE(fdSer.serialize(nullptr, nullptr, 85, SerializeIF::Endianness::NETWORK) == REQUIRE(fdSer.serialize(nullptr, nullptr, 85, SerializeIF::Endianness::NETWORK) ==
HasReturnvaluesIF::RETURN_FAILED); HasReturnvaluesIF::RETURN_FAILED);
}
SECTION("Buffer Too Short") {
for (uint8_t idx = 0; idx < 8; idx++) { for (uint8_t idx = 0; idx < 8; idx++) {
serTarget = serBuf.data(); serTarget = serBuf.data();
serSize = 0; serSize = 0;
REQUIRE(fdSer.serialize(&serTarget, &serSize, idx, SerializeIF::Endianness::NETWORK) == REQUIRE(fdSer.serialize(&serTarget, &serSize, idx, SerializeIF::Endianness::NETWORK) ==
SerializeIF::BUFFER_TOO_SHORT); SerializeIF::BUFFER_TOO_SHORT);
} }
}
SECTION("Deserialize") {
CHECK(fdSer.serialize(&serTarget, &serSize, serBuf.size(), SerializeIF::Endianness::NETWORK) ==
result::OK);
serTarget = serBuf.data();
REQUIRE(fdSer.deSerialize(&deserTarget, &serSize, SerializeIF::Endianness::NETWORK) ==
HasReturnvaluesIF::RETURN_FAILED);
deserTarget = serBuf.data(); deserTarget = serBuf.data();
deserSize = 0; CHECK(serSize == 8);
auto fdDeser = FileDirectiveReader(deserTarget, serBuf.size()); auto fdDeser = FileDirectiveReader(deserTarget, serBuf.size());
REQUIRE(not fdDeser.isNull());
REQUIRE(fdDeser);
REQUIRE(fdDeser.getEndianness() == SerializeIF::Endianness::NETWORK); REQUIRE(fdDeser.getEndianness() == SerializeIF::Endianness::NETWORK);
fdDeser.setEndianness(SerializeIF::Endianness::MACHINE); fdDeser.setEndianness(SerializeIF::Endianness::MACHINE);
REQUIRE(fdDeser.getEndianness() == SerializeIF::Endianness::MACHINE); REQUIRE(fdDeser.getEndianness() == SerializeIF::Endianness::MACHINE);