swift
testworker.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2017 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
11 #include <QObject>
12 #include <QTest>
13 
14 #include "misc/eventloop.h"
15 #include "misc/worker.h"
16 
17 using namespace swift::misc;
18 
19 namespace MiscTest
20 {
22  class CTestWorker : public QObject
23  {
24  Q_OBJECT
25 
26  public:
28  explicit CTestWorker(QObject *parent = nullptr);
29 
30  private slots:
32  void singleShot();
33  };
34 
35  CTestWorker::CTestWorker(QObject *parent) : QObject(parent)
36  {
37  // void
38  }
39 
40  void CTestWorker::singleShot()
41  {
42  QFuture<int> future = swift::misc::singleShot(0, this, []() { return 123; });
43  CEventLoop::processEventsFor(0);
44  QVERIFY2(future.isFinished(), "Future is finished after slot has returned");
45  QVERIFY2(future.result() == 123, "Future provides access to slot's return value");
46  }
47 
48 } // namespace MiscTest
49 
52 
53 #include "testworker.moc"
54 
Aviation classes basic tests.
Definition: testworker.cpp:23
Free functions in swift::misc.
auto singleShot(int msec, QObject *target, F &&task)
Starts a single-shot timer which will call a task in the thread of the given object when it times out...
Definition: threadutils.h:30
SWIFTTEST_APPLESS_MAIN(MiscTest::CTestWorker)
main