1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
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 
tst_QSystemTrayIcon()69 tst_QSystemTrayIcon::tst_QSystemTrayIcon()
70 {
71 }
72 
~tst_QSystemTrayIcon()73 tst_QSystemTrayIcon::~tst_QSystemTrayIcon()
74 {
75 }
76 
77 // Testing get/set functions
showHide()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
showMessage()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
getSetCheck()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 
supportsMessages()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 
lastWindowClosed()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"
149