From b60e4bcb906b9564ef91b048dbf70d23dfea08b0 Mon Sep 17 00:00:00 2001 From: Steffen Gaisser Date: Mon, 20 Jun 2022 15:15:33 +0200 Subject: [PATCH] Fix StorageAccessor move assignment * Added Unittest for this * Fixed missing include in test --- src/fsfw/storagemanager/StorageAccessor.cpp | 2 +- .../unit/storagemanager/TestNewAccessor.cpp | 19 +++++++++++++++++++ .../unit/storagemanager/TestPool.cpp | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/fsfw/storagemanager/StorageAccessor.cpp b/src/fsfw/storagemanager/StorageAccessor.cpp index e2b083b2..b8096c1e 100644 --- a/src/fsfw/storagemanager/StorageAccessor.cpp +++ b/src/fsfw/storagemanager/StorageAccessor.cpp @@ -13,7 +13,7 @@ StorageAccessor::StorageAccessor(store_address_t storeId, StorageManagerIF* stor StorageAccessor& StorageAccessor::operator=(StorageAccessor&& other) { // Call the parent move assignment and also assign own member. dataPointer = other.dataPointer; - StorageAccessor::operator=(std::move(other)); + ConstStorageAccessor::operator=(std::move(other)); return *this; } diff --git a/tests/src/fsfw_tests/unit/storagemanager/TestNewAccessor.cpp b/tests/src/fsfw_tests/unit/storagemanager/TestNewAccessor.cpp index e1db9ce0..98654a44 100644 --- a/tests/src/fsfw_tests/unit/storagemanager/TestNewAccessor.cpp +++ b/tests/src/fsfw_tests/unit/storagemanager/TestNewAccessor.cpp @@ -156,4 +156,23 @@ TEST_CASE("New Accessor", "[NewAccessor]") { CHECK(receptionArray[i] == 42); } } + + SECTION("Operators"){ + result = SimplePool.addData(&testStoreId, testDataArray.data(), size); + REQUIRE(result == retval::CATCH_OK); + { + StorageAccessor accessor(testStoreId); + StorageAccessor accessor2(0); + accessor2 = std::move(accessor); + REQUIRE(accessor.data() == nullptr); + std::array data; + size_t size = 10; + result = accessor.write(data.data(), size); + REQUIRE(result == HasReturnvaluesIF::RETURN_FAILED); + result = SimplePool.modifyData(testStoreId, accessor2); + REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + CHECK(accessor2.getId() == testStoreId); + CHECK(accessor2.size() == 10); + } + } } diff --git a/tests/src/fsfw_tests/unit/storagemanager/TestPool.cpp b/tests/src/fsfw_tests/unit/storagemanager/TestPool.cpp index 2cbf951d..ce1f8518 100644 --- a/tests/src/fsfw_tests/unit/storagemanager/TestPool.cpp +++ b/tests/src/fsfw_tests/unit/storagemanager/TestPool.cpp @@ -3,6 +3,7 @@ #include #include +#include #include "fsfw_tests/unit/CatchDefinitions.h"