Changeset View
Changeset View
Standalone View
Standalone View
tests/processtest.cpp
Show First 20 Lines • Show All 190 Lines • ▼ Show 20 Line(s) | 184 | void testProcess::testUpdateOrAddProcess() { | |||
---|---|---|---|---|---|
191 | if (process) | 191 | if (process) | ||
192 | QCOMPARE(process->pid(), 1l); | 192 | QCOMPARE(process->pid(), 1l); | ||
193 | 193 | | |||
194 | // Make sure that this doesn't crash at least | 194 | // Make sure that this doesn't crash at least | ||
195 | processController->updateOrAddProcess(1); | 195 | processController->updateOrAddProcess(1); | ||
196 | processController->updateOrAddProcess(0); | 196 | processController->updateOrAddProcess(0); | ||
197 | processController->updateOrAddProcess(-1); | 197 | processController->updateOrAddProcess(-1); | ||
198 | } | 198 | } | ||
199 | | ||||
199 | void testProcess::testHistoriesWithWidget() { | 200 | void testProcess::testHistoriesWithWidget() { | ||
200 | KSysGuardProcessList *processList = new KSysGuardProcessList; | 201 | KSysGuardProcessList *processList = new KSysGuardProcessList; | ||
201 | processList->treeView()->setColumnHidden(13, false); | 202 | processList->treeView()->setColumnHidden(13, false); | ||
202 | processList->show(); | 203 | processList->show(); | ||
203 | QTest::qWaitForWindowExposed(processList); | 204 | QTest::qWaitForWindowExposed(processList); | ||
204 | KSysGuard::Processes *processController = processList->processModel()->processController(); | 205 | KSysGuard::Processes *processController = processList->processModel()->processController(); | ||
205 | 206 | | |||
206 | QList< QPair<QDateTime, uint> > history = processController->historiesAvailable(); | 207 | QList< QPair<QDateTime, uint> > history = processController->historiesAvailable(); | ||
207 | 208 | | |||
208 | for(int i = 0; i < history.size(); i++) { | 209 | for(int i = 0; i < history.size(); i++) { | ||
209 | qCDebug(LIBKSYSGUARD) << "Viewing time" << history[i].first; | 210 | qCDebug(LIBKSYSGUARD) << "Viewing time" << history[i].first; | ||
210 | bool success = processController->setViewingTime(history[i].first); | 211 | bool success = processController->setViewingTime(history[i].first); | ||
211 | QVERIFY(success); | 212 | QVERIFY(success); | ||
212 | QCOMPARE(processController->viewingTime(), history[i].first); | 213 | QCOMPARE(processController->viewingTime(), history[i].first); | ||
213 | processList->updateList(); | 214 | processList->updateList(); | ||
214 | QTest::qWait(100); | 215 | QTest::qWait(100); | ||
215 | } | 216 | } | ||
216 | delete processList; | 217 | delete processList; | ||
217 | } | 218 | } | ||
219 | | ||||
220 | void testProcess::testCPUGraphHistory() { | ||||
221 | KSysGuardProcessList *processList = new KSysGuardProcessList; | ||||
broulik: This leaks (note how the other tests delete it afterwards), or wrap it in a `QScopedPointer` | |||||
222 | processList->show(); | ||||
223 | QTest::qWaitForWindowExposed(processList); | ||||
224 | auto model = processList->processModel(); | ||||
225 | // Access the PercentageHistoryRole to enable collection | ||||
226 | for(int i = 0; i < model->rowCount({}); i++) { | ||||
broulik: `rowCount()` already has a default argument for `index` | |||||
227 | auto index = model->index(i, ProcessModel::HeadingCPUUsage, {}); | ||||
228 | auto percentageHist = index.data(ProcessModel::PercentageHistoryRole).value<QVector<ProcessModel::PercentageHistoryEntry>>(); | ||||
229 | } | ||||
230 | | ||||
231 | processList->updateList(); | ||||
232 | | ||||
233 | // Verify that the current value is the newest history entry | ||||
234 | for(int i = 0; i < model->rowCount({}); i++) { | ||||
235 | auto index = model->index(i, ProcessModel::HeadingCPUUsage, {}); | ||||
236 | auto percentage = index.data(ProcessModel::PercentageRole).toFloat(); | ||||
237 | auto percentageHist = index.data(ProcessModel::PercentageHistoryRole).value<QVector<ProcessModel::PercentageHistoryEntry>>(); | ||||
238 | QVERIFY(percentageHist.size() > 0); | ||||
239 | QCOMPARE(percentage, percentageHist.constLast().value); | ||||
240 | } | ||||
241 | } | ||||
242 | | ||||
218 | QTEST_MAIN(testProcess) | 243 | QTEST_MAIN(testProcess) | ||
219 | 244 | | |||
220 | 245 | | |||
221 | 246 | |
This leaks (note how the other tests delete it afterwards), or wrap it in a QScopedPointer