35 #if !defined(_WINDOWS) 37 #include <sys/socket.h> 43 #define MAXHOSTNAMELEN 256 44 #define EAGAIN WSAEWOULDBLOCK 45 #define EINTR WSAEINTR 46 #define EINPROGRESS WSAEINPROGRESS 47 #define EWOULDBLOCK WSAEWOULDBLOCK 48 #define ENOTCONN WSAENOTCONN 49 #define ECONNRESET WSAECONNRESET 50 #define setenv(a, b, c) _putenv_s(a, b) 53 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) 71 "m2m.eclipse.org:1883",
85 if (strcmp(argv[count],
"--test_no") == 0)
92 else if (strcmp(argv[count],
"--connection") == 0)
102 else if (strcmp(argv[count],
"--haconnections") == 0)
106 char* tok = strtok(argv[count],
" ");
114 tok = strtok(NULL,
" ");
120 else if (strcmp(argv[count],
"--iterations") == 0)
127 else if (strcmp(argv[count],
"--verbose") == 0)
130 printf(
"\nSetting verbose on\n");
141 #include <sys/timeb.h> 155 strftime(msg_buf, 80,
"%Y%m%d %H%M%S", timeinfo);
157 sprintf(&msg_buf[strlen(msg_buf)],
".%.3hu ", ts.millitm);
159 va_start(args, format);
160 vsnprintf(&msg_buf[strlen(msg_buf)],
sizeof(msg_buf) - strlen(msg_buf), format, args);
163 printf(
"%s\n", msg_buf);
168 #if defined(_WIN32) || defined(_WINDOWS) 169 #define mqsleep(A) Sleep(1000*A) 170 #define START_TIME_TYPE DWORD 171 static DWORD start_time = 0;
174 return GetTickCount();
177 #define mqsleep sleep 178 #define START_TIME_TYPE struct timespec 181 static struct timespec start;
182 clock_gettime(CLOCK_REALTIME, &start);
186 #define mqsleep sleep 187 #define START_TIME_TYPE struct timeval 191 struct timeval start_time;
192 gettimeofday(&start_time, NULL);
201 return GetTickCount() - start_time;
205 long elapsed(
struct timespec start)
207 struct timespec now, res;
209 clock_gettime(CLOCK_REALTIME, &now);
210 ntimersub(now, start, res);
211 return (res.tv_sec)*1000L + (res.tv_nsec)/1000000L;
216 struct timeval now, res;
218 gettimeofday(&now, NULL);
219 timersub(&now, &start_time, &res);
220 return (res.tv_sec)*1000 + (res.tv_usec)/1000;
225 #define assert(a, b, c, d) myassert(__FILE__, __LINE__, a, b, c, d) 226 #define assert1(a, b, c, d, e) myassert(__FILE__, __LINE__, a, b, c, d, e) 241 fprintf(
xml,
" time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000);
247 fprintf(
xml,
"</testcase>\n");
259 MyLog(
LOGA_INFO,
"Assertion failed, file %s, line %d, description: %s\n", filename, lineno, description);
261 va_start(args, format);
262 vprintf(format, args);
266 description, filename, lineno);
269 MyLog(
LOGA_DEBUG,
"Assertion succeeded, file %s, line %d, description: %s", filename, lineno, description);
288 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback, context %p", context);
293 "serverURI was %s", response->
alt.
connect.serverURI);
294 assert(
"Correct MQTTVersion returned", response->
alt.
connect.MQTTVersion == 4,
295 "MQTTVersion was %d", response->
alt.
connect.MQTTVersion);
296 assert(
"Correct sessionPresent returned", response->
alt.
connect.sessionPresent == 1,
297 "sessionPresent was %d", response->
alt.
connect.sessionPresent);
335 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback, context %p", context);
340 "serverURI was %s", response->
alt.
connect.serverURI);
341 assert(
"Correct MQTTVersion returned", response->
alt.
connect.MQTTVersion == 4,
342 "MQTTVersion was %d", response->
alt.
connect.MQTTVersion);
343 assert(
"Correct sessionPresent returned", response->
alt.
connect.sessionPresent == 0,
344 "sessionPresent was %d", response->
alt.
connect.sessionPresent);
382 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback 1, context %p", context);
387 "serverURI was %s", response->
alt.
connect.serverURI);
388 assert(
"Correct MQTTVersion returned", response->
alt.
connect.MQTTVersion == 4,
389 "MQTTVersion was %d", response->
alt.
connect.MQTTVersion);
390 assert(
"Correct sessionPresent returned", response->
alt.
connect.sessionPresent == 0,
391 "sessionPresent was %d", response->
alt.
connect.sessionPresent);
410 fprintf(
xml,
"<testcase classname=\"test1\" name=\"sessionPresent\"");
474 MyLog(
LOGA_DEBUG,
"In subscribe onFailure callback, context %p", context);
477 "qos was %d", response->
code);
491 MyLog(
LOGA_DEBUG,
"In subscribe onSuccess callback, context %p", context);
493 assert(
"Correct subscribe return code", response->
alt.
qos == 2,
494 "qos was %d", response->
alt.
qos);
504 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback 1, context %p", context);
507 "serverURI was %s", response->
alt.
connect.serverURI);
508 assert(
"Correct MQTTVersion returned", response->
alt.
connect.MQTTVersion == 4,
509 "MQTTVersion was %d", response->
alt.
connect.MQTTVersion);
510 assert(
"Correct sessionPresent returned", response->
alt.
connect.sessionPresent == 0,
511 "sessionPresent was %d", response->
alt.
connect.sessionPresent);
513 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback, context %p", context);
544 fprintf(
xml,
"<testcase classname=\"test2\" name=\"bad subscribe\"");
595 int main(
int argc,
char** argv)
601 xml = fopen(
"TEST-MQTT4sync.xml",
"w");
602 fprintf(
xml,
"<testsuite name=\"test-mqtt4sync\" tests=\"%d\">\n", (
int)(
ARRAY_SIZE(
tests) - 1));
604 setenv(
"MQTT_C_CLIENT_TRACE",
"ON", 1);
605 setenv(
"MQTT_C_CLIENT_TRACE_LEVEL",
"ERROR", 1);
625 fprintf(
xml,
"</testsuite>\n");
MQTTAsync_onFailure * onFailure
void test1_onConnect2(void *context, MQTTAsync_successData *response)
void myassert(char *filename, int lineno, char *description, int value, char *format,...)
enum MQTTPropertyCodes value
void test1_onConnect3(void *context, MQTTAsync_successData *response)
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&...args)
union MQTTAsync_successData::@46 alt
void getopts(int argc, char **argv)
int test2(struct Options options)
#define MQTTAsync_responseOptions_initializer
void test1_onDisconnect1(void *context, MQTTAsync_successData *response)
int MQTTAsync_disconnect(MQTTAsync handle, const MQTTAsync_disconnectOptions *options)
size_t strftime(char *str, size_t count, const char *format, const std::tm *time)
#define assert(a, b, c, d)
int test1(struct Options options)
std::tm localtime(std::time_t time)
struct MQTTAsync_successData::@46::@48 connect
int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions *options)
void test2_onSubscribe2(void *context, MQTTAsync_failureData *response)
int MQTTAsync_subscribe(MQTTAsync handle, const char *topic, int qos, MQTTAsync_responseOptions *response)
void test2_onConnect1(void *context, MQTTAsync_successData *response)
int MQTTAsync_create(MQTTAsync *handle, const char *serverURI, const char *clientId, int persistence_type, void *persistence_context)
void write_test_result(void)
void test1_onDisconnect2(void *context, MQTTAsync_successData *response)
void MyLog(int LOGA_level, char *format,...)
#define MQTTAsync_disconnectOptions_initializer
MQTTAsync_onFailure * onFailure
START_TIME_TYPE global_start_time
int main(int argc, char **argv)
#define MQTTAsync_connectOptions_initializer
MQTTAsync_onSuccess * onSuccess
#define MQTTCLIENT_PERSISTENCE_DEFAULT
#define MQTT_BAD_SUBSCRIBE
void MQTTAsync_destroy(MQTTAsync *handle)
#define MQTTASYNC_SUCCESS
void test2_onSubscribe1(void *context, MQTTAsync_successData *response)
void test1_onConnect1(void *context, MQTTAsync_successData *response)
START_TIME_TYPE start_clock(void)
void test1_onDisconnect3(void *context, MQTTAsync_successData *response)
long elapsed(START_TIME_TYPE start_time)
MQTTAsync_onSuccess * onSuccess
void test2_onDisconnect(void *context, MQTTAsync_successData *response)
MQTTAsync_onSuccess * onSuccess