From 3d2af203f2e365df7f64ce28853d540c5c41ec81 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 18 Jul 2022 16:18:04 +0200 Subject: [PATCH] finished creator unittests --- unittests/cfdp/testCfdp.cpp | 2 +- unittests/datapoollocal/DataSetTest.cpp | 2 +- .../datapoollocal/LocalPoolManagerTest.cpp | 2 +- .../datapoollocal/LocalPoolVariableTest.cpp | 2 +- .../datapoollocal/LocalPoolVectorTest.cpp | 2 +- .../devicehandler/TestDeviceHandlerBase.cpp | 2 +- unittests/globalfunctions/testCRC.cpp | 2 +- unittests/globalfunctions/testDleEncoder.cpp | 2 +- .../TestInternalErrorReporter.cpp | 2 +- unittests/mocks/MessageQueueMockBase.h | 2 +- unittests/power/testPowerSwitcher.cpp | 2 +- unittests/testVersion.cpp | 5 +-- unittests/tmtcpacket/CMakeLists.txt | 2 +- ...estCcsdsReader.cpp => TestCcsdsReader.cpp} | 44 ++++++++++++++----- .../{PusTmTest.cpp => TestPusTm.cpp} | 0 15 files changed, 47 insertions(+), 26 deletions(-) rename unittests/tmtcpacket/{testCcsdsReader.cpp => TestCcsdsReader.cpp} (65%) rename unittests/tmtcpacket/{PusTmTest.cpp => TestPusTm.cpp} (100%) diff --git a/unittests/cfdp/testCfdp.cpp b/unittests/cfdp/testCfdp.cpp index 6ca95fbc..78ef618b 100644 --- a/unittests/cfdp/testCfdp.cpp +++ b/unittests/cfdp/testCfdp.cpp @@ -2,6 +2,7 @@ #include #include +#include "CatchDefinitions.h" #include "fsfw/cfdp/FileSize.h" #include "fsfw/cfdp/pdu/FileDirectiveDeserializer.h" #include "fsfw/cfdp/pdu/FileDirectiveSerializer.h" @@ -9,7 +10,6 @@ #include "fsfw/cfdp/pdu/HeaderSerializer.h" #include "fsfw/globalfunctions/arrayprinter.h" #include "fsfw/serialize/SerializeAdapter.h" -#include "CatchDefinitions.h" TEST_CASE("CFDP Base", "[CfdpBase]") { using namespace cfdp; diff --git a/unittests/datapoollocal/DataSetTest.cpp b/unittests/datapoollocal/DataSetTest.cpp index c56ed768..c9f023ef 100644 --- a/unittests/datapoollocal/DataSetTest.cpp +++ b/unittests/datapoollocal/DataSetTest.cpp @@ -8,8 +8,8 @@ #include #include -#include "LocalPoolOwnerBase.h" #include "CatchDefinitions.h" +#include "LocalPoolOwnerBase.h" #include "tests/TestsConfig.h" TEST_CASE("DataSetTest", "[DataSetTest]") { diff --git a/unittests/datapoollocal/LocalPoolManagerTest.cpp b/unittests/datapoollocal/LocalPoolManagerTest.cpp index 019c9b59..58a6065e 100644 --- a/unittests/datapoollocal/LocalPoolManagerTest.cpp +++ b/unittests/datapoollocal/LocalPoolManagerTest.cpp @@ -11,8 +11,8 @@ #include #include -#include "LocalPoolOwnerBase.h" #include "CatchDefinitions.h" +#include "LocalPoolOwnerBase.h" TEST_CASE("LocalPoolManagerTest", "[LocManTest]") { LocalPoolOwnerBase* poolOwner = diff --git a/unittests/datapoollocal/LocalPoolVariableTest.cpp b/unittests/datapoollocal/LocalPoolVariableTest.cpp index 86bd6a1e..3479cdbe 100644 --- a/unittests/datapoollocal/LocalPoolVariableTest.cpp +++ b/unittests/datapoollocal/LocalPoolVariableTest.cpp @@ -3,8 +3,8 @@ #include -#include "LocalPoolOwnerBase.h" #include "CatchDefinitions.h" +#include "LocalPoolOwnerBase.h" #include "tests/TestsConfig.h" TEST_CASE("LocalPoolVariable", "[LocPoolVarTest]") { diff --git a/unittests/datapoollocal/LocalPoolVectorTest.cpp b/unittests/datapoollocal/LocalPoolVectorTest.cpp index 3a06c826..2235ad39 100644 --- a/unittests/datapoollocal/LocalPoolVectorTest.cpp +++ b/unittests/datapoollocal/LocalPoolVectorTest.cpp @@ -3,8 +3,8 @@ #include -#include "LocalPoolOwnerBase.h" #include "CatchDefinitions.h" +#include "LocalPoolOwnerBase.h" #include "tests/TestsConfig.h" TEST_CASE("LocalPoolVector", "[LocPoolVecTest]") { diff --git a/unittests/devicehandler/TestDeviceHandlerBase.cpp b/unittests/devicehandler/TestDeviceHandlerBase.cpp index 328bc4dc..e8fdd17b 100644 --- a/unittests/devicehandler/TestDeviceHandlerBase.cpp +++ b/unittests/devicehandler/TestDeviceHandlerBase.cpp @@ -2,9 +2,9 @@ #include "ComIFMock.h" #include "DeviceFdirMock.h" -#include "devicehandler/CookieIFMock.h" #include "DeviceHandlerCommander.h" #include "DeviceHandlerMock.h" +#include "devicehandler/CookieIFMock.h" #include "objects/systemObjectList.h" TEST_CASE("Device Handler Base", "[DeviceHandlerBase]") { diff --git a/unittests/globalfunctions/testCRC.cpp b/unittests/globalfunctions/testCRC.cpp index 884bd281..2b6de4db 100644 --- a/unittests/globalfunctions/testCRC.cpp +++ b/unittests/globalfunctions/testCRC.cpp @@ -1,8 +1,8 @@ #include +#include "CatchDefinitions.h" #include "catch2/catch_test_macros.hpp" #include "fsfw/globalfunctions/CRC.h" -#include "CatchDefinitions.h" TEST_CASE("CRC", "[CRC]") { std::array testData = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; diff --git a/unittests/globalfunctions/testDleEncoder.cpp b/unittests/globalfunctions/testDleEncoder.cpp index 1ccaddb5..0c707f4c 100644 --- a/unittests/globalfunctions/testDleEncoder.cpp +++ b/unittests/globalfunctions/testDleEncoder.cpp @@ -1,8 +1,8 @@ #include +#include "CatchDefinitions.h" #include "catch2/catch_test_macros.hpp" #include "fsfw/globalfunctions/DleEncoder.h" -#include "CatchDefinitions.h" const std::vector TEST_ARRAY_0 = {0, 0, 0, 0, 0}; const std::vector TEST_ARRAY_1 = {0, DleEncoder::DLE_CHAR, 5}; diff --git a/unittests/internalerror/TestInternalErrorReporter.cpp b/unittests/internalerror/TestInternalErrorReporter.cpp index b52c5336..2b999fae 100644 --- a/unittests/internalerror/TestInternalErrorReporter.cpp +++ b/unittests/internalerror/TestInternalErrorReporter.cpp @@ -8,11 +8,11 @@ #include #include +#include "CatchDefinitions.h" #include "fsfw/action/ActionMessage.h" #include "fsfw/ipc/CommandMessage.h" #include "fsfw/ipc/MessageQueueMessage.h" #include "fsfw/objectmanager/frameworkObjects.h" -#include "CatchDefinitions.h" #include "mocks/PeriodicTaskIFMock.h" TEST_CASE("Internal Error Reporter", "[TestInternalError]") { diff --git a/unittests/mocks/MessageQueueMockBase.h b/unittests/mocks/MessageQueueMockBase.h index 60a942d9..d3323186 100644 --- a/unittests/mocks/MessageQueueMockBase.h +++ b/unittests/mocks/MessageQueueMockBase.h @@ -4,11 +4,11 @@ #include #include +#include "CatchDefinitions.h" #include "fsfw/ipc/CommandMessage.h" #include "fsfw/ipc/MessageQueueBase.h" #include "fsfw/ipc/MessageQueueIF.h" #include "fsfw/ipc/MessageQueueMessage.h" -#include "CatchDefinitions.h" class MessageQueueMockBase : public MessageQueueBase { public: diff --git a/unittests/power/testPowerSwitcher.cpp b/unittests/power/testPowerSwitcher.cpp index cf2f2148..f6a24583 100644 --- a/unittests/power/testPowerSwitcher.cpp +++ b/unittests/power/testPowerSwitcher.cpp @@ -1,9 +1,9 @@ #include #include -#include "mocks/PowerSwitcherMock.h" #include +#include "mocks/PowerSwitcherMock.h" #include "objects/systemObjectList.h" TEST_CASE("Power Switcher", "[power-switcher]") { diff --git a/unittests/testVersion.cpp b/unittests/testVersion.cpp index e0b9897b..2f487031 100644 --- a/unittests/testVersion.cpp +++ b/unittests/testVersion.cpp @@ -1,10 +1,9 @@ -#include "fsfw/version.h" - #include -#include "fsfw/serviceinterface.h" #include "CatchDefinitions.h" +#include "fsfw/serviceinterface.h" +#include "fsfw/version.h" TEST_CASE("Version API Tests", "[TestVersionAPI]") { // Check that major version is non-zero diff --git a/unittests/tmtcpacket/CMakeLists.txt b/unittests/tmtcpacket/CMakeLists.txt index 66eb4976..ea3eec21 100644 --- a/unittests/tmtcpacket/CMakeLists.txt +++ b/unittests/tmtcpacket/CMakeLists.txt @@ -1,3 +1,3 @@ target_sources(${FSFW_TEST_TGT} PRIVATE - testCcsdsReader.cpp + TestCcsdsReader.cpp ) diff --git a/unittests/tmtcpacket/testCcsdsReader.cpp b/unittests/tmtcpacket/TestCcsdsReader.cpp similarity index 65% rename from unittests/tmtcpacket/testCcsdsReader.cpp rename to unittests/tmtcpacket/TestCcsdsReader.cpp index 700e9f1e..79d86eb1 100644 --- a/unittests/tmtcpacket/testCcsdsReader.cpp +++ b/unittests/tmtcpacket/TestCcsdsReader.cpp @@ -1,15 +1,14 @@ #include -#include #include +#include #include "fsfw/tmtcpacket/SpacePacketCreator.h" #include "fsfw/tmtcpacket/SpacePacketReader.h" TEST_CASE("CCSDS Test", "[ccsds]") { - SpacePacketCreator base = SpacePacketCreator( - ccsds::PacketType::TC, true, 0x02, - ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x16); - std::array buf {}; + SpacePacketCreator base = SpacePacketCreator(ccsds::PacketType::TC, true, 0x02, + ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x16); + std::array buf{}; uint8_t* bufPtr = buf.data(); size_t serLen = 0; @@ -30,6 +29,14 @@ TEST_CASE("CCSDS Test", "[ccsds]") { REQUIRE(base.getPacketDataLen() == 0x16); REQUIRE(base.getPacketType() == ccsds::PacketType::TC); REQUIRE(base.getPacketId() == 0x1802); + REQUIRE(base.getSerializedSize() == 6); + } + + SECTION("Deserialization Fails") { + serLen = 6; + const uint8_t* readOnlyPtr = buf.data(); + REQUIRE(base.deSerialize(&readOnlyPtr, &serLen, SerializeIF::Endianness::BIG) == + HasReturnvaluesIF::RETURN_FAILED); } SECTION("Raw Output") { @@ -65,18 +72,33 @@ TEST_CASE("CCSDS Test", "[ccsds]") { } SECTION("Invalid APID") { - SpacePacketCreator invalid = SpacePacketCreator( - PacketId(ccsds::PacketType::TC, true, 0xFFFF), - PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0x34), 0x16); + SpacePacketCreator invalid = + SpacePacketCreator(PacketId(ccsds::PacketType::TC, true, 0xFFFF), + PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0x34), 0x16); REQUIRE(not invalid.isValid()); REQUIRE(invalid.serialize(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_FAILED); } SECTION("Invalid Seq Count") { - SpacePacketCreator invalid = SpacePacketCreator( - PacketId(ccsds::PacketType::TC, true, 0x02), - PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0xFFFF), 0x16); + SpacePacketCreator invalid = + SpacePacketCreator(PacketId(ccsds::PacketType::TC, true, 0x02), + PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0xFFFF), 0x16); REQUIRE(not invalid.isValid()); REQUIRE(invalid.serialize(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_FAILED); } + + SECTION("Invalid Buf Size 1") { + serLen = 2; + REQUIRE(base.serialize(&bufPtr, &serLen, buf.size()) == SerializeIF::BUFFER_TOO_SHORT); + } + + SECTION("Invalid Buf Size 2") { + serLen = 4; + REQUIRE(base.serialize(&bufPtr, &serLen, buf.size()) == SerializeIF::BUFFER_TOO_SHORT); + } + + SECTION("Invalid Buf Size 3") { + serLen = 6; + REQUIRE(base.serialize(&bufPtr, &serLen, buf.size()) == SerializeIF::BUFFER_TOO_SHORT); + } } diff --git a/unittests/tmtcpacket/PusTmTest.cpp b/unittests/tmtcpacket/TestPusTm.cpp similarity index 100% rename from unittests/tmtcpacket/PusTmTest.cpp rename to unittests/tmtcpacket/TestPusTm.cpp