1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB). |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt3D module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | #include <QtTest/QtTest> |
30 | #include <Qt3DCore/qaspectjob.h> |
31 | |
32 | using namespace Qt3DCore; |
33 | |
34 | class FakeAspectJob : public QAspectJob |
35 | { |
36 | public: |
37 | void run() override {} |
38 | }; |
39 | |
40 | class tst_QAspectJob : public QObject |
41 | { |
42 | Q_OBJECT |
43 | private Q_SLOTS: |
44 | void shouldAddDependencies() |
45 | { |
46 | // GIVEN |
47 | QAspectJobPtr job1(new FakeAspectJob); |
48 | QAspectJobPtr job2(new FakeAspectJob); |
49 | QAspectJobPtr job3(new FakeAspectJob); |
50 | |
51 | // THEN |
52 | QVERIFY(job1->dependencies().isEmpty()); |
53 | QVERIFY(job2->dependencies().isEmpty()); |
54 | QVERIFY(job3->dependencies().isEmpty()); |
55 | |
56 | // WHEN |
57 | job1->addDependency(dependency: job2); |
58 | job1->addDependency(dependency: job3); |
59 | |
60 | // THEN |
61 | QCOMPARE(job1->dependencies().size(), 2); |
62 | QCOMPARE(job1->dependencies().at(0).lock(), job2); |
63 | QCOMPARE(job1->dependencies().at(1).lock(), job3); |
64 | QVERIFY(job2->dependencies().isEmpty()); |
65 | QVERIFY(job3->dependencies().isEmpty()); |
66 | } |
67 | |
68 | void shouldRemoveDependencies() |
69 | { |
70 | // GIVEN |
71 | QAspectJobPtr job1(new FakeAspectJob); |
72 | QAspectJobPtr job2(new FakeAspectJob); |
73 | QAspectJobPtr job3(new FakeAspectJob); |
74 | |
75 | job1->addDependency(dependency: job2); |
76 | job1->addDependency(dependency: job3); |
77 | |
78 | // WHEN |
79 | job1->removeDependency(dependency: job2); |
80 | |
81 | // THEN |
82 | QCOMPARE(job1->dependencies().size(), 1); |
83 | QCOMPARE(job1->dependencies().at(0).lock(), job3); |
84 | } |
85 | |
86 | void shouldClearNullDependencies() |
87 | { |
88 | // GIVEN |
89 | QAspectJobPtr job1(new FakeAspectJob); |
90 | QAspectJobPtr job2(new FakeAspectJob); |
91 | QAspectJobPtr job3(new FakeAspectJob); |
92 | |
93 | job1->addDependency(dependency: job2); |
94 | job1->addDependency(dependency: job3); |
95 | |
96 | // WHEN |
97 | job2.clear(); |
98 | job1->removeDependency(dependency: QWeakPointer<QAspectJob>()); |
99 | |
100 | // THEN |
101 | QCOMPARE(job1->dependencies().size(), 1); |
102 | QCOMPARE(job1->dependencies().at(0).lock(), job3); |
103 | } |
104 | }; |
105 | |
106 | QTEST_MAIN(tst_QAspectJob) |
107 | |
108 | #include "tst_qaspectjob.moc" |
109 | |