Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
paho.mqtt.c
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
eclipse
paho.mqtt.c
Commits
3c3ffbed
Commit
3c3ffbed
authored
Mar 17, 2017
by
Ian Craggs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change test1 will message test back to using proxy for disconnect
parent
77fac9d3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
100 deletions
+21
-100
CMakeLists.txt
test/CMakeLists.txt
+1
-1
test1.c
test/test1.c
+20
-99
No files found.
test/CMakeLists.txt
View file @
3c3ffbed
...
...
@@ -17,7 +17,7 @@ TARGET_LINK_LIBRARIES(
ADD_TEST
(
NAME test1
COMMAND
"test1"
"--connection"
${
MQTT_TEST_BROKER
}
COMMAND
"test1"
"--connection"
${
MQTT_TEST_BROKER
}
"--proxy_connection"
${
MQTT_TEST_PROXY
}
)
ADD_EXECUTABLE
(
...
...
test/test1.c
View file @
3c3ffbed
/*******************************************************************************
* Copyright (c) 2009, 201
5
IBM Corp.
* Copyright (c) 2009, 201
7
IBM Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
...
...
@@ -13,6 +13,7 @@
* Contributors:
* Ian Craggs - initial API and implementation and/or initial documentation
* Ian Craggs - MQTT 3.1.1 support
* Ian Craggs - change will message test back to using proxy
*******************************************************************************/
...
...
@@ -62,6 +63,7 @@ struct Options
{
char
*
connection
;
/**< connection to system under test. */
char
**
haconnections
;
char
*
proxy_connection
;
int
hacount
;
int
verbose
;
int
test_no
;
...
...
@@ -69,8 +71,9 @@ struct Options
int
iterations
;
}
options
=
{
"tcp://
m2m
.eclipse.org:1883"
,
"tcp://
iot
.eclipse.org:1883"
,
NULL
,
"tcp://localhost:1883"
,
0
,
0
,
0
,
...
...
@@ -119,6 +122,13 @@ void getopts(int argc, char** argv)
else
usage
();
}
else
if
(
strcmp
(
argv
[
count
],
"--proxy_connection"
)
==
0
)
{
if
(
++
count
<
argc
)
options
.
proxy_connection
=
argv
[
count
];
else
usage
();
}
else
if
(
strcmp
(
argv
[
count
],
"--MQTTversion"
)
==
0
)
{
if
(
++
count
<
argc
)
...
...
@@ -276,8 +286,8 @@ void myassert(char* filename, int lineno, char* description, int value, char* fo
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
);
else
MyLog
(
LOGA_DEBUG
,
"Assertion succeeded, file %s, line %d, description: %s"
,
filename
,
lineno
,
description
);
}
...
...
@@ -838,16 +848,11 @@ Test 5: disconnect with quiesce timeout should allow exchanges to complete
int
test5
(
struct
Options
options
)
{
char
*
testname
=
"test 5"
;
/* TODO - unused -remove? char summaryname[50]; */
/* TODO - unused -remove? FILE *outfile = NULL; */
char
*
topic
=
"Persistence test 2"
;
int
subsqos
=
2
;
MQTTClient
c
;
MQTTClient_connectOptions
opts
=
MQTTClient_connectOptions_initializer
;
/* TODO - unused -remove? MQTTClient_message* m = NULL; */
/* TODO - unused -remove? char* topicName = NULL; */
MQTTClient_deliveryToken
*
tokens
=
NULL
;
/* TODO - unused -remove? int mytoken = -99; */
char
buffer
[
100
];
int
count
=
5
;
int
i
,
rc
;
...
...
@@ -942,89 +947,6 @@ int test6_messageArrived(void* context, char* topicName, int topicLen, MQTTClien
}
int
test6_socket_error
(
char
*
aString
,
int
sock
)
{
#if defined(WIN32)
int
errno
;
#endif
#if defined(WIN32)
errno
=
WSAGetLastError
();
#endif
if
(
errno
!=
EINTR
&&
errno
!=
EAGAIN
&&
errno
!=
EINPROGRESS
&&
errno
!=
EWOULDBLOCK
)
{
if
(
strcmp
(
aString
,
"shutdown"
)
!=
0
||
(
errno
!=
ENOTCONN
&&
errno
!=
ECONNRESET
))
printf
(
"Socket error %d in %s for socket %d"
,
errno
,
aString
,
sock
);
}
return
errno
;
}
#if !defined(SOCKET_ERROR)
#define SOCKET_ERROR -1
#endif
int
test6_socket_close
(
int
socket
)
{
int
rc
;
#if defined(WIN32)
if
(
shutdown
(
socket
,
SD_BOTH
)
==
SOCKET_ERROR
)
test6_socket_error
(
"shutdown"
,
socket
);
if
((
rc
=
closesocket
(
socket
))
==
SOCKET_ERROR
)
test6_socket_error
(
"close"
,
socket
);
#else
if
(
shutdown
(
socket
,
SHUT_RDWR
)
==
SOCKET_ERROR
)
test6_socket_error
(
"shutdown"
,
socket
);
if
((
rc
=
close
(
socket
))
==
SOCKET_ERROR
)
test6_socket_error
(
"close"
,
socket
);
#endif
return
rc
;
}
typedef
struct
{
int
socket
;
time_t
lastContact
;
#if defined(OPENSSL)
SSL
*
ssl
;
SSL_CTX
*
ctx
;
#endif
}
networkHandles
;
typedef
struct
{
char
*
clientID
;
/**< the string id of the client */
char
*
username
;
/**< MQTT v3.1 user name */
char
*
password
;
/**< MQTT v3.1 password */
unsigned
int
cleansession
:
1
;
/**< MQTT clean session flag */
unsigned
int
connected
:
1
;
/**< whether it is currently connected */
unsigned
int
good
:
1
;
/**< if we have an error on the socket we turn this off */
unsigned
int
ping_outstanding
:
1
;
int
connect_state
:
4
;
networkHandles
net
;
/* ... */
}
Clients
;
typedef
struct
{
char
*
serverURI
;
Clients
*
c
;
MQTTClient_connectionLost
*
cl
;
MQTTClient_messageArrived
*
ma
;
MQTTClient_deliveryComplete
*
dc
;
void
*
context
;
int
connect_sem
;
int
rc
;
/* getsockopt return code in connect */
int
connack_sem
;
int
suback_sem
;
int
unsuback_sem
;
void
*
pack
;
}
MQTTClients
;
int
test6
(
struct
Options
options
)
{
char
*
testname
=
"test6"
;
...
...
@@ -1054,7 +976,7 @@ int test6(struct Options options)
}
/* Client-1 with Will options */
rc
=
MQTTClient_create
(
&
test6_c1
,
options
.
connection
,
"Client_1"
,
MQTTCLIENT_PERSISTENCE_DEFAULT
,
NULL
);
rc
=
MQTTClient_create
(
&
test6_c1
,
options
.
proxy_
connection
,
"Client_1"
,
MQTTCLIENT_PERSISTENCE_DEFAULT
,
NULL
);
assert
(
"good rc from create"
,
rc
==
MQTTCLIENT_SUCCESS
,
"rc was %d
\n
"
,
rc
);
if
(
rc
!=
MQTTCLIENT_SUCCESS
)
goto
exit
;
...
...
@@ -1089,9 +1011,8 @@ 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);
assert("Good rc from publish", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);*/
test6_socket_close
(((
MQTTClients
*
)
test6_c1
)
->
c
->
net
.
socket
);
rc
=
MQTTClient_publish
(
test6_c1
,
mqttsas_topic
,
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"
);
count
=
0
;
...
...
@@ -1119,11 +1040,11 @@ int test6(struct Options options)
rc
=
MQTTClient_isConnected
(
test6_c1
);
assert
(
"Client-1 not connected"
,
rc
==
0
,
"isconnected is %d"
,
rc
);
/* rc = MQTTClient_disconnect(test6_c2, 100L); */
/* assert("Good rc from disconnect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); */
rc
=
MQTTClient_disconnect
(
test6_c2
,
100L
);
assert
(
"Good rc from disconnect"
,
rc
==
MQTTCLIENT_SUCCESS
,
"rc was %d"
,
rc
);
MQTTClient_destroy
(
&
test6_c1
);
/* MQTTClient_destroy(&test6_c2); */
MQTTClient_destroy
(
&
test6_c2
);
exit:
MyLog
(
LOGA_INFO
,
"%s: test %s. %d tests run, %d failures.
\n
"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment