summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJędrzej Nowacki <jedrzej.nowacki@digia.com>2013-10-31 14:48:14 +0000
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-04 16:25:52 +0100
commitd426585ba65c6eb5c16af7accf54d7694310eccb (patch)
treea2d05398d9e86932575ccbfaf2121d6b93224482 /tests
parentb9913bdd8d13df7447ed7a0eba5df260a3a5dbdd (diff)
downloadqtenginio-d426585ba65c6eb5c16af7accf54d7694310eccb.tar.gz
Delete QNAM instance when it is not needed anymore.
The QNAM is still shared in the thread but it may happen that is has to be recreated. The main advantage of this change is that we clean memory and that the QNAM is not destroyed after ~QCoreApplication. Change-Id: I3dc6a5e7d85b2feebb498700986d27d203dbb89e Reviewed-by: Andras Becsi <andras.becsi@digia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/enginioclient/tst_enginioclient.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/auto/enginioclient/tst_enginioclient.cpp b/tests/auto/enginioclient/tst_enginioclient.cpp
index d9d5dc8..363bbc2 100644
--- a/tests/auto/enginioclient/tst_enginioclient.cpp
+++ b/tests/auto/enginioclient/tst_enginioclient.cpp
@@ -94,6 +94,7 @@ private slots:
void acl();
void creator_updater();
void sharingNetworkManager();
+ void lifeTimeOfNetworkManager();
void search();
void assignUserToGroup();
@@ -1442,6 +1443,42 @@ void tst_EnginioClient::sharingNetworkManager()
delete e2;
}
+struct NetworkManagerDestroySignalSpy
+{
+ bool &called;
+ void operator()() { called = true; }
+};
+
+void tst_EnginioClient::lifeTimeOfNetworkManager()
+{
+ struct : public QThread {
+ void run()
+ {
+ bool result = false;
+ NetworkManagerDestroySignalSpy spy = { result };
+ {
+ EnginioClient client;
+ QNetworkAccessManager *qnam = client.networkManager();
+ QVERIFY(qnam);
+ QObject::connect(qnam, &QNetworkAccessManager::destroyed, spy);
+ }
+ QVERIFY(spy.called);
+ // we need to repeat the operation to confirm that a qnam instance will
+ // be re-created when needed.
+ result = false;
+ {
+ EnginioClient client;
+ QNetworkAccessManager *qnam = client.networkManager();
+ QVERIFY(qnam);
+ QObject::connect(qnam, &QNetworkAccessManager::destroyed, spy);
+ }
+ QVERIFY(spy.called);
+ }
+ } thread;
+ thread.start();
+ QVERIFY(thread.wait(10000));
+}
+
void tst_EnginioClient::prepareForSearch()
{
QJsonObject customObject1;