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;
} }
This diff is collapsed.
This diff is collapsed.
...@@ -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;
} }
This diff is collapsed.
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