homescreenapp/hsutils/tsrc/t_hsutils/src/t_hswidgetpositioningonorientationchange.cpp
changeset 90 3ac3aaebaee5
equal deleted inserted replaced
86:e4f038c420f7 90:3ac3aaebaee5
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef ONLY_MENU_TESTCASES
       
    19 
       
    20 #include "t_hsutils.h"
       
    21 #include "hswidgetpositioningonorientationchange.h"
       
    22 
       
    23 Q_DECLARE_METATYPE(QList<QRectF>)
       
    24 
       
    25 void t_hsUtils::testWidgetPositioningOnOrientationChangeInstance()
       
    26 {
       
    27     QVERIFY(!HsWidgetPositioningOnOrientationChange::instance());
       
    28     HsWidgetPositioningOnOrientationChange::setInstance(0);
       
    29     QVERIFY(!HsWidgetPositioningOnOrientationChange::instance());
       
    30     HsWidgetPositioningOnOrientationChange *c = new HsAdvancedWidgetPositioningOnOrientationChange;
       
    31     HsWidgetPositioningOnOrientationChange::setInstance(c);
       
    32     QVERIFY(HsWidgetPositioningOnOrientationChange::instance() == c);
       
    33     HsWidgetPositioningOnOrientationChange::setInstance(0);
       
    34     QVERIFY(!HsWidgetPositioningOnOrientationChange::instance());
       
    35 }
       
    36 
       
    37 void t_hsUtils::testAdvancedWidgetPositioningOnOrientationChange_data()
       
    38 {
       
    39     QTest::addColumn<QRectF>("fromRect");
       
    40     QTest::addColumn<QList<QRectF> >("fromGeometries");
       
    41     QTest::addColumn<QRectF>("toRect");
       
    42     QTest::addColumn<QList<QRectF> >("toGeometries");
       
    43 
       
    44     QTest::newRow("portrait to landscape1")
       
    45         << QRectF(0, 0, 100, 200)
       
    46         << (QList<QRectF>() << QRectF(0, 100, 10, 10) << QRectF(90, 0, 10, 10) << QRectF(90, 190, 10, 10) << QRectF(50, 150, 10, 10))
       
    47         << QRectF(0, 0, 200, 100)
       
    48         << (QList<QRectF>() << QRectF(100, 0, 10, 10) << QRectF(90, 0, 10, 10) << QRectF(190, 90, 10, 10) << QRectF(150, 50, 10, 10));
       
    49 
       
    50     QTest::newRow("portrait to landscape2")
       
    51         << QRectF(0, 0, 100, 200)
       
    52         << (QList<QRectF>() << QRectF(0, 94, 10, 10) << QRectF(0, 95, 10, 10) << QRectF(0, 96, 10, 10) << QRectF(-5, 95, 10, 10) << QRectF(-5, 96, 10, 10))
       
    53         << QRectF(0, 0, 200, 100)
       
    54         << (QList<QRectF>() << QRectF(0, 90, 10, 10) << QRectF(100, 0, 10, 10) << QRectF(100, 0, 10, 10) << QRectF(95, 0, 10, 10) << QRectF(95, 0, 10, 10));
       
    55 
       
    56     QTest::newRow("landscape to portrait1")
       
    57         << QRectF(0, 0, 200, 100)
       
    58         << (QList<QRectF>() << QRectF(0, 0, 10, 10) << QRectF(100, 0, 10, 10) << QRectF(90, 0, 10, 10) << QRectF(190, 90, 10, 10) << QRectF(150, 50, 10, 10))
       
    59         << QRectF(0, 0, 100, 200)
       
    60         << (QList<QRectF>() << QRectF(0, 0, 10, 10) << QRectF(90, 100, 10, 10) << QRectF(90, 0, 10, 10) << QRectF(90, 190, 10, 10) << QRectF(90, 150, 10, 10));
       
    61 
       
    62     QTest::newRow("landscape to portrait2")
       
    63         << QRectF(0, 0, 200, 100)
       
    64         << (QList<QRectF>() << QRectF(94, 0, 10, 10) << QRectF(95, 0, 10, 10) << QRectF(96, 0, 10, 10) << QRectF(95, -5, 10, 10) << QRectF(96, -5, 10, 10))
       
    65         << QRectF(0, 0, 100, 200)
       
    66         << (QList<QRectF>() << QRectF(90, 0, 10, 10) << QRectF(90, 100, 10, 10) << QRectF(90, 100, 10, 10) << QRectF(90, 95, 10, 10) << QRectF(90, 95, 10, 10));
       
    67 
       
    68     QTest::newRow("illegal from points")
       
    69         << QRectF(0, 0, 100, 100)
       
    70         << (QList<QRectF>() << QRectF(-50, -50, 10, 10))
       
    71         << QRectF(0, 0, 100, 100)
       
    72         << (QList<QRectF>() << QRectF(0, 0, 10, 10));
       
    73 
       
    74 }
       
    75 
       
    76 void t_hsUtils::testAdvancedWidgetPositioningOnOrientationChange()
       
    77 {
       
    78     QFETCH(QRectF, fromRect);
       
    79     QFETCH(QList<QRectF>, fromGeometries);
       
    80     QFETCH(QRectF, toRect);
       
    81     QFETCH(QList<QRectF>, toGeometries);
       
    82 
       
    83     HsWidgetPositioningOnOrientationChange *converter =
       
    84         new HsAdvancedWidgetPositioningOnOrientationChange;
       
    85     QList<QRectF> convertedGeometries =
       
    86         converter->convert(fromRect, fromGeometries, toRect);
       
    87 
       
    88     QCOMPARE(convertedGeometries.count(), toGeometries.count());
       
    89 
       
    90     for (int i = 0; i < toGeometries.count(); ++i) {
       
    91         QVERIFY(qFuzzyCompare(1 + toGeometries.at(i).x(), 1 + convertedGeometries.at(i).x()));
       
    92         QVERIFY(qFuzzyCompare(1 + toGeometries.at(i).y(), 1 + convertedGeometries.at(i).y()));
       
    93         QVERIFY(qFuzzyCompare(1 + toGeometries.at(i).width(), 1 + convertedGeometries.at(i).width()));
       
    94         QVERIFY(qFuzzyCompare(1 + toGeometries.at(i).height(), 1 + convertedGeometries.at(i).height()));
       
    95     }
       
    96 
       
    97     delete converter;
       
    98 }
       
    99 
       
   100 #endif // ONLY_MENU_TESTCASES