-
Notifications
You must be signed in to change notification settings - Fork 440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing virtual keyword for some funcktions #411
Comments
Hi @Hadatko, I have the exact same need: I would like to override some methods in my unit tests. Have you found a workaround for this issue? |
Hi @StefanoLusardi , yesterday i wrote you nice answer but it looks like i didn't send it :'( So once again :
class MqttClientPaho : public mqtt::client
{
public:
/**
* @brief Construct a new Mqtt Client Paho object
*
* @param[in] serverURI mqtt server address
* @param[in] clientId client identifier
* @param[in] opts paho client options passed by the user
*/
MqttClientPaho(const std::string &serverURI, const std::string &clientId, const mqtt::create_options &opts);
/**
* @brief Calls the start_consuming paho library method
*/
virtual void startConsuming(void);
/**
* @brief Calls the consume_message paho library method
*
* @return mqtt::const_message_ptr consumed message to be processed further
*/
virtual mqtt::const_message_ptr consumeMessage(void);
};
MqttClientPaho::MqttClientPaho(const std::string &serverURI, const std::string &clientId,
const mqtt::create_options &opts) :
client(serverURI, clientId, opts)
{
}
void MqttClientPaho::startConsuming(void) { start_consuming(); }
mqtt::const_message_ptr MqttClientPaho::consumeMessage(void) { return consume_message(); }
MqttClient::MqttClient(MqttClientPaho &client, const std::string &topic, LogCb *logCb) :
SetLogCb(logCb), m_client(client), m_topic(topic), m_receiveLoopThread(nullptr), m_deinit(true)
{
}
class MockMqttClientPaho : public aeler::MqttClientPaho
{
public:
MockMqttClientPaho(const std::string &serverURI = "uri", const std::string &clientId = "clientId",
const mqtt::create_options &opts = mqtt::create_options()) :
aeler::MqttClientPaho(serverURI, clientId, opts){};
MOCK_METHOD(void, disconnect, (), (override));
MOCK_METHOD(mqtt::connect_response, connect, (mqtt::connect_options opts), (override));
MOCK_METHOD(mqtt::subscribe_response, subscribe,
(const std::string &topicFilter, int qos, const mqtt::subscribe_options &opts,
const mqtt::properties &props),
(override));
MOCK_METHOD(void, startConsuming, (), (override));
MOCK_METHOD(mqtt::const_message_ptr, consumeMessage, (), (override));
MOCK_METHOD(bool, is_connected, (), (const, override));
MOCK_METHOD(void, publish, (mqtt::string_ref top, const void *payload, size_t n), (override));
};
::testing::StrictMock<MockMqttClientPaho> clientPaho;
mqtt::mock_async_client ac;
mqtt::token conToken(mqtt::token::CONNECT, ac);
MQTTAsync_successData conData;
conData.alt.connect.sessionPresent = false;
conData.alt.connect.serverURI = const_cast<char *>("tcp://some_server.com");
mqtt::mock_async_client::succeed(&conToken, &conData);
MQTTAsync_successData subData;
mqtt::token subToken(mqtt::token::SUBSCRIBE, ac);
mqtt::mock_async_client::succeed(&subToken, &subData);
EXPECT_CALL(clientPaho, connect).WillOnce(::testing::Return(conToken.get_connect_response()));
EXPECT_CALL(clientPaho, subscribe).WillOnce(::testing::Return(subToken.get_subscribe_response()));
EXPECT_CALL(clientPaho, publish).Times(1);
EXPECT_CALL(clientPaho, publish).WillOnce(MqttException()).RetiresOnSaturation();
EXPECT_CALL(clientPaho, startConsuming).Times(1);
EXPECT_CALL(clientPaho, consumeMessage).WillRepeatedly(::testing::Return(nullptr));
EXPECT_CALL(clientPaho, is_connected).WillOnce(::testing::Return(true)).WillOnce(::testing::Return(false));
EXPECT_CALL(clientPaho, disconnect).Times(1); |
Apologies. Just back from holiday and catching up on issues... This was probably just an oversight. I will add the |
Done. Also for the async client. Re-open this if I missed any. |
Hi,
in class
class client : private callback
are most of functions virtual but some of them are not (most of them at the bottom). Is there reason why not? I would like to override implementation with my google tests for testing purpose:The text was updated successfully, but these errors were encountered: