Changeset View
Changeset View
Standalone View
Standalone View
autotests/server/itemretrievertest.cpp
Show First 20 Lines • Show All 294 Lines • ▼ Show 20 Line(s) | 291 | { | |||
---|---|---|---|---|---|
295 | QFETCH(int, expectedRetrievalJobs); | 295 | QFETCH(int, expectedRetrievalJobs); | ||
296 | QFETCH(int, expectedSignals); | 296 | QFETCH(int, expectedSignals); | ||
297 | QFETCH(int, expectedParts); | 297 | QFETCH(int, expectedParts); | ||
298 | 298 | | |||
299 | 299 | | |||
300 | // Setup | 300 | // Setup | ||
301 | for (int step = 0; step < 2; ++step) { | 301 | for (int step = 0; step < 2; ++step) { | ||
302 | DbInitializer dbInitializer; | 302 | DbInitializer dbInitializer; | ||
303 | FakeItemRetrievalJobFactory factory(dbInitializer); | 303 | auto *factory = new FakeItemRetrievalJobFactory(dbInitializer); | ||
304 | ItemRetrievalManager mgr(&factory); | 304 | ItemRetrievalManager mgr{std::unique_ptr<AbstractItemRetrievalJobFactory>(factory)}; | ||
305 | QTest::qWait(100); | 305 | QTest::qWait(100); | ||
306 | 306 | | |||
307 | // Given a PimItem with existing parts | 307 | // Given a PimItem with existing parts | ||
308 | Resource res = dbInitializer.createResource("testresource"); | 308 | Resource res = dbInitializer.createResource("testresource"); | ||
309 | Collection col = dbInitializer.createCollection("col1"); | 309 | Collection col = dbInitializer.createCollection("col1"); | ||
310 | 310 | | |||
311 | // step 0: do it in the main thread, for easier debugging | 311 | // step 0: do it in the main thread, for easier debugging | ||
312 | PimItem item = dbInitializer.createItem("1", col); | 312 | PimItem item = dbInitializer.createItem("1", col); | ||
313 | Q_FOREACH (const auto &existingPart, existingParts) { | 313 | Q_FOREACH (const auto &existingPart, existingParts) { | ||
314 | dbInitializer.createPart(item.id(), existingPart.first, existingPart.second); | 314 | dbInitializer.createPart(item.id(), existingPart.first, existingPart.second); | ||
315 | } | 315 | } | ||
316 | 316 | | |||
317 | Q_FOREACH (const auto &availablePart, availableParts) { | 317 | Q_FOREACH (const auto &availablePart, availableParts) { | ||
318 | factory.addJobResult(item.id(), availablePart.first, availablePart.second); | 318 | factory->addJobResult(item.id(), availablePart.first, availablePart.second); | ||
319 | } | 319 | } | ||
320 | 320 | | |||
321 | if (step == 0) { | 321 | if (step == 0) { | ||
322 | ClientThread thread(item.id(), requestedParts); | 322 | ClientThread thread(item.id(), requestedParts); | ||
323 | thread.run(); | 323 | thread.run(); | ||
324 | 324 | | |||
325 | const ClientThread::Results results = thread.results(); | 325 | const ClientThread::Results results = thread.results(); | ||
326 | // ItemRetriever should ... succeed | 326 | // ItemRetriever should ... succeed | ||
327 | QVERIFY(results.success); | 327 | QVERIFY(results.success); | ||
328 | // Emit exactly one signal ... | 328 | // Emit exactly one signal ... | ||
329 | QCOMPARE(results.signalsCount, expectedSignals); | 329 | QCOMPARE(results.signalsCount, expectedSignals); | ||
330 | // ... with that one item | 330 | // ... with that one item | ||
331 | if (expectedSignals > 0) { | 331 | if (expectedSignals > 0) { | ||
332 | QCOMPARE(results.emittedItems, QList<qint64>{ item.id() }); | 332 | QCOMPARE(results.emittedItems, QList<qint64>{ item.id() }); | ||
333 | } | 333 | } | ||
334 | 334 | | |||
335 | // Check that the factory had exactly one retrieval job | 335 | // Check that the factory had exactly one retrieval job | ||
336 | QCOMPARE(factory.jobsCount(), expectedRetrievalJobs); | 336 | QCOMPARE(factory->jobsCount(), expectedRetrievalJobs); | ||
337 | 337 | | |||
338 | } else { | 338 | } else { | ||
339 | QVector<ClientThread *> threads; | 339 | QVector<ClientThread *> threads; | ||
340 | for (int i = 0; i < 20; ++i) { | 340 | for (int i = 0; i < 20; ++i) { | ||
341 | threads.append(new ClientThread(item.id(), requestedParts)); | 341 | threads.append(new ClientThread(item.id(), requestedParts)); | ||
342 | } | 342 | } | ||
343 | for (int i = 0; i < threads.size(); ++i) { | 343 | for (int i = 0; i < threads.size(); ++i) { | ||
344 | threads.at(i)->start(); | 344 | threads.at(i)->start(); | ||
▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines |