1
0
mirror of https://github.com/eclipse/paho.mqtt.cpp.git synced 2025-05-09 03:11:23 +08:00

Moved delivery_response_options unit tests to Catch2. Merged with response_options

This commit is contained in:
fpagliughi 2020-10-24 12:09:27 -04:00
parent 095b4e166b
commit f5e0d7f1cf
4 changed files with 67 additions and 105 deletions

View File

@ -106,6 +106,12 @@ public:
*/
delivery_response_options(const delivery_token_ptr& dtok,
int mqttVersion=MQTTVERSION_DEFAULT);
/**
* Expose the underlying C struct for the unit tests.
*/
#if defined(UNIT_TESTS)
const MQTTAsync_responseOptions& c_struct() const { return opts_; }
#endif
/**
* Sets the callback context to a delivery token.
* @param dtok The delivery token to be used as the callback context.

View File

@ -1,101 +0,0 @@
// delivery_response_options_test.h
// Unit tests for the delivery_response_options class in the Paho MQTT C++ library.
/*******************************************************************************
* Copyright (c) 2016 Guilherme M. Ferreira <guilherme.maciel.ferreira@gmail.com>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Guilherme M. Ferreira - initial implementation and documentation
*******************************************************************************/
#ifndef __mqtt_delivery_response_options_test_h
#define __mqtt_delivery_response_options_test_h
#include <cppunit/ui/text/TestRunner.h>
#include <cppunit/extensions/HelperMacros.h>
#include "mqtt/response_options.h"
#include "dummy_async_client.h"
namespace mqtt {
/////////////////////////////////////////////////////////////////////////////
class delivery_response_options_test : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( delivery_response_options_test );
CPPUNIT_TEST( test_dflt_constructor );
CPPUNIT_TEST( test_user_constructor );
CPPUNIT_TEST( test_set_token );
CPPUNIT_TEST_SUITE_END();
public:
void setUp() {}
void tearDown() {}
// ----------------------------------------------------------------------
// Test default constructor
// ----------------------------------------------------------------------
void test_dflt_constructor() {
mqtt::delivery_response_options opts;
MQTTAsync_responseOptions& c_struct = opts.opts_;
CPPUNIT_ASSERT(c_struct.context == nullptr);
// Make sure the callback functions are set during object construction
CPPUNIT_ASSERT(c_struct.onSuccess != nullptr);
CPPUNIT_ASSERT(c_struct.onFailure != nullptr);
}
// ----------------------------------------------------------------------
// Test user constructor
// ----------------------------------------------------------------------
void test_user_constructor() {
mqtt::test::dummy_async_client client;
mqtt::delivery_token_ptr token { new mqtt::delivery_token{ client } };
mqtt::delivery_response_options opts { token };
MQTTAsync_responseOptions& c_struct = opts.opts_;
CPPUNIT_ASSERT(c_struct.context == token.get());
// Make sure the callback functions are set during object construction
CPPUNIT_ASSERT(c_struct.onSuccess != nullptr);
CPPUNIT_ASSERT(c_struct.onFailure != nullptr);
}
// ----------------------------------------------------------------------
// Test set context
// ----------------------------------------------------------------------
void test_set_token() {
mqtt::delivery_response_options opts;
MQTTAsync_responseOptions& c_struct = opts.opts_;
CPPUNIT_ASSERT(c_struct.context == nullptr);
mqtt::test::dummy_async_client client;
mqtt::delivery_token_ptr token { new mqtt::delivery_token{ client } };
opts.set_token( token );
CPPUNIT_ASSERT(c_struct.context == token.get());
}
};
/////////////////////////////////////////////////////////////////////////////
// end namespace 'mqtt'
}
#endif // __mqtt_delivery_response_options_test_h

View File

@ -20,7 +20,6 @@
#include "async_client_test.h"
#include "async_client_v3_test.h"
#include "client_test.h"
#include "delivery_response_options_test.h"
#include "iclient_persistence_test.h"
#include "token_test.h"
@ -30,7 +29,6 @@ using namespace CppUnit;
int main(int argc, char* argv[])
{
CPPUNIT_TEST_SUITE_REGISTRATION( mqtt::delivery_response_options_test );
CPPUNIT_TEST_SUITE_REGISTRATION( mqtt::iclient_persistence_test );
CPPUNIT_TEST_SUITE_REGISTRATION( mqtt::token_test );

View File

@ -17,8 +17,11 @@
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Guilherme M. Ferreira - initial implementation and documentation
* Frank Pagliughi - converted to use Catch2
* Guilherme M. Ferreira
* - initial implementation and documentation
* Frank Pagliughi
* - converted to use Catch2
* - Merged in delivery response options
*******************************************************************************/
#define UNIT_TESTS
@ -84,3 +87,59 @@ TEST_CASE("response_options set token", "[options]")
REQUIRE(c_struct.context == token.get());
}
/////////////////////////////////////////////////////////////////////////////
// Delivery Response Options
/////////////////////////////////////////////////////////////////////////////
// ----------------------------------------------------------------------
// Test default constructor
// ----------------------------------------------------------------------
TEST_CASE("delivery_response_options dflt constructor", "[options]")
{
mqtt::delivery_response_options opts;
const auto& c_struct = opts.c_struct();
REQUIRE(c_struct.context == nullptr);
// Make sure the callback functions are set during object construction
REQUIRE(c_struct.onSuccess != nullptr);
REQUIRE(c_struct.onFailure != nullptr);
}
// ----------------------------------------------------------------------
// Test user constructor
// ----------------------------------------------------------------------
TEST_CASE("delivery_response_options user constructor", "[options]")
{
mqtt::test::mock_async_client cli;
mqtt::delivery_token_ptr token { new mqtt::delivery_token{ cli } };
mqtt::delivery_response_options opts { token };
const auto& c_struct = opts.c_struct();
REQUIRE(c_struct.context == token.get());
// Make sure the callback functions are set during object construction
REQUIRE(c_struct.onSuccess != nullptr);
REQUIRE(c_struct.onFailure != nullptr);
}
// ----------------------------------------------------------------------
// Test set context
// ----------------------------------------------------------------------
TEST_CASE("delivery_response_options set token", "[options]")
{
mqtt::delivery_response_options opts;
const auto& c_struct = opts.c_struct();
REQUIRE(c_struct.context == nullptr);
mqtt::test::mock_async_client cli;
mqtt::delivery_token_ptr token { new mqtt::delivery_token{ cli } };
opts.set_token( token );
REQUIRE(c_struct.context == token.get());
}