Add test for dynamic buffer resize.
This commit is contained in:
parent
a257083a66
commit
e21ac7baae
@ -160,6 +160,43 @@ int test_receive_oversized_message() {
|
|||||||
END_IT
|
END_IT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int test_resize_buffer() {
|
||||||
|
IT("receives a message larger than the default maximum");
|
||||||
|
reset_callback();
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
int length = MQTT_MAX_PACKET_SIZE+1;
|
||||||
|
client.setBufferSize(length);
|
||||||
|
byte publish[] = {0x30,length-2,0x0,0x5,0x74,0x6f,0x70,0x69,0x63,0x70,0x61,0x79,0x6c,0x6f,0x61,0x64};
|
||||||
|
byte bigPublish[length];
|
||||||
|
memset(bigPublish,'A',length);
|
||||||
|
bigPublish[length] = 'B';
|
||||||
|
memcpy(bigPublish,publish,16);
|
||||||
|
shimClient.respond(bigPublish,length);
|
||||||
|
|
||||||
|
rc = client.loop();
|
||||||
|
|
||||||
|
IS_TRUE(rc);
|
||||||
|
|
||||||
|
IS_TRUE(callback_called);
|
||||||
|
IS_TRUE(strcmp(lastTopic,"topic")==0);
|
||||||
|
IS_TRUE(lastLength == length-9);
|
||||||
|
IS_TRUE(memcmp(lastPayload,bigPublish+9,lastLength)==0);
|
||||||
|
|
||||||
|
IS_FALSE(shimClient.error());
|
||||||
|
|
||||||
|
END_IT
|
||||||
|
}
|
||||||
|
|
||||||
int test_receive_oversized_stream_message() {
|
int test_receive_oversized_stream_message() {
|
||||||
IT("drops an oversized message");
|
IT("drops an oversized message");
|
||||||
reset_callback();
|
reset_callback();
|
||||||
@ -242,6 +279,7 @@ int main()
|
|||||||
test_receive_stream();
|
test_receive_stream();
|
||||||
test_receive_max_sized_message();
|
test_receive_max_sized_message();
|
||||||
test_receive_oversized_message();
|
test_receive_oversized_message();
|
||||||
|
test_resize_buffer();
|
||||||
test_receive_oversized_stream_message();
|
test_receive_oversized_stream_message();
|
||||||
test_receive_qos1();
|
test_receive_qos1();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user