Add a pointer to Qt coding style
[profile/ivi/ofono-qt.git] / tests / test_ofonomessagewaiting.cpp
1 /*
2  * This file is part of ofono-qt
3  *
4  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
5  *
6  * Contact: Alexander Kanavin <alexander.kanavin@nokia.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * version 2.1 as published by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  *
22  */
23
24 #include <QtTest/QtTest>
25 #include <QtCore/QObject>
26
27 #include <ofonomessagewaiting.h>
28
29 #include <QtDebug>
30
31 class TestOfonoMessageWaiting : public QObject
32 {
33     Q_OBJECT
34
35 private slots:
36
37     void initTestCase()
38     {
39         m = new OfonoMessageWaiting(OfonoModem::ManualSelect, "/phonesim", this);
40         QCOMPARE(m->modem()->isValid(), true);  
41
42         if (!m->modem()->powered()) {
43             m->modem()->setPowered(true);
44             QTest::qWait(5000);
45         }
46         if (!m->modem()->online()) {
47             m->modem()->setOnline(true);
48             QTest::qWait(5000);
49         }
50         QCOMPARE(m->isValid(), true);    
51     }
52
53     void testOfonoMessageWaiting()
54     {
55         QSignalSpy waiting(m, SIGNAL(voicemailWaitingChanged(bool)));    
56         QSignalSpy messageCount(m, SIGNAL(voicemailMessageCountChanged(int)));
57         QSignalSpy mailboxNumber(m, SIGNAL(voicemailMailboxNumberChanged(QString)));
58         QSignalSpy setNumberFailed(m, SIGNAL(setVoicemailMailboxNumberFailed()));
59
60         QCOMPARE(m->voicemailWaiting(), true);
61         QCOMPARE(m->voicemailMessageCount(), 1);
62         QCOMPARE(m->voicemailMailboxNumber(), QString("6789"));
63
64         m->modem()->setOnline(false);
65         QTest::qWait(5000);
66         QCOMPARE(waiting.count(), 0);
67         QCOMPARE(messageCount.count(), 0);
68         QCOMPARE(mailboxNumber.count(), 0);
69         QCOMPARE(setNumberFailed.count(), 0);
70
71         m->modem()->setOnline(true);
72         QTest::qWait(5000);
73         QCOMPARE(waiting.count(), 1);
74         QCOMPARE(waiting.takeFirst().at(0).toBool(), true);
75         QCOMPARE(messageCount.count(), 1);
76         QCOMPARE(messageCount.takeFirst().at(0).toInt(), 1);
77         QCOMPARE(mailboxNumber.count(), 1);
78         QCOMPARE(mailboxNumber.takeFirst().at(0).toString(), QString("6789"));
79         QCOMPARE(setNumberFailed.count(), 0);
80     }
81
82     void testOfonoMessageWaitingSet()
83     {
84         QSignalSpy waiting(m, SIGNAL(voicemailWaitingChanged(bool)));    
85         QSignalSpy messageCount(m, SIGNAL(voicemailMessageCountChanged(int)));
86         QSignalSpy mailboxNumber(m, SIGNAL(voicemailMailboxNumberChanged(QString)));
87         QSignalSpy setNumberFailed(m, SIGNAL(setVoicemailMailboxNumberFailed()));
88
89         QString number = m->voicemailMailboxNumber();
90         
91         m->setVoicemailMailboxNumber("");
92         QTest::qWait(1000);
93         QCOMPARE(waiting.count(), 0);
94         QCOMPARE(messageCount.count(), 0);
95         QCOMPARE(mailboxNumber.count(), 0);
96         QCOMPARE(setNumberFailed.count(), 1);
97         setNumberFailed.takeFirst();
98
99         m->setVoicemailMailboxNumber("1234");
100         QTest::qWait(1000);
101         QCOMPARE(waiting.count(), 0);
102         QCOMPARE(messageCount.count(), 0);
103         QCOMPARE(mailboxNumber.count(), 1);
104         QCOMPARE(mailboxNumber.takeFirst().at(0).toString(), QString("1234"));
105         QCOMPARE(setNumberFailed.count(), 0);
106
107         m->setVoicemailMailboxNumber(number);
108         QTest::qWait(1000);
109         QCOMPARE(waiting.count(), 0);
110         QCOMPARE(messageCount.count(), 0);
111         QCOMPARE(mailboxNumber.count(), 1);
112         QCOMPARE(mailboxNumber.takeFirst().at(0).toString(), number);
113         QCOMPARE(setNumberFailed.count(), 0);
114     }
115
116
117     void cleanupTestCase()
118     {
119
120     }
121
122
123 private:
124     OfonoMessageWaiting *m;
125 };
126
127 QTEST_MAIN(TestOfonoMessageWaiting)
128 #include "test_ofonomessagewaiting.moc"