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