Commit b880d34f authored by Ian Craggs's avatar Ian Craggs

Windows CMake build additions and corrections

parent 526ffc18
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
PROJECT("paho" C) PROJECT("paho" C)
CMAKE_MINIMUM_REQUIRED(VERSION 3.0) CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
MESSAGE(STATUS "CMake version: " ${CMAKE_VERSION}) MESSAGE(STATUS "CMake version: " ${CMAKE_VERSION})
MESSAGE(STATUS "CMake system name: " ${CMAKE_SYSTEM_NAME})
## build settings ## build settings
SET(PAHO_VERSION_MAJOR 1) SET(PAHO_VERSION_MAJOR 1)
......
setlocal
mkdir build.paho
cd build.paho
call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64
cmake -G "NMake Makefiles" -DPAHO_WITH_SSL=FALSE -DPAHO_BUILD_DOCUMENTATION=FALSE -DPAHO_BUILD_SAMPLES=TRUE -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=TRUE ..
nmake
cd ..
endlocal
...@@ -28,6 +28,10 @@ CONFIGURE_FILE(VersionInfo.h.in ...@@ -28,6 +28,10 @@ CONFIGURE_FILE(VersionInfo.h.in
@ONLY @ONLY
) )
IF (WIN32)
ADD_DEFINITIONS(/DCMAKE_BUILD /D_CRT_SECURE_NO_DEPRECATE)
ENDIF()
IF (PAHO_WITH_SSL) IF (PAHO_WITH_SSL)
SET(OPENSSL_LIB_SEARCH_PATH "" CACHE PATH "Directory containing OpenSSL libraries") SET(OPENSSL_LIB_SEARCH_PATH "" CACHE PATH "Directory containing OpenSSL libraries")
SET(OPENSSL_INC_SEARCH_PATH "" CACHE PATH "Directory containing OpenSSL includes") SET(OPENSSL_INC_SEARCH_PATH "" CACHE PATH "Directory containing OpenSSL includes")
...@@ -95,7 +99,12 @@ SET_PROPERTY(TARGET common_obj PROPERTY POSITION_INDEPENDENT_CODE ON) ...@@ -95,7 +99,12 @@ SET_PROPERTY(TARGET common_obj PROPERTY POSITION_INDEPENDENT_CODE ON)
IF (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") IF (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
SET_PROPERTY(TARGET common_obj PROPERTY SET_PROPERTY(TARGET common_obj PROPERTY
COMPILE_DEFINITIONS "OSX=1") COMPILE_DEFINITIONS "OSX=1")
ENDIF (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") ENDIF ()
## IF (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
## MESSAGE(STATUS "Setting secure_no_warnings")
## SET_PROPERTY(TARGET common_obj PROPERTY
## COMPILE_DEFINITIONS "_CRT_SECURE_NO_DEPRECATE")
## ENDIF ()
ADD_EXECUTABLE(MQTTVersion MQTTVersion.c) ADD_EXECUTABLE(MQTTVersion MQTTVersion.c)
...@@ -165,9 +174,11 @@ IF (PAHO_WITH_SSL) ...@@ -165,9 +174,11 @@ IF (PAHO_WITH_SSL)
SET_PROPERTY(TARGET common_ssl_obj PROPERTY POSITION_INDEPENDENT_CODE ON) SET_PROPERTY(TARGET common_ssl_obj PROPERTY POSITION_INDEPENDENT_CODE ON)
IF (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") IF (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
SET_PROPERTY(TARGET common_ssl_obj PROPERTY COMPILE_DEFINITIONS "OPENSSL=1;OSX=1") SET_PROPERTY(TARGET common_ssl_obj PROPERTY COMPILE_DEFINITIONS "OPENSSL=1;OSX=1")
ELSE (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") ELSIF (WIN32)
SET_PROPERTY(TARGET common_ssl_obj PROPERTY COMPILE_DEFINITIONS "OPENSSL=1;_CRT_SECURE_NO_WARNINGS")
ELSE ()
SET_PROPERTY(TARGET common_ssl_obj PROPERTY COMPILE_DEFINITIONS "OPENSSL=1") SET_PROPERTY(TARGET common_ssl_obj PROPERTY COMPILE_DEFINITIONS "OPENSSL=1")
ENDIF (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") ENDIF ()
ADD_LIBRARY(paho-mqtt3cs SHARED $<TARGET_OBJECTS:common_ssl_obj> MQTTClient.c SSLSocket.c) ADD_LIBRARY(paho-mqtt3cs SHARED $<TARGET_OBJECTS:common_ssl_obj> MQTTClient.c SSLSocket.c)
ADD_LIBRARY(paho-mqtt3as SHARED $<TARGET_OBJECTS:common_ssl_obj> MQTTAsync.c SSLSocket.c) ADD_LIBRARY(paho-mqtt3as SHARED $<TARGET_OBJECTS:common_ssl_obj> MQTTAsync.c SSLSocket.c)
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
* *
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution. * and Eclipse Distribution License v1.0 which accompany this distribution.
* *
* The Eclipse Public License is available at * The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at * and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php. * http://www.eclipse.org/org/documents/edl-v10.php.
* *
* Contributors: * Contributors:
...@@ -106,7 +106,7 @@ int Socket_error(char* aString, int sock) ...@@ -106,7 +106,7 @@ int Socket_error(char* aString, int sock)
if (errno != EINTR && errno != EAGAIN && errno != EINPROGRESS && errno != EWOULDBLOCK) if (errno != EINTR && errno != EAGAIN && errno != EINPROGRESS && errno != EWOULDBLOCK)
{ {
if (strcmp(aString, "shutdown") != 0 || (errno != ENOTCONN && errno != ECONNRESET)) if (strcmp(aString, "shutdown") != 0 || (errno != ENOTCONN && errno != ECONNRESET))
Log(TRACE_MINIMUM, -1, "Socket error %s in %s for socket %d", strerror(errno), aString, sock); Log(TRACE_MINIMUM, -1, "Socket error %s(%d) in %s for socket %d", strerror(errno), errno, aString, sock);
} }
FUNC_EXIT_RC(errno); FUNC_EXIT_RC(errno);
return errno; return errno;
...@@ -499,7 +499,7 @@ exit: ...@@ -499,7 +499,7 @@ exit:
/** /**
* Add a socket to the pending write list, so that it is checked for writing in select. This is used * Add a socket to the pending write list, so that it is checked for writing in select. This is used
* in connect processing when the TCP connect is incomplete, as we need to check the socket for both * in connect processing when the TCP connect is incomplete, as we need to check the socket for both
* ready to read and write states. * ready to read and write states.
* @param socket the socket to add * @param socket the socket to add
*/ */
void Socket_addPendingWrite(int socket) void Socket_addPendingWrite(int socket)
...@@ -719,13 +719,13 @@ int Socket_continueWrite(int socket) ...@@ -719,13 +719,13 @@ int Socket_continueWrite(int socket)
FUNC_ENTRY; FUNC_ENTRY;
pw = SocketBuffer_getWrite(socket); pw = SocketBuffer_getWrite(socket);
#if defined(OPENSSL) #if defined(OPENSSL)
if (pw->ssl) if (pw->ssl)
{ {
rc = SSLSocket_continueWrite(pw); rc = SSLSocket_continueWrite(pw);
goto exit; goto exit;
} }
#endif #endif
for (i = 0; i < pw->count; ++i) for (i = 0; i < pw->count; ++i)
...@@ -757,7 +757,7 @@ int Socket_continueWrite(int socket) ...@@ -757,7 +757,7 @@ int Socket_continueWrite(int socket)
if (pw->frees[i]) if (pw->frees[i])
free(pw->iovecs[i].iov_base); free(pw->iovecs[i].iov_base);
} }
Log(TRACE_MIN, -1, "ContinueWrite: partial write now complete for socket %d", socket); Log(TRACE_MIN, -1, "ContinueWrite: partial write now complete for socket %d", socket);
} }
else else
Log(TRACE_MIN, -1, "ContinueWrite wrote +%lu bytes on socket %d", bytes, socket); Log(TRACE_MIN, -1, "ContinueWrite wrote +%lu bytes on socket %d", bytes, socket);
...@@ -795,7 +795,7 @@ int Socket_continueWrites(fd_set* pwset) ...@@ -795,7 +795,7 @@ int Socket_continueWrites(fd_set* pwset)
ListNextElement(s.write_pending, &curpending); ListNextElement(s.write_pending, &curpending);
} }
curpending = s.write_pending->current; curpending = s.write_pending->current;
if (writecomplete) if (writecomplete)
(*writecomplete)(socket); (*writecomplete)(socket);
} }
...@@ -828,7 +828,7 @@ char* Socket_getaddrname(struct sockaddr* sa, int sock) ...@@ -828,7 +828,7 @@ char* Socket_getaddrname(struct sockaddr* sa, int sock)
#if defined(WIN32) || defined(WIN64) #if defined(WIN32) || defined(WIN64)
int buflen = ADDRLEN*2; int buflen = ADDRLEN*2;
wchar_t buf[ADDRLEN*2]; wchar_t buf[ADDRLEN*2];
if (WSAAddressToString(sa, sizeof(struct sockaddr_in6), NULL, buf, (LPDWORD)&buflen) == SOCKET_ERROR) if (WSAAddressToStringW(sa, sizeof(struct sockaddr_in6), NULL, buf, (LPDWORD)&buflen) == SOCKET_ERROR)
Socket_error("WSAAddressToString", sock); Socket_error("WSAAddressToString", sock);
else else
wcstombs(addr_string, buf, sizeof(addr_string)); wcstombs(addr_string, buf, sizeof(addr_string));
...@@ -874,4 +874,3 @@ int main(int argc, char *argv[]) ...@@ -874,4 +874,3 @@ int main(int argc, char *argv[])
} }
#endif #endif
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
* *
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution. * and Eclipse Distribution License v1.0 which accompany this distribution.
* *
* The Eclipse Public License is available at * The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at * and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php. * http://www.eclipse.org/org/documents/edl-v10.php.
* *
* Contributors: * Contributors:
...@@ -25,12 +25,19 @@ ...@@ -25,12 +25,19 @@
#include <ws2tcpip.h> #include <ws2tcpip.h>
#define MAXHOSTNAMELEN 256 #define MAXHOSTNAMELEN 256
#if !defined(SSLSOCKET_H) #if !defined(SSLSOCKET_H)
#undef EAGAIN
#define EAGAIN WSAEWOULDBLOCK #define EAGAIN WSAEWOULDBLOCK
#undef EINTR
#define EINTR WSAEINTR #define EINTR WSAEINTR
#undef EINPROGRESS
#define EINPROGRESS WSAEINPROGRESS #define EINPROGRESS WSAEINPROGRESS
#undef EWOULDBLOCK
#define EWOULDBLOCK WSAEWOULDBLOCK #define EWOULDBLOCK WSAEWOULDBLOCK
#undef ENOTCONN
#define ENOTCONN WSAENOTCONN #define ENOTCONN WSAENOTCONN
#undef ECONNRESET
#define ECONNRESET WSAECONNRESET #define ECONNRESET WSAECONNRESET
#undef ETIMEDOUT
#define ETIMEDOUT WAIT_TIMEOUT #define ETIMEDOUT WAIT_TIMEOUT
#endif #endif
#define ioctl ioctlsocket #define ioctl ioctlsocket
......
...@@ -90,6 +90,8 @@ mutex_type Thread_create_mutex(void) ...@@ -90,6 +90,8 @@ mutex_type Thread_create_mutex(void)
FUNC_ENTRY; FUNC_ENTRY;
#if defined(WIN32) || defined(WIN64) #if defined(WIN32) || defined(WIN64)
mutex = CreateMutex(NULL, 0, NULL); mutex = CreateMutex(NULL, 0, NULL);
if (mutex == NULL)
rc = GetLastError();
#else #else
mutex = malloc(sizeof(pthread_mutex_t)); mutex = malloc(sizeof(pthread_mutex_t));
rc = pthread_mutex_init(mutex, NULL); rc = pthread_mutex_init(mutex, NULL);
...@@ -100,8 +102,7 @@ mutex_type Thread_create_mutex(void) ...@@ -100,8 +102,7 @@ mutex_type Thread_create_mutex(void)
/** /**
* Lock a mutex which has already been created, block until ready * Lock a mutex which has alrea
* @param mutex the mutex
* @return completion code, 0 is success * @return completion code, 0 is success
*/ */
int Thread_lock_mutex(mutex_type mutex) int Thread_lock_mutex(mutex_type mutex)
......
...@@ -24,6 +24,10 @@ INCLUDE_DIRECTORIES( ...@@ -24,6 +24,10 @@ INCLUDE_DIRECTORIES(
${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}
) )
IF (WIN32)
ADD_DEFINITIONS(/DCMAKE_BUILD /D_CRT_SECURE_NO_DEPRECATE)
ENDIF()
# sample files c # sample files c
ADD_EXECUTABLE(paho_c_pub paho_c_pub.c) ADD_EXECUTABLE(paho_c_pub paho_c_pub.c)
ADD_EXECUTABLE(paho_c_sub paho_c_sub.c) ADD_EXECUTABLE(paho_c_sub paho_c_sub.c)
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
* *
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution. * and Eclipse Distribution License v1.0 which accompany this distribution.
* *
* The Eclipse Public License is available at * The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at * and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php. * http://www.eclipse.org/org/documents/edl-v10.php.
* *
* Contributors: * Contributors:
...@@ -81,7 +81,7 @@ int main(int argc, char* argv[]) ...@@ -81,7 +81,7 @@ int main(int argc, char* argv[])
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
pubmsg.payload = PAYLOAD; pubmsg.payload = PAYLOAD;
pubmsg.payloadlen = strlen(PAYLOAD); pubmsg.payloadlen = (int)strlen(PAYLOAD);
pubmsg.qos = QOS; pubmsg.qos = QOS;
pubmsg.retained = 0; pubmsg.retained = 0;
deliveredtoken = 0; deliveredtoken = 0;
...@@ -94,4 +94,3 @@ int main(int argc, char* argv[]) ...@@ -94,4 +94,3 @@ int main(int argc, char* argv[])
MQTTClient_destroy(&client); MQTTClient_destroy(&client);
return rc; return rc;
} }
...@@ -3,27 +3,27 @@ ...@@ -3,27 +3,27 @@
* *
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution. * and Eclipse Distribution License v1.0 which accompany this distribution.
* *
* The Eclipse Public License is available at * The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at * and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php. * http://www.eclipse.org/org/documents/edl-v10.php.
* *
* Contributors: * Contributors:
* Ian Craggs - initial contribution * Ian Craggs - initial contribution
* Guilherme Maciel Ferreira - add keep alive option * Guilherme Maciel Ferreira - add keep alive option
*******************************************************************************/ *******************************************************************************/
/* /*
stdin publisher stdin publisher
compulsory parameters: compulsory parameters:
--topic topic to publish on --topic topic to publish on
defaulted parameters: defaulted parameters:
--host localhost --host localhost
--port 1883 --port 1883
--qos 0 --qos 0
...@@ -31,10 +31,10 @@ ...@@ -31,10 +31,10 @@
--clientid stdin-publisher-async --clientid stdin-publisher-async
--maxdatalen 100 --maxdatalen 100
--keepalive 10 --keepalive 10
--userid none --userid none
--password none --password none
*/ */
#include "MQTTAsync.h" #include "MQTTAsync.h"
...@@ -125,7 +125,7 @@ void myconnect(MQTTAsync* client); ...@@ -125,7 +125,7 @@ void myconnect(MQTTAsync* client);
void onConnectFailure(void* context, MQTTAsync_failureData* response) void onConnectFailure(void* context, MQTTAsync_failureData* response)
{ {
printf("Connect failed, rc %d\n", response ? response->code : -1); printf("Connect failed, rc %d\n", response ? response->code : -1);
connected = -1; connected = -1;
MQTTAsync client = (MQTTAsync)context; MQTTAsync client = (MQTTAsync)context;
myconnect(client); myconnect(client);
...@@ -135,8 +135,7 @@ void onConnectFailure(void* context, MQTTAsync_failureData* response) ...@@ -135,8 +135,7 @@ void onConnectFailure(void* context, MQTTAsync_failureData* response)
void onConnect(void* context, MQTTAsync_successData* response) void onConnect(void* context, MQTTAsync_successData* response)
{ {
MQTTAsync client = (MQTTAsync)context; MQTTAsync client = (MQTTAsync)context;
int rc;
printf("Connected\n"); printf("Connected\n");
connected = 1; connected = 1;
} }
...@@ -172,7 +171,7 @@ static int published = 0; ...@@ -172,7 +171,7 @@ static int published = 0;
void onPublishFailure(void* context, MQTTAsync_failureData* response) void onPublishFailure(void* context, MQTTAsync_failureData* response)
{ {
printf("Publish failed, rc %d\n", response ? -1 : response->code); printf("Publish failed, rc %d\n", response ? -1 : response->code);
published = -1; published = -1;
} }
...@@ -223,13 +222,13 @@ int main(int argc, char** argv) ...@@ -223,13 +222,13 @@ int main(int argc, char** argv)
if (argc < 2) if (argc < 2)
usage(); usage();
getopts(argc, argv); getopts(argc, argv);
sprintf(url, "%s:%s", opts.host, opts.port); sprintf(url, "%s:%s", opts.host, opts.port);
if (opts.verbose) if (opts.verbose)
printf("URL is %s\n", url); printf("URL is %s\n", url);
topic = argv[1]; topic = argv[1];
printf("Using topic %s\n", topic); printf("Using topic %s\n", topic);
...@@ -244,13 +243,13 @@ int main(int argc, char** argv) ...@@ -244,13 +243,13 @@ int main(int argc, char** argv)
myconnect(&client); myconnect(&client);
buffer = malloc(opts.maxdatalen); buffer = malloc(opts.maxdatalen);
while (!toStop) while (!toStop)
{ {
int data_len = 0; int data_len = 0;
int delim_len = 0; int delim_len = 0;
delim_len = strlen(opts.delimiter); delim_len = (int)strlen(opts.delimiter);
do do
{ {
buffer[data_len++] = getchar(); buffer[data_len++] = getchar();
...@@ -261,7 +260,7 @@ int main(int argc, char** argv) ...@@ -261,7 +260,7 @@ int main(int argc, char** argv)
break; break;
} }
} while (data_len < opts.maxdatalen); } while (data_len < opts.maxdatalen);
if (opts.verbose) if (opts.verbose)
printf("Publishing data of length %d\n", data_len); printf("Publishing data of length %d\n", data_len);
pub_opts.onSuccess = onPublish; pub_opts.onSuccess = onPublish;
...@@ -272,9 +271,9 @@ int main(int argc, char** argv) ...@@ -272,9 +271,9 @@ int main(int argc, char** argv)
} }
while (rc != MQTTASYNC_SUCCESS); while (rc != MQTTASYNC_SUCCESS);
} }
printf("Stopping\n"); printf("Stopping\n");
free(buffer); free(buffer);
disc_opts.onSuccess = onDisconnect; disc_opts.onSuccess = onDisconnect;
...@@ -299,7 +298,7 @@ int main(int argc, char** argv) ...@@ -299,7 +298,7 @@ int main(int argc, char** argv)
void getopts(int argc, char** argv) void getopts(int argc, char** argv)
{ {
int count = 2; int count = 2;
while (count < argc) while (count < argc)
{ {
if (strcmp(argv[count], "--retained") == 0) if (strcmp(argv[count], "--retained") == 0)
...@@ -380,6 +379,5 @@ void getopts(int argc, char** argv) ...@@ -380,6 +379,5 @@ void getopts(int argc, char** argv)
} }
count++; count++;
} }
}
}
...@@ -3,36 +3,36 @@ ...@@ -3,36 +3,36 @@
* *
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution. * and Eclipse Distribution License v1.0 which accompany this distribution.
* *
* The Eclipse Public License is available at * The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at * and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php. * http://www.eclipse.org/org/documents/edl-v10.php.
* *
* Contributors: * Contributors:
* Ian Craggs - initial contribution * Ian Craggs - initial contribution
*******************************************************************************/ *******************************************************************************/
/* /*
stdin publisher stdin publisher
compulsory parameters: compulsory parameters:
--topic topic to publish on --topic topic to publish on
defaulted parameters: defaulted parameters:
--host localhost --host localhost
--port 1883 --port 1883
--qos 0 --qos 0
--delimiters \n --delimiters \n
--clientid stdin_publisher --clientid stdin_publisher
--maxdatalen 100 --maxdatalen 100
--userid none --userid none
--password none --password none
*/ */
#include "MQTTClient.h" #include "MQTTClient.h"
...@@ -128,13 +128,13 @@ int main(int argc, char** argv) ...@@ -128,13 +128,13 @@ int main(int argc, char** argv)
if (argc < 2) if (argc < 2)
usage(); usage();
getopts(argc, argv); getopts(argc, argv);
sprintf(url, "%s:%s", opts.host, opts.port); sprintf(url, "%s:%s", opts.host, opts.port);
if (opts.verbose) if (opts.verbose)
printf("URL is %s\n", url); printf("URL is %s\n", url);
topic = argv[1]; topic = argv[1];
printf("Using topic %s\n", topic); printf("Using topic %s\n", topic);
...@@ -152,17 +152,17 @@ int main(int argc, char** argv) ...@@ -152,17 +152,17 @@ int main(int argc, char** argv)
conn_opts.password = opts.password; conn_opts.password = opts.password;
ssl_opts.enableServerCertAuth = 0; ssl_opts.enableServerCertAuth = 0;
conn_opts.ssl = &ssl_opts; conn_opts.ssl = &ssl_opts;
myconnect(&client, &conn_opts); myconnect(&client, &conn_opts);
buffer = malloc(opts.maxdatalen); buffer = malloc(opts.maxdatalen);
while (!toStop) while (!toStop)
{ {
int data_len = 0; int data_len = 0;
int delim_len = 0; int delim_len = 0;
delim_len = strlen(opts.delimiter); delim_len = (int)strlen(opts.delimiter);
do do
{ {
buffer[data_len++] = getchar(); buffer[data_len++] = getchar();
...@@ -173,7 +173,7 @@ int main(int argc, char** argv) ...@@ -173,7 +173,7 @@ int main(int argc, char** argv)
break; break;
} }
} while (data_len < opts.maxdatalen); } while (data_len < opts.maxdatalen);
if (opts.verbose) if (opts.verbose)
printf("Publishing data of length %d\n", data_len); printf("Publishing data of length %d\n", data_len);
rc = MQTTClient_publish(client, topic, data_len, buffer, opts.qos, opts.retained, NULL); rc = MQTTClient_publish(client, topic, data_len, buffer, opts.qos, opts.retained, NULL);
...@@ -185,9 +185,9 @@ int main(int argc, char** argv) ...@@ -185,9 +185,9 @@ int main(int argc, char** argv)
if (opts.qos > 0) if (opts.qos > 0)
MQTTClient_yield(); MQTTClient_yield();
} }
printf("Stopping\n"); printf("Stopping\n");
free(buffer); free(buffer);
MQTTClient_disconnect(client, 0); MQTTClient_disconnect(client, 0);
...@@ -200,7 +200,7 @@ int main(int argc, char** argv) ...@@ -200,7 +200,7 @@ int main(int argc, char** argv)
void getopts(int argc, char** argv) void getopts(int argc, char** argv)
{ {
int count = 2; int count = 2;
while (count < argc) while (count < argc)
{ {
if (strcmp(argv[count], "--retained") == 0) if (strcmp(argv[count], "--retained") == 0)
...@@ -274,6 +274,5 @@ void getopts(int argc, char** argv) ...@@ -274,6 +274,5 @@ void getopts(int argc, char** argv)
} }
count++; count++;
} }
}
}
...@@ -6,7 +6,7 @@ SET(MQTT_SSL_HOSTNAME "localhost" CACHE STRING "Hostname of a test SSL MQTT brok ...@@ -6,7 +6,7 @@ SET(MQTT_SSL_HOSTNAME "localhost" CACHE STRING "Hostname of a test SSL MQTT brok
SET(CERTDIR $ENV{TRAVIS_BUILD_DIR}/test/ssl ) SET(CERTDIR $ENV{TRAVIS_BUILD_DIR}/test/ssl )
IF (WIN32) IF (WIN32)
ADD_DEFINITIONS(/DCMAKE_BUILD) ADD_DEFINITIONS(/DCMAKE_BUILD /D_CRT_SECURE_NO_WARNINGS)
ENDIF() ENDIF()
...@@ -22,7 +22,7 @@ TARGET_LINK_LIBRARIES( ...@@ -22,7 +22,7 @@ TARGET_LINK_LIBRARIES(
IF (WIN32) IF (WIN32)
ADD_CUSTOM_COMMAND( ADD_CUSTOM_COMMAND(
TARGET test1 PRE_BUILD TARGET test1 PRE_BUILD
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/dll-copy.cmake COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/dll-copy.cmake
COMMENT "Copying DLLs to test directory" COMMENT "Copying DLLs to test directory"
) )
...@@ -313,5 +313,3 @@ ADD_TEST( ...@@ -313,5 +313,3 @@ ADD_TEST(
NAME test9-5-offline-buffering-max-buffered NAME test9-5-offline-buffering-max-buffered
COMMAND test9 "--test_no" "5" "--connection" ${MQTT_TEST_BROKER} "--proxy_connection" ${MQTT_TEST_PROXY} COMMAND test9 "--test_no" "5" "--connection" ${MQTT_TEST_BROKER} "--proxy_connection" ${MQTT_TEST_PROXY}
) )
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
* *
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution. * and Eclipse Distribution License v1.0 which accompany this distribution.
* *
* The Eclipse Public License is available at * The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at * and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php. * http://www.eclipse.org/org/documents/edl-v10.php.
* *
* Contributors: * Contributors:
...@@ -34,21 +34,13 @@ ...@@ -34,21 +34,13 @@
#include <stdlib.h> #include <stdlib.h>
#if !defined(_WINDOWS) #if !defined(_WINDOWS)
#include <sys/time.h> #include <sys/time.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#else #else
#include <winsock2.h> #include <windows.h>
#include <ws2tcpip.h> #define setenv(a, b, c) _putenv_s(a, b)
#define MAXHOSTNAMELEN 256
#define EAGAIN WSAEWOULDBLOCK
#define EINTR WSAEINTR
#define EINPROGRESS WSAEINPROGRESS
#define EWOULDBLOCK WSAEWOULDBLOCK
#define ENOTCONN WSAENOTCONN
#define ECONNRESET WSAECONNRESET
#define setenv(a, b, c) _putenv_s(a, b)
#endif #endif
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
...@@ -84,7 +76,7 @@ struct Options ...@@ -84,7 +76,7 @@ struct Options
void getopts(int argc, char** argv) void getopts(int argc, char** argv)
{ {
int count = 1; int count = 1;
while (count < argc) while (count < argc)
{ {
if (strcmp(argv[count], "--test_no") == 0) if (strcmp(argv[count], "--test_no") == 0)
...@@ -171,7 +163,7 @@ void MyLog(int LOGA_level, char* format, ...) ...@@ -171,7 +163,7 @@ void MyLog(int LOGA_level, char* format, ...)
if (LOGA_level == LOGA_DEBUG && options.verbose == 0) if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
return; return;
ftime(&ts); ftime(&ts);
timeinfo = localtime(&ts.time); timeinfo = localtime(&ts.time);
strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo); strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo);
...@@ -259,11 +251,11 @@ void write_test_result(void) ...@@ -259,11 +251,11 @@ void write_test_result(void)
{ {
long duration = elapsed(global_start_time); long duration = elapsed(global_start_time);
fprintf(xml, " time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000); fprintf(xml, " time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000);
if (cur_output != output) if (cur_output != output)
{ {
fprintf(xml, "%s", output); fprintf(xml, "%s", output);
cur_output = output; cur_output = output;
} }
fprintf(xml, "</testcase>\n"); fprintf(xml, "</testcase>\n");
} }
...@@ -283,11 +275,11 @@ void myassert(char* filename, int lineno, char* description, int value, char* fo ...@@ -283,11 +275,11 @@ void myassert(char* filename, int lineno, char* description, int value, char* fo
vprintf(format, args); vprintf(format, args);
va_end(args); va_end(args);
cur_output += sprintf(cur_output, "<failure type=\"%s\">file %s, line %d </failure>\n", cur_output += sprintf(cur_output, "<failure type=\"%s\">file %s, line %d </failure>\n",
description, filename, lineno); description, filename, lineno);
} }
else else
MyLog(LOGA_DEBUG, "Assertion succeeded, file %s, line %d, description: %s", filename, lineno, description); MyLog(LOGA_DEBUG, "Assertion succeeded, file %s, line %d, description: %s", filename, lineno, description);
} }
...@@ -371,9 +363,9 @@ int test1(struct Options options) ...@@ -371,9 +363,9 @@ int test1(struct Options options)
global_start_time = start_clock(); global_start_time = start_clock();
failures = 0; failures = 0;
MyLog(LOGA_INFO, "Starting test 1 - single threaded client using receive"); MyLog(LOGA_INFO, "Starting test 1 - single threaded client using receive");
rc = MQTTClient_create(&c, options.connection, "single_threaded_test", rc = MQTTClient_create(&c, options.connection, "single_threaded_test",
MQTTCLIENT_PERSISTENCE_DEFAULT, NULL); MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc); assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);
if (rc != MQTTCLIENT_SUCCESS) if (rc != MQTTCLIENT_SUCCESS)
{ {
...@@ -485,7 +477,7 @@ void test2_sendAndReceive(MQTTClient* c, int qos, char* test_topic) ...@@ -485,7 +477,7 @@ void test2_sendAndReceive(MQTTClient* c, int qos, char* test_topic)
for (i = 1; i <= iterations; ++i) for (i = 1; i <= iterations; ++i)
{ {
if (i % 10 == 0) if (i % 10 == 0)
rc = MQTTClient_publish(c, test_topic, test2_pubmsg.payloadlen, test2_pubmsg.payload, rc = MQTTClient_publish(c, test_topic, test2_pubmsg.payloadlen, test2_pubmsg.payload,
test2_pubmsg.qos, test2_pubmsg.retained, NULL); test2_pubmsg.qos, test2_pubmsg.retained, NULL);
else else
rc = MQTTClient_publishMessage(c, test_topic, &test2_pubmsg, &dt); rc = MQTTClient_publishMessage(c, test_topic, &test2_pubmsg, &dt);
...@@ -507,7 +499,7 @@ void test2_sendAndReceive(MQTTClient* c, int qos, char* test_topic) ...@@ -507,7 +499,7 @@ void test2_sendAndReceive(MQTTClient* c, int qos, char* test_topic)
usleep(1000000L); usleep(1000000L);
#endif #endif
} }
assert("Message Arrived", wait_seconds > 0, assert("Message Arrived", wait_seconds > 0,
"Time out waiting for message %d\n", i ); "Time out waiting for message %d\n", i );
} }
if (qos > 0) if (qos > 0)
...@@ -515,7 +507,7 @@ void test2_sendAndReceive(MQTTClient* c, int qos, char* test_topic) ...@@ -515,7 +507,7 @@ void test2_sendAndReceive(MQTTClient* c, int qos, char* test_topic)
/* MQ Telemetry can send a message to a subscriber before the server has /* MQ Telemetry can send a message to a subscriber before the server has
completed the QoS 2 handshake with the publisher. For QoS 1 and 2, completed the QoS 2 handshake with the publisher. For QoS 1 and 2,
allow time for the final delivery complete callback before checking allow time for the final delivery complete callback before checking
that all expected callbacks have been made */ that all expected callbacks have been made */
wait_seconds = 10; wait_seconds = 10;
while ((test2_deliveryCompleted < iterations) && (wait_seconds-- > 0)) while ((test2_deliveryCompleted < iterations) && (wait_seconds-- > 0))
{ {
...@@ -526,8 +518,8 @@ void test2_sendAndReceive(MQTTClient* c, int qos, char* test_topic) ...@@ -526,8 +518,8 @@ void test2_sendAndReceive(MQTTClient* c, int qos, char* test_topic)
usleep(1000000L); usleep(1000000L);
#endif #endif
} }
assert("All Deliveries Complete", wait_seconds > 0, assert("All Deliveries Complete", wait_seconds > 0,
"Number of deliveryCompleted callbacks was %d\n", "Number of deliveryCompleted callbacks was %d\n",
test2_deliveryCompleted); test2_deliveryCompleted);
} }
} }
...@@ -645,7 +637,7 @@ int test3(struct Options options) ...@@ -645,7 +637,7 @@ int test3(struct Options options)
/* authorization failure (RC = 5) */ /* authorization failure (RC = 5) */
opts.username = "Admin"; opts.username = "Admin";
opts.password = "Admin"; opts.password = "Admin";
/*opts.will = &wopts; "Admin" not authorized to publish to Will topic by default /*opts.will = &wopts; "Admin" not authorized to publish to Will topic by default
opts.will->message = "will message"; opts.will->message = "will message";
opts.will->qos = 1; opts.will->qos = 1;
opts.will->retained = 0; opts.will->retained = 0;
...@@ -694,7 +686,7 @@ int test4_run(int qos) ...@@ -694,7 +686,7 @@ int test4_run(int qos)
int count = 3; int count = 3;
int i, rc; int i, rc;
failures = 0; failures = 0;
MyLog(LOGA_INFO, "Starting test 4 - persistence, qos %d", qos); MyLog(LOGA_INFO, "Starting test 4 - persistence, qos %d", qos);
MQTTClient_create(&c, options.connection, "xrctest1_test_4", MQTTCLIENT_PERSISTENCE_DEFAULT, NULL); MQTTClient_create(&c, options.connection, "xrctest1_test_4", MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
...@@ -724,7 +716,7 @@ int test4_run(int qos) ...@@ -724,7 +716,7 @@ int test4_run(int qos)
assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
return -1; return -1;
} }
/* subscribe so we can get messages back */ /* subscribe so we can get messages back */
rc = MQTTClient_subscribe(c, topic, subsqos); rc = MQTTClient_subscribe(c, topic, subsqos);
assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
...@@ -804,7 +796,7 @@ int test4_run(int qos) ...@@ -804,7 +796,7 @@ int test4_run(int qos)
MQTTClient_free(topicName); MQTTClient_free(topicName);
} }
} }
MQTTClient_yield(); /* allow any unfinished protocol exchanges to finish */ MQTTClient_yield(); /* allow any unfinished protocol exchanges to finish */
rc = MQTTClient_getPendingDeliveryTokens(c, &tokens); rc = MQTTClient_getPendingDeliveryTokens(c, &tokens);
...@@ -829,11 +821,11 @@ int test4(struct Options options) ...@@ -829,11 +821,11 @@ int test4(struct Options options)
fprintf(xml, "<testcase classname=\"test1\" name=\"persistence\""); fprintf(xml, "<testcase classname=\"test1\" name=\"persistence\"");
global_start_time = start_clock(); global_start_time = start_clock();
rc = test4_run(1) + test4_run(2); rc = test4_run(1) + test4_run(2);
fprintf(xml, " time=\"%ld\" >\n", elapsed(global_start_time) / 1000); fprintf(xml, " time=\"%ld\" >\n", elapsed(global_start_time) / 1000);
if (cur_output != output) if (cur_output != output)
{ {
fprintf(xml, "%s", output); fprintf(xml, "%s", output);
cur_output = output; cur_output = output;
} }
fprintf(xml, "</testcase>\n"); fprintf(xml, "</testcase>\n");
return rc; return rc;
...@@ -954,13 +946,13 @@ int test6(struct Options options) ...@@ -954,13 +946,13 @@ int test6(struct Options options)
MQTTClient_willOptions wopts = MQTTClient_willOptions_initializer; MQTTClient_willOptions wopts = MQTTClient_willOptions_initializer;
MQTTClient_connectOptions opts2 = MQTTClient_connectOptions_initializer; MQTTClient_connectOptions opts2 = MQTTClient_connectOptions_initializer;
int rc, count; int rc, count;
char* mqttsas_topic = "MQTTSAS topic"; char* mqttsas_topic = "MQTTSAS topic";
failures = 0; failures = 0;
MyLog(LOGA_INFO, "Starting test 6 - connectionLost and will messages"); MyLog(LOGA_INFO, "Starting test 6 - connectionLost and will messages");
fprintf(xml, "<testcase classname=\"test1\" name=\"connectionLost and will messages\""); fprintf(xml, "<testcase classname=\"test1\" name=\"connectionLost and will messages\"");
global_start_time = start_clock(); global_start_time = start_clock();
opts.keepAliveInterval = 2; opts.keepAliveInterval = 2;
opts.cleansession = 1; opts.cleansession = 1;
opts.MQTTVersion = options.MQTTVersion; opts.MQTTVersion = options.MQTTVersion;
...@@ -1011,7 +1003,7 @@ int test6(struct Options options) ...@@ -1011,7 +1003,7 @@ int test6(struct Options options)
assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc); assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);
/* now send the command which will break the connection and cause the will message to be sent */ /* now send the command which will break the connection and cause the will message to be sent */
rc = MQTTClient_publish(test6_c1, mqttsas_topic, strlen("TERMINATE"), "TERMINATE", 0, 0, NULL); rc = MQTTClient_publish(test6_c1, mqttsas_topic, (int)strlen("TERMINATE"), "TERMINATE", 0, 0, NULL);
assert("Good rc from publish", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc); assert("Good rc from publish", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);
MyLog(LOGA_INFO, "Waiting to receive the will message"); MyLog(LOGA_INFO, "Waiting to receive the will message");
...@@ -1030,17 +1022,17 @@ int test6(struct Options options) ...@@ -1030,17 +1022,17 @@ int test6(struct Options options)
"will_message_arrived was %d\n", test6_will_message_arrived); "will_message_arrived was %d\n", test6_will_message_arrived);
assert("connection lost called", test6_connection_lost_called == 1, assert("connection lost called", test6_connection_lost_called == 1,
"connection_lost_called %d\n", test6_connection_lost_called); "connection_lost_called %d\n", test6_connection_lost_called);
rc = MQTTClient_unsubscribe(test6_c2, test6_will_topic); rc = MQTTClient_unsubscribe(test6_c2, test6_will_topic);
assert("Good rc from unsubscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); assert("Good rc from unsubscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
rc = MQTTClient_isConnected(test6_c2); rc = MQTTClient_isConnected(test6_c2);
assert("Client-2 still connected", rc == 1, "isconnected is %d", rc); assert("Client-2 still connected", rc == 1, "isconnected is %d", rc);
rc = MQTTClient_isConnected(test6_c1); rc = MQTTClient_isConnected(test6_c1);
assert("Client-1 not connected", rc == 0, "isconnected is %d", rc); assert("Client-1 not connected", rc == 0, "isconnected is %d", rc);
rc = MQTTClient_disconnect(test6_c2, 100L); rc = MQTTClient_disconnect(test6_c2, 100L);
assert("Good rc from disconnect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); assert("Good rc from disconnect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
MQTTClient_destroy(&test6_c1); MQTTClient_destroy(&test6_c1);
...@@ -1058,7 +1050,7 @@ int main(int argc, char** argv) ...@@ -1058,7 +1050,7 @@ int main(int argc, char** argv)
int rc = 0; int rc = 0;
int (*tests[])() = {NULL, test1, test2, test3, test4, test5, test6}; int (*tests[])() = {NULL, test1, test2, test3, test4, test5, test6};
int i; int i;
xml = fopen("TEST-test1.xml", "w"); xml = fopen("TEST-test1.xml", "w");
fprintf(xml, "<testsuite name=\"test1\" tests=\"%d\">\n", (int)(ARRAY_SIZE(tests) - 1)); fprintf(xml, "<testsuite name=\"test1\" tests=\"%d\">\n", (int)(ARRAY_SIZE(tests) - 1));
...@@ -1077,13 +1069,13 @@ int main(int argc, char** argv) ...@@ -1077,13 +1069,13 @@ int main(int argc, char** argv)
else else
rc = tests[options.test_no](options); /* run just the selected test */ rc = tests[options.test_no](options); /* run just the selected test */
} }
if (rc == 0) if (rc == 0)
MyLog(LOGA_INFO, "verdict pass"); MyLog(LOGA_INFO, "verdict pass");
else else
MyLog(LOGA_INFO, "verdict fail"); MyLog(LOGA_INFO, "verdict fail");
fprintf(xml, "</testsuite>\n"); fprintf(xml, "</testsuite>\n");
fclose(xml); fclose(xml);
return rc; return rc;
} }
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
* *
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution. * and Eclipse Distribution License v1.0 which accompany this distribution.
* *
* The Eclipse Public License is available at * The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at * and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php. * http://www.eclipse.org/org/documents/edl-v10.php.
* *
* Contributors: * Contributors:
...@@ -27,29 +27,13 @@ ...@@ -27,29 +27,13 @@
#if !defined(_WINDOWS) #if !defined(_WINDOWS)
#include <sys/time.h> #include <sys/time.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#define WINAPI #define WINAPI
#else #else
#define WIN32_LEAN_AND_MEAN #include <windows.h>
#if !defined(CMAKE_BUILD) #define setenv(a, b, c) _putenv_s(a, b)
/*
* These causes the cmake build to fail. In order to prevent affecting
* other builds, remove them only from CMAKE-related builds
*/
#include <winsock2.h>
#include <ws2tcpip.h>
#endif // CMAKE_BUILD
#define MAXHOSTNAMELEN 256
#define EAGAIN WSAEWOULDBLOCK
#define EINTR WSAEINTR
#define EINPROGRESS WSAEINPROGRESS
#define EWOULDBLOCK WSAEWOULDBLOCK
#define ENOTCONN WSAENOTCONN
#define ECONNRESET WSAECONNRESET
#define setenv(a, b, c) _putenv_s(a, b)
#endif #endif
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
...@@ -83,7 +67,7 @@ struct Options ...@@ -83,7 +67,7 @@ struct Options
void getopts(int argc, char** argv) void getopts(int argc, char** argv)
{ {
int count = 1; int count = 1;
while (count < argc) while (count < argc)
{ {
if (strcmp(argv[count], "--test_no") == 0) if (strcmp(argv[count], "--test_no") == 0)
...@@ -163,7 +147,7 @@ void MyLog(int LOGA_level, char* format, ...) ...@@ -163,7 +147,7 @@ void MyLog(int LOGA_level, char* format, ...)
if (LOGA_level == LOGA_DEBUG && options.verbose == 0) if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
return; return;
ftime(&ts); ftime(&ts);
timeinfo = localtime(&ts.time); timeinfo = localtime(&ts.time);
strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo); strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo);
...@@ -251,11 +235,11 @@ void write_test_result(void) ...@@ -251,11 +235,11 @@ void write_test_result(void)
{ {
long duration = elapsed(global_start_time); long duration = elapsed(global_start_time);
fprintf(xml, " time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000); fprintf(xml, " time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000);
if (cur_output != output) if (cur_output != output)
{ {
fprintf(xml, "%s", output); fprintf(xml, "%s", output);
cur_output = output; cur_output = output;
} }
fprintf(xml, "</testcase>\n"); fprintf(xml, "</testcase>\n");
} }
...@@ -275,11 +259,11 @@ void myassert(char* filename, int lineno, char* description, int value, char* fo ...@@ -275,11 +259,11 @@ void myassert(char* filename, int lineno, char* description, int value, char* fo
vprintf(format, args); vprintf(format, args);
va_end(args); va_end(args);
cur_output += sprintf(cur_output, "<failure type=\"%s\">file %s, line %d </failure>\n", cur_output += sprintf(cur_output, "<failure type=\"%s\">file %s, line %d </failure>\n",
description, filename, lineno); description, filename, lineno);
} }
else else
MyLog(LOGA_DEBUG, "Assertion succeeded, file %s, line %d, description: %s", filename, lineno, description); MyLog(LOGA_DEBUG, "Assertion succeeded, file %s, line %d, description: %s", filename, lineno, description);
} }
...@@ -351,7 +335,7 @@ struct thread_parms ...@@ -351,7 +335,7 @@ struct thread_parms
}; };
static int iterations = 50; static int iterations = 50;
thread_return_type WINAPI test1_sendAndReceive(void* n) thread_return_type WINAPI test1_sendAndReceive(void* n)
{ {
MQTTClient_deliveryToken dt; MQTTClient_deliveryToken dt;
...@@ -403,7 +387,7 @@ thread_return_type WINAPI test1_sendAndReceive(void* n) ...@@ -403,7 +387,7 @@ thread_return_type WINAPI test1_sendAndReceive(void* n)
assert("Message Arrived", wait_seconds > 0, assert("Message Arrived", wait_seconds > 0,
"Timed out waiting for message %d\n", i); "Timed out waiting for message %d\n", i);
} }
#if defined(_WINDOWS) #if defined(_WINDOWS)
return 0; return 0;
#else #else
...@@ -424,7 +408,7 @@ int test1(struct Options options) ...@@ -424,7 +408,7 @@ int test1(struct Options options)
global_start_time = start_clock(); global_start_time = start_clock();
failures = 0; failures = 0;
MyLog(LOGA_INFO, "Starting test 1 - multiple threads using same client object"); MyLog(LOGA_INFO, "Starting test 1 - multiple threads using same client object");
rc = MQTTClient_create(&c, options.connection, "single_object, multiple threads", rc = MQTTClient_create(&c, options.connection, "single_object, multiple threads",
MQTTCLIENT_PERSISTENCE_NONE, NULL); MQTTCLIENT_PERSISTENCE_NONE, NULL);
assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc); assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);
...@@ -478,7 +462,7 @@ int test1(struct Options options) ...@@ -478,7 +462,7 @@ int test1(struct Options options)
completed the QoS 2 handshake with the publisher. For QoS 1 and 2, completed the QoS 2 handshake with the publisher. For QoS 1 and 2,
allow time for the final delivery complete callback before checking allow time for the final delivery complete callback before checking
that all expected callbacks have been made */ that all expected callbacks have been made */
int wait_seconds = 90; int wait_seconds = 90;
while (((test1_arrivedcount < iterations*3) || (test1_deliveryCompleted < iterations*2)) && (wait_seconds-- > 0)) while (((test1_arrivedcount < iterations*3) || (test1_deliveryCompleted < iterations*2)) && (wait_seconds-- > 0))
{ {
...@@ -570,7 +554,7 @@ void test2_sendAndReceive(MQTTClient* c, int qos, char* test_topic) ...@@ -570,7 +554,7 @@ void test2_sendAndReceive(MQTTClient* c, int qos, char* test_topic)
for (i = 1; i <= iterations; ++i) for (i = 1; i <= iterations; ++i)
{ {
if (i % 10 == 0) if (i % 10 == 0)
rc = MQTTClient_publish(c, test_topic, test2_pubmsg.payloadlen, test2_pubmsg.payload, rc = MQTTClient_publish(c, test_topic, test2_pubmsg.payloadlen, test2_pubmsg.payload,
test2_pubmsg.qos, test2_pubmsg.retained, NULL); test2_pubmsg.qos, test2_pubmsg.retained, NULL);
else else
rc = MQTTClient_publishMessage(c, test_topic, &test2_pubmsg, &dt); rc = MQTTClient_publishMessage(c, test_topic, &test2_pubmsg, &dt);
...@@ -592,7 +576,7 @@ void test2_sendAndReceive(MQTTClient* c, int qos, char* test_topic) ...@@ -592,7 +576,7 @@ void test2_sendAndReceive(MQTTClient* c, int qos, char* test_topic)
usleep(1000000L); usleep(1000000L);
#endif #endif
} }
assert("Message Arrived", wait_seconds > 0, assert("Message Arrived", wait_seconds > 0,
"Time out waiting for message %d\n", i ); "Time out waiting for message %d\n", i );
} }
if (qos > 0) if (qos > 0)
...@@ -600,7 +584,7 @@ void test2_sendAndReceive(MQTTClient* c, int qos, char* test_topic) ...@@ -600,7 +584,7 @@ void test2_sendAndReceive(MQTTClient* c, int qos, char* test_topic)
/* MQ Telemetry can send a message to a subscriber before the server has /* MQ Telemetry can send a message to a subscriber before the server has
completed the QoS 2 handshake with the publisher. For QoS 1 and 2, completed the QoS 2 handshake with the publisher. For QoS 1 and 2,
allow time for the final delivery complete callback before checking allow time for the final delivery complete callback before checking
that all expected callbacks have been made */ that all expected callbacks have been made */
wait_seconds = 40; wait_seconds = 40;
while ((test2_deliveryCompleted < iterations) && (wait_seconds-- > 0)) while ((test2_deliveryCompleted < iterations) && (wait_seconds-- > 0))
{ {
...@@ -611,8 +595,8 @@ void test2_sendAndReceive(MQTTClient* c, int qos, char* test_topic) ...@@ -611,8 +595,8 @@ void test2_sendAndReceive(MQTTClient* c, int qos, char* test_topic)
usleep(1000000L); usleep(1000000L);
#endif #endif
} }
assert("All Deliveries Complete", test2_deliveryCompleted == iterations, assert("All Deliveries Complete", test2_deliveryCompleted == iterations,
"Number of deliveryCompleted callbacks was %d\n", "Number of deliveryCompleted callbacks was %d\n",
test2_deliveryCompleted); test2_deliveryCompleted);
} }
} }
...@@ -686,7 +670,7 @@ int main(int argc, char** argv) ...@@ -686,7 +670,7 @@ int main(int argc, char** argv)
#if defined(WIN32) || defined(WIN64) #if defined(WIN32) || defined(WIN64)
deliveryCompleted_mutex = CreateMutex(NULL, 0, NULL); deliveryCompleted_mutex = CreateMutex(NULL, 0, NULL);
#endif #endif
xml = fopen("TEST-test2.xml", "w"); xml = fopen("TEST-test2.xml", "w");
fprintf(xml, "<testsuite name=\"test1\" tests=\"%d\">\n", (int)(ARRAY_SIZE(tests) - 1)); fprintf(xml, "<testsuite name=\"test1\" tests=\"%d\">\n", (int)(ARRAY_SIZE(tests) - 1));
...@@ -705,13 +689,13 @@ int main(int argc, char** argv) ...@@ -705,13 +689,13 @@ int main(int argc, char** argv)
else else
rc = tests[options.test_no](options); /* run just the selected test */ rc = tests[options.test_no](options); /* run just the selected test */
} }
if (rc == 0) if (rc == 0)
MyLog(LOGA_INFO, "verdict pass"); MyLog(LOGA_INFO, "verdict pass");
else else
MyLog(LOGA_INFO, "verdict fail"); MyLog(LOGA_INFO, "verdict fail");
fprintf(xml, "</testsuite>\n"); fprintf(xml, "</testsuite>\n");
fclose(xml); fclose(xml);
return rc; return rc;
} }
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
* *
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution. * and Eclipse Distribution License v1.0 which accompany this distribution.
* *
* The Eclipse Public License is available at * The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at * and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php. * http://www.eclipse.org/org/documents/edl-v10.php.
* *
* Contributors: * Contributors:
...@@ -26,19 +26,12 @@ ...@@ -26,19 +26,12 @@
#if !defined(_WINDOWS) #if !defined(_WINDOWS)
#include <sys/time.h> #include <sys/time.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#else #else
#include <winsock2.h> #include <windows.h>
#include <ws2tcpip.h>
#define MAXHOSTNAMELEN 256 #define MAXHOSTNAMELEN 256
#define EAGAIN WSAEWOULDBLOCK
#define EINTR WSAEINTR
#define EINPROGRESS WSAEINPROGRESS
#define EWOULDBLOCK WSAEWOULDBLOCK
#define ENOTCONN WSAENOTCONN
#define ECONNRESET WSAECONNRESET
#define snprintf _snprintf #define snprintf _snprintf
#define setenv(a, b, c) _putenv_s(a, b) #define setenv(a, b, c) _putenv_s(a, b)
#endif #endif
...@@ -134,7 +127,7 @@ char* test_map[] = ...@@ -134,7 +127,7 @@ char* test_map[] =
void getopts(int argc, char** argv) void getopts(int argc, char** argv)
{ {
int count = 1; int count = 1;
while (count < argc) while (count < argc)
{ {
if (strcmp(argv[count], "--help") == 0) if (strcmp(argv[count], "--help") == 0)
...@@ -155,7 +148,7 @@ void getopts(int argc, char** argv) ...@@ -155,7 +148,7 @@ void getopts(int argc, char** argv)
} }
if (options.test_no == 0) if (options.test_no == 0)
options.test_no = atoi(argv[count]); options.test_no = atoi(argv[count]);
} }
else else
usage(); usage();
...@@ -273,7 +266,7 @@ void MyLog(int LOGA_level, char* format, ...) ...@@ -273,7 +266,7 @@ void MyLog(int LOGA_level, char* format, ...)
if (LOGA_level == LOGA_DEBUG && options.verbose == 0) if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
return; return;
ftime(&ts); ftime(&ts);
timeinfo = localtime(&ts.time); timeinfo = localtime(&ts.time);
strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo); strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo);
...@@ -363,11 +356,11 @@ void write_test_result(void) ...@@ -363,11 +356,11 @@ void write_test_result(void)
{ {
long duration = elapsed(global_start_time); long duration = elapsed(global_start_time);
fprintf(xml, " time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000); fprintf(xml, " time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000);
if (cur_output != output) if (cur_output != output)
{ {
fprintf(xml, "%s", output); fprintf(xml, "%s", output);
cur_output = output; cur_output = output;
} }
fprintf(xml, "</testcase>\n"); fprintf(xml, "</testcase>\n");
} }
...@@ -387,11 +380,11 @@ int myassert(char* filename, int lineno, char* description, int value, char* for ...@@ -387,11 +380,11 @@ int myassert(char* filename, int lineno, char* description, int value, char* for
vprintf(format, args); vprintf(format, args);
va_end(args); va_end(args);
cur_output += sprintf(cur_output, "<failure type=\"%s\">file %s, line %d </failure>\n", cur_output += sprintf(cur_output, "<failure type=\"%s\">file %s, line %d </failure>\n",
description, filename, lineno); description, filename, lineno);
} }
else else
MyLog(LOGA_DEBUG, "Assertion succeeded, file %s, line %d, description: %s", filename, lineno, description); MyLog(LOGA_DEBUG, "Assertion succeeded, file %s, line %d, description: %s", filename, lineno, description);
return value; return value;
} }
...@@ -513,7 +506,7 @@ void multiThread_sendAndReceive(MQTTClient* c, int qos, char* test_topic) ...@@ -513,7 +506,7 @@ void multiThread_sendAndReceive(MQTTClient* c, int qos, char* test_topic)
for (i = 1; i <= iterations; ++i) for (i = 1; i <= iterations; ++i)
{ {
if (i % 10 == 0) if (i % 10 == 0)
rc = MQTTClient_publish(c, test_topic, multiThread_pubmsg.payloadlen, multiThread_pubmsg.payload, rc = MQTTClient_publish(c, test_topic, multiThread_pubmsg.payloadlen, multiThread_pubmsg.payload,
multiThread_pubmsg.qos, multiThread_pubmsg.retained, NULL); multiThread_pubmsg.qos, multiThread_pubmsg.retained, NULL);
else else
rc = MQTTClient_publishMessage(c, test_topic, &multiThread_pubmsg, &dt); rc = MQTTClient_publishMessage(c, test_topic, &multiThread_pubmsg, &dt);
...@@ -535,7 +528,7 @@ void multiThread_sendAndReceive(MQTTClient* c, int qos, char* test_topic) ...@@ -535,7 +528,7 @@ void multiThread_sendAndReceive(MQTTClient* c, int qos, char* test_topic)
usleep(1000000L); usleep(1000000L);
#endif #endif
} }
assert("Message Arrived", wait_seconds > 0, assert("Message Arrived", wait_seconds > 0,
"Time out waiting for message %d\n", i ); "Time out waiting for message %d\n", i );
} }
if (qos > 0) if (qos > 0)
...@@ -543,7 +536,7 @@ void multiThread_sendAndReceive(MQTTClient* c, int qos, char* test_topic) ...@@ -543,7 +536,7 @@ void multiThread_sendAndReceive(MQTTClient* c, int qos, char* test_topic)
/* MQ Telemetry can send a message to a subscriber before the server has /* MQ Telemetry can send a message to a subscriber before the server has
completed the QoS 2 handshake with the publisher. For QoS 1 and 2, completed the QoS 2 handshake with the publisher. For QoS 1 and 2,
allow time for the final delivery complete callback before checking allow time for the final delivery complete callback before checking
that all expected callbacks have been made */ that all expected callbacks have been made */
wait_seconds = 10; wait_seconds = 10;
while ((multiThread_deliveryCompleted < iterations) && (wait_seconds-- > 0)) while ((multiThread_deliveryCompleted < iterations) && (wait_seconds-- > 0))
{ {
...@@ -554,8 +547,8 @@ void multiThread_sendAndReceive(MQTTClient* c, int qos, char* test_topic) ...@@ -554,8 +547,8 @@ void multiThread_sendAndReceive(MQTTClient* c, int qos, char* test_topic)
usleep(1000000L); usleep(1000000L);
#endif #endif
} }
assert("All Deliveries Complete", wait_seconds > 0, assert("All Deliveries Complete", wait_seconds > 0,
"Number of deliveryCompleted callbacks was %d\n", "Number of deliveryCompleted callbacks was %d\n",
multiThread_deliveryCompleted); multiThread_deliveryCompleted);
} }
} }
...@@ -581,7 +574,7 @@ int test1(struct Options options) ...@@ -581,7 +574,7 @@ int test1(struct Options options)
MyLog(LOGA_INFO, "Starting SSL test 1 - connection to nonSSL MQTT server"); MyLog(LOGA_INFO, "Starting SSL test 1 - connection to nonSSL MQTT server");
fprintf(xml, "<testcase classname=\"test3\" name=\"SSL connect fail to nonSSL MQTT server\""); fprintf(xml, "<testcase classname=\"test3\" name=\"SSL connect fail to nonSSL MQTT server\"");
global_start_time = start_clock(); global_start_time = start_clock();
rc = MQTTClient_create(&c, options.connection, "test1", MQTTCLIENT_PERSISTENCE_DEFAULT, persistenceStore); rc = MQTTClient_create(&c, options.connection, "test1", MQTTCLIENT_PERSISTENCE_DEFAULT, persistenceStore);
if (!(assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d \n", rc))) if (!(assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d \n", rc)))
goto exit; goto exit;
...@@ -597,7 +590,7 @@ int test1(struct Options options) ...@@ -597,7 +590,7 @@ int test1(struct Options options)
} }
opts.ssl = &sslopts; opts.ssl = &sslopts;
if (options.server_key_file != NULL) if (options.server_key_file != NULL)
opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/ opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/
MyLog(LOGA_DEBUG, "Connecting"); MyLog(LOGA_DEBUG, "Connecting");
...@@ -636,7 +629,7 @@ int test2a_s(struct Options options) ...@@ -636,7 +629,7 @@ int test2a_s(struct Options options)
MyLog(LOGA_INFO, "Starting test 2a_s - Mutual SSL authentication - single threaded client using receive"); MyLog(LOGA_INFO, "Starting test 2a_s - Mutual SSL authentication - single threaded client using receive");
fprintf(xml, "<testcase classname=\"test3\" name=\"test 2a_s\""); fprintf(xml, "<testcase classname=\"test3\" name=\"test 2a_s\"");
global_start_time = start_clock(); global_start_time = start_clock();
rc = MQTTClient_create(&c, options.server_auth_connection, "test2a_s", MQTTCLIENT_PERSISTENCE_DEFAULT, persistenceStore); rc = MQTTClient_create(&c, options.server_auth_connection, "test2a_s", MQTTCLIENT_PERSISTENCE_DEFAULT, persistenceStore);
if (!(assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc))) if (!(assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc)))
goto exit; goto exit;
...@@ -652,12 +645,12 @@ int test2a_s(struct Options options) ...@@ -652,12 +645,12 @@ int test2a_s(struct Options options)
} }
opts.ssl = &sslopts; opts.ssl = &sslopts;
if (options.server_key_file) if (options.server_key_file)
opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/ opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/
opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/ opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
if (options.client_key_pass) if (options.client_key_pass)
opts.ssl->privateKeyPassword = options.client_key_pass; opts.ssl->privateKeyPassword = options.client_key_pass;
if (options.client_private_key_file) if (options.client_private_key_file)
opts.ssl->privateKey = options.client_private_key_file; opts.ssl->privateKey = options.client_private_key_file;
MyLog(LOGA_DEBUG, "Connecting"); MyLog(LOGA_DEBUG, "Connecting");
...@@ -737,12 +730,12 @@ int test2a_m(struct Options options) ...@@ -737,12 +730,12 @@ int test2a_m(struct Options options)
} }
opts.ssl = &sslopts; opts.ssl = &sslopts;
if (options.server_key_file) if (options.server_key_file)
opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/ opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/
opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/ opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
if (options.client_key_pass) if (options.client_key_pass)
opts.ssl->privateKeyPassword = options.client_key_pass; opts.ssl->privateKeyPassword = options.client_key_pass;
if (options.client_private_key_file) if (options.client_private_key_file)
opts.ssl->privateKey = options.client_private_key_file; opts.ssl->privateKey = options.client_private_key_file;
//opts.ssl->enabledCipherSuites = "DEFAULT"; //opts.ssl->enabledCipherSuites = "DEFAULT";
//opts.ssl->enabledServerCertAuth = 1; //opts.ssl->enabledServerCertAuth = 1;
...@@ -802,7 +795,7 @@ int test2b(struct Options options) ...@@ -802,7 +795,7 @@ int test2b(struct Options options)
MyLog(LOGA_INFO, "Starting test 2b - connection to SSL MQTT server with clientauth=req but server does not have client cert"); MyLog(LOGA_INFO, "Starting test 2b - connection to SSL MQTT server with clientauth=req but server does not have client cert");
fprintf(xml, "<testcase classname=\"test3\" name=\"test 2b\""); fprintf(xml, "<testcase classname=\"test3\" name=\"test 2b\"");
global_start_time = start_clock(); global_start_time = start_clock();
rc = MQTTClient_create(&c, options.nocert_mutual_auth_connection, "test2b", MQTTCLIENT_PERSISTENCE_DEFAULT, persistenceStore); rc = MQTTClient_create(&c, options.nocert_mutual_auth_connection, "test2b", MQTTCLIENT_PERSISTENCE_DEFAULT, persistenceStore);
if (!(assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc))) if (!(assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc)))
goto exit; goto exit;
...@@ -818,12 +811,12 @@ int test2b(struct Options options) ...@@ -818,12 +811,12 @@ int test2b(struct Options options)
} }
opts.ssl = &sslopts; opts.ssl = &sslopts;
if (options.server_key_file) if (options.server_key_file)
opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/ opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/
opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/ opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
if (options.client_key_pass) if (options.client_key_pass)
opts.ssl->privateKeyPassword = options.client_key_pass; opts.ssl->privateKeyPassword = options.client_key_pass;
if (options.client_private_key_file) if (options.client_private_key_file)
opts.ssl->privateKey = options.client_private_key_file; opts.ssl->privateKey = options.client_private_key_file;
//opts.ssl->enabledCipherSuites = "DEFAULT"; //opts.ssl->enabledCipherSuites = "DEFAULT";
//opts.ssl->enabledServerCertAuth = 0; //opts.ssl->enabledServerCertAuth = 0;
...@@ -862,7 +855,7 @@ int test2c(struct Options options) ...@@ -862,7 +855,7 @@ int test2c(struct Options options)
MyLog(LOGA_INFO, "Starting test 2c - connection to SSL MQTT server, server auth enabled but unknown cert"); MyLog(LOGA_INFO, "Starting test 2c - connection to SSL MQTT server, server auth enabled but unknown cert");
fprintf(xml, "<testcase classname=\"test3\" name=\"test 2c\""); fprintf(xml, "<testcase classname=\"test3\" name=\"test 2c\"");
global_start_time = start_clock(); global_start_time = start_clock();
rc = MQTTClient_create(&c, options.mutual_auth_connection, "test2c", MQTTCLIENT_PERSISTENCE_DEFAULT, persistenceStore); rc = MQTTClient_create(&c, options.mutual_auth_connection, "test2c", MQTTCLIENT_PERSISTENCE_DEFAULT, persistenceStore);
if (!(assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc))) if (!(assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc)))
goto exit; goto exit;
...@@ -878,12 +871,12 @@ int test2c(struct Options options) ...@@ -878,12 +871,12 @@ int test2c(struct Options options)
} }
opts.ssl = &sslopts; opts.ssl = &sslopts;
//if (options.server_key_file) //if (options.server_key_file)
// opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/ // opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/
opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/ opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
if (options.client_key_pass) if (options.client_key_pass)
opts.ssl->privateKeyPassword = options.client_key_pass; opts.ssl->privateKeyPassword = options.client_key_pass;
if (options.client_private_key_file) if (options.client_private_key_file)
opts.ssl->privateKey = options.client_private_key_file; opts.ssl->privateKey = options.client_private_key_file;
//opts.ssl->enabledCipherSuites = "DEFAULT"; //opts.ssl->enabledCipherSuites = "DEFAULT";
//opts.ssl->enabledServerCertAuth = 0; //opts.ssl->enabledServerCertAuth = 0;
...@@ -923,7 +916,7 @@ int test3a_s(struct Options options) ...@@ -923,7 +916,7 @@ int test3a_s(struct Options options)
MyLog(LOGA_INFO, "Starting test 3a_s - Server authentication - single threaded client using receive"); MyLog(LOGA_INFO, "Starting test 3a_s - Server authentication - single threaded client using receive");
fprintf(xml, "<testcase classname=\"test3\" name=\"test 3a_s\""); fprintf(xml, "<testcase classname=\"test3\" name=\"test 3a_s\"");
global_start_time = start_clock(); global_start_time = start_clock();
rc = MQTTClient_create(&c, options.server_auth_connection, "test3a_s", MQTTCLIENT_PERSISTENCE_DEFAULT, persistenceStore); rc = MQTTClient_create(&c, options.server_auth_connection, "test3a_s", MQTTCLIENT_PERSISTENCE_DEFAULT, persistenceStore);
if (!(assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc))) if (!(assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc)))
goto exit; goto exit;
...@@ -939,7 +932,7 @@ int test3a_s(struct Options options) ...@@ -939,7 +932,7 @@ int test3a_s(struct Options options)
} }
opts.ssl = &sslopts; opts.ssl = &sslopts;
if (options.server_key_file != NULL) if (options.server_key_file != NULL)
opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/ opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/
MyLog(LOGA_DEBUG, "Connecting"); MyLog(LOGA_DEBUG, "Connecting");
...@@ -1018,7 +1011,7 @@ int test3a_m(struct Options options) ...@@ -1018,7 +1011,7 @@ int test3a_m(struct Options options)
} }
opts.ssl = &sslopts; opts.ssl = &sslopts;
if (options.server_key_file != NULL) if (options.server_key_file != NULL)
opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/ opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/
rc = MQTTClient_setCallbacks(c, NULL, NULL, multiThread_messageArrived, multiThread_deliveryComplete); rc = MQTTClient_setCallbacks(c, NULL, NULL, multiThread_messageArrived, multiThread_deliveryComplete);
...@@ -1076,7 +1069,7 @@ int test3b(struct Options options) ...@@ -1076,7 +1069,7 @@ int test3b(struct Options options)
MyLog(LOGA_INFO, "Starting test 3b - connection to SSL MQTT server with clientauth=opt but client does not have server cert"); MyLog(LOGA_INFO, "Starting test 3b - connection to SSL MQTT server with clientauth=opt but client does not have server cert");
fprintf(xml, "<testcase classname=\"test3\" name=\"test 3b\""); fprintf(xml, "<testcase classname=\"test3\" name=\"test 3b\"");
global_start_time = start_clock(); global_start_time = start_clock();
rc = MQTTClient_create(&c, options.server_auth_connection, "test3b", MQTTCLIENT_PERSISTENCE_DEFAULT, persistenceStore); rc = MQTTClient_create(&c, options.server_auth_connection, "test3b", MQTTCLIENT_PERSISTENCE_DEFAULT, persistenceStore);
if (!(assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc))) if (!(assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc)))
goto exit; goto exit;
...@@ -1128,7 +1121,7 @@ int test4_s(struct Options options) ...@@ -1128,7 +1121,7 @@ int test4_s(struct Options options)
MyLog(LOGA_INFO, "Starting test 4_s - accept invalid server certificates - single threaded"); MyLog(LOGA_INFO, "Starting test 4_s - accept invalid server certificates - single threaded");
fprintf(xml, "<testcase classname=\"test3\" name=\"test 4_s\""); fprintf(xml, "<testcase classname=\"test3\" name=\"test 4_s\"");
global_start_time = start_clock(); global_start_time = start_clock();
rc = MQTTClient_create(&c, options.server_auth_connection, "test4_s", MQTTCLIENT_PERSISTENCE_DEFAULT, persistenceStore); rc = MQTTClient_create(&c, options.server_auth_connection, "test4_s", MQTTCLIENT_PERSISTENCE_DEFAULT, persistenceStore);
if (!(assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc))) if (!(assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc)))
goto exit; goto exit;
...@@ -1279,7 +1272,7 @@ int test5a(struct Options options) ...@@ -1279,7 +1272,7 @@ int test5a(struct Options options)
MyLog(LOGA_INFO, "Starting SSL test 5a - Anonymous ciphers - server authentication disabled"); MyLog(LOGA_INFO, "Starting SSL test 5a - Anonymous ciphers - server authentication disabled");
fprintf(xml, "<testcase classname=\"test3\" name=\"test 5a\""); fprintf(xml, "<testcase classname=\"test3\" name=\"test 5a\"");
global_start_time = start_clock(); global_start_time = start_clock();
rc = MQTTClient_create(&c, options.anon_connection, "test5a", MQTTCLIENT_PERSISTENCE_DEFAULT, persistenceStore); rc = MQTTClient_create(&c, options.anon_connection, "test5a", MQTTCLIENT_PERSISTENCE_DEFAULT, persistenceStore);
if (!(assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc))) if (!(assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc)))
goto exit; goto exit;
...@@ -1358,7 +1351,7 @@ int test5b(struct Options options) ...@@ -1358,7 +1351,7 @@ int test5b(struct Options options)
MyLog(LOGA_INFO, "Starting SSL test 5b - Anonymous ciphers - server authentication enabled"); MyLog(LOGA_INFO, "Starting SSL test 5b - Anonymous ciphers - server authentication enabled");
fprintf(xml, "<testcase classname=\"test3\" name=\"test 5b\""); fprintf(xml, "<testcase classname=\"test3\" name=\"test 5b\"");
global_start_time = start_clock(); global_start_time = start_clock();
rc = MQTTClient_create(&c, options.anon_connection, "test5b", MQTTCLIENT_PERSISTENCE_DEFAULT, persistenceStore); rc = MQTTClient_create(&c, options.anon_connection, "test5b", MQTTCLIENT_PERSISTENCE_DEFAULT, persistenceStore);
if (!(assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc))) if (!(assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc)))
goto exit; goto exit;
...@@ -1440,7 +1433,7 @@ int test5c(struct Options options) ...@@ -1440,7 +1433,7 @@ int test5c(struct Options options)
MyLog(LOGA_INFO, "Starting SSL test 5c - Anonymous ciphers - client not using anonymous cipher"); MyLog(LOGA_INFO, "Starting SSL test 5c - Anonymous ciphers - client not using anonymous cipher");
fprintf(xml, "<testcase classname=\"test3\" name=\"test 5c\""); fprintf(xml, "<testcase classname=\"test3\" name=\"test 5c\"");
global_start_time = start_clock(); global_start_time = start_clock();
rc = MQTTClient_create(&c, options.anon_connection, "test5c", MQTTCLIENT_PERSISTENCE_DEFAULT, persistenceStore); rc = MQTTClient_create(&c, options.anon_connection, "test5c", MQTTCLIENT_PERSISTENCE_DEFAULT, persistenceStore);
if (!(assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc))) if (!(assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc)))
goto exit; goto exit;
...@@ -1528,7 +1521,7 @@ int main(int argc, char** argv) ...@@ -1528,7 +1521,7 @@ int main(int argc, char** argv)
xml = fopen("TEST-test3.xml", "w"); xml = fopen("TEST-test3.xml", "w");
fprintf(xml, "<testsuite name=\"test3\" tests=\"%d\">\n", (int)(ARRAY_SIZE(tests) - 1)); fprintf(xml, "<testsuite name=\"test3\" tests=\"%d\">\n", (int)(ARRAY_SIZE(tests) - 1));
setenv("MQTT_C_CLIENT_TRACE", "ON", 1); setenv("MQTT_C_CLIENT_TRACE", "ON", 1);
setenv("MQTT_C_CLIENT_TRACE_LEVEL", "ERROR", 0); setenv("MQTT_C_CLIENT_TRACE_LEVEL", "ERROR", 0);
getopts(argc, argv); getopts(argc, argv);
...@@ -1539,7 +1532,7 @@ int main(int argc, char** argv) ...@@ -1539,7 +1532,7 @@ int main(int argc, char** argv)
} }
else else
rc = tests[options.test_no](options); /* run just the selected test */ rc = tests[options.test_no](options); /* run just the selected test */
MyLog(LOGA_INFO, "Total tests run: %d", *numtests); MyLog(LOGA_INFO, "Total tests run: %d", *numtests);
if (rc == 0) if (rc == 0)
MyLog(LOGA_INFO, "verdict pass"); MyLog(LOGA_INFO, "verdict pass");
...@@ -1548,6 +1541,6 @@ int main(int argc, char** argv) ...@@ -1548,6 +1541,6 @@ int main(int argc, char** argv)
fprintf(xml, "</testsuite>\n"); fprintf(xml, "</testsuite>\n");
fclose(xml); fclose(xml);
return rc; return rc;
} }
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
* *
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution. * and Eclipse Distribution License v1.0 which accompany this distribution.
* *
* The Eclipse Public License is available at * The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at * and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php. * http://www.eclipse.org/org/documents/edl-v10.php.
* *
* Contributors: * Contributors:
...@@ -29,19 +29,11 @@ ...@@ -29,19 +29,11 @@
#if !defined(_WINDOWS) #if !defined(_WINDOWS)
#include <sys/time.h> #include <sys/time.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#else #else
#include <winsock2.h> #include <windows.h>
#include <ws2tcpip.h>
#define MAXHOSTNAMELEN 256
#define EAGAIN WSAEWOULDBLOCK
#define EINTR WSAEINTR
#define EINPROGRESS WSAEINPROGRESS
#define EWOULDBLOCK WSAEWOULDBLOCK
#define ENOTCONN WSAENOTCONN
#define ECONNRESET WSAECONNRESET
#endif #endif
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
...@@ -73,7 +65,7 @@ struct Options ...@@ -73,7 +65,7 @@ struct Options
void getopts(int argc, char** argv) void getopts(int argc, char** argv)
{ {
int count = 1; int count = 1;
while (count < argc) while (count < argc)
{ {
if (strcmp(argv[count], "--test_no") == 0) if (strcmp(argv[count], "--test_no") == 0)
...@@ -139,7 +131,7 @@ void MyLog(int LOGA_level, char* format, ...) ...@@ -139,7 +131,7 @@ void MyLog(int LOGA_level, char* format, ...)
if (LOGA_level == LOGA_DEBUG && options.verbose == 0) if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
return; return;
ftime(&ts); ftime(&ts);
timeinfo = localtime(&ts.time); timeinfo = localtime(&ts.time);
strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo); strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo);
...@@ -226,11 +218,11 @@ void write_test_result(void) ...@@ -226,11 +218,11 @@ void write_test_result(void)
{ {
long duration = elapsed(global_start_time); long duration = elapsed(global_start_time);
fprintf(xml, " time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000); fprintf(xml, " time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000);
if (cur_output != output) if (cur_output != output)
{ {
fprintf(xml, "%s", output); fprintf(xml, "%s", output);
cur_output = output; cur_output = output;
} }
fprintf(xml, "</testcase>\n"); fprintf(xml, "</testcase>\n");
} }
...@@ -249,11 +241,11 @@ void myassert(char* filename, int lineno, char* description, int value, char* fo ...@@ -249,11 +241,11 @@ void myassert(char* filename, int lineno, char* description, int value, char* fo
vprintf(format, args); vprintf(format, args);
va_end(args); va_end(args);
cur_output += sprintf(cur_output, "<failure type=\"%s\">file %s, line %d </failure>\n", cur_output += sprintf(cur_output, "<failure type=\"%s\">file %s, line %d </failure>\n",
description, filename, lineno); description, filename, lineno);
} }
else else
MyLog(LOGA_DEBUG, "Assertion succeeded, file %s, line %d, description: %s", filename, lineno, description); MyLog(LOGA_DEBUG, "Assertion succeeded, file %s, line %d, description: %s", filename, lineno, description);
} }
volatile int test_finished = 0; volatile int test_finished = 0;
...@@ -274,7 +266,7 @@ void test1_onUnsubscribe(void* context, MQTTAsync_successData* response) ...@@ -274,7 +266,7 @@ void test1_onUnsubscribe(void* context, MQTTAsync_successData* response)
MQTTAsync c = (MQTTAsync)context; MQTTAsync c = (MQTTAsync)context;
MQTTAsync_disconnectOptions opts = MQTTAsync_disconnectOptions_initializer; MQTTAsync_disconnectOptions opts = MQTTAsync_disconnectOptions_initializer;
int rc; int rc;
MyLog(LOGA_DEBUG, "In onUnsubscribe onSuccess callback %p", c); MyLog(LOGA_DEBUG, "In onUnsubscribe onSuccess callback %p", c);
opts.onSuccess = test1_onDisconnect; opts.onSuccess = test1_onDisconnect;
opts.context = c; opts.context = c;
...@@ -323,7 +315,7 @@ void test1_onSubscribe(void* context, MQTTAsync_successData* response) ...@@ -323,7 +315,7 @@ void test1_onSubscribe(void* context, MQTTAsync_successData* response)
MQTTAsync c = (MQTTAsync)context; MQTTAsync c = (MQTTAsync)context;
MQTTAsync_message pubmsg = MQTTAsync_message_initializer; MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
int rc; int rc;
MyLog(LOGA_DEBUG, "In subscribe onSuccess callback %p granted qos %d", c, response->alt.qos); MyLog(LOGA_DEBUG, "In subscribe onSuccess callback %p granted qos %d", c, response->alt.qos);
pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11"; pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
...@@ -340,7 +332,7 @@ void test1_onConnect(void* context, MQTTAsync_successData* response) ...@@ -340,7 +332,7 @@ void test1_onConnect(void* context, MQTTAsync_successData* response)
MQTTAsync c = (MQTTAsync)context; MQTTAsync c = (MQTTAsync)context;
MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
int rc; int rc;
MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context); MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
opts.onSuccess = test1_onSubscribe; opts.onSuccess = test1_onSubscribe;
opts.context = c; opts.context = c;
...@@ -369,9 +361,9 @@ int test1(struct Options options) ...@@ -369,9 +361,9 @@ int test1(struct Options options)
MyLog(LOGA_INFO, "Starting test 1 - asynchronous connect"); MyLog(LOGA_INFO, "Starting test 1 - asynchronous connect");
fprintf(xml, "<testcase classname=\"test4\" name=\"asynchronous connect\""); fprintf(xml, "<testcase classname=\"test4\" name=\"asynchronous connect\"");
global_start_time = start_clock(); global_start_time = start_clock();
rc = MQTTAsync_create(&c, options.connection, "async_test", rc = MQTTAsync_create(&c, options.connection, "async_test",
MQTTCLIENT_PERSISTENCE_DEFAULT, NULL); MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc); assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
if (rc != MQTTASYNC_SUCCESS) if (rc != MQTTASYNC_SUCCESS)
{ {
...@@ -386,7 +378,7 @@ int test1(struct Options options) ...@@ -386,7 +378,7 @@ int test1(struct Options options)
opts.cleansession = 1; opts.cleansession = 1;
opts.username = "testuser"; opts.username = "testuser";
opts.password = "testpassword"; opts.password = "testpassword";
opts.MQTTVersion = options.MQTTVersion; opts.MQTTVersion = options.MQTTVersion;
opts.will = &wopts; opts.will = &wopts;
opts.will->message = "will message"; opts.will->message = "will message";
...@@ -410,7 +402,7 @@ int test1(struct Options options) ...@@ -410,7 +402,7 @@ int test1(struct Options options)
Sleep(100); Sleep(100);
#else #else
usleep(10000L); usleep(10000L);
#endif #endif
MQTTAsync_destroy(&c); MQTTAsync_destroy(&c);
...@@ -461,9 +453,9 @@ int test2(struct Options options) ...@@ -461,9 +453,9 @@ int test2(struct Options options)
MyLog(LOGA_INFO, "Starting test 2 - connect timeout"); MyLog(LOGA_INFO, "Starting test 2 - connect timeout");
fprintf(xml, "<testcase classname=\"test4\" name=\"connect timeout\""); fprintf(xml, "<testcase classname=\"test4\" name=\"connect timeout\"");
global_start_time = start_clock(); global_start_time = start_clock();
rc = MQTTAsync_create(&c, "tcp://9.20.96.160:66", "connect timeout", rc = MQTTAsync_create(&c, "tcp://9.20.96.160:66", "connect timeout",
MQTTCLIENT_PERSISTENCE_DEFAULT, NULL); MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc); assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
if (rc != MQTTASYNC_SUCCESS) if (rc != MQTTASYNC_SUCCESS)
{ {
...@@ -503,12 +495,12 @@ int test2(struct Options options) ...@@ -503,12 +495,12 @@ int test2(struct Options options)
Sleep(100); Sleep(100);
#else #else
usleep(10000L); usleep(10000L);
#endif #endif
MQTTAsync_destroy(&c); MQTTAsync_destroy(&c);
exit: exit:
assert("Connect onFailure should be called once", test2_onFailure_called == 1, assert("Connect onFailure should be called once", test2_onFailure_called == 1,
"connect onFailure was called %d times", test2_onFailure_called); "connect onFailure was called %d times", test2_onFailure_called);
MyLog(LOGA_INFO, "TEST2: test %s. %d tests run, %d failures.", MyLog(LOGA_INFO, "TEST2: test %s. %d tests run, %d failures.",
...@@ -548,7 +540,7 @@ void test3_onUnsubscribe(void* context, MQTTAsync_successData* response) ...@@ -548,7 +540,7 @@ void test3_onUnsubscribe(void* context, MQTTAsync_successData* response)
client_data* cd = (client_data*)context; client_data* cd = (client_data*)context;
MQTTAsync_disconnectOptions opts = MQTTAsync_disconnectOptions_initializer; MQTTAsync_disconnectOptions opts = MQTTAsync_disconnectOptions_initializer;
int rc; int rc;
MyLog(LOGA_DEBUG, "In onUnsubscribe onSuccess callback \"%s\"", cd->clientid); MyLog(LOGA_DEBUG, "In onUnsubscribe onSuccess callback \"%s\"", cd->clientid);
opts.onSuccess = test3_onDisconnect; opts.onSuccess = test3_onDisconnect;
opts.context = cd; opts.context = cd;
...@@ -609,7 +601,7 @@ void test3_onSubscribe(void* context, MQTTAsync_successData* response) ...@@ -609,7 +601,7 @@ void test3_onSubscribe(void* context, MQTTAsync_successData* response)
client_data* cd = (client_data*)context; client_data* cd = (client_data*)context;
MQTTAsync_message pubmsg = MQTTAsync_message_initializer; MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
int rc; int rc;
MyLog(LOGA_DEBUG, "In subscribe onSuccess callback \"%s\"", cd->clientid); MyLog(LOGA_DEBUG, "In subscribe onSuccess callback \"%s\"", cd->clientid);
pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11"; pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
...@@ -627,7 +619,7 @@ void test3_onConnect(void* context, MQTTAsync_successData* response) ...@@ -627,7 +619,7 @@ void test3_onConnect(void* context, MQTTAsync_successData* response)
client_data* cd = (client_data*)context; client_data* cd = (client_data*)context;
MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
int rc; int rc;
MyLog(LOGA_DEBUG, "In connect onSuccess callback, \"%s\"", cd->clientid); MyLog(LOGA_DEBUG, "In connect onSuccess callback, \"%s\"", cd->clientid);
opts.onSuccess = test3_onSubscribe; opts.onSuccess = test3_onSubscribe;
opts.context = cd; opts.context = cd;
...@@ -643,7 +635,7 @@ void test3_onFailure(void* context, MQTTAsync_failureData* response) ...@@ -643,7 +635,7 @@ void test3_onFailure(void* context, MQTTAsync_failureData* response)
{ {
client_data* cd = (client_data*)context; client_data* cd = (client_data*)context;
MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
assert("Should have connected", 0, "%s failed to connect\n", cd->clientid); assert("Should have connected", 0, "%s failed to connect\n", cd->clientid);
MyLog(LOGA_DEBUG, "In connect onFailure callback, \"%s\" rc %d\n", cd->clientid, response ? response->code : -999); MyLog(LOGA_DEBUG, "In connect onFailure callback, \"%s\" rc %d\n", cd->clientid, response ? response->code : -999);
if (response && response->message) if (response && response->message)
...@@ -672,7 +664,7 @@ int test3(struct Options options) ...@@ -672,7 +664,7 @@ int test3(struct Options options)
MyLog(LOGA_INFO, "Starting test 3 - multiple connections"); MyLog(LOGA_INFO, "Starting test 3 - multiple connections");
fprintf(xml, "<testcase classname=\"test4\" name=\"multiple connections\""); fprintf(xml, "<testcase classname=\"test4\" name=\"multiple connections\"");
global_start_time = start_clock(); global_start_time = start_clock();
for (i = 0; i < num_clients; ++i) for (i = 0; i < num_clients; ++i)
{ {
sprintf(clientdata[i].clientid, "async_test3_num_%d", i); sprintf(clientdata[i].clientid, "async_test3_num_%d", i);
...@@ -681,9 +673,9 @@ int test3(struct Options options) ...@@ -681,9 +673,9 @@ int test3(struct Options options)
clientdata[i].message_count = 0; clientdata[i].message_count = 0;
rc = MQTTAsync_create(&(clientdata[i].c), options.connection, clientdata[i].clientid, rc = MQTTAsync_create(&(clientdata[i].c), options.connection, clientdata[i].clientid,
MQTTCLIENT_PERSISTENCE_NONE, NULL); MQTTCLIENT_PERSISTENCE_NONE, NULL);
assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc); assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
rc = MQTTAsync_setCallbacks(clientdata[i].c, &clientdata[i], NULL, test3_messageArrived, NULL); rc = MQTTAsync_setCallbacks(clientdata[i].c, &clientdata[i], NULL, test3_messageArrived, NULL);
assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc); assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
...@@ -714,7 +706,7 @@ int test3(struct Options options) ...@@ -714,7 +706,7 @@ int test3(struct Options options)
Sleep(100); Sleep(100);
#else #else
usleep(10000L); usleep(10000L);
#endif #endif
} }
MyLog(LOGA_DEBUG, "TEST3: destroying clients"); MyLog(LOGA_DEBUG, "TEST3: destroying clients");
...@@ -736,7 +728,7 @@ int test4_payloadlen = 0; ...@@ -736,7 +728,7 @@ int test4_payloadlen = 0;
void test4_onPublish(void* context, MQTTAsync_successData* response) void test4_onPublish(void* context, MQTTAsync_successData* response)
{ {
MQTTAsync c = (MQTTAsync)context; MQTTAsync c = (MQTTAsync)context;
MyLog(LOGA_DEBUG, "In publish onSuccess callback, context %p", context); MyLog(LOGA_DEBUG, "In publish onSuccess callback, context %p", context);
} }
...@@ -810,7 +802,7 @@ void test4_onSubscribe(void* context, MQTTAsync_successData* response) ...@@ -810,7 +802,7 @@ void test4_onSubscribe(void* context, MQTTAsync_successData* response)
MQTTAsync c = (MQTTAsync)context; MQTTAsync c = (MQTTAsync)context;
MQTTAsync_message pubmsg = MQTTAsync_message_initializer; MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
int rc, i; int rc, i;
MyLog(LOGA_DEBUG, "In subscribe onSuccess callback %p", c); MyLog(LOGA_DEBUG, "In subscribe onSuccess callback %p", c);
pubmsg.payload = test4_payload = malloc(options.size); pubmsg.payload = test4_payload = malloc(options.size);
...@@ -819,7 +811,7 @@ void test4_onSubscribe(void* context, MQTTAsync_successData* response) ...@@ -819,7 +811,7 @@ void test4_onSubscribe(void* context, MQTTAsync_successData* response)
srand(33); srand(33);
for (i = 0; i < options.size; ++i) for (i = 0; i < options.size; ++i)
((char*)pubmsg.payload)[i] = rand() % 256; ((char*)pubmsg.payload)[i] = rand() % 256;
pubmsg.qos = 2; pubmsg.qos = 2;
pubmsg.retained = 0; pubmsg.retained = 0;
...@@ -832,7 +824,7 @@ void test4_onConnect(void* context, MQTTAsync_successData* response) ...@@ -832,7 +824,7 @@ void test4_onConnect(void* context, MQTTAsync_successData* response)
MQTTAsync c = (MQTTAsync)context; MQTTAsync c = (MQTTAsync)context;
MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
int rc; int rc;
MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context); MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
opts.onSuccess = test4_onSubscribe; opts.onSuccess = test4_onSubscribe;
opts.context = c; opts.context = c;
...@@ -862,9 +854,9 @@ int test4(struct Options options) ...@@ -862,9 +854,9 @@ int test4(struct Options options)
MyLog(LOGA_INFO, "Starting test 4 - big messages"); MyLog(LOGA_INFO, "Starting test 4 - big messages");
fprintf(xml, "<testcase classname=\"test4\" name=\"big messages\""); fprintf(xml, "<testcase classname=\"test4\" name=\"big messages\"");
global_start_time = start_clock(); global_start_time = start_clock();
rc = MQTTAsync_create(&c, options.connection, "async_test_4", rc = MQTTAsync_create(&c, options.connection, "async_test_4",
MQTTCLIENT_PERSISTENCE_DEFAULT, NULL); MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc); assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
if (rc != MQTTASYNC_SUCCESS) if (rc != MQTTASYNC_SUCCESS)
{ {
...@@ -903,7 +895,7 @@ int test4(struct Options options) ...@@ -903,7 +895,7 @@ int test4(struct Options options)
Sleep(100); Sleep(100);
#else #else
usleep(1000L); usleep(1000L);
#endif #endif
MQTTAsync_destroy(&c); MQTTAsync_destroy(&c);
...@@ -919,7 +911,7 @@ void test5_onConnectFailure(void* context, MQTTAsync_failureData* response) ...@@ -919,7 +911,7 @@ void test5_onConnectFailure(void* context, MQTTAsync_failureData* response)
{ {
MQTTAsync c = (MQTTAsync)context; MQTTAsync c = (MQTTAsync)context;
MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context); MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context);
MyLog(LOGA_INFO, "Connack rc is %d", response ? response->code : -999); MyLog(LOGA_INFO, "Connack rc is %d", response ? response->code : -999);
...@@ -932,7 +924,7 @@ void test5_onConnect(void* context, MQTTAsync_successData* response) ...@@ -932,7 +924,7 @@ void test5_onConnect(void* context, MQTTAsync_successData* response)
{ {
MQTTAsync c = (MQTTAsync)context; MQTTAsync c = (MQTTAsync)context;
MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context); MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context);
test_finished = 1; test_finished = 1;
...@@ -957,9 +949,9 @@ int test5(struct Options options) ...@@ -957,9 +949,9 @@ int test5(struct Options options)
MyLog(LOGA_INFO, "Starting test 5 - connack return codes"); MyLog(LOGA_INFO, "Starting test 5 - connack return codes");
fprintf(xml, "<testcase classname=\"test4\" name=\"connack return codes\""); fprintf(xml, "<testcase classname=\"test4\" name=\"connack return codes\"");
global_start_time = start_clock(); global_start_time = start_clock();
rc = MQTTAsync_create(&c, options.connection, "a clientid that is too long to be accepted", rc = MQTTAsync_create(&c, options.connection, "a clientid that is too long to be accepted",
MQTTCLIENT_PERSISTENCE_DEFAULT, NULL); MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc); assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
if (rc != MQTTASYNC_SUCCESS) if (rc != MQTTASYNC_SUCCESS)
{ {
...@@ -986,7 +978,7 @@ int test5(struct Options options) ...@@ -986,7 +978,7 @@ int test5(struct Options options)
Sleep(100); Sleep(100);
#else #else
usleep(10000L); usleep(10000L);
#endif #endif
MQTTAsync_destroy(&c); MQTTAsync_destroy(&c);
...@@ -1007,7 +999,7 @@ typedef struct ...@@ -1007,7 +999,7 @@ typedef struct
void test6_onConnectFailure(void* context, MQTTAsync_failureData* response) void test6_onConnectFailure(void* context, MQTTAsync_failureData* response)
{ {
test6_client_info cinfo = *(test6_client_info*)context; test6_client_info cinfo = *(test6_client_info*)context;
MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context); MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context);
if (response) if (response)
...@@ -1022,9 +1014,9 @@ void test6_onConnectFailure(void* context, MQTTAsync_failureData* response) ...@@ -1022,9 +1014,9 @@ void test6_onConnectFailure(void* context, MQTTAsync_failureData* response)
void test6_onConnect(void* context, MQTTAsync_successData* response) void test6_onConnect(void* context, MQTTAsync_successData* response)
{ {
test6_client_info cinfo = *(test6_client_info*)context; test6_client_info cinfo = *(test6_client_info*)context;
MyLog(LOGA_DEBUG, "In connect success callback, context %p", context); MyLog(LOGA_DEBUG, "In connect success callback, context %p", context);
assert("Should connect correctly", !cinfo.should_fail, "should_fail was %d", cinfo.should_fail); assert("Should connect correctly", !cinfo.should_fail, "should_fail was %d", cinfo.should_fail);
test_finished = 1; test_finished = 1;
...@@ -1050,11 +1042,11 @@ int test6(struct Options options) ...@@ -1050,11 +1042,11 @@ int test6(struct Options options)
MyLog(LOGA_INFO, "Starting test 6 - HA connections"); MyLog(LOGA_INFO, "Starting test 6 - HA connections");
fprintf(xml, "<testcase classname=\"test4\" name=\"HA connections\""); fprintf(xml, "<testcase classname=\"test4\" name=\"HA connections\"");
global_start_time = start_clock(); global_start_time = start_clock();
test_finished = 0; test_finished = 0;
cinfo.should_fail = 1; /* fail to connect */ cinfo.should_fail = 1; /* fail to connect */
rc = MQTTAsync_create(&cinfo.c, "tcp://rubbish:1883", "async ha connection", rc = MQTTAsync_create(&cinfo.c, "tcp://rubbish:1883", "async ha connection",
MQTTCLIENT_PERSISTENCE_DEFAULT, NULL); MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc); assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
if (rc != MQTTASYNC_SUCCESS) if (rc != MQTTASYNC_SUCCESS)
{ {
...@@ -1082,12 +1074,12 @@ int test6(struct Options options) ...@@ -1082,12 +1074,12 @@ int test6(struct Options options)
Sleep(100); Sleep(100);
#else #else
usleep(10000L); usleep(10000L);
#endif #endif
test_finished = 0; test_finished = 0;
cinfo.should_fail = 0; /* should connect */ cinfo.should_fail = 0; /* should connect */
rc = MQTTAsync_create(&cinfo.c, "tcp://rubbish:1883", "async ha connection", rc = MQTTAsync_create(&cinfo.c, "tcp://rubbish:1883", "async ha connection",
MQTTCLIENT_PERSISTENCE_DEFAULT, NULL); MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc); assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
if (rc != MQTTASYNC_SUCCESS) if (rc != MQTTASYNC_SUCCESS)
{ {
...@@ -1116,7 +1108,7 @@ int test6(struct Options options) ...@@ -1116,7 +1108,7 @@ int test6(struct Options options)
Sleep(100); Sleep(100);
#else #else
usleep(10000L); usleep(10000L);
#endif #endif
MQTTAsync_destroy(&cinfo.c); MQTTAsync_destroy(&cinfo.c);
...@@ -1704,7 +1696,7 @@ int main(int argc, char** argv) ...@@ -1704,7 +1696,7 @@ int main(int argc, char** argv)
xml = fopen("TEST-test4.xml", "w"); xml = fopen("TEST-test4.xml", "w");
fprintf(xml, "<testsuite name=\"test4\" tests=\"%d\">\n", (int)(ARRAY_SIZE(tests)) - 1); fprintf(xml, "<testsuite name=\"test4\" tests=\"%d\">\n", (int)(ARRAY_SIZE(tests)) - 1);
getopts(argc, argv); getopts(argc, argv);
MQTTAsync_setTraceCallback(trace_callback); MQTTAsync_setTraceCallback(trace_callback);
...@@ -1724,7 +1716,7 @@ int main(int argc, char** argv) ...@@ -1724,7 +1716,7 @@ int main(int argc, char** argv)
{ {
failures = 0; failures = 0;
MQTTAsync_setTraceLevel(MQTTASYNC_TRACE_ERROR); MQTTAsync_setTraceLevel(MQTTASYNC_TRACE_ERROR);
rc += tests[options.test_no](options); /* return number of failures. 0 = test succeeded */ rc += tests[options.test_no](options); /* return number of failures. 0 = test succeeded */
} }
} }
else else
...@@ -1741,6 +1733,6 @@ int main(int argc, char** argv) ...@@ -1741,6 +1733,6 @@ int main(int argc, char** argv)
fprintf(xml, "</testsuite>\n"); fprintf(xml, "</testsuite>\n");
fclose(xml); fclose(xml);
return rc; return rc;
} }
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
* *
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution. * and Eclipse Distribution License v1.0 which accompany this distribution.
* *
* The Eclipse Public License is available at * The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at * and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php. * http://www.eclipse.org/org/documents/edl-v10.php.
* *
* Contributors: * Contributors:
...@@ -37,15 +37,8 @@ ...@@ -37,15 +37,8 @@
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#else #else
#include <winsock2.h> #include <windows.h>
#include <ws2tcpip.h>
#define MAXHOSTNAMELEN 256 #define MAXHOSTNAMELEN 256
#define EAGAIN WSAEWOULDBLOCK
#define EINTR WSAEINTR
#define EINPROGRESS WSAEINPROGRESS
#define EWOULDBLOCK WSAEWOULDBLOCK
#define ENOTCONN WSAENOTCONN
#define ECONNRESET WSAECONNRESET
#define snprintf _snprintf #define snprintf _snprintf
#endif #endif
...@@ -79,7 +72,7 @@ struct Options ...@@ -79,7 +72,7 @@ struct Options
int test_no; int test_no;
int size; int size;
} options = } options =
{ {
"ssl://m2m.eclipse.org:18883", "ssl://m2m.eclipse.org:18883",
"ssl://m2m.eclipse.org:18884", "ssl://m2m.eclipse.org:18884",
"ssl://m2m.eclipse.org:18887", "ssl://m2m.eclipse.org:18887",
...@@ -282,11 +275,11 @@ void write_test_result(void) ...@@ -282,11 +275,11 @@ void write_test_result(void)
{ {
long duration = elapsed(global_start_time); long duration = elapsed(global_start_time);
fprintf(xml, " time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000); fprintf(xml, " time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000);
if (cur_output != output) if (cur_output != output)
{ {
fprintf(xml, "%s", output); fprintf(xml, "%s", output);
cur_output = output; cur_output = output;
} }
fprintf(xml, "</testcase>\n"); fprintf(xml, "</testcase>\n");
} }
...@@ -307,7 +300,7 @@ void myassert(char* filename, int lineno, char* description, int value, ...@@ -307,7 +300,7 @@ void myassert(char* filename, int lineno, char* description, int value,
vprintf(format, args); vprintf(format, args);
va_end(args); va_end(args);
cur_output += sprintf(cur_output, "<failure type=\"%s\">file %s, line %d </failure>\n", cur_output += sprintf(cur_output, "<failure type=\"%s\">file %s, line %d </failure>\n",
description, filename, lineno); description, filename, lineno);
} }
else else
...@@ -932,7 +925,7 @@ int test2c(struct Options options) ...@@ -932,7 +925,7 @@ int test2c(struct Options options)
fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname); fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname);
global_start_time = start_clock(); global_start_time = start_clock();
rc = MQTTAsync_create(&c, options.nocert_mutual_auth_connection, rc = MQTTAsync_create(&c, options.nocert_mutual_auth_connection,
"test2c", MQTTCLIENT_PERSISTENCE_DEFAULT, NULL); "test2c", MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc); assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
if (rc != MQTTASYNC_SUCCESS) if (rc != MQTTASYNC_SUCCESS)
...@@ -2071,4 +2064,3 @@ int main(int argc, char** argv) ...@@ -2071,4 +2064,3 @@ int main(int argc, char** argv)
return rc; return rc;
} }
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
#include <unistd.h> #include <unistd.h>
#include <signal.h> #include <signal.h>
#else #else
#include <winsock2.h> #include <windows.h>
#endif #endif
void usage(void) void usage(void)
...@@ -332,7 +332,7 @@ int control_send(char* message) ...@@ -332,7 +332,7 @@ int control_send(char* message)
MQTTAsync_responseOptions ropts = MQTTAsync_responseOptions_initializer; MQTTAsync_responseOptions ropts = MQTTAsync_responseOptions_initializer;
sprintf(buf, "%s: %s", opts.clientid, message); sprintf(buf, "%s: %s", opts.clientid, message);
rc = MQTTAsync_send(control_client, pub_topic, strlen(buf), rc = MQTTAsync_send(control_client, pub_topic, (int)strlen(buf),
buf, 1, 0, &ropts); buf, 1, 0, &ropts);
MyLog(LOGA_DEBUG, "Control message sent: %s", buf); MyLog(LOGA_DEBUG, "Control message sent: %s", buf);
...@@ -636,7 +636,7 @@ void one_iteration(void) ...@@ -636,7 +636,7 @@ void one_iteration(void)
sprintf(payload, "message number %d", i); sprintf(payload, "message number %d", i);
rc = MQTTAsync_send(client, opts.topic, strlen(payload)+1, payload, rc = MQTTAsync_send(client, opts.topic, (int)(strlen(payload)+1), payload,
opts.qos, opts.retained, NULL); opts.qos, opts.retained, NULL);
while (rc != MQTTASYNC_SUCCESS) while (rc != MQTTASYNC_SUCCESS)
{ {
...@@ -645,7 +645,7 @@ void one_iteration(void) ...@@ -645,7 +645,7 @@ void one_iteration(void)
if (stopping) if (stopping)
goto exit; goto exit;
mqsleep(1); mqsleep(1);
rc = MQTTAsync_send(client, opts.topic, strlen(payload)+1, payload, rc = MQTTAsync_send(client, opts.topic, (int)(strlen(payload)+1), payload,
opts.qos, opts.retained, NULL); opts.qos, opts.retained, NULL);
} }
} }
...@@ -687,7 +687,7 @@ void one_iteration(void) ...@@ -687,7 +687,7 @@ void one_iteration(void)
ropts.onSuccess = messageSent; ropts.onSuccess = messageSent;
seqno++; seqno++;
sprintf(payload, "message number %d", seqno); sprintf(payload, "message number %d", seqno);
rc = MQTTAsync_send(client, opts.topic, strlen(payload)+1, payload, rc = MQTTAsync_send(client, opts.topic, (int)(strlen(payload)+1), payload,
opts.qos, opts.retained, &ropts); opts.qos, opts.retained, &ropts);
while (rc != MQTTASYNC_SUCCESS) while (rc != MQTTASYNC_SUCCESS)
{ {
...@@ -697,7 +697,7 @@ void one_iteration(void) ...@@ -697,7 +697,7 @@ void one_iteration(void)
if (stopping) if (stopping)
goto exit; goto exit;
mqsleep(1); mqsleep(1);
rc = MQTTAsync_send(client, opts.topic, strlen(payload)+1, payload, rc = MQTTAsync_send(client, opts.topic, (int)(strlen(payload)+1), payload,
opts.qos, opts.retained, &ropts); opts.qos, opts.retained, &ropts);
} }
//MyLog(LOGA_DEBUG, "Successful publish with payload %s", payload); //MyLog(LOGA_DEBUG, "Successful publish with payload %s", payload);
......
...@@ -29,19 +29,11 @@ ...@@ -29,19 +29,11 @@
#if !defined(_WINDOWS) #if !defined(_WINDOWS)
#include <sys/time.h> #include <sys/time.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#else #else
#include <winsock2.h> #include <windows.h>
#include <ws2tcpip.h>
#define MAXHOSTNAMELEN 256
#define EAGAIN WSAEWOULDBLOCK
#define EINTR WSAEINTR
#define EINPROGRESS WSAEINPROGRESS
#define EWOULDBLOCK WSAEWOULDBLOCK
#define ENOTCONN WSAENOTCONN
#define ECONNRESET WSAECONNRESET
#endif #endif
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
...@@ -69,7 +61,7 @@ struct Options ...@@ -69,7 +61,7 @@ struct Options
void getopts(int argc, char** argv) void getopts(int argc, char** argv)
{ {
int count = 1; int count = 1;
while (count < argc) while (count < argc)
{ {
if (strcmp(argv[count], "--test_no") == 0) if (strcmp(argv[count], "--test_no") == 0)
...@@ -118,7 +110,7 @@ void MyLog(int LOGA_level, char* format, ...) ...@@ -118,7 +110,7 @@ void MyLog(int LOGA_level, char* format, ...)
if (LOGA_level == LOGA_DEBUG && options.verbose == 0) if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
return; return;
ftime(&ts); ftime(&ts);
timeinfo = localtime(&ts.time); timeinfo = localtime(&ts.time);
strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo); strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo);
...@@ -218,7 +210,7 @@ void myassert(char* filename, int lineno, char* description, int value, char* fo ...@@ -218,7 +210,7 @@ void myassert(char* filename, int lineno, char* description, int value, char* fo
va_end(args); va_end(args);
} }
else else
MyLog(LOGA_DEBUG, "Assertion succeeded, file %s, line %d, description: %s", filename, lineno, description); MyLog(LOGA_DEBUG, "Assertion succeeded, file %s, line %d, description: %s", filename, lineno, description);
} }
volatile int test_finished = 0; volatile int test_finished = 0;
...@@ -239,7 +231,7 @@ void test1_onUnsubscribe(void* context, MQTTAsync_successData* response) ...@@ -239,7 +231,7 @@ void test1_onUnsubscribe(void* context, MQTTAsync_successData* response)
MQTTAsync c = (MQTTAsync)context; MQTTAsync c = (MQTTAsync)context;
MQTTAsync_disconnectOptions opts = MQTTAsync_disconnectOptions_initializer; MQTTAsync_disconnectOptions opts = MQTTAsync_disconnectOptions_initializer;
int rc; int rc;
MyLog(LOGA_DEBUG, "In onUnsubscribe onSuccess callback %p", c); MyLog(LOGA_DEBUG, "In onUnsubscribe onSuccess callback %p", c);
opts.onSuccess = test1_onDisconnect; opts.onSuccess = test1_onDisconnect;
opts.context = c; opts.context = c;
...@@ -288,7 +280,7 @@ void test1_onSubscribe(void* context, MQTTAsync_successData* response) ...@@ -288,7 +280,7 @@ void test1_onSubscribe(void* context, MQTTAsync_successData* response)
MQTTAsync c = (MQTTAsync)context; MQTTAsync c = (MQTTAsync)context;
MQTTAsync_message pubmsg = MQTTAsync_message_initializer; MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
int rc; int rc;
MyLog(LOGA_DEBUG, "In subscribe onSuccess callback %p granted qos %d", c, response->alt.qos); MyLog(LOGA_DEBUG, "In subscribe onSuccess callback %p granted qos %d", c, response->alt.qos);
pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11"; pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
...@@ -305,7 +297,7 @@ void test1_onConnect(void* context, MQTTAsync_successData* response) ...@@ -305,7 +297,7 @@ void test1_onConnect(void* context, MQTTAsync_successData* response)
MQTTAsync c = (MQTTAsync)context; MQTTAsync c = (MQTTAsync)context;
MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
int rc; int rc;
MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context); MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
opts.onSuccess = test1_onSubscribe; opts.onSuccess = test1_onSubscribe;
opts.context = c; opts.context = c;
...@@ -321,8 +313,7 @@ void test1_onConnectFailure(void* context, MQTTAsync_failureData* response) ...@@ -321,8 +313,7 @@ void test1_onConnectFailure(void* context, MQTTAsync_failureData* response)
{ {
MQTTAsync c = (MQTTAsync)context; MQTTAsync c = (MQTTAsync)context;
MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
int rc;
MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context); MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context);
test_finished = 1; test_finished = 1;
...@@ -346,9 +337,9 @@ int test1(struct Options options) ...@@ -346,9 +337,9 @@ int test1(struct Options options)
failures = 0; failures = 0;
MyLog(LOGA_INFO, "Starting test 1 - asynchronous connect"); MyLog(LOGA_INFO, "Starting test 1 - asynchronous connect");
rc = MQTTAsync_create(&c, options.connection, "async_test", rc = MQTTAsync_create(&c, options.connection, "async_test",
MQTTCLIENT_PERSISTENCE_DEFAULT, NULL); MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc); assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
if (rc != MQTTASYNC_SUCCESS) if (rc != MQTTASYNC_SUCCESS)
{ {
...@@ -388,7 +379,7 @@ int test1(struct Options options) ...@@ -388,7 +379,7 @@ int test1(struct Options options)
Sleep(100); Sleep(100);
#else #else
usleep(10000L); usleep(10000L);
#endif #endif
MQTTAsync_destroy(&c); MQTTAsync_destroy(&c);
...@@ -437,9 +428,9 @@ int test2(struct Options options) ...@@ -437,9 +428,9 @@ int test2(struct Options options)
test_finished = 0; test_finished = 0;
MyLog(LOGA_INFO, "Starting test 2 - connect timeout"); MyLog(LOGA_INFO, "Starting test 2 - connect timeout");
rc = MQTTAsync_create(&c, "tcp://9.20.96.160:66", "connect timeout", rc = MQTTAsync_create(&c, "tcp://9.20.96.160:66", "connect timeout",
MQTTCLIENT_PERSISTENCE_DEFAULT, NULL); MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc); assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
if (rc != MQTTASYNC_SUCCESS) if (rc != MQTTASYNC_SUCCESS)
{ {
...@@ -478,12 +469,12 @@ int test2(struct Options options) ...@@ -478,12 +469,12 @@ int test2(struct Options options)
Sleep(100); Sleep(100);
#else #else
usleep(10000L); usleep(10000L);
#endif #endif
MQTTAsync_destroy(&c); MQTTAsync_destroy(&c);
exit: exit:
assert("Connect onFailure should be called once", test2_onFailure_called == 1, assert("Connect onFailure should be called once", test2_onFailure_called == 1,
"connect onFailure was called %d times", test2_onFailure_called); "connect onFailure was called %d times", test2_onFailure_called);
MyLog(LOGA_INFO, "TEST2: test %s. %d tests run, %d failures.", MyLog(LOGA_INFO, "TEST2: test %s. %d tests run, %d failures.",
...@@ -523,7 +514,7 @@ void test3_onUnsubscribe(void* context, MQTTAsync_successData* response) ...@@ -523,7 +514,7 @@ void test3_onUnsubscribe(void* context, MQTTAsync_successData* response)
client_data* cd = (client_data*)context; client_data* cd = (client_data*)context;
MQTTAsync_disconnectOptions opts = MQTTAsync_disconnectOptions_initializer; MQTTAsync_disconnectOptions opts = MQTTAsync_disconnectOptions_initializer;
int rc; int rc;
MyLog(LOGA_DEBUG, "In onUnsubscribe onSuccess callback \"%s\"", cd->clientid); MyLog(LOGA_DEBUG, "In onUnsubscribe onSuccess callback \"%s\"", cd->clientid);
opts.onSuccess = test3_onDisconnect; opts.onSuccess = test3_onDisconnect;
opts.context = cd; opts.context = cd;
...@@ -584,7 +575,7 @@ void test3_onSubscribe(void* context, MQTTAsync_successData* response) ...@@ -584,7 +575,7 @@ void test3_onSubscribe(void* context, MQTTAsync_successData* response)
client_data* cd = (client_data*)context; client_data* cd = (client_data*)context;
MQTTAsync_message pubmsg = MQTTAsync_message_initializer; MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
int rc; int rc;
MyLog(LOGA_DEBUG, "In subscribe onSuccess callback \"%s\"", cd->clientid); MyLog(LOGA_DEBUG, "In subscribe onSuccess callback \"%s\"", cd->clientid);
pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11"; pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
...@@ -602,7 +593,7 @@ void test3_onConnect(void* context, MQTTAsync_successData* response) ...@@ -602,7 +593,7 @@ void test3_onConnect(void* context, MQTTAsync_successData* response)
client_data* cd = (client_data*)context; client_data* cd = (client_data*)context;
MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
int rc; int rc;
MyLog(LOGA_DEBUG, "In connect onSuccess callback, \"%s\"", cd->clientid); MyLog(LOGA_DEBUG, "In connect onSuccess callback, \"%s\"", cd->clientid);
opts.onSuccess = test3_onSubscribe; opts.onSuccess = test3_onSubscribe;
opts.context = cd; opts.context = cd;
...@@ -618,7 +609,7 @@ void test3_onFailure(void* context, MQTTAsync_failureData* response) ...@@ -618,7 +609,7 @@ void test3_onFailure(void* context, MQTTAsync_failureData* response)
{ {
client_data* cd = (client_data*)context; client_data* cd = (client_data*)context;
MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
assert("Should have connected", 0, "failed to connect", NULL); assert("Should have connected", 0, "failed to connect", NULL);
MyLog(LOGA_DEBUG, "In connect onFailure callback, \"%s\" rc %d\n", cd->clientid, response->code); MyLog(LOGA_DEBUG, "In connect onFailure callback, \"%s\" rc %d\n", cd->clientid, response->code);
if (response->message) if (response->message)
...@@ -646,7 +637,7 @@ int test3(struct Options options) ...@@ -646,7 +637,7 @@ int test3(struct Options options)
test_finished = 0; test_finished = 0;
MyLog(LOGA_INFO, "Starting test 3 - multiple connections"); MyLog(LOGA_INFO, "Starting test 3 - multiple connections");
for (i = 0; i < num_clients; ++i) for (i = 0; i < num_clients; ++i)
{ {
sprintf(clientdata[i].clientid, "async_test3_num_%d", i); sprintf(clientdata[i].clientid, "async_test3_num_%d", i);
...@@ -655,9 +646,9 @@ int test3(struct Options options) ...@@ -655,9 +646,9 @@ int test3(struct Options options)
clientdata[i].message_count = 0; clientdata[i].message_count = 0;
rc = MQTTAsync_create(&(clientdata[i].c), options.connection, clientdata[i].clientid, rc = MQTTAsync_create(&(clientdata[i].c), options.connection, clientdata[i].clientid,
MQTTCLIENT_PERSISTENCE_NONE, NULL); MQTTCLIENT_PERSISTENCE_NONE, NULL);
assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc); assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
rc = MQTTAsync_setCallbacks(clientdata[i].c, &clientdata[i], NULL, test3_messageArrived, NULL); rc = MQTTAsync_setCallbacks(clientdata[i].c, &clientdata[i], NULL, test3_messageArrived, NULL);
assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc); assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
...@@ -687,7 +678,7 @@ int test3(struct Options options) ...@@ -687,7 +678,7 @@ int test3(struct Options options)
Sleep(100); Sleep(100);
#else #else
usleep(10000L); usleep(10000L);
#endif #endif
} }
MyLog(LOGA_DEBUG, "TEST3: destroying clients"); MyLog(LOGA_DEBUG, "TEST3: destroying clients");
...@@ -695,7 +686,7 @@ int test3(struct Options options) ...@@ -695,7 +686,7 @@ int test3(struct Options options)
for (i = 0; i < num_clients; ++i) for (i = 0; i < num_clients; ++i)
MQTTAsync_destroy(&clientdata[i].c); MQTTAsync_destroy(&clientdata[i].c);
exit: /*exit:*/
MyLog(LOGA_INFO, "TEST3: test %s. %d tests run, %d failures.", MyLog(LOGA_INFO, "TEST3: test %s. %d tests run, %d failures.",
(failures == 0) ? "passed" : "failed", tests, failures); (failures == 0) ? "passed" : "failed", tests, failures);
...@@ -709,7 +700,7 @@ int test4_payloadlen = 0; ...@@ -709,7 +700,7 @@ int test4_payloadlen = 0;
void test4_onPublish(void* context, MQTTAsync_successData* response) void test4_onPublish(void* context, MQTTAsync_successData* response)
{ {
MQTTAsync c = (MQTTAsync)context; MQTTAsync c = (MQTTAsync)context;
MyLog(LOGA_DEBUG, "In publish onSuccess callback, context %p", context); MyLog(LOGA_DEBUG, "In publish onSuccess callback, context %p", context);
} }
...@@ -783,7 +774,7 @@ void test4_onSubscribe(void* context, MQTTAsync_successData* response) ...@@ -783,7 +774,7 @@ void test4_onSubscribe(void* context, MQTTAsync_successData* response)
MQTTAsync c = (MQTTAsync)context; MQTTAsync c = (MQTTAsync)context;
MQTTAsync_message pubmsg = MQTTAsync_message_initializer; MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
int rc, i; int rc, i;
MyLog(LOGA_DEBUG, "In subscribe onSuccess callback %p", c); MyLog(LOGA_DEBUG, "In subscribe onSuccess callback %p", c);
pubmsg.payload = test4_payload = malloc(options.size); pubmsg.payload = test4_payload = malloc(options.size);
...@@ -792,7 +783,7 @@ void test4_onSubscribe(void* context, MQTTAsync_successData* response) ...@@ -792,7 +783,7 @@ void test4_onSubscribe(void* context, MQTTAsync_successData* response)
srand(33); srand(33);
for (i = 0; i < options.size; ++i) for (i = 0; i < options.size; ++i)
((char*)pubmsg.payload)[i] = rand() % 256; ((char*)pubmsg.payload)[i] = rand() % 256;
pubmsg.qos = 2; pubmsg.qos = 2;
pubmsg.retained = 0; pubmsg.retained = 0;
...@@ -805,7 +796,7 @@ void test4_onConnect(void* context, MQTTAsync_successData* response) ...@@ -805,7 +796,7 @@ void test4_onConnect(void* context, MQTTAsync_successData* response)
MQTTAsync c = (MQTTAsync)context; MQTTAsync c = (MQTTAsync)context;
MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
int rc; int rc;
MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context); MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
opts.onSuccess = test4_onSubscribe; opts.onSuccess = test4_onSubscribe;
opts.context = c; opts.context = c;
...@@ -833,9 +824,9 @@ int test4(struct Options options) ...@@ -833,9 +824,9 @@ int test4(struct Options options)
test_finished = failures = 0; test_finished = failures = 0;
MyLog(LOGA_INFO, "Starting test 4 - big messages"); MyLog(LOGA_INFO, "Starting test 4 - big messages");
rc = MQTTAsync_create(&c, options.connection, "async_test_4", rc = MQTTAsync_create(&c, options.connection, "async_test_4",
MQTTCLIENT_PERSISTENCE_DEFAULT, NULL); MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc); assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
if (rc != MQTTASYNC_SUCCESS) if (rc != MQTTASYNC_SUCCESS)
{ {
...@@ -873,7 +864,7 @@ int test4(struct Options options) ...@@ -873,7 +864,7 @@ int test4(struct Options options)
Sleep(100); Sleep(100);
#else #else
usleep(1000L); usleep(1000L);
#endif #endif
MQTTAsync_destroy(&c); MQTTAsync_destroy(&c);
...@@ -897,18 +888,18 @@ int main(int argc, char** argv) ...@@ -897,18 +888,18 @@ int main(int argc, char** argv)
int rc = 0; int rc = 0;
int (*tests[])() = {NULL, test1, test2, test3, test4}; /* indexed starting from 1 */ int (*tests[])() = {NULL, test1, test2, test3, test4}; /* indexed starting from 1 */
MQTTAsync_nameValue* info; MQTTAsync_nameValue* info;
getopts(argc, argv); getopts(argc, argv);
MQTTAsync_setTraceCallback(trace_callback); MQTTAsync_setTraceCallback(trace_callback);
info = MQTTAsync_getVersionInfo(); info = MQTTAsync_getVersionInfo();
while (info->name) while (info->name)
{ {
MyLog(LOGA_INFO, "%s: %s", info->name, info->value); MyLog(LOGA_INFO, "%s: %s", info->name, info->value);
info++; info++;
} }
if (options.test_no == -1) if (options.test_no == -1)
{ /* run all the tests */ { /* run all the tests */
...@@ -916,7 +907,7 @@ int main(int argc, char** argv) ...@@ -916,7 +907,7 @@ int main(int argc, char** argv)
{ {
failures = 0; failures = 0;
MQTTAsync_setTraceLevel(MQTTASYNC_TRACE_ERROR); MQTTAsync_setTraceLevel(MQTTASYNC_TRACE_ERROR);
rc += tests[options.test_no](options); /* return number of failures. 0 = test succeeded */ rc += tests[options.test_no](options); /* return number of failures. 0 = test succeeded */
} }
} }
else else
...@@ -929,6 +920,6 @@ int main(int argc, char** argv) ...@@ -929,6 +920,6 @@ int main(int argc, char** argv)
MyLog(LOGA_INFO, "verdict pass"); MyLog(LOGA_INFO, "verdict pass");
else else
MyLog(LOGA_INFO, "verdict fail"); MyLog(LOGA_INFO, "verdict fail");
return rc; return rc;
} }
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
* *
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution. * and Eclipse Distribution License v1.0 which accompany this distribution.
* *
* The Eclipse Public License is available at * The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at * and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php. * http://www.eclipse.org/org/documents/edl-v10.php.
* *
* Contributors: * Contributors:
...@@ -30,19 +30,11 @@ ...@@ -30,19 +30,11 @@
#if !defined(_WINDOWS) #if !defined(_WINDOWS)
#include <sys/time.h> #include <sys/time.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#else #else
#include <winsock2.h> #include <windows.h>
#include <ws2tcpip.h>
#define MAXHOSTNAMELEN 256
#define EAGAIN WSAEWOULDBLOCK
#define EINTR WSAEINTR
#define EINPROGRESS WSAEINPROGRESS
#define EWOULDBLOCK WSAEWOULDBLOCK
#define ENOTCONN WSAENOTCONN
#define ECONNRESET WSAECONNRESET
#endif #endif
char unique[50]; // unique suffix/prefix to add to clientid/topic etc char unique[50]; // unique suffix/prefix to add to clientid/topic etc
...@@ -72,7 +64,7 @@ struct Options ...@@ -72,7 +64,7 @@ struct Options
void getopts(int argc, char** argv) void getopts(int argc, char** argv)
{ {
int count = 1; int count = 1;
while (count < argc) while (count < argc)
{ {
if (strcmp(argv[count], "--test_no") == 0) if (strcmp(argv[count], "--test_no") == 0)
...@@ -212,11 +204,11 @@ void write_test_result(void) ...@@ -212,11 +204,11 @@ void write_test_result(void)
{ {
long duration = elapsed(global_start_time); long duration = elapsed(global_start_time);
fprintf(xml, " time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000); fprintf(xml, " time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000);
if (cur_output != output) if (cur_output != output)
{ {
fprintf(xml, "%s", output); fprintf(xml, "%s", output);
cur_output = output; cur_output = output;
} }
fprintf(xml, "</testcase>\n"); fprintf(xml, "</testcase>\n");
} }
...@@ -237,7 +229,7 @@ void myassert(char* filename, int lineno, char* description, int value, ...@@ -237,7 +229,7 @@ void myassert(char* filename, int lineno, char* description, int value,
vprintf(format, args); vprintf(format, args);
va_end(args); va_end(args);
cur_output += sprintf(cur_output, "<failure type=\"%s\">file %s, line %d </failure>\n", cur_output += sprintf(cur_output, "<failure type=\"%s\">file %s, line %d </failure>\n",
description, filename, lineno); description, filename, lineno);
} }
else else
...@@ -248,46 +240,46 @@ void myassert(char* filename, int lineno, char* description, int value, ...@@ -248,46 +240,46 @@ void myassert(char* filename, int lineno, char* description, int value,
/********************************************************************* /*********************************************************************
Tests: offline buffering - sending messages while disconnected Tests: offline buffering - sending messages while disconnected
1. send some messages while disconnected, check that they are sent 1. send some messages while disconnected, check that they are sent
2. repeat test 1 using serverURIs 2. repeat test 1 using serverURIs
3. repeat test 1 using auto reconnect 3. repeat test 1 using auto reconnect
4. repeat test 2 using auto reconnect 4. repeat test 2 using auto reconnect
5. check max-buffered 5. check max-buffered
6. check auto-reconnect parms alter behaviour as expected 6. check auto-reconnect parms alter behaviour as expected
Tests: automatic reconnect Tests: automatic reconnect
- check that connected() is called - check that connected() is called
- check that reconnect() causes reconnect attempt - check that reconnect() causes reconnect attempt
- check that reconnect() fails if no connect has been previously attempted - check that reconnect() fails if no connect has been previously attempted
*********************************************************************/ *********************************************************************/
/********************************************************************* /*********************************************************************
Test1: offline buffering - sending messages while disconnected Test1: offline buffering - sending messages while disconnected
1. call connect 1. call connect
2. use proxy to disconnect the client 2. use proxy to disconnect the client
3. while the client is disconnected, send more messages 3. while the client is disconnected, send more messages
4. when the client reconnects, check that those messages are sent 4. when the client reconnects, check that those messages are sent
*********************************************************************/ *********************************************************************/
int test1_will_message_received = 0; int test1_will_message_received = 0;
int test1_messages_received = 0; int test1_messages_received = 0;
int test1_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message) int test1_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
{ {
MQTTAsync c = (MQTTAsync)context; MQTTAsync c = (MQTTAsync)context;
static int message_count = 0; static int message_count = 0;
MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\"", topicName, message->payloadlen, message->payload); MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\"", topicName, message->payloadlen, message->payload);
if (memcmp(message->payload, "will message", message->payloadlen) == 0) if (memcmp(message->payload, "will message", message->payloadlen) == 0)
test1_will_message_received = 1; test1_will_message_received = 1;
else else
...@@ -325,10 +317,10 @@ void test1cOnConnect(void* context, MQTTAsync_successData* response) ...@@ -325,10 +317,10 @@ void test1cOnConnect(void* context, MQTTAsync_successData* response)
MyLog(LOGA_DEBUG, "In connect onSuccess callback for client d, context %p\n", context); MyLog(LOGA_DEBUG, "In connect onSuccess callback for client d, context %p\n", context);
MQTTAsync c = (MQTTAsync)context; MQTTAsync c = (MQTTAsync)context;
int rc; int rc;
/* send a message to the proxy to break the connection */ /* send a message to the proxy to break the connection */
pubmsg.payload = "TERMINATE"; pubmsg.payload = "TERMINATE";
pubmsg.payloadlen = strlen(pubmsg.payload); pubmsg.payloadlen = (int)strlen(pubmsg.payload);
pubmsg.qos = 0; pubmsg.qos = 0;
pubmsg.retained = 0; pubmsg.retained = 0;
rc = MQTTAsync_sendMessage(c, "MQTTSAS topic", &pubmsg, NULL); rc = MQTTAsync_sendMessage(c, "MQTTSAS topic", &pubmsg, NULL);
...@@ -391,7 +383,7 @@ int test1(struct Options options) ...@@ -391,7 +383,7 @@ int test1(struct Options options)
char clientidd[50]; char clientidd[50];
int i = 0; int i = 0;
MQTTAsync_token *tokens; MQTTAsync_token *tokens;
sprintf(willTopic, "paho-test9-1-%s", unique); sprintf(willTopic, "paho-test9-1-%s", unique);
sprintf(clientidc, "paho-test9-1-c-%s", unique); sprintf(clientidc, "paho-test9-1-c-%s", unique);
sprintf(clientidd, "paho-test9-1-d-%s", unique); sprintf(clientidd, "paho-test9-1-d-%s", unique);
...@@ -404,7 +396,7 @@ int test1(struct Options options) ...@@ -404,7 +396,7 @@ int test1(struct Options options)
global_start_time = start_clock(); global_start_time = start_clock();
createOptions.sendWhileDisconnected = 1; createOptions.sendWhileDisconnected = 1;
rc = MQTTAsync_createWithOptions(&c, options.proxy_connection, clientidc, MQTTCLIENT_PERSISTENCE_DEFAULT, rc = MQTTAsync_createWithOptions(&c, options.proxy_connection, clientidc, MQTTCLIENT_PERSISTENCE_DEFAULT,
NULL, &createOptions); NULL, &createOptions);
assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc); assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
if (rc != MQTTASYNC_SUCCESS) if (rc != MQTTASYNC_SUCCESS)
...@@ -412,7 +404,7 @@ int test1(struct Options options) ...@@ -412,7 +404,7 @@ int test1(struct Options options)
MQTTAsync_destroy(&c); MQTTAsync_destroy(&c);
goto exit; goto exit;
} }
rc = MQTTAsync_create(&d, options.connection, clientidd, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL); rc = MQTTAsync_create(&d, options.connection, clientidd, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc); assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
if (rc != MQTTASYNC_SUCCESS) if (rc != MQTTASYNC_SUCCESS)
...@@ -425,7 +417,7 @@ int test1(struct Options options) ...@@ -425,7 +417,7 @@ int test1(struct Options options)
opts.cleansession = 1; opts.cleansession = 1;
//opts.username = "testuser"; //opts.username = "testuser";
//opts.password = "testpassword"; //opts.password = "testpassword";
rc = MQTTAsync_setCallbacks(d, d, NULL, test1_messageArrived, NULL); rc = MQTTAsync_setCallbacks(d, d, NULL, test1_messageArrived, NULL);
assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc); assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
...@@ -441,16 +433,16 @@ int test1(struct Options options) ...@@ -441,16 +433,16 @@ int test1(struct Options options)
failures++; failures++;
goto exit; goto exit;
} }
/* wait until d is ready: connected and subscribed */ /* wait until d is ready: connected and subscribed */
count = 0; count = 0;
while (!test1dReady && ++count < 10000) while (!test1dReady && ++count < 10000)
MySleep(100); MySleep(100);
assert("Count should be less than 10000", count < 10000, "count was %d", count); /* wrong */ assert("Count should be less than 10000", count < 10000, "count was %d", count); /* wrong */
rc = MQTTAsync_setConnected(c, c, test1cConnected); rc = MQTTAsync_setConnected(c, c, test1cConnected);
assert("Good rc from setConnectedCallback", rc == MQTTASYNC_SUCCESS, "rc was %d", rc); assert("Good rc from setConnectedCallback", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
/* let client c go: connect, and send disconnect command to proxy */ /* let client c go: connect, and send disconnect command to proxy */
opts.will = &wopts; opts.will = &wopts;
opts.will->message = "will message"; opts.will->message = "will message";
...@@ -470,24 +462,24 @@ int test1(struct Options options) ...@@ -470,24 +462,24 @@ int test1(struct Options options)
failures++; failures++;
goto exit; goto exit;
} }
/* wait for will message */ /* wait for will message */
while (!test1_will_message_received && ++count < 10000) while (!test1_will_message_received && ++count < 10000)
MySleep(100); MySleep(100);
MyLog(LOGA_DEBUG, "Now we can send some messages to be buffered"); MyLog(LOGA_DEBUG, "Now we can send some messages to be buffered");
test1c_connected = 0; test1c_connected = 0;
/* send some messages. Then reconnect (check connected callback), and check that those messages are received */ /* send some messages. Then reconnect (check connected callback), and check that those messages are received */
for (i = 0; i < 3; ++i) for (i = 0; i < 3; ++i)
{ {
char buf[50]; char buf[50];
MQTTAsync_message pubmsg = MQTTAsync_message_initializer; MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
sprintf(buf, "QoS %d message", i); sprintf(buf, "QoS %d message", i);
pubmsg.payload = buf; pubmsg.payload = buf;
pubmsg.payloadlen = strlen(pubmsg.payload) + 1; pubmsg.payloadlen = (int)strlen(pubmsg.payload) + 1;
pubmsg.qos = i; pubmsg.qos = i;
pubmsg.retained = 0; pubmsg.retained = 0;
rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts); rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts);
...@@ -504,14 +496,14 @@ int test1(struct Options options) ...@@ -504,14 +496,14 @@ int test1(struct Options options)
MQTTAsync_free(tokens); MQTTAsync_free(tokens);
} }
assert("Number of getPendingTokens should be 3", i == 3, "i was %d ", i); assert("Number of getPendingTokens should be 3", i == 3, "i was %d ", i);
rc = MQTTAsync_reconnect(c); rc = MQTTAsync_reconnect(c);
assert("Good rc from reconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc); assert("Good rc from reconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
/* wait for client to be reconnected */ /* wait for client to be reconnected */
while (!test1c_connected && ++count < 10000) while (!test1c_connected && ++count < 10000)
MySleep(100); MySleep(100);
/* wait for success or failure callback */ /* wait for success or failure callback */
while (test1_messages_received < 3 && ++count < 10000) while (test1_messages_received < 3 && ++count < 10000)
MySleep(100); MySleep(100);
...@@ -526,10 +518,10 @@ int test1(struct Options options) ...@@ -526,10 +518,10 @@ int test1(struct Options options)
MQTTAsync_free(tokens); MQTTAsync_free(tokens);
} }
assert("Number of getPendingTokens should be 0", i == 0, "i was %d ", i); assert("Number of getPendingTokens should be 0", i == 0, "i was %d ", i);
rc = MQTTAsync_disconnect(c, NULL); rc = MQTTAsync_disconnect(c, NULL);
assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc); assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
rc = MQTTAsync_disconnect(d, NULL); rc = MQTTAsync_disconnect(d, NULL);
assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc); assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
...@@ -546,24 +538,24 @@ exit: ...@@ -546,24 +538,24 @@ exit:
/********************************************************************* /*********************************************************************
Test2: offline buffering - sending messages while disconnected Test2: offline buffering - sending messages while disconnected
1. call connect 1. call connect
2. use proxy to disconnect the client 2. use proxy to disconnect the client
3. while the client is disconnected, send more messages 3. while the client is disconnected, send more messages
4. when the client reconnects, check that those messages are sent 4. when the client reconnects, check that those messages are sent
*********************************************************************/ *********************************************************************/
int test2_will_message_received = 0; int test2_will_message_received = 0;
int test2_messages_received = 0; int test2_messages_received = 0;
int test2_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message) int test2_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
{ {
MQTTAsync c = (MQTTAsync)context; MQTTAsync c = (MQTTAsync)context;
static int message_count = 0; static int message_count = 0;
MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\"", topicName, message->payloadlen, message->payload); MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\"", topicName, message->payloadlen, message->payload);
if (memcmp(message->payload, "will message", message->payloadlen) == 0) if (memcmp(message->payload, "will message", message->payloadlen) == 0)
test2_will_message_received = 1; test2_will_message_received = 1;
else else
...@@ -601,10 +593,10 @@ void test2cOnConnect(void* context, MQTTAsync_successData* response) ...@@ -601,10 +593,10 @@ void test2cOnConnect(void* context, MQTTAsync_successData* response)
MyLog(LOGA_DEBUG, "In connect onSuccess callback for client d, context %p\n", context); MyLog(LOGA_DEBUG, "In connect onSuccess callback for client d, context %p\n", context);
MQTTAsync c = (MQTTAsync)context; MQTTAsync c = (MQTTAsync)context;
int rc; int rc;
/* send a message to the proxy to break the connection */ /* send a message to the proxy to break the connection */
pubmsg.payload = "TERMINATE"; pubmsg.payload = "TERMINATE";
pubmsg.payloadlen = strlen(pubmsg.payload); pubmsg.payloadlen = (int)strlen(pubmsg.payload);
pubmsg.qos = 0; pubmsg.qos = 0;
pubmsg.retained = 0; pubmsg.retained = 0;
rc = MQTTAsync_sendMessage(c, "MQTTSAS topic", &pubmsg, NULL); rc = MQTTAsync_sendMessage(c, "MQTTSAS topic", &pubmsg, NULL);
...@@ -668,7 +660,7 @@ int test2(struct Options options) ...@@ -668,7 +660,7 @@ int test2(struct Options options)
int i = 0; int i = 0;
MQTTAsync_token *tokens; MQTTAsync_token *tokens;
char *URIs[2] = {"rubbish", options.proxy_connection}; char *URIs[2] = {"rubbish", options.proxy_connection};
sprintf(willTopic, "paho-test9-2-%s", unique); sprintf(willTopic, "paho-test9-2-%s", unique);
sprintf(clientidc, "paho-test9-2-c-%s", unique); sprintf(clientidc, "paho-test9-2-c-%s", unique);
sprintf(clientidd, "paho-test9-2-d-%s", unique); sprintf(clientidd, "paho-test9-2-d-%s", unique);
...@@ -681,7 +673,7 @@ int test2(struct Options options) ...@@ -681,7 +673,7 @@ int test2(struct Options options)
global_start_time = start_clock(); global_start_time = start_clock();
createOptions.sendWhileDisconnected = 1; createOptions.sendWhileDisconnected = 1;
rc = MQTTAsync_createWithOptions(&c, "not used", clientidc, MQTTCLIENT_PERSISTENCE_DEFAULT, rc = MQTTAsync_createWithOptions(&c, "not used", clientidc, MQTTCLIENT_PERSISTENCE_DEFAULT,
NULL, &createOptions); NULL, &createOptions);
assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc); assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
if (rc != MQTTASYNC_SUCCESS) if (rc != MQTTASYNC_SUCCESS)
...@@ -689,7 +681,7 @@ int test2(struct Options options) ...@@ -689,7 +681,7 @@ int test2(struct Options options)
MQTTAsync_destroy(&c); MQTTAsync_destroy(&c);
goto exit; goto exit;
} }
rc = MQTTAsync_create(&d, options.connection, clientidd, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL); rc = MQTTAsync_create(&d, options.connection, clientidd, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc); assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
if (rc != MQTTASYNC_SUCCESS) if (rc != MQTTASYNC_SUCCESS)
...@@ -700,7 +692,7 @@ int test2(struct Options options) ...@@ -700,7 +692,7 @@ int test2(struct Options options)
opts.keepAliveInterval = 20; opts.keepAliveInterval = 20;
opts.cleansession = 1; opts.cleansession = 1;
rc = MQTTAsync_setCallbacks(d, d, NULL, test2_messageArrived, NULL); rc = MQTTAsync_setCallbacks(d, d, NULL, test2_messageArrived, NULL);
assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc); assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
...@@ -716,16 +708,16 @@ int test2(struct Options options) ...@@ -716,16 +708,16 @@ int test2(struct Options options)
failures++; failures++;
goto exit; goto exit;
} }
/* wait until d is ready: connected and subscribed */ /* wait until d is ready: connected and subscribed */
count = 0; count = 0;
while (!test2dReady && ++count < 10000) while (!test2dReady && ++count < 10000)
MySleep(100); MySleep(100);
assert("Count should be less than 10000", count < 10000, "count was %d", count); /* wrong */ assert("Count should be less than 10000", count < 10000, "count was %d", count); /* wrong */
rc = MQTTAsync_setConnected(c, c, test2cConnected); rc = MQTTAsync_setConnected(c, c, test2cConnected);
assert("Good rc from setConnectedCallback", rc == MQTTASYNC_SUCCESS, "rc was %d", rc); assert("Good rc from setConnectedCallback", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
/* let client c go: connect, and send disconnect command to proxy */ /* let client c go: connect, and send disconnect command to proxy */
opts.will = &wopts; opts.will = &wopts;
opts.will->message = "will message"; opts.will->message = "will message";
...@@ -747,24 +739,24 @@ int test2(struct Options options) ...@@ -747,24 +739,24 @@ int test2(struct Options options)
failures++; failures++;
goto exit; goto exit;
} }
/* wait for will message */ /* wait for will message */
while (!test2_will_message_received && ++count < 10000) while (!test2_will_message_received && ++count < 10000)
MySleep(100); MySleep(100);
MyLog(LOGA_DEBUG, "Now we can send some messages to be buffered"); MyLog(LOGA_DEBUG, "Now we can send some messages to be buffered");
test2c_connected = 0; test2c_connected = 0;
/* send some messages. Then reconnect (check connected callback), and check that those messages are received */ /* send some messages. Then reconnect (check connected callback), and check that those messages are received */
for (i = 0; i < 3; ++i) for (i = 0; i < 3; ++i)
{ {
char buf[50]; char buf[50];
MQTTAsync_message pubmsg = MQTTAsync_message_initializer; MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
sprintf(buf, "QoS %d message", i); sprintf(buf, "QoS %d message", i);
pubmsg.payload = buf; pubmsg.payload = buf;
pubmsg.payloadlen = strlen(pubmsg.payload) + 1; pubmsg.payloadlen = (int)(strlen(pubmsg.payload) + 1);
pubmsg.qos = i; pubmsg.qos = i;
pubmsg.retained = 0; pubmsg.retained = 0;
rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts); rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts);
...@@ -781,14 +773,14 @@ int test2(struct Options options) ...@@ -781,14 +773,14 @@ int test2(struct Options options)
MQTTAsync_free(tokens); MQTTAsync_free(tokens);
} }
assert("Number of getPendingTokens should be 3", i == 3, "i was %d ", i); assert("Number of getPendingTokens should be 3", i == 3, "i was %d ", i);
rc = MQTTAsync_reconnect(c); rc = MQTTAsync_reconnect(c);
assert("Good rc from reconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc); assert("Good rc from reconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
/* wait for client to be reconnected */ /* wait for client to be reconnected */
while (!test2c_connected && ++count < 10000) while (!test2c_connected && ++count < 10000)
MySleep(100); MySleep(100);
/* wait for success or failure callback */ /* wait for success or failure callback */
while (test2_messages_received < 3 && ++count < 10000) while (test2_messages_received < 3 && ++count < 10000)
MySleep(100); MySleep(100);
...@@ -803,10 +795,10 @@ int test2(struct Options options) ...@@ -803,10 +795,10 @@ int test2(struct Options options)
MQTTAsync_free(tokens); MQTTAsync_free(tokens);
} }
assert("Number of getPendingTokens should be 0", i == 0, "i was %d ", i); assert("Number of getPendingTokens should be 0", i == 0, "i was %d ", i);
rc = MQTTAsync_disconnect(c, NULL); rc = MQTTAsync_disconnect(c, NULL);
assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc); assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
rc = MQTTAsync_disconnect(d, NULL); rc = MQTTAsync_disconnect(d, NULL);
assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc); assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
...@@ -822,24 +814,24 @@ exit: ...@@ -822,24 +814,24 @@ exit:
/********************************************************************* /*********************************************************************
test3: offline buffering - sending messages while disconnected test3: offline buffering - sending messages while disconnected
1. call connect 1. call connect
2. use proxy to disconnect the client 2. use proxy to disconnect the client
3. while the client is disconnected, send more messages 3. while the client is disconnected, send more messages
4. when the client auto reconnects, check that those messages are sent 4. when the client auto reconnects, check that those messages are sent
*********************************************************************/ *********************************************************************/
int test3_will_message_received = 0; int test3_will_message_received = 0;
int test3_messages_received = 0; int test3_messages_received = 0;
int test3_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message) int test3_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
{ {
MQTTAsync c = (MQTTAsync)context; MQTTAsync c = (MQTTAsync)context;
static int message_count = 0; static int message_count = 0;
MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\"", topicName, message->payloadlen, message->payload); MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\"", topicName, message->payloadlen, message->payload);
if (memcmp(message->payload, "will message", message->payloadlen) == 0) if (memcmp(message->payload, "will message", message->payloadlen) == 0)
test3_will_message_received = 1; test3_will_message_received = 1;
else else
...@@ -877,10 +869,10 @@ void test3cOnConnect(void* context, MQTTAsync_successData* response) ...@@ -877,10 +869,10 @@ void test3cOnConnect(void* context, MQTTAsync_successData* response)
MyLog(LOGA_DEBUG, "In connect onSuccess callback for client d, context %p\n", context); MyLog(LOGA_DEBUG, "In connect onSuccess callback for client d, context %p\n", context);
MQTTAsync c = (MQTTAsync)context; MQTTAsync c = (MQTTAsync)context;
int rc; int rc;
/* send a message to the proxy to break the connection */ /* send a message to the proxy to break the connection */
pubmsg.payload = "TERMINATE"; pubmsg.payload = "TERMINATE";
pubmsg.payloadlen = strlen(pubmsg.payload); pubmsg.payloadlen = (int)strlen(pubmsg.payload);
pubmsg.qos = 0; pubmsg.qos = 0;
pubmsg.retained = 0; pubmsg.retained = 0;
rc = MQTTAsync_sendMessage(c, "MQTTSAS topic", &pubmsg, NULL); rc = MQTTAsync_sendMessage(c, "MQTTSAS topic", &pubmsg, NULL);
...@@ -943,7 +935,7 @@ int test3(struct Options options) ...@@ -943,7 +935,7 @@ int test3(struct Options options)
char clientidd[50]; char clientidd[50];
int i = 0; int i = 0;
MQTTAsync_token *tokens; MQTTAsync_token *tokens;
sprintf(willTopic, "paho-test9-3-%s", unique); sprintf(willTopic, "paho-test9-3-%s", unique);
sprintf(clientidc, "paho-test9-3-c-%s", unique); sprintf(clientidc, "paho-test9-3-c-%s", unique);
sprintf(clientidd, "paho-test9-3-d-%s", unique); sprintf(clientidd, "paho-test9-3-d-%s", unique);
...@@ -956,7 +948,7 @@ int test3(struct Options options) ...@@ -956,7 +948,7 @@ int test3(struct Options options)
global_start_time = start_clock(); global_start_time = start_clock();
createOptions.sendWhileDisconnected = 1; createOptions.sendWhileDisconnected = 1;
rc = MQTTAsync_createWithOptions(&c, options.proxy_connection, clientidc, MQTTCLIENT_PERSISTENCE_DEFAULT, rc = MQTTAsync_createWithOptions(&c, options.proxy_connection, clientidc, MQTTCLIENT_PERSISTENCE_DEFAULT,
NULL, &createOptions); NULL, &createOptions);
assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc); assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
if (rc != MQTTASYNC_SUCCESS) if (rc != MQTTASYNC_SUCCESS)
...@@ -964,7 +956,7 @@ int test3(struct Options options) ...@@ -964,7 +956,7 @@ int test3(struct Options options)
MQTTAsync_destroy(&c); MQTTAsync_destroy(&c);
goto exit; goto exit;
} }
rc = MQTTAsync_create(&d, options.connection, clientidd, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL); rc = MQTTAsync_create(&d, options.connection, clientidd, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc); assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
if (rc != MQTTASYNC_SUCCESS) if (rc != MQTTASYNC_SUCCESS)
...@@ -977,7 +969,7 @@ int test3(struct Options options) ...@@ -977,7 +969,7 @@ int test3(struct Options options)
opts.cleansession = 1; opts.cleansession = 1;
//opts.username = "testuser"; //opts.username = "testuser";
//opts.password = "testpassword"; //opts.password = "testpassword";
rc = MQTTAsync_setCallbacks(d, d, NULL, test3_messageArrived, NULL); rc = MQTTAsync_setCallbacks(d, d, NULL, test3_messageArrived, NULL);
assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc); assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
...@@ -993,16 +985,16 @@ int test3(struct Options options) ...@@ -993,16 +985,16 @@ int test3(struct Options options)
failures++; failures++;
goto exit; goto exit;
} }
/* wait until d is ready: connected and subscribed */ /* wait until d is ready: connected and subscribed */
count = 0; count = 0;
while (!test3dReady && ++count < 10000) while (!test3dReady && ++count < 10000)
MySleep(100); MySleep(100);
assert("Count should be less than 10000", count < 10000, "count was %d", count); /* wrong */ assert("Count should be less than 10000", count < 10000, "count was %d", count); /* wrong */
rc = MQTTAsync_setConnected(c, c, test3cConnected); rc = MQTTAsync_setConnected(c, c, test3cConnected);
assert("Good rc from setConnectedCallback", rc == MQTTASYNC_SUCCESS, "rc was %d", rc); assert("Good rc from setConnectedCallback", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
/* let client c go: connect, and send disconnect command to proxy */ /* let client c go: connect, and send disconnect command to proxy */
opts.will = &wopts; opts.will = &wopts;
opts.will->message = "will message"; opts.will->message = "will message";
...@@ -1023,24 +1015,24 @@ int test3(struct Options options) ...@@ -1023,24 +1015,24 @@ int test3(struct Options options)
failures++; failures++;
goto exit; goto exit;
} }
/* wait for will message */ /* wait for will message */
while (!test3_will_message_received && ++count < 10000) while (!test3_will_message_received && ++count < 10000)
MySleep(100); MySleep(100);
MyLog(LOGA_DEBUG, "Now we can send some messages to be buffered"); MyLog(LOGA_DEBUG, "Now we can send some messages to be buffered");
test3c_connected = 0; test3c_connected = 0;
/* send some messages. Then reconnect (check connected callback), and check that those messages are received */ /* send some messages. Then reconnect (check connected callback), and check that those messages are received */
for (i = 0; i < 3; ++i) for (i = 0; i < 3; ++i)
{ {
char buf[50]; char buf[50];
MQTTAsync_message pubmsg = MQTTAsync_message_initializer; MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
sprintf(buf, "QoS %d message", i); sprintf(buf, "QoS %d message", i);
pubmsg.payload = buf; pubmsg.payload = buf;
pubmsg.payloadlen = strlen(pubmsg.payload) + 1; pubmsg.payloadlen = (int)(strlen(pubmsg.payload) + 1);
pubmsg.qos = i; pubmsg.qos = i;
pubmsg.retained = 0; pubmsg.retained = 0;
rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts); rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts);
...@@ -1057,11 +1049,11 @@ int test3(struct Options options) ...@@ -1057,11 +1049,11 @@ int test3(struct Options options)
MQTTAsync_free(tokens); MQTTAsync_free(tokens);
} }
assert("Number of getPendingTokens should be 3", i == 3, "i was %d ", i); assert("Number of getPendingTokens should be 3", i == 3, "i was %d ", i);
/* wait for client to be reconnected */ /* wait for client to be reconnected */
while (!test3c_connected && ++count < 10000) while (!test3c_connected && ++count < 10000)
MySleep(100); MySleep(100);
/* wait for success or failure callback */ /* wait for success or failure callback */
while (test3_messages_received < 3 && ++count < 10000) while (test3_messages_received < 3 && ++count < 10000)
MySleep(100); MySleep(100);
...@@ -1076,11 +1068,11 @@ int test3(struct Options options) ...@@ -1076,11 +1068,11 @@ int test3(struct Options options)
MQTTAsync_free(tokens); MQTTAsync_free(tokens);
} }
assert("Number of getPendingTokens should be 0", i == 0, "i was %d ", i); assert("Number of getPendingTokens should be 0", i == 0, "i was %d ", i);
rc = MQTTAsync_disconnect(c, NULL); rc = MQTTAsync_disconnect(c, NULL);
assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc); assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
rc = MQTTAsync_disconnect(d, NULL); rc = MQTTAsync_disconnect(d, NULL);
assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc); assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
...@@ -1096,24 +1088,24 @@ exit: ...@@ -1096,24 +1088,24 @@ exit:
/********************************************************************* /*********************************************************************
test4: offline buffering - sending messages while disconnected test4: offline buffering - sending messages while disconnected
1. call connect 1. call connect
2. use proxy to disconnect the client 2. use proxy to disconnect the client
3. while the client is disconnected, send more messages 3. while the client is disconnected, send more messages
4. when the client auto reconnects, check that those messages are sent 4. when the client auto reconnects, check that those messages are sent
*********************************************************************/ *********************************************************************/
int test4_will_message_received = 0; int test4_will_message_received = 0;
int test4_messages_received = 0; int test4_messages_received = 0;
int test4_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message) int test4_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
{ {
MQTTAsync c = (MQTTAsync)context; MQTTAsync c = (MQTTAsync)context;
static int message_count = 0; static int message_count = 0;
MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\"", topicName, message->payloadlen, message->payload); MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\"", topicName, message->payloadlen, message->payload);
if (memcmp(message->payload, "will message", message->payloadlen) == 0) if (memcmp(message->payload, "will message", message->payloadlen) == 0)
test4_will_message_received = 1; test4_will_message_received = 1;
else else
...@@ -1151,10 +1143,10 @@ void test4cOnConnect(void* context, MQTTAsync_successData* response) ...@@ -1151,10 +1143,10 @@ void test4cOnConnect(void* context, MQTTAsync_successData* response)
MyLog(LOGA_DEBUG, "In connect onSuccess callback for client d, context %p\n", context); MyLog(LOGA_DEBUG, "In connect onSuccess callback for client d, context %p\n", context);
MQTTAsync c = (MQTTAsync)context; MQTTAsync c = (MQTTAsync)context;
int rc; int rc;
/* send a message to the proxy to break the connection */ /* send a message to the proxy to break the connection */
pubmsg.payload = "TERMINATE"; pubmsg.payload = "TERMINATE";
pubmsg.payloadlen = strlen(pubmsg.payload); pubmsg.payloadlen = (int)strlen(pubmsg.payload);
pubmsg.qos = 0; pubmsg.qos = 0;
pubmsg.retained = 0; pubmsg.retained = 0;
rc = MQTTAsync_sendMessage(c, "MQTTSAS topic", &pubmsg, NULL); rc = MQTTAsync_sendMessage(c, "MQTTSAS topic", &pubmsg, NULL);
...@@ -1218,7 +1210,7 @@ int test4(struct Options options) ...@@ -1218,7 +1210,7 @@ int test4(struct Options options)
int i = 0; int i = 0;
MQTTAsync_token *tokens; MQTTAsync_token *tokens;
char *URIs[2] = {"rubbish", options.proxy_connection}; char *URIs[2] = {"rubbish", options.proxy_connection};
sprintf(willTopic, "paho-test9-4-%s", unique); sprintf(willTopic, "paho-test9-4-%s", unique);
sprintf(clientidc, "paho-test9-4-c-%s", unique); sprintf(clientidc, "paho-test9-4-c-%s", unique);
sprintf(clientidd, "paho-test9-4-d-%s", unique); sprintf(clientidd, "paho-test9-4-d-%s", unique);
...@@ -1231,7 +1223,7 @@ int test4(struct Options options) ...@@ -1231,7 +1223,7 @@ int test4(struct Options options)
global_start_time = start_clock(); global_start_time = start_clock();
createOptions.sendWhileDisconnected = 1; createOptions.sendWhileDisconnected = 1;
rc = MQTTAsync_createWithOptions(&c, "not used", clientidc, MQTTCLIENT_PERSISTENCE_DEFAULT, rc = MQTTAsync_createWithOptions(&c, "not used", clientidc, MQTTCLIENT_PERSISTENCE_DEFAULT,
NULL, &createOptions); NULL, &createOptions);
assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc); assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
if (rc != MQTTASYNC_SUCCESS) if (rc != MQTTASYNC_SUCCESS)
...@@ -1239,7 +1231,7 @@ int test4(struct Options options) ...@@ -1239,7 +1231,7 @@ int test4(struct Options options)
MQTTAsync_destroy(&c); MQTTAsync_destroy(&c);
goto exit; goto exit;
} }
rc = MQTTAsync_create(&d, options.connection, clientidd, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL); rc = MQTTAsync_create(&d, options.connection, clientidd, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc); assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
if (rc != MQTTASYNC_SUCCESS) if (rc != MQTTASYNC_SUCCESS)
...@@ -1250,7 +1242,7 @@ int test4(struct Options options) ...@@ -1250,7 +1242,7 @@ int test4(struct Options options)
opts.keepAliveInterval = 20; opts.keepAliveInterval = 20;
opts.cleansession = 1; opts.cleansession = 1;
rc = MQTTAsync_setCallbacks(d, d, NULL, test4_messageArrived, NULL); rc = MQTTAsync_setCallbacks(d, d, NULL, test4_messageArrived, NULL);
assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc); assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
...@@ -1266,16 +1258,16 @@ int test4(struct Options options) ...@@ -1266,16 +1258,16 @@ int test4(struct Options options)
failures++; failures++;
goto exit; goto exit;
} }
/* wait until d is ready: connected and subscribed */ /* wait until d is ready: connected and subscribed */
count = 0; count = 0;
while (!test4dReady && ++count < 10000) while (!test4dReady && ++count < 10000)
MySleep(100); MySleep(100);
assert("Count should be less than 10000", count < 10000, "count was %d", count); /* wrong */ assert("Count should be less than 10000", count < 10000, "count was %d", count); /* wrong */
rc = MQTTAsync_setConnected(c, c, test4cConnected); rc = MQTTAsync_setConnected(c, c, test4cConnected);
assert("Good rc from setConnectedCallback", rc == MQTTASYNC_SUCCESS, "rc was %d", rc); assert("Good rc from setConnectedCallback", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
/* let client c go: connect, and send disconnect command to proxy */ /* let client c go: connect, and send disconnect command to proxy */
opts.will = &wopts; opts.will = &wopts;
opts.will->message = "will message"; opts.will->message = "will message";
...@@ -1298,24 +1290,24 @@ int test4(struct Options options) ...@@ -1298,24 +1290,24 @@ int test4(struct Options options)
failures++; failures++;
goto exit; goto exit;
} }
/* wait for will message */ /* wait for will message */
while (!test4_will_message_received && ++count < 10000) while (!test4_will_message_received && ++count < 10000)
MySleep(100); MySleep(100);
MyLog(LOGA_DEBUG, "Now we can send some messages to be buffered"); MyLog(LOGA_DEBUG, "Now we can send some messages to be buffered");
test4c_connected = 0; test4c_connected = 0;
/* send some messages. Then reconnect (check connected callback), and check that those messages are received */ /* send some messages. Then reconnect (check connected callback), and check that those messages are received */
for (i = 0; i < 3; ++i) for (i = 0; i < 3; ++i)
{ {
char buf[50]; char buf[50];
MQTTAsync_message pubmsg = MQTTAsync_message_initializer; MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
sprintf(buf, "QoS %d message", i); sprintf(buf, "QoS %d message", i);
pubmsg.payload = buf; pubmsg.payload = buf;
pubmsg.payloadlen = strlen(pubmsg.payload) + 1; pubmsg.payloadlen = (int)(strlen(pubmsg.payload) + 1);
pubmsg.qos = i; pubmsg.qos = i;
pubmsg.retained = 0; pubmsg.retained = 0;
rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts); rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts);
...@@ -1332,11 +1324,11 @@ int test4(struct Options options) ...@@ -1332,11 +1324,11 @@ int test4(struct Options options)
MQTTAsync_free(tokens); MQTTAsync_free(tokens);
} }
assert("Number of getPendingTokens should be 3", i == 3, "i was %d ", i); assert("Number of getPendingTokens should be 3", i == 3, "i was %d ", i);
/* wait for client to be reconnected */ /* wait for client to be reconnected */
while (!test4c_connected && ++count < 10000) while (!test4c_connected && ++count < 10000)
MySleep(100); MySleep(100);
/* wait for success or failure callback */ /* wait for success or failure callback */
while (test4_messages_received < 3 && ++count < 10000) while (test4_messages_received < 3 && ++count < 10000)
MySleep(100); MySleep(100);
...@@ -1351,10 +1343,10 @@ int test4(struct Options options) ...@@ -1351,10 +1343,10 @@ int test4(struct Options options)
MQTTAsync_free(tokens); MQTTAsync_free(tokens);
} }
assert("Number of getPendingTokens should be 0", i == 0, "i was %d ", i); assert("Number of getPendingTokens should be 0", i == 0, "i was %d ", i);
rc = MQTTAsync_disconnect(c, NULL); rc = MQTTAsync_disconnect(c, NULL);
assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc); assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
rc = MQTTAsync_disconnect(d, NULL); rc = MQTTAsync_disconnect(d, NULL);
assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc); assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
...@@ -1371,24 +1363,24 @@ exit: ...@@ -1371,24 +1363,24 @@ exit:
/********************************************************************* /*********************************************************************
test5: offline buffering - check max buffered test5: offline buffering - check max buffered
1. call connect 1. call connect
2. use proxy to disconnect the client 2. use proxy to disconnect the client
3. while the client is disconnected, send more messages 3. while the client is disconnected, send more messages
4. when the client reconnects, check that those messages are sent 4. when the client reconnects, check that those messages are sent
*********************************************************************/ *********************************************************************/
int test5_will_message_received = 0; int test5_will_message_received = 0;
int test5_messages_received = 0; int test5_messages_received = 0;
int test5_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message) int test5_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
{ {
MQTTAsync c = (MQTTAsync)context; MQTTAsync c = (MQTTAsync)context;
static int message_count = 0; static int message_count = 0;
MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\"", topicName, message->payloadlen, message->payload); MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\"", topicName, message->payloadlen, message->payload);
if (memcmp(message->payload, "will message", message->payloadlen) == 0) if (memcmp(message->payload, "will message", message->payloadlen) == 0)
test5_will_message_received = 1; test5_will_message_received = 1;
else else
...@@ -1426,10 +1418,10 @@ void test5cOnConnect(void* context, MQTTAsync_successData* response) ...@@ -1426,10 +1418,10 @@ void test5cOnConnect(void* context, MQTTAsync_successData* response)
MyLog(LOGA_DEBUG, "In connect onSuccess callback for client d, context %p\n", context); MyLog(LOGA_DEBUG, "In connect onSuccess callback for client d, context %p\n", context);
MQTTAsync c = (MQTTAsync)context; MQTTAsync c = (MQTTAsync)context;
int rc; int rc;
/* send a message to the proxy to break the connection */ /* send a message to the proxy to break the connection */
pubmsg.payload = "TERMINATE"; pubmsg.payload = "TERMINATE";
pubmsg.payloadlen = strlen(pubmsg.payload); pubmsg.payloadlen = (int)strlen(pubmsg.payload);
pubmsg.qos = 0; pubmsg.qos = 0;
pubmsg.retained = 0; pubmsg.retained = 0;
rc = MQTTAsync_sendMessage(c, "MQTTSAS topic", &pubmsg, NULL); rc = MQTTAsync_sendMessage(c, "MQTTSAS topic", &pubmsg, NULL);
...@@ -1492,7 +1484,7 @@ int test5(struct Options options) ...@@ -1492,7 +1484,7 @@ int test5(struct Options options)
char clientidd[50]; char clientidd[50];
int i = 0; int i = 0;
MQTTAsync_token *tokens; MQTTAsync_token *tokens;
sprintf(willTopic, "paho-test9-5-%s", unique); sprintf(willTopic, "paho-test9-5-%s", unique);
sprintf(clientidc, "paho-test9-5-c-%s", unique); sprintf(clientidc, "paho-test9-5-c-%s", unique);
sprintf(clientidd, "paho-test9-5-d-%s", unique); sprintf(clientidd, "paho-test9-5-d-%s", unique);
...@@ -1506,7 +1498,7 @@ int test5(struct Options options) ...@@ -1506,7 +1498,7 @@ int test5(struct Options options)
createOptions.sendWhileDisconnected = 1; createOptions.sendWhileDisconnected = 1;
createOptions.maxBufferedMessages = 3; createOptions.maxBufferedMessages = 3;
rc = MQTTAsync_createWithOptions(&c, options.proxy_connection, clientidc, MQTTCLIENT_PERSISTENCE_DEFAULT, rc = MQTTAsync_createWithOptions(&c, options.proxy_connection, clientidc, MQTTCLIENT_PERSISTENCE_DEFAULT,
NULL, &createOptions); NULL, &createOptions);
assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc); assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
if (rc != MQTTASYNC_SUCCESS) if (rc != MQTTASYNC_SUCCESS)
...@@ -1514,7 +1506,7 @@ int test5(struct Options options) ...@@ -1514,7 +1506,7 @@ int test5(struct Options options)
MQTTAsync_destroy(&c); MQTTAsync_destroy(&c);
goto exit; goto exit;
} }
rc = MQTTAsync_create(&d, options.connection, clientidd, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL); rc = MQTTAsync_create(&d, options.connection, clientidd, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc); assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
if (rc != MQTTASYNC_SUCCESS) if (rc != MQTTASYNC_SUCCESS)
...@@ -1527,7 +1519,7 @@ int test5(struct Options options) ...@@ -1527,7 +1519,7 @@ int test5(struct Options options)
opts.cleansession = 1; opts.cleansession = 1;
//opts.username = "testuser"; //opts.username = "testuser";
//opts.password = "testpassword"; //opts.password = "testpassword";
rc = MQTTAsync_setCallbacks(d, d, NULL, test5_messageArrived, NULL); rc = MQTTAsync_setCallbacks(d, d, NULL, test5_messageArrived, NULL);
assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc); assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
...@@ -1543,16 +1535,16 @@ int test5(struct Options options) ...@@ -1543,16 +1535,16 @@ int test5(struct Options options)
failures++; failures++;
goto exit; goto exit;
} }
/* wait until d is ready: connected and subscribed */ /* wait until d is ready: connected and subscribed */
count = 0; count = 0;
while (!test5dReady && ++count < 10000) while (!test5dReady && ++count < 10000)
MySleep(100); MySleep(100);
assert("Count should be less than 10000", count < 10000, "count was %d", count); /* wrong */ assert("Count should be less than 10000", count < 10000, "count was %d", count); /* wrong */
rc = MQTTAsync_setConnected(c, c, test5cConnected); rc = MQTTAsync_setConnected(c, c, test5cConnected);
assert("Good rc from setConnectedCallback", rc == MQTTASYNC_SUCCESS, "rc was %d", rc); assert("Good rc from setConnectedCallback", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
/* let client c go: connect, and send disconnect command to proxy */ /* let client c go: connect, and send disconnect command to proxy */
opts.will = &wopts; opts.will = &wopts;
opts.will->message = "will message"; opts.will->message = "will message";
...@@ -1572,24 +1564,24 @@ int test5(struct Options options) ...@@ -1572,24 +1564,24 @@ int test5(struct Options options)
failures++; failures++;
goto exit; goto exit;
} }
/* wait for will message */ /* wait for will message */
while (!test5_will_message_received && ++count < 10000) while (!test5_will_message_received && ++count < 10000)
MySleep(100); MySleep(100);
MyLog(LOGA_DEBUG, "Now we can send some messages to be buffered"); MyLog(LOGA_DEBUG, "Now we can send some messages to be buffered");
test5c_connected = 0; test5c_connected = 0;
/* send some messages. Then reconnect (check connected callback), and check that those messages are received */ /* send some messages. Then reconnect (check connected callback), and check that those messages are received */
for (i = 0; i < 5; ++i) for (i = 0; i < 5; ++i)
{ {
char buf[50]; char buf[50];
MQTTAsync_message pubmsg = MQTTAsync_message_initializer; MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
sprintf(buf, "QoS %d message", i); sprintf(buf, "QoS %d message", i);
pubmsg.payload = buf; pubmsg.payload = buf;
pubmsg.payloadlen = strlen(pubmsg.payload) + 1; pubmsg.payloadlen = (int)(strlen(pubmsg.payload) + 1);
pubmsg.qos = i % 3; pubmsg.qos = i % 3;
pubmsg.retained = 0; pubmsg.retained = 0;
rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts); rc = MQTTAsync_sendMessage(c, test_topic, &pubmsg, &opts);
...@@ -1609,14 +1601,14 @@ int test5(struct Options options) ...@@ -1609,14 +1601,14 @@ int test5(struct Options options)
MQTTAsync_free(tokens); MQTTAsync_free(tokens);
} }
assert("Number of getPendingTokens should be 3", i == 3, "i was %d ", i); assert("Number of getPendingTokens should be 3", i == 3, "i was %d ", i);
rc = MQTTAsync_reconnect(c); rc = MQTTAsync_reconnect(c);
assert("Good rc from reconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc); assert("Good rc from reconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
/* wait for client to be reconnected */ /* wait for client to be reconnected */
while (!test5c_connected && ++count < 10000) while (!test5c_connected && ++count < 10000)
MySleep(100); MySleep(100);
/* wait for success or failure callback */ /* wait for success or failure callback */
while (test5_messages_received < 3 && ++count < 10000) while (test5_messages_received < 3 && ++count < 10000)
MySleep(100); MySleep(100);
...@@ -1631,10 +1623,10 @@ int test5(struct Options options) ...@@ -1631,10 +1623,10 @@ int test5(struct Options options)
MQTTAsync_free(tokens); MQTTAsync_free(tokens);
} }
assert("Number of getPendingTokens should be 0", i == 0, "i was %d ", i); assert("Number of getPendingTokens should be 0", i == 0, "i was %d ", i);
rc = MQTTAsync_disconnect(c, NULL); rc = MQTTAsync_disconnect(c, NULL);
assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc); assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
rc = MQTTAsync_disconnect(d, NULL); rc = MQTTAsync_disconnect(d, NULL);
assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc); assert("Good rc from disconnect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
...@@ -1659,12 +1651,12 @@ int main(int argc, char** argv) ...@@ -1659,12 +1651,12 @@ int main(int argc, char** argv)
int* numtests = &tests; int* numtests = &tests;
int rc = 0; int rc = 0;
int (*tests[])() = { NULL, test1, test2, test3, test4, test5}; int (*tests[])() = { NULL, test1, test2, test3, test4, test5};
sprintf(unique, "%u", rand()); sprintf(unique, "%u", rand());
MyLog(LOGA_INFO, "Random prefix/suffix is %s", unique); MyLog(LOGA_INFO, "Random prefix/suffix is %s", unique);
xml = fopen("TEST-test9.xml", "w"); xml = fopen("TEST-test9.xml", "w");
fprintf(xml, "<testsuite name=\"test9\" tests=\"%lu\">\n", ARRAY_SIZE(tests) - 1); fprintf(xml, "<testsuite name=\"test9\" tests=\"%d\">\n", (int)(ARRAY_SIZE(tests) - 1));
MQTTAsync_setTraceCallback(handleTrace); MQTTAsync_setTraceCallback(handleTrace);
getopts(argc, argv); getopts(argc, argv);
...@@ -1695,4 +1687,3 @@ int main(int argc, char** argv) ...@@ -1695,4 +1687,3 @@ int main(int argc, char** argv)
return rc; return rc;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment