27 #if !defined(_WINDOWS) 29 #include <sys/socket.h> 35 #define setenv(a, b, c) _putenv_s(a, b) 38 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) 72 if (strcmp(argv[count],
"--test_no") == 0)
79 else if (strcmp(argv[count],
"--connection") == 0)
89 else if (strcmp(argv[count],
"--haconnections") == 0)
93 char* tok = strtok(argv[count],
" ");
101 tok = strtok(NULL,
" ");
107 else if (strcmp(argv[count],
"--MQTTversion") == 0)
117 else if (strcmp(argv[count],
"--iterations") == 0)
124 else if (strcmp(argv[count],
"--verbose") == 0)
127 printf(
"\nSetting verbose on\n");
138 #include <sys/timeb.h> 143 #if defined(_WIN32) || defined(_WINDOWS) 153 #if defined(_WIN32) || defined(_WINDOWS) 157 gettimeofday(&ts, NULL);
158 localtime_r(&ts.tv_sec, &timeinfo);
160 strftime(msg_buf, 80,
"%Y%m%d %H%M%S", &timeinfo);
162 #if defined(_WIN32) || defined(_WINDOWS) 163 sprintf(&msg_buf[strlen(msg_buf)],
".%.3hu ", ts.millitm);
165 sprintf(&msg_buf[strlen(msg_buf)],
".%.3lu ", ts.tv_usec / 1000);
168 va_start(args, format);
169 vsnprintf(&msg_buf[strlen(msg_buf)],
sizeof(msg_buf) - strlen(msg_buf), format, args);
172 printf(
"%s\n", msg_buf);
179 #if defined(WIN32) || defined(WIN64) 182 usleep(milliseconds*1000);
186 #if defined(WIN32) || defined(_WINDOWS) 187 #define START_TIME_TYPE DWORD 188 static DWORD start_time = 0;
191 return GetTickCount();
194 #define START_TIME_TYPE struct timespec 197 static struct timespec start;
198 clock_gettime(CLOCK_REALTIME, &start);
202 #define START_TIME_TYPE struct timeval 206 struct timeval start_time;
207 gettimeofday(&start_time, NULL);
216 return GetTickCount() - start_time;
220 long elapsed(
struct timespec start)
222 struct timespec now, res;
224 clock_gettime(CLOCK_REALTIME, &now);
225 ntimersub(now, start, res);
226 return (res.tv_sec)*1000L + (res.tv_nsec)/1000000L;
231 struct timeval now, res;
233 gettimeofday(&now, NULL);
234 timersub(&now, &start_time, &res);
235 return (res.tv_sec)*1000 + (res.tv_usec)/1000;
240 #define assert(a, b, c, d) myassert(__FILE__, __LINE__, a, b, c, d) 241 #define assert1(a, b, c, d, e) myassert(__FILE__, __LINE__, a, b, c, d, e) 255 fprintf(
xml,
" time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000);
261 fprintf(
xml,
"</testcase>\n");
273 MyLog(
LOGA_INFO,
"Assertion failed, file %s, line %d, description: %s\n", filename, lineno, description);
275 va_start(args, format);
276 vprintf(format, args);
280 description, filename, lineno);
283 MyLog(
LOGA_DEBUG,
"Assertion succeeded, file %s, line %d, description: %s", filename, lineno, description);
326 srand((
unsigned int)
time(0));
334 fprintf(
xml,
"<testcase classname=\"test1\" name=\"destroy mqtt while connecting\"");
337 MyLog(
LOGA_INFO,
"Starting test 1 - execute destroy while connecting");
382 int main(
int argc,
char** argv)
388 xml = fopen(
"TEST-test2.xml",
"w");
389 fprintf(
xml,
"<testsuite name=\"test1\" tests=\"%d\">\n", (
int)(
ARRAY_SIZE(
tests) - 1));
391 setenv(
"MQTT_C_CLIENT_TRACE",
"ON", 1);
392 setenv(
"MQTT_C_CLIENT_TRACE_LEVEL",
"ERROR", 0);
414 fprintf(
xml,
"</testsuite>\n");
enum MQTTPropertyCodes value
START_TIME_TYPE start_clock(void)
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&...args)
#define MQTTCLIENT_SUCCESS
int MQTTClient_connect(MQTTClient handle, MQTTClient_connectOptions *options)
int Thread_lock_mutex(mutex_type mutex)
void unlock_mutex(mutex_type amutex)
size_t strftime(char *str, size_t count, const char *format, const std::tm *time)
void write_test_result(void)
#define MQTTClient_willOptions_initializer
START_TIME_TYPE global_start_time
int main(int argc, char **argv)
int Thread_unlock_mutex(mutex_type mutex)
void lock_mutex(mutex_type amutex)
long elapsed(START_TIME_TYPE start_time)
void MyLog(int LOGA_level, char *format,...)
void MQTTClient_destroy(MQTTClient *handle)
void MySleep(long milliseconds)
thread_return_type WINAPI test1_destroy(void *n)
void getopts(int argc, char **argv)
#define thread_return_type
#define MQTTCLIENT_PERSISTENCE_NONE
void myassert(char *filename, int lineno, char *description, int value, char *format,...)
#define MQTTClient_connectOptions_initializer
thread_type Thread_start(thread_fn fn, void *parameter)
int test1(struct Options options)
int MQTTClient_create(MQTTClient *handle, const char *serverURI, const char *clientId, int persistence_type, void *persistence_context)
#define MQTTVERSION_DEFAULT
MQTTClient_willOptions * will
#define assert(a, b, c, d)