test9.c
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright (c) 2012, 2020 IBM Corp. and others
3  *
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v2.0
6  * and Eclipse Distribution License v1.0 which accompany this distribution.
7  *
8  * The Eclipse Public License is available at
9  * https://www.eclipse.org/legal/epl-2.0/
10  * and the Eclipse Distribution License is available at
11  * http://www.eclipse.org/org/documents/edl-v10.php.
12  *
13  * Contributors:
14  * Ian Craggs - initial API and implementation and/or initial documentation
15  * Ian Craggs - correct some compile warnings
16  * Ian Craggs - add binary will message test
17  *******************************************************************************/
18 
19 
27 #include "MQTTAsync.h"
28 #include <string.h>
29 #include <stdlib.h>
30 #include "Thread.h"
31 
32 #if !defined(_WINDOWS)
33  #include <sys/time.h>
34  #include <sys/socket.h>
35  #include <unistd.h>
36  #include <errno.h>
37 #else
38  #include <windows.h>
39 #endif
40 
41 char unique[50]; // unique suffix/prefix to add to clientid/topic etc
42 
43 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
44 
45 void usage(void)
46 {
47  printf("help!!\n");
48  exit(EXIT_FAILURE);
49 }
50 
51 struct Options
52 {
53  char* connection;
54  char* proxy_connection;
55  int verbose;
56  int test_no;
57 } options =
58 {
59  "mqtt.eclipse.org:1883",
60  "localhost:1883",
61  0,
62  0,
63 };
64 
65 void getopts(int argc, char** argv)
66 {
67  int count = 1;
68 
69  while (count < argc)
70  {
71  if (strcmp(argv[count], "--test_no") == 0)
72  {
73  if (++count < argc)
74  options.test_no = atoi(argv[count]);
75  else
76  usage();
77  }
78  else if (strcmp(argv[count], "--connection") == 0)
79  {
80  if (++count < argc)
81  options.connection = argv[count];
82  else
83  usage();
84  }
85  else if (strcmp(argv[count], "--proxy_connection") == 0)
86  {
87  if (++count < argc)
89  else
90  usage();
91  }
92  else if (strcmp(argv[count], "--verbose") == 0)
93  options.verbose = 1;
94  count++;
95  }
96 }
97 
98 
99 #define LOGA_DEBUG 0
100 #define LOGA_INFO 1
101 #include <stdarg.h>
102 #include <time.h>
103 #include <sys/timeb.h>
104 void MyLog(int LOGA_level, char* format, ...)
105 {
106  static char msg_buf[256];
107  va_list args;
108 #if defined(_WIN32) || defined(_WINDOWS)
109  struct timeb ts;
110 #else
111  struct timeval ts;
112 #endif
113  struct tm timeinfo;
114 
115  if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
116  return;
117 
118 #if defined(_WIN32) || defined(_WINDOWS)
119  ftime(&ts);
120  localtime_s(&timeinfo, &ts.time);
121 #else
122  gettimeofday(&ts, NULL);
123  localtime_r(&ts.tv_sec, &timeinfo);
124 #endif
125  strftime(msg_buf, 80, "%Y%m%d %H%M%S", &timeinfo);
126 
127 #if defined(_WIN32) || defined(_WINDOWS)
128  sprintf(&msg_buf[strlen(msg_buf)], ".%.3hu ", ts.millitm);
129 #else
130  sprintf(&msg_buf[strlen(msg_buf)], ".%.3lu ", ts.tv_usec / 1000);
131 #endif
132 
133  va_start(args, format);
134  vsnprintf(&msg_buf[strlen(msg_buf)], sizeof(msg_buf) - strlen(msg_buf), format, args);
135  va_end(args);
136 
137  printf("%s\n", msg_buf);
138  fflush(stdout);
139 }
140 
141 void MySleep(long milliseconds)
142 {
143 #if defined(_WIN32) || defined(_WIN64)
144  Sleep(milliseconds);
145 #else
146  usleep(milliseconds*1000);
147 #endif
148 }
149 
150 #if defined(_WIN32) || defined(_WINDOWS)
151 #define START_TIME_TYPE DWORD
152 static DWORD start_time = 0;
154 {
155  return GetTickCount();
156 }
157 #elif defined(AIX)
158 #define START_TIME_TYPE struct timespec
160 {
161  static struct timespec start;
162  clock_gettime(CLOCK_REALTIME, &start);
163  return start;
164 }
165 #else
166 #define START_TIME_TYPE struct timeval
167 /* TODO - unused - remove? static struct timeval start_time; */
169 {
170  struct timeval start_time;
171  gettimeofday(&start_time, NULL);
172  return start_time;
173 }
174 #endif
175 
176 #if defined(_WIN32)
177 long elapsed(START_TIME_TYPE start_time)
178 {
179  return GetTickCount() - start_time;
180 }
181 #elif defined(AIX)
182 #define assert(a)
183 long elapsed(struct timespec start)
184 {
185  struct timespec now, res;
186 
187  clock_gettime(CLOCK_REALTIME, &now);
188  ntimersub(now, start, res);
189  return (res.tv_sec)*1000L + (res.tv_nsec)/1000000L;
190 }
191 #else
192 long elapsed(START_TIME_TYPE start_time)
193 {
194  struct timeval now, res;
195 
196  gettimeofday(&now, NULL);
197  timersub(&now, &start_time, &res);
198  return (res.tv_sec) * 1000 + (res.tv_usec) / 1000;
199 }
200 #endif
201 
202 #define assert(a, b, c, d) myassert(__FILE__, __LINE__, a, b, c, d)
203 #define assert1(a, b, c, d, e) myassert(__FILE__, __LINE__, a, b, c, d, e)
204 
205 #define MAXMSGS 30;
206 
207 int tests = 0;
208 int failures = 0;
209 FILE* xml;
211 char output[3000];
213 
214 
216 {
217  long duration = elapsed(global_start_time);
218 
219  fprintf(xml, " time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000);
220  if (cur_output != output)
221  {
222  fprintf(xml, "%s", output);
223  cur_output = output;
224  }
225  fprintf(xml, "</testcase>\n");
226 }
227 
228 void myassert(char* filename, int lineno, char* description, int value,
229  char* format, ...)
230 {
231  ++tests;
232  if (!value)
233  {
234  va_list args;
235 
236  ++failures;
237  MyLog(LOGA_INFO, "Assertion failed, file %s, line %d, description: %s", filename,
238  lineno, description);
239 
240  va_start(args, format);
241  vprintf(format, args);
242  va_end(args);
243 
244  cur_output += sprintf(cur_output, "<failure type=\"%s\">file %s, line %d </failure>\n",
245  description, filename, lineno);
246  }
247  else
248  MyLog(LOGA_DEBUG, "Assertion succeeded, file %s, line %d, description: %s",
249  filename, lineno, description);
250 }
251 
252 
254 {
255  int i = 0, rc = 0, count = 0;
256  MQTTAsync_token *tokens;
257 
258  /* acks for outgoing messages could arrive after incoming exchanges are complete */
259  do
260  {
261  rc = MQTTAsync_getPendingTokens(c, &tokens);
262  assert("Good rc from getPendingTokens", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
263  i = 0;
264  if (tokens)
265  {
266  while (tokens[i] != -1)
267  ++i;
268  MQTTAsync_free(tokens);
269  }
270  if (i > 0)
271  MySleep(100);
272  }
273  while (i > 0 && ++count < 10);
274  assert("Number of getPendingTokens should be 0", i == 0, "i was %d ", i);
275 }
276 
277 
279 {
280  int i = 0, rc = 0;
281  MQTTAsync_token *tokens;
282 
283  rc = MQTTAsync_getPendingTokens(c, &tokens);
284  assert("Good rc from getPendingTokens", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
285  i = 0;
286  if (tokens)
287  {
288  while (tokens[i] != -1)
289  ++i;
290  MQTTAsync_free(tokens);
291  }
292  assert("Number of getPendingTokens should be 3", i == 3, "i was %d\n", i);
293 }
294 
295 /*********************************************************************
296 
297  Tests: offline buffering - sending messages while disconnected
298 
299  1. send some messages while disconnected, check that they are sent
300  2. repeat test 1 using serverURIs
301  3. repeat test 1 using auto reconnect
302  4. repeat test 2 using auto reconnect
303  5. check max-buffered
304  6. check auto-reconnect parms alter behaviour as expected
305 
306  Tests: automatic reconnect
307 
308  - check that connected() is called
309  - check that reconnect() causes reconnect attempt
310  - check that reconnect() fails if no connect has been previously attempted
311 
312  *********************************************************************/
313 
314 void handleTrace(enum MQTTASYNC_TRACE_LEVELS level, char* message)
315 {
316  printf("%s\n", message);
317 }
318 
319 
320 /*********************************************************************
321 
322  Test1: offline buffering - sending messages while disconnected
323 
324  1. call connect
325  2. use proxy to disconnect the client
326  3. while the client is disconnected, send more messages
327  4. when the client reconnects, check that those messages are sent
328 
329  *********************************************************************/
330 
333 
334 int test1_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
335 {
336  MQTTAsync c = (MQTTAsync)context;
337  static int message_count = 0;
338 
339  MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\"", topicName, message->payloadlen, message->payload);
340 
341  if (memcmp(message->payload, "will message", message->payloadlen) == 0)
343  else
345 
346  MQTTAsync_freeMessage(&message);
347  MQTTAsync_free(topicName);
348 
349  return 1;
350 }
351 
353 
355 
357 {
358  MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context);
359 
361  test1Finished = 1;
362 }
363 
365 {
366  MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context);
367 
369  test1Finished = 1;
370 }
371 
373 {
375  MyLog(LOGA_DEBUG, "In connect onSuccess callback for client d, context %p\n", context);
376  MQTTAsync c = (MQTTAsync)context;
377  int rc;
378 
379  /* send a message to the proxy to break the connection */
380  pubmsg.payload = "TERMINATE";
381  pubmsg.payloadlen = (int)strlen(pubmsg.payload);
382  pubmsg.qos = 0;
383  pubmsg.retained = 0;
384  rc = MQTTAsync_sendMessage(c, "MQTTSAS topic", &pubmsg, NULL);
385  assert("Good rc from sendMessage", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
386 }
387 
388 
389 int test1dReady = 0;
390 char willTopic[100];
391 char test_topic[100];
392 
394 {
395  MQTTAsync c = (MQTTAsync)context;
396  MyLog(LOGA_DEBUG, "In subscribe onSuccess callback for client d, %p granted qos %d", c, response->alt.qos);
397  test1dReady = 1;
398 }
399 
400 
402 {
403  MQTTAsync c = (MQTTAsync)context;
405  int rc;
406  int qoss[2] = {2, 2};
407  char* topics[2] = {willTopic, test_topic};
408 
409  MyLog(LOGA_DEBUG, "In connect onSuccess callback for client c, context %p\n", context);
411  opts.context = c;
412 
413  rc = MQTTAsync_subscribeMany(c, 2, topics, qoss, &opts);
414  assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
415  if (rc != MQTTASYNC_SUCCESS)
416  test1Finished = 1;
417 }
418 
420 
421 void test1cConnected(void* context, char* cause)
422 {
423  MQTTAsync c = (MQTTAsync)context;
424 
425  MyLog(LOGA_DEBUG, "In connected callback for client c, context %p\n", context);
426  test1c_connected = 1;
427 }
428 
429 
430 int test1(struct Options options)
431 {
432  char* testname = "test1";
433  int subsqos = 2;
434  MQTTAsync c, d;
438  int rc = 0;
439  int count = 0;
440  char clientidc[70];
441  char clientidd[70];
442  int i = 0;
443 
444  sprintf(willTopic, "paho-test9-1-%s", unique);
445  sprintf(clientidc, "paho-test9-1-c-%s", unique);
446  sprintf(clientidd, "paho-test9-1-d-%s", unique);
447  sprintf(test_topic, "paho-test9-1-test topic %s", unique);
448 
449  test1Finished = 0;
450  failures = 0;
451  MyLog(LOGA_INFO, "Starting Offline buffering 1 - messages while disconnected");
452  fprintf(xml, "<testcase classname=\"test1\" name=\"%s\"", testname);
454 
455  createOptions.sendWhileDisconnected = 1;
457  NULL, &createOptions);
458  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
459  if (rc != MQTTASYNC_SUCCESS)
460  {
461  MQTTAsync_destroy(&c);
462  goto exit;
463  }
464 
465  rc = MQTTAsync_create(&d, options.connection, clientidd, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
466  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
467  if (rc != MQTTASYNC_SUCCESS)
468  {
469  MQTTAsync_destroy(&c);
470  goto exit;
471  }
472 
473  opts.keepAliveInterval = 5;
474  opts.cleansession = 1;
475  //opts.username = "testuser";
476  //opts.password = "testpassword";
477 
478  rc = MQTTAsync_setCallbacks(d, d, NULL, test1_messageArrived, NULL);
479  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
480 
481  opts.will = NULL; /* don't need will for this client, as it's going to be connected all the time */
482  opts.context = d;
483  opts.onSuccess = test1dOnConnect;
484  opts.onFailure = test1dOnFailure;
485  MyLog(LOGA_DEBUG, "Connecting client d");
486  rc = MQTTAsync_connect(d, &opts);
487  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
488  if (rc != MQTTASYNC_SUCCESS)
489  {
490  failures++;
491  goto exit;
492  }
493 
494  /* wait until d is ready: connected and subscribed */
495  count = 0;
496  while (!test1dReady && ++count < 10000)
497  MySleep(100);
498  assert("Count should be less than 10000", count < 10000, "count was %d", count); /* wrong */
499 
501  assert("Good rc from setConnectedCallback", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
502 
503  /* let client c go: connect, and send disconnect command to proxy */
504  opts.will = &wopts;
505  opts.will->message = "will message";
506  opts.will->qos = 1;
507  opts.will->retained = 0;
508  opts.will->topicName = willTopic;
509  opts.onSuccess = test1cOnConnect;
510  opts.onFailure = test1cOnFailure;
511  opts.context = c;
512  opts.cleansession = 0;
513 
514  MyLog(LOGA_DEBUG, "Connecting client c");
515  rc = MQTTAsync_connect(c, &opts);
516  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
517  if (rc != MQTTASYNC_SUCCESS)
518  {
519  failures++;
520  goto exit;
521  }
522 
523  /* wait for will message */
524  while (!test1_will_message_received && ++count < 10000)
525  MySleep(100);
526  /* ensure not connected */
527  while (MQTTAsync_isConnected(c) && ++count < 10000)
528  MySleep(100);
529 
530  MyLog(LOGA_DEBUG, "Now we can send some messages to be buffered");
531 
532  test1c_connected = 0;
533  /* send some messages. Then reconnect (check connected callback), and check that those messages are received */
534  for (i = 0; i < 3; ++i)
535  {
536  char buf[50];
537 
540  sprintf(buf, "QoS %d message", i);
541  pubmsg.payload = buf;
542  pubmsg.payloadlen = (int)strlen(pubmsg.payload) + 1;
543  pubmsg.qos = i;
544  pubmsg.retained = 0;
545  rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts);
546  assert("Good rc from sendMessage", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
547  }
548 
550 
551  rc = MQTTAsync_reconnect(c);
552  assert("Good rc from reconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
553 
554  /* wait for client to be reconnected */
555  while (!test1c_connected && ++count < 10000)
556  MySleep(100);
557 
558  /* wait for success or failure callback */
559  while (test1_messages_received < 3 && ++count < 10000)
560  MySleep(100);
561 
563 
564  rc = MQTTAsync_disconnect(c, NULL);
565  assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
566 
567  rc = MQTTAsync_disconnect(d, NULL);
568  assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
569 
570 exit:
571  MQTTAsync_destroy(&c);
572  MQTTAsync_destroy(&d);
573  MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
574  (failures == 0) ? "passed" : "failed", testname, tests, failures);
576  return failures;
577 }
578 
579 
580 /*********************************************************************
581 
582  Test2: offline buffering - sending messages while disconnected
583 
584  1. call connect
585  2. use proxy to disconnect the client
586  3. while the client is disconnected, send more messages
587  4. when the client reconnects, check that those messages are sent
588 
589  *********************************************************************/
590 
593 
594 int test2_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
595 {
596  MQTTAsync c = (MQTTAsync)context;
597  static int message_count = 0;
598 
599  MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\"", topicName, message->payloadlen, message->payload);
600 
601  if (memcmp(message->payload, "will message", message->payloadlen) == 0)
603  else
605 
606  MQTTAsync_freeMessage(&message);
607  MQTTAsync_free(topicName);
608 
609  return 1;
610 }
611 
613 
615 
617 {
618  MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context);
619 
621  test2Finished = 1;
622 }
623 
625 {
626  MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context);
627 
629  test2Finished = 1;
630 }
631 
633 {
635  MyLog(LOGA_DEBUG, "In connect onSuccess callback for client d, context %p\n", context);
636  MQTTAsync c = (MQTTAsync)context;
637  int rc;
638 
639  /* send a message to the proxy to break the connection */
640  pubmsg.payload = "TERMINATE";
641  pubmsg.payloadlen = (int)strlen(pubmsg.payload);
642  pubmsg.qos = 0;
643  pubmsg.retained = 0;
644  rc = MQTTAsync_sendMessage(c, "MQTTSAS topic", &pubmsg, NULL);
645  assert("Good rc from sendMessage", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
646 }
647 
648 
649 int test2dReady = 0;
650 char willTopic[100];
651 char test_topic[100];
652 
654 {
655  MQTTAsync c = (MQTTAsync)context;
656  MyLog(LOGA_DEBUG, "In subscribe onSuccess callback for client d, %p granted qos %d", c, response->alt.qos);
657  test2dReady = 1;
658 }
659 
660 
662 {
663  MQTTAsync c = (MQTTAsync)context;
665  int rc;
666  int qoss[2] = {2, 2};
667  char* topics[2] = {willTopic, test_topic};
668 
669  MyLog(LOGA_DEBUG, "In connect onSuccess callback for client c, context %p\n", context);
671  opts.context = c;
672 
673  rc = MQTTAsync_subscribeMany(c, 2, topics, qoss, &opts);
674  assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
675  if (rc != MQTTASYNC_SUCCESS)
676  test2Finished = 1;
677 }
678 
680 
681 void test2cConnected(void* context, char* cause)
682 {
683  MQTTAsync c = (MQTTAsync)context;
684 
685  MyLog(LOGA_DEBUG, "In connected callback for client c, context %p\n", context);
686  test2c_connected = 1;
687 }
688 
689 
690 int test2(struct Options options)
691 {
692  char* testname = "test2";
693  int subsqos = 2;
694  MQTTAsync c, d;
698  int rc = 0;
699  int count = 0;
700  char clientidc[70];
701  char clientidd[70];
702  int i = 0;
703  char *URIs[2] = {"rubbish", options.proxy_connection};
704 
705  sprintf(willTopic, "paho-test9-2-%s", unique);
706  sprintf(clientidc, "paho-test9-2-c-%s", unique);
707  sprintf(clientidd, "paho-test9-2-d-%s", unique);
708  sprintf(test_topic, "paho-test9-2-test topic %s", unique);
709 
710  test2Finished = 0;
711  failures = 0;
712  MyLog(LOGA_INFO, "Starting Offline buffering 2 - messages while disconnected with serverURIs");
713  fprintf(xml, "<testcase classname=\"test2\" name=\"%s\"", testname);
715 
716  createOptions.sendWhileDisconnected = 1;
717  rc = MQTTAsync_createWithOptions(&c, "not used", clientidc, MQTTCLIENT_PERSISTENCE_DEFAULT,
718  NULL, &createOptions);
719  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
720  if (rc != MQTTASYNC_SUCCESS)
721  {
722  MQTTAsync_destroy(&c);
723  goto exit;
724  }
725 
726  rc = MQTTAsync_create(&d, options.connection, clientidd, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
727  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
728  if (rc != MQTTASYNC_SUCCESS)
729  {
730  MQTTAsync_destroy(&c);
731  goto exit;
732  }
733 
734  opts.keepAliveInterval = 5;
735  opts.cleansession = 1;
736 
737  rc = MQTTAsync_setCallbacks(d, d, NULL, test2_messageArrived, NULL);
738  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
739 
740  opts.will = NULL; /* don't need will for this client, as it's going to be connected all the time */
741  opts.context = d;
742  opts.onSuccess = test2dOnConnect;
743  opts.onFailure = test2dOnFailure;
744  MyLog(LOGA_DEBUG, "Connecting client d");
745  rc = MQTTAsync_connect(d, &opts);
746  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
747  if (rc != MQTTASYNC_SUCCESS)
748  {
749  failures++;
750  goto exit;
751  }
752 
753  /* wait until d is ready: connected and subscribed */
754  count = 0;
755  while (!test2dReady && ++count < 300)
756  MySleep(100);
757  assert("Count should be less than 300", count < 300, "count was %d", count); /* wrong */
758 
760  assert("Good rc from setConnectedCallback", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
761 
762  /* let client c go: connect, and send disconnect command to proxy */
763  opts.will = &wopts;
764  opts.will->message = "will message";
765  opts.will->qos = 1;
766  opts.will->retained = 0;
767  opts.will->topicName = willTopic;
768  opts.onSuccess = test2cOnConnect;
769  opts.onFailure = test2cOnFailure;
770  opts.context = c;
771  opts.cleansession = 0;
772  opts.serverURIs = URIs;
773  opts.serverURIcount = 2;
775 
776  MyLog(LOGA_DEBUG, "Connecting client c");
777  rc = MQTTAsync_connect(c, &opts);
778  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
779  if (rc != MQTTASYNC_SUCCESS)
780  {
781  failures++;
782  goto exit;
783  }
784 
785  /* wait for will message */
786  count = 0;
787  while (!test2_will_message_received && ++count < 300)
788  MySleep(100);
789  assert("Count should be less than 300", count < 300, "count was %d", count); /* wrong */
790  /* ensure not connected */
791  count = 0;
792  while (MQTTAsync_isConnected(c) && ++count < 300)
793  MySleep(100);
794  assert("Count should be less than 300", count < 300, "count was %d", count); /* wrong */
795 
796  MyLog(LOGA_DEBUG, "Now we can send some messages to be buffered");
797 
798  test2c_connected = 0;
799  /* send some messages. Then reconnect (check connected callback), and check that those messages are received */
800  for (i = 0; i < 3; ++i)
801  {
802  char buf[50];
803 
806  sprintf(buf, "QoS %d message", i);
807  pubmsg.payload = buf;
808  pubmsg.payloadlen = (int)(strlen(pubmsg.payload) + 1);
809  pubmsg.qos = i;
810  pubmsg.retained = 0;
811  rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts);
812  assert("Good rc from sendMessage", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
813  }
814 
816 
817  rc = MQTTAsync_reconnect(c);
818  assert("Good rc from reconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
819 
820  /* wait for client to be reconnected */
821  count = 0;
822  while (!test2c_connected && ++count < 300)
823  MySleep(100);
824  assert("Count should be less than 300", count < 300, "count was %d", count); /* wrong */
825 
826  /* wait for success or failure callback */
827  count = 0;
828  while (test2_messages_received < 3 && ++count < 300)
829  MySleep(100);
830  assert("Count should be less than 300", count < 300, "count was %d", count); /* wrong */
831 
833 
834  rc = MQTTAsync_disconnect(c, NULL);
835  assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
836 
837  rc = MQTTAsync_disconnect(d, NULL);
838  assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
839 
840 exit:
841  MySleep(200);
842  MQTTAsync_destroy(&c);
843  MQTTAsync_destroy(&d);
844  MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
845  (failures == 0) ? "passed" : "failed", testname, tests, failures);
847  return failures;
848 }
849 
850 /*********************************************************************
851 
852  test3: offline buffering - sending messages while disconnected
853 
854  1. call connect
855  2. use proxy to disconnect the client
856  3. while the client is disconnected, send more messages
857  4. when the client auto reconnects, check that those messages are sent
858 
859  *********************************************************************/
860 
863 
864 int test3_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
865 {
866  MQTTAsync c = (MQTTAsync)context;
867  static int message_count = 0;
868 
869  MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\"", topicName, message->payloadlen, message->payload);
870 
871  if (memcmp(message->payload, "will message", message->payloadlen) == 0)
873  else
875 
876  MQTTAsync_freeMessage(&message);
877  MQTTAsync_free(topicName);
878 
879  return 1;
880 }
881 
883 
885 
887 {
888  MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context);
889 
891  test3Finished = 1;
892 }
893 
895 {
896  MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context);
897 
899  test3Finished = 1;
900 }
901 
903 {
905  MyLog(LOGA_DEBUG, "In connect onSuccess callback for client d, context %p\n", context);
906  MQTTAsync c = (MQTTAsync)context;
907  int rc;
908 
909  /* send a message to the proxy to break the connection */
910  pubmsg.payload = "TERMINATE";
911  pubmsg.payloadlen = (int)strlen(pubmsg.payload);
912  pubmsg.qos = 0;
913  pubmsg.retained = 0;
914  rc = MQTTAsync_sendMessage(c, "MQTTSAS topic", &pubmsg, NULL);
915  assert("Good rc from sendMessage", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
916 }
917 
918 
919 int test3dReady = 0;
920 char willTopic[100];
921 char test_topic[100];
922 
924 {
925  MQTTAsync c = (MQTTAsync)context;
926  MyLog(LOGA_DEBUG, "In subscribe onSuccess callback for client d, %p granted qos %d", c, response->alt.qos);
927  test3dReady = 1;
928 }
929 
930 
932 {
933  MQTTAsync c = (MQTTAsync)context;
935  int rc;
936  int qoss[2] = {2, 2};
937  char* topics[2] = {willTopic, test_topic};
938 
939  MyLog(LOGA_DEBUG, "In connect onSuccess callback for client c, context %p\n", context);
941  opts.context = c;
942 
943  rc = MQTTAsync_subscribeMany(c, 2, topics, qoss, &opts);
944  assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
945  if (rc != MQTTASYNC_SUCCESS)
946  test3Finished = 1;
947 }
948 
950 
951 void test3cConnected(void* context, char* cause)
952 {
953  MQTTAsync c = (MQTTAsync)context;
954 
955  MyLog(LOGA_DEBUG, "In connected callback for client c, context %p\n", context);
956  test3c_connected = 1;
957 }
958 
959 
960 int test3(struct Options options)
961 {
962  char* testname = "test3";
963  int subsqos = 2;
964  MQTTAsync c, d;
968  int rc = 0;
969  int count = 0;
970  char clientidc[70];
971  char clientidd[70];
972  int i = 0;
973 
974  sprintf(willTopic, "paho-test9-3-%s", unique);
975  sprintf(clientidc, "paho-test9-3-c-%s", unique);
976  sprintf(clientidd, "paho-test9-3-d-%s", unique);
977  sprintf(test_topic, "paho-test9-3-test topic %s", unique);
978 
979  test3Finished = 0;
980  failures = 0;
981  MyLog(LOGA_INFO, "Starting Offline buffering 3 - messages while disconnected");
982  fprintf(xml, "<testcase classname=\"test3\" name=\"%s\"", testname);
984 
985  createOptions.sendWhileDisconnected = 1;
987  NULL, &createOptions);
988  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
989  if (rc != MQTTASYNC_SUCCESS)
990  {
991  MQTTAsync_destroy(&c);
992  goto exit;
993  }
994 
995  rc = MQTTAsync_create(&d, options.connection, clientidd, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
996  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
997  if (rc != MQTTASYNC_SUCCESS)
998  {
999  MQTTAsync_destroy(&c);
1000  goto exit;
1001  }
1002 
1003  opts.keepAliveInterval = 5;
1004  opts.cleansession = 1;
1005  //opts.username = "testuser";
1006  //opts.password = "testpassword";
1007 
1008  rc = MQTTAsync_setCallbacks(d, d, NULL, test3_messageArrived, NULL);
1009  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1010 
1011  opts.will = NULL; /* don't need will for this client, as it's going to be connected all the time */
1012  opts.context = d;
1013  opts.onSuccess = test3dOnConnect;
1014  opts.onFailure = test3dOnFailure;
1015  MyLog(LOGA_DEBUG, "Connecting client d");
1016  rc = MQTTAsync_connect(d, &opts);
1017  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
1018  if (rc != MQTTASYNC_SUCCESS)
1019  {
1020  failures++;
1021  goto exit;
1022  }
1023 
1024  /* wait until d is ready: connected and subscribed */
1025  count = 0;
1026  while (!test3dReady && ++count < 10000)
1027  MySleep(100);
1028  assert("Count should be less than 10000", count < 10000, "count was %d", count); /* wrong */
1029 
1031  assert("Good rc from setConnectedCallback", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1032 
1033  /* let client c go: connect, and send disconnect command to proxy */
1034  opts.will = &wopts;
1035  opts.will->message = "will message";
1036  opts.will->qos = 1;
1037  opts.will->retained = 0;
1038  opts.will->topicName = willTopic;
1039  opts.onSuccess = test3cOnConnect;
1040  opts.onFailure = test3cOnFailure;
1041  opts.context = c;
1042  opts.cleansession = 0;
1043  opts.automaticReconnect = 1;
1044 
1045  MyLog(LOGA_DEBUG, "Connecting client c");
1046  rc = MQTTAsync_connect(c, &opts);
1047  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
1048  if (rc != MQTTASYNC_SUCCESS)
1049  {
1050  failures++;
1051  goto exit;
1052  }
1053 
1054  /* wait for will message */
1055  while (!test3_will_message_received && ++count < 10000)
1056  MySleep(100);
1057  /* ensure not connected */
1058  while (MQTTAsync_isConnected(c) && ++count < 10000)
1059  MySleep(100);
1060 
1061  MyLog(LOGA_DEBUG, "Now we can send some messages to be buffered");
1062 
1063  test3c_connected = 0;
1064  /* send some messages. Then reconnect (check connected callback), and check that those messages are received */
1065  for (i = 0; i < 3; ++i)
1066  {
1067  char buf[50];
1068 
1071  sprintf(buf, "QoS %d message", i);
1072  pubmsg.payload = buf;
1073  pubmsg.payloadlen = (int)(strlen(pubmsg.payload) + 1);
1074  pubmsg.qos = i;
1075  pubmsg.retained = 0;
1076  rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts);
1077  assert("Good rc from sendMessage", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
1078  }
1079 
1081 
1082  /* wait for client to be reconnected */
1083  while (!test3c_connected && ++count < 10000)
1084  MySleep(100);
1085 
1086  /* wait for success or failure callback */
1087  while (test3_messages_received < 3 && ++count < 10000)
1088  MySleep(100);
1089 
1091 
1092  rc = MQTTAsync_disconnect(c, NULL);
1093  assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
1094 
1095  rc = MQTTAsync_disconnect(d, NULL);
1096  assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
1097 
1098 exit:
1099  MySleep(200);
1100  MQTTAsync_destroy(&c);
1101  MQTTAsync_destroy(&d);
1102  MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
1103  (failures == 0) ? "passed" : "failed", testname, tests, failures);
1105  return failures;
1106 }
1107 
1108 /*********************************************************************
1109 
1110  test4: offline buffering - sending messages while disconnected
1111 
1112  1. call connect
1113  2. use proxy to disconnect the client
1114  3. while the client is disconnected, send more messages
1115  4. when the client auto reconnects, check that those messages are sent
1116 
1117  *********************************************************************/
1118 
1121 
1122 int test4_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
1123 {
1124  MQTTAsync c = (MQTTAsync)context;
1125  static int message_count = 0;
1126 
1127  MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\"", topicName, message->payloadlen, message->payload);
1128 
1129  if (memcmp(message->payload, "will message", message->payloadlen) == 0)
1131  else
1133 
1134  MQTTAsync_freeMessage(&message);
1135  MQTTAsync_free(topicName);
1136 
1137  return 1;
1138 }
1139 
1141 
1143 
1145 {
1146  MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context);
1147 
1149  test4Finished = 1;
1150 }
1151 
1153 {
1154  MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context);
1155 
1157  test4Finished = 1;
1158 }
1159 
1161 {
1163  MyLog(LOGA_DEBUG, "In connect onSuccess callback for client d, context %p\n", context);
1164  MQTTAsync c = (MQTTAsync)context;
1165  int rc;
1166 
1167  /* send a message to the proxy to break the connection */
1168  pubmsg.payload = "TERMINATE";
1169  pubmsg.payloadlen = (int)strlen(pubmsg.payload);
1170  pubmsg.qos = 0;
1171  pubmsg.retained = 0;
1172  rc = MQTTAsync_sendMessage(c, "MQTTSAS topic", &pubmsg, NULL);
1173  assert("Good rc from sendMessage", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1174 }
1175 
1176 
1177 int test4dReady = 0;
1178 char willTopic[100];
1179 char test_topic[100];
1180 
1182 {
1183  MQTTAsync c = (MQTTAsync)context;
1184  MyLog(LOGA_DEBUG, "In subscribe onSuccess callback for client d, %p granted qos %d", c, response->alt.qos);
1185  test4dReady = 1;
1186 }
1187 
1188 
1190 {
1191  MQTTAsync c = (MQTTAsync)context;
1193  int rc;
1194  int qoss[2] = {2, 2};
1195  char* topics[2] = {willTopic, test_topic};
1196 
1197  MyLog(LOGA_DEBUG, "In connect onSuccess callback for client c, context %p\n", context);
1199  opts.context = c;
1200 
1201  rc = MQTTAsync_subscribeMany(c, 2, topics, qoss, &opts);
1202  assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1203  if (rc != MQTTASYNC_SUCCESS)
1204  test4Finished = 1;
1205 }
1206 
1208 
1209 void test4cConnected(void* context, char* cause)
1210 {
1211  MQTTAsync c = (MQTTAsync)context;
1212 
1213  MyLog(LOGA_DEBUG, "In connected callback for client c, context %p\n", context);
1214  test4c_connected = 1;
1215 }
1216 
1217 
1218 int test4(struct Options options)
1219 {
1220  char* testname = "test4";
1221  int subsqos = 2;
1222  MQTTAsync c, d;
1226  int rc = 0;
1227  int count = 0;
1228  char clientidc[70];
1229  char clientidd[70];
1230  int i = 0;
1231  char *URIs[2] = {"rubbish", options.proxy_connection};
1232 
1233  sprintf(willTopic, "paho-test9-4-%s", unique);
1234  sprintf(clientidc, "paho-test9-4-c-%s", unique);
1235  sprintf(clientidd, "paho-test9-4-d-%s", unique);
1236  sprintf(test_topic, "paho-test9-4-test topic %s", unique);
1237 
1238  test4Finished = 0;
1239  failures = 0;
1240  MyLog(LOGA_INFO, "Starting Offline buffering 4 - messages while disconnected with serverURIs");
1241  fprintf(xml, "<testcase classname=\"test4\" name=\"%s\"", testname);
1243 
1244  createOptions.sendWhileDisconnected = 1;
1245  rc = MQTTAsync_createWithOptions(&c, "not used", clientidc, MQTTCLIENT_PERSISTENCE_DEFAULT,
1246  NULL, &createOptions);
1247  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
1248  if (rc != MQTTASYNC_SUCCESS)
1249  {
1250  MQTTAsync_destroy(&c);
1251  goto exit;
1252  }
1253 
1254  rc = MQTTAsync_create(&d, options.connection, clientidd, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
1255  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
1256  if (rc != MQTTASYNC_SUCCESS)
1257  {
1258  MQTTAsync_destroy(&c);
1259  goto exit;
1260  }
1261 
1262  opts.keepAliveInterval = 5;
1263  opts.cleansession = 1;
1264 
1265  rc = MQTTAsync_setCallbacks(d, d, NULL, test4_messageArrived, NULL);
1266  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1267 
1268  opts.will = NULL; /* don't need will for this client, as it's going to be connected all the time */
1269  opts.context = d;
1270  opts.onSuccess = test4dOnConnect;
1271  opts.onFailure = test4dOnFailure;
1272  MyLog(LOGA_DEBUG, "Connecting client d");
1273  rc = MQTTAsync_connect(d, &opts);
1274  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
1275  if (rc != MQTTASYNC_SUCCESS)
1276  {
1277  failures++;
1278  goto exit;
1279  }
1280 
1281  /* wait until d is ready: connected and subscribed */
1282  count = 0;
1283  while (!test4dReady && ++count < 10000)
1284  MySleep(100);
1285  assert("Count should be less than 10000", count < 10000, "count was %d", count); /* wrong */
1286 
1288  assert("Good rc from setConnectedCallback", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1289 
1290  /* let client c go: connect, and send disconnect command to proxy */
1291  opts.will = &wopts;
1292  opts.will->message = "will message";
1293  opts.will->qos = 1;
1294  opts.will->retained = 0;
1295  opts.will->topicName = willTopic;
1296  opts.onSuccess = test4cOnConnect;
1297  opts.onFailure = test4cOnFailure;
1298  opts.context = c;
1299  opts.cleansession = 0;
1300  opts.serverURIs = URIs;
1301  opts.serverURIcount = 2;
1302  opts.automaticReconnect = 1;
1303 
1304  MyLog(LOGA_DEBUG, "Connecting client c");
1305  rc = MQTTAsync_connect(c, &opts);
1306  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
1307  if (rc != MQTTASYNC_SUCCESS)
1308  {
1309  failures++;
1310  goto exit;
1311  }
1312 
1313  /* wait for will message */
1314  while (!test4_will_message_received && ++count < 10000)
1315  MySleep(100);
1316  /* ensure not connected */
1317  while (MQTTAsync_isConnected(c) && ++count < 10000)
1318  MySleep(100);
1319 
1320  MyLog(LOGA_DEBUG, "Now we can send some messages to be buffered");
1321 
1322  test4c_connected = 0;
1323  /* send some messages. Then reconnect (check connected callback), and check that those messages are received */
1324  for (i = 0; i < 3; ++i)
1325  {
1326  char buf[50];
1327 
1330  sprintf(buf, "QoS %d message", i);
1331  pubmsg.payload = buf;
1332  pubmsg.payloadlen = (int)(strlen(pubmsg.payload) + 1);
1333  pubmsg.qos = i;
1334  pubmsg.retained = 0;
1335  rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts);
1336  assert("Good rc from sendMessage", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
1337  }
1338 
1340 
1341  /* wait for client to be reconnected */
1342  while (!test4c_connected && ++count < 10000)
1343  MySleep(100);
1344 
1345  /* wait for success or failure callback */
1346  while (test4_messages_received < 3 && ++count < 10000)
1347  MySleep(100);
1348 
1350 
1351  rc = MQTTAsync_disconnect(c, NULL);
1352  assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
1353 
1354  rc = MQTTAsync_disconnect(d, NULL);
1355  assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
1356 
1357 exit:
1358  MySleep(200);
1359  MQTTAsync_destroy(&c);
1360  MQTTAsync_destroy(&d);
1361  MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
1362  (failures == 0) ? "passed" : "failed", testname, tests, failures);
1364  return failures;
1365 }
1366 
1367 
1368 /*********************************************************************
1369 
1370  test5: offline buffering - check max buffered
1371 
1372  1. call connect
1373  2. use proxy to disconnect the client
1374  3. while the client is disconnected, send more messages
1375  4. when the client reconnects, check that those messages are sent
1376 
1377  *********************************************************************/
1378 
1384 
1385 int test5_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
1386 {
1387  MQTTAsync c = (MQTTAsync)context;
1388  static int message_count = 0;
1389 
1390  MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\"", topicName, message->payloadlen, message->payload);
1391 
1392  if (memcmp(message->payload, "will message", message->payloadlen) == 0)
1394  else
1396 
1397  MQTTAsync_freeMessage(&message);
1398  MQTTAsync_free(topicName);
1399 
1400  return 1;
1401 }
1402 
1404 {
1405  MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context);
1406 
1408  test5Finished = 1;
1409 }
1410 
1412 {
1413  MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context);
1414 
1416  test5Finished = 1;
1417 }
1418 
1420 {
1422  MyLog(LOGA_DEBUG, "In connect onSuccess callback for client d, context %p\n", context);
1423  MQTTAsync c = (MQTTAsync)context;
1424  int rc;
1425 
1426  /* send a message to the proxy to break the connection */
1427  pubmsg.payload = "TERMINATE";
1428  pubmsg.payloadlen = (int)strlen(pubmsg.payload);
1429  pubmsg.qos = 0;
1430  pubmsg.retained = 0;
1431  rc = MQTTAsync_sendMessage(c, "MQTTSAS topic", &pubmsg, NULL);
1432  assert("Good rc from sendMessage", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1433 }
1434 
1435 
1436 int test5dReady = 0;
1437 char willTopic[100];
1438 char test_topic[100];
1439 
1441 {
1442  MQTTAsync c = (MQTTAsync)context;
1443  MyLog(LOGA_DEBUG, "In subscribe onSuccess callback for client d, %p granted qos %d", c, response->alt.qos);
1444  test5dReady = 1;
1445 }
1446 
1447 
1449 {
1450  MQTTAsync c = (MQTTAsync)context;
1452  int rc;
1453  int qoss[2] = {2, 2};
1454  char* topics[2] = {willTopic, test_topic};
1455 
1456  MyLog(LOGA_DEBUG, "In connect onSuccess callback for client c, context %p\n", context);
1458  opts.context = c;
1459 
1460  rc = MQTTAsync_subscribeMany(c, 2, topics, qoss, &opts);
1461  assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1462  if (rc != MQTTASYNC_SUCCESS)
1463  test5Finished = 1;
1464 }
1465 
1466 void test5cConnected(void* context, char* cause)
1467 {
1468  MQTTAsync c = (MQTTAsync)context;
1469 
1470  MyLog(LOGA_DEBUG, "In connected callback for client c, context %p\n", context);
1471  test5c_connected = 1;
1472 }
1473 
1474 
1475 int test5(struct Options options)
1476 {
1477  char* testname = "test5";
1478  int subsqos = 2;
1479  MQTTAsync c, d;
1483  int rc = 0;
1484  int count = 0;
1485  char clientidc[70];
1486  char clientidd[70];
1487  int i = 0;
1488 
1489  sprintf(willTopic, "paho-test9-5-%s", unique);
1490  sprintf(clientidc, "paho-test9-5-c-%s", unique);
1491  sprintf(clientidd, "paho-test9-5-d-%s", unique);
1492  sprintf(test_topic, "paho-test9-5-test topic %s", unique);
1493 
1494  test5Finished = 0;
1495  failures = 0;
1496  MyLog(LOGA_INFO, "Starting Offline buffering 5 - max buffered");
1497  fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname);
1499 
1500  createOptions.sendWhileDisconnected = 1;
1501  createOptions.maxBufferedMessages = 3;
1503  NULL, &createOptions);
1504  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
1505  if (rc != MQTTASYNC_SUCCESS)
1506  {
1507  MQTTAsync_destroy(&c);
1508  goto exit;
1509  }
1510 
1511  rc = MQTTAsync_create(&d, options.connection, clientidd, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
1512  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
1513  if (rc != MQTTASYNC_SUCCESS)
1514  {
1515  MQTTAsync_destroy(&c);
1516  goto exit;
1517  }
1518 
1519  opts.keepAliveInterval = 5;
1520  opts.cleansession = 1;
1521  //opts.username = "testuser";
1522  //opts.password = "testpassword";
1523 
1524  rc = MQTTAsync_setCallbacks(d, d, NULL, test5_messageArrived, NULL);
1525  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1526 
1527  opts.will = NULL; /* don't need will for this client, as it's going to be connected all the time */
1528  opts.context = d;
1529  opts.onSuccess = test5dOnConnect;
1530  opts.onFailure = test5dOnFailure;
1531  MyLog(LOGA_DEBUG, "Connecting client d");
1532  rc = MQTTAsync_connect(d, &opts);
1533  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
1534  if (rc != MQTTASYNC_SUCCESS)
1535  {
1536  failures++;
1537  goto exit;
1538  }
1539 
1540  /* wait until d is ready: connected and subscribed */
1541  count = 0;
1542  while (!test5dReady && ++count < 10000)
1543  MySleep(100);
1544  assert("Count should be less than 10000", count < 10000, "count was %d", count); /* wrong */
1545 
1547  assert("Good rc from setConnectedCallback", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1548 
1549  /* let client c go: connect, and send disconnect command to proxy */
1550  opts.will = &wopts;
1551  opts.will->message = "will message";
1552  opts.will->qos = 1;
1553  opts.will->retained = 0;
1554  opts.will->topicName = willTopic;
1555  opts.onSuccess = test5cOnConnect;
1556  opts.onFailure = test5cOnFailure;
1557  opts.context = c;
1558  opts.cleansession = 0;
1559 
1560  MyLog(LOGA_DEBUG, "Connecting client c");
1561  rc = MQTTAsync_connect(c, &opts);
1562  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
1563  if (rc != MQTTASYNC_SUCCESS)
1564  {
1565  failures++;
1566  goto exit;
1567  }
1568 
1569  /* wait for will message */
1570  while (!test5_will_message_received && ++count < 10000)
1571  MySleep(100);
1572  /* ensure not connected */
1573  while (MQTTAsync_isConnected(c) && ++count < 10000)
1574  MySleep(100);
1575 
1576  MyLog(LOGA_DEBUG, "Now we can send some messages to be buffered");
1577 
1578  test5c_connected = 0;
1579  /* send some messages. Then reconnect (check connected callback), and check that those messages are received */
1580  for (i = 0; i < 5; ++i)
1581  {
1582  char buf[50];
1583 
1586  sprintf(buf, "QoS %d message", i);
1587  pubmsg.payload = buf;
1588  pubmsg.payloadlen = (int)(strlen(pubmsg.payload) + 1);
1589  pubmsg.qos = i % 3;
1590  pubmsg.retained = 0;
1591  rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts);
1592  if (i <= 2)
1593  assert("Good rc from sendMessage", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
1594  else
1595  assert("Bad rc from sendMessage", rc == MQTTASYNC_MAX_BUFFERED_MESSAGES, "rc was %d ", rc);
1596  }
1597 
1599 
1600  rc = MQTTAsync_reconnect(c);
1601  assert("Good rc from reconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
1602 
1603  /* wait for client to be reconnected */
1604  while (!test5c_connected && ++count < 10000)
1605  MySleep(100);
1606 
1607  /* wait for success or failure callback */
1608  while (test5_messages_received < 3 && ++count < 10000)
1609  MySleep(100);
1610 
1612 
1613  rc = MQTTAsync_disconnect(c, NULL);
1614  assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
1615 
1616  rc = MQTTAsync_disconnect(d, NULL);
1617  assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
1618 
1619 exit:
1620  MySleep(200);
1621  MQTTAsync_destroy(&c);
1622  MQTTAsync_destroy(&d);
1623  MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
1624  (failures == 0) ? "passed" : "failed", testname, tests, failures);
1626  return failures;
1627 }
1628 
1629 
1630 int test6(struct Options options)
1631 {
1632  char* testname = "test6";
1633  int subsqos = 2;
1634  MQTTAsync c, d;
1638  int rc = 0;
1639  int count = 0;
1640  char clientidc[70];
1641  char clientidd[70];
1642  int i = 0;
1643 
1646  test5Finished = 0;
1648  test5c_connected = 0;
1649 
1650  sprintf(willTopic, "paho-test9-6-%s", unique);
1651  sprintf(clientidc, "paho-test9-6-c-%s", unique);
1652  sprintf(clientidd, "paho-test9-6-d-%s", unique);
1653  sprintf(test_topic, "paho-test9-6-test topic %s", unique);
1654 
1655  test5Finished = 0;
1656  failures = 0;
1657  MyLog(LOGA_INFO, "Starting Offline buffering 6 - max buffered with binary will");
1658  fprintf(xml, "<testcase classname=\"test6\" name=\"%s\"", testname);
1660 
1661  createOptions.sendWhileDisconnected = 1;
1662  createOptions.maxBufferedMessages = 3;
1664  NULL, &createOptions);
1665  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
1666  if (rc != MQTTASYNC_SUCCESS)
1667  {
1668  MQTTAsync_destroy(&c);
1669  goto exit;
1670  }
1671 
1672  rc = MQTTAsync_create(&d, options.connection, clientidd, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
1673  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
1674  if (rc != MQTTASYNC_SUCCESS)
1675  {
1676  MQTTAsync_destroy(&c);
1677  goto exit;
1678  }
1679 
1680  opts.keepAliveInterval = 5;
1681  opts.cleansession = 1;
1682  //opts.username = "testuser";
1683  //opts.password = "testpassword";
1684 
1685  rc = MQTTAsync_setCallbacks(d, d, NULL, test5_messageArrived, NULL);
1686  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1687 
1688  opts.will = NULL; /* don't need will for this client, as it's going to be connected all the time */
1689  opts.context = d;
1690  opts.onSuccess = test5dOnConnect;
1691  opts.onFailure = test5dOnFailure;
1692  MyLog(LOGA_DEBUG, "Connecting client d");
1693  rc = MQTTAsync_connect(d, &opts);
1694  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
1695  if (rc != MQTTASYNC_SUCCESS)
1696  {
1697  failures++;
1698  goto exit;
1699  }
1700 
1701  /* wait until d is ready: connected and subscribed */
1702  count = 0;
1703  while (!test5dReady && ++count < 10000)
1704  MySleep(100);
1705  assert("Count should be less than 10000", count < 10000, "count was %d", count); /* wrong */
1706 
1708  assert("Good rc from setConnectedCallback", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1709 
1710  /* let client c go: connect, and send disconnect command to proxy */
1711  opts.will = &wopts;
1712  opts.will->payload.data = "will message";
1713  opts.will->payload.len = (int)strlen(opts.will->payload.data) + 1;
1714  opts.will->qos = 1;
1715  opts.will->retained = 0;
1716  opts.will->topicName = willTopic;
1717  opts.onSuccess = test5cOnConnect;
1718  opts.onFailure = test5cOnFailure;
1719  opts.context = c;
1720  opts.cleansession = 0;
1721 
1722  MyLog(LOGA_DEBUG, "Connecting client c");
1723  rc = MQTTAsync_connect(c, &opts);
1724  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
1725  if (rc != MQTTASYNC_SUCCESS)
1726  {
1727  failures++;
1728  goto exit;
1729  }
1730 
1731  /* wait for will message */
1732  while (!test5_will_message_received && ++count < 10000)
1733  MySleep(100);
1734  /* ensure not connected */
1735  while (MQTTAsync_isConnected(c) && ++count < 10000)
1736  MySleep(100);
1737 
1738  MyLog(LOGA_DEBUG, "Now we can send some messages to be buffered");
1739 
1740  test5c_connected = 0;
1741  /* send some messages. Then reconnect (check connected callback), and check that those messages are received */
1742  for (i = 0; i < 5; ++i)
1743  {
1744  char buf[50];
1745 
1748  sprintf(buf, "QoS %d message", i);
1749  pubmsg.payload = buf;
1750  pubmsg.payloadlen = (int)(strlen(pubmsg.payload) + 1);
1751  pubmsg.qos = i % 3;
1752  pubmsg.retained = 0;
1753  rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts);
1754  if (i <= 2)
1755  assert("Good rc from sendMessage", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
1756  else
1757  assert("Bad rc from sendMessage", rc == MQTTASYNC_MAX_BUFFERED_MESSAGES, "rc was %d ", rc);
1758  }
1759 
1761 
1762  rc = MQTTAsync_reconnect(c);
1763  assert("Good rc from reconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
1764 
1765  /* wait for client to be reconnected */
1766  while (!test5c_connected && ++count < 10000)
1767  MySleep(100);
1768 
1769  /* wait for success or failure callback */
1770  while (test5_messages_received < 3 && ++count < 10000)
1771  MySleep(100);
1772 
1774 
1775  rc = MQTTAsync_disconnect(c, NULL);
1776  assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
1777 
1778  rc = MQTTAsync_disconnect(d, NULL);
1779  assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
1780 
1781 exit:
1782  MySleep(200);
1783  MQTTAsync_destroy(&c);
1784  MQTTAsync_destroy(&d);
1785  MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
1786  (failures == 0) ? "passed" : "failed", testname, tests, failures);
1788  return failures;
1789 }
1790 
1791 
1792 /*********************************************************************
1793 
1794 Test7: Fill up TCP buffer with QoS 0 messages
1795 
1796 *********************************************************************/
1802 int test7dReady = 0;
1803 
1804 int test7_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
1805 {
1806  MQTTAsync c = (MQTTAsync)context;
1807  static int message_count = 0;
1808 
1809  MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\"", topicName, message->payloadlen, message->payload);
1810 
1811  if (memcmp(message->payload, "will message", message->payloadlen) == 0)
1813  else
1815 
1816  MQTTAsync_freeMessage(&message);
1817  MQTTAsync_free(topicName);
1818 
1819  return 1;
1820 }
1821 
1822 void test7cConnected(void* context, char* cause)
1823 {
1824  MQTTAsync c = (MQTTAsync)context;
1825 
1826  MyLog(LOGA_DEBUG, "In connected callback for client c, context %p\n", context);
1827  test7c_connected = 1;
1828 }
1829 
1831 {
1832  MyLog(LOGA_DEBUG, "In c connect onFailure callback, context %p", context);
1833 
1835  test7Finished = 1;
1836 }
1837 
1839 {
1840  MQTTAsync c = (MQTTAsync)context;
1842 
1843  MyLog(LOGA_DEBUG, "In connect onSuccess callback for client c, context %p\n", context);
1844 
1845  /* send a message to the proxy to break the connection */
1846  pubmsg.payload = "TERMINATE";
1847  pubmsg.payloadlen = (int)strlen(pubmsg.payload);
1848  pubmsg.qos = 0;
1849  pubmsg.retained = 0;
1850  //rc = MQTTAsync_sendMessage(c, "MQTTSAS topic", &pubmsg, NULL);
1851  //assert("Good rc from sendMessage", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1852 }
1853 
1855 {
1856  MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context);
1857 
1859  test7Finished = 1;
1860 }
1861 
1862 
1864 {
1865  MQTTAsync c = (MQTTAsync)context;
1866  MyLog(LOGA_DEBUG, "In subscribe onSuccess callback for client d, %p granted qos %d", c, response->alt.qos);
1867  test7dReady = 1;
1868 }
1869 
1870 
1872 {
1873  MQTTAsync c = (MQTTAsync)context;
1875  int qoss[2] = {2, 2};
1876  char* topics[2] = {willTopic, test_topic};
1877 
1878  MyLog(LOGA_DEBUG, "In connect onSuccess callback for client c, context %p\n", context);
1880  opts.context = c;
1881 
1882  //rc = MQTTAsync_subscribeMany(c, 2, topics, qoss, &opts);
1883  //assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1884  //if (rc != MQTTASYNC_SUCCESS)
1885  // test5Finished = 1;
1886  test7dReady = 1;
1887 }
1888 
1889 
1890 int test7(struct Options options)
1891 {
1892  char* testname = "test7";
1893  int subsqos = 2;
1894  MQTTAsync c, d;
1897  //MQTTAsync_createOptions createOptions = MQTTAsync_createOptions_initializer;
1898  int rc = 0;
1899  int count = 0;
1900  char clientidc[70];
1901  char clientidd[70];
1902  int i = 0;
1903 
1906  test7Finished = 0;
1908  test7c_connected = 0;
1909 
1910  sprintf(willTopic, "paho-test9-7-%s", unique);
1911  sprintf(clientidc, "paho-test9-7-c-%s", unique);
1912  sprintf(clientidd, "paho-test9-7-d-%s", unique);
1913  sprintf(test_topic, "longer paho-test9-7-test topic %s", unique);
1914 
1915  test7Finished = 0;
1916  failures = 0;
1917  MyLog(LOGA_INFO, "Starting Offline buffering 7 - fill TCP buffer");
1918  fprintf(xml, "<testcase classname=\"test7\" name=\"%s\"", testname);
1920 
1921  rc = MQTTAsync_create(&c, options.proxy_connection, clientidc, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
1922  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
1923  if (rc != MQTTASYNC_SUCCESS)
1924  {
1925  MQTTAsync_destroy(&c);
1926  goto exit;
1927  }
1928 
1929  rc = MQTTAsync_create(&d, options.connection, clientidd, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
1930  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
1931  if (rc != MQTTASYNC_SUCCESS)
1932  {
1933  MQTTAsync_destroy(&c);
1934  goto exit;
1935  }
1936 
1937  opts.keepAliveInterval = 5;
1938  opts.cleansession = 1;
1939 
1940  rc = MQTTAsync_setCallbacks(d, d, NULL, test7_messageArrived, NULL);
1941  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1942 
1943  opts.will = NULL; /* don't need will for this client, as it's going to be connected all the time */
1944  opts.context = d;
1947  MyLog(LOGA_DEBUG, "Connecting client d");
1948  rc = MQTTAsync_connect(d, &opts);
1949  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
1950  if (rc != MQTTASYNC_SUCCESS)
1951  {
1952  failures++;
1953  goto exit;
1954  }
1955 
1956  /* wait until d is ready: connected and subscribed */
1957  count = 0;
1958  while (!test7dReady && ++count < 10000)
1959  {
1960  if (test7Finished)
1961  goto exit;
1962  MySleep(100);
1963  }
1964  assert("Count should be less than 10000", count < 10000, "count was %d", count); /* wrong */
1965 
1967  assert("Good rc from setConnectedCallback", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1968 
1969  /* let client c go: connect, and send disconnect command to proxy */
1970  opts.will = &wopts;
1971  opts.will->payload.data = "will message";
1972  opts.will->payload.len = (int)strlen(opts.will->payload.data) + 1;
1973  opts.will->qos = 1;
1974  opts.will->retained = 0;
1975  opts.will->topicName = willTopic;
1978  opts.context = c;
1979  opts.cleansession = 0;
1980  /*opts.automaticReconnect = 1;
1981  opts.minRetryInterval = 3;
1982  opts.maxRetryInterval = 6;*/
1983 
1984  MyLog(LOGA_DEBUG, "Connecting client c");
1985  rc = MQTTAsync_connect(c, &opts);
1986  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
1987  if (rc != MQTTASYNC_SUCCESS)
1988  {
1989  failures++;
1990  goto exit;
1991  }
1992 
1993  count = 0;
1994  while (!test7c_connected && ++count < 10000)
1995  MySleep(100);
1996  assert("Count should be less than 10000", count < 10000, "count was %d", count); /* wrong */
1997 
1998  /* wait for will message */
1999  //while (test7_will_message_received == 0 && ++count < 10000)
2000  // MySleep(100);
2001 
2002  MyLog(LOGA_DEBUG, "Now we can send some messages to be buffered by TCP");
2003 
2004  test7c_connected = 0;
2005  char buf[5000000];
2006  /* send some messages. Then reconnect (check connected callback), and check that those messages are received */
2007  for (i = 0; i < 50000; ++i)
2008  {
2011  pubmsg.qos = 0; /*i % 3;*/
2012  sprintf(buf, "QoS %d message", pubmsg.qos);
2013  pubmsg.payload = buf;
2014  pubmsg.payloadlen = 5000000; //(int)(strlen(pubmsg.payload) + 1);
2015  pubmsg.retained = 0;
2016  rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &pubopts);
2017  assert("Good rc from sendMessage", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
2018  if (rc != 0)
2019  {
2020  //MyLog(LOGA_DEBUG, "Connecting client c");
2021  //rc = MQTTAsync_connect(c, &opts);
2022  //MySleep(1000);
2023  break;
2024  }
2025  }
2026 
2027 #if 0
2029 
2030  rc = MQTTAsync_reconnect(c);
2031  assert("Good rc from reconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
2032 
2033  /* wait for client to be reconnected */
2034  while (!test5c_connected && ++count < 10000)
2035  MySleep(100);
2036 
2037  /* wait for success or failure callback */
2038  while (test5_messages_received < 3 && ++count < 10000)
2039  MySleep(100);
2040 
2042 #endif
2043 
2044 exit:
2045  rc = MQTTAsync_disconnect(c, NULL);
2046  assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
2047 
2048  rc = MQTTAsync_disconnect(d, NULL);
2049  assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
2050 
2051  MySleep(200);
2052  MQTTAsync_destroy(&c);
2053  MQTTAsync_destroy(&d);
2054  MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
2055  (failures == 0) ? "passed" : "failed", testname, tests, failures);
2057  return failures;
2058 }
2059 
2060 
2061 
2062 /*********************************************************************
2063 
2064 Test8: send buffered messages before connect
2065 
2066 *********************************************************************/
2073 
2074 int test8_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
2075 {
2076  MQTTAsync c = (MQTTAsync)context;
2077  static int message_count = 0;
2078 
2079  MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\"", topicName, message->payloadlen, message->payload);
2080 
2082 
2083  MQTTAsync_freeMessage(&message);
2084  MQTTAsync_free(topicName);
2085 
2086  return 1;
2087 }
2088 
2090 {
2091  MQTTAsync c = (MQTTAsync)context;
2092  MyLog(LOGA_DEBUG, "In subscribe onSuccess callback for client d, %p granted qos %d", c, response->alt.qos);
2093  test8dSubscribed = 1;
2094 }
2095 
2097 {
2098  MQTTAsync c = (MQTTAsync)context;
2100  int rc;
2101 
2102  MyLog(LOGA_DEBUG, "In connect onSuccess callback for client c, context %p\n", context);
2103  test8dConnected = 1;
2104 
2106  opts.context = c;
2107 
2108  rc = MQTTAsync_subscribe(c, test_topic, 2, &opts);
2109  assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
2110  if (rc != MQTTASYNC_SUCCESS)
2111  test8Finished = 1;
2112 }
2113 
2114 
2116 {
2117  MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context);
2118 
2120  test8Finished = 1;
2121 }
2122 
2124 {
2125  MQTTAsync c = (MQTTAsync)context;
2126  int rc;
2127 
2128  MyLog(LOGA_DEBUG, "In connect onSuccess callback for client c, context %p\n", context);
2129  test8cConnected = 1;
2130 }
2131 
2132 
2133 int test8(struct Options options)
2134 {
2135  char* testname = "test8";
2136  int subsqos = 2;
2137  MQTTAsync c, d;
2141  int rc = 0;
2142  int count = 0;
2143  char clientidc[70];
2144  char clientidd[70];
2145  int i = 0;
2146 
2147  sprintf(willTopic, "paho-test9-8-%s", unique);
2148  sprintf(clientidc, "paho-test9-8-c-%s", unique);
2149  sprintf(clientidd, "paho-test9-8-d-%s", unique);
2150  sprintf(test_topic, "paho-test9-8-test topic %s", unique);
2151 
2152  test8Finished = 0;
2153  failures = 0;
2154  MyLog(LOGA_INFO, "Starting Offline buffering 8 - send messages before successful connect");
2155  fprintf(xml, "<testcase classname=\"test8\" name=\"%s\"", testname);
2157 
2158  /* first check that by default we can't send messages before connect */
2159  createOptions.sendWhileDisconnected = 1;
2160  createOptions.maxBufferedMessages = 3;
2162  NULL, &createOptions);
2163  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
2164  if (rc != MQTTASYNC_SUCCESS)
2165  {
2166  MQTTAsync_destroy(&c);
2167  goto exit;
2168  }
2169 
2170  /* check can't send messages */
2171  for (i = 0; i < 5; ++i)
2172  {
2173  char buf[50];
2174 
2177  sprintf(buf, "QoS %d message", i);
2178  pubmsg.payload = buf;
2179  pubmsg.payloadlen = (int)(strlen(pubmsg.payload) + 1);
2180  pubmsg.qos = i % 3;
2181  pubmsg.retained = 0;
2182  rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts);
2183  assert("Good rc from sendMessage", rc == MQTTASYNC_DISCONNECTED, "rc was %d ", rc);
2184  }
2185 
2186  MQTTAsync_destroy(&c);
2188 
2189  /* client to check receipt of messages */
2190  rc = MQTTAsync_create(&d, options.connection, clientidd, MQTTCLIENT_PERSISTENCE_NONE, NULL);
2191  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
2192  if (rc != MQTTASYNC_SUCCESS)
2193  {
2194  MQTTAsync_destroy(&d);
2195  goto exit;
2196  }
2197 
2198  createOptions.allowDisconnectedSendAtAnyTime = 1;
2200  NULL, &createOptions);
2201  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
2202  if (rc != MQTTASYNC_SUCCESS)
2203  {
2204  MQTTAsync_destroy(&c);
2205  MQTTAsync_destroy(&d);
2206  goto exit;
2207  }
2208 
2209  rc = MQTTAsync_setCallbacks(d, d, NULL, test8_messageArrived, NULL);
2210  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
2211 
2212  /* let client d go and subscribe */
2213  opts.onSuccess = test8dOnConnect;
2214  opts.onFailure = test8OnFailure;
2215  opts.context = d;
2216  MyLog(LOGA_DEBUG, "Connecting client d");
2217  rc = MQTTAsync_connect(d, &opts);
2218  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
2219  if (rc != MQTTASYNC_SUCCESS)
2220  {
2221  MQTTAsync_destroy(&c);
2222  MQTTAsync_destroy(&d);
2223  goto exit;
2224  }
2225 
2226  count = 0;
2227  while (!test8dSubscribed && ++count < 10000)
2228  MySleep(100);
2229  assert("Count should be less than 10000", count < 10000, "count was %d", count); /* wrong */
2230 
2231  /* send some messages while disconnected */
2232  for (i = 0; i < 5; ++i)
2233  {
2234  char buf[50];
2235 
2238  sprintf(buf, "QoS %d message", i);
2239  pubmsg.payload = buf;
2240  pubmsg.payloadlen = (int)(strlen(pubmsg.payload) + 1);
2241  pubmsg.qos = i % 3;
2242  pubmsg.retained = 0;
2243  rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts);
2244  if (i <= 2)
2245  assert("Good rc from sendMessage", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
2246  else
2247  assert("Bad rc from sendMessage", rc == MQTTASYNC_MAX_BUFFERED_MESSAGES, "rc was %d ", rc);
2248  }
2249 
2251 
2252  opts.onSuccess = test8cOnConnect;
2253  opts.onFailure = test8OnFailure;
2254  opts.context = c;
2255  opts.cleansession = 0;
2256 
2257  MyLog(LOGA_DEBUG, "Connecting client c");
2258  rc = MQTTAsync_connect(c, &opts);
2259  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
2260  if (rc != MQTTASYNC_SUCCESS)
2261  {
2262  failures++;
2263  goto exit;
2264  }
2265 
2266  count = 0;
2267  while (!test8cConnected && ++count < 10000)
2268  MySleep(100);
2269  assert("Count should be less than 10000", count < 10000, "count was %d", count); /* wrong */
2270 
2271  /* after connect, those queued up messages should be delivered */
2272  while (test8_messages_received < 3 && ++count < 10000)
2273  MySleep(100);
2274 
2276 
2277  rc = MQTTAsync_disconnect(c, NULL);
2278  assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
2279 
2280  rc = MQTTAsync_disconnect(d, NULL);
2281  assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
2282 
2283 exit:
2284  MySleep(200);
2285  MQTTAsync_destroy(&c);
2286  MQTTAsync_destroy(&d);
2287  MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
2288  (failures == 0) ? "passed" : "failed", testname, tests, failures);
2290  return failures;
2291 }
2292 
2293 
2294 /*********************************************************************
2295 
2296 Test9: large nos of messages on create
2297 
2298 *********************************************************************/
2303 
2305 {
2306  MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context);
2307 
2309  test9Finished = 1;
2310 }
2311 
2313 {
2314  MQTTAsync c = (MQTTAsync)context;
2315 
2316  MyLog(LOGA_DEBUG, "In connect onSuccess callback for client c, context %p\n", context);
2317  test9cConnected = 1;
2318 }
2319 
2320 
2321 int test9(struct Options options)
2322 {
2323  char* testname = "test9";
2324  int subsqos = 2;
2325  MQTTAsync c;
2329  int rc = 0;
2330  int count = 0;
2331  char clientidc[70];
2332  int i = 0;
2333  START_TIME_TYPE start;
2334  int no_buffered_messages = 50000;
2335 
2336  sprintf(willTopic, "paho-test9-9-%s", unique);
2337  sprintf(clientidc, "paho-test9-9-c-%s", unique);
2338  sprintf(test_topic, "paho-test9-9-test topic %s", unique);
2339 
2340  test9Finished = 0;
2341  failures = 0;
2342  MyLog(LOGA_INFO, "Starting Offline buffering - large nos messages on create");
2343  fprintf(xml, "<testcase classname=\"test\" name=\"%s\"", testname);
2345 
2346  createOptions.allowDisconnectedSendAtAnyTime = 1;
2347  createOptions.sendWhileDisconnected = 1;
2348  createOptions.maxBufferedMessages = no_buffered_messages;
2350  NULL, &createOptions);
2351  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
2352  if (rc != MQTTASYNC_SUCCESS)
2353  {
2354  MQTTAsync_destroy(&c);
2355  goto exit;
2356  }
2357 
2358  /* send some messages while disconnected */
2359  for (i = 0; i < no_buffered_messages; ++i)
2360  {
2361  char buf[50];
2362 
2365  sprintf(buf, "QoS %d message", i);
2366  pubmsg.payload = buf;
2367  pubmsg.payloadlen = (int)(strlen(pubmsg.payload) + 1);
2368  pubmsg.qos = i % 3;
2369  pubmsg.retained = 0;
2370  rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts);
2371  assert("Good rc from sendMessage", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
2372  }
2373 
2374  MQTTAsync_destroy(&c);
2376 
2377  MyLog(LOGA_INFO, "Create starting with %d messages", no_buffered_messages);
2378  start = start_clock();
2380  NULL, &createOptions);
2381  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
2382  if (rc != MQTTASYNC_SUCCESS)
2383  {
2384  MQTTAsync_destroy(&c);
2385  goto exit;
2386  }
2387  long used = elapsed(start);
2388  MyLog(LOGA_INFO, "Time taken for create %ld ms", used);
2389 
2390  opts.onSuccess = test9cOnConnect;
2391  opts.onFailure = test9OnFailure;
2392  opts.context = c;
2393  opts.cleansession = 1;
2394 
2395  MyLog(LOGA_DEBUG, "Connecting client c");
2396  rc = MQTTAsync_connect(c, &opts);
2397  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
2398  if (rc != MQTTASYNC_SUCCESS)
2399  goto exit;
2400 
2401  count = 0;
2402  while (!test9cConnected && ++count < 10000)
2403  MySleep(100);
2404  assert("Count should be less than 10000", count < 10000, "count was %d", count); /* wrong */
2405 
2406  rc = MQTTAsync_disconnect(c, NULL);
2407  assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
2408 
2409 exit:
2410  MySleep(200);
2411  MQTTAsync_destroy(&c);
2412  MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
2413  (failures == 0) ? "passed" : "failed", testname, tests, failures);
2415  return failures;
2416 }
2417 
2418 
2419 /*********************************************************************
2420 
2421 Test10: delete oldest buffered messages first on buffer full
2422 
2423 *********************************************************************/
2432 
2433 int test10_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
2434 {
2435  MQTTAsync c = (MQTTAsync)context;
2436  static int message_count = 0;
2437  int sequence_no = atoi(message->payload);
2438 
2439  MyLog(LOGA_INFO, "Message received on topic %s, \"%.*s\"", topicName, message->payloadlen, message->payload);
2440 
2442 
2443  assert("Expected message sequence no", test10MessageSeqno == sequence_no, "sequence_no was %d\n", sequence_no);
2444 
2446  MQTTAsync_freeMessage(&message);
2447  MQTTAsync_free(topicName);
2448 
2449  return 1;
2450 }
2451 
2453 {
2454  MQTTAsync c = (MQTTAsync)context;
2455  MyLog(LOGA_DEBUG, "In subscribe onSuccess callback for client d, %p granted qos %d", c, response->alt.qos);
2456  test10dSubscribed = 1;
2457 }
2458 
2460 {
2461  MQTTAsync c = (MQTTAsync)context;
2463  int rc;
2464 
2465  MyLog(LOGA_DEBUG, "In connect onSuccess callback for client c, context %p\n", context);
2466  test10dConnected = 1;
2467 
2469  opts.context = c;
2470 
2471  rc = MQTTAsync_subscribe(c, test_topic, 2, &opts);
2472  assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
2473  if (rc != MQTTASYNC_SUCCESS)
2474  test10Finished = 1;
2475 }
2476 
2477 
2479 {
2480  MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context);
2481 
2483  test10Finished = 1;
2484 }
2485 
2487 {
2488  MQTTAsync c = (MQTTAsync)context;
2489  int rc;
2490 
2491  MyLog(LOGA_DEBUG, "In connect onSuccess callback for client c, context %p\n", context);
2492  test10cConnected = 1;
2493 }
2494 
2495 
2497 {
2498  char* testname = "test10";
2499  int subsqos = 2;
2500  MQTTAsync c, d;
2504  int rc = 0;
2505  int count = 0;
2506  char clientidc[70];
2507  char clientidd[70];
2508  int i = 0;
2509 
2510  sprintf(willTopic, "paho-test9-10-%s", unique);
2511  sprintf(clientidc, "paho-test9-10-c-%s", unique);
2512  sprintf(clientidd, "paho-test9-10-d-%s", unique);
2513  sprintf(test_topic, "paho-test9-10-test topic %s", unique);
2514 
2515  test10Finished = 0;
2516  failures = 0;
2517  MyLog(LOGA_INFO, "Starting Offline buffering 10 - delete oldest buffered messages first");
2518  fprintf(xml, "<testcase classname=\"test9\" name=\"%s\"", testname);
2520 
2521  rc = MQTTAsync_create(&d, options.connection, clientidd, MQTTCLIENT_PERSISTENCE_NONE, NULL);
2522  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
2523  if (rc != MQTTASYNC_SUCCESS)
2524  {
2525  MQTTAsync_destroy(&d);
2526  goto exit;
2527  }
2528 
2529  createOptions.sendWhileDisconnected = 1;
2530  createOptions.maxBufferedMessages = 3;
2531  createOptions.allowDisconnectedSendAtAnyTime = 1;
2532  createOptions.deleteOldestMessages = 1;
2534  NULL, &createOptions);
2535  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
2536  if (rc != MQTTASYNC_SUCCESS)
2537  {
2538  MQTTAsync_destroy(&c);
2539  MQTTAsync_destroy(&d);
2540  goto exit;
2541  }
2542 
2543  rc = MQTTAsync_setCallbacks(d, d, NULL, test10_messageArrived, NULL);
2544  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
2545 
2546  /* let client d go and subscribe */
2547  opts.onSuccess = test10dOnConnect;
2548  opts.onFailure = test10OnFailure;
2549  opts.context = d;
2550  MyLog(LOGA_DEBUG, "Connecting client d");
2551  rc = MQTTAsync_connect(d, &opts);
2552  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
2553  if (rc != MQTTASYNC_SUCCESS)
2554  {
2555  MQTTAsync_destroy(&c);
2556  MQTTAsync_destroy(&d);
2557  goto exit;
2558  }
2559 
2560  count = 0;
2561  while (!test10dSubscribed && ++count < 10000)
2562  MySleep(100);
2563  assert("Count should be less than 10000", count < 10000, "count was %d", count); /* wrong */
2564 
2565  /* send some messages while disconnected */
2566  for (i = 0; i < test10MessagesToSend; ++i)
2567  {
2568  char buf[50];
2569 
2572  pubmsg.qos = i % 3;
2573  sprintf(buf, "%d message no, QoS %d", i, pubmsg.qos);
2574  pubmsg.payload = buf;
2575  pubmsg.payloadlen = (int)(strlen(pubmsg.payload) + 1);
2576  pubmsg.retained = 0;
2577  rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts);
2578  assert("Good rc from sendMessage", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
2579  }
2580 
2582 
2583  opts.onSuccess = test10cOnConnect;
2584  opts.onFailure = test10OnFailure;
2585  opts.context = c;
2586  opts.cleansession = 0;
2587 
2588  MyLog(LOGA_DEBUG, "Connecting client c");
2589  rc = MQTTAsync_connect(c, &opts);
2590  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
2591  if (rc != MQTTASYNC_SUCCESS)
2592  {
2593  failures++;
2594  goto exit;
2595  }
2596 
2597  count = 0;
2598  while (!test10cConnected && ++count < 10000)
2599  MySleep(100);
2600  assert("Count should be less than 10000", count < 10000, "count was %d", count); /* wrong */
2601 
2602  /* after connect, those queued up messages should be delivered */
2603  while (test10_messages_received < 3 && ++count < 10000)
2604  MySleep(100);
2605 
2607 
2608  /* Now try the same thing, but force messages to be persisted and re-read */
2609 
2610  /* disconnect so we buffer some messages again */
2611  rc = MQTTAsync_disconnect(c, NULL);
2612  assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
2613 
2614  /* send some messages while disconnected */
2615  for (i = 0; i < test10MessagesToSend; ++i)
2616  {
2617  char buf[50];
2618 
2621  pubmsg.qos = i % 3;
2622  sprintf(buf, "%d message no, QoS %d", i, pubmsg.qos);
2623  pubmsg.payload = buf;
2624  pubmsg.payloadlen = (int)(strlen(pubmsg.payload) + 1);
2625  pubmsg.retained = 0;
2626  rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts);
2627  assert("Good rc from sendMessage", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
2628  }
2629 
2631 
2632  MQTTAsync_destroy(&c);
2633  test10MessageSeqno = 3;
2634 
2635  /* re-read persistence */
2637  NULL, &createOptions);
2638  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
2639 
2641 
2642  MyLog(LOGA_DEBUG, "Connecting client c");
2643  rc = MQTTAsync_connect(c, &opts);
2644  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
2645  if (rc != MQTTASYNC_SUCCESS)
2646  {
2647  failures++;
2648  goto exit;
2649  }
2650 
2651  test10_messages_received = count = 0;
2652  while (!test10cConnected && ++count < 10000)
2653  MySleep(100);
2654  assert("Count should be less than 10000", count < 10000, "count was %d", count); /* wrong */
2655 
2656  /* after connect, those queued up messages should be delivered */
2657  while (test10_messages_received < 3 && ++count < 10000)
2658  MySleep(100);
2659 
2661 
2662  rc = MQTTAsync_disconnect(c, NULL);
2663  assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
2664 
2665  rc = MQTTAsync_disconnect(d, NULL);
2666  assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
2667 
2668 exit:
2669  MySleep(200);
2670  MQTTAsync_destroy(&c);
2671  MQTTAsync_destroy(&d);
2672  MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
2673  (failures == 0) ? "passed" : "failed", testname, tests, failures);
2675  return failures;
2676 }
2677 
2678 
2679 int main(int argc, char** argv)
2680 {
2681  int* numtests = &tests;
2682  int rc = 0;
2683  int (*tests[])() = { NULL, test1, test2, test3, test4, test5, test6, test7, test8, test9, test10};
2684  time_t randtime;
2685 
2686  srand((unsigned) time(&randtime));
2687  sprintf(unique, "%u", rand());
2688  MyLog(LOGA_INFO, "Random prefix/suffix is %s", unique);
2689 
2690  xml = fopen("TEST-test9.xml", "w");
2691  fprintf(xml, "<testsuite name=\"test9\" tests=\"%d\">\n", (int)(ARRAY_SIZE(tests) - 1));
2692 
2694  getopts(argc, argv);
2695 
2696  if (options.test_no == 0)
2697  { /* run all the tests */
2699  {
2700  failures = 0;
2702  rc += tests[options.test_no](options); /* return number of failures. 0 = test succeeded */
2703  }
2704  }
2705  else
2706  {
2708  rc = tests[options.test_no](options); /* run just the selected test */
2709  }
2710 
2711  MyLog(LOGA_INFO, "Total tests run: %d", *numtests);
2712  if (rc == 0)
2713  MyLog(LOGA_INFO, "verdict pass");
2714  else
2715  MyLog(LOGA_INFO, "verdict fail");
2716 
2717  fprintf(xml, "</testsuite>\n");
2718  fclose(xml);
2719 
2720  return rc;
2721 }
int test3(struct Options options)
Definition: test9.c:960
int test3dReady
Definition: test9.c:919
int failures
Definition: test9.c:208
MQTTAsync_onFailure * onFailure
Definition: MQTTAsync.h:1255
void test4cConnected(void *context, char *cause)
Definition: test9.c:1209
void test8donSubscribe(void *context, MQTTAsync_successData *response)
Definition: test9.c:2089
int test5c_connected
Definition: test9.c:1383
int test10_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
Definition: test9.c:2433
int test9(struct Options options)
Definition: test9.c:2321
void handleTrace(enum MQTTASYNC_TRACE_LEVELS level, char *message)
Definition: test9.c:314
void MyLog(int LOGA_level, char *format,...)
Definition: test9.c:104
void test2donSubscribe(void *context, MQTTAsync_successData *response)
Definition: test9.c:653
#define LOGA_DEBUG
Definition: test9.c:99
enum MQTTPropertyCodes value
char * cur_output
Definition: test9.c:212
int test3OnFailureCalled
Definition: test9.c:884
int MQTTAsync_createWithOptions(MQTTAsync *handle, const char *serverURI, const char *clientId, int persistence_type, void *persistence_context, MQTTAsync_createOptions *options)
Definition: MQTTAsync.c:575
void test3cOnFailure(void *context, MQTTAsync_failureData *response)
Definition: test9.c:886
int test10Finished
Definition: test9.c:2425
int test2Finished
Definition: test9.c:612
int test2_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
Definition: test9.c:594
int test3Finished
Definition: test9.c:882
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&...args)
Definition: core.h:2081
void myassert(char *filename, int lineno, char *description, int value, char *format,...)
Definition: test9.c:228
int test7_messages_received
Definition: test9.c:1799
int test8Finished
Definition: test9.c:2068
int test9Finished
Definition: test9.c:2300
void test1dOnConnect(void *context, MQTTAsync_successData *response)
Definition: test9.c:401
void test2dOnConnect(void *context, MQTTAsync_successData *response)
Definition: test9.c:661
char * proxy_connection
Definition: test1.c:51
union MQTTAsync_successData::@46 alt
int test5_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
Definition: test9.c:1385
int test10MessagesToSend
Definition: test9.c:2430
int test10cConnected
Definition: test9.c:2427
const char * message
Definition: MQTTAsync.h:996
int test2dReady
Definition: test9.c:649
char * connection
const char * topicName
Definition: MQTTAsync.h:994
void test4dOnFailure(void *context, MQTTAsync_failureData *response)
Definition: test9.c:1152
#define MQTTAsync_responseOptions_initializer
Definition: MQTTAsync.h:746
void test1cOnConnect(void *context, MQTTAsync_successData *response)
Definition: test9.c:372
MQTTClient d
Definition: test10.c:1656
void test5dOnConnect(void *context, MQTTAsync_successData *response)
Definition: test9.c:1448
int test8(struct Options options)
Definition: test9.c:2133
int MQTTAsync_disconnect(MQTTAsync handle, const MQTTAsync_disconnectOptions *options)
Definition: MQTTAsync.c:3923
int test2c_connected
Definition: test9.c:679
int MQTTAsync_setCallbacks(MQTTAsync handle, void *context, MQTTAsync_connectionLost *cl, MQTTAsync_messageArrived *ma, MQTTAsync_deliveryComplete *dc)
Definition: MQTTAsync.c:3062
void test7donSubscribe(void *context, MQTTAsync_successData *response)
Definition: test9.c:1863
int test4_messages_received
Definition: test9.c:1120
void test7cOnConnectSuccess(void *context, MQTTAsync_successData *response)
Definition: test9.c:1838
void MySleep(long milliseconds)
Definition: test9.c:141
struct pubsub_opts opts
Definition: paho_c_pub.c:42
int test4_will_message_received
Definition: test9.c:1119
FILE * xml
Definition: test9.c:209
void * MQTTAsync
Definition: MQTTAsync.h:239
size_t strftime(char *str, size_t count, const char *format, const std::tm *time)
Definition: chrono.h:375
void MQTTAsync_free(void *memory)
Definition: MQTTAsync.c:2626
char output[3000]
Definition: test9.c:211
void MQTTAsync_freeMessage(MQTTAsync_message **message)
Definition: MQTTAsync.c:2615
#define MQTTASYNC_DISCONNECTED
Definition: MQTTAsync.h:127
int MQTTAsync_setConnected(MQTTAsync handle, void *context, MQTTAsync_connected *connected)
Definition: MQTTAsync.c:3178
int test7c_connected
Definition: test9.c:1797
int test7_will_message_received
Definition: test9.c:1798
void test9cOnConnect(void *context, MQTTAsync_successData *response)
Definition: test9.c:2312
#define START_TIME_TYPE
Definition: test9.c:166
void MQTTAsync_setTraceCallback(MQTTAsync_traceCallback *callback)
Definition: MQTTAsync.c:4903
int test1_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
Definition: test9.c:334
int test8cConnected
Definition: test9.c:2070
int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions *options)
Definition: MQTTAsync.c:3480
MQTTASYNC_TRACE_LEVELS
Definition: MQTTAsync.h:1650
void test7cOnConnectFailure(void *context, MQTTAsync_failureData *response)
Definition: test9.c:1830
int test10(struct Options options)
Definition: test9.c:2496
static char msg_buf[512]
Definition: Log.c:122
void test5cOnFailure(void *context, MQTTAsync_failureData *response)
Definition: test9.c:1403
void write_test_result(void)
Definition: test9.c:215
#define assert(a, b, c, d)
Definition: test9.c:202
START_TIME_TYPE global_start_time
Definition: test9.c:210
int test5OnFailureCalled
Definition: test9.c:1382
int test4_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
Definition: test9.c:1122
void test3dOnConnect(void *context, MQTTAsync_successData *response)
Definition: test9.c:931
int MQTTAsync_subscribe(MQTTAsync handle, const char *topic, int qos, MQTTAsync_responseOptions *response)
Definition: MQTTAsync.c:4121
int test1_will_message_received
Definition: test9.c:331
void test5cOnConnect(void *context, MQTTAsync_successData *response)
Definition: test9.c:1419
int tests
Definition: test9.c:207
void test2cOnConnect(void *context, MQTTAsync_successData *response)
Definition: test9.c:632
#define MQTTAsync_willOptions_initializer
Definition: MQTTAsync.h:1014
int test1(struct Options options)
Definition: test9.c:430
int test5(struct Options options)
Definition: test9.c:1475
constexpr size_t count()
Definition: core.h:960
void test2dOnFailure(void *context, MQTTAsync_failureData *response)
Definition: test9.c:624
int test7(struct Options options)
Definition: test9.c:1890
int test7_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
Definition: test9.c:1804
int test3c_connected
Definition: test9.c:949
int MQTTAsync_create(MQTTAsync *handle, const char *serverURI, const char *clientId, int persistence_type, void *persistence_context)
Definition: MQTTAsync.c:737
void test4dOnConnect(void *context, MQTTAsync_successData *response)
Definition: test9.c:1189
int MQTTAsync_getPendingTokens(MQTTAsync handle, MQTTAsync_token **tokens)
Definition: MQTTAsync.c:4737
void test4cOnFailure(void *context, MQTTAsync_failureData *response)
Definition: test9.c:1144
int test8_messages_received
Definition: test9.c:2067
void test7cConnected(void *context, char *cause)
Definition: test9.c:1822
int test10OnFailureCalled
Definition: test9.c:2426
description
Definition: setup.py:19
void test8dOnConnect(void *context, MQTTAsync_successData *response)
Definition: test9.c:2096
int message_count
Definition: test5.c:72
int test6(struct Options options)
Definition: test9.c:1630
char willTopic[100]
Definition: test9.c:390
#define MQTTVERSION_3_1_1
Definition: MQTTAsync.h:203
int test8_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
Definition: test9.c:2074
struct MQTTAsync_willOptions::@54 payload
int test3_will_message_received
Definition: test9.c:861
void test1cConnected(void *context, char *cause)
Definition: test9.c:421
int test9cConnected
Definition: test9.c:2302
int test1OnFailureCalled
Definition: test9.c:354
#define MQTTAsync_createOptions_initializer
Definition: MQTTAsync.h:965
int MQTTAsync_isConnected(MQTTAsync handle)
Definition: MQTTAsync.c:3932
void test3dOnFailure(void *context, MQTTAsync_failureData *response)
Definition: test9.c:894
int MQTTAsync_subscribeMany(MQTTAsync handle, int count, char *const *topic, int *qos, MQTTAsync_responseOptions *response)
Definition: MQTTAsync.c:4004
int test1c_connected
Definition: test9.c:419
START_TIME_TYPE start_clock(void)
Definition: test9.c:168
int test7dReady
Definition: test9.c:1802
void test8cOnConnect(void *context, MQTTAsync_successData *response)
Definition: test9.c:2123
void test5dOnFailure(void *context, MQTTAsync_failureData *response)
Definition: test9.c:1411
#define MQTTASYNC_MAX_BUFFERED_MESSAGES
Definition: MQTTAsync.h:167
#define MQTTAsync_connectOptions_initializer
Definition: MQTTAsync.h:1335
int MQTTAsync_token
Definition: MQTTAsync.h:249
MQTTAsync_onSuccess * onSuccess
Definition: MQTTAsync.h:696
int test8dSubscribed
Definition: test9.c:2072
int test10MessageSeqno
Definition: test9.c:2431
int test9OnFailureCalled
Definition: test9.c:2301
int test10_messages_received
Definition: test9.c:2424
MQTTAsync_willOptions * will
Definition: MQTTAsync.h:1214
void test10OnFailure(void *context, MQTTAsync_failureData *response)
Definition: test9.c:2478
#define MQTTCLIENT_PERSISTENCE_DEFAULT
void test3cOnConnect(void *context, MQTTAsync_successData *response)
Definition: test9.c:902
struct Options options
void test4cOnConnect(void *context, MQTTAsync_successData *response)
Definition: test9.c:1160
void test3cConnected(void *context, char *cause)
Definition: test9.c:951
int test1_messages_received
Definition: test9.c:332
void MQTTAsync_destroy(MQTTAsync *handle)
Definition: MQTTAsync.c:2554
int test2(struct Options options)
Definition: test9.c:690
void test7dOnConnectSuccess(void *context, MQTTAsync_successData *response)
Definition: test9.c:1871
#define ARRAY_SIZE(a)
Definition: test9.c:43
void test2cOnFailure(void *context, MQTTAsync_failureData *response)
Definition: test9.c:616
int test7OnFailureCalled
Definition: test9.c:1801
int test5dReady
Definition: test9.c:1436
#define MQTTASYNC_SUCCESS
Definition: MQTTAsync.h:113
void MQTTAsync_setTraceLevel(enum MQTTASYNC_TRACE_LEVELS level)
Definition: MQTTAsync.c:4897
int MQTTAsync_sendMessage(MQTTAsync handle, const char *destinationName, const MQTTAsync_message *message, MQTTAsync_responseOptions *response)
Definition: MQTTAsync.c:4328
MQTTClient c
Definition: test10.c:1656
int test2OnFailureCalled
Definition: test9.c:614
int test1Finished
Definition: test9.c:352
float time
Definition: mqtt_test.py:17
void test5cConnected(void *context, char *cause)
Definition: test9.c:1466
dictionary context
Definition: test2.py:57
void test9OnFailure(void *context, MQTTAsync_failureData *response)
Definition: test9.c:2304
void test7dOnConnectFailure(void *context, MQTTAsync_failureData *response)
Definition: test9.c:1854
null localtime_s(...)
Definition: chrono.h:286
int main(int argc, char **argv)
Definition: test9.c:2679
int test4OnFailureCalled
Definition: test9.c:1142
#define LOGA_INFO
Definition: test9.c:100
#define MQTTCLIENT_PERSISTENCE_NONE
void test1dOnFailure(void *context, MQTTAsync_failureData *response)
Definition: test9.c:364
int test7Finished
Definition: test9.c:1800
void assert3PendingTokens(MQTTAsync c)
Definition: test9.c:278
int test5_messages_received
Definition: test9.c:1380
int test4(struct Options options)
Definition: test9.c:1218
void test4donSubscribe(void *context, MQTTAsync_successData *response)
Definition: test9.c:1181
int MQTTAsync_reconnect(MQTTAsync handle)
Definition: MQTTAsync.c:1545
int test8dConnected
Definition: test9.c:2071
char test_topic[100]
Definition: test9.c:391
int test2_messages_received
Definition: test9.c:592
void getopts(int argc, char **argv)
Definition: test9.c:65
int test8OnFailureCalled
Definition: test9.c:2069
int test1dReady
Definition: test9.c:389
int test4Finished
Definition: test9.c:1140
void test2cConnected(void *context, char *cause)
Definition: test9.c:681
const void * data
Definition: MQTTAsync.h:1010
void usage(void)
Definition: test9.c:45
int test5Finished
Definition: test9.c:1381
void waitForNoPendingTokens(MQTTAsync c)
Definition: test9.c:253
void test1donSubscribe(void *context, MQTTAsync_successData *response)
Definition: test9.c:393
int test9_messages_received
Definition: test9.c:2299
char *const * serverURIs
Definition: MQTTAsync.h:1277
#define MQTTAsync_message_initializer
Definition: MQTTAsync.h:319
char * topics[]
long elapsed(START_TIME_TYPE start_time)
Definition: test9.c:192
int test4dReady
Definition: test9.c:1177
enum MQTTReasonCodes rc
Definition: test10.c:1112
int test5_will_message_received
Definition: test9.c:1379
MQTTAsync_onSuccess * onSuccess
Definition: MQTTAsync.h:1249
int test4c_connected
Definition: test9.c:1207
int test3_messages_received
Definition: test9.c:862
void test10cOnConnect(void *context, MQTTAsync_successData *response)
Definition: test9.c:2486
void test1cOnFailure(void *context, MQTTAsync_failureData *response)
Definition: test9.c:356
int test10dConnected
Definition: test9.c:2428
int test3_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
Definition: test9.c:864
void test10dOnConnect(void *context, MQTTAsync_successData *response)
Definition: test9.c:2459
void test5donSubscribe(void *context, MQTTAsync_successData *response)
Definition: test9.c:1440
int test2_will_message_received
Definition: test9.c:591
int test_no
Definition: test1.c:54
void test8OnFailure(void *context, MQTTAsync_failureData *response)
Definition: test9.c:2115
char unique[50]
Definition: test9.c:41
void test10donSubscribe(void *context, MQTTAsync_successData *response)
Definition: test9.c:2452
void test3donSubscribe(void *context, MQTTAsync_successData *response)
Definition: test9.c:923
int test10dSubscribed
Definition: test9.c:2429


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 04:02:48