Change contact email address as the nokia one will be no longer valid soon
[profile/ivi/ofono-qt.git] / tests / test_ofonocallvolume.cpp
1 /*
2  * This file is part of ofono-qt
3  *
4  * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
5  *
6  * Contact: Alexander Kanavin <alex.kanavin@gmail.com>
7  * Author: Arun Ravindran <ext-arun.1.ravindran@nokia.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * version 2.1 as published by the Free Software Foundation.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  *
23  */
24
25 #include <QtTest/QtTest>
26 #include <QtCore/QObject>
27
28 #include <ofonocallvolume.h>
29
30 #include <QtDebug>
31
32 class TestOfonoCallVolume : public QObject
33 {
34     Q_OBJECT
35
36 private slots:
37     void initTestCase()
38     {
39
40         m = new OfonoCallVolume(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 testOfonoCallVolume()
55     {
56
57         QSignalSpy mutedChanged(m, SIGNAL(mutedChanged(const bool)));
58         QSignalSpy speakerVolumeChanged(m, SIGNAL(speakerVolumeChanged(const quint8)));
59         QSignalSpy microphoneVolumeChanged(m, SIGNAL(microphoneVolumeChanged(const quint8)));
60         QSignalSpy spfail(m, SIGNAL(setSpeakerVolumeFailed()));
61         QSignalSpy mvfail(m, SIGNAL(setMicrophoneVolumeFailed()));
62
63         m->modem()->setPowered(false);
64         QTest::qWait(5000);
65         m->modem()->setPowered(true);
66         QTest::qWait(5000);
67         m->modem()->setOnline(true);
68         QTest::qWait(5000);
69
70         m->setMuted(true);
71         QTest::qWait(2000);
72         QCOMPARE(mutedChanged.count(), 1);
73         QVERIFY(mutedChanged.takeFirst().at(0).toBool()==bool(true));
74         QVERIFY(m->muted()==bool(true));
75
76         m->setMuted(false);
77         QTest::qWait(2000);
78         QCOMPARE(mutedChanged.count(), 1);
79         QVERIFY(mutedChanged.takeFirst().at(0).toBool()==bool(false));
80         QVERIFY(m->muted()==bool(false));
81
82
83         m->setSpeakerVolume(quint8(15));
84         QTest::qWait(2000);
85         QCOMPARE(speakerVolumeChanged.count(), 1);
86         QCOMPARE(quint8(speakerVolumeChanged.takeFirst().at(0).toUInt()), quint8(15));
87         QCOMPARE(m->speakerVolume(),quint8(15));
88
89         m->setSpeakerVolume(quint8(250));
90         QTest::qWait(2000);
91         QCOMPARE(spfail.count(), 1);
92
93         m->setMicrophoneVolume(quint8(10));
94         QTest::qWait(2000);
95         QCOMPARE(mvfail.count(), 1);
96
97     }
98     void cleanupTestCase()
99     {
100
101     }
102
103
104 private:
105     OfonoCallVolume *m;
106 };
107
108 QTEST_MAIN(TestOfonoCallVolume)
109 #include "test_ofonocallvolume.moc"