more tests, minor bugfix
This commit is contained in:
parent
41d8cbda55
commit
4255176b5c
@ -100,8 +100,8 @@ public:
|
||||
return vectorSize;
|
||||
}
|
||||
|
||||
T& operator [](int i);
|
||||
const T &operator [](int i) const;
|
||||
T& operator [](size_t i);
|
||||
const T &operator [](size_t i) const;
|
||||
|
||||
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
const size_t maxSize,
|
||||
@ -126,6 +126,7 @@ public:
|
||||
ReturnValue_t read(MutexIF::TimeoutType timeoutType =
|
||||
MutexIF::TimeoutType::WAITING,
|
||||
uint32_t timeoutMs = 20) override;
|
||||
|
||||
/**
|
||||
* @brief The commit call copies the array values back to the data pool.
|
||||
* @details
|
||||
|
@ -91,8 +91,8 @@ inline ReturnValue_t LocalPoolVector<T, vectorSize>::commitWithoutLock() {
|
||||
}
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline T& LocalPoolVector<T, vectorSize>::operator [](int i) {
|
||||
if(i <= vectorSize) {
|
||||
inline T& LocalPoolVector<T, vectorSize>::operator [](size_t i) {
|
||||
if(i < vectorSize) {
|
||||
return value[i];
|
||||
}
|
||||
// If this happens, I have to set some value. I consider this
|
||||
@ -100,13 +100,16 @@ inline T& LocalPoolVector<T, vectorSize>::operator [](int i) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "LocalPoolVector: Invalid index. Setting or returning"
|
||||
" last value!" << std::endl;
|
||||
#else
|
||||
fsfw::printError("LocalPoolVector: Invalid index. Setting or returning"
|
||||
" last value!\n\r");
|
||||
#endif
|
||||
return value[i];
|
||||
return value[vectorSize];
|
||||
}
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline const T& LocalPoolVector<T, vectorSize>::operator [](int i) const {
|
||||
if(i <= vectorSize) {
|
||||
inline const T& LocalPoolVector<T, vectorSize>::operator [](size_t i) const {
|
||||
if(i < vectorSize) {
|
||||
return value[i];
|
||||
}
|
||||
// If this happens, I have to set some value. I consider this
|
||||
@ -114,8 +117,11 @@ inline const T& LocalPoolVector<T, vectorSize>::operator [](int i) const {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "LocalPoolVector: Invalid index. Setting or returning"
|
||||
" last value!" << std::endl;
|
||||
#else
|
||||
fsfw::printError("LocalPoolVector: Invalid index. Setting or returning"
|
||||
" last value!\n\r");
|
||||
#endif
|
||||
return value[i];
|
||||
return value[vectorSize];
|
||||
}
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
|
@ -16,7 +16,7 @@ TEST_CASE("LocalPoolVector" , "[LocPoolVecTest]") {
|
||||
// very basic test.
|
||||
lp_vec_t<uint16_t, 3> testVector = lp_vec_t<uint16_t, 3>(
|
||||
objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint16Vec3Id);
|
||||
CHECK(testVector.read() == retval::CATCH_OK);
|
||||
REQUIRE(testVector.read() == retval::CATCH_OK);
|
||||
testVector.value[0] = 5;
|
||||
testVector.value[1] = 232;
|
||||
testVector.value[2] = 32023;
|
||||
@ -32,6 +32,38 @@ TEST_CASE("LocalPoolVector" , "[LocPoolVecTest]") {
|
||||
CHECK(testVector.value[0] == 5);
|
||||
CHECK(testVector.value[1] == 232);
|
||||
CHECK(testVector.value[2] == 32023);
|
||||
|
||||
CHECK(testVector[0] == 5);
|
||||
|
||||
// This is invalid access, so the last value will be set instead.
|
||||
// (we can't throw exceptions)
|
||||
testVector[4] = 12;
|
||||
CHECK(testVector[3] == 12);
|
||||
CHECK(testVector.commit() == retval::CATCH_OK);
|
||||
|
||||
// Use read-only reference.
|
||||
const lp_vec_t<uint16_t, 3>& roTestVec = testVector;
|
||||
uint16_t valueOne = roTestVec[0];
|
||||
CHECK(valueOne == 5);
|
||||
|
||||
uint16_t lastVal = roTestVec[25];
|
||||
CHECK(lastVal == 12);
|
||||
}
|
||||
|
||||
SECTION("ErrorHandling") {
|
||||
// not try to use a local pool variable which does not exist
|
||||
lp_vec_t<uint16_t, 3> invalidVector = lp_vec_t<uint16_t, 3>(
|
||||
objects::TEST_LOCAL_POOL_OWNER_BASE, 0xffffffff);
|
||||
REQUIRE(invalidVector.read() ==
|
||||
static_cast<int>(HasLocalDataPoolIF::POOL_ENTRY_NOT_FOUND));
|
||||
REQUIRE(invalidVector.commit() ==
|
||||
static_cast<int>(HasLocalDataPoolIF::POOL_ENTRY_NOT_FOUND));
|
||||
|
||||
// now try to access with wrong type
|
||||
lp_vec_t<uint32_t, 3> invalidVector2 = lp_vec_t<uint32_t, 3>(
|
||||
objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint16Vec3Id);
|
||||
REQUIRE(invalidVector2.read() ==
|
||||
static_cast<int>(HasLocalDataPoolIF::POOL_ENTRY_TYPE_CONFLICT));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user