fsfw/unittests/tmtcservices/testStoreHelper.cpp

110 lines
4.4 KiB
C++
Raw Permalink Normal View History

2022-07-23 11:43:48 +02:00
#include <catch2/catch_test_macros.hpp>
2022-07-25 10:38:44 +02:00
#include "fsfw/storagemanager/LocalPool.h"
#include "fsfw/tmtcservices/TmStoreHelper.h"
2022-07-25 20:41:01 +02:00
#include "fsfw/tmtcservices/tmHelpers.h"
#include "mock/CdsShortTimestamperMock.h"
#include "mock/SimpleSerializable.h"
2022-07-25 10:38:44 +02:00
TEST_CASE("TM Store Helper", "[tm-store-helper]") {
auto timeStamper = CdsShortTimestamperMock();
2022-07-25 13:39:07 +02:00
LocalPool::LocalPoolConfig cfg = {{5, 32}, {2, 64}};
2022-07-25 10:38:44 +02:00
LocalPool pool(objects::NO_OBJECT, cfg);
auto storeHelper = TmStoreHelper(2, pool, timeStamper);
SECTION("State") {
REQUIRE(storeHelper.getCurrentAddr() == store_address_t::invalid());
2022-07-25 13:39:07 +02:00
REQUIRE(storeHelper.getTimeStamper() == &timeStamper);
2022-07-25 11:24:13 +02:00
REQUIRE(storeHelper.getTmStore() == &pool);
2022-08-16 01:08:26 +02:00
REQUIRE(storeHelper.preparePacket(17, 1, 1) == returnvalue::OK);
auto& creator = storeHelper.getCreatorRef();
REQUIRE(creator.getApid() == 2);
REQUIRE(creator.getService() == 17);
REQUIRE(creator.getSubService() == 1);
REQUIRE(creator.getSequenceCount() == 0);
REQUIRE(creator.getMessageTypeCounter() == 1);
}
2022-07-25 13:39:07 +02:00
SECTION("Timestamper Setter") {
auto timeStamper2 = CdsShortTimestamperMock();
storeHelper.setTimeStamper(timeStamper2);
REQUIRE(storeHelper.getTimeStamper() == &timeStamper2);
}
SECTION("Pool Setter") {
LocalPool::LocalPoolConfig cfg2 = {{10, 32}, {5, 64}};
LocalPool pool2(objects::NO_OBJECT, cfg);
storeHelper.setTmStore(pool2);
REQUIRE(storeHelper.getTmStore() == &pool2);
}
SECTION("APID Setter") {
storeHelper.setApid(3);
auto& creator = storeHelper.getCreatorRef();
REQUIRE(creator.getApid() == 3);
}
SECTION("Basic") {
2022-08-16 01:08:26 +02:00
REQUIRE(storeHelper.preparePacket(17, 1, 1) == returnvalue::OK);
REQUIRE(storeHelper.addPacketToStore() == returnvalue::OK);
REQUIRE(storeHelper.getCurrentAddr() != store_address_t::invalid());
2022-07-25 11:24:13 +02:00
auto accessor = pool.getData(storeHelper.getCurrentAddr());
2022-08-16 01:08:26 +02:00
REQUIRE(accessor.first == returnvalue::OK);
2022-07-25 11:24:13 +02:00
// Not going to verify individual fields, the creator was unittested separately
REQUIRE(accessor.second.size() == 22);
}
2022-07-25 13:39:07 +02:00
SECTION("Deletion") {
2022-08-16 01:08:26 +02:00
REQUIRE(storeHelper.preparePacket(17, 1, 1) == returnvalue::OK);
REQUIRE(storeHelper.addPacketToStore() == returnvalue::OK);
2022-07-25 13:39:07 +02:00
REQUIRE(storeHelper.getCurrentAddr() != store_address_t::invalid());
{
auto accessor = pool.getData(storeHelper.getCurrentAddr());
2022-08-16 01:08:26 +02:00
REQUIRE(accessor.first == returnvalue::OK);
2022-07-25 13:39:07 +02:00
REQUIRE(accessor.second.size() == 22);
accessor.second.release();
}
2022-08-16 01:08:26 +02:00
REQUIRE(storeHelper.deletePacket() == returnvalue::OK);
2022-07-25 13:39:07 +02:00
REQUIRE(storeHelper.getCurrentAddr() == store_address_t::invalid());
auto accessor = pool.getData(storeHelper.getCurrentAddr());
2022-08-16 01:08:26 +02:00
REQUIRE(accessor.first != returnvalue::OK);
2022-07-25 13:39:07 +02:00
}
SECTION("With App Data Raw") {
2022-08-16 01:08:26 +02:00
REQUIRE(storeHelper.preparePacket(17, 1, 1) == returnvalue::OK);
2022-07-25 13:39:07 +02:00
std::array<uint8_t, 3> data = {1, 2, 3};
2022-08-16 01:08:26 +02:00
REQUIRE(storeHelper.setSourceDataRaw(data.data(), data.size()) == returnvalue::OK);
REQUIRE(storeHelper.addPacketToStore() == returnvalue::OK);
2022-07-25 13:39:07 +02:00
REQUIRE(storeHelper.getCurrentAddr() != store_address_t::invalid());
auto accessor = pool.getData(storeHelper.getCurrentAddr());
2022-08-16 01:08:26 +02:00
REQUIRE(accessor.first == returnvalue::OK);
2022-07-25 13:39:07 +02:00
// Not going to verify individual fields, the creator was unittested separately
REQUIRE(accessor.second.size() == 25);
}
SECTION("With App Data Serializable") {
2022-08-16 01:08:26 +02:00
REQUIRE(storeHelper.preparePacket(17, 1, 1) == returnvalue::OK);
2022-07-25 13:39:07 +02:00
auto serializable = SimpleSerializable();
2022-08-16 01:08:26 +02:00
REQUIRE(storeHelper.setSourceDataSerializable(serializable) == returnvalue::OK);
REQUIRE(storeHelper.addPacketToStore() == returnvalue::OK);
2022-07-25 13:39:07 +02:00
REQUIRE(storeHelper.getCurrentAddr() != store_address_t::invalid());
auto accessor = pool.getData(storeHelper.getCurrentAddr());
2022-08-16 01:08:26 +02:00
REQUIRE(accessor.first == returnvalue::OK);
2022-07-25 13:39:07 +02:00
// Not going to verify individual fields, the creator was unittested separately
REQUIRE(accessor.second.size() == 25);
}
SECTION("APID Only CTOR") {
auto storeHelperApidOnly = TmStoreHelper(2);
REQUIRE(storeHelperApidOnly.getApid() == 2);
REQUIRE(storeHelperApidOnly.getTmStore() == nullptr);
REQUIRE(storeHelperApidOnly.getTimeStamper() == nullptr);
}
SECTION("APID and TM Store Only CTOR") {
auto storeHelperApidOnly = TmStoreHelper(2, pool);
REQUIRE(storeHelperApidOnly.getApid() == 2);
REQUIRE(storeHelperApidOnly.getTmStore() == &pool);
REQUIRE(storeHelperApidOnly.getTimeStamper() == nullptr);
}
2022-07-25 10:38:44 +02:00
}