| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2019 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/QTest> | 
| 30 | #include <Qt3DRender/qtexturedataupdate.h> | 
| 31 | #include <Qt3DRender/qabstracttexture.h> | 
| 32 | #include <Qt3DRender/qtextureimagedata.h> | 
| 33 |  | 
| 34 | class tst_QTextureDataUpdate : public QObject | 
| 35 | { | 
| 36 |     Q_OBJECT | 
| 37 |  | 
| 38 | private Q_SLOTS: | 
| 39 |  | 
| 40 |     void checkDefaultConstruction() | 
| 41 |     { | 
| 42 |         // GIVEN | 
| 43 |         Qt3DRender::QTextureDataUpdate textureUpdate; | 
| 44 |  | 
| 45 |         // THEN | 
| 46 |         QCOMPARE(textureUpdate.x(), 0); | 
| 47 |         QCOMPARE(textureUpdate.y(), 0); | 
| 48 |         QCOMPARE(textureUpdate.z(), 0); | 
| 49 |         QCOMPARE(textureUpdate.layer(), 0); | 
| 50 |         QCOMPARE(textureUpdate.mipLevel(), 0); | 
| 51 |         QCOMPARE(textureUpdate.face(), Qt3DRender::QAbstractTexture::CubeMapPositiveX); | 
| 52 |         QVERIFY(textureUpdate.data().isNull()); | 
| 53 |     } | 
| 54 |  | 
| 55 |     void checkSettersAndGetters() | 
| 56 |     { | 
| 57 |         // GIVEN | 
| 58 |         Qt3DRender::QTextureDataUpdate textureUpdate; | 
| 59 |  | 
| 60 |         // WHEN | 
| 61 |         textureUpdate.setX(883); | 
| 62 |  | 
| 63 |         // THEN | 
| 64 |         QCOMPARE(textureUpdate.x(), 883); | 
| 65 |  | 
| 66 |         // WHEN | 
| 67 |         textureUpdate.setY(1340); | 
| 68 |         // THEN | 
| 69 |         QCOMPARE(textureUpdate.y(), 1340); | 
| 70 |  | 
| 71 |         // WHEN | 
| 72 |         textureUpdate.setZ(1584); | 
| 73 |  | 
| 74 |         // THEN | 
| 75 |         QCOMPARE(textureUpdate.z(), 1584); | 
| 76 |  | 
| 77 |         // WHEN | 
| 78 |         textureUpdate.setLayer(454); | 
| 79 |  | 
| 80 |         // THEN | 
| 81 |         QCOMPARE(textureUpdate.layer(), 454); | 
| 82 |  | 
| 83 |         // WHEN | 
| 84 |         textureUpdate.setMipLevel(350); | 
| 85 |         // THEN | 
| 86 |         QCOMPARE(textureUpdate.mipLevel(), 350); | 
| 87 |  | 
| 88 |         // WHEN | 
| 89 |         textureUpdate.setFace(Qt3DRender::QAbstractTexture::CubeMapNegativeZ); | 
| 90 |  | 
| 91 |         // THEN | 
| 92 |         QCOMPARE(textureUpdate.face(), Qt3DRender::QAbstractTexture::CubeMapNegativeZ); | 
| 93 |  | 
| 94 |         // WHEN | 
| 95 |         Qt3DRender::QTextureImageDataPtr imgData = Qt3DRender::QTextureImageDataPtr::create(); | 
| 96 |         textureUpdate.setData(imgData); | 
| 97 |  | 
| 98 |         // THEN | 
| 99 |         QCOMPARE(textureUpdate.data(), imgData); | 
| 100 |     } | 
| 101 |  | 
| 102 |     void checkCopyConstruction() | 
| 103 |     { | 
| 104 |         // GIVEN | 
| 105 |         Qt3DRender::QTextureDataUpdate textureUpdate; | 
| 106 |         textureUpdate.setX(883); | 
| 107 |         textureUpdate.setY(1340); | 
| 108 |         textureUpdate.setZ(1584); | 
| 109 |         textureUpdate.setLayer(454); | 
| 110 |         textureUpdate.setMipLevel(350); | 
| 111 |         textureUpdate.setFace(Qt3DRender::QAbstractTexture::CubeMapNegativeZ); | 
| 112 |         Qt3DRender::QTextureImageDataPtr imgData = Qt3DRender::QTextureImageDataPtr::create(); | 
| 113 |         textureUpdate.setData(imgData); | 
| 114 |  | 
| 115 |         // WHEN | 
| 116 |         Qt3DRender::QTextureDataUpdate textureUpdateCpy(textureUpdate); | 
| 117 |  | 
| 118 |         // THEN | 
| 119 |         QCOMPARE(textureUpdateCpy.x(), 883); | 
| 120 |         QCOMPARE(textureUpdateCpy.y(), 1340); | 
| 121 |         QCOMPARE(textureUpdateCpy.z(), 1584); | 
| 122 |         QCOMPARE(textureUpdateCpy.layer(), 454); | 
| 123 |         QCOMPARE(textureUpdateCpy.mipLevel(), 350); | 
| 124 |         QCOMPARE(textureUpdateCpy.face(), Qt3DRender::QAbstractTexture::CubeMapNegativeZ); | 
| 125 |         QCOMPARE(textureUpdateCpy.data(), imgData); | 
| 126 |     } | 
| 127 |  | 
| 128 |     void checkAssigment() | 
| 129 |     { | 
| 130 |         // GIVEN | 
| 131 |         Qt3DRender::QTextureDataUpdate textureUpdate; | 
| 132 |         Qt3DRender::QTextureDataUpdate textureUpdateAssign; | 
| 133 |         textureUpdate.setX(883); | 
| 134 |         textureUpdate.setY(1340); | 
| 135 |         textureUpdate.setZ(1584); | 
| 136 |         textureUpdate.setLayer(454); | 
| 137 |         textureUpdate.setMipLevel(350); | 
| 138 |         textureUpdate.setFace(Qt3DRender::QAbstractTexture::CubeMapNegativeZ); | 
| 139 |         Qt3DRender::QTextureImageDataPtr imgData = Qt3DRender::QTextureImageDataPtr::create(); | 
| 140 |         textureUpdate.setData(imgData); | 
| 141 |  | 
| 142 |         // WHEN | 
| 143 |         textureUpdateAssign = textureUpdate; | 
| 144 |  | 
| 145 |         // THEN | 
| 146 |         QCOMPARE(textureUpdateAssign.x(), 883); | 
| 147 |         QCOMPARE(textureUpdateAssign.y(), 1340); | 
| 148 |         QCOMPARE(textureUpdateAssign.z(), 1584); | 
| 149 |         QCOMPARE(textureUpdateAssign.layer(), 454); | 
| 150 |         QCOMPARE(textureUpdateAssign.mipLevel(), 350); | 
| 151 |         QCOMPARE(textureUpdateAssign.face(), Qt3DRender::QAbstractTexture::CubeMapNegativeZ); | 
| 152 |         QCOMPARE(textureUpdateAssign.data(), imgData); | 
| 153 |  | 
| 154 |         QCOMPARE(textureUpdateAssign.x(), textureUpdate.x()); | 
| 155 |         QCOMPARE(textureUpdateAssign.y(), textureUpdate.y()); | 
| 156 |         QCOMPARE(textureUpdateAssign.z(), textureUpdate.z()); | 
| 157 |         QCOMPARE(textureUpdateAssign.layer(), textureUpdate.layer()); | 
| 158 |         QCOMPARE(textureUpdateAssign.mipLevel(), textureUpdate.mipLevel()); | 
| 159 |         QCOMPARE(textureUpdateAssign.face(), textureUpdate.face()); | 
| 160 |         QCOMPARE(textureUpdateAssign.data(), textureUpdate.data()); | 
| 161 |     } | 
| 162 |  | 
| 163 |     void checkConversionToVariant() | 
| 164 |     { | 
| 165 |         // GIVEN | 
| 166 |         Qt3DRender::QTextureDataUpdate textureUpdate; | 
| 167 |         textureUpdate.setX(883); | 
| 168 |         textureUpdate.setY(1340); | 
| 169 |         textureUpdate.setZ(1584); | 
| 170 |         textureUpdate.setLayer(454); | 
| 171 |         textureUpdate.setMipLevel(350); | 
| 172 |         textureUpdate.setFace(Qt3DRender::QAbstractTexture::CubeMapNegativeZ); | 
| 173 |         Qt3DRender::QTextureImageDataPtr imgData = Qt3DRender::QTextureImageDataPtr::create(); | 
| 174 |         textureUpdate.setData(imgData); | 
| 175 |  | 
| 176 |         // WHEN | 
| 177 |         const QVariant v = QVariant::fromValue(value: textureUpdate); | 
| 178 |         const Qt3DRender::QTextureDataUpdate out = v.value<Qt3DRender::QTextureDataUpdate>(); | 
| 179 |  | 
| 180 |         // THEN | 
| 181 |         QCOMPARE(out.x(), 883); | 
| 182 |         QCOMPARE(out.y(), 1340); | 
| 183 |         QCOMPARE(out.z(), 1584); | 
| 184 |         QCOMPARE(out.layer(), 454); | 
| 185 |         QCOMPARE(out.mipLevel(), 350); | 
| 186 |         QCOMPARE(out.face(), Qt3DRender::QAbstractTexture::CubeMapNegativeZ); | 
| 187 |         QCOMPARE(out.data(), imgData); | 
| 188 |     } | 
| 189 |  | 
| 190 |     void checkComparison() | 
| 191 |     { | 
| 192 |         // GIVEN | 
| 193 |         Qt3DRender::QTextureDataUpdate textureUpdate1; | 
| 194 |         Qt3DRender::QTextureDataUpdate textureUpdate2; | 
| 195 |  | 
| 196 |         // THEN | 
| 197 |         QVERIFY(textureUpdate1 == textureUpdate2); | 
| 198 |         QVERIFY(!(textureUpdate1 != textureUpdate2)); | 
| 199 |  | 
| 200 |         // WHEN | 
| 201 |         textureUpdate1.setX(883); | 
| 202 |  | 
| 203 |         // THEN | 
| 204 |         QVERIFY(textureUpdate1 != textureUpdate2); | 
| 205 |  | 
| 206 |         // WHEN | 
| 207 |         textureUpdate2.setX(883); | 
| 208 |  | 
| 209 |         // THEN | 
| 210 |         QVERIFY(textureUpdate1 == textureUpdate2); | 
| 211 |  | 
| 212 |         // WHEN | 
| 213 |         textureUpdate1.setY(883); | 
| 214 |  | 
| 215 |         // THEN | 
| 216 |         QVERIFY(textureUpdate1 != textureUpdate2); | 
| 217 |  | 
| 218 |         // WHEN | 
| 219 |         textureUpdate2.setY(883); | 
| 220 |  | 
| 221 |         // THEN | 
| 222 |         QVERIFY(textureUpdate1 == textureUpdate2); | 
| 223 |  | 
| 224 |         // WHEN | 
| 225 |         textureUpdate1.setZ(883); | 
| 226 |  | 
| 227 |         // THEN | 
| 228 |         QVERIFY(textureUpdate1 != textureUpdate2); | 
| 229 |  | 
| 230 |         // WHEN | 
| 231 |         textureUpdate2.setZ(883); | 
| 232 |  | 
| 233 |         // THEN | 
| 234 |         QVERIFY(textureUpdate1 == textureUpdate2); | 
| 235 |  | 
| 236 |         // WHEN | 
| 237 |         textureUpdate1.setLayer(883); | 
| 238 |  | 
| 239 |         // THEN | 
| 240 |         QVERIFY(textureUpdate1 != textureUpdate2); | 
| 241 |  | 
| 242 |         // WHEN | 
| 243 |         textureUpdate2.setLayer(883); | 
| 244 |  | 
| 245 |         // THEN | 
| 246 |         QVERIFY(textureUpdate1 == textureUpdate2); | 
| 247 |  | 
| 248 |         // WHEN | 
| 249 |         textureUpdate1.setMipLevel(883); | 
| 250 |  | 
| 251 |         // THEN | 
| 252 |         QVERIFY(textureUpdate1 != textureUpdate2); | 
| 253 |  | 
| 254 |         // WHEN | 
| 255 |         textureUpdate2.setMipLevel(883); | 
| 256 |  | 
| 257 |         // THEN | 
| 258 |         QVERIFY(textureUpdate1 == textureUpdate2); | 
| 259 |  | 
| 260 |         // WHEN | 
| 261 |         textureUpdate1.setFace(Qt3DRender::QAbstractTexture::CubeMapNegativeX); | 
| 262 |  | 
| 263 |         // THEN | 
| 264 |         QVERIFY(textureUpdate1 != textureUpdate2); | 
| 265 |  | 
| 266 |         // WHEN | 
| 267 |         textureUpdate2.setFace(Qt3DRender::QAbstractTexture::CubeMapNegativeX); | 
| 268 |  | 
| 269 |         // THEN | 
| 270 |         QVERIFY(textureUpdate1 == textureUpdate2); | 
| 271 |  | 
| 272 |         // WHEN | 
| 273 |         Qt3DRender::QTextureImageDataPtr imgData = Qt3DRender::QTextureImageDataPtr::create(); | 
| 274 |         textureUpdate1.setData(imgData); | 
| 275 |  | 
| 276 |         // THEN | 
| 277 |         QVERIFY(textureUpdate1 != textureUpdate2); | 
| 278 |  | 
| 279 |         // WHEN | 
| 280 |         textureUpdate2.setData(imgData); | 
| 281 |  | 
| 282 |         // THEN | 
| 283 |         QVERIFY(textureUpdate1 == textureUpdate2); | 
| 284 |     } | 
| 285 | }; | 
| 286 |  | 
| 287 | QTEST_APPLESS_MAIN(tst_QTextureDataUpdate) | 
| 288 |  | 
| 289 | #include "tst_qtexturedataupdate.moc" | 
| 290 |  |