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)
121 #include <sys/timeb.h> 126 #if defined(_WIN32) || defined(_WINDOWS) 136 #if defined(_WIN32) || defined(_WINDOWS) 140 gettimeofday(&ts, NULL);
141 localtime_r(&ts.tv_sec, &timeinfo);
143 strftime(msg_buf, 80,
"%Y%m%d %H%M%S", &timeinfo);
145 #if defined(_WIN32) || defined(_WINDOWS) 146 sprintf(&msg_buf[strlen(msg_buf)],
".%.3hu ", ts.millitm);
148 sprintf(&msg_buf[strlen(msg_buf)],
".%.3lu ", ts.tv_usec / 1000);
151 va_start(args, format);
152 vsnprintf(&msg_buf[strlen(msg_buf)],
sizeof(msg_buf) - strlen(msg_buf), format, args);
155 printf(
"%s\n", msg_buf);
162 #if defined(_WIN32) || defined(_WIN64) 165 usleep(milliseconds*1000);
170 #if defined(_WIN32) || defined(_WINDOWS) 171 #define START_TIME_TYPE DWORD 172 static DWORD start_time = 0;
175 return GetTickCount();
178 #define START_TIME_TYPE struct timespec 181 static struct timespec start;
182 clock_gettime(CLOCK_REALTIME, &start);
186 #define START_TIME_TYPE struct timeval 190 struct timeval start_time;
191 gettimeofday(&start_time, NULL);
200 return GetTickCount() - start_time;
204 long elapsed(
struct timespec start)
206 struct timespec now, res;
208 clock_gettime(CLOCK_REALTIME, &now);
209 ntimersub(now, start, res);
210 return (res.tv_sec)*1000L + (res.tv_nsec)/1000000L;
215 struct timeval now, res;
217 gettimeofday(&now, NULL);
218 timersub(&now, &start_time, &res);
219 return (res.tv_sec)*1000 + (res.tv_usec)/1000;
223 #define assert(a, b, c, d) myassert(__FILE__, __LINE__, a, b, c, d) 224 #define assert1(a, b, c, d, e) myassert(__FILE__, __LINE__, a, b, c, d, e) 237 fprintf(
xml,
" time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000);
243 fprintf(
xml,
"</testcase>\n");
254 printf(
"Assertion failed, file %s, line %d, description: %s\n", filename, lineno, description);
256 va_start(args, format);
257 vprintf(format, args);
261 description, filename, lineno);
264 MyLog(
LOGA_DEBUG,
"Assertion succeeded, file %s, line %d, description: %s", filename, lineno, description);
272 for (i = 0; i < props->
count; ++i)
276 char* intformat =
"Property name %s value %d";
320 while (tokens[i] != -1)
327 while (i > 0 && ++
count < 100);
328 assert(
"Number of getPendingTokens should be 0", i == 0,
"i was %d ", i);
356 "Property count was %d\n", response->
properties);
363 property.value.integer4 = 0;
389 if (++message_count == 1)
397 property.value.data.data =
"test user property";
398 property.value.data.len = (int)strlen(property.
value.
data.data);
399 property.value.value.data =
"test user property value";
400 property.value.value.len = (int)strlen(property.
value.value.
data);
404 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
419 property.value.data.data =
"test user property";
420 property.value.data.len = (int)strlen(property.
value.
data.data);
421 property.value.value.data =
"test user property value";
422 property.value.value.len = (int)strlen(property.
value.value.
data);
456 property.value.data.data =
"test user property";
457 property.value.data.len = (int)strlen(property.
value.
data.data);
458 property.value.value.data =
"test user property value";
459 property.value.value.len = (int)strlen(property.
value.value.
data);
463 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
481 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback, context %p", context);
484 "Reason code was %d\n", response->
reasonCode);
493 property.value.integer4 = 33;
526 fprintf(
xml,
"<testcase classname=\"test45\" name=\"asynchronous connect\"");
558 property.value.integer4 = 30;
562 property.value.data.data =
"test user property";
563 property.value.data.len = (int)strlen(property.
value.
data.data);
564 property.value.value.data =
"test user property value";
565 property.value.value.len = (int)strlen(property.
value.value.
data);
595 MyLog(
LOGA_DEBUG,
"In connect onFailure callback, context %p", context);
605 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback, context %p\n", context);
607 assert(
"Connect should not succeed", 0,
"connect success callback was called", 0);
630 fprintf(
xml,
"<testcase classname=\"test4\" name=\"connect timeout\"");
736 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
747 pubmsg.
payload =
"a QoS 0 message that we can shorten to the extent that we need to payload up to 11";
779 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
811 assert(
"Should have connected", 0,
"%s failed to connect\n", cd->
clientid);
813 if (response && response->
message)
827 #define num_clients 10 838 fprintf(
xml,
"<testcase classname=\"test4\" name=\"multiple connections\"");
843 sprintf(clientdata[i].
clientid,
"async_test3_num_%d", i);
844 sprintf(clientdata[i].
test_topic,
"async test3 topic num %d", i);
845 clientdata[i].
index = i;
901 MyLog(
LOGA_DEBUG,
"In publish onSuccess callback, context %p", context);
920 "message content was %c", ((
char*)message->
payload)[i]);
925 if (++message_count == 1)
939 else if (message_count == 2)
962 property.value.data.data =
"test user property";
963 property.value.data.len = (int)strlen(property.
value.
data.data);
964 property.value.value.data =
"test user property value";
965 property.value.value.len = (int)strlen(property.
value.value.
data);
983 #define min(a, b) ((a < b) ? a : b) 1000 for (i = 0; i < (max_packet_size-100); ++i)
1001 ((
char*)pubmsg.
payload)[i] = rand() % 256;
1018 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback, context %p", context);
1046 fprintf(
xml,
"<testcase classname=\"test4\" name=\"big messages\"");
1101 MyLog(
LOGA_DEBUG,
"In connect onFailure callback, context %p", context);
1114 MyLog(
LOGA_DEBUG,
"In connect onFailure callback, context %p", context);
1137 fprintf(
xml,
"<testcase classname=\"test45\" name=\"connack return codes\"");
1186 MyLog(
LOGA_DEBUG,
"In connect onFailure callback, context %p", context);
1201 MyLog(
LOGA_DEBUG,
"In connect success callback, context %p", context);
1237 fprintf(
xml,
"<testcase classname=\"test4\" name=\"HA connections\"");
1319 assert(
"Successful disconnect", 0,
"disconnect failed", 0);
1330 assert(
"Successful disconnect", 0,
"disconnect failed", 0);
1415 MyLog(
LOGA_DEBUG,
"In subscribe onSuccess callback %p granted qos %d", c,
1429 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback, context %p", context);
1453 MyLog(
LOGA_DEBUG,
"In connect onSuccess5 callback, context %p", context);
1493 MyLog(
LOGA_INFO,
"Starting test 7 - persistence, qos %d, MQTT versions: %s then %s", qos,
1497 fprintf(
xml,
"<testcase classname=\"test45\" name=\"pending tokens\"");
1539 property.value.integer4 = 999999;
1584 pubmsg.
payload =
"first test of a much longer message that we can shorten to the extent that we need to payload up to 11";
1594 assert(
"1 rc from isComplete", rc == 1,
"rc was %d", rc);
1601 sprintf(buf,
"%d a much longer message that we can shorten to the extent that we need", i);
1624 assert(
"should get some tokens back", tokens != NULL,
"tokens was %p", tokens);
1649 assert(
"should get some tokens back", tokens != NULL,
"tokens was %p", tokens);
1653 while (tokens[i] != -1)
1656 assert(
"no of tokens should be > 0", i > 0,
"no of tokens %d", i);
1671 property.value.integer4 = 0;
1739 fprintf(
xml,
"<testcase classname=\"test7\" name=\"persistence\"");
1753 fprintf(
xml,
"</testcase>\n");
1784 "rc was %d", response->
code);
1795 assert(
"Successful disconnect", 0,
"disconnect failed", 0);
1825 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback, context %p", context);
1867 fprintf(
xml,
"<testcase classname=\"test4\" name=\"incomplete commands\"");
1910 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
1912 pubmsg.
qos = (pubmsg.
qos == 2) ? 1 : 2;
1941 property.value.integer4 = 30;
1961 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
1963 pubmsg.
qos = (pubmsg.
qos == 2) ? 1 : 2;
1981 assert(
"should get some tokens back", tokens != NULL,
"tokens was %p", tokens);
2039 printf(
"Trace : %d, %s\n", level, message);
2052 xml = fopen(
"TEST-test4.xml",
"w");
2053 fprintf(
xml,
"<testsuite name=\"test4\" tests=\"%d\">\n", (
int)(
ARRAY_SIZE(
tests)) - 1);
2094 fprintf(
xml,
"</testsuite>\n");
int test7_run(int qos, int start_mqtt_version, int restore_mqtt_version)
MQTTAsync_onFailure * onFailure
int test7_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
MQTTProperties properties
#define assert(a, b, c, d)
int test6(struct Options options)
void test3_onUnsubscribe(void *context, MQTTAsync_successData5 *response)
enum MQTTPropertyCodes value
int MQTTAsync_createWithOptions(MQTTAsync *handle, const char *serverURI, const char *clientId, int persistence_type, void *persistence_context, MQTTAsync_createOptions *options)
void test2_onConnect(void *context, MQTTAsync_successData5 *response)
void logProperties(MQTTProperties *props)
MQTTAsync_onFailure5 * onFailure5
void test7_onDisconnect(void *context, MQTTAsync_successData *response)
void test7_onConnect(void *context, MQTTAsync_successData *response)
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&...args)
void test3_onPublish(void *context, MQTTAsync_successData5 *response)
void test8_onConnect(void *context, MQTTAsync_successData5 *response)
void test7_onDisconnectFailure5(void *context, MQTTAsync_failureData5 *response)
union MQTTAsync_successData::@46 alt
void test7_onUnsubscribe(void *context, MQTTAsync_successData *response)
int test8_publishFailures
void MQTTProperties_free(MQTTProperties *props)
#define MQTTAsync_responseOptions_initializer
int main(int argc, char **argv)
MQTTProperties properties
void MySleep(long milliseconds)
int MQTTAsync_disconnect(MQTTAsync handle, const MQTTAsync_disconnectOptions *options)
int MQTTAsync_setCallbacks(MQTTAsync handle, void *context, MQTTAsync_connectionLost *cl, MQTTAsync_messageArrived *ma, MQTTAsync_deliveryComplete *dc)
void test1_onUnsubscribe(void *context, MQTTAsync_successData5 *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 MQTTAsync_free(void *memory)
int MQTTProperty_getType(enum MQTTPropertyCodes value)
enum MQTTReasonCodes reasonCode
static int test7_subscribed
void MQTTAsync_freeMessage(MQTTAsync_message **message)
void test6_onConnect(void *context, MQTTAsync_successData5 *response)
int MQTTAsync_unsubscribe(MQTTAsync handle, const char *topic, MQTTAsync_responseOptions *response)
MQTTAsync_onSuccess5 * onSuccess5
void MQTTAsync_setTraceCallback(MQTTAsync_traceCallback *callback)
void test5_onConnect(void *context, MQTTAsync_successData5 *response)
unsigned char retainAsPublished
int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions *options)
int test2_onFailure_called
void test2_onFailure(void *context, MQTTAsync_failureData5 *response)
int MQTTProperties_getNumericValue(MQTTProperties *props, enum MQTTPropertyCodes propid)
void myassert(char *filename, int lineno, char *description, int value, char *format,...)
int test4(struct Options options)
void test3_onFailure(void *context, MQTTAsync_failureData5 *response)
void test4_onSubscribe(void *context, MQTTAsync_successData5 *response)
int MQTTAsync_subscribe(MQTTAsync handle, const char *topic, int qos, MQTTAsync_responseOptions *response)
volatile int test_finished
#define MQTTASYNC_OPERATION_INCOMPLETE
void test4_onPublish(void *context, MQTTAsync_successData5 *response)
#define MQTTAsync_willOptions_initializer
void test7_onUnsubscribe5(void *context, MQTTAsync_successData5 *response)
void test3_onDisconnect(void *context, MQTTAsync_successData5 *response)
void test7_onDisconnectFailure(void *context, MQTTAsync_failureData *response)
#define MQTTAsync_connectOptions_initializer5
MQTTAsync_onFailure5 * onFailure5
static int test7_just_connect
int MQTTAsync_getPendingTokens(MQTTAsync handle, MQTTAsync_token **tokens)
const char * MQTTPropertyName(enum MQTTPropertyCodes value)
#define MQTTAsync_disconnectOptions_initializer
MQTTAsync_onFailure5 * onFailure5
#define MQTTVERSION_3_1_1
int test8_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
enum MQTTPropertyCodes identifier
int test3(struct Options options)
void test7_onConnect5(void *context, MQTTAsync_successData5 *response)
#define MQTTAsync_createOptions_initializer
MQTTAsync_onFailure * onFailure
void test8_onDisconnectFailure(void *context, MQTTAsync_failureData5 *response)
void test3_onSubscribe(void *context, MQTTAsync_successData5 *response)
struct MQTTAsync_connectOptions::@55 binarypwd
long elapsed(START_TIME_TYPE start_time)
void test1_onSubscribe(void *context, MQTTAsync_successData5 *response)
void test5_onConnectFailure(void *context, MQTTAsync_failureData5 *response)
void test7_onSubscribe5(void *context, MQTTAsync_successData5 *response)
void test4_onConnect(void *context, MQTTAsync_successData5 *response)
MQTTAsync_onSuccess * onSuccess
void test8_onSubscribe(void *context, MQTTAsync_successData5 *response)
MQTTAsync_willOptions * will
void test8_onPublish(void *context, MQTTAsync_successData5 *response)
MQTTProperties properties
#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)
int test7(struct Options options)
int test4_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
void test8_onDisconnect(void *context, MQTTAsync_successData5 *response)
MQTTProperties properties
START_TIME_TYPE global_start_time
int test8(struct Options options)
int test5(struct Options options)
void MQTTAsync_destroy(MQTTAsync *handle)
void test3_onConnect(void *context, MQTTAsync_successData5 *response)
#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)
void test6_onConnectFailure(void *context, MQTTAsync_failureData5 *response)
START_TIME_TYPE start_clock(void)
int test3_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
void trace_callback(enum MQTTASYNC_TRACE_LEVELS level, char *message)
void test6_onDisconnect5(void *context, MQTTAsync_successData5 *response)
void test7_onSubscribe(void *context, MQTTAsync_successData *response)
#define MQTTCLIENT_PERSISTENCE_NONE
void MyLog(int LOGA_level, char *format,...)
enum MQTTReasonCodes reasonCode
#define MQTTASYNC_PERSISTENCE_ERROR
MQTTProperties * willProperties
MQTTSubscribe_options subscribeOptions
void waitForNoPendingTokens(MQTTAsync c)
void test1_onConnect(void *context, MQTTAsync_successData5 *response)
int test1_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
void test7_onDisconnect5(void *context, MQTTAsync_successData5 *response)
MQTTAsync_onSuccess5 * onSuccess5
void test1_onDisconnect(void *context, MQTTAsync_successData *response)
void write_test_result(void)
int test1(struct Options options)
enum MQTTReasonCodes reasonCode
void getopts(int argc, char **argv)
#define MQTTAsync_message_initializer
MQTTAsync_onSuccess * onSuccess
#define MQTTAsync_callOptions_initializer
MQTTAsync_onSuccess5 * onSuccess5
void test8_onPublishFailure(void *context, MQTTAsync_failureData5 *response)
int test2(struct Options options)
MQTTAsync_onSuccess * onSuccess
int MQTTAsync_waitForCompletion(MQTTAsync handle, MQTTAsync_token dt, unsigned long timeout)
MQTTProperties * connectProperties
#define MQTTProperties_initializer