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

0001 /*
0002     SPDX-FileCopyrightText: 2023 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include <QTest>
0008 
0009 #include "core/output.h"
0010 
0011 using namespace KWin;
0012 
0013 class TestOutputTransform : public QObject
0014 {
0015     Q_OBJECT
0016 
0017 public:
0018     TestOutputTransform();
0019 
0020 private Q_SLOTS:
0021     void mapSizeF_data();
0022     void mapSizeF();
0023     void mapSize_data();
0024     void mapSize();
0025     void mapRectF_data();
0026     void mapRectF();
0027     void mapRect_data();
0028     void mapRect();
0029     void mapPointF_data();
0030     void mapPointF();
0031     void mapPoint_data();
0032     void mapPoint();
0033     void inverted_data();
0034     void inverted();
0035     void combine_data();
0036     void combine();
0037     void matrix_data();
0038     void matrix();
0039 };
0040 
0041 TestOutputTransform::TestOutputTransform()
0042 {
0043 }
0044 
0045 void TestOutputTransform::mapSizeF_data()
0046 {
0047     QTest::addColumn<OutputTransform::Kind>("kind");
0048     QTest::addColumn<QSizeF>("source");
0049     QTest::addColumn<QSizeF>("target");
0050 
0051     QTest::addRow("rotate-0") << OutputTransform::Normal << QSizeF(10, 20) << QSizeF(10, 20);
0052     QTest::addRow("rotate-90") << OutputTransform::Rotate90 << QSizeF(10, 20) << QSizeF(20, 10);
0053     QTest::addRow("rotate-180") << OutputTransform::Rotate180 << QSizeF(10, 20) << QSizeF(10, 20);
0054     QTest::addRow("rotate-270") << OutputTransform::Rotate270 << QSizeF(10, 20) << QSizeF(20, 10);
0055     QTest::addRow("flip-x-0") << OutputTransform::FlipX << QSizeF(10, 20) << QSizeF(10, 20);
0056     QTest::addRow("flip-x-90") << OutputTransform::FlipX90 << QSizeF(10, 20) << QSizeF(20, 10);
0057     QTest::addRow("flip-x-180") << OutputTransform::FlipX180 << QSizeF(10, 20) << QSizeF(10, 20);
0058     QTest::addRow("flip-x-270") << OutputTransform::FlipX270 << QSizeF(10, 20) << QSizeF(20, 10);
0059     QTest::addRow("flip-y-0") << OutputTransform::FlipY << QSizeF(10, 20) << QSizeF(10, 20);
0060     QTest::addRow("flip-y-90") << OutputTransform::FlipY90 << QSizeF(10, 20) << QSizeF(20, 10);
0061     QTest::addRow("flip-y-180") << OutputTransform::FlipY180 << QSizeF(10, 20) << QSizeF(10, 20);
0062     QTest::addRow("flip-y-270") << OutputTransform::FlipY270 << QSizeF(10, 20) << QSizeF(20, 10);
0063 }
0064 
0065 void TestOutputTransform::mapSizeF()
0066 {
0067     QFETCH(OutputTransform::Kind, kind);
0068     QFETCH(QSizeF, source);
0069     QFETCH(QSizeF, target);
0070 
0071     QCOMPARE(OutputTransform(kind).map(source), target);
0072 }
0073 
0074 void TestOutputTransform::mapSize_data()
0075 {
0076     QTest::addColumn<OutputTransform::Kind>("kind");
0077     QTest::addColumn<QSize>("source");
0078     QTest::addColumn<QSize>("target");
0079 
0080     QTest::addRow("rotate-0") << OutputTransform::Normal << QSize(10, 20) << QSize(10, 20);
0081     QTest::addRow("rotate-90") << OutputTransform::Rotate90 << QSize(10, 20) << QSize(20, 10);
0082     QTest::addRow("rotate-180") << OutputTransform::Rotate180 << QSize(10, 20) << QSize(10, 20);
0083     QTest::addRow("rotate-270") << OutputTransform::Rotate270 << QSize(10, 20) << QSize(20, 10);
0084     QTest::addRow("flip-x-0") << OutputTransform::FlipX << QSize(10, 20) << QSize(10, 20);
0085     QTest::addRow("flip-x-90") << OutputTransform::FlipX90 << QSize(10, 20) << QSize(20, 10);
0086     QTest::addRow("flip-x-180") << OutputTransform::FlipX180 << QSize(10, 20) << QSize(10, 20);
0087     QTest::addRow("flip-x-270") << OutputTransform::FlipX270 << QSize(10, 20) << QSize(20, 10);
0088     QTest::addRow("flip-y-0") << OutputTransform::FlipY << QSize(10, 20) << QSize(10, 20);
0089     QTest::addRow("flip-y-90") << OutputTransform::FlipY90 << QSize(10, 20) << QSize(20, 10);
0090     QTest::addRow("flip-y-180") << OutputTransform::FlipY180 << QSize(10, 20) << QSize(10, 20);
0091     QTest::addRow("flip-y-270") << OutputTransform::FlipY270 << QSize(10, 20) << QSize(20, 10);
0092 }
0093 
0094 void TestOutputTransform::mapSize()
0095 {
0096     QFETCH(OutputTransform::Kind, kind);
0097     QFETCH(QSize, source);
0098     QFETCH(QSize, target);
0099 
0100     QCOMPARE(OutputTransform(kind).map(source), target);
0101 }
0102 
0103 void TestOutputTransform::mapRectF_data()
0104 {
0105     QTest::addColumn<OutputTransform::Kind>("kind");
0106     QTest::addColumn<QRectF>("source");
0107     QTest::addColumn<QRectF>("target");
0108 
0109     QTest::addRow("rotate-0") << OutputTransform::Normal << QRectF(10, 20, 30, 40) << QRectF(10, 20, 30, 40);
0110     QTest::addRow("rotate-90") << OutputTransform::Rotate90 << QRectF(10, 20, 30, 40) << QRectF(20, 60, 40, 30);
0111     QTest::addRow("rotate-180") << OutputTransform::Rotate180 << QRectF(10, 20, 30, 40) << QRectF(60, 140, 30, 40);
0112     QTest::addRow("rotate-270") << OutputTransform::Rotate270 << QRectF(10, 20, 30, 40) << QRectF(140, 10, 40, 30);
0113     QTest::addRow("flip-x-0") << OutputTransform::FlipX << QRectF(10, 20, 30, 40) << QRectF(60, 20, 30, 40);
0114     QTest::addRow("flip-x-90") << OutputTransform::FlipX90 << QRectF(10, 20, 30, 40) << QRectF(20, 10, 40, 30);
0115     QTest::addRow("flip-x-180") << OutputTransform::FlipX180 << QRectF(10, 20, 30, 40) << QRectF(10, 140, 30, 40);
0116     QTest::addRow("flip-x-270") << OutputTransform::FlipX270 << QRectF(10, 20, 30, 40) << QRectF(140, 60, 40, 30);
0117     QTest::addRow("flip-y-0") << OutputTransform::FlipY << QRectF(10, 20, 30, 40) << QRectF(10, 140, 30, 40);
0118     QTest::addRow("flip-y-90") << OutputTransform::FlipY90 << QRectF(10, 20, 30, 40) << QRectF(140, 60, 40, 30);
0119     QTest::addRow("flip-y-180") << OutputTransform::FlipY180 << QRectF(10, 20, 30, 40) << QRectF(60, 20, 30, 40);
0120     QTest::addRow("flip-y-270") << OutputTransform::FlipY270 << QRectF(10, 20, 30, 40) << QRectF(20, 10, 40, 30);
0121 }
0122 
0123 void TestOutputTransform::mapRectF()
0124 {
0125     QFETCH(OutputTransform::Kind, kind);
0126     QFETCH(QRectF, source);
0127     QFETCH(QRectF, target);
0128 
0129     QCOMPARE(OutputTransform(kind).map(source, QSizeF(100, 200)), target);
0130 }
0131 
0132 void TestOutputTransform::mapRect_data()
0133 {
0134     QTest::addColumn<OutputTransform::Kind>("kind");
0135     QTest::addColumn<QRect>("source");
0136     QTest::addColumn<QRect>("target");
0137 
0138     QTest::addRow("rotate-0") << OutputTransform::Normal << QRect(10, 20, 30, 40) << QRect(10, 20, 30, 40);
0139     QTest::addRow("rotate-90") << OutputTransform::Rotate90 << QRect(10, 20, 30, 40) << QRect(20, 60, 40, 30);
0140     QTest::addRow("rotate-180") << OutputTransform::Rotate180 << QRect(10, 20, 30, 40) << QRect(60, 140, 30, 40);
0141     QTest::addRow("rotate-270") << OutputTransform::Rotate270 << QRect(10, 20, 30, 40) << QRect(140, 10, 40, 30);
0142     QTest::addRow("flip-x-0") << OutputTransform::FlipX << QRect(10, 20, 30, 40) << QRect(60, 20, 30, 40);
0143     QTest::addRow("flip-x-90") << OutputTransform::FlipX90 << QRect(10, 20, 30, 40) << QRect(20, 10, 40, 30);
0144     QTest::addRow("flip-x-180") << OutputTransform::FlipX180 << QRect(10, 20, 30, 40) << QRect(10, 140, 30, 40);
0145     QTest::addRow("flip-x-270") << OutputTransform::FlipX270 << QRect(10, 20, 30, 40) << QRect(140, 60, 40, 30);
0146     QTest::addRow("flip-y-0") << OutputTransform::FlipY << QRect(10, 20, 30, 40) << QRect(10, 140, 30, 40);
0147     QTest::addRow("flip-y-90") << OutputTransform::FlipY90 << QRect(10, 20, 30, 40) << QRect(140, 60, 40, 30);
0148     QTest::addRow("flip-y-180") << OutputTransform::FlipY180 << QRect(10, 20, 30, 40) << QRect(60, 20, 30, 40);
0149     QTest::addRow("flip-y-270") << OutputTransform::FlipY270 << QRect(10, 20, 30, 40) << QRect(20, 10, 40, 30);
0150 }
0151 
0152 void TestOutputTransform::mapRect()
0153 {
0154     QFETCH(OutputTransform::Kind, kind);
0155     QFETCH(QRect, source);
0156     QFETCH(QRect, target);
0157 
0158     QCOMPARE(OutputTransform(kind).map(source, QSize(100, 200)), target);
0159 }
0160 
0161 void TestOutputTransform::mapPointF_data()
0162 {
0163     QTest::addColumn<OutputTransform::Kind>("kind");
0164     QTest::addColumn<QPointF>("source");
0165     QTest::addColumn<QPointF>("target");
0166 
0167     QTest::addRow("rotate-0") << OutputTransform::Normal << QPointF(10, 20) << QPointF(10, 20);
0168     QTest::addRow("rotate-90") << OutputTransform::Rotate90 << QPointF(10, 20) << QPointF(20, 90);
0169     QTest::addRow("rotate-180") << OutputTransform::Rotate180 << QPointF(10, 20) << QPointF(90, 180);
0170     QTest::addRow("rotate-270") << OutputTransform::Rotate270 << QPointF(10, 20) << QPointF(180, 10);
0171     QTest::addRow("flip-x-0") << OutputTransform::FlipX << QPointF(10, 20) << QPointF(90, 20);
0172     QTest::addRow("flip-x-90") << OutputTransform::FlipX90 << QPointF(10, 20) << QPointF(20, 10);
0173     QTest::addRow("flip-x-180") << OutputTransform::FlipX180 << QPointF(10, 20) << QPointF(10, 180);
0174     QTest::addRow("flip-x-270") << OutputTransform::FlipX270 << QPointF(10, 20) << QPointF(180, 90);
0175     QTest::addRow("flip-y-0") << OutputTransform::FlipY << QPointF(10, 20) << QPointF(10, 180);
0176     QTest::addRow("flip-y-90") << OutputTransform::FlipY90 << QPointF(10, 20) << QPointF(180, 90);
0177     QTest::addRow("flip-y-180") << OutputTransform::FlipY180 << QPointF(10, 20) << QPointF(90, 20);
0178     QTest::addRow("flip-y-270") << OutputTransform::FlipY270 << QPointF(10, 20) << QPointF(20, 10);
0179 }
0180 
0181 void TestOutputTransform::mapPointF()
0182 {
0183     QFETCH(OutputTransform::Kind, kind);
0184     QFETCH(QPointF, source);
0185     QFETCH(QPointF, target);
0186 
0187     const OutputTransform transform(kind);
0188 
0189     QCOMPARE(transform.map(source, QSizeF(100, 200)), target);
0190     QCOMPARE(transform.map(QRectF(source, QSizeF(0, 0)), QSizeF(100, 200)), QRectF(target, QSizeF(0, 0)));
0191 }
0192 
0193 void TestOutputTransform::mapPoint_data()
0194 {
0195     QTest::addColumn<OutputTransform::Kind>("kind");
0196     QTest::addColumn<QPoint>("source");
0197     QTest::addColumn<QPoint>("target");
0198 
0199     QTest::addRow("rotate-0") << OutputTransform::Normal << QPoint(10, 20) << QPoint(10, 20);
0200     QTest::addRow("rotate-90") << OutputTransform::Rotate90 << QPoint(10, 20) << QPoint(20, 90);
0201     QTest::addRow("rotate-180") << OutputTransform::Rotate180 << QPoint(10, 20) << QPoint(90, 180);
0202     QTest::addRow("rotate-270") << OutputTransform::Rotate270 << QPoint(10, 20) << QPoint(180, 10);
0203     QTest::addRow("flip-x-0") << OutputTransform::FlipX << QPoint(10, 20) << QPoint(90, 20);
0204     QTest::addRow("flip-x-90") << OutputTransform::FlipX90 << QPoint(10, 20) << QPoint(20, 10);
0205     QTest::addRow("flip-x-180") << OutputTransform::FlipX180 << QPoint(10, 20) << QPoint(10, 180);
0206     QTest::addRow("flip-x-270") << OutputTransform::FlipX270 << QPoint(10, 20) << QPoint(180, 90);
0207     QTest::addRow("flip-y-0") << OutputTransform::FlipY << QPoint(10, 20) << QPoint(10, 180);
0208     QTest::addRow("flip-y-90") << OutputTransform::FlipY90 << QPoint(10, 20) << QPoint(180, 90);
0209     QTest::addRow("flip-y-180") << OutputTransform::FlipY180 << QPoint(10, 20) << QPoint(90, 20);
0210     QTest::addRow("flip-y-270") << OutputTransform::FlipY270 << QPoint(10, 20) << QPoint(20, 10);
0211 }
0212 
0213 void TestOutputTransform::mapPoint()
0214 {
0215     QFETCH(OutputTransform::Kind, kind);
0216     QFETCH(QPoint, source);
0217     QFETCH(QPoint, target);
0218 
0219     const OutputTransform transform(kind);
0220 
0221     QCOMPARE(transform.map(source, QSize(100, 200)), target);
0222     QCOMPARE(transform.map(QRect(source, QSize(0, 0)), QSize(100, 200)), QRect(target, QSize(0, 0)));
0223 }
0224 
0225 void TestOutputTransform::inverted_data()
0226 {
0227     QTest::addColumn<OutputTransform::Kind>("kind");
0228     QTest::addColumn<OutputTransform::Kind>("inverted");
0229 
0230     QTest::addRow("rotate-0") << OutputTransform::Normal << OutputTransform::Normal;
0231     QTest::addRow("rotate-90") << OutputTransform::Rotate90 << OutputTransform::Rotate270;
0232     QTest::addRow("rotate-180") << OutputTransform::Rotate180 << OutputTransform::Rotate180;
0233     QTest::addRow("rotate-270") << OutputTransform::Rotate270 << OutputTransform::Rotate90;
0234     QTest::addRow("flip-x-0") << OutputTransform::FlipX << OutputTransform::FlipX;
0235     QTest::addRow("flip-x-90") << OutputTransform::FlipX90 << OutputTransform::FlipX90;
0236     QTest::addRow("flip-x-180") << OutputTransform::FlipX180 << OutputTransform::FlipX180;
0237     QTest::addRow("flip-x-270") << OutputTransform::FlipX270 << OutputTransform::FlipX270;
0238     QTest::addRow("flip-y-0") << OutputTransform::FlipY << OutputTransform::FlipY;
0239     QTest::addRow("flip-y-90") << OutputTransform::FlipY90 << OutputTransform::FlipY90;
0240     QTest::addRow("flip-y-180") << OutputTransform::FlipY180 << OutputTransform::FlipY180;
0241     QTest::addRow("flip-y-270") << OutputTransform::FlipY270 << OutputTransform::FlipY270;
0242 }
0243 
0244 void TestOutputTransform::inverted()
0245 {
0246     QFETCH(OutputTransform::Kind, kind);
0247     QFETCH(OutputTransform::Kind, inverted);
0248 
0249     QCOMPARE(OutputTransform(kind).inverted(), OutputTransform(inverted));
0250 }
0251 
0252 void TestOutputTransform::combine_data()
0253 {
0254     QTest::addColumn<OutputTransform::Kind>("first");
0255     QTest::addColumn<OutputTransform::Kind>("second");
0256     QTest::addColumn<OutputTransform::Kind>("result");
0257 
0258     QTest::addRow("rotate-0 | rotate-0") << OutputTransform::Normal << OutputTransform::Normal << OutputTransform::Normal;
0259     QTest::addRow("rotate-90 | rotate-0") << OutputTransform::Rotate90 << OutputTransform::Normal << OutputTransform::Rotate90;
0260     QTest::addRow("rotate-180 | rotate-0") << OutputTransform::Rotate180 << OutputTransform::Normal << OutputTransform::Rotate180;
0261     QTest::addRow("rotate-270 | rotate-0") << OutputTransform::Rotate270 << OutputTransform::Normal << OutputTransform::Rotate270;
0262     QTest::addRow("flip-x-0 | rotate-0") << OutputTransform::FlipX << OutputTransform::Normal << OutputTransform::FlipX;
0263     QTest::addRow("flip-x-90 | rotate-0") << OutputTransform::FlipX90 << OutputTransform::Normal << OutputTransform::FlipX90;
0264     QTest::addRow("flip-x-180 | rotate-0") << OutputTransform::FlipX180 << OutputTransform::Normal << OutputTransform::FlipX180;
0265     QTest::addRow("flip-x-270 | rotate-0") << OutputTransform::FlipX270 << OutputTransform::Normal << OutputTransform::FlipX270;
0266     QTest::addRow("flip-y-0 | rotate-0") << OutputTransform::FlipY << OutputTransform::Normal << OutputTransform::FlipY;
0267     QTest::addRow("flip-y-90 | rotate-0") << OutputTransform::FlipY90 << OutputTransform::Normal << OutputTransform::FlipY90;
0268     QTest::addRow("flip-y-180 | rotate-0") << OutputTransform::FlipY180 << OutputTransform::Normal << OutputTransform::FlipY180;
0269     QTest::addRow("flip-y-270 | rotate-0") << OutputTransform::FlipY270 << OutputTransform::Normal << OutputTransform::FlipY270;
0270 
0271     QTest::addRow("rotate-0 | rotate-90") << OutputTransform::Normal << OutputTransform::Rotate90 << OutputTransform::Rotate90;
0272     QTest::addRow("rotate-90 | rotate-90") << OutputTransform::Rotate90 << OutputTransform::Rotate90 << OutputTransform::Rotate180;
0273     QTest::addRow("rotate-180 | rotate-90") << OutputTransform::Rotate180 << OutputTransform::Rotate90 << OutputTransform::Rotate270;
0274     QTest::addRow("rotate-270 | rotate-90") << OutputTransform::Rotate270 << OutputTransform::Rotate90 << OutputTransform::Normal;
0275     QTest::addRow("flip-x-0 | rotate-90") << OutputTransform::FlipX << OutputTransform::Rotate90 << OutputTransform::FlipX90;
0276     QTest::addRow("flip-x-90 | rotate-90") << OutputTransform::FlipX90 << OutputTransform::Rotate90 << OutputTransform::FlipX180;
0277     QTest::addRow("flip-x-180 | rotate-90") << OutputTransform::FlipX180 << OutputTransform::Rotate90 << OutputTransform::FlipX270;
0278     QTest::addRow("flip-x-270 | rotate-90") << OutputTransform::FlipX270 << OutputTransform::Rotate90 << OutputTransform::FlipX;
0279     QTest::addRow("flip-y-0 | rotate-90") << OutputTransform::FlipY << OutputTransform::Rotate90 << OutputTransform::FlipY90;
0280     QTest::addRow("flip-y-90 | rotate-90") << OutputTransform::FlipY90 << OutputTransform::Rotate90 << OutputTransform::FlipY180;
0281     QTest::addRow("flip-y-180 | rotate-90") << OutputTransform::FlipY180 << OutputTransform::Rotate90 << OutputTransform::FlipY270;
0282     QTest::addRow("flip-y-270 | rotate-90") << OutputTransform::FlipY270 << OutputTransform::Rotate90 << OutputTransform::FlipY;
0283 
0284     QTest::addRow("rotate-0 | rotate-180") << OutputTransform::Normal << OutputTransform::Rotate180 << OutputTransform::Rotate180;
0285     QTest::addRow("rotate-90 | rotate-180") << OutputTransform::Rotate90 << OutputTransform::Rotate180 << OutputTransform::Rotate270;
0286     QTest::addRow("rotate-180 | rotate-180") << OutputTransform::Rotate180 << OutputTransform::Rotate180 << OutputTransform::Normal;
0287     QTest::addRow("rotate-270 | rotate-180") << OutputTransform::Rotate270 << OutputTransform::Rotate180 << OutputTransform::Rotate90;
0288     QTest::addRow("flip-x-0 | rotate-180") << OutputTransform::FlipX << OutputTransform::Rotate180 << OutputTransform::FlipX180;
0289     QTest::addRow("flip-x-90 | rotate-180") << OutputTransform::FlipX90 << OutputTransform::Rotate180 << OutputTransform::FlipX270;
0290     QTest::addRow("flip-x-180 | rotate-180") << OutputTransform::FlipX180 << OutputTransform::Rotate180 << OutputTransform::FlipX;
0291     QTest::addRow("flip-x-270 | rotate-180") << OutputTransform::FlipX270 << OutputTransform::Rotate180 << OutputTransform::FlipX90;
0292     QTest::addRow("flip-y-0 | rotate-180") << OutputTransform::FlipY << OutputTransform::Rotate180 << OutputTransform::FlipY180;
0293     QTest::addRow("flip-y-90 | rotate-180") << OutputTransform::FlipY90 << OutputTransform::Rotate180 << OutputTransform::FlipY270;
0294     QTest::addRow("flip-y-180 | rotate-180") << OutputTransform::FlipY180 << OutputTransform::Rotate180 << OutputTransform::FlipY;
0295     QTest::addRow("flip-y-270 | rotate-180") << OutputTransform::FlipY270 << OutputTransform::Rotate180 << OutputTransform::FlipY90;
0296 
0297     QTest::addRow("rotate-0 | rotate-270") << OutputTransform::Normal << OutputTransform::Rotate270 << OutputTransform::Rotate270;
0298     QTest::addRow("rotate-90 | rotate-270") << OutputTransform::Rotate90 << OutputTransform::Rotate270 << OutputTransform::Normal;
0299     QTest::addRow("rotate-180 | rotate-270") << OutputTransform::Rotate180 << OutputTransform::Rotate270 << OutputTransform::Rotate90;
0300     QTest::addRow("rotate-270 | rotate-270") << OutputTransform::Rotate270 << OutputTransform::Rotate270 << OutputTransform::Rotate180;
0301     QTest::addRow("flip-x-0 | rotate-270") << OutputTransform::FlipX << OutputTransform::Rotate270 << OutputTransform::FlipX270;
0302     QTest::addRow("flip-x-90 | rotate-270") << OutputTransform::FlipX90 << OutputTransform::Rotate270 << OutputTransform::FlipX;
0303     QTest::addRow("flip-x-180 | rotate-270") << OutputTransform::FlipX180 << OutputTransform::Rotate270 << OutputTransform::FlipX90;
0304     QTest::addRow("flip-x-270 | rotate-270") << OutputTransform::FlipX270 << OutputTransform::Rotate270 << OutputTransform::FlipX180;
0305     QTest::addRow("flip-y-0 | rotate-270") << OutputTransform::FlipY << OutputTransform::Rotate270 << OutputTransform::FlipY270;
0306     QTest::addRow("flip-y-90 | rotate-270") << OutputTransform::FlipY90 << OutputTransform::Rotate270 << OutputTransform::FlipY;
0307     QTest::addRow("flip-y-180 | rotate-270") << OutputTransform::FlipY180 << OutputTransform::Rotate270 << OutputTransform::FlipY90;
0308     QTest::addRow("flip-y-270 | rotate-270") << OutputTransform::FlipY270 << OutputTransform::Rotate270 << OutputTransform::FlipY180;
0309 
0310     QTest::addRow("rotate-0 | flip-x-0") << OutputTransform::Normal << OutputTransform::FlipX << OutputTransform::FlipX;
0311     QTest::addRow("rotate-90 | flip-x-0") << OutputTransform::Rotate90 << OutputTransform::FlipX << OutputTransform::FlipX270;
0312     QTest::addRow("rotate-180 | flip-x-0") << OutputTransform::Rotate180 << OutputTransform::FlipX << OutputTransform::FlipX180;
0313     QTest::addRow("rotate-270 | flip-x-0") << OutputTransform::Rotate270 << OutputTransform::FlipX << OutputTransform::FlipX90;
0314     QTest::addRow("flip-x-0 | flip-x-0") << OutputTransform::FlipX << OutputTransform::FlipX << OutputTransform::Normal;
0315     QTest::addRow("flip-x-90 | flip-x-0") << OutputTransform::FlipX90 << OutputTransform::FlipX << OutputTransform::Rotate270;
0316     QTest::addRow("flip-x-180 | flip-x-0") << OutputTransform::FlipX180 << OutputTransform::FlipX << OutputTransform::Rotate180;
0317     QTest::addRow("flip-x-270 | flip-x-0") << OutputTransform::FlipX270 << OutputTransform::FlipX << OutputTransform::Rotate90;
0318     QTest::addRow("flip-y-0 | flip-x-0") << OutputTransform::FlipY << OutputTransform::FlipX << OutputTransform::Rotate180;
0319     QTest::addRow("flip-y-90 | flip-x-0") << OutputTransform::FlipY90 << OutputTransform::FlipX << OutputTransform::Rotate90;
0320     QTest::addRow("flip-y-180 | flip-x-0") << OutputTransform::FlipY180 << OutputTransform::FlipX << OutputTransform::Normal;
0321     QTest::addRow("flip-y-270 | flip-x-0") << OutputTransform::FlipY270 << OutputTransform::FlipX << OutputTransform::Rotate270;
0322 
0323     QTest::addRow("rotate-0 | flip-x-90") << OutputTransform::Normal << OutputTransform::FlipX90 << OutputTransform::FlipX90;
0324     QTest::addRow("rotate-90 | flip-x-90") << OutputTransform::Rotate90 << OutputTransform::FlipX90 << OutputTransform::FlipX;
0325     QTest::addRow("rotate-180 | flip-x-90") << OutputTransform::Rotate180 << OutputTransform::FlipX90 << OutputTransform::FlipX270;
0326     QTest::addRow("rotate-270 | flip-x-90") << OutputTransform::Rotate270 << OutputTransform::FlipX90 << OutputTransform::FlipX180;
0327     QTest::addRow("flip-x-0 | flip-x-90") << OutputTransform::FlipX << OutputTransform::FlipX90 << OutputTransform::Rotate90;
0328     QTest::addRow("flip-x-90 | flip-x-90") << OutputTransform::FlipX90 << OutputTransform::FlipX90 << OutputTransform::Normal;
0329     QTest::addRow("flip-x-180 | flip-x-90") << OutputTransform::FlipX180 << OutputTransform::FlipX90 << OutputTransform::Rotate270;
0330     QTest::addRow("flip-x-270 | flip-x-90") << OutputTransform::FlipX270 << OutputTransform::FlipX90 << OutputTransform::Rotate180;
0331     QTest::addRow("flip-y-0 | flip-x-90") << OutputTransform::FlipY << OutputTransform::FlipX90 << OutputTransform::Rotate270;
0332     QTest::addRow("flip-y-90 | flip-x-90") << OutputTransform::FlipY90 << OutputTransform::FlipX90 << OutputTransform::Rotate180;
0333     QTest::addRow("flip-y-180 | flip-x-90") << OutputTransform::FlipY180 << OutputTransform::FlipX90 << OutputTransform::Rotate90;
0334     QTest::addRow("flip-y-270 | flip-x-90") << OutputTransform::FlipY270 << OutputTransform::FlipX90 << OutputTransform::Normal;
0335 
0336     QTest::addRow("rotate-0 | flip-x-180") << OutputTransform::Normal << OutputTransform::FlipX180 << OutputTransform::FlipX180;
0337     QTest::addRow("rotate-90 | flip-x-180") << OutputTransform::Rotate90 << OutputTransform::FlipX180 << OutputTransform::FlipX90;
0338     QTest::addRow("rotate-180 | flip-x-180") << OutputTransform::Rotate180 << OutputTransform::FlipX180 << OutputTransform::FlipX;
0339     QTest::addRow("rotate-270 | flip-x-180") << OutputTransform::Rotate270 << OutputTransform::FlipX180 << OutputTransform::FlipX270;
0340     QTest::addRow("flip-x-0 | flip-x-180") << OutputTransform::FlipX << OutputTransform::FlipX180 << OutputTransform::Rotate180;
0341     QTest::addRow("flip-x-90 | flip-x-180") << OutputTransform::FlipX90 << OutputTransform::FlipX180 << OutputTransform::Rotate90;
0342     QTest::addRow("flip-x-180 | flip-x-180") << OutputTransform::FlipX180 << OutputTransform::FlipX180 << OutputTransform::Normal;
0343     QTest::addRow("flip-x-270 | flip-x-180") << OutputTransform::FlipX270 << OutputTransform::FlipX180 << OutputTransform::Rotate270;
0344     QTest::addRow("flip-y-0 | flip-x-180") << OutputTransform::FlipY << OutputTransform::FlipX180 << OutputTransform::Normal;
0345     QTest::addRow("flip-y-90 | flip-x-180") << OutputTransform::FlipY90 << OutputTransform::FlipX180 << OutputTransform::Rotate270;
0346     QTest::addRow("flip-y-180 | flip-x-180") << OutputTransform::FlipY180 << OutputTransform::FlipX180 << OutputTransform::Rotate180;
0347     QTest::addRow("flip-y-270 | flip-x-180") << OutputTransform::FlipY270 << OutputTransform::FlipX180 << OutputTransform::Rotate90;
0348 
0349     QTest::addRow("rotate-0 | flip-x-270") << OutputTransform::Normal << OutputTransform::FlipX270 << OutputTransform::FlipX270;
0350     QTest::addRow("rotate-90 | flip-x-270") << OutputTransform::Rotate90 << OutputTransform::FlipX270 << OutputTransform::FlipX180;
0351     QTest::addRow("rotate-180 | flip-x-270") << OutputTransform::Rotate180 << OutputTransform::FlipX270 << OutputTransform::FlipX90;
0352     QTest::addRow("rotate-270 | flip-x-270") << OutputTransform::Rotate270 << OutputTransform::FlipX270 << OutputTransform::FlipX;
0353     QTest::addRow("flip-x-0 | flip-x-270") << OutputTransform::FlipX << OutputTransform::FlipX270 << OutputTransform::Rotate270;
0354     QTest::addRow("flip-x-90 | flip-x-270") << OutputTransform::FlipX90 << OutputTransform::FlipX270 << OutputTransform::Rotate180;
0355     QTest::addRow("flip-x-180 | flip-x-270") << OutputTransform::FlipX180 << OutputTransform::FlipX270 << OutputTransform::Rotate90;
0356     QTest::addRow("flip-x-270 | flip-x-270") << OutputTransform::FlipX270 << OutputTransform::FlipX270 << OutputTransform::Normal;
0357     QTest::addRow("flip-y-0 | flip-x-270") << OutputTransform::FlipY << OutputTransform::FlipX270 << OutputTransform::Rotate90;
0358     QTest::addRow("flip-y-90 | flip-x-270") << OutputTransform::FlipY90 << OutputTransform::FlipX270 << OutputTransform::Normal;
0359     QTest::addRow("flip-y-180 | flip-x-270") << OutputTransform::FlipY180 << OutputTransform::FlipX270 << OutputTransform::Rotate270;
0360     QTest::addRow("flip-y-270 | flip-x-270") << OutputTransform::FlipY270 << OutputTransform::FlipX270 << OutputTransform::Rotate180;
0361 
0362     QTest::addRow("rotate-0 | flip-y-0") << OutputTransform::Normal << OutputTransform::FlipY << OutputTransform::FlipY;
0363     QTest::addRow("rotate-90 | flip-y-0") << OutputTransform::Rotate90 << OutputTransform::FlipY << OutputTransform::FlipY270;
0364     QTest::addRow("rotate-180 | flip-y-0") << OutputTransform::Rotate180 << OutputTransform::FlipY << OutputTransform::FlipY180;
0365     QTest::addRow("rotate-270 | flip-y-0") << OutputTransform::Rotate270 << OutputTransform::FlipY << OutputTransform::FlipY90;
0366     QTest::addRow("flip-x-0 | flip-y-0") << OutputTransform::FlipX << OutputTransform::FlipY << OutputTransform::Rotate180;
0367     QTest::addRow("flip-x-90 | flip-y-0") << OutputTransform::FlipX90 << OutputTransform::FlipY << OutputTransform::Rotate90;
0368     QTest::addRow("flip-x-180 | flip-y-0") << OutputTransform::FlipX180 << OutputTransform::FlipY << OutputTransform::Normal;
0369     QTest::addRow("flip-x-270 | flip-y-0") << OutputTransform::FlipX270 << OutputTransform::FlipY << OutputTransform::Rotate270;
0370     QTest::addRow("flip-y-0 | flip-y-0") << OutputTransform::FlipY << OutputTransform::FlipY << OutputTransform::Normal;
0371     QTest::addRow("flip-y-90 | flip-y-0") << OutputTransform::FlipY90 << OutputTransform::FlipY << OutputTransform::Rotate270;
0372     QTest::addRow("flip-y-180 | flip-y-0") << OutputTransform::FlipY180 << OutputTransform::FlipY << OutputTransform::Rotate180;
0373     QTest::addRow("flip-y-270 | flip-y-0") << OutputTransform::FlipY270 << OutputTransform::FlipY << OutputTransform::Rotate90;
0374 
0375     QTest::addRow("rotate-0 | flip-y-90") << OutputTransform::Normal << OutputTransform::FlipY90 << OutputTransform::FlipY90;
0376     QTest::addRow("rotate-90 | flip-y-90") << OutputTransform::Rotate90 << OutputTransform::FlipY90 << OutputTransform::FlipY;
0377     QTest::addRow("rotate-180 | flip-y-90") << OutputTransform::Rotate180 << OutputTransform::FlipY90 << OutputTransform::FlipY270;
0378     QTest::addRow("rotate-270 | flip-y-90") << OutputTransform::Rotate270 << OutputTransform::FlipY90 << OutputTransform::FlipY180;
0379     QTest::addRow("flip-x-0 | flip-y-90") << OutputTransform::FlipX << OutputTransform::FlipY90 << OutputTransform::Rotate270;
0380     QTest::addRow("flip-x-90 | flip-y-90") << OutputTransform::FlipX90 << OutputTransform::FlipY90 << OutputTransform::Rotate180;
0381     QTest::addRow("flip-x-180 | flip-y-90") << OutputTransform::FlipX180 << OutputTransform::FlipY90 << OutputTransform::Rotate90;
0382     QTest::addRow("flip-x-270 | flip-y-90") << OutputTransform::FlipX270 << OutputTransform::FlipY90 << OutputTransform::Normal;
0383     QTest::addRow("flip-y-0 | flip-y-90") << OutputTransform::FlipY << OutputTransform::FlipY90 << OutputTransform::Rotate90;
0384     QTest::addRow("flip-y-90 | flip-y-90") << OutputTransform::FlipY90 << OutputTransform::FlipY90 << OutputTransform::Normal;
0385     QTest::addRow("flip-y-180 | flip-y-90") << OutputTransform::FlipY180 << OutputTransform::FlipY90 << OutputTransform::Rotate270;
0386     QTest::addRow("flip-y-270 | flip-y-90") << OutputTransform::FlipY270 << OutputTransform::FlipY90 << OutputTransform::Rotate180;
0387 
0388     QTest::addRow("rotate-0 | flip-y-180") << OutputTransform::Normal << OutputTransform::FlipY180 << OutputTransform::FlipY180;
0389     QTest::addRow("rotate-90 | flip-y-180") << OutputTransform::Rotate90 << OutputTransform::FlipY180 << OutputTransform::FlipY90;
0390     QTest::addRow("rotate-180 | flip-y-180") << OutputTransform::Rotate180 << OutputTransform::FlipY180 << OutputTransform::FlipY;
0391     QTest::addRow("rotate-270 | flip-y-180") << OutputTransform::Rotate270 << OutputTransform::FlipY180 << OutputTransform::FlipY270;
0392     QTest::addRow("flip-x-0 | flip-y-180") << OutputTransform::FlipX << OutputTransform::FlipY180 << OutputTransform::Normal;
0393     QTest::addRow("flip-x-90 | flip-y-180") << OutputTransform::FlipX90 << OutputTransform::FlipY180 << OutputTransform::Rotate270;
0394     QTest::addRow("flip-x-180 | flip-y-180") << OutputTransform::FlipX180 << OutputTransform::FlipY180 << OutputTransform::Rotate180;
0395     QTest::addRow("flip-x-270 | flip-y-180") << OutputTransform::FlipX270 << OutputTransform::FlipY180 << OutputTransform::Rotate90;
0396     QTest::addRow("flip-y-0 | flip-y-180") << OutputTransform::FlipY << OutputTransform::FlipY180 << OutputTransform::Rotate180;
0397     QTest::addRow("flip-y-90 | flip-y-180") << OutputTransform::FlipY90 << OutputTransform::FlipY180 << OutputTransform::Rotate90;
0398     QTest::addRow("flip-y-180 | flip-y-180") << OutputTransform::FlipY180 << OutputTransform::FlipY180 << OutputTransform::Normal;
0399     QTest::addRow("flip-y-270 | flip-y-180") << OutputTransform::FlipY270 << OutputTransform::FlipY180 << OutputTransform::Rotate270;
0400 
0401     QTest::addRow("rotate-0 | flip-y-270") << OutputTransform::Normal << OutputTransform::FlipY270 << OutputTransform::FlipY270;
0402     QTest::addRow("rotate-90 | flip-y-270") << OutputTransform::Rotate90 << OutputTransform::FlipY270 << OutputTransform::FlipY180;
0403     QTest::addRow("rotate-180 | flip-y-270") << OutputTransform::Rotate180 << OutputTransform::FlipY270 << OutputTransform::FlipY90;
0404     QTest::addRow("rotate-270 | flip-y-270") << OutputTransform::Rotate270 << OutputTransform::FlipY270 << OutputTransform::FlipY;
0405     QTest::addRow("flip-x-0 | flip-y-270") << OutputTransform::FlipX << OutputTransform::FlipY270 << OutputTransform::Rotate90;
0406     QTest::addRow("flip-x-90 | flip-y-270") << OutputTransform::FlipX90 << OutputTransform::FlipY270 << OutputTransform::Normal;
0407     QTest::addRow("flip-x-180 | flip-y-270") << OutputTransform::FlipX180 << OutputTransform::FlipY270 << OutputTransform::Rotate270;
0408     QTest::addRow("flip-x-270 | flip-y-270") << OutputTransform::FlipX270 << OutputTransform::FlipY270 << OutputTransform::Rotate180;
0409     QTest::addRow("flip-y-0 | flip-y-270") << OutputTransform::FlipY << OutputTransform::FlipY270 << OutputTransform::Rotate270;
0410     QTest::addRow("flip-y-90 | flip-y-270") << OutputTransform::FlipY90 << OutputTransform::FlipY270 << OutputTransform::Rotate180;
0411     QTest::addRow("flip-y-180 | flip-y-270") << OutputTransform::FlipY180 << OutputTransform::FlipY270 << OutputTransform::Rotate90;
0412     QTest::addRow("flip-y-270 | flip-y-270") << OutputTransform::FlipY270 << OutputTransform::FlipY270 << OutputTransform::Normal;
0413 }
0414 
0415 void TestOutputTransform::combine()
0416 {
0417     QFETCH(OutputTransform::Kind, first);
0418     QFETCH(OutputTransform::Kind, second);
0419     QFETCH(OutputTransform::Kind, result);
0420 
0421     const OutputTransform firstTransform(first);
0422     const OutputTransform secondTransform(second);
0423     const OutputTransform combinedTransform = firstTransform.combine(secondTransform);
0424     QCOMPARE(combinedTransform.kind(), result);
0425 
0426     const QRectF box(10, 20, 30, 40);
0427     const QSizeF bounds(100, 200);
0428     QCOMPARE(combinedTransform.map(box, bounds), secondTransform.map(firstTransform.map(box, bounds), firstTransform.map(bounds)));
0429 }
0430 
0431 void TestOutputTransform::matrix_data()
0432 {
0433     QTest::addColumn<OutputTransform::Kind>("kind");
0434     QTest::addColumn<QRectF>("source");
0435     QTest::addColumn<QRectF>("target");
0436 
0437     QTest::addRow("rotate-0") << OutputTransform::Normal << QRectF(10, 20, 30, 40) << QRectF(10, 20, 30, 40);
0438     QTest::addRow("rotate-90") << OutputTransform::Rotate90 << QRectF(10, 20, 30, 40) << QRectF(20, 60, 40, 30);
0439     QTest::addRow("rotate-180") << OutputTransform::Rotate180 << QRectF(10, 20, 30, 40) << QRectF(60, 140, 30, 40);
0440     QTest::addRow("rotate-270") << OutputTransform::Rotate270 << QRectF(10, 20, 30, 40) << QRectF(140, 10, 40, 30);
0441     QTest::addRow("flip-x-0") << OutputTransform::FlipX << QRectF(10, 20, 30, 40) << QRectF(60, 20, 30, 40);
0442     QTest::addRow("flip-x-90") << OutputTransform::FlipX90 << QRectF(10, 20, 30, 40) << QRectF(20, 10, 40, 30);
0443     QTest::addRow("flip-x-180") << OutputTransform::FlipX180 << QRectF(10, 20, 30, 40) << QRectF(10, 140, 30, 40);
0444     QTest::addRow("flip-x-270") << OutputTransform::FlipX270 << QRectF(10, 20, 30, 40) << QRectF(140, 60, 40, 30);
0445     QTest::addRow("flip-y-0") << OutputTransform::FlipY << QRectF(10, 20, 30, 40) << QRectF(10, 140, 30, 40);
0446     QTest::addRow("flip-y-90") << OutputTransform::FlipY90 << QRectF(10, 20, 30, 40) << QRectF(140, 60, 40, 30);
0447     QTest::addRow("flip-y-180") << OutputTransform::FlipY180 << QRectF(10, 20, 30, 40) << QRectF(60, 20, 30, 40);
0448     QTest::addRow("flip-y-270") << OutputTransform::FlipY270 << QRectF(10, 20, 30, 40) << QRectF(20, 10, 40, 30);
0449 }
0450 
0451 void TestOutputTransform::matrix()
0452 {
0453     QFETCH(OutputTransform::Kind, kind);
0454     QFETCH(QRectF, source);
0455     QFETCH(QRectF, target);
0456 
0457     const OutputTransform transform = kind;
0458     const QSizeF sourceBounds = QSizeF(100, 200);
0459     const QSizeF targetBounds = transform.map(sourceBounds);
0460 
0461     QMatrix4x4 matrix;
0462     matrix.scale(targetBounds.width(), targetBounds.height());
0463     matrix.translate(0.5, 0.5);
0464     matrix.scale(0.5, -0.5);
0465     matrix.scale(1, -1); // flip the y axis back
0466     matrix *= transform.toMatrix();
0467     matrix.scale(1, -1); // undo ortho() flipping the y axis
0468     matrix.ortho(QRectF(0, 0, sourceBounds.width(), sourceBounds.height()));
0469 
0470     const QRectF mapped = matrix.mapRect(source);
0471     QCOMPARE(mapped, target);
0472     QCOMPARE(mapped, transform.map(source, sourceBounds));
0473 }
0474 
0475 QTEST_MAIN(TestOutputTransform)
0476 
0477 #include "output_transform_test.moc"