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 "tcp://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) 240 fprintf(
xml,
" time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000);
246 fprintf(
xml,
"</testcase>\n");
258 MyLog(
LOGA_INFO,
"Assertion failed, file %s, line %d, description: %s\n", filename, lineno, description);
260 va_start(args, format);
261 vprintf(format, args);
265 description, filename, lineno);
268 MyLog(
LOGA_DEBUG,
"Assertion succeeded, file %s, line %d, description: %s", filename, lineno, description);
285 fprintf(
xml,
"<testcase classname=\"test1\" name=\"sessionPresent\"");
389 MyLog(
LOGA_DEBUG,
"Callback: %d message received on topic %s is %.*s.",
398 char* testname =
"test2";
404 char*
topics[2] = {
"test_topic",
"nosubscribe"};
405 int qoss[2] = {2, 2};
407 fprintf(
xml,
"<testcase classname=\"test1\" name=\"bad return code from subscribe\"");
408 MyLog(
LOGA_INFO,
"Starting test 2 - bad return code from subscribe");
443 assert(
"0x80 from subscribe", rc == 0x80,
"rc was %d", rc);
447 assert(
"Correct returned qos from subscribe", qoss[0] == 2,
"qos 0 was %d", qoss[0]);
448 assert(
"Correct returned qos from subscribe", qoss[1] == 0x80,
"qos 0 was %d", qoss[0]);
465 int main(
int argc,
char** argv)
471 xml = fopen(
"TEST-MQTT4sync.xml",
"w");
472 fprintf(
xml,
"<testsuite name=\"test-mqtt4sync\" tests=\"%d\">\n", (
int)(
ARRAY_SIZE(
tests) - 1));
474 setenv(
"MQTT_C_CLIENT_TRACE",
"ON", 1);
475 setenv(
"MQTT_C_CLIENT_TRACE_LEVEL",
"ERROR", 1);
495 fprintf(
xml,
"</testsuite>\n");
void MyLog(int LOGA_level, char *format,...)
MQTTClient_message test2_pubmsg
START_TIME_TYPE global_start_time
enum MQTTPropertyCodes value
void getopts(int argc, char **argv)
void write_test_result(void)
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&...args)
#define MQTTCLIENT_SUCCESS
struct MQTTClient_connectOptions::@57 returned
int MQTTClient_connect(MQTTClient handle, MQTTClient_connectOptions *options)
int MQTTClient_disconnect(MQTTClient handle, int timeout)
int test2(struct Options options)
size_t strftime(char *str, size_t count, const char *format, const std::tm *time)
std::tm localtime(std::time_t time)
void test2_deliveryComplete(void *context, MQTTClient_deliveryToken dt)
#define MQTTClient_message_initializer
#define MQTTClient_willOptions_initializer
int test2_deliveryCompleted
int MQTTClient_setCallbacks(MQTTClient handle, void *context, MQTTClient_connectionLost *cl, MQTTClient_messageArrived *ma, MQTTClient_deliveryComplete *dc)
#define assert(a, b, c, d)
int MQTTClient_unsubscribe(MQTTClient handle, const char *topic)
void MQTTClient_freeMessage(MQTTClient_message **message)
START_TIME_TYPE start_clock(void)
int main(int argc, char **argv)
void MQTTClient_destroy(MQTTClient *handle)
int test2_messageArrived(void *context, char *topicName, int topicLen, MQTTClient_message *m)
#define MQTTCLIENT_PERSISTENCE_DEFAULT
int MQTTClient_subscribe(MQTTClient handle, const char *topic, int qos)
long elapsed(START_TIME_TYPE start_time)
void MQTTClient_free(void *memory)
#define MQTTClient_connectOptions_initializer
int MQTTClient_subscribeMany(MQTTClient handle, int count, char *const *topic, int *qos)
int MQTTClient_deliveryToken
int test1(struct Options options)
void myassert(char *filename, int lineno, char *description, int value, char *format,...)
volatile int test2_arrivedcount
int MQTTClient_create(MQTTClient *handle, const char *serverURI, const char *clientId, int persistence_type, void *persistence_context)
MQTTClient_willOptions * will