2021-01-04 00:21:44 +01:00
|
|
|
#include "LocalPoolOwnerBase.h"
|
|
|
|
|
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
|
|
#include <fsfw/datapoollocal/HasLocalDataPoolIF.h>
|
|
|
|
#include <unittest/core/CatchDefinitions.h>
|
|
|
|
|
|
|
|
|
|
|
|
TEST_CASE("LocalPoolVariable" , "[LocPoolVarTest]") {
|
2021-01-06 21:14:23 +01:00
|
|
|
LocalPoolOwnerBase* poolOwner = objectManager->
|
|
|
|
get<LocalPoolOwnerBase>(objects::TEST_LOCAL_POOL_OWNER_BASE);
|
|
|
|
REQUIRE(poolOwner != nullptr);
|
|
|
|
REQUIRE(poolOwner->initializeHkManager() == retval::CATCH_OK);
|
|
|
|
REQUIRE(poolOwner->initializeHkManagerAfterTaskCreation()
|
2021-01-04 00:21:44 +01:00
|
|
|
== retval::CATCH_OK);
|
|
|
|
|
2021-01-05 22:46:17 +01:00
|
|
|
SECTION("Basic Tests") {
|
|
|
|
// very basic test.
|
|
|
|
lp_var_t<uint8_t> testVariable = lp_var_t<uint8_t>(
|
|
|
|
objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint8VarId);
|
|
|
|
REQUIRE(testVariable.read() == retval::CATCH_OK);
|
|
|
|
CHECK(testVariable.value == 0);
|
|
|
|
testVariable.value = 5;
|
|
|
|
REQUIRE(testVariable.commit() == retval::CATCH_OK);
|
|
|
|
REQUIRE(testVariable.read() == retval::CATCH_OK);
|
|
|
|
REQUIRE(testVariable.value == 5);
|
|
|
|
CHECK(not testVariable.isValid());
|
2021-01-05 22:51:49 +01:00
|
|
|
testVariable.setValid(true);
|
|
|
|
CHECK(testVariable.isValid());
|
2021-01-08 20:44:05 +01:00
|
|
|
CHECK(testVariable.commit(true) == retval::CATCH_OK);
|
2021-01-05 22:46:17 +01:00
|
|
|
|
2021-01-06 21:14:23 +01:00
|
|
|
testVariable.setReadWriteMode(pool_rwm_t::VAR_READ);
|
|
|
|
CHECK(testVariable.getReadWriteMode() == pool_rwm_t::VAR_READ);
|
|
|
|
testVariable.setReadWriteMode(pool_rwm_t::VAR_READ_WRITE);
|
|
|
|
|
|
|
|
testVariable.setDataPoolId(22);
|
|
|
|
CHECK(testVariable.getDataPoolId() == 22);
|
|
|
|
testVariable.setDataPoolId(lpool::uint8VarId);
|
|
|
|
|
|
|
|
testVariable.setChanged(true);
|
|
|
|
CHECK(testVariable.hasChanged());
|
|
|
|
testVariable.setChanged(false);
|
|
|
|
|
2021-01-06 18:20:38 +01:00
|
|
|
gp_id_t globPoolId(objects::TEST_LOCAL_POOL_OWNER_BASE,
|
|
|
|
lpool::uint8VarId);
|
|
|
|
lp_var_t<uint8_t> testVariable2 = lp_var_t<uint8_t>(globPoolId);
|
2021-01-06 19:07:35 +01:00
|
|
|
REQUIRE(testVariable2.read() == retval::CATCH_OK);
|
|
|
|
CHECK(testVariable2 == 5);
|
|
|
|
CHECK(testVariable == testVariable2);
|
|
|
|
testVariable = 10;
|
|
|
|
CHECK(testVariable != 5);
|
|
|
|
//CHECK(not testVariable != testVariable2);
|
|
|
|
uint8_t variableRaw = 0;
|
|
|
|
uint8_t* varPtr = &variableRaw;
|
|
|
|
size_t maxSize = testVariable.getSerializedSize();
|
|
|
|
CHECK(maxSize == 1);
|
|
|
|
size_t serSize = 0;
|
|
|
|
CHECK(testVariable.serialize(&varPtr, &serSize, maxSize,
|
|
|
|
SerializeIF::Endianness::MACHINE) == retval::CATCH_OK);
|
|
|
|
CHECK(variableRaw == 10);
|
|
|
|
const uint8_t* varConstPtr = &variableRaw;
|
|
|
|
testVariable = 5;
|
|
|
|
CHECK(testVariable.deSerialize(&varConstPtr, &serSize,
|
|
|
|
SerializeIF::Endianness::MACHINE) == retval::CATCH_OK);
|
|
|
|
CHECK(testVariable == 10);
|
2021-01-06 19:16:41 +01:00
|
|
|
CHECK(testVariable != testVariable2);
|
|
|
|
CHECK(testVariable2 < testVariable);
|
|
|
|
CHECK(testVariable2 < 10);
|
|
|
|
CHECK(testVariable > 5);
|
|
|
|
CHECK(testVariable > testVariable2);
|
|
|
|
variableRaw = static_cast<uint8_t>(testVariable2);
|
|
|
|
CHECK(variableRaw == 5);
|
|
|
|
|
|
|
|
CHECK(testVariable == 10);
|
|
|
|
testVariable = testVariable2;
|
|
|
|
CHECK(testVariable == 5);
|
2021-01-06 18:20:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("ErrorHandling") {
|
|
|
|
|
2021-01-05 22:46:17 +01:00
|
|
|
// not try to use a local pool variable which does not exist
|
|
|
|
lp_var_t<uint8_t> invalidVariable = lp_var_t<uint8_t>(
|
|
|
|
objects::TEST_LOCAL_POOL_OWNER_BASE, 0xffffffff);
|
|
|
|
REQUIRE(invalidVariable.read() ==
|
2021-01-12 20:33:53 +01:00
|
|
|
static_cast<int>(localpool::POOL_ENTRY_NOT_FOUND));
|
2021-01-05 22:46:17 +01:00
|
|
|
|
2021-01-06 18:20:38 +01:00
|
|
|
REQUIRE(invalidVariable.commit() ==
|
2021-01-12 20:33:53 +01:00
|
|
|
static_cast<int>(localpool::POOL_ENTRY_NOT_FOUND));
|
2021-01-05 22:46:17 +01:00
|
|
|
// now try to access with wrong type
|
|
|
|
lp_var_t<int8_t> invalidVariable2 = lp_var_t<int8_t>(
|
|
|
|
objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint8VarId);
|
|
|
|
REQUIRE(invalidVariable2.read() ==
|
2021-01-12 20:33:53 +01:00
|
|
|
static_cast<int>(localpool::POOL_ENTRY_TYPE_CONFLICT));
|
2021-01-05 22:46:17 +01:00
|
|
|
|
2021-01-05 22:51:49 +01:00
|
|
|
lp_var_t<uint8_t> readOnlyVar = lp_var_t<uint8_t>(
|
2021-01-05 22:46:17 +01:00
|
|
|
objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint8VarId,
|
|
|
|
nullptr, pool_rwm_t::VAR_READ);
|
|
|
|
REQUIRE(readOnlyVar.commit() ==
|
|
|
|
static_cast<int>(PoolVariableIF::INVALID_READ_WRITE_MODE));
|
2021-01-05 22:51:49 +01:00
|
|
|
lp_var_t<uint8_t> writeOnlyVar = lp_var_t<uint8_t>(
|
|
|
|
objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint8VarId,
|
|
|
|
nullptr, pool_rwm_t::VAR_WRITE);
|
|
|
|
REQUIRE(writeOnlyVar.read() == static_cast<int>(
|
|
|
|
PoolVariableIF::INVALID_READ_WRITE_MODE));
|
|
|
|
|
|
|
|
lp_var_t<uint32_t> uint32tVar = lp_var_t<uint32_t>(
|
|
|
|
objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint32VarId);
|
2021-01-06 19:32:33 +01:00
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2021-01-05 22:51:49 +01:00
|
|
|
sif::info << "LocalPoolVariable printout: " <<uint32tVar << std::endl;
|
2021-01-06 19:32:33 +01:00
|
|
|
#endif
|
2021-01-06 21:14:23 +01:00
|
|
|
|
|
|
|
// for code coverage. If program does not crash -> OK
|
|
|
|
lp_var_t<uint8_t> invalidObjectVar = lp_var_t<uint8_t>(
|
|
|
|
0xffffffff, lpool::uint8VarId);
|
|
|
|
gp_id_t globPoolId(0xffffffff,
|
|
|
|
lpool::uint8VarId);
|
|
|
|
lp_var_t<uint8_t> invalidObjectVar2 = lp_var_t<uint8_t>(globPoolId);
|
|
|
|
lp_var_t<uint8_t> invalidObjectVar3 = lp_var_t<uint8_t>(nullptr,
|
|
|
|
lpool::uint8VarId);
|
2021-01-05 22:46:17 +01:00
|
|
|
}
|
|
|
|
|
2021-01-04 00:21:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|