33 #if !defined(_WINDOWS) 35 #include <sys/socket.h> 44 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) 60 "mqtt.eclipse.org:1883",
72 if (strcmp(argv[count],
"--test_no") == 0)
79 else if (strcmp(argv[count],
"--connection") == 0)
86 else if (strcmp(argv[count],
"--proxy_connection") == 0)
93 else if (strcmp(argv[count],
"--verbose") == 0)
104 #include <sys/timeb.h> 109 #if defined(_WIN32) || defined(_WINDOWS) 119 #if defined(_WIN32) || defined(_WINDOWS) 123 gettimeofday(&ts, NULL);
124 localtime_r(&ts.tv_sec, &timeinfo);
126 strftime(msg_buf, 80,
"%Y%m%d %H%M%S", &timeinfo);
128 #if defined(_WIN32) || defined(_WINDOWS) 129 sprintf(&msg_buf[strlen(msg_buf)],
".%.3hu ", ts.millitm);
131 sprintf(&msg_buf[strlen(msg_buf)],
".%.3lu ", ts.tv_usec / 1000);
134 va_start(args, format);
135 vsnprintf(&msg_buf[strlen(msg_buf)],
sizeof(msg_buf) - strlen(msg_buf), format, args);
138 printf(
"%s\n", msg_buf);
144 #if defined(_WIN32) || defined(_WIN64) 147 usleep(milliseconds*1000);
151 #if defined(_WIN32) || defined(_WINDOWS) 152 #define START_TIME_TYPE DWORD 153 static DWORD start_time = 0;
156 return GetTickCount();
159 #define START_TIME_TYPE struct timespec 162 static struct timespec start;
163 clock_gettime(CLOCK_REALTIME, &start);
167 #define START_TIME_TYPE struct timeval 171 struct timeval start_time;
172 gettimeofday(&start_time, NULL);
180 return GetTickCount() - start_time;
184 long elapsed(
struct timespec start)
186 struct timespec now, res;
188 clock_gettime(CLOCK_REALTIME, &now);
189 ntimersub(now, start, res);
190 return (res.tv_sec)*1000L + (res.tv_nsec)/1000000L;
195 struct timeval now, res;
197 gettimeofday(&now, NULL);
198 timersub(&now, &start_time, &res);
199 return (res.tv_sec) * 1000 + (res.tv_usec) / 1000;
203 #define assert(a, b, c, d) myassert(__FILE__, __LINE__, a, b, c, d) 204 #define assert1(a, b, c, d, e) myassert(__FILE__, __LINE__, a, b, c, d, e) 220 fprintf(
xml,
" time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000);
226 fprintf(
xml,
"</testcase>\n");
238 MyLog(
LOGA_INFO,
"Assertion failed, file %s, line %d, description: %s", filename,
239 lineno, description);
241 va_start(args, format);
242 vprintf(format, args);
246 description, filename, lineno);
249 MyLog(
LOGA_DEBUG,
"Assertion succeeded, file %s, line %d, description: %s",
250 filename, lineno, description);
258 for (i = 0; i < props->
count; ++i)
262 char* intformat =
"Property name %s value %d";
306 while (tokens[i] != -1)
313 while (i > 0 && ++
count < 10);
314 assert(
"Number of getPendingTokens should be 0", i == 0,
"i was %d ", i);
328 while (tokens[i] != -1)
332 assert(
"Number of getPendingTokens should be 3", i == 3,
"i was %d ", i);
376 static int first = 1;
410 MyLog(
LOGA_DEBUG,
"In connect onFailure callback, context %p", context);
418 MyLog(
LOGA_DEBUG,
"In connect onFailure callback, context %p", context);
427 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback for client d, context %p\n", context);
453 MyLog(
LOGA_DEBUG,
"In subscribe onSuccess callback for client d, %p granted qos %d", c,
464 int qoss[2] = {2, 2};
467 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback for client c, context %p\n", context);
483 MyLog(
LOGA_DEBUG,
"In connected callback for client c, context %p\n", context);
490 char* testname =
"test1";
506 sprintf(clientidc,
"paho-test95-1-c-%s",
unique);
507 sprintf(clientidd,
"paho-test95-1-d-%s",
unique);
512 MyLog(
LOGA_INFO,
"Starting Offline buffering 1 - messages while disconnected");
513 fprintf(
xml,
"<testcase classname=\"test1\" name=\"%s\"", testname);
561 assert(
"Count should be less than 10000", count < 10000,
"count was %d", count);
574 property.value.data.data =
"test user property";
575 property.value.data.len = (int)strlen(property.
value.
data.data);
576 property.value.value.data =
"test user property value";
577 property.value.value.len = (int)strlen(property.
value.value.
data);
587 property.value.integer4 = 30;
611 for (i = 0; i < 3; ++i)
619 sprintf(buf,
"QoS %d message", i);
627 property.value.data.data =
"test user property";
628 property.value.data.len = (int)strlen(property.
value.
data.data);
629 property.value.value.data =
"test user property value";
630 property.value.value.len = (int)strlen(property.
value.value.
data);
740 MyLog(
LOGA_DEBUG,
"In connect onFailure callback, context %p", context);
748 MyLog(
LOGA_DEBUG,
"In connect onFailure callback, context %p", context);
757 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback for client d, context %p\n", context);
778 MyLog(
LOGA_DEBUG,
"In subscribe onSuccess callback for client d, %p granted qos %d", c,
789 int qoss[2] = {2, 2};
792 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback for client c, context %p\n", context);
808 MyLog(
LOGA_DEBUG,
"In connected callback for client c, context %p\n", context);
815 char* testname =
"test2";
831 sprintf(clientidc,
"paho-test95-2-c-%s",
unique);
832 sprintf(clientidd,
"paho-test95-2-d-%s",
unique);
837 MyLog(
LOGA_INFO,
"Starting Offline buffering 2 - messages while disconnected with serverURIs");
838 fprintf(
xml,
"<testcase classname=\"test2\" name=\"%s\"", testname);
844 NULL, &createOptions);
855 NULL, &createOptions);
887 assert(
"Count should be less than 10000", count < 10000,
"count was %d", count);
904 property.value.integer4 = 30;
928 for (i = 0; i < 3; ++i)
934 sprintf(buf,
"QoS %d message", i);
1012 MyLog(
LOGA_DEBUG,
"In connect onFailure callback, context %p", context);
1020 MyLog(
LOGA_DEBUG,
"In connect onFailure callback, context %p", context);
1029 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback for client d, context %p\n", context);
1050 MyLog(
LOGA_DEBUG,
"In subscribe onSuccess callback for client d, %p granted qos %d", c,
1061 int qoss[2] = {2, 2};
1064 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback for client c, context %p\n", context);
1080 MyLog(
LOGA_DEBUG,
"In connected callback for client c, context %p\n", context);
1087 char* testname =
"test3";
1102 sprintf(clientidc,
"paho-test95-3-c-%s",
unique);
1103 sprintf(clientidd,
"paho-test95-3-d-%s",
unique);
1108 MyLog(
LOGA_INFO,
"Starting Offline buffering 3 - messages while disconnected");
1109 fprintf(
xml,
"<testcase classname=\"test3\" name=\"%s\"", testname);
1115 NULL, &createOptions);
1126 NULL, &createOptions);
1158 assert(
"Count should be less than 10000", count < 10000,
"count was %d", count);
1174 property.value.integer4 = 30;
1198 for (i = 0; i < 3; ++i)
1204 sprintf(buf,
"QoS %d message", i);
1280 MyLog(
LOGA_DEBUG,
"In connect onFailure callback, context %p", context);
1288 MyLog(
LOGA_DEBUG,
"In connect onFailure callback, context %p", context);
1297 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback for client d, context %p\n", context);
1318 MyLog(
LOGA_DEBUG,
"In subscribe onSuccess callback for client d, %p granted qos %d", c,
1329 int qoss[2] = {2, 2};
1332 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback for client c, context %p\n", context);
1348 MyLog(
LOGA_DEBUG,
"In connected callback for client c, context %p\n", context);
1355 char* testname =
"test4";
1371 sprintf(clientidc,
"paho-test95-4-c-%s",
unique);
1372 sprintf(clientidd,
"paho-test95-4-d-%s",
unique);
1377 MyLog(
LOGA_INFO,
"Starting Offline buffering 4 - messages while disconnected with serverURIs");
1378 fprintf(
xml,
"<testcase classname=\"test4\" name=\"%s\"", testname);
1384 NULL, &createOptions);
1395 NULL, &createOptions);
1426 assert(
"Count should be less than 10000", count < 10000,
"count was %d", count);
1442 property.value.integer4 = 30;
1467 for (i = 0; i < 3; ++i)
1473 sprintf(buf,
"QoS %d message", i);
1548 MyLog(
LOGA_DEBUG,
"In connect onFailure callback, context %p", context);
1556 MyLog(
LOGA_DEBUG,
"In connect onFailure callback, context %p", context);
1565 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback for client d, context %p\n", context);
1586 MyLog(
LOGA_DEBUG,
"In subscribe onSuccess callback for client d, %p granted qos %d", c,
1597 int qoss[2] = {2, 2};
1600 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback for client c, context %p\n", context);
1614 MyLog(
LOGA_DEBUG,
"In connected callback for client c, context %p\n", context);
1621 char* testname =
"test5";
1636 sprintf(clientidc,
"paho-test95-5-c-%s",
unique);
1637 sprintf(clientidd,
"paho-test95-5-d-%s",
unique);
1643 fprintf(
xml,
"<testcase classname=\"test5\" name=\"%s\"", testname);
1650 NULL, &createOptions);
1662 NULL, &createOptions);
1694 assert(
"Count should be less than 10000", count < 10000,
"count was %d", count);
1711 property.value.integer4 = 30;
1733 for (i = 0; i < 5; ++i)
1739 sprintf(buf,
"QoS %d message", i);
1785 char* testname =
"test6";
1806 sprintf(clientidc,
"paho-test95-6-c-%s",
unique);
1807 sprintf(clientidd,
"paho-test95-6-d-%s",
unique);
1812 MyLog(
LOGA_INFO,
"Starting Offline buffering 6 - max buffered with binary will");
1813 fprintf(
xml,
"<testcase classname=\"test6\" name=\"%s\"", testname);
1820 NULL, &createOptions);
1832 NULL, &createOptions);
1864 assert(
"Count should be less than 10000", count < 10000,
"count was %d", count);
1882 property.value.integer4 = 30;
1904 for (i = 0; i < 5; ++i)
1910 sprintf(buf,
"QoS %d message", i);
1988 MyLog(
LOGA_DEBUG,
"In connected callback for client c, context %p\n", context);
1994 MyLog(
LOGA_DEBUG,
"In c connect onFailure callback, context %p", context);
2005 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback for client c, context %p\n", context);
2018 MyLog(
LOGA_DEBUG,
"In connect onFailure callback, context %p", context);
2028 MyLog(
LOGA_DEBUG,
"In subscribe onSuccess callback for client d, %p granted qos %d", c,
2038 int qoss[2] = {2, 2};
2041 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback for client c, context %p\n", context);
2055 char* testname =
"test7";
2074 sprintf(clientidc,
"paho-test9-7-c-%s",
unique);
2075 sprintf(clientidd,
"paho-test9-7-d-%s",
unique);
2080 MyLog(
LOGA_INFO,
"Starting Offline buffering 7 - fill TCP buffer");
2081 fprintf(
xml,
"<testcase classname=\"test7\" name=\"%s\"", testname);
2131 assert(
"Count should be less than 10000", count < 10000,
"count was %d", count);
2163 assert(
"Count should be less than 10000", count < 10000,
"count was %d", count);
2169 MyLog(
LOGA_DEBUG,
"Now we can send some messages to be buffered by TCP");
2174 for (i = 0; i < 50000; ++i)
2179 sprintf(buf,
"QoS %d message", pubmsg.
qos);
2231 printf(
"%s\n", message);
2237 int* numtests = &
tests;
2242 srand((
unsigned)
time(&randtime));
2243 sprintf(
unique,
"%u", rand());
2246 xml = fopen(
"TEST-test9.xml",
"w");
2247 fprintf(
xml,
"<testsuite name=\"test9\" tests=\"%d\">\n", (
int)(
ARRAY_SIZE(
tests) - 1));
2273 fprintf(
xml,
"</testsuite>\n");
#define assert(a, b, c, d)
MQTTProperties properties
int test6(struct Options options)
int test7_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
void test1dOnConnect(void *context, MQTTAsync_successData5 *response)
enum MQTTPropertyCodes value
void logProperties(MQTTProperties *props)
void test7cOnConnectSuccess(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)
int test3_will_message_received
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&...args)
void test7cOnConnectFailure(void *context, MQTTAsync_failureData5 *response)
void test5donSubscribe(void *context, MQTTAsync_successData5 *response)
void test2cConnected(void *context, char *cause)
int test2_will_message_received
void test2cOnFailure(void *context, MQTTAsync_failureData5 *response)
void test7cConnected(void *context, char *cause)
void test3donSubscribe(void *context, MQTTAsync_successData5 *response)
int sendWhileDisconnected
int main(int argc, char **argv)
void MQTTProperties_free(MQTTProperties *props)
#define MQTTAsync_responseOptions_initializer
void test4dOnFailure(void *context, MQTTAsync_failureData5 *response)
int MQTTAsync_disconnect(MQTTAsync handle, const MQTTAsync_disconnectOptions *options)
void MySleep(long milliseconds)
int MQTTAsync_setCallbacks(MQTTAsync handle, void *context, MQTTAsync_connectionLost *cl, MQTTAsync_messageArrived *ma, MQTTAsync_deliveryComplete *dc)
void test2donSubscribe(void *context, MQTTAsync_successData5 *response)
void test7dOnConnectFailure(void *context, MQTTAsync_failureData5 *response)
int test7_will_message_received
int MQTTProperties_add(MQTTProperties *props, const MQTTProperty *prop)
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
void MQTTAsync_freeMessage(MQTTAsync_message **message)
int test4_will_message_received
int MQTTAsync_setConnected(MQTTAsync handle, void *context, MQTTAsync_connected *connected)
int test2_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
void test4cOnConnect(void *context, MQTTAsync_successData5 *response)
MQTTAsync_onSuccess5 * onSuccess5
int test4_messages_received
void MQTTAsync_setTraceCallback(MQTTAsync_traceCallback *callback)
void test5cOnConnect(void *context, MQTTAsync_successData5 *response)
void myassert(char *filename, int lineno, char *description, int value, char *format,...)
int test4(struct Options options)
int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions *options)
void test2dOnConnect(void *context, MQTTAsync_successData5 *response)
void test7donSubscribe(void *context, MQTTAsync_successData5 *response)
void test5dOnFailure(void *context, MQTTAsync_failureData5 *response)
int test1_messages_received
#define MQTTAsync_willOptions_initializer
void test3dOnFailure(void *context, MQTTAsync_failureData5 *response)
void test1cConnected(void *context, char *cause)
#define MQTTAsync_connectOptions_initializer5
int MQTTAsync_getPendingTokens(MQTTAsync handle, MQTTAsync_token **tokens)
const char * MQTTPropertyName(enum MQTTPropertyCodes value)
void test2dOnFailure(void *context, MQTTAsync_failureData5 *response)
MQTTAsync_onFailure5 * onFailure5
int test3(struct Options options)
enum MQTTPropertyCodes identifier
struct MQTTAsync_willOptions::@54 payload
#define MQTTAsync_createOptions_initializer
void test5cOnFailure(void *context, MQTTAsync_failureData5 *response)
int MQTTAsync_subscribeMany(MQTTAsync handle, int count, char *const *topic, int *qos, MQTTAsync_responseOptions *response)
void test4donSubscribe(void *context, MQTTAsync_successData5 *response)
long elapsed(START_TIME_TYPE start_time)
#define MQTTASYNC_MAX_BUFFERED_MESSAGES
void handleTrace(enum MQTTASYNC_TRACE_LEVELS level, char *message)
int test2_messages_received
MQTTAsync_willOptions * will
void test4cConnected(void *context, char *cause)
#define MQTTCLIENT_PERSISTENCE_DEFAULT
void test7dOnConnectSuccess(void *context, MQTTAsync_successData5 *response)
void test4dOnConnect(void *context, MQTTAsync_successData5 *response)
int test4_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
int test7(struct Options options)
void test1donSubscribe(void *context, MQTTAsync_successData5 *response)
START_TIME_TYPE global_start_time
void test3cConnected(void *context, char *cause)
void MQTTAsync_destroy(MQTTAsync *handle)
int test5(struct Options options)
void test1dOnFailure(void *context, MQTTAsync_failureData5 *response)
#define MQTTASYNC_SUCCESS
START_TIME_TYPE start_clock(void)
void MQTTAsync_setTraceLevel(enum MQTTASYNC_TRACE_LEVELS level)
int MQTTAsync_sendMessage(MQTTAsync handle, const char *destinationName, const MQTTAsync_message *message, MQTTAsync_responseOptions *response)
void test1cOnConnect(void *context, MQTTAsync_successData5 *response)
int test3_messages_received
int test3_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
void assert3PendingTokens(MQTTAsync c)
void MyLog(int LOGA_level, char *format,...)
void test3cOnConnect(void *context, MQTTAsync_successData5 *response)
int MQTTAsync_reconnect(MQTTAsync handle)
MQTTProperties * willProperties
void waitForNoPendingTokens(MQTTAsync c)
void test3dOnConnect(void *context, MQTTAsync_successData5 *response)
int test7_messages_received
void test4cOnFailure(void *context, MQTTAsync_failureData5 *response)
int test1_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
void write_test_result(void)
void test1cOnFailure(void *context, MQTTAsync_failureData5 *response)
int test1(struct Options options)
int test5_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
int test5_messages_received
void getopts(int argc, char **argv)
#define MQTTAsync_message_initializer
int test1_will_message_received
int test5_will_message_received
void test3cOnFailure(void *context, MQTTAsync_failureData5 *response)
void test5dOnConnect(void *context, MQTTAsync_successData5 *response)
MQTTAsync_onSuccess5 * onSuccess5
void test5cConnected(void *context, char *cause)
int test2(struct Options options)
MQTTProperties * connectProperties
void test2cOnConnect(void *context, MQTTAsync_successData5 *response)
#define MQTTProperties_initializer