fsfw/tests/src/fsfw_tests/unit/container/TestPlacementFactory.cpp
Robin Mueller a18706ec53
Make FSFW tests accessible from outside
1. Further reduces the amount of code the user needs to copy and paste
2. Makes FSFW tests more accessible. This can be used to simplify moving mission unit tests
   to the FSFW
3. A lot of include improvements
2021-08-16 10:49:07 +02:00

50 lines
1.9 KiB
C++

#include "fsfw_tests/unit/CatchDefinitions.h"
#include <fsfw/container/PlacementFactory.h>
#include <fsfw/storagemanager/LocalPool.h>
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
#include <fsfw/container/ArrayList.h>
#include <catch2/catch_test_macros.hpp>
TEST_CASE( "PlacementFactory Tests", "[TestPlacementFactory]") {
INFO("PlacementFactory Tests");
LocalPool::LocalPoolConfig poolCfg= {{1, sizeof(uint16_t)},
{1, sizeof(uint32_t)}, {1, sizeof(uint64_t)}
};
//const uint16_t element_sizes[3] = {sizeof(uint16_t), sizeof(uint32_t), sizeof(uint64_t)};
//const uint16_t n_elements[3] = {1, 1, 1};
LocalPool storagePool(0x1, poolCfg, false, true);
PlacementFactory factory(&storagePool);
SECTION("Pool overload"){
store_address_t address;
uint8_t* ptr = nullptr;
REQUIRE(storagePool.getFreeElement(&address, sizeof(ArrayList<uint32_t, uint16_t>), &ptr)
== static_cast<int>(StorageManagerIF::DATA_TOO_LARGE));
ArrayList<uint32_t, uint16_t>* list2 = factory.generate<ArrayList<uint32_t, uint16_t> >(80);
REQUIRE(list2 == nullptr);
}
SECTION("Test generate and destroy"){
uint64_t* number = factory.generate<uint64_t>(32000);
REQUIRE(number != nullptr);
REQUIRE(*number == 32000);
store_address_t address;
uint8_t* ptr = nullptr;
REQUIRE(storagePool.getFreeElement(&address, sizeof(uint64_t), &ptr)
== static_cast<int>(StorageManagerIF::DATA_TOO_LARGE));
uint64_t* number2 = factory.generate<uint64_t>(12345);
REQUIRE(number2 == nullptr);
REQUIRE(factory.destroy(number) == static_cast<int>(HasReturnvaluesIF::RETURN_OK));
REQUIRE(storagePool.getFreeElement(&address, sizeof(uint64_t), &ptr)
== static_cast<int>(HasReturnvaluesIF::RETURN_OK));
REQUIRE(storagePool.deleteData(address) == static_cast<int>(HasReturnvaluesIF::RETURN_OK));
//Check that PlacementFactory checks for nullptr
ptr = nullptr;
REQUIRE(factory.destroy(ptr) == static_cast<int>(HasReturnvaluesIF::RETURN_FAILED));
}
}