diff options
author | Remko Tronçon <git@el-tramo.be> | 2011-10-10 07:37:12 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2011-10-10 07:46:36 (GMT) |
commit | 150542a5c60fe49f4e164ffdaa51236795426214 (patch) | |
tree | 238eda2d89e8347e32d2eabc224633c518fe5083 /Swiften/QA | |
parent | f9187481a14493a729987ebbcfd10839b2439b96 (diff) | |
download | swift-150542a5c60fe49f4e164ffdaa51236795426214.zip swift-150542a5c60fe49f4e164ffdaa51236795426214.tar.bz2 |
Force disconnect signals when calling connect() shortly after disconnect().
Diffstat (limited to 'Swiften/QA')
-rw-r--r-- | Swiften/QA/ClientTest/ClientTest.cpp | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/Swiften/QA/ClientTest/ClientTest.cpp b/Swiften/QA/ClientTest/ClientTest.cpp index 584f644..4515893 100644 --- a/Swiften/QA/ClientTest/ClientTest.cpp +++ b/Swiften/QA/ClientTest/ClientTest.cpp @@ -22,27 +22,33 @@ SimpleEventLoop eventLoop; BoostNetworkFactories networkFactories(&eventLoop); Client* client = 0; -bool reconnected = false; bool rosterReceived = false; +enum TestStage { + FirstConnect, + Reconnect +}; +TestStage stage; -void handleDisconnected(boost::optional<ClientError>) { - eventLoop.stop(); -} - -void handleRosterReceived(boost::shared_ptr<Payload>) { - if (reconnected) { - rosterReceived = true; - client->onDisconnected.connect(boost::bind(&handleDisconnected, _1)); - client->disconnect(); +void handleDisconnected(boost::optional<ClientError> e) { + std::cout << "Disconnected: " << e << std::endl; + if (stage == FirstConnect) { + stage = Reconnect; + client->connect(); } else { - reconnected = true; - client->disconnect(); - client->connect(); + eventLoop.stop(); } } +void handleRosterReceived(boost::shared_ptr<Payload>) { + rosterReceived = true; + std::cout << "Disconnecting" << std::endl; + client->disconnect(); +} + void handleConnected() { + std::cout << "Connected" << std::endl; + rosterReceived = false; GetRosterRequest::ref rosterRequest = GetRosterRequest::create(client->getIQRouter()); rosterRequest->onResponse.connect(boost::bind(&handleRosterReceived, _1)); rosterRequest->send(); @@ -63,7 +69,9 @@ int main(int, char**) { client = new Swift::Client(JID(jid), std::string(pass), &networkFactories); ClientXMLTracer* tracer = new ClientXMLTracer(client); client->onConnected.connect(&handleConnected); + client->onDisconnected.connect(boost::bind(&handleDisconnected, _1)); client->setAlwaysTrustCertificates(); + stage = FirstConnect; client->connect(); { |