Commit b880d34f authored by Ian Craggs's avatar Ian Craggs

Windows CMake build additions and corrections

parent 526ffc18
......@@ -19,6 +19,7 @@
PROJECT("paho" C)
CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
MESSAGE(STATUS "CMake version: " ${CMAKE_VERSION})
MESSAGE(STATUS "CMake system name: " ${CMAKE_SYSTEM_NAME})
## build settings
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
@ONLY
)
IF (WIN32)
ADD_DEFINITIONS(/DCMAKE_BUILD /D_CRT_SECURE_NO_DEPRECATE)
ENDIF()
IF (PAHO_WITH_SSL)
SET(OPENSSL_LIB_SEARCH_PATH "" CACHE PATH "Directory containing OpenSSL libraries")
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)
IF (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
SET_PROPERTY(TARGET common_obj PROPERTY
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)
......@@ -165,9 +174,11 @@ IF (PAHO_WITH_SSL)
SET_PROPERTY(TARGET common_ssl_obj PROPERTY POSITION_INDEPENDENT_CODE ON)
IF (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
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")
ENDIF (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
ENDIF ()
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)
......
......@@ -3,11 +3,11 @@
*
* All rights reserved. This program and the accompanying materials
* 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
* 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.
*
* Contributors:
......@@ -106,7 +106,7 @@ int Socket_error(char* aString, int sock)
if (errno != EINTR && errno != EAGAIN && errno != EINPROGRESS && errno != EWOULDBLOCK)
{
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);
return errno;
......@@ -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
* 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
*/
void Socket_addPendingWrite(int socket)
......@@ -719,13 +719,13 @@ int Socket_continueWrite(int socket)
FUNC_ENTRY;
pw = SocketBuffer_getWrite(socket);
#if defined(OPENSSL)
if (pw->ssl)
{
rc = SSLSocket_continueWrite(pw);
goto exit;
}
}
#endif
for (i = 0; i < pw->count; ++i)
......@@ -757,7 +757,7 @@ int Socket_continueWrite(int socket)
if (pw->frees[i])
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
Log(TRACE_MIN, -1, "ContinueWrite wrote +%lu bytes on socket %d", bytes, socket);
......@@ -795,7 +795,7 @@ int Socket_continueWrites(fd_set* pwset)
ListNextElement(s.write_pending, &curpending);
}
curpending = s.write_pending->current;
if (writecomplete)
(*writecomplete)(socket);
}
......@@ -828,7 +828,7 @@ char* Socket_getaddrname(struct sockaddr* sa, int sock)
#if defined(WIN32) || defined(WIN64)
int buflen = 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);
else
wcstombs(addr_string, buf, sizeof(addr_string));
......@@ -874,4 +874,3 @@ int main(int argc, char *argv[])
}
#endif
......@@ -3,11 +3,11 @@
*
* All rights reserved. This program and the accompanying materials
* 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
* 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.
*
* Contributors:
......@@ -25,12 +25,19 @@
#include <ws2tcpip.h>
#define MAXHOSTNAMELEN 256
#if !defined(SSLSOCKET_H)
#undef EAGAIN
#define EAGAIN WSAEWOULDBLOCK
#undef EINTR
#define EINTR WSAEINTR
#undef EINPROGRESS
#define EINPROGRESS WSAEINPROGRESS
#undef EWOULDBLOCK
#define EWOULDBLOCK WSAEWOULDBLOCK
#undef ENOTCONN
#define ENOTCONN WSAENOTCONN
#undef ECONNRESET
#define ECONNRESET WSAECONNRESET
#undef ETIMEDOUT
#define ETIMEDOUT WAIT_TIMEOUT
#endif
#define ioctl ioctlsocket
......
......@@ -90,6 +90,8 @@ mutex_type Thread_create_mutex(void)
FUNC_ENTRY;
#if defined(WIN32) || defined(WIN64)
mutex = CreateMutex(NULL, 0, NULL);
if (mutex == NULL)
rc = GetLastError();
#else
mutex = malloc(sizeof(pthread_mutex_t));
rc = pthread_mutex_init(mutex, NULL);
......@@ -100,8 +102,7 @@ mutex_type Thread_create_mutex(void)
/**
* Lock a mutex which has already been created, block until ready
* @param mutex the mutex
* Lock a mutex which has alrea
* @return completion code, 0 is success
*/
int Thread_lock_mutex(mutex_type mutex)
......
......@@ -24,6 +24,10 @@ INCLUDE_DIRECTORIES(
${CMAKE_BINARY_DIR}
)
IF (WIN32)
ADD_DEFINITIONS(/DCMAKE_BUILD /D_CRT_SECURE_NO_DEPRECATE)
ENDIF()
# sample files c
ADD_EXECUTABLE(paho_c_pub paho_c_pub.c)
ADD_EXECUTABLE(paho_c_sub paho_c_sub.c)
......
......@@ -3,11 +3,11 @@
*
* All rights reserved. This program and the accompanying materials
* 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
* 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.
*
* Contributors:
......@@ -81,7 +81,7 @@ int main(int argc, char* argv[])
exit(EXIT_FAILURE);
}
pubmsg.payload = PAYLOAD;
pubmsg.payloadlen = strlen(PAYLOAD);
pubmsg.payloadlen = (int)strlen(PAYLOAD);
pubmsg.qos = QOS;
pubmsg.retained = 0;
deliveredtoken = 0;
......@@ -94,4 +94,3 @@ int main(int argc, char* argv[])
MQTTClient_destroy(&client);
return rc;
}
......@@ -3,27 +3,27 @@
*
* All rights reserved. This program and the accompanying materials
* 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
* 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.
*
* Contributors:
* Ian Craggs - initial contribution
* Guilherme Maciel Ferreira - add keep alive option
*******************************************************************************/
/*
stdin publisher
compulsory parameters:
--topic topic to publish on
defaulted parameters:
--host localhost
--port 1883
--qos 0
......@@ -31,10 +31,10 @@
--clientid stdin-publisher-async
--maxdatalen 100
--keepalive 10
--userid none
--password none
*/
#include "MQTTAsync.h"
......@@ -125,7 +125,7 @@ void myconnect(MQTTAsync* client);
void onConnectFailure(void* context, MQTTAsync_failureData* response)
{
printf("Connect failed, rc %d\n", response ? response->code : -1);
connected = -1;
connected = -1;
MQTTAsync client = (MQTTAsync)context;
myconnect(client);
......@@ -135,8 +135,7 @@ void onConnectFailure(void* context, MQTTAsync_failureData* response)
void onConnect(void* context, MQTTAsync_successData* response)
{
MQTTAsync client = (MQTTAsync)context;
int rc;
printf("Connected\n");
connected = 1;
}
......@@ -172,7 +171,7 @@ static int published = 0;
void onPublishFailure(void* context, MQTTAsync_failureData* response)
{
printf("Publish failed, rc %d\n", response ? -1 : response->code);
published = -1;
published = -1;
}
......@@ -223,13 +222,13 @@ int main(int argc, char** argv)
if (argc < 2)
usage();
getopts(argc, argv);
sprintf(url, "%s:%s", opts.host, opts.port);
if (opts.verbose)
printf("URL is %s\n", url);
topic = argv[1];
printf("Using topic %s\n", topic);
......@@ -244,13 +243,13 @@ int main(int argc, char** argv)
myconnect(&client);
buffer = malloc(opts.maxdatalen);
while (!toStop)
{
int data_len = 0;
int delim_len = 0;
delim_len = strlen(opts.delimiter);
delim_len = (int)strlen(opts.delimiter);
do
{
buffer[data_len++] = getchar();
......@@ -261,7 +260,7 @@ int main(int argc, char** argv)
break;
}
} while (data_len < opts.maxdatalen);
if (opts.verbose)
printf("Publishing data of length %d\n", data_len);
pub_opts.onSuccess = onPublish;
......@@ -272,9 +271,9 @@ int main(int argc, char** argv)
}
while (rc != MQTTASYNC_SUCCESS);
}
printf("Stopping\n");
free(buffer);
disc_opts.onSuccess = onDisconnect;
......@@ -299,7 +298,7 @@ int main(int argc, char** argv)
void getopts(int argc, char** argv)
{
int count = 2;
while (count < argc)
{
if (strcmp(argv[count], "--retained") == 0)
......@@ -380,6 +379,5 @@ void getopts(int argc, char** argv)
}
count++;
}
}
}
......@@ -3,36 +3,36 @@
*
* All rights reserved. This program and the accompanying materials
* 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
* 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.
*
* Contributors:
* Ian Craggs - initial contribution
*******************************************************************************/
/*
stdin publisher
compulsory parameters:
--topic topic to publish on
defaulted parameters:
--host localhost
--port 1883
--qos 0
--delimiters \n
--clientid stdin_publisher
--maxdatalen 100
--userid none
--password none
*/
#include "MQTTClient.h"
......@@ -128,13 +128,13 @@ int main(int argc, char** argv)
if (argc < 2)
usage();
getopts(argc, argv);
sprintf(url, "%s:%s", opts.host, opts.port);
if (opts.verbose)
printf("URL is %s\n", url);
topic = argv[1];
printf("Using topic %s\n", topic);
......@@ -152,17 +152,17 @@ int main(int argc, char** argv)
conn_opts.password = opts.password;
ssl_opts.enableServerCertAuth = 0;
conn_opts.ssl = &ssl_opts;
myconnect(&client, &conn_opts);
buffer = malloc(opts.maxdatalen);
while (!toStop)
{
int data_len = 0;
int delim_len = 0;
delim_len = strlen(opts.delimiter);
delim_len = (int)strlen(opts.delimiter);
do
{
buffer[data_len++] = getchar();
......@@ -173,7 +173,7 @@ int main(int argc, char** argv)
break;
}
} while (data_len < opts.maxdatalen);
if (opts.verbose)
printf("Publishing data of length %d\n", data_len);
rc = MQTTClient_publish(client, topic, data_len, buffer, opts.qos, opts.retained, NULL);
......@@ -185,9 +185,9 @@ int main(int argc, char** argv)
if (opts.qos > 0)
MQTTClient_yield();
}
printf("Stopping\n");
free(buffer);
MQTTClient_disconnect(client, 0);
......@@ -200,7 +200,7 @@ int main(int argc, char** argv)
void getopts(int argc, char** argv)
{
int count = 2;
while (count < argc)
{
if (strcmp(argv[count], "--retained") == 0)
......@@ -274,6 +274,5 @@ void getopts(int argc, char** argv)
}
count++;
}
}
}
......@@ -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 )
IF (WIN32)
ADD_DEFINITIONS(/DCMAKE_BUILD)
ADD_DEFINITIONS(/DCMAKE_BUILD /D_CRT_SECURE_NO_WARNINGS)
ENDIF()
......@@ -22,7 +22,7 @@ TARGET_LINK_LIBRARIES(
IF (WIN32)
ADD_CUSTOM_COMMAND(
TARGET test1 PRE_BUILD
TARGET test1 PRE_BUILD
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/dll-copy.cmake
COMMENT "Copying DLLs to test directory"
)
......@@ -313,5 +313,3 @@ ADD_TEST(
NAME test9-5-offline-buffering-max-buffered
COMMAND test9 "--test_no" "5" "--connection" ${MQTT_TEST_BROKER} "--proxy_connection" ${MQTT_TEST_PROXY}
)
......@@ -3,11 +3,11 @@
*
* All rights reserved. This program and the accompanying materials
* 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
* 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.
*
* Contributors:
......@@ -34,21 +34,13 @@
#include <stdlib.h>
#if !defined(_WINDOWS)
#include <sys/time.h>
#include <sys/socket.h>
#include <unistd.h>
#include <errno.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <unistd.h>
#include <errno.h>
#else
#include <winsock2.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
#define setenv(a, b, c) _putenv_s(a, b)
#include <windows.h>
#define setenv(a, b, c) _putenv_s(a, b)
#endif
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
......@@ -84,7 +76,7 @@ struct Options
void getopts(int argc, char** argv)
{
int count = 1;
while (count < argc)
{
if (strcmp(argv[count], "--test_no") == 0)
......@@ -171,7 +163,7 @@ void MyLog(int LOGA_level, char* format, ...)
if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
return;
ftime(&ts);
timeinfo = localtime(&ts.time);
strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo);
......@@ -259,11 +251,11 @@ void write_test_result(void)
{
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)
{
fprintf(xml, "%s", output);
cur_output = output;
cur_output = output;
}
fprintf(xml, "</testcase>\n");
}
......@@ -283,11 +275,11 @@ void myassert(char* filename, int lineno, char* description, int value, char* fo
vprintf(format, 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);
}
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)
global_start_time = start_clock();
failures = 0;
MyLog(LOGA_INFO, "Starting test 1 - single threaded client using receive");
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);
if (rc != MQTTCLIENT_SUCCESS)
{
......@@ -485,7 +477,7 @@ void test2_sendAndReceive(MQTTClient* c, int qos, char* test_topic)
for (i = 1; i <= iterations; ++i)
{
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);
else
rc = MQTTClient_publishMessage(c, test_topic, &test2_pubmsg, &dt);
......@@ -507,7 +499,7 @@ void test2_sendAndReceive(MQTTClient* c, int qos, char* test_topic)
usleep(1000000L);
#endif
}
assert("Message Arrived", wait_seconds > 0,
assert("Message Arrived", wait_seconds > 0,
"Time out waiting for message %d\n", i );
}
if (qos > 0)
......@@ -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
completed the QoS 2 handshake with the publisher. For QoS 1 and 2,
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;
while ((test2_deliveryCompleted < iterations) && (wait_seconds-- > 0))
{
......@@ -526,8 +518,8 @@ void test2_sendAndReceive(MQTTClient* c, int qos, char* test_topic)
usleep(1000000L);
#endif
}
assert("All Deliveries Complete", wait_seconds > 0,
"Number of deliveryCompleted callbacks was %d\n",
assert("All Deliveries Complete", wait_seconds > 0,
"Number of deliveryCompleted callbacks was %d\n",
test2_deliveryCompleted);
}
}
......@@ -645,7 +637,7 @@ int test3(struct Options options)
/* authorization failure (RC = 5) */
opts.username = "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->qos = 1;
opts.will->retained = 0;
......@@ -694,7 +686,7 @@ int test4_run(int qos)
int count = 3;
int i, rc;
failures = 0;
failures = 0;
MyLog(LOGA_INFO, "Starting test 4 - persistence, qos %d", qos);
MQTTClient_create(&c, options.connection, "xrctest1_test_4", MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
......@@ -724,7 +716,7 @@ int test4_run(int qos)
assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
return -1;
}
/* subscribe so we can get messages back */
rc = MQTTClient_subscribe(c, topic, subsqos);
assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
......@@ -804,7 +796,7 @@ int test4_run(int qos)
MQTTClient_free(topicName);
}
}
MQTTClient_yield(); /* allow any unfinished protocol exchanges to finish */
rc = MQTTClient_getPendingDeliveryTokens(c, &tokens);
......@@ -829,11 +821,11 @@ int test4(struct Options options)
fprintf(xml, "<testcase classname=\"test1\" name=\"persistence\"");
global_start_time = start_clock();
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)
{
fprintf(xml, "%s", output);
cur_output = output;
cur_output = output;
}
fprintf(xml, "</testcase>\n");
return rc;
......@@ -954,13 +946,13 @@ int test6(struct Options options)
MQTTClient_willOptions wopts = MQTTClient_willOptions_initializer;
MQTTClient_connectOptions opts2 = MQTTClient_connectOptions_initializer;
int rc, count;
char* mqttsas_topic = "MQTTSAS topic";
char* mqttsas_topic = "MQTTSAS topic";
failures = 0;
MyLog(LOGA_INFO, "Starting test 6 - connectionLost and will messages");
fprintf(xml, "<testcase classname=\"test1\" name=\"connectionLost and will messages\"");
global_start_time = start_clock();
opts.keepAliveInterval = 2;
opts.cleansession = 1;
opts.MQTTVersion = options.MQTTVersion;
......@@ -1011,7 +1003,7 @@ int test6(struct Options options)
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 */
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);
MyLog(LOGA_INFO, "Waiting to receive the will message");
......@@ -1030,17 +1022,17 @@ int test6(struct Options options)
"will_message_arrived was %d\n", test6_will_message_arrived);
assert("connection lost called", test6_connection_lost_called == 1,
"connection_lost_called %d\n", test6_connection_lost_called);
rc = MQTTClient_unsubscribe(test6_c2, test6_will_topic);
assert("Good rc from unsubscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
rc = MQTTClient_isConnected(test6_c2);
assert("Client-2 still connected", rc == 1, "isconnected is %d", rc);
rc = MQTTClient_isConnected(test6_c1);
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);
MQTTClient_destroy(&test6_c1);
......@@ -1058,7 +1050,7 @@ int main(int argc, char** argv)
int rc = 0;
int (*tests[])() = {NULL, test1, test2, test3, test4, test5, test6};
int i;
xml = fopen("TEST-test1.xml", "w");
fprintf(xml, "<testsuite name=\"test1\" tests=\"%d\">\n", (int)(ARRAY_SIZE(tests) - 1));
......@@ -1077,13 +1069,13 @@ int main(int argc, char** argv)
else
rc = tests[options.test_no](options); /* run just the selected test */
}
if (rc == 0)
MyLog(LOGA_INFO, "verdict pass");
else
MyLog(LOGA_INFO, "verdict fail");
fprintf(xml, "</testsuite>\n");
fclose(xml);
fclose(xml);
return rc;
}
......@@ -3,11 +3,11 @@
*
* All rights reserved. This program and the accompanying materials
* 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
* 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.
*
* Contributors:
......@@ -27,29 +27,13 @@
#if !defined(_WINDOWS)
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/socket.h>
#include <unistd.h>
#include <errno.h>
#include <errno.h>
#define WINAPI
#else
#define WIN32_LEAN_AND_MEAN
#if !defined(CMAKE_BUILD)
/*
* 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)
#include <windows.h>
#define setenv(a, b, c) _putenv_s(a, b)
#endif
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
......@@ -83,7 +67,7 @@ struct Options
void getopts(int argc, char** argv)
{
int count = 1;
while (count < argc)
{
if (strcmp(argv[count], "--test_no") == 0)
......@@ -163,7 +147,7 @@ void MyLog(int LOGA_level, char* format, ...)
if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
return;
ftime(&ts);
timeinfo = localtime(&ts.time);
strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo);
......@@ -251,11 +235,11 @@ void write_test_result(void)
{
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)
{
fprintf(xml, "%s", output);
cur_output = output;
cur_output = output;
}
fprintf(xml, "</testcase>\n");
}
......@@ -275,11 +259,11 @@ void myassert(char* filename, int lineno, char* description, int value, char* fo
vprintf(format, 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);
}
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
};
static int iterations = 50;
thread_return_type WINAPI test1_sendAndReceive(void* n)
{
MQTTClient_deliveryToken dt;
......@@ -403,7 +387,7 @@ thread_return_type WINAPI test1_sendAndReceive(void* n)
assert("Message Arrived", wait_seconds > 0,
"Timed out waiting for message %d\n", i);
}
#if defined(_WINDOWS)
return 0;
#else
......@@ -424,7 +408,7 @@ int test1(struct Options options)
global_start_time = start_clock();
failures = 0;
MyLog(LOGA_INFO, "Starting test 1 - multiple threads using same client object");
rc = MQTTClient_create(&c, options.connection, "single_object, multiple threads",
MQTTCLIENT_PERSISTENCE_NONE, NULL);
assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);
......@@ -478,7 +462,7 @@ int test1(struct Options options)
completed the QoS 2 handshake with the publisher. For QoS 1 and 2,
allow time for the final delivery complete callback before checking
that all expected callbacks have been made */
int wait_seconds = 90;
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)
for (i = 1; i <= iterations; ++i)
{
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);
else
rc = MQTTClient_publishMessage(c, test_topic, &test2_pubmsg, &dt);
......@@ -592,7 +576,7 @@ void test2_sendAndReceive(MQTTClient* c, int qos, char* test_topic)
usleep(1000000L);
#endif
}
assert("Message Arrived", wait_seconds > 0,
assert("Message Arrived", wait_seconds > 0,
"Time out waiting for message %d\n", i );
}
if (qos > 0)
......@@ -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
completed the QoS 2 handshake with the publisher. For QoS 1 and 2,
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;
while ((test2_deliveryCompleted < iterations) && (wait_seconds-- > 0))
{
......@@ -611,8 +595,8 @@ void test2_sendAndReceive(MQTTClient* c, int qos, char* test_topic)
usleep(1000000L);
#endif
}
assert("All Deliveries Complete", test2_deliveryCompleted == iterations,
"Number of deliveryCompleted callbacks was %d\n",
assert("All Deliveries Complete", test2_deliveryCompleted == iterations,
"Number of deliveryCompleted callbacks was %d\n",
test2_deliveryCompleted);
}
}
......@@ -686,7 +670,7 @@ int main(int argc, char** argv)
#if defined(WIN32) || defined(WIN64)
deliveryCompleted_mutex = CreateMutex(NULL, 0, NULL);
#endif
xml = fopen("TEST-test2.xml", "w");
fprintf(xml, "<testsuite name=\"test1\" tests=\"%d\">\n", (int)(ARRAY_SIZE(tests) - 1));
......@@ -705,13 +689,13 @@ int main(int argc, char** argv)
else
rc = tests[options.test_no](options); /* run just the selected test */
}
if (rc == 0)
MyLog(LOGA_INFO, "verdict pass");
else
MyLog(LOGA_INFO, "verdict fail");
fprintf(xml, "</testsuite>\n");
fclose(xml);
fclose(xml);
return rc;
}
This diff is collapsed.
This diff is collapsed.
......@@ -3,11 +3,11 @@
*
* All rights reserved. This program and the accompanying materials
* 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
* 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.
*
* Contributors:
......@@ -37,15 +37,8 @@
#include <unistd.h>
#include <errno.h>
#else
#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>
#define MAXHOSTNAMELEN 256
#define EAGAIN WSAEWOULDBLOCK
#define EINTR WSAEINTR
#define EINPROGRESS WSAEINPROGRESS
#define EWOULDBLOCK WSAEWOULDBLOCK
#define ENOTCONN WSAENOTCONN
#define ECONNRESET WSAECONNRESET
#define snprintf _snprintf
#endif
......@@ -79,7 +72,7 @@ struct Options
int test_no;
int size;
} options =
{
{
"ssl://m2m.eclipse.org:18883",
"ssl://m2m.eclipse.org:18884",
"ssl://m2m.eclipse.org:18887",
......@@ -282,11 +275,11 @@ void write_test_result(void)
{
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)
{
fprintf(xml, "%s", output);
cur_output = output;
cur_output = output;
}
fprintf(xml, "</testcase>\n");
}
......@@ -307,7 +300,7 @@ void myassert(char* filename, int lineno, char* description, int value,
vprintf(format, 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);
}
else
......@@ -932,7 +925,7 @@ int test2c(struct Options options)
fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname);
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);
assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
if (rc != MQTTASYNC_SUCCESS)
......@@ -2071,4 +2064,3 @@ int main(int argc, char** argv)
return rc;
}
......@@ -35,7 +35,7 @@
#include <unistd.h>
#include <signal.h>
#else
#include <winsock2.h>
#include <windows.h>
#endif
void usage(void)
......@@ -332,7 +332,7 @@ int control_send(char* message)
MQTTAsync_responseOptions ropts = MQTTAsync_responseOptions_initializer;
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);
MyLog(LOGA_DEBUG, "Control message sent: %s", buf);
......@@ -636,7 +636,7 @@ void one_iteration(void)
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);
while (rc != MQTTASYNC_SUCCESS)
{
......@@ -645,7 +645,7 @@ void one_iteration(void)
if (stopping)
goto exit;
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);
}
}
......@@ -687,7 +687,7 @@ void one_iteration(void)
ropts.onSuccess = messageSent;
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);
while (rc != MQTTASYNC_SUCCESS)
{
......@@ -697,7 +697,7 @@ void one_iteration(void)
if (stopping)
goto exit;
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);
}
//MyLog(LOGA_DEBUG, "Successful publish with payload %s", payload);
......
......@@ -29,19 +29,11 @@
#if !defined(_WINDOWS)
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/socket.h>
#include <unistd.h>
#include <errno.h>
#include <errno.h>
#else
#include <winsock2.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
#include <windows.h>
#endif
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
......@@ -69,7 +61,7 @@ struct Options
void getopts(int argc, char** argv)
{
int count = 1;
while (count < argc)
{
if (strcmp(argv[count], "--test_no") == 0)
......@@ -118,7 +110,7 @@ void MyLog(int LOGA_level, char* format, ...)
if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
return;
ftime(&ts);
timeinfo = localtime(&ts.time);
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
va_end(args);
}
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;
......@@ -239,7 +231,7 @@ void test1_onUnsubscribe(void* context, MQTTAsync_successData* response)
MQTTAsync c = (MQTTAsync)context;
MQTTAsync_disconnectOptions opts = MQTTAsync_disconnectOptions_initializer;
int rc;
MyLog(LOGA_DEBUG, "In onUnsubscribe onSuccess callback %p", c);
opts.onSuccess = test1_onDisconnect;
opts.context = c;
......@@ -288,7 +280,7 @@ void test1_onSubscribe(void* context, MQTTAsync_successData* response)
MQTTAsync c = (MQTTAsync)context;
MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
int rc;
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";
......@@ -305,7 +297,7 @@ void test1_onConnect(void* context, MQTTAsync_successData* response)
MQTTAsync c = (MQTTAsync)context;
MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
int rc;
MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
opts.onSuccess = test1_onSubscribe;
opts.context = c;
......@@ -321,8 +313,7 @@ void test1_onConnectFailure(void* context, MQTTAsync_failureData* response)
{
MQTTAsync c = (MQTTAsync)context;
MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
int rc;
MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context);
test_finished = 1;
......@@ -346,9 +337,9 @@ int test1(struct Options options)
failures = 0;
MyLog(LOGA_INFO, "Starting test 1 - asynchronous connect");
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);
if (rc != MQTTASYNC_SUCCESS)
{
......@@ -388,7 +379,7 @@ int test1(struct Options options)
Sleep(100);
#else
usleep(10000L);
#endif
#endif
MQTTAsync_destroy(&c);
......@@ -437,9 +428,9 @@ int test2(struct Options options)
test_finished = 0;
MyLog(LOGA_INFO, "Starting test 2 - 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);
if (rc != MQTTASYNC_SUCCESS)
{
......@@ -478,12 +469,12 @@ int test2(struct Options options)
Sleep(100);
#else
usleep(10000L);
#endif
#endif
MQTTAsync_destroy(&c);
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);
MyLog(LOGA_INFO, "TEST2: test %s. %d tests run, %d failures.",
......@@ -523,7 +514,7 @@ void test3_onUnsubscribe(void* context, MQTTAsync_successData* response)
client_data* cd = (client_data*)context;
MQTTAsync_disconnectOptions opts = MQTTAsync_disconnectOptions_initializer;
int rc;
MyLog(LOGA_DEBUG, "In onUnsubscribe onSuccess callback \"%s\"", cd->clientid);
opts.onSuccess = test3_onDisconnect;
opts.context = cd;
......@@ -584,7 +575,7 @@ void test3_onSubscribe(void* context, MQTTAsync_successData* response)
client_data* cd = (client_data*)context;
MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
int rc;
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";
......@@ -602,7 +593,7 @@ void test3_onConnect(void* context, MQTTAsync_successData* response)
client_data* cd = (client_data*)context;
MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
int rc;
MyLog(LOGA_DEBUG, "In connect onSuccess callback, \"%s\"", cd->clientid);
opts.onSuccess = test3_onSubscribe;
opts.context = cd;
......@@ -618,7 +609,7 @@ void test3_onFailure(void* context, MQTTAsync_failureData* response)
{
client_data* cd = (client_data*)context;
MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
assert("Should have connected", 0, "failed to connect", NULL);
MyLog(LOGA_DEBUG, "In connect onFailure callback, \"%s\" rc %d\n", cd->clientid, response->code);
if (response->message)
......@@ -646,7 +637,7 @@ int test3(struct Options options)
test_finished = 0;
MyLog(LOGA_INFO, "Starting test 3 - multiple connections");
for (i = 0; i < num_clients; ++i)
{
sprintf(clientdata[i].clientid, "async_test3_num_%d", i);
......@@ -655,9 +646,9 @@ int test3(struct Options options)
clientdata[i].message_count = 0;
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);
rc = MQTTAsync_setCallbacks(clientdata[i].c, &clientdata[i], NULL, test3_messageArrived, NULL);
assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
......@@ -687,7 +678,7 @@ int test3(struct Options options)
Sleep(100);
#else
usleep(10000L);
#endif
#endif
}
MyLog(LOGA_DEBUG, "TEST3: destroying clients");
......@@ -695,7 +686,7 @@ int test3(struct Options options)
for (i = 0; i < num_clients; ++i)
MQTTAsync_destroy(&clientdata[i].c);
exit:
/*exit:*/
MyLog(LOGA_INFO, "TEST3: test %s. %d tests run, %d failures.",
(failures == 0) ? "passed" : "failed", tests, failures);
......@@ -709,7 +700,7 @@ int test4_payloadlen = 0;
void test4_onPublish(void* context, MQTTAsync_successData* response)
{
MQTTAsync c = (MQTTAsync)context;
MyLog(LOGA_DEBUG, "In publish onSuccess callback, context %p", context);
}
......@@ -783,7 +774,7 @@ void test4_onSubscribe(void* context, MQTTAsync_successData* response)
MQTTAsync c = (MQTTAsync)context;
MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
int rc, i;
MyLog(LOGA_DEBUG, "In subscribe onSuccess callback %p", c);
pubmsg.payload = test4_payload = malloc(options.size);
......@@ -792,7 +783,7 @@ void test4_onSubscribe(void* context, MQTTAsync_successData* response)
srand(33);
for (i = 0; i < options.size; ++i)
((char*)pubmsg.payload)[i] = rand() % 256;
pubmsg.qos = 2;
pubmsg.retained = 0;
......@@ -805,7 +796,7 @@ void test4_onConnect(void* context, MQTTAsync_successData* response)
MQTTAsync c = (MQTTAsync)context;
MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
int rc;
MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
opts.onSuccess = test4_onSubscribe;
opts.context = c;
......@@ -833,9 +824,9 @@ int test4(struct Options options)
test_finished = failures = 0;
MyLog(LOGA_INFO, "Starting test 4 - big messages");
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);
if (rc != MQTTASYNC_SUCCESS)
{
......@@ -873,7 +864,7 @@ int test4(struct Options options)
Sleep(100);
#else
usleep(1000L);
#endif
#endif
MQTTAsync_destroy(&c);
......@@ -897,18 +888,18 @@ int main(int argc, char** argv)
int rc = 0;
int (*tests[])() = {NULL, test1, test2, test3, test4}; /* indexed starting from 1 */
MQTTAsync_nameValue* info;
getopts(argc, argv);
MQTTAsync_setTraceCallback(trace_callback);
info = MQTTAsync_getVersionInfo();
while (info->name)
{
MyLog(LOGA_INFO, "%s: %s", info->name, info->value);
info++;
}
}
if (options.test_no == -1)
{ /* run all the tests */
......@@ -916,7 +907,7 @@ int main(int argc, char** argv)
{
failures = 0;
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
......@@ -929,6 +920,6 @@ int main(int argc, char** argv)
MyLog(LOGA_INFO, "verdict pass");
else
MyLog(LOGA_INFO, "verdict fail");
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