31 #if !defined(_WINDOWS) 33 #include <sys/socket.h> 40 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) 72 if (strcmp(argv[count],
"--test_no") == 0)
79 else if (strcmp(argv[count],
"--size") == 0)
86 else if (strcmp(argv[count],
"--connection") == 0)
93 else if (strcmp(argv[count],
"--MQTTversion") == 0)
103 else if (strcmp(argv[count],
"--iterations") == 0)
110 else if (strcmp(argv[count],
"--verbose") == 0)
118 #define MyLog logaLine 124 #include <sys/timeb.h> 129 #if defined(_WIN32) || defined(_WINDOWS) 139 #if defined(_WIN32) || defined(_WINDOWS) 143 gettimeofday(&ts, NULL);
146 strftime(msg_buf, 80,
"%Y%m%d %H%M%S", timeinfo);
148 #if defined(_WIN32) || defined(_WINDOWS) 149 sprintf(&msg_buf[strlen(msg_buf)],
".%.3hu ", ts.millitm);
151 sprintf(&msg_buf[strlen(msg_buf)],
".%.3lu ", ts.tv_usec / 1000);
154 va_start(args, format);
155 vsnprintf(&msg_buf[strlen(msg_buf)],
sizeof(msg_buf) - strlen(msg_buf), format, args);
158 printf(
"%s\n", msg_buf);
164 #if defined(_WIN32) || defined(_WINDOWS) 165 #define mqsleep(A) Sleep(1000*A) 166 #define START_TIME_TYPE DWORD 167 static DWORD start_time = 0;
170 return GetTickCount();
173 #define mqsleep sleep 174 #define START_TIME_TYPE struct timespec 177 static struct timespec start;
178 clock_gettime(CLOCK_REALTIME, &start);
182 #define mqsleep sleep 183 #define START_TIME_TYPE struct timeval 187 struct timeval start_time;
188 gettimeofday(&start_time, NULL);
197 return GetTickCount() - start_time;
201 long elapsed(
struct timespec start)
203 struct timespec now, res;
205 clock_gettime(CLOCK_REALTIME, &now);
206 ntimersub(now, start, res);
207 return (res.tv_sec)*1000L + (res.tv_nsec)/1000000L;
212 struct timeval now, res;
214 gettimeofday(&now, NULL);
215 timersub(&now, &start_time, &res);
216 return (res.tv_sec)*1000 + (res.tv_usec)/1000;
220 #define assert(a, b, c, d) myassert(__FILE__, __LINE__, a, b, c, d) 221 #define assert1(a, b, c, d, e) myassert(__FILE__, __LINE__, a, b, c, d, e) 234 fprintf(
xml,
" time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000);
240 fprintf(
xml,
"</testcase>\n");
251 printf(
"Assertion failed, file %s, line %d, description: %s\n", filename, lineno, description);
253 va_start(args, format);
254 vprintf(format, args);
258 description, filename, lineno);
261 MyLog(
LOGA_DEBUG,
"Assertion succeeded, file %s, line %d, description: %s", filename, lineno, description);
269 for (i = 0; i < props->
count; ++i)
273 char* intformat =
"Property name %s value %d";
311 0,
"client topic aliases topic", 0
326 static int received = 0;
333 const int props_count = 0;
339 "Topic name was %s\n", topicName);
365 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
372 property.value.integer2 = 1;
407 static int first = 1;
409 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback, context %p", context);
412 "Reason code was %d\n", response->
reasonCode);
420 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
427 property.value.integer2 = 0;
464 char*
test_topic =
"V5 C client test client topic aliases";
468 fprintf(
xml,
"<testcase classname=\"test11\" name=\"client topic aliases\"");
503 property.value.integer4 = 30;
507 property.value.data.data =
"test user property";
508 property.value.data.len = (int)strlen(property.
value.
data.data);
509 property.value.value.data =
"test user property value";
510 property.value.value.len = (int)strlen(property.
value.value.
data);
562 "server topic aliases topic", 0, 0, 3
569 static int received = 0;
570 static int first_topic_alias = 0;
578 const int props_count = 0;
585 first_topic_alias = topicAlias;
587 "Topic name was %s\n", topicName);
591 assert(
"All topic aliases should be the same", topicAlias == first_topic_alias,
592 "Topic alias was %d\n", topicAlias);
593 assert(
"Topic should be 0 length", strcmp(topicName,
"") == 0,
594 "Topic name was %s\n", topicName);
597 assert(
"topicAlias should not be 0", topicAlias > 0,
"Topic alias was %d\n", topicAlias);
623 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
646 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback, context %p", context);
649 "Reason code was %d\n", response->
reasonCode);
677 char*
test_topic =
"V5 C client test server topic aliases";
681 fprintf(
xml,
"<testcase classname=\"test11\" name=\"server topic aliases\"");
699 property.value.integer2 = 1;
745 "server subscription ids topic", 0, 0
762 int subsidcount = 0, i = 0;
766 for (i = 0; i < subsidcount; ++i)
769 assert(
"Subsid is i+1", subsid == i+1,
"subsid is not correct %d\n", subsid);
790 static int subs_count = 0;
795 if (++subs_count == 1)
799 property.value.integer4 = 2;
815 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
834 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback, context %p", context);
837 "Reason code was %d\n", response->
reasonCode);
846 property.value.integer4 = 1;
866 fprintf(
xml,
"<testcase classname=\"test11\" name=\"subscription ids\"");
924 "flow control topic", 0, 0, 65535, 0
964 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
985 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback, context %p", context);
988 "Reason code was %d\n", response->
reasonCode);
1010 static char* msg =
"Blocking on server receive maximum";
1012 if (strstr(message, msg) != NULL)
1025 fprintf(
xml,
"<testcase classname=\"test11\" name=\"flow control\"");
1081 "error reporting topic", 0, 0
1094 assert(
"Reason code count should be 2", response->
alt.
unsub.reasonCodeCount == 2,
1095 "Reason code count was %d\n", response->
alt.
unsub.reasonCodeCount);
1097 if (response->
alt.
unsub.reasonCodeCount == 1)
1099 else if (response->
alt.
unsub.reasonCodeCount > 1)
1101 for (i = 0; i < response->
alt.
unsub.reasonCodeCount; ++i)
1123 assert(
"Reason code count should be 2", response->
alt.
sub.reasonCodeCount == 2,
1124 "Reason code count was %d\n", response->
alt.
sub.reasonCodeCount);
1126 if (response->
alt.
sub.reasonCodeCount == 1)
1128 else if (response->
alt.
sub.reasonCodeCount > 1)
1130 for (i = 0; i < response->
alt.
sub.reasonCodeCount; ++i)
1140 property.value.data.data =
"test user property";
1141 property.value.data.len = (int)strlen(property.
value.
data.data);
1142 property.value.value.data =
"test user property value";
1143 property.value.value.len = (int)strlen(property.
value.value.
data);
1160 int qoss[2] = {2, 2};
1164 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback, context %p", context);
1167 "Reason code was %d\n", response->
reasonCode);
1176 property.value.data.data =
"test user property";
1177 property.value.data.len = (int)strlen(property.
value.
data.data);
1178 property.value.value.data =
"test user property value";
1179 property.value.value.len = (int)strlen(property.
value.value.
data);
1202 fprintf(
xml,
"<testcase classname=\"test11\" name=\"error reporting\"");
1252 0,
"test_qos_1_2_errors" 1259 MyLog(
LOGA_DEBUG,
"Callback: publish success, reason code \"%s\" msgid: %d",
1273 MyLog(
LOGA_DEBUG,
"Callback: publish failure, reason code \"%s\" msgid: %d packet type: %d",
1290 MyLog(
LOGA_DEBUG,
"Callback: publish failure, reason code \"%s\" msgid: %d packet type: %d",
1299 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
1305 property.value.data.data =
"pub user property";
1306 property.value.data.len = (int)strlen(property.
value.
data.data);
1307 property.value.value.data =
"pub user property value";
1308 property.value.value.len = (int)strlen(property.
value.value.
data);
1328 MyLog(
LOGA_DEBUG,
"Callback: publish failure, reason code \"%s\" msgid: %d packet type: %d",
1337 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
1343 property.value.data.data =
"pub user property";
1344 property.value.data.len = (int)strlen(property.
value.
data.data);
1345 property.value.value.data =
"pub user property value";
1346 property.value.value.len = (int)strlen(property.
value.value.
data);
1366 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback, context %p", context);
1369 "Reason code was %d\n", response->
reasonCode);
1378 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
1384 property.value.data.data =
"pub user property";
1385 property.value.data.len = (int)strlen(property.
value.
data.data);
1386 property.value.value.data =
"pub user property value";
1387 property.value.value.len = (int)strlen(property.
value.value.
data);
1407 fprintf(
xml,
"<testcase classname=\"test11\" name=\"qos 1 and 2 errors\"");
1462 "test_7_correlation_id",
1486 MQTTProperty *corr_prop = NULL, *response_topic_prop = NULL;
1489 char myTopicName[100];
1491 assert(
"Topic should be request",
1493 "topic was %s\n", topicName);
1498 assert(
"Topic should be response",
1500 response_topic_prop->value.data.len) == 0,
1501 "topic was %.4s\n", response_topic_prop->value.data.data);
1506 assert(
"Correlation data should be",
1509 "Correlation data was %.4s\n", corr_prop->
value.
data.data);
1512 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
1519 property.value.data.len = (int)strlen(property.
value.
data.data);
1522 memcpy(myTopicName, response_topic_prop->value.data.data, response_topic_prop->value.data.len);
1523 myTopicName[response_topic_prop->value.data.len] =
'\0';
1536 assert(
"Topic should be response",
1538 "topic was %s\n", topicName);
1543 assert(
"Correlation data should be",
1546 "Correlation data was %.4s\n", corr_prop->
value.
data.data);
1571 assert(
"Reason code count should be 2", response->
alt.
sub.reasonCodeCount == 2,
1572 "Reason code count was %d\n", response->
alt.
sub.reasonCodeCount);
1574 if (response->
alt.
sub.reasonCodeCount == 1)
1576 else if (response->
alt.
sub.reasonCodeCount > 1)
1578 for (i = 0; i < response->
alt.
sub.reasonCodeCount; ++i)
1582 "Reason code was %d\n", response->
alt.
sub.reasonCodes[i]);
1586 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
1593 property.value.data.len = (int)strlen(property.
value.
data.data);
1598 property.value.data.len = (int)strlen(property.
value.
data.data);
1617 int qos[2] = {2, 2};
1619 MyLog(
LOGA_DEBUG,
"In request response connect onSuccess callback, context %p", context);
1622 "Reason code was %d\n", response->
reasonCode);
1644 fprintf(
xml,
"<testcase classname=\"test11\" name=\"request response\"");
1697 "subscribe options topic",
1719 int subsidcount, subsid;
1722 assert(
"Subsidcount is i", subsidcount == 1,
"subsidcount is not correct %d\n", subsidcount);
1725 assert(
"Subsid is 2", subsid == 2,
"subsid is not correct %d\n", subsid);
1742 static int called = 0;
1744 MyLog(
LOGA_DEBUG,
"In subscribe options connect onSuccess callback, context %p", context);
1748 "Reason code was %d\n", response->
reasonCode);
1761 property.value.integer4 = 2;
1775 else if (called == 2)
1779 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
1799 MyLog(
LOGA_DEBUG,
"In subscribe options connect onSuccess callback, context %p", context);
1802 "Reason code was %d\n", response->
reasonCode);
1808 property.value.integer4 = 1;
1831 fprintf(
xml,
"<testcase classname=\"test11\" name=\"subscribe options\"");
1884 "$share/share_test/any",
1921 static int called = 0;
1924 MyLog(
LOGA_DEBUG,
"In subscribe options connect onSuccess callback, context %p, called %d", context, called);
1927 "Reason code was %d\n", response->
reasonCode);
1942 sprintf(buf,
"shared subscriptions sequence number %d", i);
1968 MyLog(
LOGA_DEBUG,
"In shared subscriptions connect d onSuccess callback, context %p", context);
1971 "Reason code was %d\n", response->
reasonCode);
1988 MyLog(
LOGA_DEBUG,
"In shared subscriptions connect c onSuccess callback, context %p", context);
1991 "Reason code was %d\n", response->
reasonCode);
2010 fprintf(
xml,
"<testcase classname=\"test11\" name=\"shared subscriptions\"");
2071 assert(
"Correct number of messages arrived",
2087 printf(
"Trace : %d, %s\n", level, message);
2094 int (*
tests[])() = {NULL,
2108 xml = fopen(
"TEST-test4.xml",
"w");
2109 fprintf(
xml,
"<testsuite name=\"test4\" tests=\"%d\">\n", (
int)(
ARRAY_SIZE(
tests)) - 1);
2150 fprintf(
xml,
"</testsuite>\n");
void test_subscribeOptions_onSubscribe(void *context, MQTTAsync_successData5 *response)
int test_request_response(struct Options options)
MQTTProperties properties
void test_client_topic_aliases_disconnected(void *context, MQTTProperties *props, enum MQTTReasonCodes rc)
void test_subscription_ids_onConnect(void *context, MQTTAsync_successData5 *response)
enum MQTTPropertyCodes value
void test_subscription_ids_onSubscribe(void *context, MQTTAsync_successData5 *response)
int test_subscribeOptions(struct Options options)
void test_shared_subscriptions_onSubscribe(void *context, MQTTAsync_successData5 *response)
int MQTTAsync_createWithOptions(MQTTAsync *handle, const char *serverURI, const char *clientId, int persistence_type, void *persistence_context, MQTTAsync_createOptions *options)
MQTTAsync_onFailure5 * onFailure5
void test_request_response_onConnect(void *context, MQTTAsync_successData5 *response)
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&...args)
START_TIME_TYPE global_start_time
struct @80 test_client_topic_aliases_globals
void test_error_reporting_onSubscribe(void *context, MQTTAsync_successData5 *response)
START_TIME_TYPE start_clock(void)
void MQTTProperties_free(MQTTProperties *props)
#define MQTTAsync_responseOptions_initializer
MQTTProperties properties
void test_qos_1_2_errors_onPublishFailure(void *context, MQTTAsync_failureData5 *response)
MQTTProperties properties
void MyLog(int LOGA_level, char *format,...)
int MQTTAsync_setCallbacks(MQTTAsync handle, void *context, MQTTAsync_connectionLost *cl, MQTTAsync_messageArrived *ma, MQTTAsync_deliveryComplete *dc)
const char * MQTTReasonCode_toString(enum MQTTReasonCodes value)
struct MQTTAsync_successData5::@49::@53 unsub
MQTTSubscribe_options * subscribeOptionsList
void test_qos_1_2_errors_onPublishFailure2(void *context, MQTTAsync_failureData5 *response)
int MQTTProperties_add(MQTTProperties *props, const MQTTProperty *prop)
MQTTAsync_nameValue * MQTTAsync_getVersionInfo(void)
size_t strftime(char *str, size_t count, const char *format, const std::tm *time)
void test_qos_1_2_errors_onPublishFailure3(void *context, MQTTAsync_failureData5 *response)
void MQTTAsync_free(void *memory)
int MQTTProperty_getType(enum MQTTPropertyCodes value)
enum MQTTReasonCodes reasonCode
int test_flow_control(struct Options options)
int test_subscription_ids(struct Options options)
void MQTTAsync_freeMessage(MQTTAsync_message **message)
int test_client_topic_aliases_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
struct @85 test_qos_1_2_errors_globals
MQTTAsync_onSuccess5 * onSuccess5
struct @82 test_subscription_ids_globals
void write_test_result(void)
std::tm localtime(std::time_t time)
void MQTTAsync_setTraceCallback(MQTTAsync_traceCallback *callback)
unsigned char retainAsPublished
MQTTProperty * MQTTProperties_getProperty(MQTTProperties *props, enum MQTTPropertyCodes propid)
int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions *options)
void getopts(int argc, char **argv)
int MQTTProperties_getNumericValue(MQTTProperties *props, enum MQTTPropertyCodes propid)
int test_server_topic_aliases_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
struct @87 test_subscribeOptions_globals
union MQTTAsync_successData5::@49 alt
void test_error_reporting_onUnsubscribe(void *context, MQTTAsync_successData5 *response)
struct @84 test_error_reporting_globals
void test_server_topic_aliases_onSubscribe(void *context, MQTTAsync_successData5 *response)
int MQTTAsync_subscribe(MQTTAsync handle, const char *topic, int qos, MQTTAsync_responseOptions *response)
void test_qos_1_2_errors_onPublishSuccess(void *context, MQTTAsync_successData5 *response)
struct @88 test_shared_subscriptions_globals
#define MQTTAsync_willOptions_initializer
#define MQTTAsync_connectOptions_initializer5
void test1_onDisconnect(void *context, MQTTAsync_successData *response)
#define assert(a, b, c, d)
int MQTTAsync_setDisconnected(MQTTAsync handle, void *context, MQTTAsync_disconnected *disconnected)
const char * MQTTPropertyName(enum MQTTPropertyCodes value)
struct @86 test_request_response_globals
void test_shared_subscriptions_onConnectc(void *context, MQTTAsync_successData5 *response)
int MQTTAsync_unsubscribeMany(MQTTAsync handle, int count, char *const *topic, MQTTAsync_responseOptions *response)
MQTTAsync_onFailure5 * onFailure5
enum MQTTPropertyCodes identifier
void logProperties(MQTTProperties *props)
void myassert(char *filename, int lineno, char *description, int value, char *format,...)
int test_subscribeOptions_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
struct @81 test_server_topic_aliases_globals
#define MQTTAsync_createOptions_initializer
void trace_callback(enum MQTTASYNC_TRACE_LEVELS level, char *message)
void test_request_response_onSubscribe(void *context, MQTTAsync_successData5 *response)
int MQTTAsync_subscribeMany(MQTTAsync handle, int count, char *const *topic, int *qos, MQTTAsync_responseOptions *response)
void flow_control_trace_callback(enum MQTTASYNC_TRACE_LEVELS level, char *message)
int main(int argc, char **argv)
int subscribeOptionsCount
int MQTTProperties_propertyCount(MQTTProperties *props, enum MQTTPropertyCodes propid)
MQTTAsync_willOptions * will
#define MQTTCLIENT_PERSISTENCE_DEFAULT
int test_qos_1_2_errors(struct Options options)
void test_client_topic_aliases_onConnect(void *context, MQTTAsync_successData5 *response)
int MQTTProperties_hasProperty(MQTTProperties *props, enum MQTTPropertyCodes propid)
MQTTProperties properties
void MQTTAsync_destroy(MQTTAsync *handle)
void test_flow_control_onSubscribe(void *context, MQTTAsync_successData5 *response)
#define MQTTASYNC_SUCCESS
void MQTTAsync_setTraceLevel(enum MQTTASYNC_TRACE_LEVELS level)
int test_request_response_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
int MQTTAsync_sendMessage(MQTTAsync handle, const char *destinationName, const MQTTAsync_message *message, MQTTAsync_responseOptions *response)
void test_server_topic_aliases_onConnect(void *context, MQTTAsync_successData5 *response)
long elapsed(START_TIME_TYPE start_time)
enum MQTTReasonCodes reasonCode
void test_qos_1_2_errors_onConnect(void *context, MQTTAsync_successData5 *response)
int test_server_topic_aliases(struct Options options)
MQTTProperties * willProperties
int test_error_reporting(struct Options options)
MQTTSubscribe_options subscribeOptions
void test_flow_control_onConnect(void *context, MQTTAsync_successData5 *response)
void test_error_reporting_onConnect(void *context, MQTTAsync_successData5 *response)
int test_flow_control_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
int MQTTProperties_getNumericValueAt(MQTTProperties *props, enum MQTTPropertyCodes propid, int index)
struct @83 test_flow_control_globals
void test_client_topic_aliases_onSubscribe(void *context, MQTTAsync_successData5 *response)
unsigned char retainHandling
#define MQTTSubscribe_options_initializer
void test_subscribeOptions_onConnect(void *context, MQTTAsync_successData5 *response)
int test_shared_subscriptions(struct Options options)
int test_subscription_ids_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
#define MQTTAsync_message_initializer
int test_shared_subscriptions_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
struct MQTTAsync_successData5::@49::@50 sub
MQTTAsync_onSuccess5 * onSuccess5
int test_client_topic_aliases(struct Options options)
void test_shared_subscriptions_onConnectd(void *context, MQTTAsync_successData5 *response)
MQTTProperties * connectProperties
#define MQTTProperties_initializer