1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the test suite of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
43 #include <QtTest/QtTest>
45 #include <qcoreapplication.h>
47 #include <qsystemtrayicon.h>
50 class tst_QSystemTrayIcon: public QObject
55 tst_QSystemTrayIcon();
56 virtual ~tst_QSystemTrayIcon();
62 void supportsMessages();
63 void lastWindowClosed();
66 tst_QSystemTrayIcon::tst_QSystemTrayIcon()
70 tst_QSystemTrayIcon::~tst_QSystemTrayIcon()
74 // Testing get/set functions
75 void tst_QSystemTrayIcon::showHide()
78 icon.setIcon(QIcon("icons/icon.png"));
80 icon.setIcon(QIcon("icons/icon.png"));
84 // Testing get/set functions
85 void tst_QSystemTrayIcon::showMessage()
88 icon.setIcon(QIcon("icons/icon.png"));
90 icon.showMessage("Title", "Messagecontents");
91 icon.showMessage("Title", "Messagecontents", QSystemTrayIcon::NoIcon);
92 icon.showMessage("Title", "Messagecontents", QSystemTrayIcon::Warning);
93 icon.showMessage("Title", "Messagecontents", QSystemTrayIcon::Critical);
96 icon.showMessage("Title", "Messagecontents");
97 icon.showMessage("Title", "Messagecontents", QSystemTrayIcon::NoIcon);
98 icon.showMessage("Title", "Messagecontents", QSystemTrayIcon::Warning);
99 icon.showMessage("Title", "Messagecontents", QSystemTrayIcon::Critical);
102 // Testing get/set functions
103 void tst_QSystemTrayIcon::getSetCheck()
105 QSystemTrayIcon icon;
106 QCOMPARE(true, icon.toolTip().isEmpty());
107 icon.setToolTip("testToolTip");
108 QCOMPARE(true, "testToolTip" == icon.toolTip());
110 QCOMPARE(true, icon.icon().isNull());
111 icon.setIcon(QIcon("icons/icon.png"));
112 QCOMPARE(false, icon.icon().isNull());
115 QCOMPARE(true, icon.contextMenu() == 0);
116 icon.setContextMenu(&menu);
117 QCOMPARE(false, icon.contextMenu() == 0);
120 void tst_QSystemTrayIcon::supportsMessages()
122 // ### fixme: Check platforms.
123 QEXPECT_FAIL("", "QTBUG-20978 QSystemTrayIcon is unimplemented for qpa", Abort);
125 #if !defined(Q_WS_QWS)
126 QCOMPARE(QSystemTrayIcon::supportsMessages(), true );
128 QCOMPARE(QSystemTrayIcon::supportsMessages(), false );
133 void tst_QSystemTrayIcon::lastWindowClosed()
135 QSignalSpy spy(qApp, SIGNAL(lastWindowClosed()));
137 QSystemTrayIcon icon;
138 icon.setIcon(QIcon("whatever.png"));
141 QTimer::singleShot(2500, &window, SLOT(close()));
142 QTimer::singleShot(20000, qApp, SLOT(quit())); // in case the test fails
144 QVERIFY(spy.count() == 1);
147 QTEST_MAIN(tst_QSystemTrayIcon)
148 #include "tst_qsystemtrayicon.moc"