File: qcorowaitfor.cpp

package info (click to toggle)
qcoro 0.12.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,700 kB
  • sloc: cpp: 8,573; python: 32; xml: 26; makefile: 23; sh: 15
file content (62 lines) | stat: -rw-r--r-- 1,517 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// SPDX-FileCopyrightText: 2024 Joey Richey <joey@dogsplayingpoker.org>
//
// SPDX-License-Identifier: MIT

#include "testobject.h"

#include "qcorotimer.h"

#include <chrono>

class QCoroWaitForTest : public QCoro::TestObject<QCoroWaitForTest> {
    Q_OBJECT

private:
    QCoro::Task<void> testPrimitiveType_coro(QCoro::TestContext ctx)
    {
        ctx.setShouldNotSuspend();
        auto task_test = []() -> QCoro::Task<int> {
            co_return 7;
        };

        const int ret = QCoro::waitFor(task_test());
        QCORO_VERIFY(ret == 7);
    }

    QCoro::Task<void> testDefaultConstructible_coro(QCoro::TestContext ctx)
    {
        ctx.setShouldNotSuspend();
        auto task_test = []() -> QCoro::Task<std::string> {
            co_return "seven";
        };

        const std::string ret = QCoro::waitFor(task_test());
        QCORO_VERIFY(ret == "seven");
    }

    QCoro::Task<void> testNonDefaultConstructible_coro(QCoro::TestContext ctx)
    {
        ctx.setShouldNotSuspend();

        struct test_struct {
            explicit test_struct(int i_) : i(i_) {}
            int i;
        };

        auto task_test = []() -> QCoro::Task<test_struct> {
            co_return test_struct(7);
        };

        const test_struct ret = QCoro::waitFor(task_test());
        QCORO_VERIFY(ret.i == 7);
    }

private Q_SLOTS:
    addTest(PrimitiveType)
    addTest(DefaultConstructible)
    addTest(NonDefaultConstructible)
};

QTEST_GUILESS_MAIN(QCoroWaitForTest)

#include "qcorowaitfor.moc"