abc518ccbaca696378cd7d776783a32234d8b909
[profile/ivi/ofono-qt.git] / tests / test_ofonomessagemanager.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 <ofonomessagemanager.h>
28
29 #include <QtDebug>
30
31
32 class TestOfonoMessageManager : public QObject
33 {
34     Q_OBJECT
35
36 private slots:
37
38     void initTestCase()
39     {
40         m = new OfonoMessageManager(OfonoModem::ManualSelect, "/phonesim", this);
41         QCOMPARE(m->modem()->isValid(), true);  
42
43         if (!m->modem()->powered()) {
44             m->modem()->setPowered(true);
45             QTest::qWait(5000);
46         }
47         if (!m->modem()->online()) {
48             m->modem()->setOnline(true);
49             QTest::qWait(5000);
50         }
51         QCOMPARE(m->isValid(), true);    
52     }
53
54     void testOfonoMessageManagerSca()
55     {
56         QSignalSpy scaComplete(m, SIGNAL(serviceCenterAddressComplete(bool, QString)));
57         m->requestServiceCenterAddress();
58         for (int i=0; i<30; i++) {
59             if (scaComplete.count() > 0)
60                 break;
61             QTest::qWait(1000);
62         }
63         QCOMPARE(scaComplete.count(), 1);
64         QVariantList params = scaComplete.takeFirst();
65         QCOMPARE(params.at(0).toBool(), true);
66         QString sca = params.at(1).toString();
67         QVERIFY(sca.length() > 0);
68         qDebug() << sca;
69
70         QSignalSpy setScaFailed(m, SIGNAL(setServiceCenterAddressFailed()));
71         QSignalSpy scaChanged(m, SIGNAL(serviceCenterAddressChanged(QString)));
72
73         m->setServiceCenterAddress("+12345678");
74         for (int i=0; i<30; i++) {
75             if (setScaFailed.count() > 0 || scaChanged.count() > 0)
76                 break;
77             QTest::qWait(1000);
78         }
79         QCOMPARE(setScaFailed.count(), 0);
80         QCOMPARE(scaChanged.count(), 1);
81         QCOMPARE(scaChanged.takeFirst().at(0).toString(), QString("+12345678"));
82
83         m->setServiceCenterAddress("");
84         for (int i=0; i<30; i++) {
85             if (setScaFailed.count() > 0 || scaChanged.count() > 0)
86                 break;
87             QTest::qWait(1000);
88         }
89         QCOMPARE(setScaFailed.count(), 1);
90         setScaFailed.takeFirst();
91         QCOMPARE(scaChanged.count(), 0);
92         QCOMPARE(m->errorName(), QString("org.ofono.Error.InvalidFormat"));
93         QCOMPARE(m->errorMessage(), QString("Argument format is not recognized"));
94         
95         m->setServiceCenterAddress(sca);
96         for (int i=0; i<30; i++) {
97             if (setScaFailed.count() > 0 || scaChanged.count() > 0)
98                 break;
99             QTest::qWait(1000);
100         }
101         QCOMPARE(setScaFailed.count(), 0);
102         QCOMPARE(scaChanged.count(), 1);
103         QCOMPARE(scaChanged.takeFirst().at(0).toString(), sca);
104     }
105
106
107     void cleanupTestCase()
108     {
109
110     }
111
112
113 private:
114     OfonoMessageManager *m;
115 };
116
117 QTEST_MAIN(TestOfonoMessageManager)
118 #include "test_ofonomessagemanager.moc"