blob: cb113091fd55e56fe98da9e8f9742b67138e2587 (
plain)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
// Copyright (C) 2016 Paul Lemire
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QtTest/QTest>
#include <Qt3DRender/private/genericlambdajob_p.h>
#include <functional>
namespace {
int randomTestValue = 0;
void freeStandingFunction()
{
randomTestValue = 883;
}
} // anonymous
class tst_GenericLambdaJob : public QObject
{
Q_OBJECT
private Q_SLOTS:
void lambdaTest()
{
// GIVEN
int a = 0;
auto incremeneterLambda = [&] () { ++a; };
Qt3DRender::Render::GenericLambdaJob<decltype(incremeneterLambda)> job(incremeneterLambda);
// THEN
QCOMPARE(a, 0);
// WHEN
job.run();
// THEN
QCOMPARE(a, 1);
// WHEN
job.run();
QCOMPARE(a, 2);
}
void functionTest()
{
// GIVEN
Qt3DRender::Render::GenericLambdaJob<decltype(&freeStandingFunction)> job(&freeStandingFunction);
// THEN
QCOMPARE(randomTestValue, 0);
// WHEN
job.run();
// THEN
QCOMPARE(randomTestValue, 883);
}
void stdFunctionTest()
{
// GIVEN
int u = 1584;
auto decrementerLambda = [&] () { u = 0; };
std::function<void ()> func = decrementerLambda;
Qt3DRender::Render::GenericLambdaJob<decltype(func)> job(func);
// THEN
QCOMPARE(u, 1584);
// WHEN
job.run();
// THEN
QCOMPARE(u, 0);
}
};
QTEST_APPLESS_MAIN(tst_GenericLambdaJob)
#include "tst_genericlambdajob.moc"
|