summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative
diff options
context:
space:
mode:
authorAndrew Christian <andrew.christian@nokia.com>2012-03-22 07:51:25 -0400
committerAndrew Christian <andrew.christian@nokia.com>2012-03-22 19:29:10 +0100
commit1a45397265d17753225c2ca3134fd0793f70cfc8 (patch)
tree3e83dc0a3b20e188ea3cf4d9990e7003a7b70d9d /tests/auto/declarative
parent6490c4501e8a2c4f734bb163d273000f43b21de9 (diff)
Exposed IdleDelegates to ProcessManager and added declarative test case
Change-Id: I95dd813cdcee26e1ce654cc4fd49bbe63697c5fc Reviewed-by: Lasse Holmstedt <lasse.holmstedt@nokia.com> Reviewed-by: Chris Craig <ext-chris.craig@nokia.com>
Diffstat (limited to 'tests/auto/declarative')
-rw-r--r--tests/auto/declarative/tst_declarative.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/auto/declarative/tst_declarative.cpp b/tests/auto/declarative/tst_declarative.cpp
index c486c6c..a01a9e8 100644
--- a/tests/auto/declarative/tst_declarative.cpp
+++ b/tests/auto/declarative/tst_declarative.cpp
@@ -58,6 +58,7 @@
#include "processfrontend.h"
#include "processbackend.h"
#include "process.h"
+#include "timeoutidledelegate.h"
QT_USE_NAMESPACE_PROCESSMANAGER
@@ -80,6 +81,7 @@ private slots:
void match();
void rewrite();
+ void timeoutIdleDelegate();
};
@@ -102,6 +104,9 @@ void tst_DeclarativeProcessManager::initTestCase()
qmlRegisterType<DeclarativeRewriteDelegate>(uri, 1, 0, "DeclarativeRewriteDelegate");
qmlRegisterUncreatableType<Process>(uri, 1, 0, "Process", "Don't try to make this");
+ qmlRegisterUncreatableType<IdleDelegate>(uri, 1, 0, "IdleDelegate", "Don't try to make this");
+ qmlRegisterType<TimeoutIdleDelegate>(uri, 1, 0, "TimeoutIdleDelegate");
+
qRegisterMetaType<QProcess::ProcessState>();
qRegisterMetaType<QProcess::ExitStatus>();
qRegisterMetaType<QProcess::ProcessError>();
@@ -130,6 +135,30 @@ static void waitForSocket(const QString& socketname, int timeout=5000)
}
}
+static void waitForChange(QSignalSpy& spy, int count, int timeout=4000)
+{
+ QTime stopWatch;
+ stopWatch.start();
+ forever {
+ if (spy.count() >= count)
+ break;
+ if (stopWatch.elapsed() >= timeout)
+ QFAIL("Timed out");
+ QTestEventLoop::instance().enterLoop(1);
+ }
+}
+
+static void waitForTimeout(int timeout=5000)
+{
+ QTime stopWatch;
+ stopWatch.start();
+ forever {
+ if (stopWatch.elapsed() >= timeout)
+ break;
+ QTestEventLoop::instance().enterLoop(1);
+ }
+}
+
class Spy {
public:
@@ -369,6 +398,43 @@ void tst_DeclarativeProcessManager::rewrite()
QCOMPARE(info.environment().value(QStringLiteral("noiselevel")).toInt(), 85);
}
+
+const char *kTimeoutIdleDelegateTest = "import QtQuick 2.0; import Test 1.0; \n"
+"TimeoutIdleDelegate { \n"
+" id: idled\n"
+" idleInterval: 1000\n"
+" enabled: false\n"
+"}\n";
+
+void tst_DeclarativeProcessManager::timeoutIdleDelegate()
+{
+ QQmlEngine engine;
+ QQmlContext context(&engine);
+ QQmlComponent component(&engine);
+ component.setData(kTimeoutIdleDelegateTest, QUrl());
+ QCOMPARE(component.status(), QQmlComponent::Ready);
+ TimeoutIdleDelegate *delegate = qobject_cast<TimeoutIdleDelegate *>(component.create());
+ QVERIFY(delegate);
+
+ QSignalSpy spyIdleInterval(delegate, SIGNAL(idleIntervalChanged()));
+ QSignalSpy spyIdleCpu(delegate, SIGNAL(idleCpuAvailable()));
+ QSignalSpy spyEnabled(delegate, SIGNAL(enabledChanged()));
+
+ waitForTimeout(2000);
+ QCOMPARE(spyIdleCpu.count(), 0);
+
+ delegate->requestIdleCpu(true);
+ waitForTimeout(2000);
+ QCOMPARE(spyIdleCpu.count(), 0);
+
+ delegate->setEnabled(true);
+ waitForChange(spyIdleCpu, 1);
+ waitForChange(spyIdleCpu, 2);
+
+ delete delegate;
+}
+
+
QTEST_MAIN(tst_DeclarativeProcessManager)
#include "tst_declarative.moc"