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
=== modified file '.bzrignore'
--- .bzrignore 2015-03-06 19:27:55 +0000
+++ .bzrignore 2015-04-16 21:40:33 +0000
@@ -48,6 +48,9 @@
48tests/common/dbus-test-wrapper.sh48tests/common/dbus-test-wrapper.sh
49tests/common/mock/mockconnectionadaptor.*49tests/common/mock/mockconnectionadaptor.*
50tests/common/mock/telepathy-mock50tests/common/mock/telepathy-mock
51tests/common/dbus-session.conf
52tests/common/dbus-services/*
51tests/Ubuntu.Telephony/ContactWatcherTest53tests/Ubuntu.Telephony/ContactWatcherTest
52tests/libtelephonyservice/GreeterContactsTestExe54tests/libtelephonyservice/GreeterContactsTestExe
53tests/libtelephonyservice/GreeterContactsTestServerExe55tests/libtelephonyservice/GreeterContactsTestServerExe
56tests/libtelephonyservice/ToneGeneratorMock
5457
=== modified file 'libtelephonyservice/tonegenerator.cpp'
--- libtelephonyservice/tonegenerator.cpp 2015-04-16 21:40:33 +0000
+++ libtelephonyservice/tonegenerator.cpp 2015-04-16 21:40:33 +0000
@@ -108,7 +108,7 @@
108 stopTone();108 stopTone();
109 }109 }
110110
111 if (startEventTone((uint)79)) {111 if (startEventTone(WAITING_TONE)) {
112 mWaitingPlaybackTimer->start(WAITING_PLAYBACK_DURATION);112 mWaitingPlaybackTimer->start(WAITING_PLAYBACK_DURATION);
113 }113 }
114}114}
@@ -121,6 +121,6 @@
121121
122void ToneGenerator::playCallEndedTone()122void ToneGenerator::playCallEndedTone()
123{123{
124 startEventTone((uint)257);124 startEventTone(CALL_ENDED_TONE);
125 QTimer::singleShot(2000, this, SLOT(stopTone()));125 QTimer::singleShot(2000, this, SLOT(stopTone()));
126}126}
127127
=== modified file 'libtelephonyservice/tonegenerator.h'
--- libtelephonyservice/tonegenerator.h 2014-10-15 22:10:45 +0000
+++ libtelephonyservice/tonegenerator.h 2015-04-16 21:40:33 +0000
@@ -29,6 +29,8 @@
2929
30static const int DTMF_LOCAL_PLAYBACK_DURATION = 200; /* in milliseconds */30static const int DTMF_LOCAL_PLAYBACK_DURATION = 200; /* in milliseconds */
31static const int WAITING_PLAYBACK_DURATION = 8000; /* in milliseconds */31static const int WAITING_PLAYBACK_DURATION = 8000; /* in milliseconds */
32static const uint WAITING_TONE = 79;
33static const uint CALL_ENDED_TONE = 257;
3234
33class ToneGenerator : public QObject35class ToneGenerator : public QObject
34{36{
3537
=== modified file 'tests/libtelephonyservice/CMakeLists.txt'
--- tests/libtelephonyservice/CMakeLists.txt 2015-03-20 21:50:47 +0000
+++ tests/libtelephonyservice/CMakeLists.txt 2015-04-16 21:40:33 +0000
@@ -9,15 +9,25 @@
9add_executable(GreeterContactsTestServerExe GreeterContactsTestServer.cpp)9add_executable(GreeterContactsTestServerExe GreeterContactsTestServer.cpp)
10qt5_use_modules(GreeterContactsTestServerExe Core DBus)10qt5_use_modules(GreeterContactsTestServerExe Core DBus)
1111
12add_executable(ToneGeneratorMock ToneGeneratorMock.cpp)
13qt5_use_modules(ToneGeneratorMock Core DBus)
14
12generate_test(GreeterContactsTest USE_DBUS15generate_test(GreeterContactsTest USE_DBUS
13 SOURCES GreeterContactsTest.cpp ${LIBTELEPHONYSERVICE_DIR}/greetercontacts.cpp16 SOURCES GreeterContactsTest.cpp ${LIBTELEPHONYSERVICE_DIR}/greetercontacts.cpp
14 QT5_MODULES Contacts Core DBus Test17 QT5_MODULES Contacts Core DBus Test
15 ENVIRONMENT XDG_SESSION_CLASS=greeter XDG_GREETER_DATA_DIR=${CMAKE_BINARY_DIR}/Testing/Temporary18 ENVIRONMENT XDG_SESSION_CLASS=greeter XDG_GREETER_DATA_DIR=${CMAKE_BINARY_DIR}/Testing/Temporary
16 TASKS --task env --ignore-return --task ${CMAKE_CURRENT_BINARY_DIR}/GreeterContactsTestServerExe --task-name server --ignore-return19 TASKS --task ${CMAKE_CURRENT_BINARY_DIR}/GreeterContactsTestServerExe --task-name server --ignore-return
17 WAIT_FOR org.freedesktop.Accounts)20 WAIT_FOR org.freedesktop.Accounts)
18set_target_properties(GreeterContactsTest PROPERTIES COMPILE_DEFINITIONS "AS_BUSNAME=sessionBus;CMAKE_SOURCE_DIR=\"${CMAKE_SOURCE_DIR}\"")21set_target_properties(GreeterContactsTest PROPERTIES COMPILE_DEFINITIONS "AS_BUSNAME=sessionBus;CMAKE_SOURCE_DIR=\"${CMAKE_SOURCE_DIR}\"")
19add_dependencies(GreeterContactsTest GreeterContactsTestServerExe)22add_dependencies(GreeterContactsTest GreeterContactsTestServerExe)
2023
24generate_test(ToneGeneratorTest USE_DBUS
25 SOURCES ToneGeneratorTest.cpp ${LIBTELEPHONYSERVICE_DIR}/tonegenerator.cpp
26 QT5_MODULES Core DBus Test
27 TASKS --task ${CMAKE_CURRENT_BINARY_DIR}/ToneGeneratorMock --task-name tone-gen --ignore-return
28 WAIT_FOR com.Nokia.Telephony.Tones)
29add_dependencies(ToneGeneratorTest ToneGeneratorMock)
30
21generate_test(ContactUtilsTest SOURCES ContactUtilsTest.cpp QT5_MODULES Contacts Core Test LIBRARIES telephonyservice USE_UI)31generate_test(ContactUtilsTest SOURCES ContactUtilsTest.cpp QT5_MODULES Contacts Core Test LIBRARIES telephonyservice USE_UI)
22generate_test(PhoneUtilsTest SOURCES PhoneUtilsTest.cpp LIBRARIES telephonyservice USE_UI)32generate_test(PhoneUtilsTest SOURCES PhoneUtilsTest.cpp LIBRARIES telephonyservice USE_UI)
2333
2434
=== added file 'tests/libtelephonyservice/ToneGeneratorMock.cpp'
--- tests/libtelephonyservice/ToneGeneratorMock.cpp 1970-01-01 00:00:00 +0000
+++ tests/libtelephonyservice/ToneGeneratorMock.cpp 2015-04-16 21:40:33 +0000
@@ -0,0 +1,66 @@
1/*
2 * Copyright (C) 2015 Canonical, Ltd.
3 *
4 * This file is part of telephony-service.
5 *
6 * telephony-service is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * telephony-service is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <QObject>
20#include <QCoreApplication>
21#include <QDBusConnection>
22#include <QDBusMessage>
23#include <QDBusObjectPath>
24#include <QDebug>
25
26#define TONEGEN_DBUS_SERVICE_NAME "com.Nokia.Telephony.Tones"
27#define TONEGEN_DBUS_OBJ_PATH "/com/Nokia/Telephony/Tones"
28
29class ToneGeneratorMock : public QObject
30{
31 Q_OBJECT
32 Q_CLASSINFO("D-Bus Interface", TONEGEN_DBUS_SERVICE_NAME)
33
34public:
35 Q_SCRIPTABLE void StartEventTone(uint key, int volume, uint duration);
36 Q_SCRIPTABLE void StopTone();
37
38Q_SIGNALS:
39 Q_SCRIPTABLE void StartEventToneRequested(uint key, int volume, uint duration);
40 Q_SCRIPTABLE void StopToneRequested();
41};
42
43void ToneGeneratorMock::StartEventTone(uint key, int volume, uint duration)
44{
45 Q_EMIT StartEventToneRequested(key, volume, duration);
46}
47
48void ToneGeneratorMock::StopTone()
49{
50 Q_EMIT StopToneRequested();
51}
52
53int main(int argc, char **argv)
54{
55 QCoreApplication a(argc, argv);
56
57 QDBusConnection connection = QDBusConnection::sessionBus();
58
59 ToneGeneratorMock toneGen;
60 connection.registerObject(TONEGEN_DBUS_OBJ_PATH, &toneGen, QDBusConnection::ExportScriptableContents);
61 connection.registerService(TONEGEN_DBUS_SERVICE_NAME);
62
63 return a.exec();
64}
65
66#include "ToneGeneratorMock.moc"
067
=== added file 'tests/libtelephonyservice/ToneGeneratorTest.cpp'
--- tests/libtelephonyservice/ToneGeneratorTest.cpp 1970-01-01 00:00:00 +0000
+++ tests/libtelephonyservice/ToneGeneratorTest.cpp 2015-04-16 21:40:33 +0000
@@ -0,0 +1,134 @@
1/*
2 * Copyright (C) 2015 Canonical, Ltd.
3 *
4 * This file is part of telephony-service.
5 *
6 * telephony-service is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * telephony-service is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <QtCore/QObject>
20#include <QtTest/QtTest>
21#include <QDBusInterface>
22
23#include "tonegenerator.h"
24
25#define TONEGEN_DBUS_SERVICE_NAME "com.Nokia.Telephony.Tones"
26#define TONEGEN_DBUS_OBJ_PATH "/com/Nokia/Telephony/Tones"
27
28class ToneGeneratorTest : public QObject
29{
30 Q_OBJECT
31
32private Q_SLOTS:
33 void initTestCase();
34 void cleanupTestCase();
35 void cleanup();
36 void testSingleTone_data();
37 void testSingleTone();
38 void testMultipleTones();
39 void testWaitingTone();
40 void testCallEndedTone();
41
42private:
43 QDBusInterface *mToneInterface;
44 QSignalSpy *mStartToneSpy;
45 QSignalSpy *mStopToneSpy;
46};
47
48void ToneGeneratorTest::initTestCase()
49{
50 mToneInterface = new QDBusInterface(TONEGEN_DBUS_SERVICE_NAME,
51 TONEGEN_DBUS_OBJ_PATH,
52 TONEGEN_DBUS_SERVICE_NAME,
53 QDBusConnection::sessionBus(),
54 this);
55
56 mStartToneSpy = new QSignalSpy(mToneInterface, SIGNAL(StartEventToneRequested(uint, int, uint)));
57 mStopToneSpy = new QSignalSpy(mToneInterface,SIGNAL(StopToneRequested()));
58}
59
60void ToneGeneratorTest::cleanupTestCase()
61{
62 mToneInterface->deleteLater();
63 mStartToneSpy->deleteLater();
64 mStopToneSpy->deleteLater();
65}
66
67void ToneGeneratorTest::cleanup()
68{
69 mStartToneSpy->clear();
70 mStopToneSpy->clear();
71}
72
73void ToneGeneratorTest::testSingleTone_data()
74{
75 QTest::addColumn<uint>("key");
76
77 QTest::newRow("0") << (uint)0;
78 QTest::newRow("1") << (uint)1;
79 QTest::newRow("2") << (uint)2;
80 QTest::newRow("3") << (uint)3;
81 QTest::newRow("4") << (uint)4;
82 QTest::newRow("5") << (uint)5;
83 QTest::newRow("6") << (uint)6;
84 QTest::newRow("7") << (uint)7;
85 QTest::newRow("8") << (uint)8;
86 QTest::newRow("9") << (uint)9;
87 QTest::newRow("10") << (uint)10;
88 QTest::newRow("11") << (uint)11;
89}
90
91void ToneGeneratorTest::testSingleTone()
92{
93 QFETCH(uint, key);
94
95 ToneGenerator::instance()->playDTMFTone(key);
96 QTRY_COMPARE(mStartToneSpy->count(), 1);
97 QCOMPARE(mStartToneSpy->first()[0].toUInt(), key);
98
99 QTRY_COMPARE(mStopToneSpy->count(), 1);
100}
101
102void ToneGeneratorTest::testMultipleTones()
103{
104 int count = 12;
105 for (uint key = 0; key < count; ++key) {
106 ToneGenerator::instance()->playDTMFTone(key);
107 }
108
109 QTRY_COMPARE(mStartToneSpy->count(), count);
110 QTRY_COMPARE(mStopToneSpy->count(), 1);
111}
112
113void ToneGeneratorTest::testWaitingTone()
114{
115 ToneGenerator::instance()->playWaitingTone();
116 QTRY_COMPARE(mStartToneSpy->count(), 1);
117 QCOMPARE(mStartToneSpy->first()[0].toUInt(), WAITING_TONE);
118
119 ToneGenerator::instance()->stopWaitingTone();
120 QTRY_COMPARE(mStopToneSpy->count(), 1);
121}
122
123void ToneGeneratorTest::testCallEndedTone()
124{
125 ToneGenerator::instance()->playCallEndedTone();
126
127 QTRY_COMPARE(mStartToneSpy->count(), 1);
128 QCOMPARE(mStartToneSpy->first()[0].toUInt(), CALL_ENDED_TONE);
129
130 QTRY_COMPARE(mStopToneSpy->count(), 1);
131}
132
133QTEST_MAIN(ToneGeneratorTest)
134#include "ToneGeneratorTest.moc"

Subscribers

People subscribed via source and target branches