test45.c
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright (c) 2009, 2020 IBM Corp.
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 - MQTT 3.1.1 support
16  * Ian Craggs - test8 - failure callbacks
17  * Ian Craggs - MQTT V5
18  *******************************************************************************/
19 
20 
27 #include "MQTTAsync.h"
28 #include <string.h>
29 #include <stdlib.h>
30 
31 #if !defined(_WINDOWS)
32  #include <sys/time.h>
33  #include <sys/socket.h>
34  #include <unistd.h>
35  #include <errno.h>
36 #else
37  #include <windows.h>
38 #endif
39 
40 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
41 
42 void usage(void)
43 {
44  printf("help!!\n");
45  exit(EXIT_FAILURE);
46 }
47 
48 struct Options
49 {
50  char* connection;
51  int verbose;
52  int test_no;
53  int size;
54  int MQTTVersion;
55  int iterations;
56 } options =
57 {
58  "localhost:1883",
59  0,
60  -1,
61  10000,
63  1,
64 };
65 
66 void getopts(int argc, char** argv)
67 {
68  int count = 1;
69 
70  while (count < argc)
71  {
72  if (strcmp(argv[count], "--test_no") == 0)
73  {
74  if (++count < argc)
75  options.test_no = atoi(argv[count]);
76  else
77  usage();
78  }
79  else if (strcmp(argv[count], "--size") == 0)
80  {
81  if (++count < argc)
82  options.size = atoi(argv[count]);
83  else
84  usage();
85  }
86  else if (strcmp(argv[count], "--connection") == 0)
87  {
88  if (++count < argc)
89  options.connection = argv[count];
90  else
91  usage();
92  }
93  else if (strcmp(argv[count], "--MQTTversion") == 0)
94  {
95  if (++count < argc)
96  {
97  options.MQTTVersion = atoi(argv[count]);
98  printf("setting MQTT version to %d\n", options.MQTTVersion);
99  }
100  else
101  usage();
102  }
103  else if (strcmp(argv[count], "--iterations") == 0)
104  {
105  if (++count < argc)
106  options.iterations = atoi(argv[count]);
107  else
108  usage();
109  }
110  else if (strcmp(argv[count], "--verbose") == 0)
111  options.verbose = 1;
112  count++;
113  }
114 }
115 
116 
117 #define LOGA_DEBUG 0
118 #define LOGA_INFO 1
119 #include <stdarg.h>
120 #include <time.h>
121 #include <sys/timeb.h>
122 void MyLog(int LOGA_level, char* format, ...)
123 {
124  static char msg_buf[256];
125  va_list args;
126 #if defined(_WIN32) || defined(_WINDOWS)
127  struct timeb ts;
128 #else
129  struct timeval ts;
130 #endif
131  struct tm timeinfo;
132 
133  if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
134  return;
135 
136 #if defined(_WIN32) || defined(_WINDOWS)
137  ftime(&ts);
138  localtime_s(&timeinfo, &ts.time);
139 #else
140  gettimeofday(&ts, NULL);
141  localtime_r(&ts.tv_sec, &timeinfo);
142 #endif
143  strftime(msg_buf, 80, "%Y%m%d %H%M%S", &timeinfo);
144 
145 #if defined(_WIN32) || defined(_WINDOWS)
146  sprintf(&msg_buf[strlen(msg_buf)], ".%.3hu ", ts.millitm);
147 #else
148  sprintf(&msg_buf[strlen(msg_buf)], ".%.3lu ", ts.tv_usec / 1000);
149 #endif
150 
151  va_start(args, format);
152  vsnprintf(&msg_buf[strlen(msg_buf)], sizeof(msg_buf) - strlen(msg_buf), format, args);
153  va_end(args);
154 
155  printf("%s\n", msg_buf);
156  fflush(stdout);
157 }
158 
159 
160 void MySleep(long milliseconds)
161 {
162 #if defined(_WIN32) || defined(_WIN64)
163  Sleep(milliseconds);
164 #else
165  usleep(milliseconds*1000);
166 #endif
167 }
168 
169 
170 #if defined(_WIN32) || defined(_WINDOWS)
171 #define START_TIME_TYPE DWORD
172 static DWORD start_time = 0;
174 {
175  return GetTickCount();
176 }
177 #elif defined(AIX)
178 #define START_TIME_TYPE struct timespec
180 {
181  static struct timespec start;
182  clock_gettime(CLOCK_REALTIME, &start);
183  return start;
184 }
185 #else
186 #define START_TIME_TYPE struct timeval
187 /* TODO - unused - remove? static struct timeval start_time; */
189 {
190  struct timeval start_time;
191  gettimeofday(&start_time, NULL);
192  return start_time;
193 }
194 #endif
195 
196 
197 #if defined(_WIN32)
198 long elapsed(START_TIME_TYPE start_time)
199 {
200  return GetTickCount() - start_time;
201 }
202 #elif defined(AIX)
203 #define assert(a)
204 long elapsed(struct timespec start)
205 {
206  struct timespec now, res;
207 
208  clock_gettime(CLOCK_REALTIME, &now);
209  ntimersub(now, start, res);
210  return (res.tv_sec)*1000L + (res.tv_nsec)/1000000L;
211 }
212 #else
213 long elapsed(START_TIME_TYPE start_time)
214 {
215  struct timeval now, res;
216 
217  gettimeofday(&now, NULL);
218  timersub(&now, &start_time, &res);
219  return (res.tv_sec)*1000 + (res.tv_usec)/1000;
220 }
221 #endif
222 
223 #define assert(a, b, c, d) myassert(__FILE__, __LINE__, a, b, c, d)
224 #define assert1(a, b, c, d, e) myassert(__FILE__, __LINE__, a, b, c, d, e)
225 
226 int tests = 0;
227 int failures = 0;
228 FILE* xml;
230 char output[3000];
232 
234 {
235  long duration = elapsed(global_start_time);
236 
237  fprintf(xml, " time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000);
238  if (cur_output != output)
239  {
240  fprintf(xml, "%s", output);
241  cur_output = output;
242  }
243  fprintf(xml, "</testcase>\n");
244 }
245 
246 void myassert(char* filename, int lineno, char* description, int value, char* format, ...)
247 {
248  ++tests;
249  if (!value)
250  {
251  va_list args;
252 
253  ++failures;
254  printf("Assertion failed, file %s, line %d, description: %s\n", filename, lineno, description);
255 
256  va_start(args, format);
257  vprintf(format, args);
258  va_end(args);
259 
260  cur_output += sprintf(cur_output, "<failure type=\"%s\">file %s, line %d </failure>\n",
261  description, filename, lineno);
262  }
263  else
264  MyLog(LOGA_DEBUG, "Assertion succeeded, file %s, line %d, description: %s", filename, lineno, description);
265 }
266 
267 
269 {
270  int i = 0;
271 
272  for (i = 0; i < props->count; ++i)
273  {
274  int id = props->array[i].identifier;
275  const char* name = MQTTPropertyName(id);
276  char* intformat = "Property name %s value %d";
277 
278  switch (MQTTProperty_getType(id))
279  {
281  MyLog(LOGA_INFO, intformat, name, props->array[i].value.byte);
282  break;
284  MyLog(LOGA_INFO, intformat, name, props->array[i].value.integer2);
285  break;
287  MyLog(LOGA_INFO, intformat, name, props->array[i].value.integer4);
288  break;
290  MyLog(LOGA_INFO, intformat, name, props->array[i].value.integer4);
291  break;
294  MyLog(LOGA_INFO, "Property name %s value len %.*s", name,
295  props->array[i].value.data.len, props->array[i].value.data.data);
296  break;
298  MyLog(LOGA_INFO, "Property name %s key %.*s value %.*s", name,
299  props->array[i].value.data.len, props->array[i].value.data.data,
300  props->array[i].value.value.len, props->array[i].value.value.data);
301  break;
302  }
303  }
304 }
305 
306 
308 {
309  int i = 0, rc = 0, count = 0;
310  MQTTAsync_token *tokens;
311 
312  /* acks for outgoing messages could arrive after incoming exchanges are complete */
313  do
314  {
315  rc = MQTTAsync_getPendingTokens(c, &tokens);
316  assert("Good rc from getPendingTokens", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
317  i = 0;
318  if (tokens)
319  {
320  while (tokens[i] != -1)
321  ++i;
322  MQTTAsync_free(tokens);
323  }
324  if (i > 0)
325  MySleep(100);
326  }
327  while (i > 0 && ++count < 100);
328  assert("Number of getPendingTokens should be 0", i == 0, "i was %d ", i);
329 }
330 
331 
332 volatile int test_finished = 0;
333 
334 char* test_topic = "async test topic";
335 
336 
338 {
339  MQTTAsync c = (MQTTAsync)context;
340  MyLog(LOGA_DEBUG, "In onDisconnect callback %p", c);
341  test_finished = 1;
342 }
343 
344 
346 {
347  MQTTAsync c = (MQTTAsync)context;
350  int rc;
351 
352  MyLog(LOGA_DEBUG, "In onUnsubscribe onSuccess callback %p", c);
353  MyLog(LOGA_INFO, "Unsuback properties:");
354  logProperties(&response->properties);
355  assert("A property should exist", response->properties.count > 0,
356  "Property count was %d\n", response->properties);
357 
359  opts.context = c;
361 
362  property.identifier = MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL;
363  property.value.integer4 = 0;
364  MQTTProperties_add(&opts.properties, &property);
365 
366  rc = MQTTAsync_disconnect(c, &opts);
367  assert("Disconnect successful", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
369 }
370 
371 
372 int test1_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
373 {
374  MQTTAsync c = (MQTTAsync)context;
375  static int message_count = 0;
376  int rc;
377 
378  MyLog(LOGA_DEBUG, "In messageArrived callback %p", c);
379 
380  assert("Message structure version should be 1", message->struct_version == 1,
381  "message->struct_version was %d", message->struct_version);
382  if (message->struct_version == 1)
383  {
384  assert("Properties count should be 2", message->properties.count == 2,
385  "Properties count was %d\n", message->properties.count);
386  logProperties(&message->properties);
387  }
388 
389  if (++message_count == 1)
390  {
395 
396  property.identifier = MQTTPROPERTY_CODE_USER_PROPERTY;
397  property.value.data.data = "test user property";
398  property.value.data.len = (int)strlen(property.value.data.data);
399  property.value.value.data = "test user property value";
400  property.value.value.len = (int)strlen(property.value.value.data);
401  MQTTProperties_add(&props, &property);
402  pubmsg.properties = props;
403 
404  pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
405  pubmsg.payloadlen = 11;
406  pubmsg.qos = 2;
407  pubmsg.retained = 0;
408  rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts);
409  assert("Publish should return 0", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
410  MQTTProperties_free(&props);
411  }
412  else
413  {
417 
418  property.identifier = MQTTPROPERTY_CODE_USER_PROPERTY;
419  property.value.data.data = "test user property";
420  property.value.data.len = (int)strlen(property.value.data.data);
421  property.value.value.data = "test user property value";
422  property.value.value.len = (int)strlen(property.value.value.data);
423  MQTTProperties_add(&props, &property);
424  opts.properties = props;
425 
427  opts.context = c;
428  rc = MQTTAsync_unsubscribe(c, test_topic, &opts);
429  assert("Unsubscribe successful", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
430  MQTTProperties_free(&props);
431  }
432 
433  MQTTAsync_freeMessage(&message);
434  MQTTAsync_free(topicName);
435 
436  return 1;
437 }
438 
440 {
441  MQTTAsync c = (MQTTAsync)context;
443  int rc;
447 
448  MyLog(LOGA_DEBUG, "In subscribe onSuccess callback %p granted qos %d", c, response->reasonCode);
449  assert("Subscribe response should be 2", response->reasonCode == MQTTREASONCODE_GRANTED_QOS_2,
450  "response was %d", response->reasonCode);
451 
452  MyLog(LOGA_INFO, "Suback properties:");
453  logProperties(&response->properties);
454 
455  property.identifier = MQTTPROPERTY_CODE_USER_PROPERTY;
456  property.value.data.data = "test user property";
457  property.value.data.len = (int)strlen(property.value.data.data);
458  property.value.value.data = "test user property value";
459  property.value.value.len = (int)strlen(property.value.value.data);
460  MQTTProperties_add(&props, &property);
461  opts.properties = props;
462 
463  pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
464  pubmsg.payloadlen = 11;
465  pubmsg.qos = 2;
466  pubmsg.retained = 0;
467 
468  rc = MQTTAsync_send(c, test_topic, pubmsg.payloadlen, pubmsg.payload, pubmsg.qos, pubmsg.retained, &opts);
469  MQTTProperties_free(&props);
470 }
471 
472 
474 {
475  MQTTAsync c = (MQTTAsync)context;
479  int rc;
480 
481  MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
482 
483  assert("Reason code should be 0", response->reasonCode == MQTTREASONCODE_SUCCESS,
484  "Reason code was %d\n", response->reasonCode);
485 
486  MyLog(LOGA_INFO, "Connack properties:");
487  logProperties(&response->properties);
488 
490  opts.context = c;
491 
492  property.identifier = MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIER;
493  property.value.integer4 = 33;
494  MQTTProperties_add(&props, &property);
495  opts.properties = props;
496 
498 
499  rc = MQTTAsync_subscribe(c, test_topic, 2, &opts);
500  assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
501  if (rc != MQTTASYNC_SUCCESS)
502  test_finished = 1;
503  MQTTProperties_free(&props);
504 }
505 
506 
507 /*********************************************************************
508 
509 Test1: Basic connect, subscribe send and receive.
510 
511 *********************************************************************/
512 int test1(struct Options options)
513 {
514  int subsqos = 2;
515  MQTTAsync c;
521  int rc = 0;
522  char* test_topic = "V5 C client test1";
524 
525  MyLog(LOGA_INFO, "Starting V5 test 1 - asynchronous connect");
526  fprintf(xml, "<testcase classname=\"test45\" name=\"asynchronous connect\"");
528 
529  createOpts.MQTTVersion = MQTTVERSION_5;
530  rc = MQTTAsync_createWithOptions(&c, options.connection, "async_test",
531  MQTTCLIENT_PERSISTENCE_DEFAULT, NULL, &createOpts);
532  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
533  if (rc != MQTTASYNC_SUCCESS)
534  {
535  MQTTAsync_destroy(&c);
536  goto exit;
537  }
538 
539  rc = MQTTAsync_setCallbacks(c, c, NULL, test1_messageArrived, NULL);
540  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
541 
542  opts.keepAliveInterval = 20;
543  opts.username = "testuser";
544  opts.password = "testpassword";
545  opts.MQTTVersion = options.MQTTVersion;
546 
547  opts.will = &wopts;
548  opts.will->message = "will message";
549  opts.will->qos = 1;
550  opts.will->retained = 0;
551  opts.will->topicName = "will topic";
552  opts.will = NULL;
554  opts.onFailure5 = NULL;
555  opts.context = c;
556 
557  property.identifier = MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL;
558  property.value.integer4 = 30;
559  MQTTProperties_add(&props, &property);
560 
561  property.identifier = MQTTPROPERTY_CODE_USER_PROPERTY;
562  property.value.data.data = "test user property";
563  property.value.data.len = (int)strlen(property.value.data.data);
564  property.value.value.data = "test user property value";
565  property.value.value.len = (int)strlen(property.value.value.data);
566  MQTTProperties_add(&props, &property);
567 
568  opts.connectProperties = &props;
569  opts.willProperties = &willProps;
570 
571  MyLog(LOGA_DEBUG, "Connecting");
572  rc = MQTTAsync_connect(c, &opts);
573  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
574  if (rc != MQTTASYNC_SUCCESS)
575  goto exit;
576 
577  while (!test_finished)
578  MySleep(100);
579 
580  MQTTProperties_free(&props);
581  MQTTProperties_free(&willProps);
582  MQTTAsync_destroy(&c);
583 
584 exit:
585  MyLog(LOGA_INFO, "TEST1: test %s. %d tests run, %d failures.",
586  (failures == 0) ? "passed" : "failed", tests, failures);
588  return failures;
589 }
590 
592 
594 {
595  MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context);
596 
598  test_finished = 1;
599 }
600 
601 
603 {
604 
605  MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p\n", context);
606 
607  assert("Connect should not succeed", 0, "connect success callback was called", 0);
608 
609  test_finished = 1;
610 }
611 
612 /*********************************************************************
613 
614 Test2: connect timeout
615 
616 *********************************************************************/
617 int test2(struct Options options)
618 {
619  int subsqos = 2;
620  MQTTAsync c;
623  int rc = 0;
624  char* test_topic = "C client test2";
626 
627  test_finished = 0;
628 
629  MyLog(LOGA_INFO, "Starting test 2 - connect timeout");
630  fprintf(xml, "<testcase classname=\"test4\" name=\"connect timeout\"");
632 
633  createOpts.MQTTVersion = MQTTVERSION_5;
634  rc = MQTTAsync_createWithOptions(&c, "tcp://9.20.96.160:66", "connect timeout",
635  MQTTCLIENT_PERSISTENCE_DEFAULT, NULL, &createOpts);
636  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
637  if (rc != MQTTASYNC_SUCCESS)
638  {
639  MQTTAsync_destroy(&c);
640  goto exit;
641  }
642 
643  rc = MQTTAsync_setCallbacks(c, c, NULL, test1_messageArrived, NULL);
644  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
645 
646  opts.connectTimeout = 5;
647  opts.keepAliveInterval = 20;
648  opts.username = "testuser";
649  opts.binarypwd.data = "testpassword";
650  opts.binarypwd.len = (int)strlen(opts.binarypwd.data);
651  opts.MQTTVersion = options.MQTTVersion;
652 
653  opts.will = &wopts;
654  opts.will->message = "will message";
655  opts.will->qos = 1;
656  opts.will->retained = 0;
657  opts.will->topicName = "will topic";
658  opts.will = NULL;
661  opts.context = c;
662 
663  MyLog(LOGA_DEBUG, "Connecting");
664  rc = MQTTAsync_connect(c, &opts);
665  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
666  if (rc != MQTTASYNC_SUCCESS)
667  goto exit;
668 
669  while (!test_finished)
670  MySleep(100);
671 
672  MQTTAsync_destroy(&c);
673 
674 exit:
675  assert("Connect onFailure should be called once", test2_onFailure_called == 1,
676  "connect onFailure was called %d times", test2_onFailure_called);
677 
678  MyLog(LOGA_INFO, "TEST2: test %s. %d tests run, %d failures.",
679  (failures == 0) ? "passed" : "failed", tests, failures);
681  return failures;
682 }
683 
684 
685 typedef struct
686 {
687  MQTTAsync c;
688  int index;
689  char clientid[24];
690  char test_topic[100];
691  int message_count;
692 } client_data;
693 
694 
696 {
697  client_data* cd = (client_data*)context;
698  MyLog(LOGA_DEBUG, "In onDisconnect callback for client \"%s\"", cd->clientid);
699  test_finished++;
700 }
701 
702 
704 {
705  client_data* cd = (client_data*)context;
706  MyLog(LOGA_DEBUG, "In QoS 0 onPublish callback for client \"%s\"", cd->clientid);
707 }
708 
709 
711 {
712  client_data* cd = (client_data*)context;
714  int rc;
715 
716  MyLog(LOGA_DEBUG, "In onUnsubscribe onSuccess callback \"%s\"", cd->clientid);
718  opts.context = cd;
719 
720  rc = MQTTAsync_disconnect(cd->c, &opts);
721  assert("Disconnect successful", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
722 }
723 
724 
725 int test3_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
726 {
727  client_data* cd = (client_data*)context;
728  int rc;
729 
730  MyLog(LOGA_DEBUG, "In messageArrived callback \"%s\" message count ", cd->clientid);
731 
732  if (++cd->message_count == 1)
733  {
736  pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
737  pubmsg.payloadlen = 25;
738  pubmsg.qos = 1;
739  pubmsg.retained = 0;
740  rc = MQTTAsync_sendMessage(cd->c, cd->test_topic, &pubmsg, &opts);
741  assert("Good rc from publish", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
742  }
743  else if (cd->message_count == 2)
744  {
747  pubmsg.payload = "a QoS 0 message that we can shorten to the extent that we need to payload up to 11";
748  pubmsg.payloadlen = 29;
749  pubmsg.qos = 0;
750  pubmsg.retained = 0;
751  opts.context = cd;
753 
754  rc = MQTTAsync_sendMessage(cd->c, cd->test_topic, &pubmsg, &opts);
755  assert("Good rc from publish", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
756  }
757  else
758  {
760 
762  opts.context = cd;
763  rc = MQTTAsync_unsubscribe(cd->c, cd->test_topic, &opts);
764  assert("Unsubscribe successful", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
765  }
766  MQTTAsync_freeMessage(&message);
767  MQTTAsync_free(topicName);
768  return 1;
769 }
770 
772 {
773  client_data* cd = (client_data*)context;
775  int rc;
776 
777  MyLog(LOGA_DEBUG, "In subscribe onSuccess callback \"%s\"", cd->clientid);
778 
779  pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
780  pubmsg.payloadlen = 11;
781  pubmsg.qos = 2;
782  pubmsg.retained = 0;
783 
784  rc = MQTTAsync_send(cd->c, cd->test_topic, pubmsg.payloadlen, pubmsg.payload, pubmsg.qos, pubmsg.retained, NULL);
785  assert("Good rc from publish", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
786 }
787 
788 
790 {
791  client_data* cd = (client_data*)context;
793  int rc;
794 
795  MyLog(LOGA_DEBUG, "In connect onSuccess callback, \"%s\"", cd->clientid);
797  opts.context = cd;
798 
799  rc = MQTTAsync_subscribe(cd->c, cd->test_topic, 2, &opts);
800  assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
801  if (rc != MQTTASYNC_SUCCESS)
802  test_finished++;
803 }
804 
805 
807 {
808  client_data* cd = (client_data*)context;
810 
811  assert("Should have connected", 0, "%s failed to connect\n", cd->clientid);
812  MyLog(LOGA_DEBUG, "In connect onFailure callback, \"%s\" rc %d\n", cd->clientid, response ? response->reasonCode : -999);
813  if (response && response->message)
814  MyLog(LOGA_DEBUG, "In connect onFailure callback, \"%s\"\n", response->message);
815 
816  test_finished++;
817 }
818 
819 
820 /*********************************************************************
821 
822 Test3: More than one client object - simultaneous working.
823 
824 *********************************************************************/
825 int test3(struct Options options)
826 {
827  #define num_clients 10
828  int subsqos = 2;
831  int rc = 0;
832  int i;
833  client_data clientdata[num_clients];
835 
836  test_finished = 0;
837  MyLog(LOGA_INFO, "Starting test 3 - multiple connections");
838  fprintf(xml, "<testcase classname=\"test4\" name=\"multiple connections\"");
840 
841  for (i = 0; i < num_clients; ++i)
842  {
843  sprintf(clientdata[i].clientid, "async_test3_num_%d", i);
844  sprintf(clientdata[i].test_topic, "async test3 topic num %d", i);
845  clientdata[i].index = i;
846  clientdata[i].message_count = 0;
847 
848  createOpts.MQTTVersion = MQTTVERSION_5;
849  rc = MQTTAsync_createWithOptions(&(clientdata[i].c), options.connection, clientdata[i].clientid,
850  MQTTCLIENT_PERSISTENCE_NONE, NULL, &createOpts);
851  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
852 
853  rc = MQTTAsync_setCallbacks(clientdata[i].c, &clientdata[i], NULL, test3_messageArrived, NULL);
854  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
855 
856  opts.keepAliveInterval = 20;
857  opts.username = "testuser";
858  opts.password = "testpassword";
859  opts.MQTTVersion = options.MQTTVersion;
860 
861  opts.will = &wopts;
862  opts.will->message = "will message";
863  opts.will->qos = 1;
864  opts.will->retained = 0;
865  opts.will->topicName = "will topic";
868  opts.context = &clientdata[i];
869 
870  MyLog(LOGA_DEBUG, "Connecting");
871  rc = MQTTAsync_connect(clientdata[i].c, &opts);
872  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
873  }
874 
875  while (test_finished < num_clients)
876  {
877  MyLog(LOGA_DEBUG, "num_clients %d test_finished %d\n", num_clients, test_finished);
878  MySleep(100);
879  }
880 
881  MyLog(LOGA_DEBUG, "TEST3: destroying clients");
882 
883  for (i = 0; i < num_clients; ++i)
884  MQTTAsync_destroy(&clientdata[i].c);
885 
886 //exit:
887  MyLog(LOGA_INFO, "TEST3: test %s. %d tests run, %d failures.",
888  (failures == 0) ? "passed" : "failed", tests, failures);
890  return failures;
891 }
892 
893 
894 void* test4_payload = NULL;
896 
898 {
899  MQTTAsync c = (MQTTAsync)context;
900 
901  MyLog(LOGA_DEBUG, "In publish onSuccess callback, context %p", context);
902 }
903 
904 int test4_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
905 {
906  MQTTAsync c = (MQTTAsync)context;
907  static int message_count = 0;
908  int rc, i;
909 
910  MyLog(LOGA_DEBUG, "In messageArrived callback %p", c);
911 
912  assert("Message size correct", message->payloadlen == test4_payloadlen,
913  "message size was %d", message->payloadlen);
914 
915  for (i = 0; i < options.size; ++i)
916  {
917  if (((char*)test4_payload)[i] != ((char*)message->payload)[i])
918  {
919  assert("Message contents correct", ((char*)test4_payload)[i] != ((char*)message->payload)[i],
920  "message content was %c", ((char*)message->payload)[i]);
921  break;
922  }
923  }
924 
925  if (++message_count == 1)
926  {
929 
930  pubmsg.payload = test4_payload;
931  pubmsg.payloadlen = test4_payloadlen;
932  pubmsg.qos = 1;
933  pubmsg.retained = 0;
935  opts.context = c;
936 
937  rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts);
938  }
939  else if (message_count == 2)
940  {
943 
944  pubmsg.payload = test4_payload;
945  pubmsg.payloadlen = test4_payloadlen;
946  pubmsg.qos = 0;
947  pubmsg.retained = 0;
949  opts.context = c;
950  rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts);
951  }
952  else
953  {
957 
959  opts.context = c;
960 
961  property.identifier = MQTTPROPERTY_CODE_USER_PROPERTY;
962  property.value.data.data = "test user property";
963  property.value.data.len = (int)strlen(property.value.data.data);
964  property.value.value.data = "test user property value";
965  property.value.value.len = (int)strlen(property.value.value.data);
966  MQTTProperties_add(&props, &property);
967 
968  opts.properties = props;
969  rc = MQTTAsync_unsubscribe(c, test_topic, &opts);
970  assert("Unsubscribe successful", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
971  MQTTProperties_free(&props);
972  }
973 
974  MQTTAsync_freeMessage(&message);
975  MQTTAsync_free(topicName);
976 
977  return 1;
978 }
979 
980 int test4_packet_size = 10000;
981 
982 #if !defined(min)
983 #define min(a, b) ((a < b) ? a : b)
984 #endif
985 
987 {
988  MQTTAsync c = (MQTTAsync)context;
990  int rc, i;
991  int max_packet_size = min(test4_packet_size, options.size);
992 
993  MyLog(LOGA_DEBUG, "In subscribe onSuccess callback %p", c);
994 
997 
998  MyLog(LOGA_INFO, "Max packet size %d", max_packet_size);
999  srand(33);
1000  for (i = 0; i < (max_packet_size-100); ++i)
1001  ((char*)pubmsg.payload)[i] = rand() % 256;
1002 
1003  pubmsg.qos = 2;
1004  pubmsg.retained = 0;
1005 
1006  rc = MQTTAsync_send(c, test_topic, pubmsg.payloadlen, pubmsg.payload, pubmsg.qos, pubmsg.retained, NULL);
1007 }
1008 
1009 
1011 {
1012  MQTTAsync c = (MQTTAsync)context;
1014  int rc;
1015 
1017 
1018  MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
1020  opts.context = c;
1021 
1022  rc = MQTTAsync_subscribe(c, test_topic, 2, &opts);
1023  assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1024  if (rc != MQTTASYNC_SUCCESS)
1025  test_finished = 1;
1026 }
1027 
1028 
1029 /*********************************************************************
1030 
1031 Test4: Send and receive big messages
1032 
1033 *********************************************************************/
1034 int test4(struct Options options)
1035 {
1036  int subsqos = 2;
1037  MQTTAsync c;
1040  int rc = 0;
1041  char* test_topic = "C client test4";
1043 
1044  test_finished = failures = 0;
1045  MyLog(LOGA_INFO, "Starting test 4 - big messages");
1046  fprintf(xml, "<testcase classname=\"test4\" name=\"big messages\"");
1048 
1049  createOpts.MQTTVersion = MQTTVERSION_5;
1050  rc = MQTTAsync_createWithOptions(&c, options.connection, "async_test_4",
1051  MQTTCLIENT_PERSISTENCE_DEFAULT, NULL, &createOpts);
1052  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
1053  if (rc != MQTTASYNC_SUCCESS)
1054  {
1055  MQTTAsync_destroy(&c);
1056  goto exit;
1057  }
1058 
1059  rc = MQTTAsync_setCallbacks(c, c, NULL, test4_messageArrived, NULL);
1060  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1061 
1062  opts.keepAliveInterval = 20;
1063  opts.username = "testuser";
1064  opts.password = "testpassword";
1065  opts.MQTTVersion = options.MQTTVersion;
1066 
1067  opts.will = &wopts;
1068  opts.will->message = "will message";
1069  opts.will->qos = 1;
1070  opts.will->retained = 0;
1071  opts.will->topicName = "will topic";
1072  opts.will = NULL;
1073  opts.onSuccess5 = test4_onConnect;
1074  opts.onFailure5 = NULL;
1075  opts.context = c;
1076 
1077  MyLog(LOGA_DEBUG, "Connecting");
1078  rc = MQTTAsync_connect(c, &opts);
1079  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1080  if (rc != MQTTASYNC_SUCCESS)
1081  goto exit;
1082 
1083  while (!test_finished)
1084  MySleep(100);
1085 
1086  MQTTAsync_destroy(&c);
1087 
1088 exit:
1089  MyLog(LOGA_INFO, "TEST4: test %s. %d tests run, %d failures.",
1090  (failures == 0) ? "passed" : "failed", tests, failures);
1092  return failures;
1093 }
1094 
1095 
1097 {
1098  MQTTAsync c = (MQTTAsync)context;
1100 
1101  MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context);
1102 
1103  MyLog(LOGA_INFO, "Connack rc is %d", response ? response->reasonCode : -999);
1104 
1105  test_finished = 1;
1106 }
1107 
1108 
1110 {
1111  MQTTAsync c = (MQTTAsync)context;
1113 
1114  MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context);
1115 
1116  test_finished = 1;
1117 }
1118 
1119 
1120 /********************************************************************
1121 
1122 Test5: Connack return codes
1123 
1124 *********************************************************************/
1125 int test5(struct Options options)
1126 {
1127  int subsqos = 2;
1128  MQTTAsync c;
1131  int rc = 0;
1132  char* test_topic = "C client test1";
1134 
1135  test_finished = failures = 0;
1136  MyLog(LOGA_INFO, "Starting test 5 - connack return codes");
1137  fprintf(xml, "<testcase classname=\"test45\" name=\"connack return codes\"");
1139 
1140  createOpts.MQTTVersion = MQTTVERSION_5;
1141  rc = MQTTAsync_createWithOptions(&c, options.connection, "a clientid that is too long to be accepted",
1142  MQTTCLIENT_PERSISTENCE_DEFAULT, NULL, &createOpts);
1143  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
1144  if (rc != MQTTASYNC_SUCCESS)
1145  {
1146  MQTTAsync_destroy(&c);
1147  goto exit;
1148  }
1149 
1150  rc = MQTTAsync_setCallbacks(c, c, NULL, test1_messageArrived, NULL);
1151  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1152 
1153  opts.onSuccess5 = test5_onConnect;
1155  opts.context = c;
1156 
1157  MyLog(LOGA_DEBUG, "Connecting");
1158  rc = MQTTAsync_connect(c, &opts);
1159  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1160  if (rc != MQTTASYNC_SUCCESS)
1161  goto exit;
1162 
1163  while (!test_finished)
1164  MySleep(100);
1165 
1166  MQTTAsync_destroy(&c);
1167 
1168 exit:
1169  MyLog(LOGA_INFO, "TEST5: test %s. %d tests run, %d failures.",
1170  (failures == 0) ? "passed" : "failed", tests, failures);
1172  return failures;
1173 }
1174 
1175 
1176 typedef struct
1177 {
1178  MQTTAsync c;
1179  int should_fail;
1181 
1183 {
1184  test6_client_info cinfo = *(test6_client_info*)context;
1185 
1186  MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context);
1187 
1188  if (response)
1189  MyLog(LOGA_INFO, "Connack rc is %d", response->reasonCode);
1190 
1191  assert("Should fail to connect", cinfo.should_fail, "should_fail was %d", cinfo.should_fail);
1192 
1193  test_finished = 1;
1194 }
1195 
1196 
1198 {
1199  test6_client_info cinfo = *(test6_client_info*)context;
1200 
1201  MyLog(LOGA_DEBUG, "In connect success callback, context %p", context);
1202 
1203  assert("Should connect correctly", !cinfo.should_fail, "should_fail was %d", cinfo.should_fail);
1204 
1205  test_finished = 1;
1206 }
1207 
1208 
1210 {
1211  test6_client_info cinfo = *(test6_client_info*)context;
1212 
1213  MyLog(LOGA_DEBUG, "In onDisconnect5 callback %p", cinfo.c);
1214  test_finished = 1;
1215 }
1216 
1217 
1218 /********************************************************************
1219 
1220 Test6: HA connections
1221 
1222 *********************************************************************/
1223 int test6(struct Options options)
1224 {
1225  int subsqos = 2;
1226  test6_client_info cinfo;
1229  int rc = 0;
1230  char* test_topic = "C client test1";
1231  char* uris[2] = {options.connection, options.connection};
1234 
1235  failures = 0;
1236  MyLog(LOGA_INFO, "Starting test 6 - HA connections");
1237  fprintf(xml, "<testcase classname=\"test4\" name=\"HA connections\"");
1239 
1240  test_finished = 0;
1241  cinfo.should_fail = 1; /* fail to connect */
1242  createOpts.MQTTVersion = MQTTVERSION_5;
1243  rc = MQTTAsync_createWithOptions(&cinfo.c, "tcp://rubbish:1883", "async ha connection",
1244  MQTTCLIENT_PERSISTENCE_DEFAULT, NULL, &createOpts);
1245  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
1246  if (rc != MQTTASYNC_SUCCESS)
1247  {
1248  MQTTAsync_destroy(&cinfo.c);
1249  goto exit;
1250  }
1251 
1252  rc = MQTTAsync_setCallbacks(cinfo.c, cinfo.c, NULL, test1_messageArrived, NULL);
1253  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1254 
1255  opts.onSuccess5 = test6_onConnect;
1257  opts.context = &cinfo;
1258  opts.MQTTVersion = options.MQTTVersion;
1259 
1260  MyLog(LOGA_DEBUG, "Connecting");
1261  rc = MQTTAsync_connect(cinfo.c, &opts);
1262  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1263  if (rc != MQTTASYNC_SUCCESS)
1264  goto exit;
1265 
1266  while (!test_finished)
1267  MySleep(100);
1268 
1269  test_finished = 0;
1270  cinfo.should_fail = 0; /* should connect through the serverURIs in connect options*/
1271  opts.serverURIs = uris;
1272  opts.serverURIcount = 2;
1273 
1274  MyLog(LOGA_DEBUG, "Connecting");
1275  rc = MQTTAsync_connect(cinfo.c, &opts);
1276  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1277  if (rc != MQTTASYNC_SUCCESS)
1278  goto exit;
1279 
1280  while (!test_finished)
1281  MySleep(100);
1282 
1283  test_finished = 0;
1284  dopts.timeout = 0;
1286  dopts.context = cinfo.c;
1287  dopts.timeout = 0;
1288  MQTTAsync_disconnect(cinfo.c, &dopts);
1289 
1290  while (!test_finished)
1291  MySleep(100);
1292 
1293  MQTTAsync_destroy(&cinfo.c);
1294 
1295 exit:
1296  MyLog(LOGA_INFO, "TEST6: test %s. %d tests run, %d failures.",
1297  (failures == 0) ? "passed" : "failed", tests, failures);
1299  return failures;
1300 }
1301 
1302 
1303 
1304 /********************************************************************
1305 
1306 Test7: Persistence
1307 
1308 *********************************************************************/
1309 
1310 char* test7_topic = "C client test7";
1312 
1313 
1315 {
1316  MQTTAsync c = (MQTTAsync)context;
1317  MyLog(LOGA_DEBUG, "In onDisconnect failure callback %p", c);
1318 
1319  assert("Successful disconnect", 0, "disconnect failed", 0);
1320 
1321  test_finished = 1;
1322 }
1323 
1324 
1326 {
1327  MQTTAsync c = (MQTTAsync)context;
1328  MyLog(LOGA_DEBUG, "In onDisconnect5 failure callback %p", c);
1329 
1330  assert("Successful disconnect", 0, "disconnect failed", 0);
1331 
1332  test_finished = 1;
1333 }
1334 
1335 
1337 {
1338  MQTTAsync c = (MQTTAsync)context;
1339  MyLog(LOGA_DEBUG, "In onDisconnect callback %p", c);
1340  test_finished = 1;
1341 }
1342 
1343 
1345 {
1346  MQTTAsync c = (MQTTAsync)context;
1347  MyLog(LOGA_DEBUG, "In onDisconnect5 callback %p", c);
1348  test_finished = 1;
1349 }
1350 
1351 
1353 {
1354  MQTTAsync c = (MQTTAsync)context;
1356  int rc;
1357 
1358  MyLog(LOGA_DEBUG, "In onUnsubscribe onSuccess callback %p", c);
1360  opts.context = c;
1361 
1362  rc = MQTTAsync_disconnect(c, &opts);
1363  assert("Disconnect successful", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1364 }
1365 
1366 
1368 {
1369  MQTTAsync c = (MQTTAsync)context;
1371  int rc;
1372 
1373  MyLog(LOGA_DEBUG, "In onUnsubscribe onSuccess5 callback %p", c);
1375  opts.context = c;
1376 
1377  rc = MQTTAsync_disconnect(c, &opts);
1378  assert("Disconnect successful", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1379 }
1380 
1381 
1382 int test7_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
1383 {
1384  MQTTAsync c = (MQTTAsync)context;
1385  static int message_count = 0;
1386 
1387  MyLog(LOGA_DEBUG, "Test7: received message id %d, %.*s", message->msgid,
1388  message->payloadlen, message->payload);
1389 
1391 
1392  MQTTAsync_freeMessage(&message);
1393  MQTTAsync_free(topicName);
1394 
1395  return 1;
1396 }
1397 
1398 
1399 static int test7_subscribed = 0;
1400 
1402 {
1403  MQTTAsync c = (MQTTAsync)context;
1404 
1405  MyLog(LOGA_DEBUG, "In subscribe onSuccess5 callback %p granted qos %d", c, response->reasonCode);
1406 
1407  test7_subscribed = 1;
1408 }
1409 
1410 
1412 {
1413  MQTTAsync c = (MQTTAsync)context;
1414 
1415  MyLog(LOGA_DEBUG, "In subscribe onSuccess callback %p granted qos %d", c,
1416  response->alt.qos);
1417 
1418  test7_subscribed = 1;
1419 }
1420 
1421 static int test7_just_connect = 0;
1422 
1424 {
1425  MQTTAsync c = (MQTTAsync)context;
1427  int rc;
1428 
1429  MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
1430 
1431  if (test7_just_connect == 1)
1432  {
1433  test7_just_connect = 2;
1434  return;
1435  }
1436 
1438  opts.context = c;
1439 
1440  rc = MQTTAsync_subscribe(c, test7_topic, 2, &opts);
1441  assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1442  if (rc != MQTTASYNC_SUCCESS)
1443  test_finished = 1;
1444 }
1445 
1446 
1448 {
1449  MQTTAsync c = (MQTTAsync)context;
1451  int rc;
1452 
1453  MyLog(LOGA_DEBUG, "In connect onSuccess5 callback, context %p", context);
1454 
1455  if (test7_just_connect == 1)
1456  { /* we don't need to subscribe if we reconnected */
1457  test7_subscribed = 1;
1458  return;
1459  }
1460 
1462  opts.context = c;
1463 
1464  rc = MQTTAsync_subscribe(c, test7_topic, 2, &opts);
1465  assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1466  if (rc != MQTTASYNC_SUCCESS)
1467  test_finished = 1;
1468 }
1469 
1470 
1471 /*********************************************************************
1472 
1473 Test7: Pending tokens
1474 
1475 *********************************************************************/
1476 int test7_run(int qos, int start_mqtt_version, int restore_mqtt_version)
1477 {
1478  int subsqos = 2;
1479  MQTTAsync c;
1482  int rc = 0;
1486  MQTTAsync_token* tokens = NULL;
1487  int msg_count = 6;
1491  int i = 0;
1492 
1493  MyLog(LOGA_INFO, "Starting test 7 - persistence, qos %d, MQTT versions: %s then %s", qos,
1494  (start_mqtt_version == MQTTVERSION_5) ? "5" : "3.1.1",
1495  (restore_mqtt_version == MQTTVERSION_5) ? "5" : "3.1.1");
1496 
1497  fprintf(xml, "<testcase classname=\"test45\" name=\"pending tokens\"");
1499  test_finished = 0;
1500 
1501  createOpts.MQTTVersion = start_mqtt_version;
1503  rc = MQTTAsync_createWithOptions(&c, options.connection, "async_test7",
1504  MQTTCLIENT_PERSISTENCE_DEFAULT, NULL, &createOpts);
1505  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
1506  if (rc != MQTTASYNC_SUCCESS)
1507  {
1508  MQTTAsync_destroy(&c);
1509  goto exit;
1510  }
1511 
1512  rc = MQTTAsync_setCallbacks(c, c, NULL, test7_messageArrived, NULL);
1513  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1514 
1515  opts.keepAliveInterval = 20;
1516  opts.username = "testuser";
1517  opts.password = "testpassword";
1518  opts.MQTTVersion = start_mqtt_version;
1519 
1520  opts.will = &wopts;
1521  opts.will->message = "will message";
1522  opts.will->qos = 1;
1523  opts.will->retained = 0;
1524  opts.will->topicName = "will topic";
1525  opts.will = NULL;
1526  opts.context = c;
1527 
1528  /* connect clean and then leave messages lying around */
1529  test_finished = 0;
1530  test7_subscribed = 0;
1531  MyLog(LOGA_DEBUG, "Connecting");
1532 
1533  if (start_mqtt_version == MQTTVERSION_5)
1534  {
1535  opts.cleanstart = 1;
1536  test7_just_connect = 0;
1537  opts.connectProperties = &props;
1538  property.identifier = MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL;
1539  property.value.integer4 = 999999;
1540  MQTTProperties_add(opts.connectProperties, &property);
1542  opts.onFailure5 = NULL;
1543  rc = MQTTAsync_connect(c, &opts);
1544  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1546  if (rc != MQTTASYNC_SUCCESS)
1547  goto exit;
1548  }
1549  else
1550  { /* MQTT 3 version */
1551  opts.cleanstart = 0;
1552  opts.cleansession = 1; /* clean up */
1553  test7_just_connect = 1;
1554  opts.onSuccess = test7_onConnect;
1555  opts.onFailure = NULL;
1556  rc = MQTTAsync_connect(c, &opts);
1557  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1558  if (rc != MQTTASYNC_SUCCESS)
1559  goto exit;
1560  while (test7_just_connect < 2)
1561  MySleep(100);
1562  test_finished = 0;
1563  dopts.onSuccess5 = NULL;
1564  dopts.onFailure5 = NULL;
1566  dopts.onSuccess = test7_onDisconnect;
1567  rc = MQTTAsync_disconnect(c, &dopts);
1568  assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1569  while (!test_finished)
1570  MySleep(100);
1571  test_finished = 0;
1572  opts.cleansession = 0; /* now it's clean */
1573  test7_just_connect = 0;
1574  rc = MQTTAsync_connect(c, &opts);
1575  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1576  if (rc != MQTTASYNC_SUCCESS)
1577  goto exit;
1578  }
1579 
1580  while (!test7_subscribed)
1581  MySleep(100);
1582 
1583  test7_messageCount = 0;
1584  pubmsg.payload = "first test of a much longer message that we can shorten to the extent that we need to payload up to 11";
1585  pubmsg.payloadlen = 11;
1586  pubmsg.qos = qos;
1587  pubmsg.retained = 0;
1588  rc = MQTTAsync_send(c, test7_topic, pubmsg.payloadlen, pubmsg.payload, pubmsg.qos, pubmsg.retained, &ropts);
1589  assert("Good rc from send", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1590  MyLog(LOGA_DEBUG, "Token was %d", ropts.token);
1591  rc = MQTTAsync_waitForCompletion(c, ropts.token, 5000L);
1592  assert("Good rc from waitForCompletion", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1593  rc = MQTTAsync_isComplete(c, ropts.token);
1594  assert("1 rc from isComplete", rc == 1, "rc was %d", rc);
1595 
1596  i = 0;
1597  pubmsg.qos = qos;
1598  for (i = 0; i < msg_count; ++i)
1599  {
1600  char buf[100];
1601  sprintf(buf, "%d a much longer message that we can shorten to the extent that we need", i);
1602  pubmsg.payload = buf;
1603  pubmsg.payloadlen = 11 + i;
1604  pubmsg.retained = 0;
1605  rc = MQTTAsync_sendMessage(c, test7_topic, &pubmsg, &ropts);
1606  }
1607  /* disconnect immediately without receiving the incoming messages */
1608  dopts.timeout = 0;
1609  if (start_mqtt_version == MQTTVERSION_5)
1611  else
1612  dopts.onSuccess = test7_onDisconnect;
1613  dopts.context = c;
1614  dopts.timeout = 0;
1615  MQTTAsync_disconnect(c, &dopts); /* now there should be "orphaned" publications */
1616 
1617  while (!test_finished)
1618  MySleep(100);
1619  test_finished = 0;
1620 
1621  rc = MQTTAsync_getPendingTokens(c, &tokens);
1622  assert("getPendingTokens rc == 0", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1623 
1624  assert("should get some tokens back", tokens != NULL, "tokens was %p", tokens);
1625  if (tokens)
1626  MQTTAsync_free(tokens);
1628 
1629  MQTTAsync_destroy(&c); /* force re-reading persistence on create */
1630 
1632  createOpts.MQTTVersion = restore_mqtt_version;
1633  rc = MQTTAsync_createWithOptions(&c, options.connection, "async_test7",
1634  MQTTCLIENT_PERSISTENCE_DEFAULT, NULL, &createOpts);
1635 
1636  if (start_mqtt_version == MQTTVERSION_5 && restore_mqtt_version == MQTTVERSION_3_1_1)
1637  assert("Persistence error from create", rc == MQTTASYNC_PERSISTENCE_ERROR, "rc was %d", rc);
1638  else
1639  assert("Good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1640  if (rc != MQTTASYNC_SUCCESS)
1641  {
1642  //MQTTAsync_destroy(&c);
1643  goto exit;
1644  }
1645 
1646  rc = MQTTAsync_getPendingTokens(c, &tokens);
1647  assert("getPendingTokens rc == 0", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1648 
1649  assert("should get some tokens back", tokens != NULL, "tokens was %p", tokens);
1650  if (tokens)
1651  {
1652  int i = 0;
1653  while (tokens[i] != -1)
1654  MyLog(LOGA_DEBUG, "Delivery token %d", tokens[i++]);
1655  MQTTAsync_free(tokens);
1656  assert("no of tokens should be > 0", i > 0, "no of tokens %d", i);
1657  }
1658 
1659  rc = MQTTAsync_setCallbacks(c, c, NULL, test7_messageArrived, NULL);
1660  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1661 
1662  MyLog(LOGA_DEBUG, "Reconnecting");
1663  opts.context = c;
1664  opts.MQTTVersion = restore_mqtt_version;
1665  if (restore_mqtt_version == MQTTVERSION_5)
1666  {
1667  opts.cleanstart = opts.cleansession = 0;
1668  test7_just_connect = 1;
1669  opts.connectProperties = &props;
1670  property.identifier = MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL;
1671  property.value.integer4 = 0; /* clean up at end of test */
1672  MQTTProperties_add(opts.connectProperties, &property);
1673  opts.onSuccess = NULL;
1674  opts.onFailure = NULL;
1676  opts.onFailure5 = NULL;
1677  rc = MQTTAsync_connect(c, &opts);
1678  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1680  if (rc != MQTTASYNC_SUCCESS)
1681  goto exit;
1682  }
1683  else
1684  { /* MQTT 3 version */
1685  opts.cleanstart = opts.cleansession = 0;
1686  test7_just_connect = 1;
1687  opts.onSuccess5 = NULL;
1688  opts.onFailure5 = NULL;
1689  opts.onSuccess = test7_onConnect;
1690  opts.onFailure = NULL;
1691  rc = MQTTAsync_connect(c, &opts);
1692  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1693  if (rc != MQTTASYNC_SUCCESS)
1694  goto exit;
1695  }
1696 
1698 
1699  if (qos == 2)
1700  assert("no of messages should be count", test7_messageCount == msg_count + 1,
1701  "messages received %d\n", test7_messageCount);
1702  else if (qos == 1)
1703  assert("no of messages should be at least count", test7_messageCount >= msg_count + 1,
1704  "messages received %d\n", test7_messageCount);
1705 
1706  if (restore_mqtt_version == MQTTVERSION_5)
1707  {
1710  }
1711  else
1712  {
1714  dopts.onSuccess = test7_onDisconnect;
1715  }
1716  dopts.timeout = 300;
1717  rc = MQTTAsync_disconnect(c, &dopts);
1718  assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1719 
1720  i = 0;
1721  while (!test_finished && ++i < 20)
1722  MySleep(100);
1723  assert("Test finished should be true", test_finished,
1724  "test_finished was %d", test_finished);
1725 
1726  MQTTAsync_destroy(&c);
1727 
1728 exit:
1729  MyLog(LOGA_INFO, "TEST7: test %s. %d tests run, %d failures.",
1730  (failures == 0) ? "passed" : "failed", tests, failures);
1732  return failures;
1733 }
1734 
1735 
1736 int test7(struct Options options)
1737 {
1738  int rc = 0;
1739  fprintf(xml, "<testcase classname=\"test7\" name=\"persistence\"");
1745  test7_run(2, MQTTVERSION_3_1_1, MQTTVERSION_5) +
1746  test7_run(2, MQTTVERSION_5, MQTTVERSION_3_1_1)*/;
1747  fprintf(xml, " time=\"%ld\" >\n", elapsed(global_start_time) / 1000);
1748  if (cur_output != output)
1749  {
1750  fprintf(xml, "%s", output);
1751  cur_output = output;
1752  }
1753  fprintf(xml, "</testcase>\n");
1754  return rc;
1755 }
1756 
1757 
1758 
1759 /*********************************************************************
1760 
1761 Test8: Incomplete commands and requests
1762 
1763 *********************************************************************/
1764 
1765 char* test8_topic = "C client test8";
1769 
1771 {
1772  MQTTAsync c = (MQTTAsync)context;
1773 
1774  MyLog(LOGA_DEBUG, "In publish onSuccess callback %p token %d", c, response->token);
1775 
1776 }
1777 
1779 {
1780  MQTTAsync c = (MQTTAsync)context;
1781  MyLog(LOGA_DEBUG, "In onPublish failure callback %p", c);
1782 
1783  assert("Response code should be interrupted", response->code == MQTTASYNC_OPERATION_INCOMPLETE,
1784  "rc was %d", response->code);
1785 
1787 }
1788 
1789 
1791 {
1792  MQTTAsync c = (MQTTAsync)context;
1793  MyLog(LOGA_DEBUG, "In onDisconnect failure callback %p", c);
1794 
1795  assert("Successful disconnect", 0, "disconnect failed", 0);
1796 
1797  test_finished = 1;
1798 }
1799 
1800 
1802 {
1803  MQTTAsync c = (MQTTAsync)context;
1804  MyLog(LOGA_DEBUG, "In onDisconnect callback %p", c);
1805  test_finished = 1;
1806 }
1807 
1808 
1810 {
1811  MQTTAsync c = (MQTTAsync)context;
1812 
1813  MyLog(LOGA_DEBUG, "In subscribe onSuccess callback %p granted qos %d", c, response->reasonCode);
1814 
1815  test8_subscribed = 1;
1816 }
1817 
1818 
1820 {
1821  MQTTAsync c = (MQTTAsync)context;
1823  int rc;
1824 
1825  MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
1827  opts.context = c;
1828 
1829  rc = MQTTAsync_subscribe(c, test8_topic, 2, &opts);
1830  assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1831  if (rc != MQTTASYNC_SUCCESS)
1832  test_finished = 1;
1833 }
1834 
1835 int test8_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
1836 {
1837  MQTTAsync c = (MQTTAsync)context;
1838  static int message_count = 0;
1839 
1840  MyLog(LOGA_DEBUG, "Test8: received message id %d", message->msgid);
1841 
1843 
1844  MQTTAsync_freeMessage(&message);
1845  MQTTAsync_free(topicName);
1846 
1847  return 1;
1848 }
1849 
1850 
1851 int test8(struct Options options)
1852 {
1853  int subsqos = 2;
1854  MQTTAsync c;
1856  int rc = 0;
1860  MQTTAsync_token* tokens = NULL;
1861  int msg_count = 6;
1865 
1866  MyLog(LOGA_INFO, "Starting test 8 - incomplete commands");
1867  fprintf(xml, "<testcase classname=\"test4\" name=\"incomplete commands\"");
1869  test_finished = 0;
1870 
1871  createOpts.MQTTVersion = MQTTVERSION_5;
1872  rc = MQTTAsync_createWithOptions(&c, options.connection, "async_test8",
1873  MQTTCLIENT_PERSISTENCE_DEFAULT, NULL, &createOpts);
1874  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
1875  if (rc != MQTTASYNC_SUCCESS)
1876  {
1877  MQTTAsync_destroy(&c);
1878  goto exit;
1879  }
1880 
1881  rc = MQTTAsync_setCallbacks(c, c, NULL, test8_messageArrived, NULL);
1882  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1883 
1884  opts.keepAliveInterval = 20;
1885  opts.username = "testuser";
1886  opts.password = "testpassword";
1887  opts.MQTTVersion = options.MQTTVersion;
1888 
1889  opts.onFailure = NULL;
1890  opts.context = c;
1891 
1892  MyLog(LOGA_DEBUG, "Connecting");
1893  opts.cleanstart = 1;
1894  opts.onSuccess5 = test8_onConnect;
1895  rc = MQTTAsync_connect(c, &opts);
1896  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1897  if (rc != MQTTASYNC_SUCCESS)
1898  goto exit;
1899 
1900  while (!test8_subscribed)
1901  MySleep(100);
1902 
1903  int i = 0;
1904  pubmsg.qos = 2;
1905  ropts.onSuccess5 = test8_onPublish;
1907  ropts.context = c;
1908  for (i = 0; i < msg_count; ++i)
1909  {
1910  pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
1911  pubmsg.payloadlen = 11;
1912  pubmsg.qos = (pubmsg.qos == 2) ? 1 : 2; /* alternate */
1913  pubmsg.retained = 0;
1914  rc = MQTTAsync_sendMessage(c, test8_topic, &pubmsg, &ropts);
1915  assert("Good rc from sendMessage", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1916  }
1917  /* disconnect immediately without completing the commands */
1918  dopts.timeout = 0;
1920  dopts.context = c;
1921  rc = MQTTAsync_disconnect(c, &dopts); /* now there should be incomplete commands */
1922  assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1923 
1924  while (!test_finished)
1925  MySleep(100);
1926  test_finished = 0;
1927 
1929 
1930  assert("test8_publishFailures > 0", test8_publishFailures > 0,
1931  "test8_publishFailures = %d", test8_publishFailures);
1932 
1933  /* Now elicit failure callbacks on destroy */
1934 
1936 
1937  MyLog(LOGA_DEBUG, "Connecting");
1938  opts.onSuccess5 = test8_onConnect;
1939 
1940  property.identifier = MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL;
1941  property.value.integer4 = 30;
1942  MQTTProperties_add(&props, &property);
1943 
1944  opts.connectProperties = &props;
1945 
1946  rc = MQTTAsync_connect(c, &opts);
1947  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1948  if (rc != MQTTASYNC_SUCCESS)
1949  goto exit;
1950 
1951  while (!test8_subscribed)
1952  MySleep(100);
1953 
1954  i = 0;
1955  pubmsg.qos = 2;
1956  ropts.onSuccess5 = test8_onPublish;
1958  ropts.context = c;
1959  for (i = 0; i < msg_count; ++i)
1960  {
1961  pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
1962  pubmsg.payloadlen = 11;
1963  pubmsg.qos = (pubmsg.qos == 2) ? 1 : 2; /* alternate */
1964  pubmsg.retained = 0;
1965  rc = MQTTAsync_sendMessage(c, test8_topic, &pubmsg, &ropts);
1966  assert("Good rc from sendMessage", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1967  }
1968  /* disconnect immediately without completing the commands */
1969  dopts.timeout = 0;
1971  dopts.context = c;
1972  rc = MQTTAsync_disconnect(c, &dopts); /* now there should be incomplete commands */
1973  assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1974 
1975  while (!test_finished)
1976  MySleep(100);
1977  test_finished = 0;
1978 
1979  rc = MQTTAsync_getPendingTokens(c, &tokens);
1980  assert("getPendingTokens rc == 0", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1981  assert("should get some tokens back", tokens != NULL, "tokens was %p", tokens);
1982  MQTTAsync_free(tokens);
1983  MQTTProperties_free(&props);
1984 
1985  assert("test8_publishFailures == 0", test8_publishFailures == 0,
1986  "test8_publishFailures = %d", test8_publishFailures);
1987 
1988  MQTTAsync_destroy(&c);
1989 
1990  assert("test8_publishFailures > 0", test8_publishFailures > 0,
1991  "test8_publishFailures = %d", test8_publishFailures);
1992 
1993  /* cleanup persistence of any left over message data*/
1994 
1996  rc = MQTTAsync_createWithOptions(&c, options.connection, "async_test8",
1997  MQTTCLIENT_PERSISTENCE_DEFAULT, NULL, &createOpts);
1998  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
1999  if (rc != MQTTASYNC_SUCCESS)
2000  {
2001  MQTTAsync_destroy(&c);
2002  goto exit;
2003  }
2004 
2005  test8_subscribed = 0;
2006  opts.connectProperties = NULL;
2007  opts.cleanstart = 1;
2008  opts.context = c;
2009 
2010  rc = MQTTAsync_connect(c, &opts);
2011  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
2012  if (rc != MQTTASYNC_SUCCESS)
2013  goto exit;
2014 
2015  while (!test8_subscribed)
2016  MySleep(100);
2017 
2018  test_finished = 0;
2019  dopts.context = c;
2020  rc = MQTTAsync_disconnect(c, &dopts);
2021  assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
2022 
2023  while (!test_finished)
2024  MySleep(100);
2025 
2026  MQTTAsync_destroy(&c);
2027 
2028 exit:
2029  MyLog(LOGA_INFO, "TEST8: test %s. %d tests run, %d failures.",
2030  (failures == 0) ? "passed" : "failed", tests, failures);
2032  return failures;
2033 }
2034 
2035 
2036 
2037 void trace_callback(enum MQTTASYNC_TRACE_LEVELS level, char* message)
2038 {
2039  printf("Trace : %d, %s\n", level, message);
2040 }
2041 
2042 
2043 
2044 
2045 int main(int argc, char** argv)
2046 {
2047  int rc = -1;
2048  int (*tests[])() = {NULL, test1, test2, test3, test4, test5, test6, test7, test8}; /* indexed starting from 1 */
2049  MQTTAsync_nameValue* info;
2050  int i;
2051 
2052  xml = fopen("TEST-test4.xml", "w");
2053  fprintf(xml, "<testsuite name=\"test4\" tests=\"%d\">\n", (int)(ARRAY_SIZE(tests)) - 1);
2054 
2055  getopts(argc, argv);
2056 
2058 
2059  info = MQTTAsync_getVersionInfo();
2060  while (info->name)
2061  {
2062  MyLog(LOGA_INFO, "%s: %s", info->name, info->value);
2063  info++;
2064  }
2065 
2066  for (i = 0; i < options.iterations; ++i)
2067  {
2068  if (options.test_no == -1)
2069  { /* run all the tests */
2071  {
2072  failures = rc = 0;
2074  rc += tests[options.test_no](options); /* return number of failures. 0 = test succeeded */
2075  }
2076  }
2077  else
2078  {
2079  if (options.test_no >= ARRAY_SIZE(tests))
2080  MyLog(LOGA_INFO, "No test number %d", options.test_no);
2081  else
2082  {
2084  rc = tests[options.test_no](options); /* run just the selected test */
2085  }
2086  }
2087  }
2088 
2089  if (rc == 0)
2090  MyLog(LOGA_INFO, "verdict pass");
2091  else
2092  MyLog(LOGA_INFO, "verdict fail");
2093 
2094  fprintf(xml, "</testsuite>\n");
2095  fclose(xml);
2096 
2097  return rc;
2098 }
int test7_run(int qos, int start_mqtt_version, int restore_mqtt_version)
Definition: test45.c:1476
MQTTAsync_onFailure * onFailure
Definition: MQTTAsync.h:1255
int test7_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
Definition: test45.c:1382
MQTTProperties properties
Definition: MQTTAsync.h:316
#define assert(a, b, c, d)
Definition: test45.c:223
int test6(struct Options options)
Definition: test45.c:1223
void test3_onUnsubscribe(void *context, MQTTAsync_successData5 *response)
Definition: test45.c:710
enum MQTTPropertyCodes value
int MQTTAsync_createWithOptions(MQTTAsync *handle, const char *serverURI, const char *clientId, int persistence_type, void *persistence_context, MQTTAsync_createOptions *options)
Definition: MQTTAsync.c:575
int size
Definition: test11.c:53
void test2_onConnect(void *context, MQTTAsync_successData5 *response)
Definition: test45.c:602
void logProperties(MQTTProperties *props)
Definition: test45.c:268
MQTTAsync_onFailure5 * onFailure5
Definition: MQTTAsync.h:726
void test7_onDisconnect(void *context, MQTTAsync_successData *response)
Definition: test45.c:1336
int failures
Definition: test45.c:227
void test7_onConnect(void *context, MQTTAsync_successData *response)
Definition: test45.c:1423
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&...args)
Definition: core.h:2081
void test3_onPublish(void *context, MQTTAsync_successData5 *response)
Definition: test45.c:703
int test8_subscribed
Definition: test45.c:1767
char * cur_output
Definition: test45.c:231
MQTTProperties props
Definition: paho_c_pub.c:54
void test8_onConnect(void *context, MQTTAsync_successData5 *response)
Definition: test45.c:1819
void test7_onDisconnectFailure5(void *context, MQTTAsync_failureData5 *response)
Definition: test45.c:1325
const char * name
Definition: MQTTAsync.h:1149
union MQTTAsync_successData::@46 alt
void test7_onUnsubscribe(void *context, MQTTAsync_successData *response)
Definition: test45.c:1352
int test8_publishFailures
Definition: test45.c:1768
const char * message
Definition: MQTTAsync.h:996
MQTTLenString value
char * connection
const char * topicName
Definition: MQTTAsync.h:994
void MQTTProperties_free(MQTTProperties *props)
char test_topic[100]
Definition: test4.c:528
#define MQTTAsync_responseOptions_initializer
Definition: MQTTAsync.h:746
MQTTAsync_token token
Definition: MQTTAsync.h:582
int main(int argc, char **argv)
Definition: test45.c:2045
MQTTProperties properties
Definition: MQTTAsync.h:584
void MySleep(long milliseconds)
Definition: test45.c:160
int MQTTAsync_disconnect(MQTTAsync handle, const MQTTAsync_disconnectOptions *options)
Definition: MQTTAsync.c:3923
int MQTTAsync_setCallbacks(MQTTAsync handle, void *context, MQTTAsync_connectionLost *cl, MQTTAsync_messageArrived *ma, MQTTAsync_deliveryComplete *dc)
Definition: MQTTAsync.c:3062
void test1_onUnsubscribe(void *context, MQTTAsync_successData5 *response)
Definition: test45.c:345
struct pubsub_opts opts
Definition: paho_c_pub.c:42
int MQTTProperties_add(MQTTProperties *props, const MQTTProperty *prop)
MQTTAsync_nameValue * MQTTAsync_getVersionInfo(void)
Definition: MQTTAsync.c:4909
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
char output[3000]
Definition: test45.c:230
void MQTTAsync_free(void *memory)
Definition: MQTTAsync.c:2626
int MQTTProperty_getType(enum MQTTPropertyCodes value)
#define malloc(x)
Definition: Heap.h:41
enum MQTTReasonCodes reasonCode
Definition: MQTTAsync.h:583
static int test7_subscribed
Definition: test45.c:1399
void MQTTAsync_freeMessage(MQTTAsync_message **message)
Definition: MQTTAsync.c:2615
void test6_onConnect(void *context, MQTTAsync_successData5 *response)
Definition: test45.c:1197
int MQTTAsync_unsubscribe(MQTTAsync handle, const char *topic, MQTTAsync_responseOptions *response)
Definition: MQTTAsync.c:4209
MQTTAsync_onSuccess5 * onSuccess5
Definition: MQTTAsync.h:720
void MQTTAsync_setTraceCallback(MQTTAsync_traceCallback *callback)
Definition: MQTTAsync.c:4903
void test5_onConnect(void *context, MQTTAsync_successData5 *response)
Definition: test45.c:1109
unsigned char retainAsPublished
int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions *options)
Definition: MQTTAsync.c:3480
int test2_onFailure_called
Definition: test45.c:591
void test2_onFailure(void *context, MQTTAsync_failureData5 *response)
Definition: test45.c:593
int MQTTProperties_getNumericValue(MQTTProperties *props, enum MQTTPropertyCodes propid)
void myassert(char *filename, int lineno, char *description, int value, char *format,...)
Definition: test45.c:246
MQTTASYNC_TRACE_LEVELS
Definition: MQTTAsync.h:1650
int test4(struct Options options)
Definition: test45.c:1034
static char msg_buf[512]
Definition: Log.c:122
void test3_onFailure(void *context, MQTTAsync_failureData5 *response)
Definition: test45.c:806
void test4_onSubscribe(void *context, MQTTAsync_successData5 *response)
Definition: test45.c:986
#define num_clients
int MQTTAsync_subscribe(MQTTAsync handle, const char *topic, int qos, MQTTAsync_responseOptions *response)
Definition: MQTTAsync.c:4121
volatile int test_finished
Definition: test45.c:332
#define MQTTASYNC_OPERATION_INCOMPLETE
Definition: MQTTAsync.h:163
struct Options options
void test4_onPublish(void *context, MQTTAsync_successData5 *response)
Definition: test45.c:897
#define LOGA_INFO
Definition: test45.c:118
#define MQTTAsync_willOptions_initializer
Definition: MQTTAsync.h:1014
void test7_onUnsubscribe5(void *context, MQTTAsync_successData5 *response)
Definition: test45.c:1367
constexpr size_t count()
Definition: core.h:960
void test3_onDisconnect(void *context, MQTTAsync_successData5 *response)
Definition: test45.c:695
char * test8_topic
Definition: test45.c:1765
void test7_onDisconnectFailure(void *context, MQTTAsync_failureData *response)
Definition: test45.c:1314
#define MQTTAsync_connectOptions_initializer5
Definition: MQTTAsync.h:1338
MQTTAsync_onFailure5 * onFailure5
Definition: MQTTAsync.h:1419
static int test7_just_connect
Definition: test45.c:1421
int MQTTAsync_getPendingTokens(MQTTAsync handle, MQTTAsync_token **tokens)
Definition: MQTTAsync.c:4737
const char * MQTTPropertyName(enum MQTTPropertyCodes value)
description
Definition: setup.py:19
#define MQTTAsync_disconnectOptions_initializer
Definition: MQTTAsync.h:1422
int message_count
Definition: test5.c:72
#define ARRAY_SIZE(a)
Definition: test45.c:40
MQTTAsync_onFailure5 * onFailure5
Definition: MQTTAsync.h:1327
#define MQTTVERSION_3_1_1
Definition: MQTTAsync.h:203
int test8_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
Definition: test45.c:1835
enum MQTTPropertyCodes identifier
int test3(struct Options options)
Definition: test45.c:825
int test4_packet_size
Definition: test45.c:980
#define START_TIME_TYPE
Definition: test45.c:186
void test7_onConnect5(void *context, MQTTAsync_successData5 *response)
Definition: test45.c:1447
int qos
Definition: test6.c:56
void usage(void)
Definition: test45.c:42
#define MQTTAsync_createOptions_initializer
Definition: MQTTAsync.h:965
MQTTAsync_onFailure * onFailure
Definition: MQTTAsync.h:1393
void test8_onDisconnectFailure(void *context, MQTTAsync_failureData5 *response)
Definition: test45.c:1790
void test3_onSubscribe(void *context, MQTTAsync_successData5 *response)
Definition: test45.c:771
MQTTAsync_token token
Definition: MQTTAsync.h:714
struct MQTTAsync_connectOptions::@55 binarypwd
char clientid[24]
Definition: test4.c:527
long elapsed(START_TIME_TYPE start_time)
Definition: test45.c:213
void test1_onSubscribe(void *context, MQTTAsync_successData5 *response)
Definition: test45.c:439
void test5_onConnectFailure(void *context, MQTTAsync_failureData5 *response)
Definition: test45.c:1096
void test7_onSubscribe5(void *context, MQTTAsync_successData5 *response)
Definition: test45.c:1401
void test4_onConnect(void *context, MQTTAsync_successData5 *response)
Definition: test45.c:1010
int MQTTAsync_token
Definition: MQTTAsync.h:249
MQTTAsync_onSuccess * onSuccess
Definition: MQTTAsync.h:696
int msg_count
Definition: test11.c:559
void test8_onSubscribe(void *context, MQTTAsync_successData5 *response)
Definition: test45.c:1809
MQTTAsync_willOptions * will
Definition: MQTTAsync.h:1214
int test8_messageCount
Definition: test45.c:1766
char * test_topic
Definition: test45.c:334
void * test4_payload
Definition: test45.c:894
int test4_payloadlen
Definition: test45.c:895
int index
Definition: test4.c:526
void test8_onPublish(void *context, MQTTAsync_successData5 *response)
Definition: test45.c:1770
MQTTProperties properties
Definition: MQTTAsync.h:1403
#define MQTTCLIENT_PERSISTENCE_DEFAULT
int MQTTAsync_isComplete(MQTTAsync handle, MQTTAsync_token dt)
Definition: MQTTAsync.c:4803
const char * name
int MQTTAsync_send(MQTTAsync handle, const char *destinationName, int payloadlen, const void *payload, int qos, int retained, MQTTAsync_responseOptions *response)
Definition: MQTTAsync.c:4230
MQTTProperty * array
int test7(struct Options options)
Definition: test45.c:1736
int test4_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
Definition: test45.c:904
void test8_onDisconnect(void *context, MQTTAsync_successData5 *response)
Definition: test45.c:1801
const char * message
Definition: MQTTAsync.h:538
MQTTProperties properties
Definition: MQTTAsync.h:730
START_TIME_TYPE global_start_time
Definition: test45.c:229
int test8(struct Options options)
Definition: test45.c:1851
int test5(struct Options options)
Definition: test45.c:1125
int tests
Definition: test45.c:226
void MQTTAsync_destroy(MQTTAsync *handle)
Definition: MQTTAsync.c:2554
const char * value
Definition: MQTTAsync.h:1150
#define LOGA_DEBUG
Definition: test45.c:117
#define MQTTVERSION_5
Definition: MQTTAsync.h:207
void test3_onConnect(void *context, MQTTAsync_successData5 *response)
Definition: test45.c:789
#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
void test6_onConnectFailure(void *context, MQTTAsync_failureData5 *response)
Definition: test45.c:1182
START_TIME_TYPE start_clock(void)
Definition: test45.c:188
int test3_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
Definition: test45.c:725
void trace_callback(enum MQTTASYNC_TRACE_LEVELS level, char *message)
Definition: test45.c:2037
dictionary context
Definition: test2.py:57
char * clientid
Definition: test6.c:54
void test6_onDisconnect5(void *context, MQTTAsync_successData5 *response)
Definition: test45.c:1209
null localtime_s(...)
Definition: chrono.h:286
void test7_onSubscribe(void *context, MQTTAsync_successData *response)
Definition: test45.c:1411
#define MQTTCLIENT_PERSISTENCE_NONE
int message_count
Definition: test4.c:529
void MyLog(int LOGA_level, char *format,...)
Definition: test45.c:122
char * test7_topic
Definition: test45.c:1310
enum MQTTReasonCodes reasonCode
Definition: MQTTAsync.h:532
#define MQTTASYNC_PERSISTENCE_ERROR
Definition: MQTTAsync.h:122
MQTTProperties * willProperties
Definition: MQTTAsync.h:1315
MQTTSubscribe_options subscribeOptions
Definition: MQTTAsync.h:734
void waitForNoPendingTokens(MQTTAsync c)
Definition: test45.c:307
void test1_onConnect(void *context, MQTTAsync_successData5 *response)
Definition: test45.c:473
int test7_messageCount
Definition: test45.c:1311
int test1_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
Definition: test45.c:372
void test7_onDisconnect5(void *context, MQTTAsync_successData5 *response)
Definition: test45.c:1344
MQTTAsync_onSuccess5 * onSuccess5
Definition: MQTTAsync.h:1413
void test1_onDisconnect(void *context, MQTTAsync_successData *response)
Definition: test45.c:337
void write_test_result(void)
Definition: test45.c:233
int test1(struct Options options)
Definition: test45.c:512
char *const * serverURIs
Definition: MQTTAsync.h:1277
enum MQTTReasonCodes reasonCode
Definition: MQTTAsync.h:1407
MQTTAsync c
Definition: test4.c:525
void getopts(int argc, char **argv)
Definition: test45.c:66
#define MQTTAsync_message_initializer
Definition: MQTTAsync.h:319
MQTTAsync c
Definition: test4.c:1005
MQTTProperty property
Definition: paho_c_pub.c:53
enum MQTTReasonCodes rc
Definition: test10.c:1112
MQTTAsync_onSuccess * onSuccess
Definition: MQTTAsync.h:1249
#define MQTTAsync_callOptions_initializer
Definition: MQTTAsync.h:750
MQTTAsync_onSuccess5 * onSuccess5
Definition: MQTTAsync.h:1321
int test_no
Definition: test1.c:54
void test8_onPublishFailure(void *context, MQTTAsync_failureData5 *response)
Definition: test45.c:1778
int test2(struct Options options)
Definition: test45.c:617
FILE * xml
Definition: test45.c:228
MQTTAsync_onSuccess * onSuccess
Definition: MQTTAsync.h:1387
int MQTTAsync_waitForCompletion(MQTTAsync handle, MQTTAsync_token dt, unsigned long timeout)
Definition: MQTTAsync.c:4848
MQTTProperties * connectProperties
Definition: MQTTAsync.h:1311
#define min(a, b)
Definition: test45.c:983
#define MQTTProperties_initializer


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