File indexing completed on 2024-11-10 04:56:25

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2012 Martin Gräßlin <mgraesslin@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #include "effect/effecthandler.h"
0011 
0012 #include "virtualdesktops.h"
0013 
0014 #include <QGraphicsRotation>
0015 #include <QGraphicsScale>
0016 #include <QVector2D>
0017 
0018 #include <QTest>
0019 
0020 using namespace KWin;
0021 
0022 class TestWindowPaintData : public QObject
0023 {
0024     Q_OBJECT
0025 private Q_SLOTS:
0026     void testCtor();
0027     void testCopyCtor();
0028     void testOperatorMultiplyAssign();
0029     void testOperatorPlus();
0030     void testMultiplyOpacity();
0031     void testMultiplySaturation();
0032     void testMultiplyBrightness();
0033 };
0034 
0035 void TestWindowPaintData::testCtor()
0036 {
0037     WindowPaintData data;
0038     QCOMPARE(data.xScale(), 1.0);
0039     QCOMPARE(data.yScale(), 1.0);
0040     QCOMPARE(data.zScale(), 1.0);
0041     QCOMPARE(data.xTranslation(), 0.0);
0042     QCOMPARE(data.yTranslation(), 0.0);
0043     QCOMPARE(data.zTranslation(), 0.0);
0044     QCOMPARE(data.translation(), QVector3D());
0045     QCOMPARE(data.rotationAngle(), 0.0);
0046     QCOMPARE(data.rotationOrigin(), QVector3D());
0047     QCOMPARE(data.rotationAxis(), QVector3D(0.0, 0.0, 1.0));
0048     QCOMPARE(data.opacity(), 1.0);
0049     QCOMPARE(data.brightness(), 1.0);
0050     QCOMPARE(data.saturation(), 1.0);
0051 }
0052 
0053 void TestWindowPaintData::testCopyCtor()
0054 {
0055     WindowPaintData data;
0056     WindowPaintData data2(data);
0057     // no value had been changed
0058     QCOMPARE(data2.xScale(), 1.0);
0059     QCOMPARE(data2.yScale(), 1.0);
0060     QCOMPARE(data2.zScale(), 1.0);
0061     QCOMPARE(data2.xTranslation(), 0.0);
0062     QCOMPARE(data2.yTranslation(), 0.0);
0063     QCOMPARE(data2.zTranslation(), 0.0);
0064     QCOMPARE(data2.translation(), QVector3D());
0065     QCOMPARE(data2.rotationAngle(), 0.0);
0066     QCOMPARE(data2.rotationOrigin(), QVector3D());
0067     QCOMPARE(data2.rotationAxis(), QVector3D(0.0, 0.0, 1.0));
0068     QCOMPARE(data2.opacity(), 1.0);
0069     QCOMPARE(data2.brightness(), 1.0);
0070     QCOMPARE(data2.saturation(), 1.0);
0071 
0072     data2.setScale(QVector3D(0.5, 2.0, 3.0));
0073     data2.translate(0.5, 2.0, 3.0);
0074     data2.setRotationAngle(45.0);
0075     data2.setRotationOrigin(QVector3D(1.0, 2.0, 3.0));
0076     data2.setRotationAxis(QVector3D(1.0, 1.0, 0.0));
0077     data2.setOpacity(0.1);
0078     data2.setBrightness(0.3);
0079     data2.setSaturation(0.4);
0080 
0081     WindowPaintData data3(data2);
0082     QCOMPARE(data3.xScale(), 0.5);
0083     QCOMPARE(data3.yScale(), 2.0);
0084     QCOMPARE(data3.zScale(), 3.0);
0085     QCOMPARE(data3.xTranslation(), 0.5);
0086     QCOMPARE(data3.yTranslation(), 2.0);
0087     QCOMPARE(data3.zTranslation(), 3.0);
0088     QCOMPARE(data3.translation(), QVector3D(0.5, 2.0, 3.0));
0089     QCOMPARE(data3.rotationAngle(), 45.0);
0090     QCOMPARE(data3.rotationOrigin(), QVector3D(1.0, 2.0, 3.0));
0091     QCOMPARE(data3.rotationAxis(), QVector3D(1.0, 1.0, 0.0));
0092     QCOMPARE(data3.opacity(), 0.1);
0093     QCOMPARE(data3.brightness(), 0.3);
0094     QCOMPARE(data3.saturation(), 0.4);
0095 }
0096 
0097 void TestWindowPaintData::testOperatorMultiplyAssign()
0098 {
0099     WindowPaintData data;
0100     // without anything set, it's 1.0 on all axis
0101     QCOMPARE(data.xScale(), 1.0);
0102     QCOMPARE(data.yScale(), 1.0);
0103     QCOMPARE(data.zScale(), 1.0);
0104     // multiplying by a factor should set all components
0105     data *= 2.0;
0106     QCOMPARE(data.xScale(), 2.0);
0107     QCOMPARE(data.yScale(), 2.0);
0108     QCOMPARE(data.zScale(), 2.0);
0109     // multiplying by a vector2D should set x and y components
0110     data *= QVector2D(2.0, 3.0);
0111     QCOMPARE(data.xScale(), 4.0);
0112     QCOMPARE(data.yScale(), 6.0);
0113     QCOMPARE(data.zScale(), 2.0);
0114     // multiplying by a vector3d should set all components
0115     data *= QVector3D(0.5, 1.5, 2.0);
0116     QCOMPARE(data.xScale(), 2.0);
0117     QCOMPARE(data.yScale(), 9.0);
0118     QCOMPARE(data.zScale(), 4.0);
0119 }
0120 
0121 void TestWindowPaintData::testOperatorPlus()
0122 {
0123     WindowPaintData data;
0124     QCOMPARE(data.xTranslation(), 0.0);
0125     QCOMPARE(data.yTranslation(), 0.0);
0126     QCOMPARE(data.zTranslation(), 0.0);
0127     QCOMPARE(data.translation(), QVector3D());
0128     // test with point
0129     data += QPoint(1, 2);
0130     QCOMPARE(data.translation(), QVector3D(1.0, 2.0, 0.0));
0131     // test with pointf
0132     data += QPointF(0.5, 0.75);
0133     QCOMPARE(data.translation(), QVector3D(1.5, 2.75, 0.0));
0134     // test with QVector2D
0135     data += QVector2D(0.25, 1.5);
0136     QCOMPARE(data.translation(), QVector3D(1.75, 4.25, 0.0));
0137     // test with QVector3D
0138     data += QVector3D(1.0, 2.0, 3.5);
0139     QCOMPARE(data.translation(), QVector3D(2.75, 6.25, 3.5));
0140 }
0141 
0142 void TestWindowPaintData::testMultiplyBrightness()
0143 {
0144     WindowPaintData data;
0145     QCOMPARE(0.2, data.multiplyBrightness(0.2));
0146     QCOMPARE(0.2, data.brightness());
0147     QCOMPARE(0.6, data.multiplyBrightness(3.0));
0148     QCOMPARE(0.6, data.brightness());
0149     // just for safety
0150     QCOMPARE(1.0, data.opacity());
0151     QCOMPARE(1.0, data.saturation());
0152 }
0153 
0154 void TestWindowPaintData::testMultiplyOpacity()
0155 {
0156     WindowPaintData data;
0157     QCOMPARE(0.2, data.multiplyOpacity(0.2));
0158     QCOMPARE(0.2, data.opacity());
0159     QCOMPARE(0.6, data.multiplyOpacity(3.0));
0160     QCOMPARE(0.6, data.opacity());
0161     // just for safety
0162     QCOMPARE(1.0, data.brightness());
0163     QCOMPARE(1.0, data.saturation());
0164 }
0165 
0166 void TestWindowPaintData::testMultiplySaturation()
0167 {
0168     WindowPaintData data;
0169     QCOMPARE(0.2, data.multiplySaturation(0.2));
0170     QCOMPARE(0.2, data.saturation());
0171     QCOMPARE(0.6, data.multiplySaturation(3.0));
0172     QCOMPARE(0.6, data.saturation());
0173     // just for safety
0174     QCOMPARE(1.0, data.brightness());
0175     QCOMPARE(1.0, data.opacity());
0176 }
0177 
0178 QTEST_MAIN(TestWindowPaintData)
0179 #include "test_window_paint_data.moc"