repaired unit tests

This commit is contained in:
Robin Müller 2021-01-03 23:18:10 +01:00
parent e9da8e79f3
commit e9a8313df7
4 changed files with 209 additions and 208 deletions

View File

@ -3,6 +3,7 @@
#include "ArrayList.h"
#include <cstring>
#include <functional>
/**
* @brief An associative container which allows multiple entries of the same key.

View File

@ -1,45 +1,48 @@
//#include <fsfw/container/PlacementFactory.h>
//#include <fsfw/storagemanager/LocalPool.h>
//#include <fsfw/returnvalues/HasReturnvaluesIF.h>
//#include <fsfw/container/ArrayList.h>
//
//#include <catch2/catch.hpp>
//#include "../../core/CatchDefinitions.h"
//
//TEST_CASE( "PlacementFactory Tests", "[TestPlacementFactory]") {
// INFO("PlacementFactory Tests");
//
#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>
#include <unittest/core/CatchDefinitions.h>
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<3> storagePool(0x1, element_sizes, n_elements, 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));
// }
//}
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));
}
}

View File

@ -1,161 +1,160 @@
//#include <fsfw/storagemanager/LocalPool.h>
//#include <catch2/catch.hpp>
//#include "../../core/CatchDefinitions.h"
//#include <array>
//
//TEST_CASE( "New Accessor" , "[NewAccessor]") {
// uint16_t numberOfElements[1] = {1};
// uint16_t sizeofElements[1] = {10};
// LocalPool<1> SimplePool = LocalPool<1>(0, sizeofElements, numberOfElements);
// std::array<uint8_t, 20> testDataArray;
// std::array<uint8_t, 20> receptionArray;
// store_address_t testStoreId;
// ReturnValue_t result = retval::CATCH_FAILED;
//
// for(size_t i = 0; i < testDataArray.size(); i++) {
// testDataArray[i] = i;
// }
// size_t size = 10;
//
// SECTION ("Simple tests getter functions") {
// result = SimplePool.addData(&testStoreId, testDataArray.data(), size);
// REQUIRE(result == retval::CATCH_OK);
// auto resultPair = SimplePool.getData(testStoreId);
// REQUIRE(resultPair.first == retval::CATCH_OK);
// resultPair.second.getDataCopy(receptionArray.data(), 20);
// CHECK(resultPair.second.getId() == testStoreId);
// CHECK(resultPair.second.size() == 10);
// for(size_t i = 0; i < size; i++) {
// CHECK(receptionArray[i] == i );
// }
//
// std::copy(resultPair.second.data(), resultPair.second.data() +
// resultPair.second.size(), receptionArray.data());
// for(size_t i = 0; i < size; i++) {
// CHECK(receptionArray[i] == i );
// }
//
// {
// auto resultPairLoc = SimplePool.getData(testStoreId);
// REQUIRE(resultPairLoc.first == retval::CATCH_OK);
// // data should be deleted when accessor goes out of scope.
// }
// resultPair = SimplePool.getData(testStoreId);
// REQUIRE(resultPair.first == (int) StorageManagerIF::DATA_DOES_NOT_EXIST);
//
// result = SimplePool.addData(&testStoreId, testDataArray.data(), size);
// REQUIRE(result == retval::CATCH_OK);
// {
// ConstStorageAccessor constAccessor(testStoreId);
// result = SimplePool.getData(testStoreId, constAccessor);
// REQUIRE(result == retval::CATCH_OK);
// constAccessor.getDataCopy(receptionArray.data(), 20);
// for(size_t i = 0; i < size; i++) {
// CHECK(receptionArray[i] == i );
// }
// // likewise, data should be deleted when accessor gets out of scope.
// }
// resultPair = SimplePool.getData(testStoreId);
// REQUIRE(resultPair.first == (int) StorageManagerIF::DATA_DOES_NOT_EXIST);
//
// result = SimplePool.addData(&testStoreId, testDataArray.data(), size);
// {
// resultPair = SimplePool.getData(testStoreId);
// REQUIRE(resultPair.first == retval::CATCH_OK);
// resultPair.second.release();
// // now data should not be deleted anymore
// }
// resultPair = SimplePool.getData(testStoreId);
// REQUIRE(resultPair.first == retval::CATCH_OK);
// resultPair.second.getDataCopy(receptionArray.data(), 20);
// for(size_t i = 0; i < size; i++) {
// CHECK(receptionArray[i] == i );
// }
// }
//
//
// SECTION("Simple tests modify functions") {
// result = SimplePool.addData(&testStoreId, testDataArray.data(), size);
// REQUIRE(result == retval::CATCH_OK);
// {
// StorageAccessor accessor(testStoreId);
// result = SimplePool.modifyData(testStoreId, accessor);
// REQUIRE(result == retval::CATCH_OK);
// CHECK(accessor.getId() == testStoreId);
// CHECK(accessor.size() == 10);
// accessor.getDataCopy(receptionArray.data(), 20);
// for(size_t i = 0; i < size; i++) {
// CHECK(receptionArray[i] == i );
// }
// std::copy(accessor.data(), accessor.data() +
// accessor.size(), receptionArray.data());
// for(size_t i = 0; i < size; i++) {
// CHECK(receptionArray[i] == i );
// }
// // data should be deleted when accessor goes out of scope
// }
// auto resultPair = SimplePool.getData(testStoreId);
// REQUIRE(resultPair.first == (int) StorageManagerIF::DATA_DOES_NOT_EXIST);
//
// result = SimplePool.addData(&testStoreId, testDataArray.data(), size);
// REQUIRE(result == retval::CATCH_OK);
// {
// auto resultPairLoc = SimplePool.modifyData(testStoreId);
// REQUIRE(resultPairLoc.first == retval::CATCH_OK);
// CHECK(resultPairLoc.second.getId() == testStoreId);
// CHECK(resultPairLoc.second.size() == 10);
// resultPairLoc.second.getDataCopy(receptionArray.data(), 20);
// for(size_t i = 0; i < size; i++) {
// CHECK(receptionArray[i] == i );
// }
// std::copy(resultPairLoc.second.data(), resultPairLoc.second.data() +
// resultPairLoc.second.size(), receptionArray.data());
// for(size_t i = 0; i < size; i++) {
// CHECK(receptionArray[i] == i );
// }
// resultPairLoc.second.release();
// // data should not be deleted when accessor goes out of scope
// }
// resultPair = SimplePool.getData(testStoreId);
// REQUIRE(resultPair.first == retval::CATCH_OK);
// }
//
//
// SECTION("Write tests") {
// result = SimplePool.addData(&testStoreId, testDataArray.data(), size);
// REQUIRE(result == retval::CATCH_OK);
// {
// auto resultPair = SimplePool.modifyData(testStoreId);
// REQUIRE(resultPair.first == retval::CATCH_OK);
// testDataArray[9] = 42;
// resultPair.second.write(testDataArray.data(), 10, 0);
// // now data should not be deleted
// resultPair.second.release();
// }
// auto resultConstPair = SimplePool.getData(testStoreId);
// REQUIRE(resultConstPair.first == retval::CATCH_OK);
//
// resultConstPair.second.getDataCopy(receptionArray.data(), 10);
// for(size_t i = 0; i < size-1; i++) {
// CHECK(receptionArray[i] == i );
// }
// CHECK(receptionArray[9] == 42 );
//
// auto resultPair = SimplePool.modifyData(testStoreId);
// REQUIRE(resultPair.first == retval::CATCH_OK);
// result = resultPair.second.write(testDataArray.data(), 20, 0);
// REQUIRE(result == retval::CATCH_FAILED);
// result = resultPair.second.write(testDataArray.data(), 10, 5);
// REQUIRE(result == retval::CATCH_FAILED);
//
// memset(testDataArray.data(), 42, 5);
// result = resultPair.second.write(testDataArray.data(), 5, 5);
// REQUIRE(result == retval::CATCH_OK);
// resultConstPair = SimplePool.getData(testStoreId);
// resultPair.second.getDataCopy(receptionArray.data(), 20);
// for(size_t i = 5; i < 10; i++) {
// CHECK(receptionArray[i] == 42 );
// }
//
// }
//}
#include <fsfw/storagemanager/LocalPool.h>
#include <catch2/catch_test_macros.hpp>
#include <unittest/core/CatchDefinitions.h>
#include <array>
TEST_CASE( "New Accessor" , "[NewAccessor]") {
LocalPool::LocalPoolConfig poolCfg = {{1, 10}};
LocalPool SimplePool = LocalPool(0, poolCfg);
std::array<uint8_t, 20> testDataArray;
std::array<uint8_t, 20> receptionArray;
store_address_t testStoreId;
ReturnValue_t result = retval::CATCH_FAILED;
for(size_t i = 0; i < testDataArray.size(); i++) {
testDataArray[i] = i;
}
size_t size = 10;
SECTION ("Simple tests getter functions") {
result = SimplePool.addData(&testStoreId, testDataArray.data(), size);
REQUIRE(result == retval::CATCH_OK);
auto resultPair = SimplePool.getData(testStoreId);
REQUIRE(resultPair.first == retval::CATCH_OK);
resultPair.second.getDataCopy(receptionArray.data(), 20);
CHECK(resultPair.second.getId() == testStoreId);
CHECK(resultPair.second.size() == 10);
for(size_t i = 0; i < size; i++) {
CHECK(receptionArray[i] == i );
}
std::copy(resultPair.second.data(), resultPair.second.data() +
resultPair.second.size(), receptionArray.data());
for(size_t i = 0; i < size; i++) {
CHECK(receptionArray[i] == i );
}
{
auto resultPairLoc = SimplePool.getData(testStoreId);
REQUIRE(resultPairLoc.first == retval::CATCH_OK);
// data should be deleted when accessor goes out of scope.
}
resultPair = SimplePool.getData(testStoreId);
REQUIRE(resultPair.first == (int) StorageManagerIF::DATA_DOES_NOT_EXIST);
result = SimplePool.addData(&testStoreId, testDataArray.data(), size);
REQUIRE(result == retval::CATCH_OK);
{
ConstStorageAccessor constAccessor(testStoreId);
result = SimplePool.getData(testStoreId, constAccessor);
REQUIRE(result == retval::CATCH_OK);
constAccessor.getDataCopy(receptionArray.data(), 20);
for(size_t i = 0; i < size; i++) {
CHECK(receptionArray[i] == i );
}
// likewise, data should be deleted when accessor gets out of scope.
}
resultPair = SimplePool.getData(testStoreId);
REQUIRE(resultPair.first == (int) StorageManagerIF::DATA_DOES_NOT_EXIST);
result = SimplePool.addData(&testStoreId, testDataArray.data(), size);
{
resultPair = SimplePool.getData(testStoreId);
REQUIRE(resultPair.first == retval::CATCH_OK);
resultPair.second.release();
// now data should not be deleted anymore
}
resultPair = SimplePool.getData(testStoreId);
REQUIRE(resultPair.first == retval::CATCH_OK);
resultPair.second.getDataCopy(receptionArray.data(), 20);
for(size_t i = 0; i < size; i++) {
CHECK(receptionArray[i] == i );
}
}
SECTION("Simple tests modify functions") {
result = SimplePool.addData(&testStoreId, testDataArray.data(), size);
REQUIRE(result == retval::CATCH_OK);
{
StorageAccessor accessor(testStoreId);
result = SimplePool.modifyData(testStoreId, accessor);
REQUIRE(result == retval::CATCH_OK);
CHECK(accessor.getId() == testStoreId);
CHECK(accessor.size() == 10);
accessor.getDataCopy(receptionArray.data(), 20);
for(size_t i = 0; i < size; i++) {
CHECK(receptionArray[i] == i );
}
std::copy(accessor.data(), accessor.data() +
accessor.size(), receptionArray.data());
for(size_t i = 0; i < size; i++) {
CHECK(receptionArray[i] == i );
}
// data should be deleted when accessor goes out of scope
}
auto resultPair = SimplePool.getData(testStoreId);
REQUIRE(resultPair.first == (int) StorageManagerIF::DATA_DOES_NOT_EXIST);
result = SimplePool.addData(&testStoreId, testDataArray.data(), size);
REQUIRE(result == retval::CATCH_OK);
{
auto resultPairLoc = SimplePool.modifyData(testStoreId);
REQUIRE(resultPairLoc.first == retval::CATCH_OK);
CHECK(resultPairLoc.second.getId() == testStoreId);
CHECK(resultPairLoc.second.size() == 10);
resultPairLoc.second.getDataCopy(receptionArray.data(), 20);
for(size_t i = 0; i < size; i++) {
CHECK(receptionArray[i] == i );
}
std::copy(resultPairLoc.second.data(), resultPairLoc.second.data() +
resultPairLoc.second.size(), receptionArray.data());
for(size_t i = 0; i < size; i++) {
CHECK(receptionArray[i] == i );
}
resultPairLoc.second.release();
// data should not be deleted when accessor goes out of scope
}
resultPair = SimplePool.getData(testStoreId);
REQUIRE(resultPair.first == retval::CATCH_OK);
}
SECTION("Write tests") {
result = SimplePool.addData(&testStoreId, testDataArray.data(), size);
REQUIRE(result == retval::CATCH_OK);
{
auto resultPair = SimplePool.modifyData(testStoreId);
REQUIRE(resultPair.first == retval::CATCH_OK);
testDataArray[9] = 42;
resultPair.second.write(testDataArray.data(), 10, 0);
// now data should not be deleted
resultPair.second.release();
}
auto resultConstPair = SimplePool.getData(testStoreId);
REQUIRE(resultConstPair.first == retval::CATCH_OK);
resultConstPair.second.getDataCopy(receptionArray.data(), 10);
for(size_t i = 0; i < size-1; i++) {
CHECK(receptionArray[i] == i );
}
CHECK(receptionArray[9] == 42 );
auto resultPair = SimplePool.modifyData(testStoreId);
REQUIRE(resultPair.first == retval::CATCH_OK);
result = resultPair.second.write(testDataArray.data(), 20, 0);
REQUIRE(result == retval::CATCH_FAILED);
result = resultPair.second.write(testDataArray.data(), 10, 5);
REQUIRE(result == retval::CATCH_FAILED);
memset(testDataArray.data(), 42, 5);
result = resultPair.second.write(testDataArray.data(), 5, 5);
REQUIRE(result == retval::CATCH_OK);
resultConstPair = SimplePool.getData(testStoreId);
resultPair.second.getDataCopy(receptionArray.data(), 20);
for(size_t i = 5; i < 10; i++) {
CHECK(receptionArray[i] == 42 );
}
}
}

View File

@ -8,8 +8,6 @@
TEST_CASE( "Local Pool Simple Tests [1 Pool]" , "[TestPool]") {
// uint16_t numberOfElements[1] = {1};
// uint16_t sizeofElements[1] = {10};
LocalPool::LocalPoolConfig config = {{1, 10}};
LocalPool simplePool(0, config);
std::array<uint8_t, 20> testDataArray;