29f8cf0a05bb34666eabd8d16fe4a19d59787d5f
[situare] / tests / ui / sidepanel / testsidepanel.cpp
1  /*
2     Situare - A location system for Facebook
3     Copyright (C) 2010  Ixonos Plc. Authors:
4
5         Kaj Wallin - kaj.wallin@ixonos.com
6
7     Situare is free software; you can redistribute it and/or
8     modify it under the terms of the GNU General Public License
9     version 2 as published by the Free Software Foundation.
10
11     Situare is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with Situare; if not, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
19     USA.
20  */
21
22
23
24 #include <QtTest/QtTest>
25 #include <QtCore>
26 #include "ui/sidepanel.h"
27
28 class TestSidePanel : public QObject
29 {
30     Q_OBJECT
31
32 private slots:
33     void testPanelTypes();
34     void testPanelToggling();
35 };
36
37 void TestSidePanel::testPanelTypes()
38 {
39     SidePanel *testPanel = new SidePanel();
40     testPanel->setType(SidePanel::UserPanel);
41     QCOMPARE(testPanel->objectName(), QString("UserPanel"));
42     delete testPanel;
43
44     testPanel = new SidePanel();
45     testPanel->setType(SidePanel::FriendPanel);
46     QCOMPARE(testPanel->objectName(), QString("FriendPanel"));
47     delete testPanel;
48 }
49
50 void TestSidePanel::testPanelToggling()
51 {
52     SidePanel *testPanel = new SidePanel();
53     testPanel->setType(SidePanel::UserPanel);
54     QSignalSpy toggleSpy(testPanel, SIGNAL(toggleState()));
55
56     QVERIFY(toggleSpy.isValid());
57     QCOMPARE(toggleSpy.count(),0);
58
59     //Try to close the panel. As the panel is closed, no toggle signal should be sent
60     testPanel->closePanel();
61     QTest::qWait(1);
62     QCOMPARE(toggleSpy.count(),0);
63
64     //Now try to open the panel. Signal should be sent
65     testPanel->openPanel();
66     QTest::qWait(1);
67     QCOMPARE(toggleSpy.count(), 1);
68
69     //Now try to open the panel again. Signal should not be sent as the panel is already open
70     testPanel->openPanel();
71     QTest::qWait(1);
72     QCOMPARE(toggleSpy.count(), 1);
73
74     //Now try to close the panel, signal should be sent
75     testPanel->closePanel();
76     QTest::qWait(1);
77     QCOMPARE(toggleSpy.count(), 2);
78     delete testPanel;
79 }
80 QTEST_MAIN(TestSidePanel)
81 #include "testsidepanel.moc"