| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2017 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt Graphical Effects module. |
| 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 <qtest.h> |
| 30 | #include <QtCore/qscopedpointer.h> |
| 31 | #include <QtQml> |
| 32 | |
| 33 | class tst_qtgraphicaleffects : public QObject |
| 34 | { |
| 35 | Q_OBJECT |
| 36 | |
| 37 | private slots: |
| 38 | void initTestCase(); |
| 39 | |
| 40 | void blend(); |
| 41 | void brightnessContrast(); |
| 42 | void colorize(); |
| 43 | void colorOverlay(); |
| 44 | void conicalGradient(); |
| 45 | void desaturate(); |
| 46 | void directionalBlur(); |
| 47 | void displace(); |
| 48 | void dropShadow(); |
| 49 | void fastBlur(); |
| 50 | void gammaAdjust(); |
| 51 | void gaussianBlur(); |
| 52 | void glow(); |
| 53 | void hueSaturation(); |
| 54 | void innerShadow(); |
| 55 | void levelAdjust(); |
| 56 | void linearGradient(); |
| 57 | void maskedBlur(); |
| 58 | void opacityMask(); |
| 59 | void radialBlur(); |
| 60 | void radialGradient(); |
| 61 | void recursiveBlur(); |
| 62 | void rectangularGlow(); |
| 63 | void thresholdMask(); |
| 64 | void zoomBlur(); |
| 65 | |
| 66 | private: |
| 67 | QString componentErrors(const QQmlComponent*) const; |
| 68 | |
| 69 | QString importSelf; |
| 70 | QQmlEngine engine; |
| 71 | }; |
| 72 | |
| 73 | QString tst_qtgraphicaleffects::componentErrors(const QQmlComponent* component) const |
| 74 | { |
| 75 | if (!component) { |
| 76 | return "(null component)" ; |
| 77 | } |
| 78 | |
| 79 | QStringList out; |
| 80 | |
| 81 | const auto errors = component->errors(); |
| 82 | for (const QQmlError &error : errors) |
| 83 | out << error.toString(); |
| 84 | |
| 85 | return out.join(sep: "\n" ); |
| 86 | } |
| 87 | |
| 88 | void tst_qtgraphicaleffects::initTestCase() |
| 89 | { |
| 90 | QString import; |
| 91 | |
| 92 | QString qmlImportPath = qgetenv(varName: "QML2_IMPORT_PATH" ); |
| 93 | if (qmlImportPath.isEmpty() || !QFile::exists(fileName: qmlImportPath)) |
| 94 | qmlImportPath = QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath); |
| 95 | |
| 96 | // Allow the test to work whether or not the module is yet installed. |
| 97 | if (QFile::exists(fileName: qmlImportPath + "/QtGraphicalEffects" )) { |
| 98 | // Module is installed - import it the nice way |
| 99 | import = "QtGraphicalEffects" ; |
| 100 | } |
| 101 | else { |
| 102 | // Module is not installed - import it from the source tree, by URI |
| 103 | QString qmldir = QFINDTESTDATA("../../src/effects/qmldir" ); |
| 104 | QVERIFY2(QFile::exists(qmldir), qPrintable(qmldir)); |
| 105 | |
| 106 | QUrl url = QUrl::fromLocalFile(localfile: QFileInfo(qmldir).canonicalPath()); |
| 107 | import = "\"" + url.toString() + "\"" ; |
| 108 | } |
| 109 | |
| 110 | importSelf = QString("import %1 1.0\n" ).arg(a: import); |
| 111 | } |
| 112 | |
| 113 | |
| 114 | void tst_qtgraphicaleffects::brightnessContrast() |
| 115 | { |
| 116 | // Creation |
| 117 | QString componentStr = "import QtQuick 2.0\n" |
| 118 | + importSelf + |
| 119 | "BrightnessContrast {" |
| 120 | "width: 50; height: 50\n" |
| 121 | "source: ShaderEffectSource {sourceItem: Rectangle {width: 100; height: 100}}" |
| 122 | "}" ; |
| 123 | QQmlComponent component(&engine); |
| 124 | component.setData(componentStr.toLatin1(), baseUrl: QUrl::fromLocalFile(localfile: "" )); |
| 125 | QVERIFY2(component.status() != QQmlComponent::Error, qPrintable(componentErrors(&component))); |
| 126 | QTRY_COMPARE(component.status(), QQmlComponent::Ready); |
| 127 | QScopedPointer<QObject> obj(component.create()); |
| 128 | QVERIFY(!obj.isNull()); |
| 129 | |
| 130 | // Default values |
| 131 | QCOMPARE(obj->property("brightness" ).type(), QVariant::Double); |
| 132 | QCOMPARE(obj->property("brightness" ).toDouble(), 0.0); |
| 133 | QCOMPARE(obj->property("contrast" ).type(), QVariant::Double); |
| 134 | QCOMPARE(obj->property("contrast" ).toDouble(), 0.0); |
| 135 | QCOMPARE(obj->property("source" ).toInt(), 0); |
| 136 | QCOMPARE(obj->property("cached" ).toBool(), false); |
| 137 | } |
| 138 | |
| 139 | void tst_qtgraphicaleffects::colorize() |
| 140 | { |
| 141 | // Creation |
| 142 | QString componentStr = "import QtQuick 2.0\n" |
| 143 | + importSelf + |
| 144 | "Colorize {" |
| 145 | "width: 50; height: 50\n" |
| 146 | "source: ShaderEffectSource {sourceItem: Rectangle {width: 100; height: 100}}" |
| 147 | "}" ; |
| 148 | QQmlComponent component(&engine); |
| 149 | component.setData(componentStr.toLatin1(), baseUrl: QUrl::fromLocalFile(localfile: "" )); |
| 150 | QVERIFY2(component.status() != QQmlComponent::Error, qPrintable(componentErrors(&component))); |
| 151 | QTRY_COMPARE(component.status(), QQmlComponent::Ready); |
| 152 | QScopedPointer<QObject> obj(component.create()); |
| 153 | QVERIFY(!obj.isNull()); |
| 154 | |
| 155 | // Default values |
| 156 | QCOMPARE(obj->property("hue" ).type(), QVariant::Double); |
| 157 | QCOMPARE(obj->property("hue" ).toDouble(), 0.0); |
| 158 | QCOMPARE(obj->property("saturation" ).type(), QVariant::Double); |
| 159 | QCOMPARE(obj->property("saturation" ).toDouble(), 1.0); |
| 160 | QCOMPARE(obj->property("lightness" ).type(), QVariant::Double); |
| 161 | QCOMPARE(obj->property("lightness" ).toDouble(), 0.0); |
| 162 | QCOMPARE(obj->property("source" ).toInt(), 0); |
| 163 | QCOMPARE(obj->property("cached" ).toBool(), false); |
| 164 | } |
| 165 | |
| 166 | void tst_qtgraphicaleffects::fastBlur() |
| 167 | { |
| 168 | // Creation |
| 169 | QString componentStr = "import QtQuick 2.0\n" |
| 170 | + importSelf + |
| 171 | "FastBlur {" |
| 172 | "width: 50; height: 50\n" |
| 173 | "source: ShaderEffectSource {sourceItem: Rectangle {width: 100; height: 100}}" |
| 174 | "}" ; |
| 175 | QQmlComponent component(&engine); |
| 176 | component.setData(componentStr.toLatin1(), baseUrl: QUrl::fromLocalFile(localfile: "" )); |
| 177 | QVERIFY2(component.status() != QQmlComponent::Error, qPrintable(componentErrors(&component))); |
| 178 | QTRY_COMPARE(component.status(), QQmlComponent::Ready); |
| 179 | QScopedPointer<QObject> obj(component.create()); |
| 180 | QVERIFY(!obj.isNull()); |
| 181 | |
| 182 | // Default values |
| 183 | QCOMPARE(obj->property("radius" ).type(), QVariant::Double); |
| 184 | QCOMPARE(obj->property("radius" ).toDouble(), 0.0); |
| 185 | QCOMPARE(obj->property("transparentBorder" ).toBool(), false); |
| 186 | QCOMPARE(obj->property("source" ).toInt(), 0); |
| 187 | QCOMPARE(obj->property("cached" ).toBool(), false); |
| 188 | } |
| 189 | |
| 190 | void tst_qtgraphicaleffects::desaturate() |
| 191 | { |
| 192 | // Creation |
| 193 | QString componentStr = "import QtQuick 2.0\n" |
| 194 | + importSelf + |
| 195 | "Desaturate {" |
| 196 | "width: 50; height: 50\n" |
| 197 | "source: ShaderEffectSource {sourceItem: Rectangle {width: 100; height: 100}}" |
| 198 | "}" ; |
| 199 | QQmlComponent component(&engine); |
| 200 | component.setData(componentStr.toLatin1(), baseUrl: QUrl::fromLocalFile(localfile: "" )); |
| 201 | QVERIFY2(component.status() != QQmlComponent::Error, qPrintable(componentErrors(&component))); |
| 202 | QTRY_COMPARE(component.status(), QQmlComponent::Ready); |
| 203 | QScopedPointer<QObject> obj(component.create()); |
| 204 | QVERIFY(!obj.isNull()); |
| 205 | |
| 206 | // Default values |
| 207 | QCOMPARE(obj->property("desaturation" ).type(), QVariant::Double); |
| 208 | QCOMPARE(obj->property("desaturation" ).toDouble(), 0.0); |
| 209 | QCOMPARE(obj->property("source" ).toInt(), 0); |
| 210 | QCOMPARE(obj->property("cached" ).toBool(), false); |
| 211 | } |
| 212 | |
| 213 | void tst_qtgraphicaleffects::hueSaturation() |
| 214 | { |
| 215 | // Creation |
| 216 | QString componentStr = "import QtQuick 2.0\n" |
| 217 | + importSelf + |
| 218 | "HueSaturation {" |
| 219 | "width: 50; height: 50\n" |
| 220 | "source: ShaderEffectSource {sourceItem: Rectangle {width: 100; height: 100}}" |
| 221 | "}" ; |
| 222 | QQmlComponent component(&engine); |
| 223 | component.setData(componentStr.toLatin1(), baseUrl: QUrl::fromLocalFile(localfile: "" )); |
| 224 | QVERIFY2(component.status() != QQmlComponent::Error, qPrintable(componentErrors(&component))); |
| 225 | QTRY_COMPARE(component.status(), QQmlComponent::Ready); |
| 226 | QScopedPointer<QObject> obj(component.create()); |
| 227 | QVERIFY(!obj.isNull()); |
| 228 | |
| 229 | // Default values |
| 230 | QCOMPARE(obj->property("hue" ).type(), QVariant::Double); |
| 231 | QCOMPARE(obj->property("hue" ).toDouble(), 0.0); |
| 232 | QCOMPARE(obj->property("saturation" ).type(), QVariant::Double); |
| 233 | QCOMPARE(obj->property("saturation" ).toDouble(), 0.0); |
| 234 | QCOMPARE(obj->property("lightness" ).type(), QVariant::Double); |
| 235 | QCOMPARE(obj->property("lightness" ).toDouble(), 0.0); |
| 236 | QCOMPARE(obj->property("source" ).toInt(), 0); |
| 237 | QCOMPARE(obj->property("cached" ).toBool(), false); |
| 238 | } |
| 239 | |
| 240 | void tst_qtgraphicaleffects::opacityMask() |
| 241 | { |
| 242 | // Creation |
| 243 | QString componentStr = "import QtQuick 2.0\n" |
| 244 | + importSelf + |
| 245 | "OpacityMask {" |
| 246 | "width: 50; height: 50\n" |
| 247 | "source: ShaderEffectSource {sourceItem: Rectangle {width: 100; height: 100}}" |
| 248 | "maskSource: ShaderEffectSource {sourceItem: Rectangle {width: 100; height: 100}}" |
| 249 | "}" ; |
| 250 | QQmlComponent component(&engine); |
| 251 | component.setData(componentStr.toLatin1(), baseUrl: QUrl::fromLocalFile(localfile: "" )); |
| 252 | QVERIFY2(component.status() != QQmlComponent::Error, qPrintable(componentErrors(&component))); |
| 253 | QTRY_COMPARE(component.status(), QQmlComponent::Ready); |
| 254 | QScopedPointer<QObject> obj(component.create()); |
| 255 | QVERIFY(!obj.isNull()); |
| 256 | |
| 257 | // Default values |
| 258 | QCOMPARE(obj->property("source" ).toInt(), 0); |
| 259 | QCOMPARE(obj->property("maskSource" ).toInt(), 0); |
| 260 | QCOMPARE(obj->property("cached" ).toBool(), false); |
| 261 | } |
| 262 | |
| 263 | void tst_qtgraphicaleffects::radialGradient() |
| 264 | { |
| 265 | // Creation |
| 266 | QString componentStr = "import QtQuick 2.0\n" |
| 267 | + importSelf + |
| 268 | "RadialGradient {" |
| 269 | "width: 50; height: 50\n" |
| 270 | "}" ; |
| 271 | QQmlComponent component(&engine); |
| 272 | component.setData(componentStr.toLatin1(), baseUrl: QUrl::fromLocalFile(localfile: "" )); |
| 273 | QVERIFY2(component.status() != QQmlComponent::Error, qPrintable(componentErrors(&component))); |
| 274 | QTRY_COMPARE(component.status(), QQmlComponent::Ready); |
| 275 | QScopedPointer<QObject> obj(component.create()); |
| 276 | QVERIFY(!obj.isNull()); |
| 277 | |
| 278 | // Default values |
| 279 | QCOMPARE(obj->property("gradient" ).toInt(), 0); |
| 280 | QCOMPARE(obj->property("horizontalOffset" ).type(), QVariant::Double); |
| 281 | QCOMPARE(obj->property("horizontalOffset" ).toDouble(), 0.0); |
| 282 | QCOMPARE(obj->property("verticalOffset" ).type(), QVariant::Double); |
| 283 | QCOMPARE(obj->property("verticalOffset" ).toDouble(), 0.0); |
| 284 | QCOMPARE(obj->property("horizontalRadius" ).type(), QVariant::Double); |
| 285 | QCOMPARE(obj->property("horizontalRadius" ).toDouble(), 50.0); |
| 286 | QCOMPARE(obj->property("verticalRadius" ).type(), QVariant::Double); |
| 287 | QCOMPARE(obj->property("verticalRadius" ).toDouble(), 50.0); |
| 288 | QCOMPARE(obj->property("source" ).toInt(), 0); |
| 289 | QCOMPARE(obj->property("angle" ).type(), QVariant::Double); |
| 290 | QCOMPARE(obj->property("angle" ).toDouble(), 0.0); |
| 291 | QCOMPARE(obj->property("cached" ).toBool(), false); |
| 292 | } |
| 293 | |
| 294 | void tst_qtgraphicaleffects::linearGradient() |
| 295 | { |
| 296 | // Creation |
| 297 | QString componentStr = "import QtQuick 2.0\n" |
| 298 | + importSelf + |
| 299 | "LinearGradient {" |
| 300 | "width: 50; height: 50\n" |
| 301 | "}" ; |
| 302 | QQmlComponent component(&engine); |
| 303 | component.setData(componentStr.toLatin1(), baseUrl: QUrl::fromLocalFile(localfile: "" )); |
| 304 | QVERIFY2(component.status() != QQmlComponent::Error, qPrintable(componentErrors(&component))); |
| 305 | QTRY_COMPARE(component.status(), QQmlComponent::Ready); |
| 306 | QScopedPointer<QObject> obj(component.create()); |
| 307 | QVERIFY(!obj.isNull()); |
| 308 | |
| 309 | // Default values |
| 310 | QCOMPARE(obj->property("gradient" ).toInt(), 0); |
| 311 | QCOMPARE(obj->property("start" ).toPointF(), QPointF(0.0, 0.0)); |
| 312 | QCOMPARE(obj->property("end" ).toPointF(), QPointF(0.0, 50.0)); |
| 313 | QCOMPARE(obj->property("source" ).toInt(), 0); |
| 314 | QCOMPARE(obj->property("cached" ).toBool(), false); |
| 315 | } |
| 316 | |
| 317 | void tst_qtgraphicaleffects::rectangularGlow() |
| 318 | { |
| 319 | // Creation |
| 320 | QString componentStr = "import QtQuick 2.0\n" |
| 321 | + importSelf + |
| 322 | "RectangularGlow {" |
| 323 | "width: 50; height: 50\n" |
| 324 | "}" ; |
| 325 | QQmlComponent component(&engine); |
| 326 | component.setData(componentStr.toLatin1(), baseUrl: QUrl::fromLocalFile(localfile: "" )); |
| 327 | QVERIFY2(component.status() != QQmlComponent::Error, qPrintable(componentErrors(&component))); |
| 328 | QTRY_COMPARE(component.status(), QQmlComponent::Ready); |
| 329 | QScopedPointer<QObject> obj(component.create()); |
| 330 | QVERIFY(!obj.isNull()); |
| 331 | |
| 332 | // Default values |
| 333 | QCOMPARE(obj->property("spread" ).type(), QVariant::Double); |
| 334 | QCOMPARE(obj->property("spread" ).toDouble(), 0.0); |
| 335 | QCOMPARE(obj->property("glowRadius" ).type(), QVariant::Double); |
| 336 | QCOMPARE(obj->property("glowRadius" ).toDouble(), 0.0); |
| 337 | QCOMPARE(obj->property("color" ).toString(), QString("#ffffff" )); |
| 338 | QCOMPARE(obj->property("cornerRadius" ).type(), QVariant::Double); |
| 339 | QCOMPARE(obj->property("cornerRadius" ).toDouble(), 0.0); |
| 340 | QCOMPARE(obj->property("cached" ).toBool(), false); |
| 341 | } |
| 342 | |
| 343 | void tst_qtgraphicaleffects::conicalGradient() |
| 344 | { |
| 345 | // Creation |
| 346 | QString componentStr = "import QtQuick 2.0\n" |
| 347 | + importSelf + |
| 348 | "ConicalGradient {" |
| 349 | "width: 50; height: 50\n" |
| 350 | "}" ; |
| 351 | QQmlComponent component(&engine); |
| 352 | component.setData(componentStr.toLatin1(), baseUrl: QUrl::fromLocalFile(localfile: "" )); |
| 353 | QVERIFY2(component.status() != QQmlComponent::Error, qPrintable(componentErrors(&component))); |
| 354 | QTRY_COMPARE(component.status(), QQmlComponent::Ready); |
| 355 | QScopedPointer<QObject> obj(component.create()); |
| 356 | QVERIFY(!obj.isNull()); |
| 357 | |
| 358 | // Default values |
| 359 | QCOMPARE(obj->property("angle" ).type(), QVariant::Double); |
| 360 | QCOMPARE(obj->property("angle" ).toDouble(), 0.0); |
| 361 | QCOMPARE(obj->property("gradient" ).toInt(), 0); |
| 362 | QCOMPARE(obj->property("horizontalOffset" ).type(), QVariant::Double); |
| 363 | QCOMPARE(obj->property("horizontalOffset" ).toDouble(), 0.0); |
| 364 | QCOMPARE(obj->property("horizontalOffset" ).type(), QVariant::Double); |
| 365 | QCOMPARE(obj->property("verticalOffset" ).toDouble(), 0.0); |
| 366 | QCOMPARE(obj->property("source" ).toInt(), 0); |
| 367 | QCOMPARE(obj->property("cached" ).toBool(), false); |
| 368 | } |
| 369 | |
| 370 | void tst_qtgraphicaleffects::colorOverlay() |
| 371 | { |
| 372 | // Creation |
| 373 | QString componentStr = "import QtQuick 2.0\n" |
| 374 | + importSelf + |
| 375 | "ColorOverlay {" |
| 376 | "width: 50; height: 50\n" |
| 377 | "source: ShaderEffectSource {sourceItem: Rectangle {width: 100; height: 100}}" |
| 378 | "}" ; |
| 379 | QQmlComponent component(&engine); |
| 380 | component.setData(componentStr.toLatin1(), baseUrl: QUrl::fromLocalFile(localfile: "" )); |
| 381 | QVERIFY2(component.status() != QQmlComponent::Error, qPrintable(componentErrors(&component))); |
| 382 | QTRY_COMPARE(component.status(), QQmlComponent::Ready); |
| 383 | QScopedPointer<QObject> obj(component.create()); |
| 384 | QVERIFY(!obj.isNull()); |
| 385 | |
| 386 | // Default values |
| 387 | QCOMPARE(obj->property("cached" ).toBool(), false); |
| 388 | QCOMPARE(obj->property("color" ).toString(), QString("#00000000" )); |
| 389 | } |
| 390 | |
| 391 | void tst_qtgraphicaleffects::gaussianBlur() |
| 392 | { |
| 393 | // Creation |
| 394 | QString componentStr = "import QtQuick 2.0\n" |
| 395 | + importSelf + |
| 396 | "GaussianBlur {" |
| 397 | "source: ShaderEffectSource {sourceItem: Rectangle {width: 100; height: 100}}" |
| 398 | "width: 50; height: 50\n" |
| 399 | "}" ; |
| 400 | QQmlComponent component(&engine); |
| 401 | component.setData(componentStr.toLatin1(), baseUrl: QUrl::fromLocalFile(localfile: "" )); |
| 402 | QVERIFY2(component.status() != QQmlComponent::Error, qPrintable(componentErrors(&component))); |
| 403 | QTRY_COMPARE(component.status(), QQmlComponent::Ready); |
| 404 | QScopedPointer<QObject> obj(component.create()); |
| 405 | QVERIFY(!obj.isNull()); |
| 406 | |
| 407 | // Default values |
| 408 | QCOMPARE(obj->property("radius" ).type(), QVariant::Double); |
| 409 | QCOMPARE(obj->property("radius" ).toDouble(), 4.0); |
| 410 | QCOMPARE(obj->property("samples" ).toInt(), 9); |
| 411 | QCOMPARE(obj->property("transparentBorder" ).toBool(), false); |
| 412 | |
| 413 | double res = obj->property(name: "deviation" ).toDouble(); |
| 414 | QVERIFY(res > 0.0); |
| 415 | |
| 416 | QCOMPARE(obj->property("cached" ).toBool(), false); |
| 417 | } |
| 418 | |
| 419 | void tst_qtgraphicaleffects::dropShadow() |
| 420 | { |
| 421 | // Creation |
| 422 | QString componentStr = "import QtQuick 2.0\n" |
| 423 | + importSelf + |
| 424 | "DropShadow {" |
| 425 | "source: ShaderEffectSource {sourceItem: Rectangle {width: 100; height: 100}}" |
| 426 | "width: 50; height: 50\n" |
| 427 | "}" ; |
| 428 | QQmlComponent component(&engine); |
| 429 | component.setData(componentStr.toLatin1(), baseUrl: QUrl::fromLocalFile(localfile: "" )); |
| 430 | QVERIFY2(component.status() != QQmlComponent::Error, qPrintable(componentErrors(&component))); |
| 431 | QTRY_COMPARE(component.status(), QQmlComponent::Ready); |
| 432 | QScopedPointer<QObject> obj(component.create()); |
| 433 | QVERIFY(!obj.isNull()); |
| 434 | |
| 435 | // Default values |
| 436 | QCOMPARE(obj->property("radius" ).type(), QVariant::Double); |
| 437 | QCOMPARE(obj->property("radius" ).toDouble(), 4.0); |
| 438 | QCOMPARE(obj->property("samples" ).toInt(), 9); |
| 439 | QCOMPARE(obj->property("horizontalOffset" ).type(), QVariant::Double); |
| 440 | QCOMPARE(obj->property("horizontalOffset" ).toDouble(), 0.0); |
| 441 | QCOMPARE(obj->property("verticalOffset" ).type(), QVariant::Double); |
| 442 | QCOMPARE(obj->property("verticalOffset" ).toDouble(), 0.0); |
| 443 | QCOMPARE(obj->property("cached" ).toBool(), false); |
| 444 | QCOMPARE(obj->property("source" ).toInt(), 0); |
| 445 | QCOMPARE(obj->property("color" ).toString(), QString("#000000" )); |
| 446 | QCOMPARE(obj->property("spread" ).type(), QVariant::Double); |
| 447 | QCOMPARE(obj->property("spread" ).toDouble(), 0.0); |
| 448 | QCOMPARE(obj->property("transparentBorder" ).toBool(), true); |
| 449 | } |
| 450 | |
| 451 | void tst_qtgraphicaleffects::innerShadow() |
| 452 | { |
| 453 | // Creation |
| 454 | QString componentStr = "import QtQuick 2.0\n" |
| 455 | + importSelf + |
| 456 | "InnerShadow {" |
| 457 | "source: ShaderEffectSource {sourceItem: Rectangle {width: 100; height: 100}}" |
| 458 | "width: 50; height: 50\n" |
| 459 | "}" ; |
| 460 | QQmlComponent component(&engine); |
| 461 | component.setData(componentStr.toLatin1(), baseUrl: QUrl::fromLocalFile(localfile: "" )); |
| 462 | QVERIFY2(component.status() != QQmlComponent::Error, qPrintable(componentErrors(&component))); |
| 463 | QTRY_COMPARE(component.status(), QQmlComponent::Ready); |
| 464 | QScopedPointer<QObject> obj(component.create()); |
| 465 | QVERIFY(!obj.isNull()); |
| 466 | |
| 467 | // Default values |
| 468 | QCOMPARE(obj->property("radius" ).type(), QVariant::Double); |
| 469 | QCOMPARE(obj->property("radius" ).toDouble(), 0.0); |
| 470 | QCOMPARE(obj->property("samples" ).toInt(), 0); |
| 471 | QCOMPARE(obj->property("horizontalOffset" ).type(), QVariant::Double); |
| 472 | QCOMPARE(obj->property("horizontalOffset" ).toDouble(), 0.0); |
| 473 | QCOMPARE(obj->property("verticalOffset" ).type(), QVariant::Double); |
| 474 | QCOMPARE(obj->property("verticalOffset" ).toDouble(), 0.0); |
| 475 | QCOMPARE(obj->property("cached" ).toBool(), false); |
| 476 | QCOMPARE(obj->property("source" ).toInt(), 0); |
| 477 | QCOMPARE(obj->property("color" ).toString(), QString("#000000" )); |
| 478 | QCOMPARE(obj->property("spread" ).type(), QVariant::Double); |
| 479 | QCOMPARE(obj->property("spread" ).toDouble(), 0.0); |
| 480 | QCOMPARE(obj->property("fast" ).toBool(), false); |
| 481 | } |
| 482 | |
| 483 | void tst_qtgraphicaleffects::gammaAdjust() |
| 484 | { |
| 485 | // Creation |
| 486 | QString componentStr = "import QtQuick 2.0\n" |
| 487 | + importSelf + |
| 488 | "GammaAdjust {" |
| 489 | "source: ShaderEffectSource {sourceItem: Rectangle {width: 100; height: 100}}" |
| 490 | "width: 50; height: 50\n" |
| 491 | "}" ; |
| 492 | QQmlComponent component(&engine); |
| 493 | component.setData(componentStr.toLatin1(), baseUrl: QUrl::fromLocalFile(localfile: "" )); |
| 494 | QVERIFY2(component.status() != QQmlComponent::Error, qPrintable(componentErrors(&component))); |
| 495 | QTRY_COMPARE(component.status(), QQmlComponent::Ready); |
| 496 | QScopedPointer<QObject> obj(component.create()); |
| 497 | QVERIFY(!obj.isNull()); |
| 498 | |
| 499 | // Default values |
| 500 | QCOMPARE(obj->property("gamma" ).type(), QVariant::Double); |
| 501 | QCOMPARE(obj->property("gamma" ).toDouble(), 1.0); |
| 502 | QCOMPARE(obj->property("source" ).toInt(), 0); |
| 503 | QCOMPARE(obj->property("cached" ).toBool(), false); |
| 504 | } |
| 505 | |
| 506 | void tst_qtgraphicaleffects::thresholdMask() |
| 507 | { |
| 508 | // Creation |
| 509 | QString componentStr = "import QtQuick 2.0\n" |
| 510 | + importSelf + |
| 511 | "ThresholdMask {" |
| 512 | "width: 50; height: 50\n" |
| 513 | "source: ShaderEffectSource {sourceItem: Rectangle {width: 100; height: 100}}" |
| 514 | "maskSource: ShaderEffectSource {sourceItem: Rectangle {width: 100; height: 100}}" |
| 515 | "}" ; |
| 516 | QQmlComponent component(&engine); |
| 517 | component.setData(componentStr.toLatin1(), baseUrl: QUrl::fromLocalFile(localfile: "" )); |
| 518 | QVERIFY2(component.status() != QQmlComponent::Error, qPrintable(componentErrors(&component))); |
| 519 | QTRY_COMPARE(component.status(), QQmlComponent::Ready); |
| 520 | QScopedPointer<QObject> obj(component.create()); |
| 521 | QVERIFY(!obj.isNull()); |
| 522 | |
| 523 | // Default values |
| 524 | QCOMPARE(obj->property("source" ).toInt(), 0); |
| 525 | QCOMPARE(obj->property("maskSource" ).toInt(), 0); |
| 526 | QCOMPARE(obj->property("cached" ).toBool(), false); |
| 527 | QCOMPARE(obj->property("threshold" ).type(), QVariant::Double); |
| 528 | QCOMPARE(obj->property("threshold" ).toDouble(), 0.0); |
| 529 | QCOMPARE(obj->property("spread" ).type(), QVariant::Double); |
| 530 | QCOMPARE(obj->property("spread" ).toDouble(), 0.0); |
| 531 | } |
| 532 | |
| 533 | void tst_qtgraphicaleffects::glow() |
| 534 | { |
| 535 | // Creation |
| 536 | QString componentStr = "import QtQuick 2.0\n" |
| 537 | + importSelf + |
| 538 | "Glow {" |
| 539 | "source: ShaderEffectSource {sourceItem: Rectangle {width: 100; height: 100}}" |
| 540 | "width: 50; height: 50\n" |
| 541 | "}" ; |
| 542 | QQmlComponent component(&engine); |
| 543 | component.setData(componentStr.toLatin1(), baseUrl: QUrl::fromLocalFile(localfile: "" )); |
| 544 | QVERIFY2(component.status() != QQmlComponent::Error, qPrintable(componentErrors(&component))); |
| 545 | QTRY_COMPARE(component.status(), QQmlComponent::Ready); |
| 546 | QScopedPointer<QObject> obj(component.create()); |
| 547 | QVERIFY(!obj.isNull()); |
| 548 | |
| 549 | // Default values |
| 550 | QCOMPARE(obj->property("radius" ).type(), QVariant::Double); |
| 551 | QCOMPARE(obj->property("radius" ).toDouble(), 4.0); |
| 552 | QCOMPARE(obj->property("samples" ).toInt(), 9); |
| 553 | QCOMPARE(obj->property("cached" ).toBool(), false); |
| 554 | QCOMPARE(obj->property("spread" ).type(), QVariant::Double); |
| 555 | QCOMPARE(obj->property("spread" ).toDouble(), 0.5); |
| 556 | QCOMPARE(obj->property("color" ).toString(), QString("#ffffff" )); |
| 557 | QCOMPARE(obj->property("transparentBorder" ).toBool(), true); |
| 558 | } |
| 559 | |
| 560 | void tst_qtgraphicaleffects::blend() |
| 561 | { |
| 562 | // Creation |
| 563 | QString componentStr = "import QtQuick 2.0\n" |
| 564 | + importSelf + |
| 565 | "Blend {" |
| 566 | "source: ShaderEffectSource {sourceItem: Rectangle {width: 100; height: 100}}" |
| 567 | "foregroundSource: ShaderEffectSource {sourceItem: Rectangle {width: 100; height: 100}}" |
| 568 | "width: 50; height: 50\n" |
| 569 | "}" ; |
| 570 | QQmlComponent component(&engine); |
| 571 | component.setData(componentStr.toLatin1(), baseUrl: QUrl::fromLocalFile(localfile: "" )); |
| 572 | QVERIFY2(component.status() != QQmlComponent::Error, qPrintable(componentErrors(&component))); |
| 573 | QTRY_COMPARE(component.status(), QQmlComponent::Ready); |
| 574 | QScopedPointer<QObject> obj(component.create()); |
| 575 | QVERIFY(!obj.isNull()); |
| 576 | |
| 577 | // Default values |
| 578 | QCOMPARE(obj->property("source" ).toInt(), 0); |
| 579 | QCOMPARE(obj->property("foregroundSource" ).toInt(), 0); |
| 580 | QCOMPARE(obj->property("cached" ).toBool(), false); |
| 581 | QCOMPARE(obj->property("mode" ).toString(), QString("normal" )); |
| 582 | } |
| 583 | |
| 584 | void tst_qtgraphicaleffects::displace() |
| 585 | { |
| 586 | // Creation |
| 587 | QString componentStr = "import QtQuick 2.0\n" |
| 588 | + importSelf + |
| 589 | "Displace {" |
| 590 | "source: ShaderEffectSource {sourceItem: Rectangle {width: 100; height: 100}}" |
| 591 | "displacementSource: ShaderEffectSource {sourceItem: Rectangle {width: 100; height: 100}}" |
| 592 | "width: 50; height: 50\n" |
| 593 | "}" ; |
| 594 | QQmlComponent component(&engine); |
| 595 | component.setData(componentStr.toLatin1(), baseUrl: QUrl::fromLocalFile(localfile: "" )); |
| 596 | QVERIFY2(component.status() != QQmlComponent::Error, qPrintable(componentErrors(&component))); |
| 597 | QTRY_COMPARE(component.status(), QQmlComponent::Ready); |
| 598 | QScopedPointer<QObject> obj(component.create()); |
| 599 | QVERIFY(!obj.isNull()); |
| 600 | |
| 601 | // Default values |
| 602 | QCOMPARE(obj->property("source" ).toInt(), 0); |
| 603 | QCOMPARE(obj->property("displacementSource" ).toInt(), 0); |
| 604 | QCOMPARE(obj->property("cached" ).toBool(), false); |
| 605 | QCOMPARE(obj->property("displacement" ).type(), QVariant::Double); |
| 606 | QCOMPARE(obj->property("displacement" ).toDouble(), 0.0); |
| 607 | } |
| 608 | |
| 609 | void tst_qtgraphicaleffects::recursiveBlur() |
| 610 | { |
| 611 | // Creation |
| 612 | QString componentStr = "import QtQuick 2.0\n" |
| 613 | + importSelf + |
| 614 | "RecursiveBlur {" |
| 615 | "source: ShaderEffectSource {sourceItem: Rectangle {width: 100; height: 100}}" |
| 616 | "width: 50; height: 50\n" |
| 617 | "}" ; |
| 618 | QQmlComponent component(&engine); |
| 619 | component.setData(componentStr.toLatin1(), baseUrl: QUrl::fromLocalFile(localfile: "" )); |
| 620 | QVERIFY2(component.status() != QQmlComponent::Error, qPrintable(componentErrors(&component))); |
| 621 | QTRY_COMPARE(component.status(), QQmlComponent::Ready); |
| 622 | QScopedPointer<QObject> obj(component.create()); |
| 623 | QVERIFY(!obj.isNull()); |
| 624 | |
| 625 | // Default values |
| 626 | QCOMPARE(obj->property("source" ).toInt(), 0); |
| 627 | QCOMPARE(obj->property("loops" ).toInt(), 0); |
| 628 | QCOMPARE(obj->property("radius" ).type(), QVariant::Double); |
| 629 | QCOMPARE(obj->property("radius" ).toDouble(), 0.0); |
| 630 | QCOMPARE(obj->property("progress" ).type(), QVariant::Double); |
| 631 | QCOMPARE(obj->property("progress" ).toDouble(), 0.0); |
| 632 | QCOMPARE(obj->property("transparentBorder" ).toBool(), false); |
| 633 | QCOMPARE(obj->property("cached" ).toBool(), false); |
| 634 | } |
| 635 | |
| 636 | void tst_qtgraphicaleffects::directionalBlur() |
| 637 | { |
| 638 | // Creation |
| 639 | QString componentStr = "import QtQuick 2.0\n" |
| 640 | + importSelf + |
| 641 | "DirectionalBlur {" |
| 642 | "source: ShaderEffectSource {sourceItem: Rectangle {width: 100; height: 100}}" |
| 643 | "width: 50; height: 50\n" |
| 644 | "}" ; |
| 645 | QQmlComponent component(&engine); |
| 646 | component.setData(componentStr.toLatin1(), baseUrl: QUrl::fromLocalFile(localfile: "" )); |
| 647 | QVERIFY2(component.status() != QQmlComponent::Error, qPrintable(componentErrors(&component))); |
| 648 | QTRY_COMPARE(component.status(), QQmlComponent::Ready); |
| 649 | QScopedPointer<QObject> obj(component.create()); |
| 650 | QVERIFY(!obj.isNull()); |
| 651 | |
| 652 | // Default values |
| 653 | QCOMPARE(obj->property("source" ).toInt(), 0); |
| 654 | QCOMPARE(obj->property("length" ).toInt(), 0); |
| 655 | QCOMPARE(obj->property("samples" ).type(), QVariant::Int); |
| 656 | QCOMPARE(obj->property("samples" ).toInt(), 0); |
| 657 | QCOMPARE(obj->property("angle" ).type(), QVariant::Double); |
| 658 | QCOMPARE(obj->property("angle" ).toDouble(), 0.0); |
| 659 | QCOMPARE(obj->property("transparentBorder" ).toBool(), false); |
| 660 | QCOMPARE(obj->property("cached" ).toBool(), false); |
| 661 | } |
| 662 | |
| 663 | void tst_qtgraphicaleffects::radialBlur() |
| 664 | { |
| 665 | // Creation |
| 666 | QString componentStr = "import QtQuick 2.0\n" |
| 667 | + importSelf + |
| 668 | "RadialBlur {" |
| 669 | "source: ShaderEffectSource {sourceItem: Rectangle {width: 100; height: 100}}" |
| 670 | "width: 50; height: 50\n" |
| 671 | "}" ; |
| 672 | QQmlComponent component(&engine); |
| 673 | component.setData(componentStr.toLatin1(), baseUrl: QUrl::fromLocalFile(localfile: "" )); |
| 674 | QVERIFY2(component.status() != QQmlComponent::Error, qPrintable(componentErrors(&component))); |
| 675 | QTRY_COMPARE(component.status(), QQmlComponent::Ready); |
| 676 | QScopedPointer<QObject> obj(component.create()); |
| 677 | QVERIFY(!obj.isNull()); |
| 678 | |
| 679 | // Default values |
| 680 | QCOMPARE(obj->property("source" ).toInt(), 0); |
| 681 | QCOMPARE(obj->property("samples" ).type(), QVariant::Int); |
| 682 | QCOMPARE(obj->property("samples" ).toInt(), 0); |
| 683 | QCOMPARE(obj->property("angle" ).type(), QVariant::Double); |
| 684 | QCOMPARE(obj->property("angle" ).toDouble(), 0.0); |
| 685 | QCOMPARE(obj->property("transparentBorder" ).toBool(), false); |
| 686 | QCOMPARE(obj->property("cached" ).toBool(), false); |
| 687 | QCOMPARE(obj->property("horizontalOffset" ).type(), QVariant::Double); |
| 688 | QCOMPARE(obj->property("horizontalOffset" ).toDouble(), 0.0); |
| 689 | QCOMPARE(obj->property("verticalOffset" ).type(), QVariant::Double); |
| 690 | QCOMPARE(obj->property("verticalOffset" ).toDouble(), 0.0); |
| 691 | } |
| 692 | |
| 693 | void tst_qtgraphicaleffects::zoomBlur() |
| 694 | { |
| 695 | // Creation |
| 696 | QString componentStr = "import QtQuick 2.0\n" |
| 697 | + importSelf + |
| 698 | "ZoomBlur {" |
| 699 | "source: ShaderEffectSource {sourceItem: Rectangle {width: 100; height: 100}}" |
| 700 | "width: 50; height: 50\n" |
| 701 | "}" ; |
| 702 | QQmlComponent component(&engine); |
| 703 | component.setData(componentStr.toLatin1(), baseUrl: QUrl::fromLocalFile(localfile: "" )); |
| 704 | QVERIFY2(component.status() != QQmlComponent::Error, qPrintable(componentErrors(&component))); |
| 705 | QTRY_COMPARE(component.status(), QQmlComponent::Ready); |
| 706 | QScopedPointer<QObject> obj(component.create()); |
| 707 | QVERIFY(!obj.isNull()); |
| 708 | |
| 709 | // Default values |
| 710 | QCOMPARE(obj->property("source" ).toInt(), 0); |
| 711 | QCOMPARE(obj->property("length" ).toInt(), 0); |
| 712 | QCOMPARE(obj->property("samples" ).type(), QVariant::Int); |
| 713 | QCOMPARE(obj->property("samples" ).toInt(), 0); |
| 714 | QCOMPARE(obj->property("transparentBorder" ).toBool(), false); |
| 715 | QCOMPARE(obj->property("cached" ).toBool(), false); |
| 716 | QCOMPARE(obj->property("horizontalOffset" ).type(), QVariant::Double); |
| 717 | QCOMPARE(obj->property("horizontalOffset" ).toDouble(), 0.0); |
| 718 | QCOMPARE(obj->property("verticalOffset" ).type(), QVariant::Double); |
| 719 | QCOMPARE(obj->property("verticalOffset" ).toDouble(), 0.0); |
| 720 | } |
| 721 | |
| 722 | void tst_qtgraphicaleffects::levelAdjust() |
| 723 | { |
| 724 | // Creation |
| 725 | QString componentStr = "import QtQuick 2.0\n" |
| 726 | + importSelf + |
| 727 | "LevelAdjust {" |
| 728 | "width: 50; height: 50\n" |
| 729 | "}" ; |
| 730 | QQmlComponent component(&engine); |
| 731 | component.setData(componentStr.toLatin1(), baseUrl: QUrl::fromLocalFile(localfile: "" )); |
| 732 | QVERIFY2(component.status() != QQmlComponent::Error, qPrintable(componentErrors(&component))); |
| 733 | QTRY_COMPARE(component.status(), QQmlComponent::Ready); |
| 734 | QScopedPointer<QObject> obj(component.create()); |
| 735 | QVERIFY(!obj.isNull()); |
| 736 | |
| 737 | // Default values |
| 738 | QCOMPARE(obj->property("source" ).toInt(), 0); |
| 739 | QCOMPARE(obj->property("minimumInput" ).toString(), QString("#00000000" )); |
| 740 | QCOMPARE(obj->property("maximumInput" ).toString(), QString("#ffffff" )); |
| 741 | QCOMPARE(obj->property("minimumOutput" ).toString(), QString("#00000000" )); |
| 742 | QCOMPARE(obj->property("maximumOutput" ).toString(), QString("#ffffff" )); |
| 743 | QCOMPARE(obj->property("cached" ).toBool(), false); |
| 744 | } |
| 745 | |
| 746 | void tst_qtgraphicaleffects::maskedBlur() |
| 747 | { |
| 748 | // Creation |
| 749 | QString componentStr = "import QtQuick 2.0\n" |
| 750 | + importSelf + |
| 751 | "MaskedBlur {" |
| 752 | "source: ShaderEffectSource {sourceItem: Rectangle {width: 100; height: 100}}" |
| 753 | "maskSource: ShaderEffectSource {sourceItem: Rectangle {width: 100; height: 100}}" |
| 754 | "width: 50; height: 50\n" |
| 755 | "}" ; |
| 756 | QQmlComponent component(&engine); |
| 757 | component.setData(componentStr.toLatin1(), baseUrl: QUrl::fromLocalFile(localfile: "" )); |
| 758 | QVERIFY2(component.status() != QQmlComponent::Error, qPrintable(componentErrors(&component))); |
| 759 | QTRY_COMPARE(component.status(), QQmlComponent::Ready); |
| 760 | QScopedPointer<QObject> obj(component.create()); |
| 761 | QVERIFY(!obj.isNull()); |
| 762 | |
| 763 | // Default values |
| 764 | QCOMPARE(obj->property("source" ).toInt(), 0); |
| 765 | QCOMPARE(obj->property("maskSource" ).toInt(), 0); |
| 766 | QCOMPARE(obj->property("radius" ).type(), QVariant::Double); |
| 767 | QCOMPARE(obj->property("radius" ).toDouble(), 4.0); |
| 768 | QCOMPARE(obj->property("samples" ).toInt(), 9); |
| 769 | QCOMPARE(obj->property("cached" ).toBool(), false); |
| 770 | } |
| 771 | |
| 772 | QTEST_MAIN(tst_qtgraphicaleffects) |
| 773 | |
| 774 | #include "tst_qtgraphicaleffects.moc" |
| 775 | |