test11.c
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright (c) 2009, 2018 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 #if 0
117 #include <logaX.h> /* For general log messages */
118 #define MyLog logaLine
119 #else
120 #define LOGA_DEBUG 0
121 #define LOGA_INFO 1
122 #include <stdarg.h>
123 #include <time.h>
124 #include <sys/timeb.h>
125 void MyLog(int LOGA_level, char* format, ...)
126 {
127  static char msg_buf[256];
128  va_list args;
129 #if defined(_WIN32) || defined(_WINDOWS)
130  struct timeb ts;
131 #else
132  struct timeval ts;
133 #endif
134  struct tm *timeinfo;
135 
136  if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
137  return;
138 
139 #if defined(_WIN32) || defined(_WINDOWS)
140  ftime(&ts);
141  timeinfo = localtime(&ts.time);
142 #else
143  gettimeofday(&ts, NULL);
144  timeinfo = localtime(&ts.tv_sec);
145 #endif
146  strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo);
147 
148 #if defined(_WIN32) || defined(_WINDOWS)
149  sprintf(&msg_buf[strlen(msg_buf)], ".%.3hu ", ts.millitm);
150 #else
151  sprintf(&msg_buf[strlen(msg_buf)], ".%.3lu ", ts.tv_usec / 1000);
152 #endif
153 
154  va_start(args, format);
155  vsnprintf(&msg_buf[strlen(msg_buf)], sizeof(msg_buf) - strlen(msg_buf), format, args);
156  va_end(args);
157 
158  printf("%s\n", msg_buf);
159  fflush(stdout);
160 }
161 #endif
162 
163 
164 #if defined(_WIN32) || defined(_WINDOWS)
165 #define mqsleep(A) Sleep(1000*A)
166 #define START_TIME_TYPE DWORD
167 static DWORD start_time = 0;
169 {
170  return GetTickCount();
171 }
172 #elif defined(AIX)
173 #define mqsleep sleep
174 #define START_TIME_TYPE struct timespec
176 {
177  static struct timespec start;
178  clock_gettime(CLOCK_REALTIME, &start);
179  return start;
180 }
181 #else
182 #define mqsleep sleep
183 #define START_TIME_TYPE struct timeval
184 /* TODO - unused - remove? static struct timeval start_time; */
186 {
187  struct timeval start_time;
188  gettimeofday(&start_time, NULL);
189  return start_time;
190 }
191 #endif
192 
193 
194 #if defined(_WIN32)
195 long elapsed(START_TIME_TYPE start_time)
196 {
197  return GetTickCount() - start_time;
198 }
199 #elif defined(AIX)
200 #define assert(a)
201 long elapsed(struct timespec start)
202 {
203  struct timespec now, res;
204 
205  clock_gettime(CLOCK_REALTIME, &now);
206  ntimersub(now, start, res);
207  return (res.tv_sec)*1000L + (res.tv_nsec)/1000000L;
208 }
209 #else
210 long elapsed(START_TIME_TYPE start_time)
211 {
212  struct timeval now, res;
213 
214  gettimeofday(&now, NULL);
215  timersub(&now, &start_time, &res);
216  return (res.tv_sec)*1000 + (res.tv_usec)/1000;
217 }
218 #endif
219 
220 #define assert(a, b, c, d) myassert(__FILE__, __LINE__, a, b, c, d)
221 #define assert1(a, b, c, d, e) myassert(__FILE__, __LINE__, a, b, c, d, e)
222 
223 int tests = 0;
224 int failures = 0;
225 FILE* xml;
227 char output[3000];
229 
231 {
232  long duration = elapsed(global_start_time);
233 
234  fprintf(xml, " time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000);
235  if (cur_output != output)
236  {
237  fprintf(xml, "%s", output);
238  cur_output = output;
239  }
240  fprintf(xml, "</testcase>\n");
241 }
242 
243 void myassert(char* filename, int lineno, char* description, int value, char* format, ...)
244 {
245  ++tests;
246  if (!value)
247  {
248  va_list args;
249 
250  ++failures;
251  printf("Assertion failed, file %s, line %d, description: %s\n", filename, lineno, description);
252 
253  va_start(args, format);
254  vprintf(format, args);
255  va_end(args);
256 
257  cur_output += sprintf(cur_output, "<failure type=\"%s\">file %s, line %d </failure>\n",
258  description, filename, lineno);
259  }
260  else
261  MyLog(LOGA_DEBUG, "Assertion succeeded, file %s, line %d, description: %s", filename, lineno, description);
262 }
263 
264 
266 {
267  int i = 0;
268 
269  for (i = 0; i < props->count; ++i)
270  {
271  int id = props->array[i].identifier;
272  const char* name = MQTTPropertyName(id);
273  char* intformat = "Property name %s value %d";
274 
275  switch (MQTTProperty_getType(id))
276  {
278  MyLog(LOGA_DEBUG, intformat, name, props->array[i].value.byte);
279  break;
281  MyLog(LOGA_DEBUG, intformat, name, props->array[i].value.integer2);
282  break;
284  MyLog(LOGA_DEBUG, intformat, name, props->array[i].value.integer4);
285  break;
287  MyLog(LOGA_DEBUG, intformat, name, props->array[i].value.integer4);
288  break;
291  MyLog(LOGA_DEBUG, "Property name %s value len %.*s", name,
292  props->array[i].value.data.len, props->array[i].value.data.data);
293  break;
295  MyLog(LOGA_DEBUG, "Property name %s key %.*s value %.*s", name,
296  props->array[i].value.data.len, props->array[i].value.data.data,
297  props->array[i].value.value.len, props->array[i].value.value.data);
298  break;
299  }
300  }
301 }
302 
303 
304 struct
305 {
307  char* test_topic;
310 {
311  0, "client topic aliases topic", 0
312 };
313 
314 
316 {
317  MQTTAsync c = (MQTTAsync)context;
318  MyLog(LOGA_DEBUG, "In onDisconnect callback %p", c);
319  test_client_topic_aliases_globals.test_finished = 1;
320 }
321 
322 
323 int test_client_topic_aliases_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
324 {
325  MQTTAsync c = (MQTTAsync)context;
326  static int received = 0;
327 
328  received++;
329  assert("Message structure version should be 1", message->struct_version == 1,
330  "message->struct_version was %d", message->struct_version);
331  if (message->struct_version == 1)
332  {
333  const int props_count = 0;
334 
336  "topic alias is %d\n", MQTTProperties_hasProperty(&message->properties, MQTTPROPERTY_CODE_TOPIC_ALIAS));
337 
338  assert("Topic should be name", strcmp(topicName, test_client_topic_aliases_globals.test_topic) == 0,
339  "Topic name was %s\n", topicName);
340 
341  logProperties(&message->properties);
342  }
343 
344  if (received == 2)
345  test_client_topic_aliases_globals.test_finished = 1;
346 
347  MQTTAsync_freeMessage(&message);
348  MQTTAsync_free(topicName);
349 
350  return 1;
351 }
352 
353 
355 {
356  MQTTAsync c = (MQTTAsync)context;
360  int rc;
361 
362  MyLog(LOGA_DEBUG, "Suback properties:");
363  logProperties(&response->properties);
364 
365  pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
366  pubmsg.payloadlen = 11;
367  pubmsg.retained = 0;
368  pubmsg.qos = 1;
369 
370  /* first set the topic alias */
371  property.identifier = MQTTPROPERTY_CODE_TOPIC_ALIAS;
372  property.value.integer2 = 1;
373  MQTTProperties_add(&pubmsg.properties, &property);
374 
375  rc = MQTTAsync_sendMessage(c, test_client_topic_aliases_globals.test_topic, &pubmsg, &opts);
376  assert("Good rc from send", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
377  if (rc != MQTTASYNC_SUCCESS)
378  test_client_topic_aliases_globals.test_finished = 1;
379  else
380  {
381  /* now send the publish with topic alias only */
382  rc = MQTTAsync_sendMessage(c, "", &pubmsg, &opts);
383  assert("Good rc from send", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
384  if (rc != MQTTASYNC_SUCCESS)
385  test_client_topic_aliases_globals.test_finished = 1;
386  }
388 }
389 
390 
392 {
393  MQTTAsync c = (MQTTAsync)context;
394  MyLog(LOGA_DEBUG, "Callback: disconnected, reason code \"%s\"", MQTTReasonCode_toString(rc));
395  logProperties(props);
396  test_client_topic_aliases_globals.disconnected = 1;
397 }
398 
399 
401 {
402  MQTTAsync c = (MQTTAsync)context;
406  int rc;
407  static int first = 1;
408 
409  MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
410 
411  assert("Reason code should be 0", response->reasonCode == MQTTREASONCODE_SUCCESS,
412  "Reason code was %d\n", response->reasonCode);
413 
414  MyLog(LOGA_DEBUG, "Connack properties:");
415  logProperties(&response->properties);
416 
417  if (first)
418  {
419  first = 0;
420  pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
421  pubmsg.payloadlen = 11;
422  pubmsg.qos = 1;
423  pubmsg.retained = 0;
424 
425  /* a Topic Alias of 0 is not allowed, so we should be disconnected */
426  property.identifier = MQTTPROPERTY_CODE_TOPIC_ALIAS;
427  property.value.integer2 = 0;
428  MQTTProperties_add(&pubmsg.properties, &property);
429 
430  rc = MQTTAsync_sendMessage(c, test_client_topic_aliases_globals.test_topic, &pubmsg, &opts);
431  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
432  if (rc != MQTTASYNC_SUCCESS)
433  test_client_topic_aliases_globals.test_finished = 1;
435  }
436  else
437  {
439  opts.context = c;
440  rc = MQTTAsync_subscribe(c, test_client_topic_aliases_globals.test_topic, 2, &opts);
441  assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
442  if (rc != MQTTASYNC_SUCCESS)
443  test_client_topic_aliases_globals.test_finished = 1;
444 
445  }
446 }
447 
448 
449 /*********************************************************************
450 
451 Test1: client topic aliases
452 
453 *********************************************************************/
455 {
456  int subsqos = 2;
457  MQTTAsync c;
463  int rc = 0;
464  char* test_topic = "V5 C client test client topic aliases";
466 
467  MyLog(LOGA_INFO, "Starting V5 test 1 - client topic aliases");
468  fprintf(xml, "<testcase classname=\"test11\" name=\"client topic aliases\"");
470 
471  createOpts.MQTTVersion = MQTTVERSION_5;
472  rc = MQTTAsync_createWithOptions(&c, options.connection, "async_test_aliases",
473  MQTTCLIENT_PERSISTENCE_DEFAULT, NULL, &createOpts);
474  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
475  if (rc != MQTTASYNC_SUCCESS)
476  {
477  MQTTAsync_destroy(&c);
478  goto exit;
479  }
480 
482  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
483 
485 
486  opts.keepAliveInterval = 20;
487  opts.username = "testuser";
488  opts.password = "testpassword";
489  opts.MQTTVersion = options.MQTTVersion;
490  opts.cleanstart = 1;
491 
492  opts.will = &wopts;
493  opts.will->message = "will message";
494  opts.will->qos = 1;
495  opts.will->retained = 0;
496  opts.will->topicName = "will topic";
497  opts.will = NULL;
499  opts.onFailure5 = NULL;
500  opts.context = c;
501 
502  property.identifier = MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL;
503  property.value.integer4 = 30;
504  MQTTProperties_add(&props, &property);
505 
506  property.identifier = MQTTPROPERTY_CODE_USER_PROPERTY;
507  property.value.data.data = "test user property";
508  property.value.data.len = (int)strlen(property.value.data.data);
509  property.value.value.data = "test user property value";
510  property.value.value.len = (int)strlen(property.value.value.data);
511  MQTTProperties_add(&props, &property);
512 
513  opts.connectProperties = &props;
514  opts.willProperties = &willProps;
515 
516  MyLog(LOGA_DEBUG, "Connecting");
517  rc = MQTTAsync_connect(c, &opts);
518  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
519  if (rc != MQTTASYNC_SUCCESS)
520  goto exit;
521 
522  while (test_client_topic_aliases_globals.disconnected == 0)
523  #if defined(_WIN32)
524  Sleep(100);
525  #else
526  usleep(10000L);
527  #endif
528 
529  /* Now try a valid topic alias */
530  rc = MQTTAsync_connect(c, &opts);
531  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
532  if (rc != MQTTASYNC_SUCCESS)
533  goto exit;
534 
535  while (test_client_topic_aliases_globals.test_finished == 0)
536  #if defined(_WIN32)
537  Sleep(100);
538  #else
539  usleep(10000L);
540  #endif
541 
542  MQTTProperties_free(&props);
543  MQTTProperties_free(&willProps);
544  MQTTAsync_destroy(&c);
545 
546 exit:
547  MyLog(LOGA_INFO, "TEST1: test %s. %d tests run, %d failures.",
548  (failures == 0) ? "passed" : "failed", tests, failures);
550  return failures;
551 }
552 
553 
554 struct
555 {
556  char* test_topic;
557  int test_finished;
561 {
562  "server topic aliases topic", 0, 0, 3
563 };
564 
565 
566 int test_server_topic_aliases_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
567 {
568  MQTTAsync c = (MQTTAsync)context;
569  static int received = 0;
570  static int first_topic_alias = 0;
571  int topicAlias = 0;
572 
573  received++;
574  assert("Message structure version should be 1", message->struct_version == 1,
575  "message->struct_version was %d", message->struct_version);
576  if (message->struct_version == 1)
577  {
578  const int props_count = 0;
579 
582 
583  if (received == 1)
584  {
585  first_topic_alias = topicAlias;
586  assert("Topic should be name", strcmp(topicName, test_server_topic_aliases_globals.test_topic) == 0,
587  "Topic name was %s\n", topicName);
588  }
589  else
590  {
591  assert("All topic aliases should be the same", topicAlias == first_topic_alias,
592  "Topic alias was %d\n", topicAlias);
593  assert("Topic should be 0 length", strcmp(topicName, "") == 0,
594  "Topic name was %s\n", topicName);
595  }
596 
597  assert("topicAlias should not be 0", topicAlias > 0, "Topic alias was %d\n", topicAlias);
598  logProperties(&message->properties);
599  }
600  test_server_topic_aliases_globals.messages_arrived++;
601 
603  test_server_topic_aliases_globals.test_finished = 1;
604 
605  MQTTAsync_freeMessage(&message);
606  MQTTAsync_free(topicName);
607 
608  return 1;
609 }
610 
611 
613 {
614  MQTTAsync c = (MQTTAsync)context;
617  int qos = 0, rc;
618 
619  MyLog(LOGA_DEBUG, "Suback properties:");
620  logProperties(&response->properties);
621 
622  test_server_topic_aliases_globals.messages_arrived = 0;
623  pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
624  pubmsg.payloadlen = 11;
625  pubmsg.retained = 0;
626  for (qos = 0; qos < test_server_topic_aliases_globals.msg_count; ++qos)
627  {
628  pubmsg.qos = qos;
629  rc = MQTTAsync_sendMessage(c, test_server_topic_aliases_globals.test_topic, &pubmsg, &opts);
630  assert("Good rc from send", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
631  if (rc != MQTTASYNC_SUCCESS)
632  {
633  test_server_topic_aliases_globals.test_finished = 1;
634  break;
635  }
636  }
637 }
638 
639 
641 {
642  MQTTAsync c = (MQTTAsync)context;
644  int rc;
645 
646  MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
647 
648  assert("Reason code should be 0", response->reasonCode == MQTTREASONCODE_SUCCESS,
649  "Reason code was %d\n", response->reasonCode);
650 
651  MyLog(LOGA_DEBUG, "Connack properties:");
652  logProperties(&response->properties);
653 
655  opts.context = c;
656  rc = MQTTAsync_subscribe(c, test_server_topic_aliases_globals.test_topic, 2, &opts);
657  assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
658  if (rc != MQTTASYNC_SUCCESS)
659  test_server_topic_aliases_globals.test_finished = 1;
660 }
661 
662 
663 /*********************************************************************
664 
665 Test2: server topic aliases
666 
667 *********************************************************************/
669 {
670  int subsqos = 2;
671  MQTTAsync c;
676  int rc = 0;
677  char* test_topic = "V5 C client test server topic aliases";
679 
680  MyLog(LOGA_INFO, "Starting V5 test 2 - server topic aliases");
681  fprintf(xml, "<testcase classname=\"test11\" name=\"server topic aliases\"");
683 
684  createOpts.MQTTVersion = MQTTVERSION_5;
685  rc = MQTTAsync_createWithOptions(&c, options.connection, "server_topic_aliases",
686  MQTTCLIENT_PERSISTENCE_DEFAULT, NULL, &createOpts);
687  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
688  if (rc != MQTTASYNC_SUCCESS)
689  {
690  MQTTAsync_destroy(&c);
691  goto exit;
692  }
693 
695  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
696 
697  /* Allow at least one server topic alias */
698  property.identifier = MQTTPROPERTY_CODE_TOPIC_ALIAS_MAXIMUM;
699  property.value.integer2 = 1;
700  MQTTProperties_add(&connect_props, &property);
701 
702  opts.MQTTVersion = options.MQTTVersion;
704  opts.context = c;
705  opts.connectProperties = &connect_props;
706 
707  MyLog(LOGA_DEBUG, "Connecting");
708  rc = MQTTAsync_connect(c, &opts);
709  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
710  if (rc != MQTTASYNC_SUCCESS)
711  goto exit;
712 
713  while (test_server_topic_aliases_globals.test_finished == 0)
714  #if defined(_WIN32)
715  Sleep(100);
716  #else
717  usleep(10000L);
718  #endif
719 
720  MQTTProperties_free(&connect_props);
721  MQTTAsync_destroy(&c);
722 
723 exit:
724  MyLog(LOGA_INFO, "TEST2: test %s. %d tests run, %d failures.",
725  (failures == 0) ? "passed" : "failed", tests, failures);
727  return failures;
728 }
729 
730 
731 
732 /*********************************************************************
733 
734 Test3: subscription ids
735 
736 *********************************************************************/
737 
738 struct
739 {
740  char* test_topic;
741  int test_finished;
742  int messages_arrived;
744 {
745  "server subscription ids topic", 0, 0
746 };
747 
748 
749 int test_subscription_ids_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
750 {
751  MQTTAsync c = (MQTTAsync)context;
752 
753  test_subscription_ids_globals.messages_arrived++;
754 
755  assert("Message structure version should be 1", message->struct_version == 1,
756  "message->struct_version was %d", message->struct_version);
757  MyLog(LOGA_DEBUG, "Callback: message received on topic %s is %.*s.",
758  topicName, message->payloadlen, (char*)(message->payload));
759 
760  if (message->struct_version == 1)
761  {
762  int subsidcount = 0, i = 0;
763 
765 
766  for (i = 0; i < subsidcount; ++i)
767  {
769  assert("Subsid is i+1", subsid == i+1, "subsid is not correct %d\n", subsid);
770  }
771  logProperties(&message->properties);
772  }
773 
774  test_subscription_ids_globals.test_finished = 1;
775 
776  MQTTAsync_freeMessage(&message);
777  MQTTAsync_free(topicName);
778 
779  return 1;
780 }
781 
782 
784 {
785  MQTTAsync c = (MQTTAsync)context;
789  int rc;
790  static int subs_count = 0;
791 
792  MyLog(LOGA_DEBUG, "Suback properties:");
793  logProperties(&response->properties);
794 
795  if (++subs_count == 1)
796  {
797  /* subscribe to a wildcard */
798  property.identifier = MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIER;
799  property.value.integer4 = 2;
800  MQTTProperties_add(&opts.properties, &property);
801 
803  opts.context = c;
804 
805  rc = MQTTAsync_subscribe(c, "+", 2, &opts);
806  assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
807  if (rc != MQTTASYNC_SUCCESS)
808  test_subscription_ids_globals.test_finished = 1;
809 
811  }
812  else
813  {
814  test_subscription_ids_globals.messages_arrived = 0;
815  pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
816  pubmsg.payloadlen = 11;
817  pubmsg.retained = 0;
818  pubmsg.qos = 1;
819  rc = MQTTAsync_sendMessage(c, test_subscription_ids_globals.test_topic, &pubmsg, &opts);
820  assert("Good rc from send", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
821  if (rc != MQTTASYNC_SUCCESS)
822  test_subscription_ids_globals.test_finished = 1;
823  }
824 }
825 
826 
828 {
829  MQTTAsync c = (MQTTAsync)context;
832  int rc;
833 
834  MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
835 
836  assert("Reason code should be 0", response->reasonCode == MQTTREASONCODE_SUCCESS,
837  "Reason code was %d\n", response->reasonCode);
838 
839  MyLog(LOGA_DEBUG, "Connack properties:");
840  logProperties(&response->properties);
841 
843  opts.context = c;
844  /* subscribe to the test topic */
845  property.identifier = MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIER;
846  property.value.integer4 = 1;
847  MQTTProperties_add(&opts.properties, &property);
848 
849  rc = MQTTAsync_subscribe(c, test_subscription_ids_globals.test_topic, 2, &opts);
850  assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
851  if (rc != MQTTASYNC_SUCCESS)
852  test_subscription_ids_globals.test_finished = 1;
853 
855 }
856 
857 
859 {
860  MQTTAsync c;
863  int rc = 0;
864 
865  MyLog(LOGA_INFO, "Starting V5 test 3 - subscription ids");
866  fprintf(xml, "<testcase classname=\"test11\" name=\"subscription ids\"");
868 
869  createOpts.MQTTVersion = MQTTVERSION_5;
870  rc = MQTTAsync_createWithOptions(&c, options.connection, "subscription_ids",
871  MQTTCLIENT_PERSISTENCE_DEFAULT, NULL, &createOpts);
872  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
873  if (rc != MQTTASYNC_SUCCESS)
874  {
875  MQTTAsync_destroy(&c);
876  goto exit;
877  }
878 
880  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
881 
882  opts.MQTTVersion = options.MQTTVersion;
884  opts.context = c;
885  opts.cleanstart = 1;
886 
887  MyLog(LOGA_DEBUG, "Connecting");
888  rc = MQTTAsync_connect(c, &opts);
889  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
890  if (rc != MQTTASYNC_SUCCESS)
891  goto exit;
892 
893  while (test_subscription_ids_globals.test_finished == 0)
894  #if defined(_WIN32)
895  Sleep(100);
896  #else
897  usleep(10000L);
898  #endif
899 
900  MQTTAsync_destroy(&c);
901 
902 exit:
903  MyLog(LOGA_INFO, "TEST3: test %s. %d tests run, %d failures.",
904  (failures == 0) ? "passed" : "failed", tests, failures);
906  return failures;
907 }
908 
909 /*********************************************************************
910 
911 Test: flow control
912 
913 *********************************************************************/
914 
915 struct
916 {
917  char * test_topic;
918  int test_finished;
919  int messages_arrived;
923 {
924  "flow control topic", 0, 0, 65535, 0
925 };
926 
927 
928 int test_flow_control_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
929 {
930  MQTTAsync c = (MQTTAsync)context;
931 
932  test_flow_control_globals.messages_arrived++;
933 
934  assert("Message structure version should be 1", message->struct_version == 1,
935  "message->struct_version was %d", message->struct_version);
936  MyLog(LOGA_DEBUG, "Callback: message received on topic %s is %.*s.",
937  topicName, message->payloadlen, (char*)(message->payload));
938 
939  if (message->struct_version == 1)
940  logProperties(&message->properties);
941 
942  if (test_flow_control_globals.messages_arrived == test_flow_control_globals.receive_maximum + 2)
943  test_flow_control_globals.test_finished = 1;
944 
945  MQTTAsync_freeMessage(&message);
946  MQTTAsync_free(topicName);
947 
948  return 1;
949 }
950 
951 
953 {
954  MQTTAsync c = (MQTTAsync)context;
957  int rc;
958  int i = 0;
959 
960  MyLog(LOGA_DEBUG, "Suback properties:");
961  logProperties(&response->properties);
962 
963  test_flow_control_globals.messages_arrived = 0;
964  pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
965  pubmsg.payloadlen = 11;
966  pubmsg.retained = 0;
967  pubmsg.qos = 2;
968 
969  for (i = 0; i < test_flow_control_globals.receive_maximum + 2; ++i)
970  {
971  rc = MQTTAsync_sendMessage(c, test_flow_control_globals.test_topic, &pubmsg, &opts);
972  assert("Good rc from send", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
973  if (rc != MQTTASYNC_SUCCESS)
974  test_flow_control_globals.test_finished = 1;
975  }
976 }
977 
978 
980 {
981  MQTTAsync c = (MQTTAsync)context;
983  int rc;
984 
985  MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
986 
987  assert("Reason code should be 0", response->reasonCode == MQTTREASONCODE_SUCCESS,
988  "Reason code was %d\n", response->reasonCode);
989 
990  MyLog(LOGA_DEBUG, "Connack properties:");
991  logProperties(&response->properties);
992 
995 
997  opts.context = c;
998 
999  rc = MQTTAsync_subscribe(c, test_flow_control_globals.test_topic, 2, &opts);
1000  assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1001  if (rc != MQTTASYNC_SUCCESS)
1002  test_flow_control_globals.test_finished = 1;
1003 
1005 }
1006 
1007 
1009 {
1010  static char* msg = "Blocking on server receive maximum";
1011 
1012  if (strstr(message, msg) != NULL)
1013  test_flow_control_globals.blocking_found = 1;
1014 }
1015 
1016 
1018 {
1019  MQTTAsync c;
1022  int rc = 0;
1023 
1024  MyLog(LOGA_INFO, "Starting V5 test - flow control");
1025  fprintf(xml, "<testcase classname=\"test11\" name=\"flow control\"");
1027 
1028  createOpts.MQTTVersion = MQTTVERSION_5;
1029  rc = MQTTAsync_createWithOptions(&c, options.connection, "flow_control",
1030  MQTTCLIENT_PERSISTENCE_DEFAULT, NULL, &createOpts);
1031  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
1032  if (rc != MQTTASYNC_SUCCESS)
1033  {
1034  MQTTAsync_destroy(&c);
1035  goto exit;
1036  }
1037 
1040 
1042  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1043 
1044  opts.MQTTVersion = options.MQTTVersion;
1046  opts.context = c;
1047  opts.cleanstart = 1;
1048 
1049  MyLog(LOGA_DEBUG, "Connecting");
1050  rc = MQTTAsync_connect(c, &opts);
1051  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1052  if (rc != MQTTASYNC_SUCCESS)
1053  goto exit;
1054 
1055  while (test_flow_control_globals.test_finished == 0)
1056  #if defined(_WIN32)
1057  Sleep(100);
1058  #else
1059  usleep(10000L);
1060  #endif
1061 
1062  assert("should have blocked", test_flow_control_globals.blocking_found == 1, "was %d\n",
1063  test_flow_control_globals.blocking_found);
1064 
1065  MQTTAsync_destroy(&c);
1066 
1067 exit:
1068  MyLog(LOGA_INFO, "TEST4: test %s. %d tests run, %d failures.",
1069  (failures == 0) ? "passed" : "failed", tests, failures);
1071  return failures;
1072 }
1073 
1074 struct
1075 {
1076  char* test_topic;
1077  int test_finished;
1078  int messages_arrived;
1080 {
1081  "error reporting topic", 0, 0
1082 };
1083 
1084 
1086 {
1087  MQTTAsync c = (MQTTAsync)context;
1089  int i = 0;
1090 
1091  MyLog(LOGA_DEBUG, "Unsuback properties:");
1092  logProperties(&response->properties);
1093 
1094  assert("Reason code count should be 2", response->alt.unsub.reasonCodeCount == 2,
1095  "Reason code count was %d\n", response->alt.unsub.reasonCodeCount);
1096 
1097  if (response->alt.unsub.reasonCodeCount == 1)
1098  MyLog(LOGA_DEBUG, "reason code %d", response->reasonCode);
1099  else if (response->alt.unsub.reasonCodeCount > 1)
1100  {
1101  for (i = 0; i < response->alt.unsub.reasonCodeCount; ++i)
1102  {
1103  MyLog(LOGA_DEBUG, "Unsubscribe reason code %d", response->alt.unsub.reasonCodes[i]);
1104  }
1105  }
1106 
1107  test_error_reporting_globals.test_finished = 1;
1108 }
1109 
1110 
1112 {
1113  MQTTAsync c = (MQTTAsync)context;
1116  char* topics[2] = {test_error_reporting_globals.test_topic, "+"};
1117  int rc;
1118  int i = 0;
1119 
1120  MyLog(LOGA_DEBUG, "Suback properties:");
1121  logProperties(&response->properties);
1122 
1123  assert("Reason code count should be 2", response->alt.sub.reasonCodeCount == 2,
1124  "Reason code count was %d\n", response->alt.sub.reasonCodeCount);
1125 
1126  if (response->alt.sub.reasonCodeCount == 1)
1127  MyLog(LOGA_DEBUG, "reason code %d", response->reasonCode);
1128  else if (response->alt.sub.reasonCodeCount > 1)
1129  {
1130  for (i = 0; i < response->alt.sub.reasonCodeCount; ++i)
1131  {
1132  MyLog(LOGA_DEBUG, "Subscribe reason code %d", response->alt.sub.reasonCodes[i]);
1133  }
1134  }
1135 
1137  opts.context = c;
1138 
1139  property.identifier = MQTTPROPERTY_CODE_USER_PROPERTY;
1140  property.value.data.data = "test user property";
1141  property.value.data.len = (int)strlen(property.value.data.data);
1142  property.value.value.data = "test user property value";
1143  property.value.value.len = (int)strlen(property.value.value.data);
1144  MQTTProperties_add(&opts.properties, &property);
1145 
1146  rc = MQTTAsync_unsubscribeMany(c, 2, topics, &opts);
1147  assert("Good rc from unsubscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1148  if (rc != MQTTASYNC_SUCCESS)
1149  test_flow_control_globals.test_finished = 1;
1150 
1152 }
1153 
1155 {
1156  MQTTAsync c = (MQTTAsync)context;
1158  int rc;
1159  char* topics[2] = {test_error_reporting_globals.test_topic, "+"};
1160  int qoss[2] = {2, 2};
1163 
1164  MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
1165 
1166  assert("Reason code should be 0", response->reasonCode == MQTTREASONCODE_SUCCESS,
1167  "Reason code was %d\n", response->reasonCode);
1168 
1169  MyLog(LOGA_DEBUG, "Connack properties:");
1170  logProperties(&response->properties);
1171 
1173  opts.context = c;
1174 
1175  property.identifier = MQTTPROPERTY_CODE_USER_PROPERTY;
1176  property.value.data.data = "test user property";
1177  property.value.data.len = (int)strlen(property.value.data.data);
1178  property.value.value.data = "test user property value";
1179  property.value.value.len = (int)strlen(property.value.value.data);
1180  MQTTProperties_add(&opts.properties, &property);
1181 
1182  opts.subscribeOptionsCount = 2;
1183  opts.subscribeOptionsList = subopts;
1184 
1185  rc = MQTTAsync_subscribeMany(c, 2, topics, qoss, &opts);
1186  assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1187  if (rc != MQTTASYNC_SUCCESS)
1188  test_flow_control_globals.test_finished = 1;
1189 
1191 }
1192 
1193 
1195 {
1196  MQTTAsync c;
1199  int rc = 0;
1200 
1201  MyLog(LOGA_INFO, "Starting V5 test - error reporting");
1202  fprintf(xml, "<testcase classname=\"test11\" name=\"error reporting\"");
1204 
1205  createOpts.MQTTVersion = MQTTVERSION_5;
1206  rc = MQTTAsync_createWithOptions(&c, options.connection, "error reporting",
1207  MQTTCLIENT_PERSISTENCE_DEFAULT, NULL, &createOpts);
1208  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
1209  if (rc != MQTTASYNC_SUCCESS)
1210  {
1211  MQTTAsync_destroy(&c);
1212  goto exit;
1213  }
1214 
1216  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1217 
1218  opts.MQTTVersion = options.MQTTVersion;
1220  opts.context = c;
1221  opts.cleanstart = 1;
1222 
1223  MyLog(LOGA_DEBUG, "Connecting");
1224  rc = MQTTAsync_connect(c, &opts);
1225  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1226  if (rc != MQTTASYNC_SUCCESS)
1227  goto exit;
1228 
1229  while (test_error_reporting_globals.test_finished == 0)
1230  #if defined(_WIN32)
1231  Sleep(100);
1232  #else
1233  usleep(10000L);
1234  #endif
1235 
1236  MQTTAsync_destroy(&c);
1237 
1238 exit:
1239  MyLog(LOGA_INFO, "TEST5: test %s. %d tests run, %d failures.",
1240  (failures == 0) ? "passed" : "failed", tests, failures);
1242  return failures;
1243 }
1244 
1245 
1246 struct
1247 {
1248  int test_finished;
1249  char* test_topic;
1251 {
1252  0, "test_qos_1_2_errors"
1253 };
1254 
1255 
1257 {
1258  MQTTAsync c = (MQTTAsync)context;
1259  MyLog(LOGA_DEBUG, "Callback: publish success, reason code \"%s\" msgid: %d",
1260  MQTTReasonCode_toString(response->reasonCode), response->token);
1261 
1262  logProperties(&response->properties);
1263 
1264  test_qos_1_2_errors_globals.test_finished = 1;
1265 }
1266 
1267 
1269 {
1270  MQTTAsync c = (MQTTAsync)context;
1272 
1273  MyLog(LOGA_DEBUG, "Callback: publish failure, reason code \"%s\" msgid: %d packet type: %d",
1274  MQTTReasonCode_toString(response->reasonCode), response->token, response->packet_type);
1275 
1276  logProperties(&response->properties);
1277 
1278  test_qos_1_2_errors_globals.test_finished = 1;
1279 }
1280 
1281 
1283 {
1284  MQTTAsync c = (MQTTAsync)context;
1288  int rc;
1289 
1290  MyLog(LOGA_DEBUG, "Callback: publish failure, reason code \"%s\" msgid: %d packet type: %d",
1291  MQTTReasonCode_toString(response->reasonCode), response->token, response->packet_type);
1292 
1293  logProperties(&response->properties);
1294 
1297  opts.context = c;
1298 
1299  pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
1300  pubmsg.payloadlen = 11;
1301  pubmsg.qos = 2;
1302  pubmsg.retained = 0;
1303 
1304  property.identifier = MQTTPROPERTY_CODE_USER_PROPERTY;
1305  property.value.data.data = "pub user property";
1306  property.value.data.len = (int)strlen(property.value.data.data);
1307  property.value.value.data = "pub user property value";
1308  property.value.value.len = (int)strlen(property.value.value.data);
1309  MQTTProperties_add(&pubmsg.properties, &property);
1310 
1311  rc = MQTTAsync_sendMessage(c, "test_qos_1_2_errors_pubcomp", &pubmsg, &opts);
1312  assert("Good rc from publish", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1313  if (rc != MQTTREASONCODE_SUCCESS)
1314  test_qos_1_2_errors_globals.test_finished = 1;
1315 
1317 }
1318 
1319 
1321 {
1322  MQTTAsync c = (MQTTAsync)context;
1326  int rc;
1327 
1328  MyLog(LOGA_DEBUG, "Callback: publish failure, reason code \"%s\" msgid: %d packet type: %d",
1329  MQTTReasonCode_toString(response->reasonCode), response->token, response->packet_type);
1330 
1331  logProperties(&response->properties);
1332 
1335  opts.context = c;
1336 
1337  pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
1338  pubmsg.payloadlen = 11;
1339  pubmsg.qos = 2;
1340  pubmsg.retained = 0;
1341 
1342  property.identifier = MQTTPROPERTY_CODE_USER_PROPERTY;
1343  property.value.data.data = "pub user property";
1344  property.value.data.len = (int)strlen(property.value.data.data);
1345  property.value.value.data = "pub user property value";
1346  property.value.value.len = (int)strlen(property.value.value.data);
1347  MQTTProperties_add(&pubmsg.properties, &property);
1348 
1349  rc = MQTTAsync_sendMessage(c, test_qos_1_2_errors_globals.test_topic, &pubmsg, &opts);
1350  assert("Good rc from publish", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1351  if (rc != MQTTREASONCODE_SUCCESS)
1352  test_qos_1_2_errors_globals.test_finished = 1;
1353 
1355 }
1356 
1357 
1359 {
1360  MQTTAsync c = (MQTTAsync)context;
1364  int rc;
1365 
1366  MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
1367 
1368  assert("Reason code should be 0", response->reasonCode == MQTTREASONCODE_SUCCESS,
1369  "Reason code was %d\n", response->reasonCode);
1370 
1371  MyLog(LOGA_DEBUG, "Connack properties:");
1372  logProperties(&response->properties);
1373 
1376  opts.context = c;
1377 
1378  pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
1379  pubmsg.payloadlen = 11;
1380  pubmsg.qos = 1;
1381  pubmsg.retained = 0;
1382 
1383  property.identifier = MQTTPROPERTY_CODE_USER_PROPERTY;
1384  property.value.data.data = "pub user property";
1385  property.value.data.len = (int)strlen(property.value.data.data);
1386  property.value.value.data = "pub user property value";
1387  property.value.value.len = (int)strlen(property.value.value.data);
1388  MQTTProperties_add(&pubmsg.properties, &property);
1389 
1390  rc = MQTTAsync_sendMessage(c, test_qos_1_2_errors_globals.test_topic, &pubmsg, &opts);
1391  assert("Good rc from publish", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1392  if (rc != MQTTREASONCODE_SUCCESS)
1393  test_qos_1_2_errors_globals.test_finished = 1;
1394 
1396 }
1397 
1398 
1400 {
1401  MQTTAsync c;
1404  int rc = 0;
1405 
1406  MyLog(LOGA_INFO, "Starting V5 test - qos 1 and 2 errors");
1407  fprintf(xml, "<testcase classname=\"test11\" name=\"qos 1 and 2 errors\"");
1409 
1410  createOpts.MQTTVersion = MQTTVERSION_5;
1411  rc = MQTTAsync_createWithOptions(&c, options.connection, "qos 1 and 2 errors",
1412  MQTTCLIENT_PERSISTENCE_DEFAULT, NULL, &createOpts);
1413  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
1414  if (rc != MQTTASYNC_SUCCESS)
1415  {
1416  MQTTAsync_destroy(&c);
1417  goto exit;
1418  }
1419 
1421  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1422 
1423  opts.MQTTVersion = options.MQTTVersion;
1425  opts.context = c;
1426  opts.cleanstart = 1;
1427 
1428  MyLog(LOGA_DEBUG, "Connecting");
1429  rc = MQTTAsync_connect(c, &opts);
1430  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1431  if (rc != MQTTASYNC_SUCCESS)
1432  goto exit;
1433 
1434  while (test_qos_1_2_errors_globals.test_finished == 0)
1435  #if defined(_WIN32)
1436  Sleep(100);
1437  #else
1438  usleep(10000L);
1439  #endif
1440 
1441  MQTTAsync_destroy(&c);
1442 
1443 exit:
1444  MyLog(LOGA_INFO, "TEST6: test %s. %d tests run, %d failures.",
1445  (failures == 0) ? "passed" : "failed", tests, failures);
1447  return failures;
1448 }
1449 
1450 struct
1451 {
1452  int test_finished;
1456  int messages_arrived;
1458 {
1459  0,
1460  "test_7_request",
1461  "test_7_response",
1462  "test_7_correlation_id",
1463  0
1464 };
1465 
1466 
1467 int test_request_response_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
1468 {
1469  MQTTAsync c = (MQTTAsync)context;
1470  int rc;
1471 
1472  test_request_response_globals.messages_arrived++;
1473 
1474  assert("Message structure version should be 1", message->struct_version == 1,
1475  "message->struct_version was %d", message->struct_version);
1476  MyLog(LOGA_DEBUG, "Callback: message received on topic %s is %.*s.",
1477  topicName, message->payloadlen, (char*)(message->payload));
1478 
1479  if (message->struct_version == 1)
1480  logProperties(&message->properties);
1481 
1482  if (test_request_response_globals.messages_arrived == 1)
1483  {
1484  /* this is the request */
1486  MQTTProperty *corr_prop = NULL, *response_topic_prop = NULL;
1489  char myTopicName[100];
1490 
1491  assert("Topic should be request",
1492  strcmp(test_request_response_globals.request_topic, topicName) == 0,
1493  "topic was %s\n", topicName);
1494 
1497 
1498  assert("Topic should be response",
1499  strncmp(test_request_response_globals.response_topic, response_topic_prop->value.data.data,
1500  response_topic_prop->value.data.len) == 0,
1501  "topic was %.4s\n", response_topic_prop->value.data.data);
1502 
1505 
1506  assert("Correlation data should be",
1507  strncmp(test_request_response_globals.correlation_id, corr_prop->value.data.data,
1508  corr_prop->value.data.len) == 0,
1509  "Correlation data was %.4s\n", corr_prop->value.data.data);
1510 
1511  /* send response */
1512  pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
1513  pubmsg.payloadlen = 11;
1514  pubmsg.retained = 0;
1515  pubmsg.qos = 1;
1516 
1517  property.identifier = MQTTPROPERTY_CODE_CORRELATION_DATA;
1518  property.value.data.data = test_request_response_globals.correlation_id;
1519  property.value.data.len = (int)strlen(property.value.data.data);
1520  MQTTProperties_add(&pubmsg.properties, &property);
1521 
1522  memcpy(myTopicName, response_topic_prop->value.data.data, response_topic_prop->value.data.len);
1523  myTopicName[response_topic_prop->value.data.len] = '\0';
1524  rc = MQTTAsync_sendMessage(c, myTopicName, &pubmsg, &opts);
1525  if (rc != MQTTREASONCODE_SUCCESS)
1526  test_request_response_globals.test_finished = 1;
1527  assert("Good rc from sendMessage", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1528 
1530  }
1531  else if (test_request_response_globals.messages_arrived == 2)
1532  {
1533  MQTTProperty *corr_prop = NULL;
1534 
1535  /* this should be response */
1536  assert("Topic should be response",
1537  strcmp(test_request_response_globals.response_topic, topicName) == 0,
1538  "topic was %s\n", topicName);
1539 
1542 
1543  assert("Correlation data should be",
1544  strncmp(test_request_response_globals.correlation_id, corr_prop->value.data.data,
1545  corr_prop->value.data.len) == 0,
1546  "Correlation data was %.4s\n", corr_prop->value.data.data);
1547 
1548  test_request_response_globals.test_finished = 1;
1549  }
1550 
1551  MQTTAsync_freeMessage(&message);
1552  MQTTAsync_free(topicName);
1553 
1554  return 1;
1555 }
1556 
1557 
1559 {
1560  MQTTAsync c = (MQTTAsync)context;
1564  char* topics[2] = {test_error_reporting_globals.test_topic, "+"};
1565  int rc;
1566  int i = 0;
1567 
1568  MyLog(LOGA_DEBUG, "Suback properties:");
1569  logProperties(&response->properties);
1570 
1571  assert("Reason code count should be 2", response->alt.sub.reasonCodeCount == 2,
1572  "Reason code count was %d\n", response->alt.sub.reasonCodeCount);
1573 
1574  if (response->alt.sub.reasonCodeCount == 1)
1575  MyLog(LOGA_DEBUG, "reason code %d", response->reasonCode);
1576  else if (response->alt.sub.reasonCodeCount > 1)
1577  {
1578  for (i = 0; i < response->alt.sub.reasonCodeCount; ++i)
1579  {
1580  MyLog(LOGA_DEBUG, "Subscribe reason code %d", response->alt.sub.reasonCodes[i]);
1581  assert("Reason code should be 2", response->alt.sub.reasonCodes[i] == MQTTREASONCODE_GRANTED_QOS_2,
1582  "Reason code was %d\n", response->alt.sub.reasonCodes[i]);
1583  }
1584  }
1585 
1586  pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
1587  pubmsg.payloadlen = 11;
1588  pubmsg.retained = 0;
1589  pubmsg.qos = 1;
1590 
1591  property.identifier = MQTTPROPERTY_CODE_RESPONSE_TOPIC;
1592  property.value.data.data = test_request_response_globals.response_topic;
1593  property.value.data.len = (int)strlen(property.value.data.data);
1594  MQTTProperties_add(&pubmsg.properties, &property);
1595 
1596  property.identifier = MQTTPROPERTY_CODE_CORRELATION_DATA;
1597  property.value.data.data = test_request_response_globals.correlation_id;
1598  property.value.data.len = (int)strlen(property.value.data.data);
1599  MQTTProperties_add(&pubmsg.properties, &property);
1600 
1601  rc = MQTTAsync_sendMessage(c, test_request_response_globals.request_topic, &pubmsg, &opts);
1602  if (rc != MQTTREASONCODE_SUCCESS)
1603  test_request_response_globals.test_finished = 1;
1604  assert("Good rc from sendMessage", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1605 
1607 }
1608 
1609 
1611 {
1612  MQTTAsync c = (MQTTAsync)context;
1614  int rc;
1615  char* topics[2] = {test_request_response_globals.request_topic,
1616  test_request_response_globals.response_topic};
1617  int qos[2] = {2, 2};
1618 
1619  MyLog(LOGA_DEBUG, "In request response connect onSuccess callback, context %p", context);
1620 
1621  assert("Reason code should be 0", response->reasonCode == MQTTREASONCODE_SUCCESS,
1622  "Reason code was %d\n", response->reasonCode);
1623 
1624  MyLog(LOGA_DEBUG, "Connack properties:");
1625  logProperties(&response->properties);
1626 
1628  opts.context = c;
1629  rc = MQTTAsync_subscribeMany(c, 2, topics, qos, &opts);
1630  if (rc != MQTTREASONCODE_SUCCESS)
1631  test_request_response_globals.test_finished = 1;
1632  assert("Good rc from subscribeMany", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1633 }
1634 
1635 
1637 {
1638  MQTTAsync c;
1641  int rc = 0;
1642 
1643  MyLog(LOGA_INFO, "Starting V5 test - request response");
1644  fprintf(xml, "<testcase classname=\"test11\" name=\"request response\"");
1646 
1647  createOpts.MQTTVersion = MQTTVERSION_5;
1648  rc = MQTTAsync_createWithOptions(&c, options.connection, "request response",
1649  MQTTCLIENT_PERSISTENCE_DEFAULT, NULL, &createOpts);
1650  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
1651  if (rc != MQTTASYNC_SUCCESS)
1652  {
1653  MQTTAsync_destroy(&c);
1654  goto exit;
1655  }
1656 
1658  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1659 
1660  opts.MQTTVersion = options.MQTTVersion;
1662  opts.context = c;
1663  opts.cleanstart = 1;
1664 
1665  MyLog(LOGA_DEBUG, "Connecting");
1666  rc = MQTTAsync_connect(c, &opts);
1667  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1668  if (rc != MQTTASYNC_SUCCESS)
1669  goto exit;
1670 
1671  while (test_request_response_globals.test_finished == 0)
1672  #if defined(_WIN32)
1673  Sleep(100);
1674  #else
1675  usleep(10000L);
1676  #endif
1677 
1678  MQTTAsync_destroy(&c);
1679 
1680 exit:
1681  MyLog(LOGA_INFO, "TEST7: test %s. %d tests run, %d failures.",
1682  (failures == 0) ? "passed" : "failed", tests, failures);
1684  return failures;
1685 }
1686 
1687 
1688 struct
1689 {
1690  int test_finished;
1691  char* topic1;
1692  char* topic2;
1693  int messages_arrived;
1695 {
1696  0,
1697  "subscribe options topic",
1698  "+",
1699  0
1700 };
1701 
1702 
1703 int test_subscribeOptions_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
1704 {
1705  MQTTAsync c = (MQTTAsync)context;
1706 
1707  test_subscribeOptions_globals.messages_arrived++;
1708 
1709  assert("Message structure version should be 1", message->struct_version == 1,
1710  "message->struct_version was %d", message->struct_version);
1711  MyLog(LOGA_DEBUG, "Callback: message received on topic %s is %.*s.",
1712  topicName, message->payloadlen, (char*)(message->payload));
1713 
1714  if (message->struct_version == 1)
1715  logProperties(&message->properties);
1716 
1717  if (test_subscribeOptions_globals.messages_arrived == 1)
1718  {
1719  int subsidcount, subsid;
1720 
1722  assert("Subsidcount is i", subsidcount == 1, "subsidcount is not correct %d\n", subsidcount);
1723 
1725  assert("Subsid is 2", subsid == 2, "subsid is not correct %d\n", subsid);
1726 
1727  test_subscribeOptions_globals.test_finished = 1;
1728  }
1729 
1730  MQTTAsync_freeMessage(&message);
1731  MQTTAsync_free(topicName);
1732 
1733  return 1;
1734 }
1735 
1736 
1738 {
1739  MQTTAsync c = (MQTTAsync)context;
1741  int rc;
1742  static int called = 0;
1743 
1744  MyLog(LOGA_DEBUG, "In subscribe options connect onSuccess callback, context %p", context);
1745  called++;
1746 
1747  assert("Reason code should be 0", response->reasonCode == MQTTREASONCODE_GRANTED_QOS_2,
1748  "Reason code was %d\n", response->reasonCode);
1749 
1750  if (response->properties.count > 0)
1751  {
1752  MyLog(LOGA_DEBUG, "Suback properties:");
1753  logProperties(&response->properties);
1754  }
1755 
1756  if (called == 1)
1757  {
1759 
1761  property.value.integer4 = 2;
1762  MQTTProperties_add(&opts.properties, &property);
1763 
1765  opts.context = c;
1768  rc = MQTTAsync_subscribe(c, test_subscribeOptions_globals.topic2, 2, &opts);
1769  if (rc != MQTTREASONCODE_SUCCESS)
1770  test_subscribeOptions_globals.test_finished = 1;
1771  assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1772 
1774  }
1775  else if (called == 2)
1776  {
1778 
1779  pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
1780  pubmsg.payloadlen = 11;
1781  pubmsg.retained = 0;
1782  pubmsg.qos = 2;
1783 
1784  rc = MQTTAsync_sendMessage(c, test_subscribeOptions_globals.topic1, &pubmsg, &opts);
1785  assert("Good rc from send", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1786  if (rc != MQTTASYNC_SUCCESS)
1787  test_subscribeOptions_globals.test_finished = 1;
1788  }
1789 }
1790 
1791 
1793 {
1794  MQTTAsync c = (MQTTAsync)context;
1797  int rc;
1798 
1799  MyLog(LOGA_DEBUG, "In subscribe options connect onSuccess callback, context %p", context);
1800 
1801  assert("Reason code should be 0", response->reasonCode == MQTTREASONCODE_SUCCESS,
1802  "Reason code was %d\n", response->reasonCode);
1803 
1804  MyLog(LOGA_DEBUG, "Connack properties:");
1805  logProperties(&response->properties);
1806 
1807  property.identifier = MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIER;
1808  property.value.integer4 = 1;
1809  MQTTProperties_add(&opts.properties, &property);
1810  opts.subscribeOptions.noLocal = 1;
1811 
1813  opts.context = c;
1814  rc = MQTTAsync_subscribe(c, test_subscribeOptions_globals.topic1, 2, &opts);
1815  if (rc != MQTTREASONCODE_SUCCESS)
1816  test_request_response_globals.test_finished = 1;
1817  assert("Good rc from subscribeMany", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1818 
1820 }
1821 
1822 
1824 {
1825  MQTTAsync c;
1828  int rc = 0;
1829 
1830  MyLog(LOGA_INFO, "Starting V5 test - subscribe options");
1831  fprintf(xml, "<testcase classname=\"test11\" name=\"subscribe options\"");
1833 
1834  createOpts.MQTTVersion = MQTTVERSION_5;
1835  rc = MQTTAsync_createWithOptions(&c, options.connection, "subscribe options",
1836  MQTTCLIENT_PERSISTENCE_DEFAULT, NULL, &createOpts);
1837  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
1838  if (rc != MQTTASYNC_SUCCESS)
1839  {
1840  MQTTAsync_destroy(&c);
1841  goto exit;
1842  }
1843 
1845  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1846 
1847  opts.MQTTVersion = options.MQTTVersion;
1849  opts.context = c;
1850  opts.cleanstart = 1;
1851 
1852  MyLog(LOGA_DEBUG, "Connecting");
1853  rc = MQTTAsync_connect(c, &opts);
1854  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1855  if (rc != MQTTASYNC_SUCCESS)
1856  goto exit;
1857 
1858  while (test_subscribeOptions_globals.test_finished == 0)
1859  #if defined(_WIN32)
1860  Sleep(100);
1861  #else
1862  usleep(10000L);
1863  #endif
1864 
1865  MQTTAsync_destroy(&c);
1866 
1867 exit:
1868  MyLog(LOGA_INFO, "TEST8: test %s. %d tests run, %d failures.",
1869  (failures == 0) ? "passed" : "failed", tests, failures);
1871  return failures;
1872 }
1873 
1874 
1875 struct
1876 {
1878  char* topic;
1879  int messages_arrived;
1880  int test_finished;
1883 {
1884  "$share/share_test/any",
1885  "any",
1886  0,
1887  0,
1888  10,
1889 };
1890 
1891 
1892 int test_shared_subscriptions_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
1893 {
1894  MQTTAsync c = (MQTTAsync)context;
1895 
1896  test_shared_subscriptions_globals.messages_arrived++;
1897 
1898  assert("Message structure version should be 1", message->struct_version == 1,
1899  "message->struct_version was %d", message->struct_version);
1900  MyLog(LOGA_DEBUG, "Callback: message received on topic %s is %.*s.",
1901  topicName, message->payloadlen, (char*)(message->payload));
1902 
1903  if (message->struct_version == 1)
1904  logProperties(&message->properties);
1905 
1906  if (test_shared_subscriptions_globals.message_count == test_shared_subscriptions_globals.messages_arrived)
1907  test_shared_subscriptions_globals.test_finished = 1;
1908 
1909  MQTTAsync_freeMessage(&message);
1910  MQTTAsync_free(topicName);
1911 
1912  return 1;
1913 }
1914 
1915 
1917 {
1918  MQTTAsync c = (MQTTAsync)context;
1920  int rc;
1921  static int called = 0;
1922 
1923  called++;
1924  MyLog(LOGA_DEBUG, "In subscribe options connect onSuccess callback, context %p, called %d", context, called);
1925 
1926  assert("Reason code should be 0", response->reasonCode == MQTTREASONCODE_GRANTED_QOS_2,
1927  "Reason code was %d\n", response->reasonCode);
1928 
1929  if (response->properties.count > 0)
1930  {
1931  MyLog(LOGA_DEBUG, "Suback properties:");
1932  logProperties(&response->properties);
1933  }
1934 
1935  if (called == 2) /* both clients now connected and subscribed */
1936  {
1938  int i = 0;
1939  char buf[100];
1940 
1941  /* for each message we publish, only one of the subscribers should get it, not both */
1942  sprintf(buf, "shared subscriptions sequence number %d", i);
1943  pubmsg.payload = buf;
1944  pubmsg.payloadlen = (int)strlen(buf);
1945  pubmsg.retained = 0;
1946  pubmsg.qos = 2;
1947 
1948  for (i = 0; i < test_shared_subscriptions_globals.message_count; ++i)
1949  {
1950  rc = MQTTAsync_sendMessage(c, test_shared_subscriptions_globals.topic, &pubmsg, &opts);
1951  assert("Good rc from send", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1952  if (rc != MQTTASYNC_SUCCESS)
1953  {
1954  test_subscribeOptions_globals.test_finished = 1;
1955  break;
1956  }
1957  }
1958  }
1959 }
1960 
1961 
1963 {
1964  MQTTAsync d = (MQTTAsync)context;
1966  int rc;
1967 
1968  MyLog(LOGA_DEBUG, "In shared subscriptions connect d onSuccess callback, context %p", context);
1969 
1970  assert("Reason code should be 0", response->reasonCode == MQTTREASONCODE_SUCCESS,
1971  "Reason code was %d\n", response->reasonCode);
1972 
1974  opts.context = d;
1975  rc = MQTTAsync_subscribe(d, test_shared_subscriptions_globals.shared_topic, 2, &opts);
1976  assert("Good rc from subscribe", rc == MQTTREASONCODE_SUCCESS, "rc was %d", rc);
1977  if (rc != MQTTREASONCODE_SUCCESS)
1978  test_shared_subscriptions_globals.test_finished = 1;
1979 }
1980 
1981 
1983 {
1984  MQTTAsync c = (MQTTAsync)context;
1986  int rc;
1987 
1988  MyLog(LOGA_DEBUG, "In shared subscriptions connect c onSuccess callback, context %p", context);
1989 
1990  assert("Reason code should be 0", response->reasonCode == MQTTREASONCODE_SUCCESS,
1991  "Reason code was %d\n", response->reasonCode);
1992 
1994  opts.context = c;
1995  rc = MQTTAsync_subscribe(c, test_shared_subscriptions_globals.shared_topic, 2, &opts);
1996  assert("Good rc from subscribe", rc == MQTTREASONCODE_SUCCESS, "rc was %d", rc);
1997  if (rc != MQTTREASONCODE_SUCCESS)
1998  test_shared_subscriptions_globals.test_finished = 1;
1999 }
2000 
2001 
2003 {
2004  MQTTAsync c, d;
2007  int rc = 0, count = 0;
2008 
2009  MyLog(LOGA_INFO, "Starting V5 test - shared subscriptions");
2010  fprintf(xml, "<testcase classname=\"test11\" name=\"shared subscriptions\"");
2012 
2013  createOpts.MQTTVersion = MQTTVERSION_5;
2014  rc = MQTTAsync_createWithOptions(&c, options.connection, "shared subscriptions c",
2015  MQTTCLIENT_PERSISTENCE_DEFAULT, NULL, &createOpts);
2016  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
2017  if (rc != MQTTASYNC_SUCCESS)
2018  {
2019  MQTTAsync_destroy(&c);
2020  goto exit;
2021  }
2022 
2023  rc = MQTTAsync_createWithOptions(&d, options.connection, "shared subscriptions d",
2024  MQTTCLIENT_PERSISTENCE_DEFAULT, NULL, &createOpts);
2025  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
2026  if (rc != MQTTASYNC_SUCCESS)
2027  {
2028  MQTTAsync_destroy(&c);
2029  goto exit;
2030  }
2031 
2033  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
2034 
2036  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
2037 
2038  opts.MQTTVersion = options.MQTTVersion;
2040  opts.context = c;
2041  opts.cleanstart = 1;
2042 
2043  MyLog(LOGA_DEBUG, "Connecting");
2044  rc = MQTTAsync_connect(c, &opts);
2045  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
2046  if (rc != MQTTASYNC_SUCCESS)
2047  goto exit;
2048 
2050  opts.context = d;
2051 
2052  MyLog(LOGA_DEBUG, "Connecting");
2053  rc = MQTTAsync_connect(d, &opts);
2054  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
2055  if (rc != MQTTASYNC_SUCCESS)
2056  goto exit;
2057 
2058  while (test_shared_subscriptions_globals.test_finished == 0 && ++count < 1000)
2059  #if defined(_WIN32)
2060  Sleep(100);
2061  #else
2062  usleep(10000L);
2063  #endif
2064 
2065  /* sleep a bit more to see if any other messages arrive */
2066  #if defined(_WIN32)
2067  Sleep(100);
2068  #else
2069  usleep(10000L);
2070  #endif
2071  assert("Correct number of messages arrived",
2072  test_shared_subscriptions_globals.message_count == test_shared_subscriptions_globals.messages_arrived,
2073  "Actual number of messages received %d\n", test_shared_subscriptions_globals.messages_arrived);
2074 
2075  MQTTAsync_destroy(&c);
2076  MQTTAsync_destroy(&d);
2077 
2078 exit:
2079  MyLog(LOGA_INFO, "TEST9: test %s. %d tests run, %d failures.",
2080  (failures == 0) ? "passed" : "failed", tests, failures);
2082  return failures;
2083 }
2084 
2085 void trace_callback(enum MQTTASYNC_TRACE_LEVELS level, char* message)
2086 {
2087  printf("Trace : %d, %s\n", level, message);
2088 }
2089 
2090 
2091 int main(int argc, char** argv)
2092 {
2093  int rc = -1;
2094  int (*tests[])() = {NULL,
2104  }; /* indexed starting from 1 */
2105  MQTTAsync_nameValue* info;
2106  int i;
2107 
2108  xml = fopen("TEST-test4.xml", "w");
2109  fprintf(xml, "<testsuite name=\"test4\" tests=\"%d\">\n", (int)(ARRAY_SIZE(tests)) - 1);
2110 
2111  getopts(argc, argv);
2112 
2114 
2115  info = MQTTAsync_getVersionInfo();
2116  while (info->name)
2117  {
2118  MyLog(LOGA_INFO, "%s: %s", info->name, info->value);
2119  info++;
2120  }
2121 
2122  for (i = 0; i < options.iterations; ++i)
2123  {
2124  if (options.test_no == -1)
2125  { /* run all the tests */
2127  {
2128  failures = rc = 0;
2130  rc += tests[options.test_no](options); /* return number of failures. 0 = test succeeded */
2131  }
2132  }
2133  else
2134  {
2135  if (options.test_no >= ARRAY_SIZE(tests))
2136  MyLog(LOGA_INFO, "No test number %d", options.test_no);
2137  else
2138  {
2140  rc = tests[options.test_no](options); /* run just the selected test */
2141  }
2142  }
2143  }
2144 
2145  if (rc == 0)
2146  MyLog(LOGA_INFO, "verdict pass");
2147  else
2148  MyLog(LOGA_INFO, "verdict fail");
2149 
2150  fprintf(xml, "</testsuite>\n");
2151  fclose(xml);
2152 
2153  return rc;
2154 }
void test_subscribeOptions_onSubscribe(void *context, MQTTAsync_successData5 *response)
Definition: test11.c:1737
int test_request_response(struct Options options)
Definition: test11.c:1636
MQTTProperties properties
Definition: MQTTAsync.h:316
void test_client_topic_aliases_disconnected(void *context, MQTTProperties *props, enum MQTTReasonCodes rc)
Definition: test11.c:391
void test_subscription_ids_onConnect(void *context, MQTTAsync_successData5 *response)
Definition: test11.c:827
int disconnected
Definition: test11.c:306
enum MQTTPropertyCodes value
void test_subscription_ids_onSubscribe(void *context, MQTTAsync_successData5 *response)
Definition: test11.c:783
int test_subscribeOptions(struct Options options)
Definition: test11.c:1823
void test_shared_subscriptions_onSubscribe(void *context, MQTTAsync_successData5 *response)
Definition: test11.c:1916
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
MQTTAsync_onFailure5 * onFailure5
Definition: MQTTAsync.h:726
#define START_TIME_TYPE
Definition: test11.c:183
void test_request_response_onConnect(void *context, MQTTAsync_successData5 *response)
Definition: test11.c:1610
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&...args)
Definition: core.h:2081
int tests
Definition: test11.c:223
MQTTReasonCodes
START_TIME_TYPE global_start_time
Definition: test11.c:226
int messages_arrived
Definition: test11.c:558
MQTTProperties props
Definition: paho_c_pub.c:54
struct @80 test_client_topic_aliases_globals
const char * name
Definition: MQTTAsync.h:1149
void test_error_reporting_onSubscribe(void *context, MQTTAsync_successData5 *response)
Definition: test11.c:1111
const char * message
Definition: MQTTAsync.h:996
MQTTLenString value
START_TIME_TYPE start_clock(void)
Definition: test11.c:185
char * connection
const char * topicName
Definition: MQTTAsync.h:994
void MQTTProperties_free(MQTTProperties *props)
#define MQTTAsync_responseOptions_initializer
Definition: MQTTAsync.h:746
MQTTProperties properties
Definition: MQTTAsync.h:534
MQTTAsync_token token
Definition: MQTTAsync.h:582
MQTTClient d
Definition: test10.c:1656
void test_qos_1_2_errors_onPublishFailure(void *context, MQTTAsync_failureData5 *response)
Definition: test11.c:1320
char * topic2
Definition: test11.c:1692
MQTTProperties properties
Definition: MQTTAsync.h:584
void MyLog(int LOGA_level, char *format,...)
Definition: test11.c:125
char * shared_topic
Definition: test11.c:1877
int MQTTAsync_setCallbacks(MQTTAsync handle, void *context, MQTTAsync_connectionLost *cl, MQTTAsync_messageArrived *ma, MQTTAsync_deliveryComplete *dc)
Definition: MQTTAsync.c:3062
const char * MQTTReasonCode_toString(enum MQTTReasonCodes value)
struct MQTTAsync_successData5::@49::@53 unsub
MQTTSubscribe_options * subscribeOptionsList
Definition: MQTTAsync.h:743
int blocking_found
Definition: test11.c:921
void test_qos_1_2_errors_onPublishFailure2(void *context, MQTTAsync_failureData5 *response)
Definition: test11.c:1282
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
void test_qos_1_2_errors_onPublishFailure3(void *context, MQTTAsync_failureData5 *response)
Definition: test11.c:1268
void MQTTAsync_free(void *memory)
Definition: MQTTAsync.c:2626
int MQTTProperty_getType(enum MQTTPropertyCodes value)
enum MQTTReasonCodes reasonCode
Definition: MQTTAsync.h:583
int test_flow_control(struct Options options)
Definition: test11.c:1017
int test_subscription_ids(struct Options options)
Definition: test11.c:858
void MQTTAsync_freeMessage(MQTTAsync_message **message)
Definition: MQTTAsync.c:2615
int test_client_topic_aliases_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
Definition: test11.c:323
struct @85 test_qos_1_2_errors_globals
MQTTAsync_onSuccess5 * onSuccess5
Definition: MQTTAsync.h:720
struct @82 test_subscription_ids_globals
void write_test_result(void)
Definition: test11.c:230
std::tm localtime(std::time_t time)
Definition: chrono.h:292
void MQTTAsync_setTraceCallback(MQTTAsync_traceCallback *callback)
Definition: MQTTAsync.c:4903
int failures
Definition: test11.c:224
unsigned char retainAsPublished
MQTTProperty * MQTTProperties_getProperty(MQTTProperties *props, enum MQTTPropertyCodes propid)
int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions *options)
Definition: MQTTAsync.c:3480
int receive_maximum
Definition: test11.c:920
void getopts(int argc, char **argv)
Definition: test11.c:66
int MQTTProperties_getNumericValue(MQTTProperties *props, enum MQTTPropertyCodes propid)
MQTTASYNC_TRACE_LEVELS
Definition: MQTTAsync.h:1650
int test_server_topic_aliases_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
Definition: test11.c:566
static char msg_buf[512]
Definition: Log.c:122
struct @87 test_subscribeOptions_globals
union MQTTAsync_successData5::@49 alt
void test_error_reporting_onUnsubscribe(void *context, MQTTAsync_successData5 *response)
Definition: test11.c:1085
void usage(void)
Definition: test11.c:42
struct @84 test_error_reporting_globals
void test_server_topic_aliases_onSubscribe(void *context, MQTTAsync_successData5 *response)
Definition: test11.c:612
int MQTTAsync_subscribe(MQTTAsync handle, const char *topic, int qos, MQTTAsync_responseOptions *response)
Definition: MQTTAsync.c:4121
void test_qos_1_2_errors_onPublishSuccess(void *context, MQTTAsync_successData5 *response)
Definition: test11.c:1256
struct @88 test_shared_subscriptions_globals
#define MQTTAsync_willOptions_initializer
Definition: MQTTAsync.h:1014
constexpr size_t count()
Definition: core.h:960
#define MQTTAsync_connectOptions_initializer5
Definition: MQTTAsync.h:1338
void test1_onDisconnect(void *context, MQTTAsync_successData *response)
Definition: test11.c:315
#define assert(a, b, c, d)
Definition: test11.c:220
char * request_topic
Definition: test11.c:1454
int MQTTAsync_setDisconnected(MQTTAsync handle, void *context, MQTTAsync_disconnected *disconnected)
Definition: MQTTAsync.c:3156
const char * MQTTPropertyName(enum MQTTPropertyCodes value)
struct @86 test_request_response_globals
description
Definition: setup.py:19
char * topic1
Definition: test11.c:1691
void test_shared_subscriptions_onConnectc(void *context, MQTTAsync_successData5 *response)
Definition: test11.c:1982
int message_count
Definition: test5.c:72
int MQTTAsync_unsubscribeMany(MQTTAsync handle, int count, char *const *topic, MQTTAsync_responseOptions *response)
Definition: MQTTAsync.c:4131
MQTTAsync_onFailure5 * onFailure5
Definition: MQTTAsync.h:1327
enum MQTTPropertyCodes identifier
void logProperties(MQTTProperties *props)
Definition: test11.c:265
void myassert(char *filename, int lineno, char *description, int value, char *format,...)
Definition: test11.c:243
int test_subscribeOptions_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
Definition: test11.c:1703
struct @81 test_server_topic_aliases_globals
int qos
Definition: test6.c:56
#define MQTTAsync_createOptions_initializer
Definition: MQTTAsync.h:965
char * cur_output
Definition: test11.c:228
void trace_callback(enum MQTTASYNC_TRACE_LEVELS level, char *message)
Definition: test11.c:2085
void test_request_response_onSubscribe(void *context, MQTTAsync_successData5 *response)
Definition: test11.c:1558
int MQTTAsync_subscribeMany(MQTTAsync handle, int count, char *const *topic, int *qos, MQTTAsync_responseOptions *response)
Definition: MQTTAsync.c:4004
MQTTAsync_token token
Definition: MQTTAsync.h:530
FILE * xml
Definition: test11.c:225
void flow_control_trace_callback(enum MQTTASYNC_TRACE_LEVELS level, char *message)
Definition: test11.c:1008
struct Options options
int test_finished
Definition: test11.c:308
int main(int argc, char **argv)
Definition: test11.c:2091
int MQTTProperties_propertyCount(MQTTProperties *props, enum MQTTPropertyCodes propid)
int msg_count
Definition: test11.c:559
MQTTAsync_willOptions * will
Definition: MQTTAsync.h:1214
#define MQTTCLIENT_PERSISTENCE_DEFAULT
const char * name
MQTTProperty * array
int test_qos_1_2_errors(struct Options options)
Definition: test11.c:1399
void test_client_topic_aliases_onConnect(void *context, MQTTAsync_successData5 *response)
Definition: test11.c:400
int MQTTProperties_hasProperty(MQTTProperties *props, enum MQTTPropertyCodes propid)
char output[3000]
Definition: test11.c:227
MQTTProperties properties
Definition: MQTTAsync.h:730
void MQTTAsync_destroy(MQTTAsync *handle)
Definition: MQTTAsync.c:2554
const char * value
Definition: MQTTAsync.h:1150
#define MQTTVERSION_5
Definition: MQTTAsync.h:207
void test_flow_control_onSubscribe(void *context, MQTTAsync_successData5 *response)
Definition: test11.c:952
#define MQTTASYNC_SUCCESS
Definition: MQTTAsync.h:113
void MQTTAsync_setTraceLevel(enum MQTTASYNC_TRACE_LEVELS level)
Definition: MQTTAsync.c:4897
int test_request_response_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
Definition: test11.c:1467
int MQTTAsync_sendMessage(MQTTAsync handle, const char *destinationName, const MQTTAsync_message *message, MQTTAsync_responseOptions *response)
Definition: MQTTAsync.c:4328
char * test_topic
Definition: test11.c:307
MQTTClient c
Definition: test10.c:1656
dictionary context
Definition: test2.py:57
void test_server_topic_aliases_onConnect(void *context, MQTTAsync_successData5 *response)
Definition: test11.c:640
long elapsed(START_TIME_TYPE start_time)
Definition: test11.c:210
enum MQTTReasonCodes reasonCode
Definition: MQTTAsync.h:532
void test_qos_1_2_errors_onConnect(void *context, MQTTAsync_successData5 *response)
Definition: test11.c:1358
int test_server_topic_aliases(struct Options options)
Definition: test11.c:668
MQTTProperties * willProperties
Definition: MQTTAsync.h:1315
char * correlation_id
Definition: test11.c:1455
int test_error_reporting(struct Options options)
Definition: test11.c:1194
char * response_topic
Definition: test11.c:1453
MQTTSubscribe_options subscribeOptions
Definition: MQTTAsync.h:734
void test_flow_control_onConnect(void *context, MQTTAsync_successData5 *response)
Definition: test11.c:979
void test_error_reporting_onConnect(void *context, MQTTAsync_successData5 *response)
Definition: test11.c:1154
#define LOGA_INFO
Definition: test11.c:121
int test_flow_control_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
Definition: test11.c:928
int MQTTProperties_getNumericValueAt(MQTTProperties *props, enum MQTTPropertyCodes propid, int index)
struct @83 test_flow_control_globals
void test_client_topic_aliases_onSubscribe(void *context, MQTTAsync_successData5 *response)
Definition: test11.c:354
char * topic
Definition: test11.c:1878
unsigned char retainHandling
#define MQTTSubscribe_options_initializer
#define LOGA_DEBUG
Definition: test11.c:120
void test_subscribeOptions_onConnect(void *context, MQTTAsync_successData5 *response)
Definition: test11.c:1792
int test_shared_subscriptions(struct Options options)
Definition: test11.c:2002
int test_subscription_ids_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
Definition: test11.c:749
#define MQTTAsync_message_initializer
Definition: MQTTAsync.h:319
#define ARRAY_SIZE(a)
Definition: test11.c:40
char * topics[]
MQTTProperty property
Definition: paho_c_pub.c:53
enum MQTTReasonCodes rc
Definition: test10.c:1112
int test_shared_subscriptions_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
Definition: test11.c:1892
struct MQTTAsync_successData5::@49::@50 sub
MQTTAsync_onSuccess5 * onSuccess5
Definition: MQTTAsync.h:1321
int test_client_topic_aliases(struct Options options)
Definition: test11.c:454
int test_no
Definition: test1.c:54
void test_shared_subscriptions_onConnectd(void *context, MQTTAsync_successData5 *response)
Definition: test11.c:1962
MQTTProperties * connectProperties
Definition: MQTTAsync.h:1311
#define MQTTProperties_initializer


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