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");
//
// const uint16_t element_sizes[3] = {sizeof(uint16_t), sizeof(uint32_t), sizeof(uint64_t)}; LocalPool::LocalPoolConfig poolCfg= {{1, sizeof(uint16_t)},
// const uint16_t n_elements[3] = {1, 1, 1}; {1, sizeof(uint32_t)}, {1, sizeof(uint64_t)}
// LocalPool<3> storagePool(0x1, element_sizes, n_elements, false, true); };
// PlacementFactory factory(&storagePool); //const uint16_t element_sizes[3] = {sizeof(uint16_t), sizeof(uint32_t), sizeof(uint64_t)};
// //const uint16_t n_elements[3] = {1, 1, 1};
// SECTION("Pool overload"){ LocalPool storagePool(0x1, poolCfg, false, true);
// store_address_t address; PlacementFactory factory(&storagePool);
// uint8_t* ptr = nullptr;
// REQUIRE(storagePool.getFreeElement(&address, sizeof(ArrayList<uint32_t, uint16_t>), &ptr) SECTION("Pool overload"){
// == static_cast<int>(StorageManagerIF::DATA_TOO_LARGE)); store_address_t address;
// ArrayList<uint32_t, uint16_t>* list2 = factory.generate<ArrayList<uint32_t, uint16_t> >(80); uint8_t* ptr = nullptr;
// REQUIRE(list2 == 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);
// SECTION("Test generate and destroy"){ REQUIRE(list2 == nullptr);
// uint64_t* number = factory.generate<uint64_t>(32000); }
// REQUIRE(number != nullptr);
// REQUIRE(*number == 32000); SECTION("Test generate and destroy"){
// store_address_t address; uint64_t* number = factory.generate<uint64_t>(32000);
// uint8_t* ptr = nullptr; REQUIRE(number != nullptr);
// REQUIRE(storagePool.getFreeElement(&address, sizeof(uint64_t), &ptr) REQUIRE(*number == 32000);
// == static_cast<int>(StorageManagerIF::DATA_TOO_LARGE)); store_address_t address;
// uint64_t* number2 = factory.generate<uint64_t>(12345); uint8_t* ptr = nullptr;
// REQUIRE(number2 == nullptr); REQUIRE(storagePool.getFreeElement(&address, sizeof(uint64_t), &ptr)
// REQUIRE(factory.destroy(number) == static_cast<int>(HasReturnvaluesIF::RETURN_OK)); == static_cast<int>(StorageManagerIF::DATA_TOO_LARGE));
// REQUIRE(storagePool.getFreeElement(&address, sizeof(uint64_t), &ptr) uint64_t* number2 = factory.generate<uint64_t>(12345);
// == static_cast<int>(HasReturnvaluesIF::RETURN_OK)); REQUIRE(number2 == nullptr);
// REQUIRE(storagePool.deleteData(address) == static_cast<int>(HasReturnvaluesIF::RETURN_OK)); REQUIRE(factory.destroy(number) == static_cast<int>(HasReturnvaluesIF::RETURN_OK));
// REQUIRE(storagePool.getFreeElement(&address, sizeof(uint64_t), &ptr)
// //Check that PlacementFactory checks for nullptr == static_cast<int>(HasReturnvaluesIF::RETURN_OK));
// ptr = nullptr; REQUIRE(storagePool.deleteData(address) == static_cast<int>(HasReturnvaluesIF::RETURN_OK));
// REQUIRE(factory.destroy(ptr) == static_cast<int>(HasReturnvaluesIF::RETURN_FAILED));
// } //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 <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;