FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pubsubclient/tests/src/subscribe_spec.cpp at master · ArduinoLibrariesForks/pubsubclient · GitHub
ArduinoLibrariesForks
pubsubclient
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pubsubclient
/
tests
/
src
/
subscribe_spec.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
177 lines (128 loc) · 4.6 KB
Breadcrumbs
pubsubclient
/
tests
/
src
/
subscribe_spec.cpp
Copy path
File metadata and controls
177 lines (128 loc) · 4.6 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#
include
"
PubSubClient.h
"
#
include
"
ShimClient.h
"
#
include
"
Buffer.h
"
#
include
"
BDDTest.h
"
#
include
"
trace.h
"
byte server[] = {
172
,
16
,
0
,
2
};
void
callback
(
char
* topic, byte* payload,
unsigned
int
length) {
//
handle message arrived
}
int
test_subscribe_no_qos
() {
IT
(
"
subscribe without qos defaults to 0
"
);
ShimClient shimClient;
shimClient.
setAllowConnect
(
true
);
byte connack[] = {
0x20
,
0x02
,
0x00
,
0x00
};
shimClient.
respond
(connack,
4
);
PubSubClient
client
(server,
1883
, callback, shimClient);
int
rc = client.
connect
((
char
*)
"
client_test1
"
);
IS_TRUE
(rc);
byte subscribe[] = {
0x82
,
0xa
,
0x0
,
0x2
,
0x0
,
0x5
,
0x74
,
0x6f
,
0x70
,
0x69
,
0x63
,
0x0
};
shimClient.
expect
(subscribe,
12
);
byte suback[] = {
0x90
,
0x3
,
0x0
,
0x2
,
0x0
};
shimClient.
respond
(suback,
5
);
rc = client.
subscribe
((
char
*)
"
topic
"
);
IS_TRUE
(rc);
IS_FALSE
(shimClient.
error
());
END_IT
}
int
test_subscribe_qos_1
() {
IT
(
"
subscribes qos 1
"
);
ShimClient shimClient;
shimClient.
setAllowConnect
(
true
);
byte connack[] = {
0x20
,
0x02
,
0x00
,
0x00
};
shimClient.
respond
(connack,
4
);
PubSubClient
client
(server,
1883
, callback, shimClient);
int
rc = client.
connect
((
char
*)
"
client_test1
"
);
IS_TRUE
(rc);
byte subscribe[] = {
0x82
,
0xa
,
0x0
,
0x2
,
0x0
,
0x5
,
0x74
,
0x6f
,
0x70
,
0x69
,
0x63
,
0x1
};
shimClient.
expect
(subscribe,
12
);
byte suback[] = {
0x90
,
0x3
,
0x0
,
0x2
,
0x1
};
shimClient.
respond
(suback,
5
);
rc = client.
subscribe
((
char
*)
"
topic
"
,
1
);
IS_TRUE
(rc);
IS_FALSE
(shimClient.
error
());
END_IT
}
int
test_subscribe_not_connected
() {
IT
(
"
subscribe fails when not connected
"
);
ShimClient shimClient;
PubSubClient
client
(server,
1883
, callback, shimClient);
int
rc = client.
subscribe
((
char
*)
"
topic
"
);
IS_FALSE
(rc);
IS_FALSE
(shimClient.
error
());
END_IT
}
int
test_subscribe_invalid_qos
() {
IT
(
"
subscribe fails with invalid qos values
"
);
ShimClient shimClient;
shimClient.
setAllowConnect
(
true
);
byte connack[] = {
0x20
,
0x02
,
0x00
,
0x00
};
shimClient.
respond
(connack,
4
);
PubSubClient
client
(server,
1883
, callback, shimClient);
int
rc = client.
connect
((
char
*)
"
client_test1
"
);
IS_TRUE
(rc);
rc = client.
subscribe
((
char
*)
"
topic
"
,
2
);
IS_FALSE
(rc);
rc = client.
subscribe
((
char
*)
"
topic
"
,
254
);
IS_FALSE
(rc);
IS_FALSE
(shimClient.
error
());
END_IT
}
int
test_subscribe_too_long
() {
IT
(
"
subscribe fails with too long topic
"
);
ShimClient shimClient;
shimClient.
setAllowConnect
(
true
);
byte connack[] = {
0x20
,
0x02
,
0x00
,
0x00
};
shimClient.
respond
(connack,
4
);
PubSubClient
client
(server,
1883
, callback, shimClient);
int
rc = client.
connect
((
char
*)
"
client_test1
"
);
IS_TRUE
(rc);
//
max length should be allowed
//
0 1 2 3 4 5 6 7 8 9 0 1 2
rc = client.
subscribe
((
char
*)
"
12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
"
);
IS_TRUE
(rc);
//
0 1 2 3 4 5 6 7 8 9 0 1 2
rc = client.
subscribe
((
char
*)
"
123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
"
);
IS_FALSE
(rc);
IS_FALSE
(shimClient.
error
());
END_IT
}
int
test_unsubscribe
() {
IT
(
"
unsubscribes
"
);
ShimClient shimClient;
shimClient.
setAllowConnect
(
true
);
byte connack[] = {
0x20
,
0x02
,
0x00
,
0x00
};
shimClient.
respond
(connack,
4
);
PubSubClient
client
(server,
1883
, callback, shimClient);
int
rc = client.
connect
((
char
*)
"
client_test1
"
);
IS_TRUE
(rc);
byte unsubscribe[] = {
0xA2
,
0x9
,
0x0
,
0x2
,
0x0
,
0x5
,
0x74
,
0x6f
,
0x70
,
0x69
,
0x63
};
shimClient.
expect
(unsubscribe,
12
);
byte unsuback[] = {
0xB0
,
0x2
,
0x0
,
0x2
};
shimClient.
respond
(unsuback,
4
);
rc = client.
unsubscribe
((
char
*)
"
topic
"
);
IS_TRUE
(rc);
IS_FALSE
(shimClient.
error
());
END_IT
}
int
test_unsubscribe_not_connected
() {
IT
(
"
unsubscribe fails when not connected
"
);
ShimClient shimClient;
PubSubClient
client
(server,
1883
, callback, shimClient);
int
rc = client.
unsubscribe
((
char
*)
"
topic
"
);
IS_FALSE
(rc);
IS_FALSE
(shimClient.
error
());
END_IT
}
int
main
()
{
SUITE
(
"
Subscribe
"
);
test_subscribe_no_qos
();
test_subscribe_qos_1
();
test_subscribe_not_connected
();
test_subscribe_invalid_qos
();
test_subscribe_too_long
();
test_unsubscribe
();
test_unsubscribe_not_connected
();
FINISH
}
Back
|
FazBrowse Home
|
New Git URL