43 #if !defined(_WINDOWS) 45 #include <sys/socket.h> 50 #define setenv(a, b, c) _putenv_s(a, b) 53 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) 73 "tcp://localhost:1883",
75 "tcp://localhost:1884",
89 if (strcmp(argv[count],
"--test_no") == 0)
96 else if (strcmp(argv[count],
"--connection") == 0)
106 else if (strcmp(argv[count],
"--haconnections") == 0)
110 char* tok = strtok(argv[count],
" ");
118 tok = strtok(NULL,
" ");
124 else if (strcmp(argv[count],
"--proxy_connection") == 0)
131 else if (strcmp(argv[count],
"--MQTTversion") == 0)
141 else if (strcmp(argv[count],
"--iterations") == 0)
148 else if (strcmp(argv[count],
"--verbose") == 0)
151 printf(
"\nSetting verbose on\n");
162 #include <sys/timeb.h> 167 #if defined(_WIN32) || defined(_WINDOWS) 177 #if defined(_WIN32) || defined(_WINDOWS) 181 gettimeofday(&ts, NULL);
182 localtime_r(&ts.tv_sec, &timeinfo);
184 strftime(msg_buf, 80,
"%Y%m%d %H%M%S", &timeinfo);
186 #if defined(_WIN32) || defined(_WINDOWS) 187 sprintf(&msg_buf[strlen(msg_buf)],
".%.3hu ", ts.millitm);
189 sprintf(&msg_buf[strlen(msg_buf)],
".%.3lu ", ts.tv_usec / 1000);
192 va_start(args, format);
193 vsnprintf(&msg_buf[strlen(msg_buf)],
sizeof(msg_buf) - strlen(msg_buf), format, args);
196 printf(
"%s\n", msg_buf);
201 #if defined(_WIN32) || defined(_WINDOWS) 202 #define mqsleep(A) Sleep(1000*A) 203 #define START_TIME_TYPE DWORD 204 static DWORD start_time = 0;
207 return GetTickCount();
210 #define mqsleep sleep 211 #define START_TIME_TYPE struct timespec 214 static struct timespec start;
215 clock_gettime(CLOCK_REALTIME, &start);
219 #define mqsleep sleep 220 #define START_TIME_TYPE struct timeval 224 struct timeval start_time;
225 gettimeofday(&start_time, NULL);
234 return GetTickCount() - start_time;
238 long elapsed(
struct timespec start)
240 struct timespec now, res;
242 clock_gettime(CLOCK_REALTIME, &now);
243 ntimersub(now, start, res);
244 return (res.tv_sec)*1000L + (res.tv_nsec)/1000000L;
249 struct timeval now, res;
251 gettimeofday(&now, NULL);
252 timersub(&now, &start_time, &res);
253 return (res.tv_sec)*1000 + (res.tv_usec)/1000;
258 #define assert(a, b, c, d) myassert(__FILE__, __LINE__, a, b, c, d) 259 #define assert1(a, b, c, d, e) myassert(__FILE__, __LINE__, a, b, c, d, e) 273 fprintf(
xml,
" time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000);
279 fprintf(
xml,
"</testcase>\n");
291 MyLog(
LOGA_INFO,
"Assertion failed, file %s, line %d, description: %s\n", filename, lineno, description);
293 va_start(args, format);
294 vprintf(format, args);
298 description, filename, lineno);
301 MyLog(
LOGA_DEBUG,
"Assertion succeeded, file %s, line %d, description: %s", filename, lineno, description);
309 for (i = 0; i < props->
count; ++i)
313 char* intformat =
"Property name %s value %d";
370 const int props_count = 0;
399 char*
test_topic =
"test_client_topic_aliases";
400 int topicAliasMaximum = 0;
403 fprintf(
xml,
"<testcase classname=\"test_client_topic_aliases\" name=\"client topic aliases\"");
445 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
452 property.value.integer2 = 0;
472 property.value.integer4 = 30;
489 assert(
"topicAliasMaximum > 0", topicAliasMaximum > 0,
"topicAliasMaximum was %d", topicAliasMaximum);
498 property.value.integer2 = 1;
563 property.value.integer2 = 1;
608 static int received = 0;
609 static int first_topic_alias = 0;
620 const int props_count = 0;
626 first_topic_alias = topicAlias;
628 assert(
"All topic aliases should be the same", topicAlias == first_topic_alias,
629 "Topic alias was %d\n", topicAlias);
631 assert(
"topicAlias should not be 0", topicAlias > 0,
"Topic alias was %d\n", topicAlias);
655 char*
test_topic =
"test_server_topic_aliases";
656 int topicAliasMaximum = 0;
661 fprintf(
xml,
"<testcase classname=\"test_server_topic_aliases\" name=\"server topic aliases\"");
690 property.value.integer2 = 1;
713 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
751 static int received = 0;
752 static int first_topic_alias = 0;
763 int subsidcount = 0, i = 0;
767 for (i = 0; i < subsidcount; ++i)
770 assert(
"Subsid is i+1", subsid == i+1,
"subsid is not correct %d\n", subsid);
800 fprintf(
xml,
"<testcase classname=\"test_subscription_ids\" name=\"subscription ids\"");
841 assert(
"Subscription ids must be available", subsids == 1,
"subsids is %d", subsids);
845 property.value.integer4 = 1;
851 property.value.integer4 = 2;
857 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
893 static int received = 0;
894 static int first_topic_alias = 0;
914 static char* msg =
"Blocking publish on queue full";
916 if (strstr(message, msg) != NULL)
935 fprintf(
xml,
"<testcase classname=\"test_flow_control\" name=\"flow control\"");
982 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
986 for (i = 0; i < receive_maximum + 2; ++i)
1032 fprintf(
xml,
"<testcase classname=\"test_error_reporting\" name=\"error reporting\"");
1072 property.value.data.data =
"unsub user property";
1073 property.value.data.len = (int)strlen(property.
value.
data.data);
1074 property.value.value.data =
"unsub user property value";
1075 property.value.value.len = (int)strlen(property.
value.value.
data);
1122 MyLog(
LOGA_INFO,
"Callback: published, reason code \"%s\" msgid: %d packet type: %d",
1136 printf(
"%s\n", message);
1162 fprintf(
xml,
"<testcase classname=\"test_qos_1_2_errors\" name=\"qos 1 2 errors\"");
1204 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
1210 property.value.data.data =
"unsub user property";
1211 property.value.data.len = (int)strlen(property.
value.
data.data);
1212 property.value.value.data =
"unsub user property value";
1213 property.value.value.len = (int)strlen(property.
value.value.
data);
1230 assert(
"Reason code was packet identifier not found",
1252 assert(
"Reason code was packet identifier not found",
1273 assert(
"Reason code was packet identifier not found",
1301 "my response topic",
1317 const int props_count = 0;
1328 assert(
"Topic should be request",
1330 "topic was %s\n", topicName);
1335 assert(
"Topic should be response",
1337 "topic was %.4s\n", prop->
value.
data.data);
1342 assert(
"Correlation data should be",
1344 "Correlation data was %.4s\n", prop->
value.
data.data);
1349 assert(
"Topic should be response",
1351 "topic was %s\n", topicName);
1378 fprintf(
xml,
"<testcase classname=\"test_request_response\" name=\"request/response\"");
1428 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
1435 property.value.data.len = (int)strlen(property.
value.
data.data);
1440 property.value.data.len = (int)strlen(property.
value.
data.data);
1460 property.value.data.data =
"request no 1";
1461 property.value.data.len = (int)strlen(property.
value.
data.data);
1500 "my response topic",
1507 int subsidcount = 0, i = 0, subsid = -1;
1516 const int props_count = 0;
1526 assert(
"Subsidcount is i", subsidcount == 1,
"subsidcount is not correct %d\n", subsidcount);
1529 assert(
"Subsid is 2", subsid == 2,
"subsid is not correct %d\n", subsid);
1555 fprintf(
xml,
"<testcase classname=\"test_subscribe_options\" name=\"subscribe options\"");
1596 property.value.integer4 = 1;
1609 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
1651 "$share/share_test/#",
1660 int subsidcount = 0, i = 0, subsid = -1;
1669 const int props_count = 0;
1701 fprintf(
xml,
"<testcase classname=\"test_shared_subscriptions\" name=\"shared subscriptions\"");
1773 pubmsg.
payload =
"a much longer message that we can shorten to the extent that we need to payload up to 11";
1779 for (i = 0; i < 10; ++i)
1816 int (*
tests[])() = {NULL,
1828 xml = fopen(
"TEST-test1.xml",
"w");
1829 fprintf(
xml,
"<testsuite name=\"test1\" tests=\"%d\">\n", (
int)(
ARRAY_SIZE(
tests) - 1));
1851 fprintf(
xml,
"</testsuite>\n");
int MQTTClient_disconnect5(MQTTClient handle, int timeout, enum MQTTReasonCodes reason, MQTTProperties *props)
enum MQTTPropertyCodes value
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&...args)
#define MQTTCLIENT_SUCCESS
int test_subscribe_options_messageArrived(void *context, char *topicName, int topicLen, MQTTClient_message *message)
int test_server_topic_aliases(struct Options options)
void myassert(char *filename, int lineno, char *description, int value, char *format,...)
void MQTTProperties_free(MQTTProperties *props)
const char * MQTTReasonCode_toString(enum MQTTReasonCodes value)
int MQTTProperties_add(MQTTProperties *props, const MQTTProperty *prop)
int main(int argc, char **argv)
size_t strftime(char *str, size_t count, const char *format, const std::tm *time)
int MQTTProperty_getType(enum MQTTPropertyCodes value)
int test_subscribe_options(struct Options options)
#define MQTTClient_connectOptions_initializer5
int MQTTClient_createWithOptions(MQTTClient *handle, const char *serverURI, const char *clientId, int persistence_type, void *persistence_context, MQTTClient_createOptions *options)
long elapsed(START_TIME_TYPE start_time)
MQTTResponse MQTTClient_unsubscribe5(MQTTClient handle, const char *topic, MQTTProperties *props)
MQTTProperty * MQTTProperties_getProperty(MQTTProperties *props, enum MQTTPropertyCodes propid)
struct @79 test_shared_subscriptions_globals
int MQTTProperties_getNumericValue(MQTTProperties *props, enum MQTTPropertyCodes propid)
int test_subscription_ids_messageArrived(void *context, char *topicName, int topicLen, MQTTClient_message *message)
#define MQTTClient_message_initializer
enum MQTTReasonCodes reasonCode
void MQTTResponse_free(MQTTResponse response)
int test_error_reporting(struct Options options)
#define MQTTClient_willOptions_initializer
int MQTTClient_setDisconnected(MQTTClient handle, void *context, MQTTClient_disconnected *disconnected)
struct @76 test_qos_1_2_errors_globals
int MQTTClient_setCallbacks(MQTTClient handle, void *context, MQTTClient_connectionLost *cl, MQTTClient_messageArrived *ma, MQTTClient_deliveryComplete *dc)
void MQTTClient_setTraceCallback(MQTTClient_traceCallback *callback)
int test_client_topic_aliases(struct Options options)
int test_flow_control_messageArrived(void *context, char *topicName, int topicLen, MQTTClient_message *message)
struct @77 test_request_response_globals
const char * MQTTPropertyName(enum MQTTPropertyCodes value)
MQTTResponse MQTTClient_publishMessage5(MQTTClient handle, const char *topicName, MQTTClient_message *message, MQTTClient_deliveryToken *deliveryToken)
int messageArrived(void *context, char *topicName, int topicLen, MQTTClient_message *message)
void test_trace_callback(enum MQTTCLIENT_TRACE_LEVELS level, char *message)
enum MQTTPropertyCodes identifier
int test2_messageArrived(void *context, char *topicName, int topicLen, MQTTClient_message *message)
int test_shared_subscriptions_messageArrived(void *context, char *topicName, int topicLen, MQTTClient_message *message)
void MyLog(int LOGA_level, char *format,...)
int test_shared_subscriptions(struct Options options)
START_TIME_TYPE global_start_time
void MQTTClient_freeMessage(MQTTClient_message **message)
struct @75 test_topic_aliases_globals
START_TIME_TYPE start_clock(void)
int MQTTProperties_propertyCount(MQTTProperties *props, enum MQTTPropertyCodes propid)
void MQTTClient_destroy(MQTTClient *handle)
MQTTResponse MQTTClient_connect5(MQTTClient handle, MQTTClient_connectOptions *options, MQTTProperties *connectProperties, MQTTProperties *willProperties)
struct @78 test_subscribe_options_globals
#define MQTTCLIENT_PERSISTENCE_DEFAULT
MQTTProperties properties
int MQTTProperties_hasProperty(MQTTProperties *props, enum MQTTPropertyCodes propid)
int test_request_response(struct Options options)
void getopts(int argc, char **argv)
int MQTTClient_setPublished(MQTTClient handle, void *context, MQTTClient_published *published)
int test_request_response_messageArrived(void *context, char *topicName, int topicLen, MQTTClient_message *message)
int test_flow_control(struct Options options)
MQTTResponse MQTTClient_subscribe5(MQTTClient handle, const char *topic, int qos, MQTTSubscribe_options *opts, MQTTProperties *props)
void write_test_result(void)
static int messages_arrived
void MQTTClient_free(void *memory)
#define MQTTResponse_initializer
int MQTTClient_deliveryToken
#define MQTTClient_createOptions_initializer
int test_subscription_ids(struct Options options)
int MQTTProperties_getNumericValueAt(MQTTProperties *props, enum MQTTPropertyCodes propid, int index)
static int blocking_found
unsigned char retainHandling
#define MQTTSubscribe_options_initializer
void test_flow_control_trace_callback(enum MQTTCLIENT_TRACE_LEVELS level, char *message)
#define assert(a, b, c, d)
void logProperties(MQTTProperties *props)
MQTTProperties * properties
#define MQTTProperties_initializer
int test_qos_1_2_errors(struct Options options)