tests/auto/qsystemtrayicon/tst_qsystemtrayicon.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 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 
       
    43 #include <QtTest/QtTest>
       
    44 
       
    45 #include <qcoreapplication.h>
       
    46 #include <qdebug.h>
       
    47 #include <qsystemtrayicon.h>
       
    48 #include <qmenu.h>
       
    49 
       
    50 //TESTED_CLASS=
       
    51 //TESTED_FILES=
       
    52 
       
    53 class tst_QSystemTrayIcon: public QObject
       
    54 {
       
    55 Q_OBJECT
       
    56 
       
    57 public:
       
    58     tst_QSystemTrayIcon();
       
    59     virtual ~tst_QSystemTrayIcon();
       
    60 
       
    61 private slots:
       
    62     void getSetCheck();
       
    63     void showHide();
       
    64     void showMessage();
       
    65     void supportsMessages();
       
    66     void lastWindowClosed();
       
    67 };
       
    68 
       
    69 tst_QSystemTrayIcon::tst_QSystemTrayIcon()
       
    70 {
       
    71 }
       
    72 
       
    73 tst_QSystemTrayIcon::~tst_QSystemTrayIcon()
       
    74 {
       
    75 }
       
    76 
       
    77 // Testing get/set functions
       
    78 void tst_QSystemTrayIcon::showHide()
       
    79 {
       
    80     QSystemTrayIcon icon;
       
    81     icon.setIcon(QIcon("icons/icon.png"));
       
    82     icon.show();
       
    83     icon.setIcon(QIcon("icons/icon.png"));
       
    84     icon.hide();
       
    85 }
       
    86 
       
    87 // Testing get/set functions
       
    88 void tst_QSystemTrayIcon::showMessage()
       
    89 {
       
    90     QSystemTrayIcon icon;
       
    91     icon.setIcon(QIcon("icons/icon.png"));
       
    92 
       
    93     icon.showMessage("Title", "Messagecontents");
       
    94     icon.showMessage("Title", "Messagecontents", QSystemTrayIcon::NoIcon);
       
    95     icon.showMessage("Title", "Messagecontents", QSystemTrayIcon::Warning);
       
    96     icon.showMessage("Title", "Messagecontents", QSystemTrayIcon::Critical);
       
    97 
       
    98     icon.show();
       
    99     icon.showMessage("Title", "Messagecontents");
       
   100     icon.showMessage("Title", "Messagecontents", QSystemTrayIcon::NoIcon);
       
   101     icon.showMessage("Title", "Messagecontents", QSystemTrayIcon::Warning);
       
   102     icon.showMessage("Title", "Messagecontents", QSystemTrayIcon::Critical);
       
   103 }
       
   104 
       
   105 // Testing get/set functions
       
   106 void tst_QSystemTrayIcon::getSetCheck()
       
   107 {
       
   108     QSystemTrayIcon icon;
       
   109     QCOMPARE(true, icon.toolTip().isEmpty());
       
   110     icon.setToolTip("testToolTip");
       
   111     QCOMPARE(true, "testToolTip" == icon.toolTip());
       
   112 
       
   113     QCOMPARE(true, icon.icon().isNull());
       
   114     icon.setIcon(QIcon("icons/icon.png"));
       
   115     QCOMPARE(false, icon.icon().isNull());
       
   116 
       
   117     QMenu menu;
       
   118     QCOMPARE(true, icon.contextMenu() == 0);
       
   119     icon.setContextMenu(&menu);
       
   120     QCOMPARE(false, icon.contextMenu() == 0);
       
   121 }
       
   122 
       
   123 void tst_QSystemTrayIcon::supportsMessages()
       
   124 {
       
   125 #if !defined(Q_WS_QWS)
       
   126     QCOMPARE(QSystemTrayIcon::supportsMessages(), true );
       
   127 #else
       
   128     QCOMPARE(QSystemTrayIcon::supportsMessages(), false );
       
   129 #endif
       
   130 
       
   131 }
       
   132 
       
   133 void tst_QSystemTrayIcon::lastWindowClosed()
       
   134 {
       
   135     QSignalSpy spy(qApp, SIGNAL(lastWindowClosed()));
       
   136     QWidget window;
       
   137     QSystemTrayIcon icon;
       
   138     icon.setIcon(QIcon("whatever.png"));
       
   139     icon.show();
       
   140     window.show();
       
   141     QTimer::singleShot(2500, &window, SLOT(close()));
       
   142     QTimer::singleShot(20000, qApp, SLOT(quit())); // in case the test fails
       
   143     qApp->exec();
       
   144     QVERIFY(spy.count() == 1);
       
   145 }
       
   146 
       
   147 QTEST_MAIN(tst_QSystemTrayIcon)
       
   148 #include "tst_qsystemtrayicon.moc"