LeechCraft
0.6.70-18450-gabe19ee3b0
Modular cross-platform feature rich live environment.
Toggle main menu visibility
Loading...
Searching...
No Matches
coroeithertest.cpp
Go to the documentation of this file.
1
/**********************************************************************
2
* LeechCraft - modular cross-platform feature rich internet client.
3
* Copyright (C) 2006-2014 Georg Rudoy
4
*
5
* Distributed under the Boost Software License, Version 1.0.
6
* (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7
**********************************************************************/
8
9
#include "
coroeithertest.h
"
10
#include <QtTest>
11
#include <
util/sll/qtutil.h
>
12
#include <
util/threads/coro.h
>
13
#include <
util/threads/coro/eithercoro.h
>
14
15
QTEST_GUILESS_MAIN (
LC::Util::CoroEitherTest
)
16
17
namespace
LC::Util
18
{
19
using
Ty
=
Either<char, int>
;
20
21
void
CoroEitherTest::testSuccess ()
22
{
23
auto
action = [] ->
Ty
24
{
25
auto
n =
co_await
Ty
{ 3 };
26
auto
m =
co_await
Ty
{ 5 };
27
co_return
n * m;
28
};
29
QCOMPARE (action (), 15);
30
}
31
32
void
CoroEitherTest::testFailure ()
33
{
34
auto
action = [] ->
Ty
35
{
36
auto
m =
co_await
Ty
{ 3 };
37
auto
n =
co_await
Ty
{
AsLeft
,
'a'
};
38
auto
k =
co_await
Ty
{
AsLeft
,
'b'
};
39
co_return
n * m * k;
40
};
41
QCOMPARE (action (), (
Ty
{
AsLeft
,
'a'
}));
42
}
43
44
void
CoroEitherTest::testException ()
45
{
46
auto
action = [] ->
Ty
47
{
48
auto
m =
co_await
Ty
{ 3 };
49
auto
n =
co_await
[] ->
Ty
{
throw
std::runtime_error {
"err"
}; } ();
50
auto
k =
co_await
Ty
{
AsLeft
,
'a'
};
51
co_return
n * m * k;
52
};
53
QVERIFY_THROWS_EXCEPTION (std::runtime_error, action ());
54
}
55
56
void
CoroEitherTest::testSuccessAllocating ()
57
{
58
using
AllocTy = Either<QByteArray, QString>;
59
60
auto
action = [] -> AllocTy
61
{
62
const
auto
& s1 =
co_await
AllocTy { QString {
"foo"
} };
63
const
auto
& s2 =
co_await
AllocTy { QString {
"bar"
} };
64
co_return
s1 + s2;
65
};
66
QCOMPARE (action (),
"foobar"
_qs);
67
}
68
}
LC::Util::CoroEitherTest
Definition
coroeithertest.h:16
LC::Util::Either
Definition
either.h:33
coro.h
coroeithertest.h
eithercoro.h
LC::Util
Definition
icoreproxy.h:34
LC::Util::AsLeft
constexpr auto AsLeft
Definition
either.h:27
LC::Util::Ty
Either< char, int > Ty
Definition
coroeithertest.cpp:19
qtutil.h
src
util
threads
tests
coroeithertest.cpp
Generated by
1.17.0