33 #if !defined(_WINDOWS) 35 #include <sys/socket.h> 44 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) 60 "mqtt.eclipse.org:1883",
72 if (strcmp(argv[count],
"--test_no") == 0)
79 else if (strcmp(argv[count],
"--connection") == 0)
86 else if (strcmp(argv[count],
"--proxy_connection") == 0)
93 else if (strcmp(argv[count],
"--verbose") == 0)
104 #include <sys/timeb.h> 118 strftime(msg_buf, 80,
"%Y%m%d %H%M%S", timeinfo);
120 sprintf(&msg_buf[strlen(msg_buf)],
".%.3hu ", ts.millitm);
122 va_start(args, format);
123 vsnprintf(&msg_buf[strlen(msg_buf)],
sizeof(msg_buf) - strlen(msg_buf),
127 printf(
"%s\n", msg_buf);
133 #if defined(_WIN32) || defined(_WIN64) 136 usleep(milliseconds*1000);
140 #if defined(_WIN32) || defined(_WINDOWS) 141 #define START_TIME_TYPE DWORD 142 static DWORD start_time = 0;
145 return GetTickCount();
148 #define START_TIME_TYPE struct timespec 151 static struct timespec start;
152 clock_gettime(CLOCK_REALTIME, &start);
156 #define START_TIME_TYPE struct timeval 160 struct timeval start_time;
161 gettimeofday(&start_time, NULL);
169 return GetTickCount() - start_time;
173 long elapsed(
struct timespec start)
175 struct timespec now, res;
177 clock_gettime(CLOCK_REALTIME, &now);
178 ntimersub(now, start, res);
179 return (res.tv_sec)*1000L + (res.tv_nsec)/1000000L;
184 struct timeval now, res;
186 gettimeofday(&now, NULL);
187 timersub(&now, &start_time, &res);
188 return (res.tv_sec) * 1000 + (res.tv_usec) / 1000;
192 #define assert(a, b, c, d) myassert(__FILE__, __LINE__, a, b, c, d) 193 #define assert1(a, b, c, d, e) myassert(__FILE__, __LINE__, a, b, c, d, e) 209 fprintf(
xml,
" time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000);
215 fprintf(
xml,
"</testcase>\n");
227 MyLog(
LOGA_INFO,
"Assertion failed, file %s, line %d, description: %s", filename,
228 lineno, description);
230 va_start(args, format);
231 vprintf(format, args);
235 description, filename, lineno);
238 MyLog(
LOGA_DEBUG,
"Assertion succeeded, file %s, line %d, description: %s",
239 filename, lineno, description);
247 for (i = 0; i < props->
count; ++i)
251 char* intformat =
"Property name %s value %d";
317 MyLog(
LOGA_DEBUG,
"In connected callback for client c, context %p\n", context);
323 MyLog(
LOGA_DEBUG,
"In c connect onFailure callback, context %p", context);
334 MyLog(
LOGA_DEBUG,
"In connect onSuccess callback for client c, context %p\n", context);
348 char* testname =
"test7";
366 sprintf(clientidc,
"paho-test9-7-c-%s",
"same");
371 MyLog(
LOGA_INFO,
"Starting Offline buffering 7 - many persisted messages");
372 fprintf(
xml,
"<testcase classname=\"test7\" name=\"%s\"", testname);
380 printf(
"Create starting\n");
384 long duration =
elapsed(start);
391 printf(
"Create finished after %ld ms\n", duration);
395 if ((cur_token = tokens) != NULL)
397 while (*cur_token != -1)
403 printf(
"%d messages restored\n", token_count);
429 while (!test7cReady && ++count < 10000)
435 assert(
"Count should be less than 10000", count < 10000,
"count was %d", count);
469 assert(
"Count should be less than 10000", count < 10000,
"count was %d", count);
476 MyLog(
LOGA_DEBUG,
"Now we can send some messages to be buffered by TCP");
479 #define PAYLOAD_LEN 500 482 for (i = 0; i < 50000; ++i)
487 sprintf(buf,
"QoS %d message", pubmsg.
qos);
508 assert(
"Count should be less than 10000", count < 10000,
"count was %d", count);
533 printf(
"%s\n", message);
537 int main(
int argc,
char** argv)
539 int* numtests = &
tests;
544 srand((
unsigned)
time(&randtime));
545 sprintf(
unique,
"%u", rand());
548 xml = fopen(
"TEST-test9.xml",
"w");
549 fprintf(
xml,
"<testsuite name=\"test9\" tests=\"%d\">\n", (
int)(
ARRAY_SIZE(
tests) - 1));
575 fprintf(
xml,
"</testsuite>\n");
enum MQTTPropertyCodes value
int test7(struct Options options)
int MQTTAsync_createWithOptions(MQTTAsync *handle, const char *serverURI, const char *clientId, int persistence_type, void *persistence_context, MQTTAsync_createOptions *options)
void test7cOnConnectSuccess(void *context, MQTTAsync_successData5 *response)
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&...args)
#define assert(a, b, c, d)
int sendWhileDisconnected
#define MQTTAsync_responseOptions_initializer
int MQTTAsync_disconnect(MQTTAsync handle, const MQTTAsync_disconnectOptions *options)
int MQTTAsync_setCallbacks(MQTTAsync handle, void *context, MQTTAsync_connectionLost *cl, MQTTAsync_messageArrived *ma, MQTTAsync_deliveryComplete *dc)
size_t strftime(char *str, size_t count, const char *format, const std::tm *time)
void MQTTAsync_free(void *memory)
int MQTTProperty_getType(enum MQTTPropertyCodes value)
void MQTTAsync_freeMessage(MQTTAsync_message **message)
int MQTTAsync_setConnected(MQTTAsync handle, void *context, MQTTAsync_connected *connected)
void handleTrace(enum MQTTASYNC_TRACE_LEVELS level, char *message)
std::tm localtime(std::time_t time)
void MQTTAsync_setTraceCallback(MQTTAsync_traceCallback *callback)
int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions *options)
int test7_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
void MySleep(long milliseconds)
int test7_messages_received
#define MQTTAsync_willOptions_initializer
#define MQTTAsync_connectOptions_initializer5
int MQTTAsync_getPendingTokens(MQTTAsync handle, MQTTAsync_token **tokens)
void MyLog(int LOGA_level, char *format,...)
void getopts(int argc, char **argv)
const char * MQTTPropertyName(enum MQTTPropertyCodes value)
MQTTAsync_onFailure5 * onFailure5
START_TIME_TYPE start_clock(void)
enum MQTTPropertyCodes identifier
struct MQTTAsync_willOptions::@54 payload
void myassert(char *filename, int lineno, char *description, int value, char *format,...)
#define MQTTAsync_createOptions_initializer
void write_test_result(void)
long elapsed(START_TIME_TYPE start_time)
MQTTAsync_willOptions * will
#define MQTTCLIENT_PERSISTENCE_DEFAULT
void MQTTAsync_destroy(MQTTAsync *handle)
void test7cConnected(void *context, char *cause)
START_TIME_TYPE global_start_time
#define MQTTASYNC_SUCCESS
void MQTTAsync_setTraceLevel(enum MQTTASYNC_TRACE_LEVELS level)
int MQTTAsync_sendMessage(MQTTAsync handle, const char *destinationName, const MQTTAsync_message *message, MQTTAsync_responseOptions *response)
void test7cOnConnectFailure(void *context, MQTTAsync_failureData5 *response)
int test7_will_message_received
void logProperties(MQTTProperties *props)
int allowDisconnectedSendAtAnyTime
int main(int argc, char **argv)
#define MQTTAsync_message_initializer
MQTTAsync_onSuccess5 * onSuccess5