1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Data Visualization module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL$
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 or (at your option) any later version
20** approved by the KDE Free Qt Foundation. The licenses are as published by
21** the Free Software Foundation and appearing in the file LICENSE.GPL3
22** included in the packaging of this file. Please review the following
23** information to ensure the GNU General Public License requirements will
24** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25**
26** $QT_END_LICENSE$
27**
28****************************************************************************/
29
30#include <QtTest/QtTest>
31
32#include <QtDataVisualization/QCustom3DLabel>
33
34#include "cpptestutil.h"
35
36using namespace QtDataVisualization;
37
38class tst_custom: public QObject
39{
40 Q_OBJECT
41
42private slots:
43 void initTestCase();
44 void cleanupTestCase();
45 void init();
46 void cleanup();
47
48 void construct();
49
50 void initialProperties();
51 void initializeProperties();
52 void invalidProperties();
53
54private:
55 QCustom3DLabel *m_custom;
56};
57
58void tst_custom::initTestCase()
59{
60 if (!CpptestUtil::isOpenGLSupported())
61 QSKIP("OpenGL not supported on this platform");
62}
63
64void tst_custom::cleanupTestCase()
65{
66}
67
68void tst_custom::init()
69{
70 m_custom = new QCustom3DLabel();
71}
72
73void tst_custom::cleanup()
74{
75 delete m_custom;
76}
77
78void tst_custom::construct()
79{
80 QCustom3DLabel *custom = new QCustom3DLabel();
81 QVERIFY(custom);
82 delete custom;
83
84 custom = new QCustom3DLabel("label", QFont("Times New Roman", 10.0), QVector3D(1.0, 1.0, 1.0),
85 QVector3D(1.0, 1.0, 1.0), QQuaternion(1.0, 1.0, 10.0, 100.0));
86 QVERIFY(custom);
87 QCOMPARE(custom->backgroundColor(), QColor(Qt::gray));
88 QCOMPARE(custom->isBackgroundEnabled(), true);
89 QCOMPARE(custom->isBorderEnabled(), true);
90 QCOMPARE(custom->isFacingCamera(), false);
91 QCOMPARE(custom->font(), QFont("Times New Roman", 10));
92 QCOMPARE(custom->text(), QString("label"));
93 QCOMPARE(custom->textColor(), QColor(Qt::white));
94 QCOMPARE(custom->meshFile(), QString(":/defaultMeshes/plane"));
95 QCOMPARE(custom->position(), QVector3D(1.0, 1.0, 1.0));
96 QCOMPARE(custom->isPositionAbsolute(), false);
97 QCOMPARE(custom->rotation(), QQuaternion(1.0, 1.0, 10.0, 100.0));
98 QCOMPARE(custom->scaling(), QVector3D(1.0, 1.0, 1.0));
99 QCOMPARE(custom->isScalingAbsolute(), true);
100 QCOMPARE(custom->isShadowCasting(), false);
101 QCOMPARE(custom->textureFile(), QString());
102 QCOMPARE(custom->isVisible(), true);
103 delete custom;
104}
105
106void tst_custom::initialProperties()
107{
108 QVERIFY(m_custom);
109
110 QCOMPARE(m_custom->backgroundColor(), QColor(Qt::gray));
111 QCOMPARE(m_custom->isBackgroundEnabled(), true);
112 QCOMPARE(m_custom->isBorderEnabled(), true);
113 QCOMPARE(m_custom->isFacingCamera(), false);
114 QCOMPARE(m_custom->font(), QFont("Arial", 20));
115 QCOMPARE(m_custom->text(), QString());
116 QCOMPARE(m_custom->textColor(), QColor(Qt::white));
117
118 // Common (from QCustom3DItem)
119 QCOMPARE(m_custom->meshFile(), QString(":/defaultMeshes/plane"));
120 QCOMPARE(m_custom->position(), QVector3D());
121 QCOMPARE(m_custom->isPositionAbsolute(), false);
122 QCOMPARE(m_custom->rotation(), QQuaternion());
123 QCOMPARE(m_custom->scaling(), QVector3D(0.1f, 0.1f, 0.1f));
124 QCOMPARE(m_custom->isScalingAbsolute(), true);
125 QCOMPARE(m_custom->isShadowCasting(), false);
126 QCOMPARE(m_custom->textureFile(), QString());
127 QCOMPARE(m_custom->isVisible(), true);
128}
129
130void tst_custom::initializeProperties()
131{
132 QVERIFY(m_custom);
133
134 m_custom->setBackgroundColor(QColor(Qt::red));
135 m_custom->setBackgroundEnabled(false);
136 m_custom->setBorderEnabled(false);
137 m_custom->setFacingCamera(true);
138 m_custom->setFont(QFont("Times New Roman", 10));
139 m_custom->setText(QString("This is a Custom Label"));
140 m_custom->setTextColor(QColor(Qt::blue));
141
142 QCOMPARE(m_custom->backgroundColor(), QColor(Qt::red));
143 QCOMPARE(m_custom->isBackgroundEnabled(), false);
144 QCOMPARE(m_custom->isBorderEnabled(), false);
145 QCOMPARE(m_custom->isFacingCamera(), true);
146 QCOMPARE(m_custom->font(), QFont("Times New Roman", 10));
147 QCOMPARE(m_custom->text(), QString("This is a Custom Label"));
148 QCOMPARE(m_custom->textColor(), QColor(Qt::blue));
149
150 // Common (from QCustom3DItem)
151 m_custom->setPosition(QVector3D(1.0, 1.0, 1.0));
152 m_custom->setPositionAbsolute(true);
153 m_custom->setRotation(QQuaternion(1.0, 1.0, 10.0, 100.0));
154 m_custom->setScaling(QVector3D(1.0, 1.0, 1.0));
155 m_custom->setShadowCasting(true);
156 m_custom->setVisible(false);
157
158 QCOMPARE(m_custom->position(), QVector3D(1.0, 1.0, 1.0));
159 QCOMPARE(m_custom->isPositionAbsolute(), true);
160 QCOMPARE(m_custom->rotation(), QQuaternion(1.0, 1.0, 10.0, 100.0));
161 QCOMPARE(m_custom->scaling(), QVector3D(1.0, 1.0, 1.0));
162 QCOMPARE(m_custom->isShadowCasting(), true);
163 QCOMPARE(m_custom->isVisible(), false);
164}
165
166void tst_custom::invalidProperties()
167{
168 m_custom->setScalingAbsolute(false);
169 QCOMPARE(m_custom->isScalingAbsolute(), true);
170}
171
172QTEST_MAIN(tst_custom)
173#include "tst_custom.moc"
174

source code of qtdatavis3d/tests/auto/cpptest/q3dcustom-label/tst_custom.cpp