fnish CFDP distributor unittests
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
#include "fsfw/cfdp/CfdpDistributor.h"
|
||||
#include "fsfw/cfdp/pdu/MetadataPduCreator.h"
|
||||
#include "fsfw/storagemanager/LocalPool.h"
|
||||
#include "fsfw/tcdistribution/definitions.h"
|
||||
#include "mocks/AcceptsTcMock.h"
|
||||
#include "mocks/MessageQueueMock.h"
|
||||
#include "mocks/StorageManagerMock.h"
|
||||
@ -17,6 +18,8 @@ TEST_CASE("CFDP Distributor", "[cfdp][distributor]") {
|
||||
auto groundEntityId = cfdp::EntityId(UnsignedByteField<uint16_t>(1));
|
||||
MessageQueueId_t receiverQueueId = 3;
|
||||
auto tcAcceptor = AcceptsTcMock("CFDP Receiver", 0, receiverQueueId);
|
||||
|
||||
// Set up Metadata PDU for generate test data.
|
||||
cfdp::FileSize fileSize(12);
|
||||
const cfdp::EntityId& sourceId(groundEntityId);
|
||||
const cfdp::EntityId& destId(obswEntityId);
|
||||
@ -43,7 +46,8 @@ TEST_CASE("CFDP Distributor", "[cfdp][distributor]") {
|
||||
CHECK(distributor.registerTcDestination(obswEntityId, tcAcceptor) == result::OK);
|
||||
size_t serLen = 0;
|
||||
store_address_t storeId;
|
||||
CHECK(pool.LocalPool::getFreeElement(&storeId, creator.getSerializedSize(), &dataPtr) == result::OK);
|
||||
CHECK(pool.LocalPool::getFreeElement(&storeId, creator.getSerializedSize(), &dataPtr) ==
|
||||
result::OK);
|
||||
REQUIRE(creator.SerializeIF::serializeBe(dataPtr, serLen, creator.getSerializedSize()) ==
|
||||
result::OK);
|
||||
TmTcMessage msg(storeId);
|
||||
@ -57,4 +61,38 @@ TEST_CASE("CFDP Distributor", "[cfdp][distributor]") {
|
||||
CHECK(queue.getNextSentMessage(receiverQueueId, sentMsg) == result::OK);
|
||||
CHECK(sentMsg.getStorageId() == storeId);
|
||||
}
|
||||
|
||||
SECTION("No Destination found") {
|
||||
CHECK(distributor.initialize() == result::OK);
|
||||
size_t serLen = 0;
|
||||
store_address_t storeId;
|
||||
CHECK(pool.LocalPool::getFreeElement(&storeId, creator.getSerializedSize(), &dataPtr) ==
|
||||
result::OK);
|
||||
REQUIRE(creator.SerializeIF::serializeBe(dataPtr, serLen, creator.getSerializedSize()) ==
|
||||
result::OK);
|
||||
TmTcMessage msg(storeId);
|
||||
queue.addReceivedMessage(msg);
|
||||
CHECK(distributor.performOperation(0) == tmtcdistrib::NO_DESTINATION_FOUND);
|
||||
}
|
||||
|
||||
SECTION("Getting data fails") {
|
||||
pool.nextModifyDataCallFails.first = true;
|
||||
pool.nextModifyDataCallFails.second = StorageManagerIF::DATA_DOES_NOT_EXIST;
|
||||
size_t serLen = 0;
|
||||
store_address_t storeId;
|
||||
CHECK(distributor.registerTcDestination(obswEntityId, tcAcceptor) == result::OK);
|
||||
CHECK(pool.LocalPool::getFreeElement(&storeId, creator.getSerializedSize(), &dataPtr) ==
|
||||
result::OK);
|
||||
REQUIRE(creator.SerializeIF::serializeBe(dataPtr, serLen, creator.getSerializedSize()) ==
|
||||
result::OK);
|
||||
TmTcMessage msg(storeId);
|
||||
queue.addReceivedMessage(msg);
|
||||
CHECK(distributor.performOperation(0) == StorageManagerIF::DATA_DOES_NOT_EXIST);
|
||||
}
|
||||
|
||||
SECTION("Duplicate registration") {
|
||||
CHECK(distributor.initialize() == result::OK);
|
||||
CHECK(distributor.registerTcDestination(obswEntityId, tcAcceptor) == result::OK);
|
||||
CHECK(distributor.registerTcDestination(obswEntityId, tcAcceptor) == result::FAILED);
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@ ReturnValue_t StorageManagerMock::addData(store_address_t *storageId, const uint
|
||||
return LocalPool::addData(storageId, data, size, ignoreFault);
|
||||
}
|
||||
ReturnValue_t StorageManagerMock::deleteData(store_address_t packet_id) {
|
||||
if(nextDeleteDataCallFails.first) {
|
||||
if (nextDeleteDataCallFails.first) {
|
||||
return nextDeleteDataCallFails.second;
|
||||
}
|
||||
return LocalPool::deleteData(packet_id);
|
||||
@ -16,7 +16,7 @@ ReturnValue_t StorageManagerMock::deleteData(store_address_t packet_id) {
|
||||
|
||||
ReturnValue_t StorageManagerMock::deleteData(uint8_t *buffer, size_t size,
|
||||
store_address_t *storeId) {
|
||||
if(nextDeleteDataCallFails.first) {
|
||||
if (nextDeleteDataCallFails.first) {
|
||||
return nextDeleteDataCallFails.second;
|
||||
}
|
||||
return LocalPool::deleteData(buffer, size, storeId);
|
||||
@ -24,9 +24,6 @@ ReturnValue_t StorageManagerMock::deleteData(uint8_t *buffer, size_t size,
|
||||
|
||||
ReturnValue_t StorageManagerMock::getData(store_address_t packet_id, const uint8_t **packet_ptr,
|
||||
size_t *size) {
|
||||
if (nextGetDataCallFails.first) {
|
||||
return nextGetDataCallFails.second;
|
||||
}
|
||||
return LocalPool::getData(packet_id, packet_ptr, size);
|
||||
}
|
||||
|
||||
@ -49,9 +46,7 @@ ReturnValue_t StorageManagerMock::getFreeElement(store_address_t *storageId, siz
|
||||
bool StorageManagerMock::hasDataAtId(store_address_t storeId) const {
|
||||
return LocalPool::hasDataAtId(storeId);
|
||||
}
|
||||
void StorageManagerMock::clearStore() {
|
||||
return LocalPool::clearStore();
|
||||
}
|
||||
void StorageManagerMock::clearStore() { return LocalPool::clearStore(); }
|
||||
|
||||
void StorageManagerMock::clearSubPool(uint8_t poolIndex) {
|
||||
return LocalPool::clearSubPool(poolIndex);
|
||||
@ -75,8 +70,6 @@ void StorageManagerMock::reset() {
|
||||
nextAddDataCallFails.second = result::OK;
|
||||
nextModifyDataCallFails.first = false;
|
||||
nextModifyDataCallFails.second = result::OK;
|
||||
nextGetDataCallFails.first = false;
|
||||
nextGetDataCallFails.second = result::OK;
|
||||
nextDeleteDataCallFails.first = false;
|
||||
nextDeleteDataCallFails.second = result::OK;
|
||||
nextFreeElementCallFails.first = false;
|
||||
@ -85,5 +78,4 @@ void StorageManagerMock::reset() {
|
||||
|
||||
StorageManagerMock::StorageManagerMock(object_id_t setObjectId,
|
||||
const LocalPool::LocalPoolConfig &poolConfig)
|
||||
: LocalPool(setObjectId, poolConfig) {
|
||||
}
|
||||
: LocalPool(setObjectId, poolConfig) {}
|
||||
|
@ -4,9 +4,9 @@
|
||||
#include "fsfw/storagemanager/LocalPool.h"
|
||||
#include "fsfw/storagemanager/StorageManagerIF.h"
|
||||
|
||||
class StorageManagerMock: public LocalPool {
|
||||
class StorageManagerMock : public LocalPool {
|
||||
public:
|
||||
StorageManagerMock(object_id_t setObjectId, const LocalPoolConfig& poolConfig);
|
||||
StorageManagerMock(object_id_t setObjectId, const LocalPoolConfig &poolConfig);
|
||||
|
||||
ReturnValue_t addData(store_address_t *storageId, const uint8_t *data, size_t size,
|
||||
bool ignoreFault) override;
|
||||
@ -25,8 +25,11 @@ class StorageManagerMock: public LocalPool {
|
||||
[[nodiscard]] max_subpools_t getNumberOfSubPools() const override;
|
||||
|
||||
std::pair<bool, ReturnValue_t> nextAddDataCallFails;
|
||||
/**
|
||||
* This can be used to make both the modify and get API call fail. This is because generally,
|
||||
* the pool implementation get functions will use the modify API internally.
|
||||
*/
|
||||
std::pair<bool, ReturnValue_t> nextModifyDataCallFails;
|
||||
std::pair<bool, ReturnValue_t> nextGetDataCallFails;
|
||||
std::pair<bool, ReturnValue_t> nextDeleteDataCallFails;
|
||||
std::pair<bool, ReturnValue_t> nextFreeElementCallFails;
|
||||
void reset();
|
||||
|
Reference in New Issue
Block a user