Debian Codegraph @

tests/auto/render/genericlambdajob/tst_genericlambdajob.cpp

raw symbols SCIP
1 // Copyright (C) 2016 Paul Lemire
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 #include <QtTest/QTest>
5 #include <Qt3DRender/private/genericlambdajob_p.h>
6 #include <functional>
7
8 namespace {
9
10 int randomTestValue = 0;
11
12 void freeStandingFunction()
13 {
14 randomTestValue = 883;
15 }
16
17 } // anonymous
18
19 class tst_GenericLambdaJob : public QObject
20 {
21 Q_OBJECT
22 private Q_SLOTS:
23 void lambdaTest()
24 {
25 // GIVEN
26 int a = 0;
27 auto incremeneterLambda = [&] () { ++a; };
28 Qt3DRender::Render::GenericLambdaJob<decltype(incremeneterLambda)> job(incremeneterLambda);
29
30 // THEN
31 QCOMPARE(a, 0);
32
33 // WHEN
34 job.run();
35
36 // THEN
37 QCOMPARE(a, 1);
38
39 // WHEN
40 job.run();
41 QCOMPARE(a, 2);
42 }
43
44 void functionTest()
45 {
46 // GIVEN
47 Qt3DRender::Render::GenericLambdaJob<decltype(&freeStandingFunction)> job(&freeStandingFunction);
48
49 // THEN
50 QCOMPARE(randomTestValue, 0);
51
52 // WHEN
53 job.run();
54
55 // THEN
56 QCOMPARE(randomTestValue, 883);
57 }
58
59 void stdFunctionTest()
60 {
61 // GIVEN
62 int u = 1584;
63 auto decrementerLambda = [&] () { u = 0; };
64 std::function<void ()> func = decrementerLambda;
65 Qt3DRender::Render::GenericLambdaJob<decltype(func)> job(func);
66
67 // THEN
68 QCOMPARE(u, 1584);
69
70 // WHEN
71 job.run();
72
73 // THEN
74 QCOMPARE(u, 0);
75 }
76 };
77
78 QTEST_APPLESS_MAIN(tst_GenericLambdaJob)
79
80 #include "tst_genericlambdajob.moc"