forked from eclipse-paho/paho.mqtt.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_response_options.cpp
145 lines (112 loc) · 4.71 KB
/
test_response_options.cpp
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// test_response_options.cpp
//
// Unit tests for the response_options class in the Paho MQTT C++ library.
//
/*******************************************************************************
* Copyright (c) 2016 Guilherme M. Ferreira <[email protected]>
* Copyright (c) 2020-2023 Frank Pagliughi <[email protected]>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v20.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
* Frank Pagliughi
* - converted to use Catch2
* - Merged in delivery response options
*******************************************************************************/
#define UNIT_TESTS
#include <cstring>
#include "catch2_version.h"
#include "mqtt/response_options.h"
#include "mock_async_client.h"
using namespace mqtt;
/////////////////////////////////////////////////////////////////////////////
static constexpr token::Type TOKEN_TYPE = token::Type::CONNECT;
static mock_async_client cli;
// ----------------------------------------------------------------------
// Test default constructor
// ----------------------------------------------------------------------
TEST_CASE("response_options dflt constructor", "[options]")
{
mqtt::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("response_options user constructor", "[options]")
{
mqtt::token_ptr token { mqtt::token::create(TOKEN_TYPE, cli) };
mqtt::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("response_options set token", "[options]")
{
mqtt::response_options opts;
const auto& c_struct = opts.c_struct();
REQUIRE(c_struct.context == nullptr);
mqtt::token_ptr token { mqtt::token::create(TOKEN_TYPE, cli) };
opts.set_token( token );
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]")
{
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);
mock_async_client cli;
mqtt::delivery_token_ptr token { new mqtt::delivery_token{ cli } };
opts.set_token( token );
REQUIRE(c_struct.context == token.get());
}