1/****************************************************************************
2**
3** Copyright (C) 2014 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/private/qhandle_p.h>
31#include <Qt3DCore/private/qresourcemanager_p.h>
32
33class tst_Handle : public QObject
34{
35 Q_OBJECT
36public:
37 tst_Handle() {}
38 ~tst_Handle() {}
39
40private slots:
41 void defaultConstruction();
42 void construction();
43 void copyConstruction();
44 void assignment();
45 void equality();
46 void inequality();
47};
48
49class SimpleResource
50{
51public:
52 SimpleResource()
53 : m_value(0)
54 {}
55
56 int m_value;
57};
58
59typedef Qt3DCore::QHandle<SimpleResource> Handle;
60typedef Qt3DCore::QHandleData<SimpleResource> HandleData;
61
62void tst_Handle::defaultConstruction()
63{
64 Handle h;
65 QVERIFY(h.isNull() == true);
66 QVERIFY(h.handle() == 0);
67}
68
69void tst_Handle::construction()
70{
71 HandleData d;
72 Handle h(&d);
73 QVERIFY(h.isNull() == false);
74 qDebug() << h;
75 QVERIFY(h.handle() == reinterpret_cast<quintptr>(&d));
76}
77
78void tst_Handle::copyConstruction()
79{
80 HandleData d;
81 Handle h(&d);
82 Handle h2(h);
83 QVERIFY(h2.isNull() == false);
84 QVERIFY(h2.handle() == h.handle());
85}
86
87void tst_Handle::assignment()
88{
89 HandleData d;
90 Handle h(&d);
91 Handle h2;
92 h2 = h;
93 QVERIFY(h2.isNull() == false);
94 QVERIFY(h2.handle() == h.handle());
95}
96
97void tst_Handle::equality()
98{
99 HandleData d;
100 Handle h1(&d);
101 Handle h2(&d);
102 QVERIFY(h1.isNull() == false);
103 QVERIFY(h1 == h2);
104}
105
106void tst_Handle::inequality()
107{
108 HandleData d1;
109 HandleData d2;
110 Handle h1(&d1);
111 Handle h2(&d2);
112 QVERIFY(h1.isNull() == false);
113 QVERIFY(h1 != h2);
114}
115
116QTEST_APPLESS_MAIN(tst_Handle)
117
118#include "tst_handle.moc"
119

source code of qt3d/tests/auto/core/handle/tst_handle.cpp