summaryrefslogtreecommitdiffstats
path: root/tests/auto/render
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire350@gmail.com>2016-05-14 15:37:51 +0200
committerSean Harmer <sean.harmer@kdab.com>2016-07-02 19:41:52 +0000
commit8117a5ac8be8fd80c5db3f426b2378823cb25353 (patch)
tree813bcb24e7ce2b0e0d9c7010e9802d537315ce36 /tests/auto/render
parent88c35fe1aec9c074bd18dde6420026212ae3382a (diff)
Unit tests for GenericLambdaJob
Change-Id: Ia247a8f022ca1aa0108398bca7b8e5023070727e Reviewed-by: Paul Lemire <paul.lemire@kdab.com> Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'tests/auto/render')
-rw-r--r--tests/auto/render/genericlambdajob/genericlambdajob.pro11
-rw-r--r--tests/auto/render/genericlambdajob/tst_genericlambdajob.cpp105
-rw-r--r--tests/auto/render/render.pro3
3 files changed, 118 insertions, 1 deletions
diff --git a/tests/auto/render/genericlambdajob/genericlambdajob.pro b/tests/auto/render/genericlambdajob/genericlambdajob.pro
new file mode 100644
index 000000000..d4b628688
--- /dev/null
+++ b/tests/auto/render/genericlambdajob/genericlambdajob.pro
@@ -0,0 +1,11 @@
+TEMPLATE = app
+
+TARGET = tst_genericlambdajob
+
+QT += core-private 3dcore 3dcore-private 3drender 3drender-private testlib
+
+CONFIG += testcase
+
+SOURCES += tst_genericlambdajob.cpp
+
+include(../commons/commons.pri)
diff --git a/tests/auto/render/genericlambdajob/tst_genericlambdajob.cpp b/tests/auto/render/genericlambdajob/tst_genericlambdajob.cpp
new file mode 100644
index 000000000..ccdd43a02
--- /dev/null
+++ b/tests/auto/render/genericlambdajob/tst_genericlambdajob.cpp
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Paul Lemire
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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"
diff --git a/tests/auto/render/render.pro b/tests/auto/render/render.pro
index 6760197e3..be5a39d2c 100644
--- a/tests/auto/render/render.pro
+++ b/tests/auto/render/render.pro
@@ -47,5 +47,6 @@ contains(QT_CONFIG, private_tests) {
ddstextures \
shadercache \
layerfiltering \
- filterentitybycomponent
+ filterentitybycomponent \
+ genericlambdajob
}