--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/taskswitcher/client/tsrc/t_tstaskmonitorclient/t_tstaskmonitorclient.cpp Thu Sep 16 12:11:40 2010 +0100
@@ -0,0 +1,177 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+
+#include "t_tstaskmonitorclient.h"
+
+#include <QtTest/QtTest>
+
+#include "tstestutils.h"
+
+#include "tstaskchangeinfo.h"
+#include "tstask.h"
+
+namespace {
+ const char KUnitTestTaskName[] = "t_tstaskmonitorclient";
+ const char KTestApplicationName[] = "appwithouticon";
+}
+
+void T_TsTaskMonitorClient::initTestCase()
+{
+ QCOMPARE(mWsSession.Connect(), KErrNone);
+}
+
+void T_TsTaskMonitorClient::cleanupTestCase()
+{
+ mWsSession.Close();
+}
+
+void T_TsTaskMonitorClient::testTaskClose()
+{
+ int firstCount = mTaskMonitor.changeList(true).count();
+
+ // start test application and wait for notification
+ quint64 testApplicationId;
+ QVERIFY(TsTestUtils::startApplication(KTestApplicationName, testApplicationId));
+ QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged())));
+
+ // find test application task
+ QSharedPointer<TsTask> testAppTask = findTask(KTestApplicationName);
+ QVERIFY(!testAppTask.isNull());
+
+ int secondCount = mTaskMonitor.changeList(true).count();
+ QCOMPARE(secondCount, firstCount + 1);
+
+ // call close and wait for task list change signal
+ testAppTask->close();
+ QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged())));
+ QTest::qWait(3000); // wait until the process fully closes
+
+ // we closed the test application, so the count should be equal to the first one
+ int thirdCount = mTaskMonitor.changeList(true).count();
+ QCOMPARE(thirdCount, firstCount);
+}
+
+void T_TsTaskMonitorClient::testTaskListChangeSignal()
+{
+ QSignalSpy spy(&mTaskMonitor, SIGNAL(taskListChanged()));
+ QVERIFY(spy.isValid());
+
+ // start app
+ quint64 testApplicationId;
+ QVERIFY(TsTestUtils::startApplication(KTestApplicationName, testApplicationId));
+ QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged())));
+ QCOMPARE(spy.count(), 1);
+
+ // find unit test task
+ QSharedPointer<TsTask> unitTestTask = findTask(KUnitTestTaskName);
+ QVERIFY(!unitTestTask.isNull());
+
+ // signal is emitted after order of tasks is changed
+ unitTestTask->open();
+ QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged())));
+ QCOMPARE(spy.count(), 2);
+
+ // close test app
+ QVERIFY(TsTestUtils::closeApplication(testApplicationId));
+ QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged())));
+}
+
+void T_TsTaskMonitorClient::testTaskList()
+{
+ // get task list, it should contain at least one application - this unit test
+ int firstCount = mTaskMonitor.changeList(true).count();
+ QVERIFY(firstCount);
+
+ // start test application, and get task list.
+ // It should contain one more item than during first check
+
+ {
+ quint64 testApplicationId;
+ QVERIFY(TsTestUtils::startApplication(KTestApplicationName, testApplicationId));
+ // wait for signals after application start and backstepping
+ QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged())));
+ QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged())));
+
+ int secondCount = mTaskMonitor.changeList(true).count();
+ QCOMPARE(secondCount, firstCount + 1);
+
+ QVERIFY(TsTestUtils::closeApplication(testApplicationId));
+ QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged())));
+ }
+ QTest::qWait(3000); // wait until the process fully closes
+
+ // close test application and get task list
+ // It should contain the same number of items as during first check
+ QCOMPARE(mTaskMonitor.changeList(true).count(), firstCount);
+}
+
+void T_TsTaskMonitorClient::testTaskChangeInfoGetters()
+{
+ const int KNewOffset(1500);
+ const int KOldOffset(2900);
+
+ TsTaskChangeInfo changeInfo(KNewOffset, KOldOffset);
+ QCOMPARE(changeInfo.newOffset(), KNewOffset);
+ QCOMPARE(changeInfo.oldOffset(), KOldOffset);
+}
+
+void T_TsTaskMonitorClient::testCreatingInsertTaskChangeInfo()
+{
+ TsTaskChangeInfo changeInfo(0, TsTaskChangeInfo::KInvalidOffset);
+ QCOMPARE(changeInfo.changeType(), TsTaskChangeInfo::EChangeInsert);
+}
+
+void T_TsTaskMonitorClient::testCreatingDeleteTaskChangeInfo()
+{
+ TsTaskChangeInfo changeInfo(TsTaskChangeInfo::KInvalidOffset, 0);
+ QCOMPARE(changeInfo.changeType(), TsTaskChangeInfo::EChangeDelete);
+}
+
+void T_TsTaskMonitorClient::testCreatingMoveTaskChangeInfo()
+{
+ TsTaskChangeInfo changeInfo(0, 1);
+ QCOMPARE(changeInfo.changeType(), TsTaskChangeInfo::EChangeMove);
+}
+
+void T_TsTaskMonitorClient::testCreatingUpdateTaskChangeInfo()
+{
+ TsTaskChangeInfo changeInfo(0, 0);
+ QCOMPARE(changeInfo.changeType(), TsTaskChangeInfo::EChangeUpdate);
+}
+
+void T_TsTaskMonitorClient::testCreatingCancelTaskChangeInfo()
+{
+ TsTaskChangeInfo changeInfo(TsTaskChangeInfo::KInvalidOffset, TsTaskChangeInfo::KInvalidOffset);
+ QCOMPARE(changeInfo.changeType(), TsTaskChangeInfo::EChangeCancel);
+}
+
+QSharedPointer<TsTask> T_TsTaskMonitorClient::findTask(const QString &taskName)
+{
+ // find unit test task
+ QSharedPointer<TsTask> myTask;
+ foreach(TsTaskChange taskChange, mTaskMonitor.changeList(true)) {
+ if (!taskChange.second.isNull()) {
+ if (taskChange.second->name().contains(taskName)) {
+ myTask = taskChange.second;
+ break;
+ }
+ }
+ }
+ return myTask;
+}
+
+QTEST_MAIN(T_TsTaskMonitorClient)