1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#pragma once
#include "imessagebus.h"
#include "iradiant.h"
#include "messages/CommandExecutionFailed.h"
#include "command/ExecutionNotPossible.h"
namespace test
{
class CommandFailureHelper
{
private:
std::size_t _msgSubscription;
bool _messageReceived;
std::string _lastReceivedMessage;
bool _executionNotPossible;
public:
CommandFailureHelper() :
_messageReceived(false),
_executionNotPossible(false)
{
// Subscribe to the event asking for the target path
_msgSubscription = GlobalRadiantCore().getMessageBus().addListener(
radiant::IMessage::Type::CommandExecutionFailed,
radiant::TypeListener<radiant::CommandExecutionFailedMessage>(
[this](radiant::CommandExecutionFailedMessage& msg)
{
_messageReceived = true;
_lastReceivedMessage = msg.getMessage();
// Check the exception type more closely
_executionNotPossible = dynamic_cast<const cmd::ExecutionNotPossible*>(&msg.getException()) != nullptr;
}));
}
bool messageReceived() const
{
return _messageReceived;
}
bool executionHasNotBeenPossible() const
{
return _executionNotPossible;
}
const std::string& getLastReceivedMessage() const
{
return _lastReceivedMessage;
}
~CommandFailureHelper()
{
GlobalRadiantCore().getMessageBus().removeListener(_msgSubscription);
}
};
}
|