Merge lp:~boiko/telephony-service/test_tone_generator into lp:telephony-service

Proposed by Gustavo Pichorim Boiko
Status: Merged
Approved by: Tiago Salem Herrmann
Approved revision: 1056
Merged at revision: 1060
Proposed branch: lp:~boiko/telephony-service/test_tone_generator
Merge into: lp:telephony-service
Prerequisite: lp:~vicamo/telephony-service/send-stop-tone-at-last
Diff against target: 288 lines (+218/-3)
6 files modified
.bzrignore (+3/-0)
libtelephonyservice/tonegenerator.cpp (+2/-2)
libtelephonyservice/tonegenerator.h (+2/-0)
tests/libtelephonyservice/CMakeLists.txt (+11/-1)
tests/libtelephonyservice/ToneGeneratorMock.cpp (+66/-0)
tests/libtelephonyservice/ToneGeneratorTest.cpp (+134/-0)
To merge this branch: bzr merge lp:~boiko/telephony-service/test_tone_generator
Reviewer Review Type Date Requested Status
Tiago Salem Herrmann (community) Approve
PS Jenkins bot continuous-integration Needs Fixing
Review via email: mp+256573@code.launchpad.net

Commit message

Add unit tests for the ToneGenerator class.

Description of the change

Add unit tests for the ToneGenerator class.

== Checklist ==
Are there any related MPs required for this MP to build/function as expected? Please list.
Yes: https://code.launchpad.net/~vicamo/telephony-service/send-stop-tone-at-last/+merge/248214

Is your branch in sync with latest trunk (e.g. bzr pull lp:trunk -> no changes)
Yes

Did you perform an exploratory manual test run of your code change and any related functionality on device or emulator?
Yes

Did you successfully run all tests found in your component's Test Plan (https://wiki.ubuntu.com/Process/Merges/TestPlan/<package-name>) on device or emulator?
Yes

If you changed the UI, was the change specified/approved by design?
N/A

If you changed UI labels, did you update the pot file?
N/A

If you changed the packaging (debian), did you add a core-dev as a reviewer to this MP?
N/A

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Tiago Salem Herrmann (tiagosh) wrote :

Looks good.

--checklist--
Did you perform an exploratory manual test run of the code change and any related functionality on device or emulator?
Yes

Did CI run pass? If not, please explain why.
No, not related to the changes

Have you checked that submitter has accurately filled out the submitter checklist and has taken no shortcut?
Yes

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2015-03-06 19:27:55 +0000
3+++ .bzrignore 2015-04-16 21:40:33 +0000
4@@ -48,6 +48,9 @@
5 tests/common/dbus-test-wrapper.sh
6 tests/common/mock/mockconnectionadaptor.*
7 tests/common/mock/telepathy-mock
8+tests/common/dbus-session.conf
9+tests/common/dbus-services/*
10 tests/Ubuntu.Telephony/ContactWatcherTest
11 tests/libtelephonyservice/GreeterContactsTestExe
12 tests/libtelephonyservice/GreeterContactsTestServerExe
13+tests/libtelephonyservice/ToneGeneratorMock
14
15=== modified file 'libtelephonyservice/tonegenerator.cpp'
16--- libtelephonyservice/tonegenerator.cpp 2015-04-16 21:40:33 +0000
17+++ libtelephonyservice/tonegenerator.cpp 2015-04-16 21:40:33 +0000
18@@ -108,7 +108,7 @@
19 stopTone();
20 }
21
22- if (startEventTone((uint)79)) {
23+ if (startEventTone(WAITING_TONE)) {
24 mWaitingPlaybackTimer->start(WAITING_PLAYBACK_DURATION);
25 }
26 }
27@@ -121,6 +121,6 @@
28
29 void ToneGenerator::playCallEndedTone()
30 {
31- startEventTone((uint)257);
32+ startEventTone(CALL_ENDED_TONE);
33 QTimer::singleShot(2000, this, SLOT(stopTone()));
34 }
35
36=== modified file 'libtelephonyservice/tonegenerator.h'
37--- libtelephonyservice/tonegenerator.h 2014-10-15 22:10:45 +0000
38+++ libtelephonyservice/tonegenerator.h 2015-04-16 21:40:33 +0000
39@@ -29,6 +29,8 @@
40
41 static const int DTMF_LOCAL_PLAYBACK_DURATION = 200; /* in milliseconds */
42 static const int WAITING_PLAYBACK_DURATION = 8000; /* in milliseconds */
43+static const uint WAITING_TONE = 79;
44+static const uint CALL_ENDED_TONE = 257;
45
46 class ToneGenerator : public QObject
47 {
48
49=== modified file 'tests/libtelephonyservice/CMakeLists.txt'
50--- tests/libtelephonyservice/CMakeLists.txt 2015-03-20 21:50:47 +0000
51+++ tests/libtelephonyservice/CMakeLists.txt 2015-04-16 21:40:33 +0000
52@@ -9,15 +9,25 @@
53 add_executable(GreeterContactsTestServerExe GreeterContactsTestServer.cpp)
54 qt5_use_modules(GreeterContactsTestServerExe Core DBus)
55
56+add_executable(ToneGeneratorMock ToneGeneratorMock.cpp)
57+qt5_use_modules(ToneGeneratorMock Core DBus)
58+
59 generate_test(GreeterContactsTest USE_DBUS
60 SOURCES GreeterContactsTest.cpp ${LIBTELEPHONYSERVICE_DIR}/greetercontacts.cpp
61 QT5_MODULES Contacts Core DBus Test
62 ENVIRONMENT XDG_SESSION_CLASS=greeter XDG_GREETER_DATA_DIR=${CMAKE_BINARY_DIR}/Testing/Temporary
63- TASKS --task env --ignore-return --task ${CMAKE_CURRENT_BINARY_DIR}/GreeterContactsTestServerExe --task-name server --ignore-return
64+ TASKS --task ${CMAKE_CURRENT_BINARY_DIR}/GreeterContactsTestServerExe --task-name server --ignore-return
65 WAIT_FOR org.freedesktop.Accounts)
66 set_target_properties(GreeterContactsTest PROPERTIES COMPILE_DEFINITIONS "AS_BUSNAME=sessionBus;CMAKE_SOURCE_DIR=\"${CMAKE_SOURCE_DIR}\"")
67 add_dependencies(GreeterContactsTest GreeterContactsTestServerExe)
68
69+generate_test(ToneGeneratorTest USE_DBUS
70+ SOURCES ToneGeneratorTest.cpp ${LIBTELEPHONYSERVICE_DIR}/tonegenerator.cpp
71+ QT5_MODULES Core DBus Test
72+ TASKS --task ${CMAKE_CURRENT_BINARY_DIR}/ToneGeneratorMock --task-name tone-gen --ignore-return
73+ WAIT_FOR com.Nokia.Telephony.Tones)
74+add_dependencies(ToneGeneratorTest ToneGeneratorMock)
75+
76 generate_test(ContactUtilsTest SOURCES ContactUtilsTest.cpp QT5_MODULES Contacts Core Test LIBRARIES telephonyservice USE_UI)
77 generate_test(PhoneUtilsTest SOURCES PhoneUtilsTest.cpp LIBRARIES telephonyservice USE_UI)
78
79
80=== added file 'tests/libtelephonyservice/ToneGeneratorMock.cpp'
81--- tests/libtelephonyservice/ToneGeneratorMock.cpp 1970-01-01 00:00:00 +0000
82+++ tests/libtelephonyservice/ToneGeneratorMock.cpp 2015-04-16 21:40:33 +0000
83@@ -0,0 +1,66 @@
84+/*
85+ * Copyright (C) 2015 Canonical, Ltd.
86+ *
87+ * This file is part of telephony-service.
88+ *
89+ * telephony-service is free software; you can redistribute it and/or modify
90+ * it under the terms of the GNU General Public License as published by
91+ * the Free Software Foundation; version 3.
92+ *
93+ * telephony-service is distributed in the hope that it will be useful,
94+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
95+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
96+ * GNU General Public License for more details.
97+ *
98+ * You should have received a copy of the GNU General Public License
99+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
100+ */
101+
102+#include <QObject>
103+#include <QCoreApplication>
104+#include <QDBusConnection>
105+#include <QDBusMessage>
106+#include <QDBusObjectPath>
107+#include <QDebug>
108+
109+#define TONEGEN_DBUS_SERVICE_NAME "com.Nokia.Telephony.Tones"
110+#define TONEGEN_DBUS_OBJ_PATH "/com/Nokia/Telephony/Tones"
111+
112+class ToneGeneratorMock : public QObject
113+{
114+ Q_OBJECT
115+ Q_CLASSINFO("D-Bus Interface", TONEGEN_DBUS_SERVICE_NAME)
116+
117+public:
118+ Q_SCRIPTABLE void StartEventTone(uint key, int volume, uint duration);
119+ Q_SCRIPTABLE void StopTone();
120+
121+Q_SIGNALS:
122+ Q_SCRIPTABLE void StartEventToneRequested(uint key, int volume, uint duration);
123+ Q_SCRIPTABLE void StopToneRequested();
124+};
125+
126+void ToneGeneratorMock::StartEventTone(uint key, int volume, uint duration)
127+{
128+ Q_EMIT StartEventToneRequested(key, volume, duration);
129+}
130+
131+void ToneGeneratorMock::StopTone()
132+{
133+ Q_EMIT StopToneRequested();
134+}
135+
136+int main(int argc, char **argv)
137+{
138+ QCoreApplication a(argc, argv);
139+
140+ QDBusConnection connection = QDBusConnection::sessionBus();
141+
142+ ToneGeneratorMock toneGen;
143+ connection.registerObject(TONEGEN_DBUS_OBJ_PATH, &toneGen, QDBusConnection::ExportScriptableContents);
144+ connection.registerService(TONEGEN_DBUS_SERVICE_NAME);
145+
146+ return a.exec();
147+}
148+
149+#include "ToneGeneratorMock.moc"
150
151=== added file 'tests/libtelephonyservice/ToneGeneratorTest.cpp'
152--- tests/libtelephonyservice/ToneGeneratorTest.cpp 1970-01-01 00:00:00 +0000
153+++ tests/libtelephonyservice/ToneGeneratorTest.cpp 2015-04-16 21:40:33 +0000
154@@ -0,0 +1,134 @@
155+/*
156+ * Copyright (C) 2015 Canonical, Ltd.
157+ *
158+ * This file is part of telephony-service.
159+ *
160+ * telephony-service is free software; you can redistribute it and/or modify
161+ * it under the terms of the GNU General Public License as published by
162+ * the Free Software Foundation; version 3.
163+ *
164+ * telephony-service is distributed in the hope that it will be useful,
165+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
166+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
167+ * GNU General Public License for more details.
168+ *
169+ * You should have received a copy of the GNU General Public License
170+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
171+ */
172+
173+#include <QtCore/QObject>
174+#include <QtTest/QtTest>
175+#include <QDBusInterface>
176+
177+#include "tonegenerator.h"
178+
179+#define TONEGEN_DBUS_SERVICE_NAME "com.Nokia.Telephony.Tones"
180+#define TONEGEN_DBUS_OBJ_PATH "/com/Nokia/Telephony/Tones"
181+
182+class ToneGeneratorTest : public QObject
183+{
184+ Q_OBJECT
185+
186+private Q_SLOTS:
187+ void initTestCase();
188+ void cleanupTestCase();
189+ void cleanup();
190+ void testSingleTone_data();
191+ void testSingleTone();
192+ void testMultipleTones();
193+ void testWaitingTone();
194+ void testCallEndedTone();
195+
196+private:
197+ QDBusInterface *mToneInterface;
198+ QSignalSpy *mStartToneSpy;
199+ QSignalSpy *mStopToneSpy;
200+};
201+
202+void ToneGeneratorTest::initTestCase()
203+{
204+ mToneInterface = new QDBusInterface(TONEGEN_DBUS_SERVICE_NAME,
205+ TONEGEN_DBUS_OBJ_PATH,
206+ TONEGEN_DBUS_SERVICE_NAME,
207+ QDBusConnection::sessionBus(),
208+ this);
209+
210+ mStartToneSpy = new QSignalSpy(mToneInterface, SIGNAL(StartEventToneRequested(uint, int, uint)));
211+ mStopToneSpy = new QSignalSpy(mToneInterface,SIGNAL(StopToneRequested()));
212+}
213+
214+void ToneGeneratorTest::cleanupTestCase()
215+{
216+ mToneInterface->deleteLater();
217+ mStartToneSpy->deleteLater();
218+ mStopToneSpy->deleteLater();
219+}
220+
221+void ToneGeneratorTest::cleanup()
222+{
223+ mStartToneSpy->clear();
224+ mStopToneSpy->clear();
225+}
226+
227+void ToneGeneratorTest::testSingleTone_data()
228+{
229+ QTest::addColumn<uint>("key");
230+
231+ QTest::newRow("0") << (uint)0;
232+ QTest::newRow("1") << (uint)1;
233+ QTest::newRow("2") << (uint)2;
234+ QTest::newRow("3") << (uint)3;
235+ QTest::newRow("4") << (uint)4;
236+ QTest::newRow("5") << (uint)5;
237+ QTest::newRow("6") << (uint)6;
238+ QTest::newRow("7") << (uint)7;
239+ QTest::newRow("8") << (uint)8;
240+ QTest::newRow("9") << (uint)9;
241+ QTest::newRow("10") << (uint)10;
242+ QTest::newRow("11") << (uint)11;
243+}
244+
245+void ToneGeneratorTest::testSingleTone()
246+{
247+ QFETCH(uint, key);
248+
249+ ToneGenerator::instance()->playDTMFTone(key);
250+ QTRY_COMPARE(mStartToneSpy->count(), 1);
251+ QCOMPARE(mStartToneSpy->first()[0].toUInt(), key);
252+
253+ QTRY_COMPARE(mStopToneSpy->count(), 1);
254+}
255+
256+void ToneGeneratorTest::testMultipleTones()
257+{
258+ int count = 12;
259+ for (uint key = 0; key < count; ++key) {
260+ ToneGenerator::instance()->playDTMFTone(key);
261+ }
262+
263+ QTRY_COMPARE(mStartToneSpy->count(), count);
264+ QTRY_COMPARE(mStopToneSpy->count(), 1);
265+}
266+
267+void ToneGeneratorTest::testWaitingTone()
268+{
269+ ToneGenerator::instance()->playWaitingTone();
270+ QTRY_COMPARE(mStartToneSpy->count(), 1);
271+ QCOMPARE(mStartToneSpy->first()[0].toUInt(), WAITING_TONE);
272+
273+ ToneGenerator::instance()->stopWaitingTone();
274+ QTRY_COMPARE(mStopToneSpy->count(), 1);
275+}
276+
277+void ToneGeneratorTest::testCallEndedTone()
278+{
279+ ToneGenerator::instance()->playCallEndedTone();
280+
281+ QTRY_COMPARE(mStartToneSpy->count(), 1);
282+ QCOMPARE(mStartToneSpy->first()[0].toUInt(), CALL_ENDED_TONE);
283+
284+ QTRY_COMPARE(mStopToneSpy->count(), 1);
285+}
286+
287+QTEST_MAIN(ToneGeneratorTest)
288+#include "ToneGeneratorTest.moc"

Subscribers

People subscribed via source and target branches