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
77d7dae4
Commit
77d7dae4
authored
Aug 28, 2013
by
Ian Craggs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve tests - will messages and ha connect options
parent
3ed9a7b3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
37 deletions
+68
-37
test1.c
test/test1.c
+9
-20
test4.c
test/test4.c
+59
-17
No files found.
test/test1.c
View file @
77d7dae4
...
@@ -994,23 +994,18 @@ typedef struct
...
@@ -994,23 +994,18 @@ typedef struct
int
test6
(
struct
Options
options
)
int
test6
(
struct
Options
options
)
{
{
char
*
testname
=
"test6"
;
char
*
testname
=
"test6"
;
/* TODO - unused -remove? char summaryname[50]; */
/* TODO - unused -remove? FILE *outfile = NULL; */
MQTTClient_connectOptions
opts
=
MQTTClient_connectOptions_initializer
;
MQTTClient_connectOptions
opts
=
MQTTClient_connectOptions_initializer
;
MQTTClient_willOptions
wopts
=
MQTTClient_willOptions_initializer
;
MQTTClient_willOptions
wopts
=
MQTTClient_willOptions_initializer
;
/* TODO - unused -remove? MQTTClient_connectOptions opts2 = MQTTClient_connectOptions_initializer; */
MQTTClient_connectOptions
opts2
=
MQTTClient_connectOptions_initializer
;
int
rc
;
int
rc
,
count
;
/* TODO - unused -remove? MQTTClient_message pubmsg = MQTTClient_message_initializer; */
char
*
mqttsas_topic
=
"MQTTSAS topic"
;
/* TODO - unused -remove? MQTTClient_message* m = NULL; */
/* TODO - unused -remove? int count = 0; */
/* TODO - unused -remove? 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
=
10
;
opts
.
keepAliveInterval
=
2
;
opts
.
cleansession
=
1
;
opts
.
cleansession
=
1
;
opts
.
will
=
&
wopts
;
opts
.
will
=
&
wopts
;
opts
.
will
->
message
=
test6_will_message
;
opts
.
will
->
message
=
test6_will_message
;
...
@@ -1024,7 +1019,6 @@ int test6(struct Options options)
...
@@ -1024,7 +1019,6 @@ int test6(struct Options options)
}
}
/* Client-1 with Will options */
/* Client-1 with Will options */
/* connect to 1884 which is the protocol tracer and which allows the connection to be broken on command */
rc
=
MQTTClient_create
(
&
test6_c1
,
options
.
connection
,
"Client_1"
,
MQTTCLIENT_PERSISTENCE_DEFAULT
,
NULL
);
rc
=
MQTTClient_create
(
&
test6_c1
,
options
.
connection
,
"Client_1"
,
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
)
...
@@ -1041,12 +1035,8 @@ int test6(struct Options options)
...
@@ -1041,12 +1035,8 @@ int test6(struct Options options)
if
(
rc
!=
MQTTCLIENT_SUCCESS
)
if
(
rc
!=
MQTTCLIENT_SUCCESS
)
goto
exit
;
goto
exit
;
#if 1
rc
=
MQTTClient_disconnect
(
test6_c1
,
100L
);
assert
(
"Good rc from disconnect"
,
rc
==
MQTTCLIENT_SUCCESS
,
"rc was %d"
,
rc
);
#else
/* Client - 2 (multi-threaded) */
/* Client - 2 (multi-threaded) */
rc
=
MQTTClient_create
(
&
test6_c2
,
"127.0.0.1:1883"
,
"Client_2"
,
MQTTCLIENT_PERSISTENCE_DEFAULT
,
NULL
);
rc
=
MQTTClient_create
(
&
test6_c2
,
options
.
connection
,
"Client_2"
,
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
);
/* Set the callback functions for the client */
/* Set the callback functions for the client */
...
@@ -1064,9 +1054,9 @@ int test6(struct Options options)
...
@@ -1064,9 +1054,9 @@ 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, 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);
*/
/* test6_socket_close(((MQTTClients*)test6_c1)->c->socket); */
test6_socket_close
(((
MQTTClients
*
)
test6_c1
)
->
c
->
socket
);
MyLog
(
LOGA_INFO
,
"Waiting to receive the will message"
);
MyLog
(
LOGA_INFO
,
"Waiting to receive the will message"
);
count
=
0
;
count
=
0
;
...
@@ -1084,9 +1074,8 @@ int test6(struct Options options)
...
@@ -1084,9 +1074,8 @@ int test6(struct Options options)
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_c
1
);
rc
=
MQTTClient_isConnected
(
test6_c
2
);
assert
(
"Client-2 still connected"
,
rc
==
1
,
"isconnected is %d"
,
rc
);
assert
(
"Client-2 still connected"
,
rc
==
1
,
"isconnected is %d"
,
rc
);
#endif
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
);
...
...
test/test4.c
View file @
77d7dae4
...
@@ -976,15 +976,22 @@ exit:
...
@@ -976,15 +976,22 @@ exit:
}
}
typedef
struct
{
MQTTAsync
c
;
int
should_fail
;
}
test6_client_info
;
void
test6_onConnectFailure
(
void
*
context
,
MQTTAsync_failureData
*
response
)
void
test6_onConnectFailure
(
void
*
context
,
MQTTAsync_failureData
*
response
)
{
{
MQTTAsync
c
=
(
MQTTAsync
)
context
;
test6_client_info
cinfo
=
*
(
test6_client_info
*
)
context
;
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
);
MyLog
(
LOGA_INFO
,
"Connack rc is %d"
,
response
?
response
->
code
:
-
999
);
if
(
response
)
MyLog
(
LOGA_INFO
,
"Connack rc is %d"
,
response
->
code
);
assert
(
"Should fail to connect"
,
cinfo
.
should_fail
,
"should_fail was %d"
,
cinfo
.
should_fail
);
test_finished
=
1
;
test_finished
=
1
;
}
}
...
@@ -992,11 +999,11 @@ void test6_onConnectFailure(void* context, MQTTAsync_failureData* response)
...
@@ -992,11 +999,11 @@ void test6_onConnectFailure(void* context, MQTTAsync_failureData* response)
void
test6_onConnect
(
void
*
context
,
MQTTAsync_successData
*
response
)
void
test6_onConnect
(
void
*
context
,
MQTTAsync_successData
*
response
)
{
{
MQTTAsync
c
=
(
MQTTAsync
)
context
;
test6_client_info
cinfo
=
*
(
test6_client_info
*
)
context
;
MQTTAsync_responseOptions
opts
=
MQTTAsync_responseOptions_initializer
;
int
rc
;
MyLog
(
LOGA_DEBUG
,
"In connect onFailure callback, context %p"
,
context
);
MyLog
(
LOGA_DEBUG
,
"In connect success callback, context %p"
,
context
);
assert
(
"Should connect correctly"
,
!
cinfo
.
should_fail
,
"should_fail was %d"
,
cinfo
.
should_fail
);
test_finished
=
1
;
test_finished
=
1
;
}
}
...
@@ -1010,38 +1017,72 @@ Test6: HA connections
...
@@ -1010,38 +1017,72 @@ Test6: HA connections
int
test6
(
struct
Options
options
)
int
test6
(
struct
Options
options
)
{
{
int
subsqos
=
2
;
int
subsqos
=
2
;
MQTTAsync
c
;
test6_client_info
cinfo
;
MQTTAsync_connectOptions
opts
=
MQTTAsync_connectOptions_initializer
;
MQTTAsync_connectOptions
opts
=
MQTTAsync_connectOptions_initializer
;
MQTTAsync_willOptions
wopts
=
MQTTAsync_willOptions_initializer
;
MQTTAsync_willOptions
wopts
=
MQTTAsync_willOptions_initializer
;
int
rc
=
0
;
int
rc
=
0
;
char
*
test_topic
=
"C client test1"
;
char
*
test_topic
=
"C client test1"
;
char
*
uris
[
2
]
=
{
"tcp://localhost:1884"
,
"tcp://localhost:1883"
};
char
*
uris
[
2
]
=
{
options
.
connection
,
options
.
connection
};
test_finished
=
failures
=
0
;
failures
=
0
;
MyLog
(
LOGA_INFO
,
"Starting test 7 - HA connections"
);
MyLog
(
LOGA_INFO
,
"Starting test 7 - HA connections"
);
fprintf
(
xml
,
"<testcase classname=
\"
test4
\"
name=
\"
HA connections
\"
"
);
fprintf
(
xml
,
"<testcase classname=
\"
test4
\"
name=
\"
HA connections
\"
"
);
global_start_time
=
start_clock
();
global_start_time
=
start_clock
();
rc
=
MQTTAsync_create
(
&
c
,
options
.
connection
,
"a clientid that is too long to be accepted"
,
test_finished
=
0
;
cinfo
.
should_fail
=
1
;
/* fail to connect */
rc
=
MQTTAsync_create
(
&
cinfo
.
c
,
"tcp://rubbish:1883"
,
"async ha connection 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
)
{
{
MQTTAsync_destroy
(
&
c
);
MQTTAsync_destroy
(
&
c
info
.
c
);
goto
exit
;
goto
exit
;
}
}
rc
=
MQTTAsync_setCallbacks
(
c
,
c
,
NULL
,
test1_messageArrived
,
NULL
);
rc
=
MQTTAsync_setCallbacks
(
c
info
.
c
,
cinfo
.
c
,
NULL
,
test1_messageArrived
,
NULL
);
assert
(
"Good rc from setCallbacks"
,
rc
==
MQTTASYNC_SUCCESS
,
"rc was %d"
,
rc
);
assert
(
"Good rc from setCallbacks"
,
rc
==
MQTTASYNC_SUCCESS
,
"rc was %d"
,
rc
);
opts
.
onSuccess
=
test6_onConnect
;
opts
.
onSuccess
=
test6_onConnect
;
opts
.
onFailure
=
test6_onConnectFailure
;
opts
.
onFailure
=
test6_onConnectFailure
;
opts
.
context
=
c
;
opts
.
context
=
&
cinfo
;
MyLog
(
LOGA_DEBUG
,
"Connecting"
);
rc
=
MQTTAsync_connect
(
cinfo
.
c
,
&
opts
);
rc
=
0
;
assert
(
"Good rc from connect"
,
rc
==
MQTTASYNC_SUCCESS
,
"rc was %d"
,
rc
);
if
(
rc
!=
MQTTASYNC_SUCCESS
)
goto
exit
;
while
(
!
test_finished
)
#if defined(WIN32)
Sleep
(
100
);
#else
usleep
(
10000L
);
#endif
test_finished
=
0
;
cinfo
.
should_fail
=
0
;
/* should connect */
rc
=
MQTTAsync_create
(
&
cinfo
.
c
,
"tcp://rubbish:1883"
,
"async ha connection test"
,
MQTTCLIENT_PERSISTENCE_DEFAULT
,
NULL
);
assert
(
"good rc from create"
,
rc
==
MQTTASYNC_SUCCESS
,
"rc was %d
\n
"
,
rc
);
if
(
rc
!=
MQTTASYNC_SUCCESS
)
{
MQTTAsync_destroy
(
&
cinfo
.
c
);
goto
exit
;
}
rc
=
MQTTAsync_setCallbacks
(
cinfo
.
c
,
cinfo
.
c
,
NULL
,
test1_messageArrived
,
NULL
);
assert
(
"Good rc from setCallbacks"
,
rc
==
MQTTASYNC_SUCCESS
,
"rc was %d"
,
rc
);
opts
.
onSuccess
=
test6_onConnect
;
opts
.
onFailure
=
test6_onConnectFailure
;
opts
.
context
=
&
cinfo
;
opts
.
serverURIs
=
uris
;
opts
.
serverURIs
=
uris
;
opts
.
serverURIcount
=
2
;
opts
.
serverURIcount
=
2
;
MyLog
(
LOGA_DEBUG
,
"Connecting"
);
MyLog
(
LOGA_DEBUG
,
"Connecting"
);
rc
=
MQTTAsync_connect
(
c
,
&
opts
);
rc
=
MQTTAsync_connect
(
c
info
.
c
,
&
opts
);
rc
=
0
;
rc
=
0
;
assert
(
"Good rc from connect"
,
rc
==
MQTTASYNC_SUCCESS
,
"rc was %d"
,
rc
);
assert
(
"Good rc from connect"
,
rc
==
MQTTASYNC_SUCCESS
,
"rc was %d"
,
rc
);
if
(
rc
!=
MQTTASYNC_SUCCESS
)
if
(
rc
!=
MQTTASYNC_SUCCESS
)
...
@@ -1054,7 +1095,8 @@ int test6(struct Options options)
...
@@ -1054,7 +1095,8 @@ int test6(struct Options options)
usleep
(
10000L
);
usleep
(
10000L
);
#endif
#endif
MQTTAsync_destroy
(
&
c
);
MQTTAsync_destroy
(
&
cinfo
.
c
);
exit:
exit:
MyLog
(
LOGA_INFO
,
"TEST6: test %s. %d tests run, %d failures."
,
MyLog
(
LOGA_INFO
,
"TEST6: test %s. %d tests run, %d failures."
,
...
...
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