From 3cc0c85f05968ab967a8e66a45af0ca5d72dedc1 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Sat, 8 Feb 2014 23:28:58 +0000 Subject: [PATCH] Add connect/disconnect/connect cycle test --- tests/src/connect_spec.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/src/connect_spec.cpp b/tests/src/connect_spec.cpp index 16d967d..46bfb9a 100644 --- a/tests/src/connect_spec.cpp +++ b/tests/src/connect_spec.cpp @@ -174,6 +174,42 @@ int test_connect_with_will_username_password() { END_IT } +int test_connect_disconnect_connect() { + IT("connects, disconnects and connects again"); + ShimClient shimClient; + + shimClient.setAllowConnect(true); + byte expectServer[] = { 172, 16, 0, 2 }; + shimClient.expectConnect(expectServer,1883); + byte connect[] = {0x10,0x1a,0x0,0x6,0x4d,0x51,0x49,0x73,0x64,0x70,0x3,0x2,0x0,0xf,0x0,0xc,0x63,0x6c,0x69,0x65,0x6e,0x74,0x5f,0x74,0x65,0x73,0x74,0x31}; + byte connack[] = { 0x20, 0x02, 0x00, 0x00 }; + + shimClient.expect(connect,28); + shimClient.respond(connack,4); + + PubSubClient client(server, 1883, callback, shimClient); + int rc = client.connect((char*)"client_test1"); + IS_TRUE(rc); + IS_FALSE(shimClient.error()); + + byte disconnect[] = {0xE0,0x00}; + shimClient.expect(disconnect,2); + + client.disconnect(); + + IS_FALSE(client.connected()); + IS_FALSE(shimClient.connected()); + IS_FALSE(shimClient.error()); + + shimClient.expect(connect,28); + shimClient.respond(connack,4); + rc = client.connect((char*)"client_test1"); + IS_TRUE(rc); + IS_FALSE(shimClient.error()); + + END_IT +} + int main() { test_connect_fails_no_network(); @@ -186,6 +222,7 @@ int main() test_connect_ignores_password_no_username(); test_connect_with_will(); test_connect_with_will_username_password(); + test_connect_disconnect_connect(); FINISH }