|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "t_tstaskmonitorclient.h" |
|
19 |
|
20 #include <QtTest/QtTest> |
|
21 |
|
22 #include "tstestutils.h" |
|
23 |
|
24 #include "tstaskchangeinfo.h" |
|
25 #include "tstask.h" |
|
26 |
|
27 namespace { |
|
28 const char KUnitTestTaskName[] = "t_tstaskmonitorclient"; |
|
29 const char KTestApplicationName[] = "appwithouticon"; |
|
30 } |
|
31 |
|
32 void T_TsTaskMonitorClient::initTestCase() |
|
33 { |
|
34 QCOMPARE(mWsSession.Connect(), KErrNone); |
|
35 } |
|
36 |
|
37 void T_TsTaskMonitorClient::cleanupTestCase() |
|
38 { |
|
39 mWsSession.Close(); |
|
40 } |
|
41 |
|
42 void T_TsTaskMonitorClient::testTaskClose() |
|
43 { |
|
44 int firstCount = mTaskMonitor.changeList(true).count(); |
|
45 |
|
46 // start test application and wait for notification |
|
47 quint64 testApplicationId; |
|
48 QVERIFY(TsTestUtils::startApplication(KTestApplicationName, testApplicationId)); |
|
49 QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged()))); |
|
50 |
|
51 // find test application task |
|
52 QSharedPointer<TsTask> testAppTask = findTask(KTestApplicationName); |
|
53 QVERIFY(!testAppTask.isNull()); |
|
54 |
|
55 int secondCount = mTaskMonitor.changeList(true).count(); |
|
56 QCOMPARE(secondCount, firstCount + 1); |
|
57 |
|
58 // call close and wait for task list change signal |
|
59 testAppTask->close(); |
|
60 QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged()))); |
|
61 QTest::qWait(3000); // wait until the process fully closes |
|
62 |
|
63 // we closed the test application, so the count should be equal to the first one |
|
64 int thirdCount = mTaskMonitor.changeList(true).count(); |
|
65 QCOMPARE(thirdCount, firstCount); |
|
66 } |
|
67 |
|
68 void T_TsTaskMonitorClient::testTaskListChangeSignal() |
|
69 { |
|
70 QSignalSpy spy(&mTaskMonitor, SIGNAL(taskListChanged())); |
|
71 QVERIFY(spy.isValid()); |
|
72 |
|
73 // start app |
|
74 quint64 testApplicationId; |
|
75 QVERIFY(TsTestUtils::startApplication(KTestApplicationName, testApplicationId)); |
|
76 QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged()))); |
|
77 QCOMPARE(spy.count(), 1); |
|
78 |
|
79 // find unit test task |
|
80 QSharedPointer<TsTask> unitTestTask = findTask(KUnitTestTaskName); |
|
81 QVERIFY(!unitTestTask.isNull()); |
|
82 |
|
83 // signal is emitted after order of tasks is changed |
|
84 unitTestTask->open(); |
|
85 QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged()))); |
|
86 QCOMPARE(spy.count(), 2); |
|
87 |
|
88 // close test app |
|
89 QVERIFY(TsTestUtils::closeApplication(testApplicationId)); |
|
90 QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged()))); |
|
91 } |
|
92 |
|
93 void T_TsTaskMonitorClient::testTaskList() |
|
94 { |
|
95 // get task list, it should contain at least one application - this unit test |
|
96 int firstCount = mTaskMonitor.changeList(true).count(); |
|
97 QVERIFY(firstCount); |
|
98 |
|
99 // start test application, and get task list. |
|
100 // It should contain one more item than during first check |
|
101 |
|
102 { |
|
103 quint64 testApplicationId; |
|
104 QVERIFY(TsTestUtils::startApplication(KTestApplicationName, testApplicationId)); |
|
105 // wait for signals after application start and backstepping |
|
106 QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged()))); |
|
107 QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged()))); |
|
108 |
|
109 int secondCount = mTaskMonitor.changeList(true).count(); |
|
110 QCOMPARE(secondCount, firstCount + 1); |
|
111 |
|
112 QVERIFY(TsTestUtils::closeApplication(testApplicationId)); |
|
113 QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged()))); |
|
114 } |
|
115 QTest::qWait(3000); // wait until the process fully closes |
|
116 |
|
117 // close test application and get task list |
|
118 // It should contain the same number of items as during first check |
|
119 QCOMPARE(mTaskMonitor.changeList(true).count(), firstCount); |
|
120 } |
|
121 |
|
122 void T_TsTaskMonitorClient::testTaskChangeInfoGetters() |
|
123 { |
|
124 const int KNewOffset(1500); |
|
125 const int KOldOffset(2900); |
|
126 |
|
127 TsTaskChangeInfo changeInfo(KNewOffset, KOldOffset); |
|
128 QCOMPARE(changeInfo.newOffset(), KNewOffset); |
|
129 QCOMPARE(changeInfo.oldOffset(), KOldOffset); |
|
130 } |
|
131 |
|
132 void T_TsTaskMonitorClient::testCreatingInsertTaskChangeInfo() |
|
133 { |
|
134 TsTaskChangeInfo changeInfo(0, TsTaskChangeInfo::KInvalidOffset); |
|
135 QCOMPARE(changeInfo.changeType(), TsTaskChangeInfo::EChangeInsert); |
|
136 } |
|
137 |
|
138 void T_TsTaskMonitorClient::testCreatingDeleteTaskChangeInfo() |
|
139 { |
|
140 TsTaskChangeInfo changeInfo(TsTaskChangeInfo::KInvalidOffset, 0); |
|
141 QCOMPARE(changeInfo.changeType(), TsTaskChangeInfo::EChangeDelete); |
|
142 } |
|
143 |
|
144 void T_TsTaskMonitorClient::testCreatingMoveTaskChangeInfo() |
|
145 { |
|
146 TsTaskChangeInfo changeInfo(0, 1); |
|
147 QCOMPARE(changeInfo.changeType(), TsTaskChangeInfo::EChangeMove); |
|
148 } |
|
149 |
|
150 void T_TsTaskMonitorClient::testCreatingUpdateTaskChangeInfo() |
|
151 { |
|
152 TsTaskChangeInfo changeInfo(0, 0); |
|
153 QCOMPARE(changeInfo.changeType(), TsTaskChangeInfo::EChangeUpdate); |
|
154 } |
|
155 |
|
156 void T_TsTaskMonitorClient::testCreatingCancelTaskChangeInfo() |
|
157 { |
|
158 TsTaskChangeInfo changeInfo(TsTaskChangeInfo::KInvalidOffset, TsTaskChangeInfo::KInvalidOffset); |
|
159 QCOMPARE(changeInfo.changeType(), TsTaskChangeInfo::EChangeCancel); |
|
160 } |
|
161 |
|
162 QSharedPointer<TsTask> T_TsTaskMonitorClient::findTask(const QString &taskName) |
|
163 { |
|
164 // find unit test task |
|
165 QSharedPointer<TsTask> myTask; |
|
166 foreach(TsTaskChange taskChange, mTaskMonitor.changeList(true)) { |
|
167 if (!taskChange.second.isNull()) { |
|
168 if (taskChange.second->name().contains(taskName)) { |
|
169 myTask = taskChange.second; |
|
170 break; |
|
171 } |
|
172 } |
|
173 } |
|
174 return myTask; |
|
175 } |
|
176 |
|
177 QTEST_MAIN(T_TsTaskMonitorClient) |