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 "ArrayList.h"
#include <cstring> #include <cstring>
#include <functional>
/** /**
* @brief An associative container which allows multiple entries of the same key. * @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/container/PlacementFactory.h>
//#include <fsfw/storagemanager/LocalPool.h> #include <fsfw/storagemanager/LocalPool.h>
//#include <fsfw/returnvalues/HasReturnvaluesIF.h> #include <fsfw/returnvalues/HasReturnvaluesIF.h>
//#include <fsfw/container/ArrayList.h> #include <fsfw/container/ArrayList.h>
//
//#include <catch2/catch.hpp> #include <catch2/catch_test_macros.hpp>
//#include "../../core/CatchDefinitions.h" #include <unittest/core/CatchDefinitions.h>
//
//TEST_CASE( "PlacementFactory Tests", "[TestPlacementFactory]") { TEST_CASE( "PlacementFactory Tests", "[TestPlacementFactory]") {
// INFO("PlacementFactory Tests"); 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 element_sizes[3] = {sizeof(uint16_t), sizeof(uint32_t), sizeof(uint64_t)};
//const uint16_t n_elements[3] = {1, 1, 1}; //const uint16_t n_elements[3] = {1, 1, 1};
// LocalPool<3> storagePool(0x1, element_sizes, n_elements, false, true); LocalPool storagePool(0x1, poolCfg, false, true);
// PlacementFactory factory(&storagePool); PlacementFactory factory(&storagePool);
//
// SECTION("Pool overload"){ SECTION("Pool overload"){
// store_address_t address; store_address_t address;
// uint8_t* ptr = nullptr; uint8_t* ptr = nullptr;
// REQUIRE(storagePool.getFreeElement(&address, sizeof(ArrayList<uint32_t, uint16_t>), &ptr) REQUIRE(storagePool.getFreeElement(&address, sizeof(ArrayList<uint32_t, uint16_t>), &ptr)
// == static_cast<int>(StorageManagerIF::DATA_TOO_LARGE)); == static_cast<int>(StorageManagerIF::DATA_TOO_LARGE));
// ArrayList<uint32_t, uint16_t>* list2 = factory.generate<ArrayList<uint32_t, uint16_t> >(80); ArrayList<uint32_t, uint16_t>* list2 = factory.generate<ArrayList<uint32_t, uint16_t> >(80);
// REQUIRE(list2 == nullptr); REQUIRE(list2 == nullptr);
// } }
//
// SECTION("Test generate and destroy"){ SECTION("Test generate and destroy"){
// uint64_t* number = factory.generate<uint64_t>(32000); uint64_t* number = factory.generate<uint64_t>(32000);
// REQUIRE(number != nullptr); REQUIRE(number != nullptr);
// REQUIRE(*number == 32000); REQUIRE(*number == 32000);
// store_address_t address; store_address_t address;
// uint8_t* ptr = nullptr; uint8_t* ptr = nullptr;
// REQUIRE(storagePool.getFreeElement(&address, sizeof(uint64_t), &ptr) REQUIRE(storagePool.getFreeElement(&address, sizeof(uint64_t), &ptr)
// == static_cast<int>(StorageManagerIF::DATA_TOO_LARGE)); == static_cast<int>(StorageManagerIF::DATA_TOO_LARGE));
// uint64_t* number2 = factory.generate<uint64_t>(12345); uint64_t* number2 = factory.generate<uint64_t>(12345);
// REQUIRE(number2 == nullptr); REQUIRE(number2 == nullptr);
// REQUIRE(factory.destroy(number) == static_cast<int>(HasReturnvaluesIF::RETURN_OK)); REQUIRE(factory.destroy(number) == static_cast<int>(HasReturnvaluesIF::RETURN_OK));
// REQUIRE(storagePool.getFreeElement(&address, sizeof(uint64_t), &ptr) REQUIRE(storagePool.getFreeElement(&address, sizeof(uint64_t), &ptr)
// == static_cast<int>(HasReturnvaluesIF::RETURN_OK)); == static_cast<int>(HasReturnvaluesIF::RETURN_OK));
// REQUIRE(storagePool.deleteData(address) == static_cast<int>(HasReturnvaluesIF::RETURN_OK)); REQUIRE(storagePool.deleteData(address) == static_cast<int>(HasReturnvaluesIF::RETURN_OK));
//
// //Check that PlacementFactory checks for nullptr //Check that PlacementFactory checks for nullptr
// ptr = nullptr; ptr = nullptr;
// REQUIRE(factory.destroy(ptr) == static_cast<int>(HasReturnvaluesIF::RETURN_FAILED)); REQUIRE(factory.destroy(ptr) == static_cast<int>(HasReturnvaluesIF::RETURN_FAILED));
// } }
//} }

View File

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

View File

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