tests/auto/declarative/qdeclarativesystempalette/tst_qdeclarativesystempalette.cpp
branchGCC_SURGE
changeset 31 5daf16870df6
parent 30 5dc02b23752f
child 33 3e2da88830cd
equal deleted inserted replaced
27:93b982ccede2 31:5daf16870df6
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the test suite of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include <qtest.h>
       
    43 #include <QDebug>
       
    44 #include <QtDeclarative/qdeclarativeengine.h>
       
    45 #include <QtDeclarative/qdeclarativecomponent.h>
       
    46 #include <private/qdeclarativesystempalette_p.h>
       
    47 #include <qpalette.h>
       
    48 #include "../../../shared/util.h"
       
    49 
       
    50 class tst_qdeclarativesystempalette : public QObject
       
    51 
       
    52 {
       
    53     Q_OBJECT
       
    54 public:
       
    55     tst_qdeclarativesystempalette();
       
    56 
       
    57 private slots:
       
    58     void activePalette();
       
    59     void inactivePalette();
       
    60     void disabledPalette();
       
    61     void paletteChanged();
       
    62 
       
    63 private:
       
    64     QDeclarativeEngine engine;
       
    65 };
       
    66 
       
    67 tst_qdeclarativesystempalette::tst_qdeclarativesystempalette()
       
    68 {
       
    69 }
       
    70 
       
    71 void tst_qdeclarativesystempalette::activePalette()
       
    72 {
       
    73     QString componentStr = "import Qt 4.7\nSystemPalette { }";
       
    74     QDeclarativeComponent component(&engine);
       
    75     component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
       
    76     QDeclarativeSystemPalette *object = qobject_cast<QDeclarativeSystemPalette*>(component.create());
       
    77 
       
    78     QVERIFY(object != 0);
       
    79 
       
    80     QPalette palette;
       
    81     palette.setCurrentColorGroup(QPalette::Active);
       
    82     QCOMPARE(palette.window().color(), object->window());
       
    83     QCOMPARE(palette.windowText().color(), object->windowText());
       
    84     QCOMPARE(palette.base().color(), object->base());
       
    85     QCOMPARE(palette.text().color(), object->text());
       
    86     QCOMPARE(palette.alternateBase().color(), object->alternateBase());
       
    87     QCOMPARE(palette.button().color(), object->button());
       
    88     QCOMPARE(palette.buttonText().color(), object->buttonText());
       
    89     QCOMPARE(palette.light().color(), object->light());
       
    90     QCOMPARE(palette.midlight().color(), object->midlight());
       
    91     QCOMPARE(palette.dark().color(), object->dark());
       
    92     QCOMPARE(palette.mid().color(), object->mid());
       
    93     QCOMPARE(palette.shadow().color(), object->shadow());
       
    94     QCOMPARE(palette.highlight().color(), object->highlight());
       
    95     QCOMPARE(palette.highlightedText().color(), object->highlightedText());
       
    96 
       
    97     delete object;
       
    98 }
       
    99 
       
   100 void tst_qdeclarativesystempalette::inactivePalette()
       
   101 {
       
   102     QString componentStr = "import Qt 4.7\nSystemPalette { colorGroup: SystemPalette.Inactive }";
       
   103     QDeclarativeComponent component(&engine);
       
   104     component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
       
   105     QDeclarativeSystemPalette *object = qobject_cast<QDeclarativeSystemPalette*>(component.create());
       
   106 
       
   107     QVERIFY(object != 0);
       
   108     QVERIFY(object->colorGroup() == QDeclarativeSystemPalette::Inactive);
       
   109 
       
   110     QPalette palette;
       
   111     palette.setCurrentColorGroup(QPalette::Inactive);
       
   112     QCOMPARE(palette.window().color(), object->window());
       
   113     QCOMPARE(palette.windowText().color(), object->windowText());
       
   114     QCOMPARE(palette.base().color(), object->base());
       
   115     QCOMPARE(palette.text().color(), object->text());
       
   116     QCOMPARE(palette.alternateBase().color(), object->alternateBase());
       
   117     QCOMPARE(palette.button().color(), object->button());
       
   118     QCOMPARE(palette.buttonText().color(), object->buttonText());
       
   119     QCOMPARE(palette.light().color(), object->light());
       
   120     QCOMPARE(palette.midlight().color(), object->midlight());
       
   121     QCOMPARE(palette.dark().color(), object->dark());
       
   122     QCOMPARE(palette.mid().color(), object->mid());
       
   123     QCOMPARE(palette.shadow().color(), object->shadow());
       
   124     QCOMPARE(palette.highlight().color(), object->highlight());
       
   125     QCOMPARE(palette.highlightedText().color(), object->highlightedText());
       
   126 
       
   127     delete object;
       
   128 }
       
   129 
       
   130 void tst_qdeclarativesystempalette::disabledPalette()
       
   131 {
       
   132     QString componentStr = "import Qt 4.7\nSystemPalette { colorGroup: SystemPalette.Disabled }";
       
   133     QDeclarativeComponent component(&engine);
       
   134     component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
       
   135     QDeclarativeSystemPalette *object = qobject_cast<QDeclarativeSystemPalette*>(component.create());
       
   136 
       
   137     QVERIFY(object != 0);
       
   138     QVERIFY(object->colorGroup() == QDeclarativeSystemPalette::Disabled);
       
   139 
       
   140     QPalette palette;
       
   141     palette.setCurrentColorGroup(QPalette::Disabled);
       
   142     QCOMPARE(palette.window().color(), object->window());
       
   143     QCOMPARE(palette.windowText().color(), object->windowText());
       
   144     QCOMPARE(palette.base().color(), object->base());
       
   145     QCOMPARE(palette.text().color(), object->text());
       
   146     QCOMPARE(palette.alternateBase().color(), object->alternateBase());
       
   147     QCOMPARE(palette.button().color(), object->button());
       
   148     QCOMPARE(palette.buttonText().color(), object->buttonText());
       
   149     QCOMPARE(palette.light().color(), object->light());
       
   150     QCOMPARE(palette.midlight().color(), object->midlight());
       
   151     QCOMPARE(palette.dark().color(), object->dark());
       
   152     QCOMPARE(palette.mid().color(), object->mid());
       
   153     QCOMPARE(palette.shadow().color(), object->shadow());
       
   154     QCOMPARE(palette.highlight().color(), object->highlight());
       
   155     QCOMPARE(palette.highlightedText().color(), object->highlightedText());
       
   156 
       
   157     delete object;
       
   158 }
       
   159 
       
   160 void tst_qdeclarativesystempalette::paletteChanged()
       
   161 {
       
   162     QString componentStr = "import Qt 4.7\nSystemPalette { }";
       
   163     QDeclarativeComponent component(&engine);
       
   164     component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
       
   165     QDeclarativeSystemPalette *object = qobject_cast<QDeclarativeSystemPalette*>(component.create());
       
   166 
       
   167     QVERIFY(object != 0);
       
   168 
       
   169     QPalette p;
       
   170     p.setCurrentColorGroup(QPalette::Active);
       
   171     p.setColor(QPalette::Active, QPalette::Text, QColor("red"));
       
   172     p.setColor(QPalette::Active, QPalette::ButtonText, QColor("green"));
       
   173     p.setColor(QPalette::Active, QPalette::WindowText, QColor("blue"));
       
   174 
       
   175     qApp->setPalette(p);
       
   176 
       
   177     object->setColorGroup(QDeclarativeSystemPalette::Active);
       
   178     QTRY_COMPARE(QColor("red"), object->text());
       
   179     QTRY_COMPARE(QColor("green"), object->buttonText());
       
   180     QTRY_COMPARE(QColor("blue"), object->windowText());
       
   181 
       
   182     delete object;
       
   183 }
       
   184 
       
   185 QTEST_MAIN(tst_qdeclarativesystempalette)
       
   186 
       
   187 #include "tst_qdeclarativesystempalette.moc"