Add setKeepAlive function and tests

This commit is contained in:
Nick O'Leary
2020-05-20 01:18:02 +01:00
parent 64e981190b
commit 77c4e445ea
3 changed files with 57 additions and 3 deletions

View File

@ -280,6 +280,38 @@ int test_connect_disconnect_connect() {
END_IT
}
int test_connect_custom_keepalive() {
IT("sends a properly formatted connect packet with custom keepalive value");
ShimClient shimClient;
shimClient.setAllowConnect(true);
byte expectServer[] = { 172, 16, 0, 2 };
shimClient.expectConnect(expectServer,1883);
// Set keepalive to 300secs == 0x01 0x2c
byte connect[] = {0x10,0x18,0x0,0x4,0x4d,0x51,0x54,0x54,0x4,0x2,0x01,0x2c,0x0,0xc,0x63,0x6c,0x69,0x65,0x6e,0x74,0x5f,0x74,0x65,0x73,0x74,0x31};
byte connack[] = { 0x20, 0x02, 0x00, 0x00 };
shimClient.expect(connect,26);
shimClient.respond(connack,4);
PubSubClient client(server, 1883, callback, shimClient);
int state = client.state();
IS_TRUE(state == MQTT_DISCONNECTED);
client.setKeepAlive(300);
int rc = client.connect((char*)"client_test1");
IS_TRUE(rc);
IS_FALSE(shimClient.error());
state = client.state();
IS_TRUE(state == MQTT_CONNECTED);
END_IT
}
int main()
{
SUITE("Connect");
@ -298,5 +330,7 @@ int main()
test_connect_with_will();
test_connect_with_will_username_password();
test_connect_disconnect_connect();
test_connect_custom_keepalive();
FINISH
}