30 #if !defined(_WINDOWS) 32 #include <sys/socket.h> 39 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) 57 "mqtt.eclipse.org:1883",
71 if (strcmp(argv[count],
"--test_no") == 0)
78 else if (strcmp(argv[count],
"--size") == 0)
85 else if (strcmp(argv[count],
"--connection") == 0)
92 else if (strcmp(argv[count],
"--MQTTversion") == 0)
102 else if (strcmp(argv[count],
"--iterations") == 0)
109 else if (strcmp(argv[count],
"--verbose") == 0)
119 #include <sys/timeb.h> 124 #if defined(_WIN32) || defined(_WINDOWS) 134 #if defined(_WIN32) || defined(_WINDOWS) 138 gettimeofday(&ts, NULL);
139 localtime_r(&ts.tv_sec, &timeinfo);
141 strftime(msg_buf, 80,
"%Y%m%d %H%M%S", &timeinfo);
143 #if defined(_WIN32) || defined(_WINDOWS) 144 sprintf(&msg_buf[strlen(msg_buf)],
".%.3hu ", ts.millitm);
146 sprintf(&msg_buf[strlen(msg_buf)],
".%.3lu ", ts.tv_usec / 1000);
149 va_start(args, format);
150 vsnprintf(&msg_buf[strlen(msg_buf)],
sizeof(msg_buf) - strlen(msg_buf), format, args);
153 printf(
"%s\n", msg_buf);
158 #if defined(_WIN32) || defined(_WINDOWS) 159 #define mqsleep(A) Sleep(1000*A) 160 #define START_TIME_TYPE DWORD 161 static DWORD start_time = 0;
164 return GetTickCount();
167 #define mqsleep sleep 168 #define START_TIME_TYPE struct timespec 171 static struct timespec start;
172 clock_gettime(CLOCK_REALTIME, &start);
176 #define mqsleep sleep 177 #define START_TIME_TYPE struct timeval 181 struct timeval start_time;
182 gettimeofday(&start_time, NULL);
191 return GetTickCount() - start_time;
195 long elapsed(
struct timespec start)
197 struct timespec now, res;
199 clock_gettime(CLOCK_REALTIME, &now);
200 ntimersub(now, start, res);
201 return (res.tv_sec)*1000L + (res.tv_nsec)/1000000L;
206 struct timeval now, res;
208 gettimeofday(&now, NULL);
209 timersub(&now, &start_time, &res);
210 return (res.tv_sec)*1000 + (res.tv_usec)/1000;
214 #define assert(a, b, c, d) myassert(__FILE__, __LINE__, a, b, c, d) 215 #define assert1(a, b, c, d, e) myassert(__FILE__, __LINE__, a, b, c, d, e) 228 fprintf(
xml,
" time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000);
234 fprintf(
xml,
"</testcase>\n");
245 printf(
"Assertion failed, file %s, line %d, description: %s\n", filename, lineno, description);
247 va_start(args, format);
248 vprintf(format, args);
252 description, filename, lineno);
255 MyLog(
LOGA_DEBUG,
"Assertion succeeded, file %s, line %d, description: %s", filename, lineno, description);
294 if (++message_count == 1)
298 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
329 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
345 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback, context %p", context);
371 fprintf(
xml,
"<testcase classname=\"test4\" name=\"asynchronous connect\"");
429 MyLog(
LOGA_DEBUG,
"In connect onFailure callback, context %p", context);
439 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback, context %p\n", context);
441 assert(
"Connect should not succeed", 0,
"connect success callback was called", 0);
463 fprintf(
xml,
"<testcase classname=\"test4\" name=\"connect timeout\"");
574 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
585 pubmsg.
payload =
"a QoS 0 message that we can shorten to the extent that we need to payload up to 11";
617 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
649 assert(
"Should have connected", 0,
"%s failed to connect\n", cd->
clientid);
651 if (response && response->
message)
665 #define num_clients 10 675 fprintf(
xml,
"<testcase classname=\"test4\" name=\"multiple connections\"");
680 sprintf(clientdata[i].
clientid,
"async_test3_num_%d", i);
681 sprintf(clientdata[i].
test_topic,
"async test3 topic num %d", i);
682 clientdata[i].
index = i;
742 MyLog(
LOGA_DEBUG,
"In publish onSuccess callback, context %p", context);
761 "message content was %c", ((
char*)message->
payload)[i]);
766 if (++message_count == 1)
780 else if (message_count == 2)
823 ((
char*)pubmsg.
payload)[i] = rand() % 256;
838 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback, context %p", context);
865 fprintf(
xml,
"<testcase classname=\"test4\" name=\"big messages\"");
925 MyLog(
LOGA_DEBUG,
"In connect onFailure callback, context %p", context);
938 MyLog(
LOGA_DEBUG,
"In connect onFailure callback, context %p", context);
960 fprintf(
xml,
"<testcase classname=\"test4\" name=\"connack return codes\"");
1013 MyLog(
LOGA_DEBUG,
"In connect onFailure callback, context %p", context);
1028 MyLog(
LOGA_DEBUG,
"In connect success callback, context %p", context);
1063 fprintf(
xml,
"<testcase classname=\"test4\" name=\"HA connections\"");
1157 assert(
"Successful disconnect", 0,
"disconnect failed", 0);
1219 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback, context %p", context);
1236 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback, context %p", context);
1267 fprintf(
xml,
"<testcase classname=\"test4\" name=\"pending tokens\"");
1331 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
1342 assert(
"1 rc from isComplete", rc == 1,
"rc was %d", rc);
1349 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
1372 assert(
"should get some tokens back", tokens != NULL,
"tokens was %p", tokens);
1389 assert(
"should get some tokens back", tokens != NULL,
"tokens was %p", tokens);
1393 while (tokens[i] != -1)
1474 "rc was %d", response->
code);
1485 assert(
"Successful disconnect", 0,
"disconnect failed", 0);
1515 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback, context %p", context);
1554 fprintf(
xml,
"<testcase classname=\"test4\" name=\"incomplete commands\"");
1601 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
1603 pubmsg.
qos = (pubmsg.
qos == 2) ? 1 : 2;
1625 assert(
"should get no tokens back", tokens == NULL,
"tokens was %p", tokens);
1657 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
1659 pubmsg.
qos = (pubmsg.
qos == 2) ? 1 : 2;
1681 assert(
"should get some tokens back", tokens != NULL,
"tokens was %p", tokens);
1745 printf(
"Trace : %d, %s\n", level, message);
1758 xml = fopen(
"TEST-test4.xml",
"w");
1759 fprintf(
xml,
"<testsuite name=\"test4\" tests=\"%d\">\n", (
int)(
ARRAY_SIZE(
tests)) - 1);
1795 fprintf(
xml,
"</testsuite>\n");
MQTTAsync_onFailure * onFailure
void test2_onFailure(void *context, MQTTAsync_failureData *response)
enum MQTTPropertyCodes value
int test7(struct Options options)
int test7_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
void test3_onSubscribe(void *context, MQTTAsync_successData *response)
void test3_onFailure(void *context, MQTTAsync_failureData *response)
void test4_onPublish(void *context, MQTTAsync_successData *response)
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&...args)
void test8_onConnect(void *context, MQTTAsync_successData *response)
union MQTTAsync_successData::@46 alt
void test8_onDisconnectFailure(void *context, MQTTAsync_failureData *response)
int test4(struct Options options)
void test1_onSubscribe(void *context, MQTTAsync_successData *response)
void test7_onUnsubscribe(void *context, MQTTAsync_successData *response)
void test1_onConnect(void *context, MQTTAsync_successData *response)
#define MQTTAsync_responseOptions_initializer
long elapsed(START_TIME_TYPE start_time)
int MQTTAsync_disconnect(MQTTAsync handle, const MQTTAsync_disconnectOptions *options)
void test6_onDisconnect(void *context, MQTTAsync_successData *response)
int MQTTAsync_setCallbacks(MQTTAsync handle, void *context, MQTTAsync_connectionLost *cl, MQTTAsync_messageArrived *ma, MQTTAsync_deliveryComplete *dc)
void test7_onConnectOnly(void *context, MQTTAsync_successData *response)
void test8_onPublishFailure(void *context, MQTTAsync_failureData *response)
MQTTAsync_nameValue * MQTTAsync_getVersionInfo(void)
size_t strftime(char *str, size_t count, const char *format, const std::tm *time)
void MQTTAsync_free(void *memory)
void MQTTAsync_freeMessage(MQTTAsync_message **message)
int test8_publishFailures
void myassert(char *filename, int lineno, char *description, int value, char *format,...)
int MQTTAsync_unsubscribe(MQTTAsync handle, const char *topic, MQTTAsync_responseOptions *response)
void getopts(int argc, char **argv)
void MQTTAsync_setTraceCallback(MQTTAsync_traceCallback *callback)
int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions *options)
void test1_onDisconnect(void *context, MQTTAsync_successData *response)
int test8(struct Options options)
void test8_onPublish(void *context, MQTTAsync_successData *response)
int MQTTAsync_subscribe(MQTTAsync handle, const char *topic, int qos, MQTTAsync_responseOptions *response)
int test3(struct Options options)
#define MQTTASYNC_OPERATION_INCOMPLETE
void test7_onSubscribe(void *context, MQTTAsync_successData *response)
#define MQTTAsync_willOptions_initializer
int MQTTAsync_create(MQTTAsync *handle, const char *serverURI, const char *clientId, int persistence_type, void *persistence_context)
void test7_onDisconnect(void *context, MQTTAsync_successData *response)
int MQTTAsync_getPendingTokens(MQTTAsync handle, MQTTAsync_token **tokens)
void test8_onDisconnect(void *context, MQTTAsync_successData *response)
#define MQTTAsync_disconnectOptions_initializer
MQTTAsync_onFailure * onFailure
void test3_onConnect(void *context, MQTTAsync_successData *response)
void test5_onConnect(void *context, MQTTAsync_successData *response)
void test2_onConnect(void *context, MQTTAsync_successData *response)
void MyLog(int LOGA_level, char *format,...)
void test3_onDisconnect(void *context, MQTTAsync_successData *response)
MQTTAsync_onFailure * onFailure
struct MQTTAsync_connectOptions::@55 binarypwd
void test8_onSubscribe(void *context, MQTTAsync_successData *response)
int test5(struct Options options)
#define MQTTAsync_connectOptions_initializer
MQTTAsync_onSuccess * onSuccess
int test3_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
void test5_onConnectFailure(void *context, MQTTAsync_failureData *response)
void test1_onUnsubscribe(void *context, MQTTAsync_successData *response)
void test3_onPublish(void *context, MQTTAsync_successData *response)
MQTTAsync_willOptions * will
void test4_onConnect(void *context, MQTTAsync_successData *response)
#define MQTTCLIENT_PERSISTENCE_DEFAULT
int MQTTAsync_isComplete(MQTTAsync handle, MQTTAsync_token dt)
int MQTTAsync_send(MQTTAsync handle, const char *destinationName, int payloadlen, const void *payload, int qos, int retained, MQTTAsync_responseOptions *response)
static int test7_subscribed
void test7_onConnect(void *context, MQTTAsync_successData *response)
int test6(struct Options options)
int test8_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
void test6_onConnectFailure(void *context, MQTTAsync_failureData *response)
void test3_onUnsubscribe(void *context, MQTTAsync_successData *response)
void MQTTAsync_destroy(MQTTAsync *handle)
void write_test_result(void)
void test6_onConnect(void *context, MQTTAsync_successData *response)
#define assert(a, b, c, d)
START_TIME_TYPE global_start_time
#define MQTTASYNC_SUCCESS
void MQTTAsync_setTraceLevel(enum MQTTASYNC_TRACE_LEVELS level)
int MQTTAsync_sendMessage(MQTTAsync handle, const char *destinationName, const MQTTAsync_message *message, MQTTAsync_responseOptions *response)
volatile int test_finished
int test1(struct Options options)
#define MQTTCLIENT_PERSISTENCE_NONE
int test2_onFailure_called
void trace_callback(enum MQTTASYNC_TRACE_LEVELS level, char *message)
int test2(struct Options options)
void test4_onSubscribe(void *context, MQTTAsync_successData *response)
#define MQTTAsync_message_initializer
void test7_onDisconnectFailure(void *context, MQTTAsync_failureData *response)
START_TIME_TYPE start_clock(void)
int main(int argc, char **argv)
MQTTAsync_onSuccess * onSuccess
#define MQTTVERSION_DEFAULT
int test1_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
MQTTAsync_onSuccess * onSuccess
int MQTTAsync_waitForCompletion(MQTTAsync handle, MQTTAsync_token dt, unsigned long timeout)
int test4_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)