File indexing completed on 2024-04-28 16:44:32
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 #include "../src/decorationshadow.h" 0007 #include <QSignalSpy> 0008 #include <QTest> 0009 0010 Q_DECLARE_METATYPE(QMargins) 0011 0012 class DecorationShadowTest : public QObject 0013 { 0014 Q_OBJECT 0015 private Q_SLOTS: 0016 void testPadding_data(); 0017 void testPadding(); 0018 void testSizes_data(); 0019 void testSizes(); 0020 }; 0021 0022 void DecorationShadowTest::testPadding_data() 0023 { 0024 QTest::addColumn<QByteArray>("propertyName"); 0025 QTest::addColumn<QMargins>("padding"); 0026 0027 QTest::newRow("top") << QByteArrayLiteral("paddingTop") << QMargins(0, 10, 0, 0); 0028 QTest::newRow("right") << QByteArrayLiteral("paddingRight") << QMargins(0, 0, 10, 0); 0029 QTest::newRow("bottom") << QByteArrayLiteral("paddingBottom") << QMargins(0, 0, 0, 10); 0030 QTest::newRow("left") << QByteArrayLiteral("paddingLeft") << QMargins(10, 0, 0, 0); 0031 } 0032 0033 void DecorationShadowTest::testPadding() 0034 { 0035 using namespace KDecoration2; 0036 DecorationShadow shadow; 0037 0038 QFETCH(QByteArray, propertyName); 0039 0040 const int propertyIndex = shadow.metaObject()->indexOfProperty(propertyName.constData()); 0041 QVERIFY(propertyIndex != -1); 0042 QMetaProperty metaProperty = shadow.metaObject()->property(propertyIndex); 0043 QCOMPARE(metaProperty.isReadable(), true); 0044 QCOMPARE(metaProperty.hasNotifySignal(), true); 0045 QCOMPARE(metaProperty.type(), QVariant::Int); 0046 QSignalSpy changedSpy(&shadow, &KDecoration2::DecorationShadow::paddingChanged); 0047 QVERIFY(changedSpy.isValid()); 0048 0049 QCOMPARE(shadow.property(propertyName.constData()).isValid(), true); 0050 QCOMPARE(shadow.property(propertyName.constData()).toInt(), 0); 0051 QFETCH(QMargins, padding); 0052 shadow.setPadding(padding); 0053 QCOMPARE(shadow.padding(), padding); 0054 QCOMPARE(shadow.property(propertyName.constData()).toInt(), 10); 0055 QCOMPARE(changedSpy.count(), 1); 0056 0057 // trying to set to same value shouldn't emit the signal 0058 shadow.setPadding(padding); 0059 QCOMPARE(shadow.property(propertyName.constData()).toInt(), 10); 0060 QCOMPARE(changedSpy.count(), 1); 0061 0062 // changing to different value should emit signal 0063 padding += 1; 0064 shadow.setPadding(padding); 0065 QCOMPARE(shadow.padding(), padding); 0066 QCOMPARE(shadow.property(propertyName.constData()).toInt(), 11); 0067 QCOMPARE(changedSpy.count(), 2); 0068 } 0069 0070 void DecorationShadowTest::testSizes_data() 0071 { 0072 QTest::addColumn<QByteArray>("propertyName"); 0073 QTest::addColumn<QRect>("innerShadowRect"); 0074 QTest::addColumn<QRect>("shadowRect"); 0075 QTest::addColumn<QSize>("shadowSize"); 0076 0077 QTest::newRow("topLeft") << QByteArrayLiteral("topLeftGeometry") << QRect(1, 2, 5, 5) << QRect(0, 0, 1, 2) << QSize(6, 7); 0078 QTest::newRow("top") << QByteArrayLiteral("topGeometry") << QRect(1, 2, 1, 5) << QRect(1, 0, 1, 2) << QSize(3, 7); 0079 QTest::newRow("topRight") << QByteArrayLiteral("topRightGeometry") << QRect(0, 2, 2, 1) << QRect(2, 0, 1, 2) << QSize(3, 3); 0080 QTest::newRow("right") << QByteArrayLiteral("rightGeometry") << QRect(0, 0, 1, 2) << QRect(1, 0, 1, 2) << QSize(2, 4); 0081 QTest::newRow("bottomRight") << QByteArrayLiteral("bottomRightGeometry") << QRect(0, 0, 1, 4) << QRect(1, 4, 1, 2) << QSize(2, 6); 0082 QTest::newRow("bottom") << QByteArrayLiteral("bottomGeometry") << QRect(0, 0, 1, 1) << QRect(0, 1, 1, 2) << QSize(1, 3); 0083 QTest::newRow("bottomLeft") << QByteArrayLiteral("bottomLeftGeometry") << QRect(1, 0, 1, 1) << QRect(0, 1, 1, 2) << QSize(2, 3); 0084 QTest::newRow("left") << QByteArrayLiteral("leftGeometry") << QRect(1, 0, 1, 2) << QRect(0, 0, 1, 2) << QSize(2, 2); 0085 } 0086 0087 void DecorationShadowTest::testSizes() 0088 { 0089 using namespace KDecoration2; 0090 DecorationShadow shadow; 0091 0092 QFETCH(QByteArray, propertyName); 0093 0094 const int propertyIndex = shadow.metaObject()->indexOfProperty(propertyName.constData()); 0095 QVERIFY(propertyIndex != -1); 0096 QMetaProperty metaProperty = shadow.metaObject()->property(propertyIndex); 0097 QCOMPARE(metaProperty.isReadable(), true); 0098 QCOMPARE(metaProperty.hasNotifySignal(), true); 0099 QCOMPARE(metaProperty.type(), QVariant::Rect); 0100 QSignalSpy changedSpy(&shadow, &KDecoration2::DecorationShadow::innerShadowRectChanged); 0101 QVERIFY(changedSpy.isValid()); 0102 0103 QCOMPARE(shadow.innerShadowRect(), QRect()); 0104 QCOMPARE(shadow.property(propertyName.constData()).isValid(), true); 0105 QCOMPARE(shadow.property(propertyName.constData()).toRect(), QRect()); 0106 QFETCH(QRect, innerShadowRect); 0107 QFETCH(QRect, shadowRect); 0108 QFETCH(QSize, shadowSize); 0109 shadow.setInnerShadowRect(innerShadowRect); 0110 QCOMPARE(shadow.innerShadowRect(), innerShadowRect); 0111 // property should still be invalid as the image is not yet set 0112 QCOMPARE(shadow.property(propertyName.constData()).toRect(), QRect()); 0113 shadow.setShadow(QImage(shadowSize, QImage::Format_ARGB32)); 0114 QCOMPARE(shadow.property(propertyName.constData()).toRect(), shadowRect); 0115 QCOMPARE(changedSpy.count(), 1); 0116 0117 // trying to set to same value shouldn't emit the signal 0118 shadow.setInnerShadowRect(innerShadowRect); 0119 QCOMPARE(shadow.property(propertyName.constData()).toRect(), shadowRect); 0120 QCOMPARE(changedSpy.count(), 1); 0121 0122 // changing to different value should emit signal 0123 shadow.setInnerShadowRect(innerShadowRect.adjusted(1, 1, 1, 1)); 0124 QCOMPARE(changedSpy.count(), 2); 0125 QCOMPARE(shadow.innerShadowRect(), innerShadowRect.adjusted(1, 1, 1, 1)); 0126 } 0127 0128 QTEST_MAIN(DecorationShadowTest) 0129 #include "shadowtest.moc"