cfafa9ea477690e8177dd26dbc3ee79febe0cd1a
[profile/ivi/qtbase.git] / tests / auto / widgets / util / qsystemtrayicon / tst_qsystemtrayicon.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
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 class tst_QSystemTrayIcon: public QObject
51 {
52 Q_OBJECT
53
54 public:
55     tst_QSystemTrayIcon();
56     virtual ~tst_QSystemTrayIcon();
57
58 private slots:
59     void getSetCheck();
60     void showHide();
61     void showMessage();
62     void supportsMessages();
63     void lastWindowClosed();
64 };
65
66 tst_QSystemTrayIcon::tst_QSystemTrayIcon()
67 {
68 }
69
70 tst_QSystemTrayIcon::~tst_QSystemTrayIcon()
71 {
72 }
73
74 // Testing get/set functions
75 void tst_QSystemTrayIcon::showHide()
76 {
77     QSystemTrayIcon icon;
78     icon.setIcon(QIcon("icons/icon.png"));
79     icon.show();
80     icon.setIcon(QIcon("icons/icon.png"));
81     icon.hide();
82 }
83
84 // Testing get/set functions
85 void tst_QSystemTrayIcon::showMessage()
86 {
87     QSystemTrayIcon icon;
88     icon.setIcon(QIcon("icons/icon.png"));
89
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);
94
95     icon.show();
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);
100 }
101
102 // Testing get/set functions
103 void tst_QSystemTrayIcon::getSetCheck()
104 {
105     QSystemTrayIcon icon;
106     QCOMPARE(true, icon.toolTip().isEmpty());
107     icon.setToolTip("testToolTip");
108     QCOMPARE(true, "testToolTip" == icon.toolTip());
109
110     QCOMPARE(true, icon.icon().isNull());
111     icon.setIcon(QIcon("icons/icon.png"));
112     QCOMPARE(false, icon.icon().isNull());
113
114     QMenu menu;
115     QCOMPARE(true, icon.contextMenu() == 0);
116     icon.setContextMenu(&menu);
117     QCOMPARE(false, icon.contextMenu() == 0);
118 }
119
120 void tst_QSystemTrayIcon::supportsMessages()
121 {
122     // ### fixme: Check platforms.
123     QEXPECT_FAIL("", "QTBUG-20978 QSystemTrayIcon is unimplemented for qpa", Abort);
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"