Merge lp:~boiko/telephony-service/non_phone_accounts_tests into lp:telephony-service
- non_phone_accounts_tests
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Tiago Salem Herrmann |
Approved revision: | 1078 |
Merged at revision: | 1046 |
Proposed branch: | lp:~boiko/telephony-service/non_phone_accounts_tests |
Merge into: | lp:telephony-service |
Prerequisite: | lp:~boiko/telephony-service/support_non_phone_accounts |
Diff against target: |
5175 lines (+3357/-703) 63 files modified
.bzrignore (+9/-6) CMakeLists.txt (+29/-19) Ubuntu/Telephony/CMakeLists.txt (+2/-1) Ubuntu/Telephony/contactwatcher.cpp (+4/-0) approver/CMakeLists.txt (+2/-0) cmake/modules/GenerateTest.cmake (+133/-0) handler/CMakeLists.txt (+2/-6) handler/handler.cpp (+1/-0) handler/tests/dbus-test-wrapper.sh.in (+0/-35) handler/tests/telepathyhelper.cpp (+0/-279) handler/tests/telepathyhelper.h (+0/-95) indicator/CMakeLists.txt (+2/-0) libtelephonyservice/CMakeLists.txt (+1/-1) libtelephonyservice/accountentry.cpp (+8/-10) libtelephonyservice/accountentryfactory.cpp (+1/-5) libtelephonyservice/accountentryfactory.h (+0/-2) libtelephonyservice/channelobserver.cpp (+1/-0) libtelephonyservice/chatmanager.cpp (+7/-2) libtelephonyservice/chatmanager.h (+2/-2) libtelephonyservice/ofonoaccountentry.cpp (+0/-1) libtelephonyservice/telepathyhelper.cpp (+11/-5) libtelephonyservice/telepathyhelper.h (+1/-0) tests/CMakeLists.txt (+6/-0) tests/Ubuntu.Telephony/CMakeLists.txt (+13/-29) tests/Ubuntu.Telephony/ContactWatcherTest.cpp (+5/-0) tests/common/CMakeLists.txt (+14/-0) tests/common/dbus-services/CMakeLists.txt (+9/-0) tests/common/dbus-session.conf.in (+42/-0) tests/common/mock/CMakeLists.txt (+4/-1) tests/common/mock/MockConnection.xml (+60/-0) tests/common/mock/callchannel.cpp (+1/-1) tests/common/mock/connection.cpp (+215/-50) tests/common/mock/connection.h (+41/-4) tests/common/mock/emergencymodeiface.cpp (+133/-0) tests/common/mock/emergencymodeiface.h (+121/-0) tests/common/mock/main.cpp (+7/-0) tests/common/mock/mockconnectiondbus.cpp (+52/-2) tests/common/mock/mockconnectiondbus.h (+19/-0) tests/common/mock/protocol.cpp (+13/-0) tests/common/mock/protocol.h (+1/-0) tests/common/mock/speakeriface.h (+5/-4) tests/common/mock/textchannel.cpp (+70/-8) tests/common/mock/textchannel.h (+10/-2) tests/common/mock/ussdiface.cpp (+312/-0) tests/common/mock/ussdiface.h (+244/-0) tests/common/mock/voicemailiface.cpp (+202/-0) tests/common/mock/voicemailiface.h (+150/-0) tests/common/mockcontroller.cpp (+68/-21) tests/common/mockcontroller.h (+19/-2) tests/common/telepathytest.cpp (+140/-0) tests/common/telepathytest.h (+54/-0) tests/handler/CMakeLists.txt (+4/-38) tests/handler/HandlerTest.cpp (+52/-28) tests/handler/approver.cpp (+1/-0) tests/libtelephonyservice/AccountEntryFactoryTest.cpp (+67/-0) tests/libtelephonyservice/AccountEntryTest.cpp (+228/-0) tests/libtelephonyservice/CMakeLists.txt (+21/-37) tests/libtelephonyservice/ChatManagerTest.cpp (+177/-0) tests/libtelephonyservice/ContactUtilsTest.cpp (+0/-2) tests/libtelephonyservice/GreeterContactsTest.cpp (+2/-4) tests/libtelephonyservice/GreeterContactsTestServer.cpp (+0/-1) tests/libtelephonyservice/OfonoAccountEntryTest.cpp (+273/-0) tests/libtelephonyservice/TelepathyHelperTest.cpp (+286/-0) |
To merge this branch: | bzr merge lp:~boiko/telephony-service/non_phone_accounts_tests |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tiago Salem Herrmann (community) | Approve | ||
PS Jenkins bot | continuous-integration | Needs Fixing | |
Review via email: mp+252522@code.launchpad.net |
Commit message
- Move all tests to root/tests to make it easier to share components
- Add tests to existing components
- Add tests to make sure supporting non-phone based accounts works
- Fix problems found while writing the tests.
- Fix coverage reports
Description of the change
- Move all tests to root/tests to make it easier to share components
- Add tests to existing components
- Add tests to make sure supporting non-phone based accounts works
- Fix problems found while writing the tests.
- Fix coverage reports
== Checklist ==
Are there any related MPs required for this MP to build/function as expected? Please list.
Yes: https:/
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:/
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
- 1043. By Gustavo Pichorim Boiko
-
Revert pot file changes.
PS Jenkins bot (ps-jenkins) wrote : | # |
- 1044. By Gustavo Pichorim Boiko
-
Test the custom interfaces used for the telephony stuff (voicemail, emergency numbers and serial)
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1044
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 1045. By Gustavo Pichorim Boiko
-
Remove extra signal emission.
- 1046. By Gustavo Pichorim Boiko
-
Test SIM locked and fix the serial test.
- 1047. By Gustavo Pichorim Boiko
-
Test emergency calls available.
- 1048. By Gustavo Pichorim Boiko
-
Test the remaining bits on OfonoAccountEntry.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1048
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 1049. By Gustavo Pichorim Boiko
-
Start adding TelepathyHelper tests.
- 1050. By Gustavo Pichorim Boiko
-
Merge latest changes from parent branch.
- 1051. By Gustavo Pichorim Boiko
-
Test more account stuff on TelepathyHelper.
- 1052. By Gustavo Pichorim Boiko
-
Revert pot changes again.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1052
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 1053. By Gustavo Pichorim Boiko
-
Merge latest changes from parent branch.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1053
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 1054. By Gustavo Pichorim Boiko
-
Launch the tests using xvfb-run.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1054
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 1055. By Gustavo Pichorim Boiko
-
Run the dbus tests using a stripped down services directory and a custom config
to prevent running unwanted stuff from the system.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1055
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 1056. By Gustavo Pichorim Boiko
-
Add some waiting time to prevent races.
- 1057. By Gustavo Pichorim Boiko
-
Clear the temporary directory every time.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1057
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 1058. By Gustavo Pichorim Boiko
-
Start mission-control manually to be able to stop it at the end of testing.
- 1059. By Gustavo Pichorim Boiko
-
Pass the temp dir as an argument and increase timeout, just in case.
- 1060. By Gustavo Pichorim Boiko
-
Output the xml with the test results in case of failures to help debugging.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1059
http://
Executed test runs:
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 1061. By Gustavo Pichorim Boiko
-
Add more debugging to figure out what is going on.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1061
http://
Executed test runs:
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 1062. By Gustavo Pichorim Boiko
-
Merge latest changes from parent branch.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1062
http://
Executed test runs:
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 1063. By Gustavo Pichorim Boiko
-
Increase some timeouts in a hope they fix the tests.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1063
http://
Executed test runs:
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 1064. By Gustavo Pichorim Boiko
-
Refactor the generate_test() function to make it more flexible and possibly more
reliable for the dbus tests. - 1065. By Gustavo Pichorim Boiko
-
Start refactoring the tests to use a common baseclass that will make sure all tests
start fresh. - 1066. By Gustavo Pichorim Boiko
-
Do not overwrite the disconnected() signal.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1065
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1066
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 1067. By Gustavo Pichorim Boiko
-
Remove some leftover debugs.
Reimplement the BaseConnection::uniqueName( ) to make sure it is really unique
during the mock CM lifetime.
Port the ChatManagerTest to the new infrastructure. - 1068. By Gustavo Pichorim Boiko
-
Change the TelepathyHelperTest to use the new infrastructure.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1067
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1068
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 1069. By Gustavo Pichorim Boiko
-
Some more stability fixes.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1069
http://
Executed test runs:
SUCCESS: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 1070. By Gustavo Pichorim Boiko
-
Remove dbus monitor.
- 1071. By Gustavo Pichorim Boiko
-
Merge latest changes from parent branch.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1071
http://
Executed test runs:
SUCCESS: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 1072. By Gustavo Pichorim Boiko
-
Output test results both in xunitxml and stdout plain text.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1072
http://
Executed test runs:
SUCCESS: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 1073. By Gustavo Pichorim Boiko
-
Merge latest changes from parent branch, and make the tests a bit more reliable
by waiting for the call channels to close before removing the accounts. - 1074. By Gustavo Pichorim Boiko
-
Set the protocol info feature for accounts.
- 1075. By Gustavo Pichorim Boiko
-
Make sure the addressable fields are loaded correctly, and add tests
to guarantee that.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1075
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
Tiago Salem Herrmann (tiagosh) : | # |
Gustavo Pichorim Boiko (boiko) wrote : | # |
One diff comment replied.
- 1076. By Gustavo Pichorim Boiko
-
Fix the documentation of the USSD Serial method
- 1077. By Gustavo Pichorim Boiko
-
Fix the default timeout.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1077
http://
Executed test runs:
SUCCESS: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 1078. By Gustavo Pichorim Boiko
-
Just to prevent timeouts on high load builders, change from 30secs to 1 minute.
Also, give sime time for the serial property to propagate.
Tiago Salem Herrmann (tiagosh) wrote : | # |
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, but they do locally. There must be something wrong with jenkins setup.
Have you checked that submitter has accurately filled out the submitter checklist and has taken no shortcut?
Yes
Preview Diff
1 | === modified file '.bzrignore' |
2 | --- .bzrignore 2014-01-07 19:53:45 +0000 |
3 | +++ .bzrignore 2015-03-30 20:55:55 +0000 |
4 | @@ -32,19 +32,22 @@ |
5 | handler/handleradaptor.* |
6 | indicator/*.desktop |
7 | indicator/*.service |
8 | +indicator/NotificationsInterface.* |
9 | |
10 | Testing |
11 | -Ubuntu/Telephony/tests/*Test |
12 | Ubuntu/Telephony/qmldir |
13 | -libtelephonyservice/tests/*Test |
14 | CTestTestfile.cmake |
15 | test_*.xml |
16 | +cmake_uninstall.cmake |
17 | |
18 | coverage* |
19 | |
20 | po/*.gmo |
21 | |
22 | -handler/tests/HandlerTest |
23 | -handler/tests/dbus-test-wrapper.sh |
24 | -handler/tests/mock/mockconnectionadaptor.* |
25 | -handler/tests/mock/telepathy-mock |
26 | +tests/*/*Test |
27 | +tests/common/dbus-test-wrapper.sh |
28 | +tests/common/mock/mockconnectionadaptor.* |
29 | +tests/common/mock/telepathy-mock |
30 | +tests/Ubuntu.Telephony/ContactWatcherTest |
31 | +tests/libtelephonyservice/GreeterContactsTestExe |
32 | +tests/libtelephonyservice/GreeterContactsTestServerExe |
33 | |
34 | === modified file 'CMakeLists.txt' |
35 | --- CMakeLists.txt 2014-08-05 20:04:00 +0000 |
36 | +++ CMakeLists.txt 2015-03-30 20:55:55 +0000 |
37 | @@ -9,23 +9,6 @@ |
38 | include(CheckIncludeFileCXX) |
39 | include(CheckIncludeFile) |
40 | |
41 | -include(EnableCoverageReport) |
42 | -##################################################################### |
43 | -# Enable code coverage calculation with gcov/gcovr/lcov |
44 | -# Usage: |
45 | -# * Switch build type to coverage (use ccmake or cmake-gui) |
46 | -# * Invoke make, make test, make coverage |
47 | -# * Find html report in subdir coveragereport |
48 | -# * Find xml report feasible for jenkins in coverage.xml |
49 | -##################################################################### |
50 | -IF(CMAKE_BUILD_TYPE MATCHES [cC][oO][vV][eE][rR][aA][gG][eE]) |
51 | - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftest-coverage -fprofile-arcs" ) |
52 | - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftest-coverage -fprofile-arcs" ) |
53 | - SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -coverage" ) |
54 | - SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -coverage" ) |
55 | - ENABLE_COVERAGE_REPORT(TARGETS ${PHONE_APP}) |
56 | -ENDIF(CMAKE_BUILD_TYPE MATCHES [cC][oO][vV][eE][rR][aA][gG][eE]) |
57 | - |
58 | # Instruct CMake to run moc automatically when needed. |
59 | set(CMAKE_AUTOMOC ON) |
60 | |
61 | @@ -36,8 +19,6 @@ |
62 | add_definitions(-DUSE_UBUNTU_PLATFORM_API) |
63 | endif (USE_UBUNTU_PLATFORM_API) |
64 | |
65 | -find_program(DBUS_RUNNER dbus-test-runner) |
66 | - |
67 | set(TELEPHONY_SERVICE_DIR ${CMAKE_INSTALL_DATADIR}/telephony-service) |
68 | |
69 | configure_file(config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h @ONLY) |
70 | @@ -81,6 +62,14 @@ |
71 | ${CMAKE_CURRENT_SOURCE_DIR} |
72 | ) |
73 | |
74 | +# generate a macro to make it easier to enable coverage support on targets |
75 | +function(ENABLE_COVERAGE) |
76 | + get_directory_property(COVERAGE_TARGETS DIRECTORY ${CMAKE_SOURCE_DIR} COVERAGE_TARGETS) |
77 | + list(APPEND COVERAGE_TARGETS ${ARGN}) |
78 | + MESSAGE(STATUS "Enabling coverage report for target(s): ${ARGN}") |
79 | + set_property(DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY COVERAGE_TARGETS ${COVERAGE_TARGETS}) |
80 | +endfunction() |
81 | + |
82 | enable_testing() |
83 | |
84 | add_definitions(-std=c++11) |
85 | @@ -98,3 +87,24 @@ |
86 | add_subdirectory(tools) |
87 | add_subdirectory(icons) |
88 | add_subdirectory(po) |
89 | +add_subdirectory(tests) |
90 | + |
91 | +include(EnableCoverageReport) |
92 | +##################################################################### |
93 | +# Enable code coverage calculation with gcov/gcovr/lcov |
94 | +# Usage: |
95 | +# * Switch build type to coverage (use ccmake or cmake-gui) |
96 | +# * Invoke make, make test, make coverage |
97 | +# * Find html report in subdir coveragereport |
98 | +# * Find xml report feasible for jenkins in coverage.xml |
99 | +##################################################################### |
100 | +IF(CMAKE_BUILD_TYPE MATCHES [cC][oO][vV][eE][rR][aA][gG][eE]) |
101 | + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftest-coverage -fprofile-arcs" ) |
102 | + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftest-coverage -fprofile-arcs" ) |
103 | + SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -coverage" ) |
104 | + SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -coverage" ) |
105 | + GET_DIRECTORY_PROPERTY(COVERAGE_TARGETS DIRECTORY ${CMAKE_SOURCE_DIR} COVERAGE_TARGETS) |
106 | + ENABLE_COVERAGE_REPORT(TARGETS ${COVERAGE_TARGETS}) |
107 | +ENDIF(CMAKE_BUILD_TYPE MATCHES [cC][oO][vV][eE][rR][aA][gG][eE]) |
108 | + |
109 | + |
110 | |
111 | === modified file 'Ubuntu/Telephony/CMakeLists.txt' |
112 | --- Ubuntu/Telephony/CMakeLists.txt 2014-04-23 20:55:13 +0000 |
113 | +++ Ubuntu/Telephony/CMakeLists.txt 2015-03-30 20:55:55 +0000 |
114 | @@ -19,10 +19,11 @@ |
115 | telephonyservice |
116 | ) |
117 | |
118 | +enable_coverage(telephonyservice-qml) |
119 | + |
120 | configure_file(qmldir.in ${CMAKE_CURRENT_BINARY_DIR}/qmldir) |
121 | set(PLUGIN_DIR ${QT_INSTALL_QML}/Ubuntu/Telephony) |
122 | install(TARGETS telephonyservice-qml DESTINATION ${PLUGIN_DIR}) |
123 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qmldir DESTINATION ${PLUGIN_DIR}) |
124 | |
125 | add_subdirectory(PhoneNumber) |
126 | -add_subdirectory(tests) |
127 | |
128 | === modified file 'Ubuntu/Telephony/contactwatcher.cpp' |
129 | --- Ubuntu/Telephony/contactwatcher.cpp 2015-03-30 20:55:55 +0000 |
130 | +++ Ubuntu/Telephony/contactwatcher.cpp 2015-03-30 20:55:55 +0000 |
131 | @@ -219,6 +219,10 @@ |
132 | void ContactWatcher::setAddressableFields(const QStringList &fields) |
133 | { |
134 | mAddressableFields = fields; |
135 | + // if the addressable fields is empty, fall back to matching phone numbers |
136 | + if (mAddressableFields.isEmpty()) { |
137 | + mAddressableFields << "tel"; |
138 | + } |
139 | Q_EMIT addressableFieldsChanged(); |
140 | |
141 | startSearching(); |
142 | |
143 | === modified file 'approver/CMakeLists.txt' |
144 | --- approver/CMakeLists.txt 2014-07-06 16:19:49 +0000 |
145 | +++ approver/CMakeLists.txt 2015-03-30 20:55:55 +0000 |
146 | @@ -25,6 +25,8 @@ |
147 | telephonyservice |
148 | ) |
149 | |
150 | +enable_coverage(telephony-service-approver) |
151 | + |
152 | configure_file(org.freedesktop.Telepathy.Client.TelephonyServiceApprover.service.in org.freedesktop.Telepathy.Client.TelephonyServiceApprover.service) |
153 | install(TARGETS telephony-service-approver RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) |
154 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.freedesktop.Telepathy.Client.TelephonyServiceApprover.service DESTINATION share/dbus-1/services) |
155 | |
156 | === added file 'cmake/modules/GenerateTest.cmake' |
157 | --- cmake/modules/GenerateTest.cmake 1970-01-01 00:00:00 +0000 |
158 | +++ cmake/modules/GenerateTest.cmake 2015-03-30 20:55:55 +0000 |
159 | @@ -0,0 +1,133 @@ |
160 | +# |
161 | +# Copyright (C) 2015 Canonical, Ltd. |
162 | +# |
163 | +# Authors: |
164 | +# Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> |
165 | +# |
166 | +# This file is part of telephony-service. |
167 | +# |
168 | +# telephony-service is free software; you can redistribute it and/or modify |
169 | +# it under the terms of the GNU General Public License as published by |
170 | +# the Free Software Foundation; version 3. |
171 | +# |
172 | +# telephony-service is distributed in the hope that it will be useful, |
173 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
174 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
175 | +# GNU General Public License for more details. |
176 | +# |
177 | +# You should have received a copy of the GNU General Public License |
178 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
179 | +# |
180 | + |
181 | +include(CMakeParseArguments) |
182 | +find_program(DBUS_RUNNER dbus-test-runner) |
183 | + |
184 | +function(generate_test TESTNAME) |
185 | + set(options USE_DBUS USE_UI) |
186 | + set(oneValueArgs TIMEOUT WORKING_DIRECTORY QML_TEST WAIT_FOR) |
187 | + set(multiValueArgs TASKS LIBRARIES QT5_MODULES SOURCES ENVIRONMENT) |
188 | + cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) |
189 | + |
190 | + MESSAGE(STATUS "Adding test: ${TESTNAME}") |
191 | + |
192 | + # set reasonable defaults for the arguments |
193 | + if (NOT DEFINED ARG_WORKING_DIRECTORY) |
194 | + set(ARG_WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) |
195 | + endif () |
196 | + |
197 | + if (NOT DEFINED ARG_TIMEOUT) |
198 | + set(ARG_TIMEOUT 60) |
199 | + endif () |
200 | + |
201 | + if (NOT DEFINED ARG_QT5_MODULES) |
202 | + set(ARG_QT5_MODULES Core Test) |
203 | + endif () |
204 | + |
205 | + if (${ARG_USE_UI}) |
206 | + if (${ARG_USE_DBUS}) |
207 | + set(PLATFORM -p -platform -p offscreen) |
208 | + else () |
209 | + set(PLATFORM -platform offscreen) |
210 | + endif () |
211 | + endif() |
212 | + |
213 | + # Generate QML tests |
214 | + if (DEFINED ARG_QML_TEST) |
215 | + add_test(NAME ${TESTNAME} |
216 | + WORKING_DIRECTORY ${ARG_WORKING_DIRECTORY} |
217 | + COMMAND qmltestrunner -platform offscreen -import ${CMAKE_BINARY_DIR} -input ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_QML_TEST}) |
218 | + set_tests_properties(${TESTNAME} PROPERTIES ENVIRONMENT "QT_QPA_FONTDIR=${CMAKE_BINARY_DIR}") |
219 | + else () |
220 | + # For sanity checking, make sure DBUS_RUNNER is available for DBUS tests |
221 | + if (${ARG_USE_DBUS} AND "${DBUS_RUNNER}" STREQUAL "") |
222 | + message(WARNING "Test ${TESTNAME} disabled because dbus-test-runner was not found.") |
223 | + return() |
224 | + endif () |
225 | + |
226 | + # No QML test, regular binary compiled test. |
227 | + add_executable(${TESTNAME} ${ARG_SOURCES}) |
228 | + qt5_use_modules(${TESTNAME} ${ARG_QT5_MODULES}) |
229 | + |
230 | + if (${ARG_USE_DBUS}) |
231 | + execute_process(COMMAND mktemp -d OUTPUT_VARIABLE TMPDIR) |
232 | + string(REPLACE "\n" "" TMPDIR ${TMPDIR}) |
233 | + |
234 | + if (NOT DEFINED ARG_ENVIRONMENT) |
235 | + set(ARG_ENVIRONMENT HOME=${TMPDIR} |
236 | + HISTORY_SQLITE_DBPATH=:memory: |
237 | + MC_ACCOUNT_DIR=${TMPDIR} |
238 | + MC_MANAGER_DIR=${TMPDIR}) |
239 | + endif () |
240 | + |
241 | + set(TEST_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME} ${PLATFORM} -p -o -p -,txt -p -o -p ${CMAKE_BINARY_DIR}/test_${TESTNAME}.xml,xunitxml) |
242 | + if (DEFINED ARG_WAIT_FOR) |
243 | + SET(TEST_COMMAND ${TEST_COMMAND} --wait-for ${ARG_WAIT_FOR}) |
244 | + endif () |
245 | + |
246 | + add_test(${TESTNAME} ${DBUS_RUNNER} --keep-env --dbus-config=${CMAKE_BINARY_DIR}/tests/common/dbus-session.conf --max-wait=${ARG_TIMEOUT} |
247 | + ${ARG_TASKS} --task ${TEST_COMMAND} --task-name ${TESTNAME}) |
248 | + else () |
249 | + add_test(${TESTNAME} ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME} ${PLATFORM} -o -,txt -o ${CMAKE_BINARY_DIR}/test_${TESTNAME}.xml,xunitxml) |
250 | + endif() |
251 | + |
252 | + set_tests_properties(${TESTNAME} PROPERTIES |
253 | + ENVIRONMENT "${ARG_ENVIRONMENT}" |
254 | + TIMEOUT ${ARG_TIMEOUT}) |
255 | + if (DEFINED ARG_LIBRARIES) |
256 | + target_link_libraries(${TESTNAME} |
257 | + ${ARG_LIBRARIES}) |
258 | + endif () |
259 | + |
260 | + enable_coverage(${TESTNAME}) |
261 | + endif () |
262 | +endfunction(generate_test) |
263 | + |
264 | +function(generate_telepathy_test TESTNAME) |
265 | + set(options "") |
266 | + set(oneValueArgs "") |
267 | + set(multiValueArgs TASKS LIBRARIES QT5_MODULES) |
268 | + cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) |
269 | + |
270 | + set(TASKS --task gnome-keyring-daemon -p -r -p -d --task-name gnome-keyring --ignore-return |
271 | + --task /usr/lib/dconf/dconf-service --task-name dconf-service --ignore-return |
272 | + --task dconf -p write -p /org/gnome/empathy/use-conn -p false --task-name dconf-write --wait-for ca.desrt.dconf --ignore-return |
273 | + --task /usr/lib/telepathy/mission-control-5 --task-name mission-control --wait-for ca.desrt.dconf --ignore-return |
274 | + --task ${CMAKE_BINARY_DIR}/tests/common/mock/telepathy-mock --task-name telepathy-mock --wait-for org.freedesktop.Telepathy.MissionControl5 --ignore-return |
275 | + # FIXME: maybe it would be better to decide whether to run the handler in a per-test basis? |
276 | + --task ${CMAKE_BINARY_DIR}/handler/telephony-service-handler --task-name telephony-service-handler --wait-for org.freedesktop.Telepathy.ConnectionManager.mock --ignore-return |
277 | + ${ARG_TASKS}) |
278 | + |
279 | + if (NOT DEFINED ARG_LIBRARIES) |
280 | + set(ARG_LIBRARIES ${TP_QT5_LIBRARIES} telephonyservice mockcontroller telepathytest) |
281 | + endif(NOT DEFINED ARG_LIBRARIES) |
282 | + |
283 | + if (NOT DEFINED ARG_QT5_MODULES) |
284 | + set(ARG_QT5_MODULES Core DBus Test Qml) |
285 | + endif (NOT DEFINED ARG_QT5_MODULES) |
286 | + generate_test(${TESTNAME} ${ARGN} |
287 | + TASKS ${TASKS} |
288 | + LIBRARIES ${ARG_LIBRARIES} |
289 | + QT5_MODULES ${ARG_QT5_MODULES} |
290 | + USE_DBUS USE_UI |
291 | + WAIT_FOR org.freedesktop.Telepathy.Client.TelephonyServiceHandler) |
292 | +endfunction(generate_telepathy_test) |
293 | |
294 | === modified file 'handler/CMakeLists.txt' |
295 | --- handler/CMakeLists.txt 2014-08-05 20:04:00 +0000 |
296 | +++ handler/CMakeLists.txt 2015-03-30 20:55:55 +0000 |
297 | @@ -26,6 +26,8 @@ |
298 | telephonyservice |
299 | ) |
300 | |
301 | +enable_coverage(telephony-service-handler) |
302 | + |
303 | configure_file(com.canonical.TelephonyServiceHandler.service.in com.canonical.TelephonyServiceHandler.service) |
304 | configure_file(org.freedesktop.Telepathy.Client.TelephonyServiceHandler.service.in org.freedesktop.Telepathy.Client.TelephonyServiceHandler.service) |
305 | |
306 | @@ -33,9 +35,3 @@ |
307 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.freedesktop.Telepathy.Client.TelephonyServiceHandler.service DESTINATION share/dbus-1/services) |
308 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/com.canonical.TelephonyServiceHandler.service DESTINATION share/dbus-1/services) |
309 | install(FILES TelephonyServiceHandler.client DESTINATION share/telepathy/clients) |
310 | - |
311 | -if(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc*") |
312 | - message(STATUS "Tests disabled on ppc") |
313 | -else() |
314 | - add_subdirectory(tests) |
315 | -endif() |
316 | |
317 | === modified file 'handler/handler.cpp' |
318 | --- handler/handler.cpp 2015-02-09 20:32:32 +0000 |
319 | +++ handler/handler.cpp 2015-03-30 20:55:55 +0000 |
320 | @@ -97,6 +97,7 @@ |
321 | specList << TelepathyHelper::audioConferenceSpec(); |
322 | specList << Tp::ChannelClassSpec::audioCall(); |
323 | specList << Tp::ChannelClassSpec::textChat(); |
324 | + specList << Tp::ChannelClassSpec::unnamedTextChat(); |
325 | |
326 | return specList; |
327 | } |
328 | |
329 | === removed file 'handler/tests/dbus-test-wrapper.sh.in' |
330 | --- handler/tests/dbus-test-wrapper.sh.in 2014-03-27 13:26:31 +0000 |
331 | +++ handler/tests/dbus-test-wrapper.sh.in 1970-01-01 00:00:00 +0000 |
332 | @@ -1,35 +0,0 @@ |
333 | -#!/bin/sh -x |
334 | - |
335 | -# export the home folder to somewhere in /tmp |
336 | -TMPDIR=/tmp/telephony_service_test_home |
337 | -rm -rf $TMPDIR |
338 | -mkdir -p $TMPDIR |
339 | -export HOME=$TMPDIR |
340 | - |
341 | -# now run gnome-keyring |
342 | -gnome-keyring-daemon -r -d |
343 | - |
344 | -# we need to set this otherwise mission-control doesn't work properly |
345 | -dconf write /org/gnome/empathy/use-conn false |
346 | - |
347 | -# start the mock connection manager |
348 | -@CMAKE_CURRENT_BINARY_DIR@/mock/telepathy-mock & |
349 | -MOCK_PID=$! |
350 | - |
351 | -# wait 1 sec for the mock to start up |
352 | -sleep 1 |
353 | - |
354 | -mc-tool add mock/mock account0 |
355 | - |
356 | -@CMAKE_CURRENT_BINARY_DIR@/../telephony-service-handler & |
357 | - |
358 | -HANDLER_PID=$! |
359 | - |
360 | -$@ |
361 | -RESULT=$? |
362 | - |
363 | -# FIXME: check the variables and things that should not be started |
364 | -kill -9 $HANDLER_PID |
365 | -kill -9 $MOCK_PID |
366 | - |
367 | -return $RESULT |
368 | |
369 | === removed file 'handler/tests/telepathyhelper.cpp' |
370 | --- handler/tests/telepathyhelper.cpp 2014-01-07 19:53:45 +0000 |
371 | +++ handler/tests/telepathyhelper.cpp 1970-01-01 00:00:00 +0000 |
372 | @@ -1,279 +0,0 @@ |
373 | -/** |
374 | - * Copyright (C) 2013 Canonical, Ltd. |
375 | - * |
376 | - * This program is free software: you can redistribute it and/or modify it under |
377 | - * the terms of the GNU General Public License version 3, as published by |
378 | - * the Free Software Foundation. |
379 | - * |
380 | - * This program is distributed in the hope that it will be useful, but WITHOUT |
381 | - * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, |
382 | - * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
383 | - * General Public License for more details. |
384 | - * |
385 | - * You should have received a copy of the GNU General Public License |
386 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
387 | - * |
388 | - * Authors: |
389 | - * Tiago Salem Herrmann <tiago.herrmann@canonical.com> |
390 | - * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> |
391 | - */ |
392 | - |
393 | -#include "telepathyhelper.h" |
394 | -#include <TelepathyQt/AbstractClient> |
395 | -#include <TelepathyQt/AccountSet> |
396 | -#include <TelepathyQt/ClientRegistrar> |
397 | -#include <TelepathyQt/PendingReady> |
398 | -#include <TelepathyQt/PendingAccount> |
399 | - |
400 | -TelepathyHelper::TelepathyHelper(QObject *parent) |
401 | - : QObject(parent), |
402 | - //mChannelObserver(0), |
403 | - mFirstTime(true), |
404 | - mConnected(false), |
405 | - mHandlerInterface(0) |
406 | -{ |
407 | - Tp::registerTypes(); |
408 | - |
409 | - mAccountFeatures << Tp::Account::FeatureCore; |
410 | - mContactFeatures << Tp::Contact::FeatureAlias |
411 | - << Tp::Contact::FeatureAvatarData |
412 | - << Tp::Contact::FeatureAvatarToken |
413 | - << Tp::Contact::FeatureCapabilities |
414 | - << Tp::Contact::FeatureSimplePresence; |
415 | - mConnectionFeatures << Tp::Connection::FeatureCore |
416 | - << Tp::Connection::FeatureSelfContact |
417 | - << Tp::Connection::FeatureSimplePresence; |
418 | - |
419 | - Tp::ChannelFactoryPtr channelFactory = Tp::ChannelFactory::create(QDBusConnection::sessionBus()); |
420 | - channelFactory->addCommonFeatures(Tp::Channel::FeatureCore); |
421 | - |
422 | - mAccountManager = Tp::AccountManager::create( |
423 | - Tp::AccountFactory::create(QDBusConnection::sessionBus(), mAccountFeatures), |
424 | - Tp::ConnectionFactory::create(QDBusConnection::sessionBus(), mConnectionFeatures), |
425 | - channelFactory, |
426 | - Tp::ContactFactory::create(mContactFeatures)); |
427 | - |
428 | - connect(mAccountManager->becomeReady(Tp::AccountManager::FeatureCore), |
429 | - SIGNAL(finished(Tp::PendingOperation*)), |
430 | - SLOT(onAccountManagerReady(Tp::PendingOperation*))); |
431 | - |
432 | - mClientRegistrar = Tp::ClientRegistrar::create(mAccountManager); |
433 | -} |
434 | - |
435 | -TelepathyHelper::~TelepathyHelper() |
436 | -{ |
437 | -} |
438 | - |
439 | -TelepathyHelper *TelepathyHelper::instance() |
440 | -{ |
441 | - static TelepathyHelper* helper = new TelepathyHelper(); |
442 | - return helper; |
443 | -} |
444 | - |
445 | -QString TelepathyHelper::accountId() const |
446 | -{ |
447 | - if (mAccount) { |
448 | - return mAccount->uniqueIdentifier(); |
449 | - } |
450 | - return QString(); |
451 | -} |
452 | - |
453 | -Tp::AccountPtr TelepathyHelper::account() const |
454 | -{ |
455 | - return mAccount; |
456 | -} |
457 | - |
458 | -/* |
459 | -ChannelObserver *TelepathyHelper::channelObserver() const |
460 | -{ |
461 | - return mChannelObserver; |
462 | -} |
463 | -*/ |
464 | - |
465 | -bool TelepathyHelper::connected() const |
466 | -{ |
467 | - return mConnected; |
468 | -} |
469 | - |
470 | -/* |
471 | -void TelepathyHelper::registerChannelObserver(const QString &observerName) |
472 | -{ |
473 | - QString name = observerName; |
474 | - |
475 | - if (name.isEmpty()) { |
476 | - name = "TelephonyPluginObserver"; |
477 | - } |
478 | - |
479 | - if (mChannelObserver) { |
480 | - mChannelObserver->deleteLater(); |
481 | - } |
482 | - |
483 | - mChannelObserver = new ChannelObserver(this); |
484 | - registerClient(mChannelObserver, name); |
485 | - |
486 | - // messages |
487 | - connect(mChannelObserver, SIGNAL(textChannelAvailable(Tp::TextChannelPtr)), |
488 | - ChatManager::instance(), SLOT(onTextChannelAvailable(Tp::TextChannelPtr))); |
489 | - |
490 | - // calls |
491 | - connect(mChannelObserver, SIGNAL(callChannelAvailable(Tp::CallChannelPtr)), |
492 | - CallManager::instance(), SLOT(onCallChannelAvailable(Tp::CallChannelPtr))); |
493 | - |
494 | - Q_EMIT channelObserverCreated(mChannelObserver); |
495 | -} |
496 | - |
497 | -void TelepathyHelper::unregisterChannelObserver() |
498 | -{ |
499 | - Tp::AbstractClientPtr clientPtr(mChannelObserver); |
500 | - if (clientPtr) { |
501 | - mClientRegistrar->unregisterClient(clientPtr); |
502 | - } |
503 | - mChannelObserver->deleteLater(); |
504 | - mChannelObserver = NULL; |
505 | - Q_EMIT channelObserverUnregistered(); |
506 | -} |
507 | -*/ |
508 | - |
509 | -QStringList TelepathyHelper::supportedProtocols() const |
510 | -{ |
511 | - QStringList protocols; |
512 | - protocols << "mock"; |
513 | - return protocols; |
514 | -} |
515 | - |
516 | -void TelepathyHelper::initializeAccount() |
517 | -{ |
518 | - // watch for account state and connection changes |
519 | - connect(mAccount.data(), |
520 | - SIGNAL(stateChanged(bool)), |
521 | - SLOT(onAccountStateChanged(bool))); |
522 | - connect(mAccount.data(), |
523 | - SIGNAL(connectionChanged(const Tp::ConnectionPtr&)), |
524 | - SLOT(onAccountConnectionChanged(const Tp::ConnectionPtr&))); |
525 | - |
526 | - // and make sure it is enabled and connected |
527 | - if (!mAccount->isEnabled()) { |
528 | - ensureAccountEnabled(); |
529 | - } else { |
530 | - ensureAccountConnected(); |
531 | - } |
532 | -} |
533 | - |
534 | -void TelepathyHelper::ensureAccountEnabled() |
535 | -{ |
536 | - mAccount->setConnectsAutomatically(true); |
537 | - connect(mAccount->setEnabled(true), |
538 | - SIGNAL(finished(Tp::PendingOperation*)), |
539 | - SLOT(onAccountEnabled(Tp::PendingOperation*))); |
540 | -} |
541 | - |
542 | -void TelepathyHelper::ensureAccountConnected() |
543 | -{ |
544 | - // if the account is not connected, request it to connect |
545 | - if (!mAccount->connection() || mAccount->connectionStatus() != Tp::ConnectionStatusConnected) { |
546 | - Tp::Presence presence(Tp::ConnectionPresenceTypeAvailable, "available", "online"); |
547 | - mAccount->setRequestedPresence(presence); |
548 | - } else { |
549 | - watchSelfContactPresence(); |
550 | - } |
551 | - |
552 | - if (mFirstTime) { |
553 | - Q_EMIT accountReady(); |
554 | - mFirstTime = false; |
555 | - } |
556 | -} |
557 | - |
558 | -void TelepathyHelper::watchSelfContactPresence() |
559 | -{ |
560 | - if (mAccount.isNull() || mAccount->connection().isNull()) { |
561 | - return; |
562 | - } |
563 | - |
564 | - connect(mAccount->connection()->selfContact().data(), |
565 | - SIGNAL(presenceChanged(Tp::Presence)), |
566 | - SLOT(onPresenceChanged(Tp::Presence))); |
567 | - onPresenceChanged(mAccount->connection()->selfContact()->presence()); |
568 | -} |
569 | - |
570 | -void TelepathyHelper::registerClient(Tp::AbstractClient *client, QString name) |
571 | -{ |
572 | - Tp::AbstractClientPtr clientPtr(client); |
573 | - bool succeeded = mClientRegistrar->registerClient(clientPtr, name); |
574 | - if (!succeeded) { |
575 | - name.append("%1"); |
576 | - int count = 0; |
577 | - // limit the number of registered clients to 20, that should be a safe margin |
578 | - while (!succeeded && count < 20) { |
579 | - succeeded = mClientRegistrar->registerClient(clientPtr, name.arg(++count)); |
580 | - if (succeeded) { |
581 | - name = name.arg(count); |
582 | - } |
583 | - } |
584 | - } |
585 | - |
586 | - if (succeeded) { |
587 | - QObject *object = dynamic_cast<QObject*>(client); |
588 | - if (object) { |
589 | - object->setProperty("clientName", TP_QT_IFACE_CLIENT + "." + name ); |
590 | - } |
591 | - } |
592 | -} |
593 | - |
594 | -void TelepathyHelper::onAccountManagerReady(Tp::PendingOperation *op) |
595 | -{ |
596 | - Q_UNUSED(op) |
597 | - |
598 | - Tp::AccountSetPtr accountSet; |
599 | - // try to find an account of the one of supported protocols |
600 | - Q_FOREACH(const QString &protocol, supportedProtocols()) { |
601 | - accountSet = mAccountManager->accountsByProtocol(protocol); |
602 | - if (accountSet->accounts().count() > 0) { |
603 | - break; |
604 | - } |
605 | - } |
606 | - |
607 | - if (accountSet->accounts().count() == 0) { |
608 | - qCritical() << "No compatible telepathy account found!"; |
609 | - return; |
610 | - } |
611 | - |
612 | - mAccount = accountSet->accounts()[0]; |
613 | - |
614 | - // in case we have more than one account, the first one to show on the list is going to be used |
615 | - if (accountSet->accounts().count() > 1) { |
616 | - qWarning() << "There are more than just one account of type" << mAccount->protocolName(); |
617 | - } |
618 | - |
619 | - Q_EMIT accountIdChanged(); |
620 | - |
621 | - initializeAccount(); |
622 | -} |
623 | - |
624 | -void TelepathyHelper::onAccountEnabled(Tp::PendingOperation *op) |
625 | -{ |
626 | - // we might need to do more stuff once the account is enabled, but making sure it is connected is a good start |
627 | - ensureAccountConnected(); |
628 | -} |
629 | - |
630 | -void TelepathyHelper::onAccountStateChanged(bool enabled) |
631 | -{ |
632 | - if (!enabled) { |
633 | - ensureAccountEnabled(); |
634 | - } |
635 | -} |
636 | - |
637 | -void TelepathyHelper::onAccountConnectionChanged(const Tp::ConnectionPtr &connection) |
638 | -{ |
639 | - if (connection.isNull()) { |
640 | - ensureAccountConnected(); |
641 | - } else { |
642 | - watchSelfContactPresence(); |
643 | - } |
644 | - Q_EMIT connectionChanged(); |
645 | -} |
646 | - |
647 | -void TelepathyHelper::onPresenceChanged(const Tp::Presence &presence) |
648 | -{ |
649 | - mConnected = (presence.type() == Tp::ConnectionPresenceTypeAvailable); |
650 | - Q_EMIT connectedChanged(); |
651 | -} |
652 | |
653 | === removed file 'handler/tests/telepathyhelper.h' |
654 | --- handler/tests/telepathyhelper.h 2014-06-27 17:45:58 +0000 |
655 | +++ handler/tests/telepathyhelper.h 1970-01-01 00:00:00 +0000 |
656 | @@ -1,95 +0,0 @@ |
657 | -/** |
658 | - * Copyright (C) 2013 Canonical, Ltd. |
659 | - * |
660 | - * This program is free software: you can redistribute it and/or modify it under |
661 | - * the terms of the GNU General Public License version 3, as published by |
662 | - * the Free Software Foundation. |
663 | - * |
664 | - * This program is distributed in the hope that it will be useful, but WITHOUT |
665 | - * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, |
666 | - * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
667 | - * General Public License for more details. |
668 | - * |
669 | - * You should have received a copy of the GNU General Public License |
670 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
671 | - * |
672 | - * Authors: |
673 | - * Tiago Salem Herrmann <tiago.herrmann@canonical.com> |
674 | - * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> |
675 | - */ |
676 | - |
677 | -#ifndef TELEPATHYHELPER_H |
678 | -#define TELEPATHYHELPER_H |
679 | - |
680 | -#include <QObject> |
681 | -#include <TelepathyQt/AccountManager> |
682 | -#include <TelepathyQt/Contact> |
683 | -#include <TelepathyQt/Connection> |
684 | -#include <TelepathyQt/ConnectionManager> |
685 | -#include <TelepathyQt/Types> |
686 | -//#include "channelobserver.h" |
687 | - |
688 | -#define CANONICAL_TELEPHONY_VOICEMAIL_IFACE "com.canonical.Telephony.Voicemail" |
689 | -#define CANONICAL_TELEPHONY_SPEAKER_IFACE "com.canonical.Telephony.Speaker" |
690 | -#define CANONICAL_TELEPHONY_EMERGENCYMODE_IFACE "com.canonical.Telephony.EmergencyMode" |
691 | - |
692 | -class TelepathyHelper : public QObject |
693 | -{ |
694 | - Q_OBJECT |
695 | - Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged) |
696 | - Q_PROPERTY(QString accountId READ accountId NOTIFY accountIdChanged) |
697 | - |
698 | -public: |
699 | - ~TelepathyHelper(); |
700 | - |
701 | - static TelepathyHelper *instance(); |
702 | - Tp::AccountPtr account() const; |
703 | - //ChannelObserver *channelObserver() const; |
704 | - |
705 | - bool connected() const; |
706 | - QString accountId() const; |
707 | - |
708 | - void registerClient(Tp::AbstractClient *client, QString name); |
709 | - |
710 | -Q_SIGNALS: |
711 | - //void channelObserverCreated(ChannelObserver *observer); |
712 | - //void channelObserverUnregistered(); |
713 | - void accountReady(); |
714 | - void connectionChanged(); |
715 | - void connectedChanged(); |
716 | - void accountIdChanged(); |
717 | - |
718 | -public Q_SLOTS: |
719 | - //Q_INVOKABLE void registerChannelObserver(const QString &observerName = QString::null); |
720 | - //Q_INVOKABLE void unregisterChannelObserver(); |
721 | - |
722 | -protected: |
723 | - QStringList supportedProtocols() const; |
724 | - void initializeAccount(); |
725 | - void ensureAccountEnabled(); |
726 | - void ensureAccountConnected(); |
727 | - void watchSelfContactPresence(); |
728 | - |
729 | -private Q_SLOTS: |
730 | - void onAccountManagerReady(Tp::PendingOperation *op); |
731 | - void onAccountEnabled(Tp::PendingOperation *op); |
732 | - void onAccountStateChanged(bool enabled); |
733 | - void onAccountConnectionChanged(const Tp::ConnectionPtr &connection); |
734 | - void onPresenceChanged(const Tp::Presence &presence); |
735 | - |
736 | -private: |
737 | - explicit TelepathyHelper(QObject *parent = 0); |
738 | - Tp::AccountManagerPtr mAccountManager; |
739 | - Tp::Features mAccountManagerFeatures; |
740 | - Tp::Features mAccountFeatures; |
741 | - Tp::Features mContactFeatures; |
742 | - Tp::Features mConnectionFeatures; |
743 | - Tp::ClientRegistrarPtr mClientRegistrar; |
744 | - Tp::AccountPtr mAccount; |
745 | - //ChannelObserver *mChannelObserver; |
746 | - bool mFirstTime; |
747 | - bool mConnected; |
748 | - QDBusInterface *mHandlerInterface; |
749 | -}; |
750 | - |
751 | -#endif // TELEPATHYHELPER_H |
752 | |
753 | === modified file 'indicator/CMakeLists.txt' |
754 | --- indicator/CMakeLists.txt 2014-04-07 19:21:14 +0000 |
755 | +++ indicator/CMakeLists.txt 2015-03-30 20:55:55 +0000 |
756 | @@ -47,6 +47,8 @@ |
757 | telephonyservice |
758 | ) |
759 | |
760 | +enable_coverage(telephony-service-indicator) |
761 | + |
762 | configure_file(org.freedesktop.Telepathy.Client.TelephonyServiceIndicator.service.in org.freedesktop.Telepathy.Client.TelephonyServiceIndicator.service) |
763 | install(TARGETS telephony-service-indicator RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) |
764 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.freedesktop.Telepathy.Client.TelephonyServiceIndicator.service DESTINATION share/dbus-1/services) |
765 | |
766 | === modified file 'libtelephonyservice/CMakeLists.txt' |
767 | --- libtelephonyservice/CMakeLists.txt 2015-03-30 20:55:55 +0000 |
768 | +++ libtelephonyservice/CMakeLists.txt 2015-03-30 20:55:55 +0000 |
769 | @@ -38,4 +38,4 @@ |
770 | |
771 | qt5_use_modules(telephonyservice Contacts Core DBus Feedback Multimedia Qml Quick) |
772 | |
773 | -add_subdirectory(tests) |
774 | +enable_coverage(telephonyservice) |
775 | |
776 | === modified file 'libtelephonyservice/accountentry.cpp' |
777 | --- libtelephonyservice/accountentry.cpp 2015-03-30 20:55:55 +0000 |
778 | +++ libtelephonyservice/accountentry.cpp 2015-03-30 20:55:55 +0000 |
779 | @@ -41,7 +41,8 @@ |
780 | |
781 | bool AccountEntry::active() const |
782 | { |
783 | - return (!mAccount->connection().isNull() && |
784 | + return (!mAccount.isNull() && |
785 | + !mAccount->connection().isNull() && |
786 | !mAccount->connection()->selfContact().isNull() && |
787 | mAccount->connection()->selfContact()->presence().type() != Tp::ConnectionPresenceTypeOffline); |
788 | } |
789 | @@ -70,10 +71,7 @@ |
790 | return QString::null; |
791 | } |
792 | Tp::Presence presence = mAccount->connection()->selfContact()->presence(); |
793 | - if (presence.type() == Tp::ConnectionPresenceTypeAvailable) { |
794 | - return presence.statusMessage(); |
795 | - } |
796 | - return QString::null; |
797 | + return presence.statusMessage(); |
798 | } |
799 | |
800 | QString AccountEntry::selfContactId() const |
801 | @@ -147,6 +145,10 @@ |
802 | SIGNAL(connectionChanged(Tp::ConnectionPtr)), |
803 | SLOT(onConnectionChanged())); |
804 | |
805 | + connect(this, |
806 | + SIGNAL(connectedChanged()), |
807 | + SIGNAL(activeChanged())); |
808 | + |
809 | // and make sure it is enabled and connected |
810 | if (!mAccount->isEnabled()) { |
811 | QTimer::singleShot(0, this, SLOT(ensureEnabled())); |
812 | @@ -203,15 +205,12 @@ |
813 | Q_EMIT statusMessageChanged(); |
814 | Q_EMIT connectedChanged(); |
815 | Q_EMIT selfContactIdChanged(); |
816 | - Q_EMIT activeChanged(); |
817 | } |
818 | |
819 | void AccountEntry::onConnectionChanged() |
820 | { |
821 | if (!mAccount->connection()) { |
822 | - |
823 | - |
824 | - // and ensure the account gets connected |
825 | + // ensure the account gets connected |
826 | ensureConnected(); |
827 | } else { |
828 | mConnectionInfo.busName = mAccount->connection()->busName(); |
829 | @@ -226,5 +225,4 @@ |
830 | |
831 | Q_EMIT connectedChanged(); |
832 | Q_EMIT selfContactIdChanged(); |
833 | - Q_EMIT activeChanged(); |
834 | } |
835 | |
836 | === modified file 'libtelephonyservice/accountentryfactory.cpp' |
837 | --- libtelephonyservice/accountentryfactory.cpp 2015-03-30 20:55:55 +0000 |
838 | +++ libtelephonyservice/accountentryfactory.cpp 2015-03-30 20:55:55 +0000 |
839 | @@ -25,7 +25,7 @@ |
840 | |
841 | AccountEntry *AccountEntryFactory::createEntry(const Tp::AccountPtr &account, QObject *parent) |
842 | { |
843 | - QString protocol = account->protocolName(); |
844 | + QString protocol = account.isNull() ? "" : account->protocolName(); |
845 | |
846 | // FIXME: check what other accounts need extra properties/methods |
847 | if (protocol == "ofono") { |
848 | @@ -34,7 +34,3 @@ |
849 | |
850 | return new AccountEntry(account, parent); |
851 | } |
852 | - |
853 | -AccountEntryFactory::AccountEntryFactory() |
854 | -{ |
855 | -} |
856 | |
857 | === modified file 'libtelephonyservice/accountentryfactory.h' |
858 | --- libtelephonyservice/accountentryfactory.h 2015-03-30 20:55:55 +0000 |
859 | +++ libtelephonyservice/accountentryfactory.h 2015-03-30 20:55:55 +0000 |
860 | @@ -31,8 +31,6 @@ |
861 | public: |
862 | static AccountEntry *createEntry(const Tp::AccountPtr &account, QObject *parent = 0); |
863 | |
864 | -private: |
865 | - explicit AccountEntryFactory(); |
866 | }; |
867 | |
868 | #endif // ACCOUNTENTRYFACTORY_H |
869 | |
870 | === modified file 'libtelephonyservice/channelobserver.cpp' |
871 | --- libtelephonyservice/channelobserver.cpp 2015-02-09 20:32:32 +0000 |
872 | +++ libtelephonyservice/channelobserver.cpp 2015-03-30 20:55:55 +0000 |
873 | @@ -38,6 +38,7 @@ |
874 | specList << TelepathyHelper::audioConferenceSpec(); |
875 | specList << Tp::ChannelClassSpec::audioCall(); |
876 | specList << Tp::ChannelClassSpec::textChat(); |
877 | + specList << Tp::ChannelClassSpec::unnamedTextChat(); |
878 | |
879 | return specList; |
880 | } |
881 | |
882 | === modified file 'libtelephonyservice/chatmanager.cpp' |
883 | --- libtelephonyservice/chatmanager.cpp 2015-03-30 20:55:55 +0000 |
884 | +++ libtelephonyservice/chatmanager.cpp 2015-03-30 20:55:55 +0000 |
885 | @@ -26,6 +26,7 @@ |
886 | #include "dbustypes.h" |
887 | #include "accountentry.h" |
888 | |
889 | +#include <TelepathyQt/Contact> |
890 | #include <TelepathyQt/ContactManager> |
891 | #include <TelepathyQt/PendingContacts> |
892 | #include <QDBusArgument> |
893 | @@ -114,6 +115,7 @@ |
894 | |
895 | void ChatManager::sendMessage(const QStringList &recipients, const QString &message, const QString &accountId) |
896 | { |
897 | + // FIXME: this probably should be handle internally by telepathy-ofono |
898 | if (recipients.size() > 1 && TelepathyHelper::instance()->mmsGroupChat()) { |
899 | sendMMS(recipients, message, QVariant(), accountId); |
900 | return; |
901 | @@ -173,9 +175,12 @@ |
902 | return; |
903 | } |
904 | |
905 | - if (!channel->targetContact().isNull()) { |
906 | - Q_EMIT messageSent(channel->targetContact()->id(), sentMessage.text()); |
907 | + QStringList recipients; |
908 | + Q_FOREACH(const Tp::ContactPtr &contact, channel->groupContacts(false)) { |
909 | + recipients << contact->id(); |
910 | } |
911 | + |
912 | + Q_EMIT messageSent(recipients, sentMessage.text()); |
913 | } |
914 | |
915 | void ChatManager::acknowledgeMessage(const QStringList &recipients, const QString &messageId, const QString &accountId) |
916 | |
917 | === modified file 'libtelephonyservice/chatmanager.h' |
918 | --- libtelephonyservice/chatmanager.h 2015-03-30 20:55:55 +0000 |
919 | +++ libtelephonyservice/chatmanager.h 2015-03-30 20:55:55 +0000 |
920 | @@ -38,8 +38,8 @@ |
921 | Q_INVOKABLE void sendMMS(const QStringList &recipients, const QString &message, const QVariant &attachments, const QString &accountId = QString:: null); |
922 | |
923 | Q_SIGNALS: |
924 | - void messageReceived(const QString &recipient, const QString &message, const QDateTime ×tamp, const QString &messageId, bool unread); |
925 | - void messageSent(const QString &recipient, const QString &message); |
926 | + void messageReceived(const QString &sender, const QString &message, const QDateTime ×tamp, const QString &messageId, bool unread); |
927 | + void messageSent(const QStringList &recipients, const QString &message); |
928 | |
929 | public Q_SLOTS: |
930 | void onTextChannelAvailable(Tp::TextChannelPtr channel); |
931 | |
932 | === modified file 'libtelephonyservice/ofonoaccountentry.cpp' |
933 | --- libtelephonyservice/ofonoaccountentry.cpp 2015-03-30 20:55:55 +0000 |
934 | +++ libtelephonyservice/ofonoaccountentry.cpp 2015-03-30 20:55:55 +0000 |
935 | @@ -203,6 +203,5 @@ |
936 | mSerial = ussdIface.property("Serial").toString(); |
937 | } |
938 | |
939 | - Q_EMIT simLockedChanged(); |
940 | Q_EMIT serialChanged(); |
941 | } |
942 | |
943 | === modified file 'libtelephonyservice/telepathyhelper.cpp' |
944 | --- libtelephonyservice/telepathyhelper.cpp 2015-03-30 20:55:55 +0000 |
945 | +++ libtelephonyservice/telepathyhelper.cpp 2015-03-30 20:55:55 +0000 |
946 | @@ -247,10 +247,7 @@ |
947 | |
948 | void TelepathyHelper::unregisterChannelObserver() |
949 | { |
950 | - Tp::AbstractClientPtr clientPtr(mChannelObserver); |
951 | - if (clientPtr) { |
952 | - mClientRegistrar->unregisterClient(clientPtr); |
953 | - } |
954 | + unregisterClient(mChannelObserver); |
955 | mChannelObserver->deleteLater(); |
956 | mChannelObserver = NULL; |
957 | Q_EMIT channelObserverUnregistered(); |
958 | @@ -315,6 +312,15 @@ |
959 | return succeeded; |
960 | } |
961 | |
962 | +bool TelepathyHelper::unregisterClient(Tp::AbstractClient *client) |
963 | +{ |
964 | + Tp::AbstractClientPtr clientPtr(client); |
965 | + if (clientPtr) { |
966 | + return mClientRegistrar->unregisterClient(clientPtr); |
967 | + } |
968 | + return false; |
969 | +} |
970 | + |
971 | AccountEntry *TelepathyHelper::accountForConnection(const Tp::ConnectionPtr &connection) const |
972 | { |
973 | if (connection.isNull()) { |
974 | @@ -401,7 +407,7 @@ |
975 | Q_FOREACH(AccountEntry *account, mAccounts) { |
976 | QString modemObjName = account->account()->parameters().value("modem-objpath").toString(); |
977 | if (modemObjName.isEmpty()) { |
978 | - sortedOtherAccounts[account->displayName()] = account; |
979 | + sortedOtherAccounts[account->accountId()] = account; |
980 | } else { |
981 | sortedOfonoAccounts[modemObjName] = account; |
982 | } |
983 | |
984 | === modified file 'libtelephonyservice/telepathyhelper.h' |
985 | --- libtelephonyservice/telepathyhelper.h 2015-02-09 20:32:32 +0000 |
986 | +++ libtelephonyservice/telepathyhelper.h 2015-03-30 20:55:55 +0000 |
987 | @@ -87,6 +87,7 @@ |
988 | Q_INVOKABLE void unlockSimCards() const; |
989 | |
990 | bool registerClient(Tp::AbstractClient *client, QString name); |
991 | + bool unregisterClient(Tp::AbstractClient *client); |
992 | |
993 | // pre-populated channel class specs for conferences |
994 | static Tp::ChannelClassSpec audioConferenceSpec(); |
995 | |
996 | === added directory 'tests' |
997 | === added file 'tests/CMakeLists.txt' |
998 | --- tests/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
999 | +++ tests/CMakeLists.txt 2015-03-30 20:55:55 +0000 |
1000 | @@ -0,0 +1,6 @@ |
1001 | +include (GenerateTest) |
1002 | + |
1003 | +add_subdirectory(common) |
1004 | +add_subdirectory(handler) |
1005 | +add_subdirectory(libtelephonyservice) |
1006 | +add_subdirectory(Ubuntu.Telephony) |
1007 | |
1008 | === renamed directory 'Ubuntu/Telephony/tests' => 'tests/Ubuntu.Telephony' |
1009 | === modified file 'tests/Ubuntu.Telephony/CMakeLists.txt' |
1010 | --- Ubuntu/Telephony/tests/CMakeLists.txt 2014-07-11 21:30:21 +0000 |
1011 | +++ tests/Ubuntu.Telephony/CMakeLists.txt 2015-03-30 20:55:55 +0000 |
1012 | @@ -1,35 +1,19 @@ |
1013 | include_directories( |
1014 | ${CMAKE_CURRENT_BINARY_DIR} |
1015 | ${CMAKE_SOURCE_DIR}/Ubuntu/Telephony |
1016 | - ) |
1017 | - |
1018 | -macro(generate_tests) |
1019 | - foreach(test ${ARGN}) |
1020 | - add_executable(${test} ${test}.cpp) |
1021 | - qt5_use_modules(${test} Contacts Core DBus Qml Test) |
1022 | - target_link_libraries(${test} |
1023 | - telephonyservice-qml |
1024 | - ) |
1025 | - add_test(${test} ${CMAKE_CURRENT_BINARY_DIR}/${test} -platform offscreen -xunitxml -o ${CMAKE_BINARY_DIR}/test_${test}.xml) |
1026 | - endforeach(test) |
1027 | -endmacro(generate_tests) |
1028 | - |
1029 | -macro(DECLARE_QML_TEST TST_NAME TST_QML_FILE) |
1030 | - add_test(NAME ${TST_NAME} |
1031 | - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
1032 | - COMMAND xvfb-run -a -s "-screen 0 1024x768x24" qmltestrunner -import ${CMAKE_BINARY_DIR} -input ${CMAKE_CURRENT_SOURCE_DIR}/${TST_QML_FILE} |
1033 | - ) |
1034 | -endmacro() |
1035 | - |
1036 | - |
1037 | -generate_tests( |
1038 | - ContactWatcherTest |
1039 | - ) |
1040 | - |
1041 | -declare_qml_test("context_properties" tst_contextProperties.qml) |
1042 | -declare_qml_test("phonenumber_field" tst_PhoneNumberField.qml) |
1043 | -declare_qml_test("phonenumber_input" tst_PhoneNumberInput.qml) |
1044 | -declare_qml_test("phonenumber_utils" tst_PhoneNumberPhoneUtils.qml) |
1045 | + ${CMAKE_SOURCE_DIR}/libtelephonyservice |
1046 | + ) |
1047 | + |
1048 | +set(SOURCE_DIR ${CMAKE_SOURCE_DIR}/Ubuntu/Telephony) |
1049 | +generate_test(ContactWatcherTest USE_UI |
1050 | + SOURCES ContactWatcherTest.cpp |
1051 | + LIBRARIES telephonyservice-qml |
1052 | + QT5_MODULES Contacts Core DBus Qml Test) |
1053 | + |
1054 | +generate_test(context_properties QML_TEST tst_contextProperties.qml) |
1055 | +generate_test(phonenumber_field QML_TEST tst_PhoneNumberField.qml) |
1056 | +generate_test(phonenumber_input QML_TEST tst_PhoneNumberInput.qml) |
1057 | +generate_test(phonenumber_utils QML_TEST tst_PhoneNumberPhoneUtils.qml) |
1058 | |
1059 | # make the files visible on qtcreator |
1060 | file(GLOB QML_TESTS *.qml *.js) |
1061 | |
1062 | === modified file 'tests/Ubuntu.Telephony/ContactWatcherTest.cpp' |
1063 | --- Ubuntu/Telephony/tests/ContactWatcherTest.cpp 2015-03-30 20:55:55 +0000 |
1064 | +++ tests/Ubuntu.Telephony/ContactWatcherTest.cpp 2015-03-30 20:55:55 +0000 |
1065 | @@ -438,6 +438,11 @@ |
1066 | watcher.setAddressableFields(addressableFields); |
1067 | QCOMPARE(addressableFieldsSpy.count(), 1); |
1068 | QCOMPARE(watcher.addressableFields(), addressableFields); |
1069 | + |
1070 | + // set the addressable fields to an empty value and make sure it falls back to "tel" |
1071 | + watcher.setAddressableFields(QStringList()); |
1072 | + QCOMPARE(watcher.addressableFields().count(), 1); |
1073 | + QCOMPARE(watcher.addressableFields()[0], QString("tel")); |
1074 | } |
1075 | |
1076 | void ContactWatcherTest::testExtendedFieldMatch() |
1077 | |
1078 | === added directory 'tests/common' |
1079 | === added file 'tests/common/CMakeLists.txt' |
1080 | --- tests/common/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
1081 | +++ tests/common/CMakeLists.txt 2015-03-30 20:55:55 +0000 |
1082 | @@ -0,0 +1,14 @@ |
1083 | +include_directories(${TP_QT5_INCLUDE_DIRS} |
1084 | + ${CMAKE_SOURCE_DIR}/libtelephonyservice) |
1085 | + |
1086 | +configure_file(dbus-session.conf.in ${CMAKE_CURRENT_BINARY_DIR}/dbus-session.conf) |
1087 | + |
1088 | +add_library(mockcontroller STATIC mockcontroller.cpp mockcontroller.h) |
1089 | +qt5_use_modules(mockcontroller Core DBus) |
1090 | + |
1091 | +add_library(telepathytest STATIC telepathytest.cpp telepathytest.h) |
1092 | +qt5_use_modules(telepathytest Core DBus) |
1093 | +target_link_libraries(telepathytest telephonyservice ${TP_QT5_LIBRARIES}) |
1094 | + |
1095 | +add_subdirectory(mock) |
1096 | +add_subdirectory(dbus-services) |
1097 | |
1098 | === added directory 'tests/common/dbus-services' |
1099 | === added file 'tests/common/dbus-services/CMakeLists.txt' |
1100 | --- tests/common/dbus-services/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
1101 | +++ tests/common/dbus-services/CMakeLists.txt 2015-03-30 20:55:55 +0000 |
1102 | @@ -0,0 +1,9 @@ |
1103 | +# copy the services we want to use |
1104 | +set(DBUS_SERVICES_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/dbus-1/services) |
1105 | + |
1106 | +file(COPY ${DBUS_SERVICES_DIR}/org.freedesktop.Telepathy.MissionControl5.service |
1107 | + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) |
1108 | +file(COPY ${DBUS_SERVICES_DIR}/org.freedesktop.Telepathy.AccountManager.service |
1109 | + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) |
1110 | +file(COPY ${DBUS_SERVICES_DIR}/ca.desrt.dconf.service |
1111 | + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) |
1112 | |
1113 | === added file 'tests/common/dbus-session.conf.in' |
1114 | --- tests/common/dbus-session.conf.in 1970-01-01 00:00:00 +0000 |
1115 | +++ tests/common/dbus-session.conf.in 2015-03-30 20:55:55 +0000 |
1116 | @@ -0,0 +1,42 @@ |
1117 | +<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN" |
1118 | + "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> |
1119 | +<busconfig> |
1120 | + <type>session</type> |
1121 | + |
1122 | + <!-- If we fork, keep the user's original umask to avoid affecting |
1123 | + the behavior of child processes. --> |
1124 | + <keep_umask/> |
1125 | + |
1126 | + <listen>unix:tmpdir=/tmp</listen> |
1127 | + |
1128 | + <servicedir>@CMAKE_CURRENT_BINARY_DIR@/dbus-services</servicedir> |
1129 | + |
1130 | + <policy context="default"> |
1131 | + <!-- Allow everything to be sent --> |
1132 | + <allow send_destination="*" eavesdrop="true"/> |
1133 | + <!-- Allow everything to be received --> |
1134 | + <allow eavesdrop="true"/> |
1135 | + <!-- Allow anyone to own anything --> |
1136 | + <allow own="*"/> |
1137 | + </policy> |
1138 | + |
1139 | + <!-- raise the service start timeout to 40 seconds as it can timeout |
1140 | + on the live cd on slow machines --> |
1141 | + <limit name="service_start_timeout">60000</limit> |
1142 | + |
1143 | + <!-- the memory limits are 1G instead of say 4G because they can't exceed 32-bit signed int max --> |
1144 | + <limit name="max_incoming_bytes">1000000000</limit> |
1145 | + <limit name="max_outgoing_bytes">1000000000</limit> |
1146 | + <limit name="max_message_size">1000000000</limit> |
1147 | + <limit name="service_start_timeout">120000</limit> |
1148 | + <limit name="auth_timeout">240000</limit> |
1149 | + <limit name="max_completed_connections">100000</limit> |
1150 | + <limit name="max_incomplete_connections">10000</limit> |
1151 | + <limit name="max_connections_per_user">100000</limit> |
1152 | + <limit name="max_pending_service_starts">10000</limit> |
1153 | + <limit name="max_names_per_connection">50000</limit> |
1154 | + <limit name="max_match_rules_per_connection">50000</limit> |
1155 | + <limit name="max_replies_per_connection">50000</limit> |
1156 | + <limit name="reply_timeout">300000</limit> |
1157 | + |
1158 | +</busconfig> |
1159 | |
1160 | === renamed directory 'handler/tests/mock' => 'tests/common/mock' |
1161 | === modified file 'tests/common/mock/CMakeLists.txt' |
1162 | --- handler/tests/mock/CMakeLists.txt 2014-03-13 17:11:09 +0000 |
1163 | +++ tests/common/mock/CMakeLists.txt 2015-03-30 20:55:55 +0000 |
1164 | @@ -4,11 +4,14 @@ |
1165 | ${Qt5DBus_INCLUDE_DIRS} |
1166 | ${CMAKE_CURRENT_BINARY_DIR} |
1167 | ${CMAKE_CURRENT_SOURCE_DIR} |
1168 | + ${CMAKE_SOURCE_DIR}/libtelephonyservice |
1169 | ) |
1170 | |
1171 | find_library(TELEPATHY_QT5_SERVICE_LIBRARIES telepathy-qt5-service) |
1172 | |
1173 | -set(mock_SRCS main.cpp protocol.cpp connection.cpp textchannel.cpp callchannel.cpp conferencecallchannel.cpp mockconnectiondbus.cpp speakeriface.cpp) |
1174 | +set(mock_SRCS main.cpp protocol.cpp connection.cpp textchannel.cpp callchannel.cpp |
1175 | + conferencecallchannel.cpp mockconnectiondbus.cpp speakeriface.cpp |
1176 | + emergencymodeiface.cpp ussdiface.cpp voicemailiface.cpp) |
1177 | qt5_add_dbus_adaptor(mock_SRCS MockConnection.xml mockconnectiondbus.h MockConnectionDBus) |
1178 | |
1179 | add_executable(telepathy-mock ${mock_SRCS}) |
1180 | |
1181 | === modified file 'tests/common/mock/MockConnection.xml' |
1182 | --- handler/tests/mock/MockConnection.xml 2014-03-20 21:03:26 +0000 |
1183 | +++ tests/common/mock/MockConnection.xml 2015-03-30 20:55:55 +0000 |
1184 | @@ -38,6 +38,55 @@ |
1185 | <arg name="phoneNumber" type="s" direction="in"/> |
1186 | <arg name="status" type="s" direction="in"/> |
1187 | </method> |
1188 | + <method name="SetOnline"> |
1189 | + <dox:d><![CDATA[ |
1190 | + Set the account online/offline |
1191 | + ]]></dox:d> |
1192 | + <arg name="online" type="b" direction="in"/> |
1193 | + </method> |
1194 | + <method name="SetPresence"> |
1195 | + <dox:d><![CDATA[ |
1196 | + Set the requested presence |
1197 | + ]]></dox:d> |
1198 | + <arg name="status" type="s" direction="in"/> |
1199 | + <arg name="statusMessage" type="s" direction="in"/> |
1200 | + </method> |
1201 | + <method name="SetVoicemailIndicator"> |
1202 | + <dox:d><![CDATA[ |
1203 | + Set the voicemail indicator on/off |
1204 | + ]]></dox:d> |
1205 | + <arg name="active" type="b" direction="in"/> |
1206 | + </method> |
1207 | + <method name="SetVoicemailNumber"> |
1208 | + <dox:d><![CDATA[ |
1209 | + Set the voicemail number |
1210 | + ]]></dox:d> |
1211 | + <arg name="number" type="s" direction="in"/> |
1212 | + </method> |
1213 | + <method name="SetVoicemailCount"> |
1214 | + <dox:d><![CDATA[ |
1215 | + Set the voicemail count |
1216 | + ]]></dox:d> |
1217 | + <arg name="count" type="i" direction="in"/> |
1218 | + </method> |
1219 | + <method name="SetEmergencyNumbers"> |
1220 | + <dox:d><![CDATA[ |
1221 | + Set the emergency numbers |
1222 | + ]]></dox:d> |
1223 | + <arg name="numbers" type="as" direction="in"/> |
1224 | + </method> |
1225 | + <method name="Serial"> |
1226 | + <dox:d><![CDATA[ |
1227 | + Get the USSD serial |
1228 | + ]]></dox:d> |
1229 | + <arg name="value" type="s" direction="out"/> |
1230 | + </method> |
1231 | + <signal name="MessageRead"> |
1232 | + <dox:d><![CDATA[ |
1233 | + A message was acknowledged |
1234 | + ]]></dox:d> |
1235 | + <arg name="messageId" type="s"/> |
1236 | + </signal> |
1237 | <signal name="MessageSent"> |
1238 | <dox:d><![CDATA[ |
1239 | A message was sent from the client. |
1240 | @@ -45,6 +94,7 @@ |
1241 | <arg name="message" type="s"/> |
1242 | <arg name="properties" type="a{sv}"/> |
1243 | <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="QVariantMap"/> |
1244 | + <annotation name="org.qtproject.QtDBus.QtTypeName.Out1" value="QVariantMap"/> |
1245 | </signal> |
1246 | <signal name="CallReceived"> |
1247 | <dox:d><![CDATA[ |
1248 | @@ -84,5 +134,15 @@ |
1249 | ]]></dox:d> |
1250 | <arg name="objectPath" type="s"/> |
1251 | </signal> |
1252 | + <signal name="Disconnected"> |
1253 | + <dox:d><![CDATA[ |
1254 | + The account was disconnected |
1255 | + ]]></dox:d> |
1256 | + </signal> |
1257 | + <signal name="Destroyed"> |
1258 | + <dox:d><![CDATA[ |
1259 | + The connection object was destroyed |
1260 | + ]]></dox:d> |
1261 | + </signal> |
1262 | </interface> |
1263 | </node> |
1264 | |
1265 | === modified file 'tests/common/mock/callchannel.cpp' |
1266 | --- handler/tests/mock/callchannel.cpp 2014-03-20 21:03:26 +0000 |
1267 | +++ tests/common/mock/callchannel.cpp 2015-03-30 20:55:55 +0000 |
1268 | @@ -172,7 +172,7 @@ |
1269 | { |
1270 | qDebug() << "call channel closed"; |
1271 | // TODO - for some reason the object is not being removed |
1272 | - mConnection->dbusConnection().unregisterObject(mObjPath, QDBusConnection::UnregisterTree); |
1273 | + mConnection->dbusConnection().unregisterObject(mBaseChannel->objectPath(), QDBusConnection::UnregisterTree); |
1274 | } |
1275 | |
1276 | Tp::BaseChannelPtr MockCallChannel::baseChannel() |
1277 | |
1278 | === modified file 'tests/common/mock/connection.cpp' |
1279 | --- handler/tests/mock/connection.cpp 2014-04-03 16:38:01 +0000 |
1280 | +++ tests/common/mock/connection.cpp 2015-03-30 20:55:55 +0000 |
1281 | @@ -36,7 +36,7 @@ |
1282 | const QString &protocolName, |
1283 | const QVariantMap ¶meters) : |
1284 | Tp::BaseConnection(dbusConnection, cmName, protocolName, parameters), |
1285 | - mHandleCount(0), mConferenceCall(0) |
1286 | + mConferenceCall(0), mVoicemailIndicator(false), mVoicemailCount(0) |
1287 | { |
1288 | setSelfHandle(newHandle("<SelfHandle>")); |
1289 | |
1290 | @@ -54,6 +54,7 @@ |
1291 | text.fixedProperties[TP_QT_IFACE_CHANNEL+".TargetHandleType"] = Tp::HandleTypeContact; |
1292 | text.allowedProperties.append(TP_QT_IFACE_CHANNEL+".TargetHandle"); |
1293 | text.allowedProperties.append(TP_QT_IFACE_CHANNEL+".TargetID"); |
1294 | + text.allowedProperties.append(TP_QT_IFACE_CHANNEL_INTERFACE_CONFERENCE + QLatin1String(".InitialInviteeHandles")); |
1295 | |
1296 | // set requestable call channel properties |
1297 | Tp::RequestableChannelClass call; |
1298 | @@ -77,26 +78,41 @@ |
1299 | // init presence interface |
1300 | simplePresenceIface = Tp::BaseConnectionSimplePresenceInterface::create(); |
1301 | simplePresenceIface->setSetPresenceCallback(Tp::memFun(this,&MockConnection::setPresence)); |
1302 | + simplePresenceIface->setMaxmimumStatusMessageLength(255); |
1303 | plugInterface(Tp::AbstractConnectionInterfacePtr::dynamicCast(simplePresenceIface)); |
1304 | |
1305 | // Set Presence |
1306 | Tp::SimpleStatusSpec presenceOnline; |
1307 | presenceOnline.type = Tp::ConnectionPresenceTypeAvailable; |
1308 | presenceOnline.maySetOnSelf = true; |
1309 | - presenceOnline.canHaveMessage = false; |
1310 | + presenceOnline.canHaveMessage = true; |
1311 | |
1312 | Tp::SimpleStatusSpec presenceOffline; |
1313 | presenceOffline.type = Tp::ConnectionPresenceTypeOffline; |
1314 | - presenceOffline.maySetOnSelf = false; |
1315 | - presenceOffline.canHaveMessage = false; |
1316 | - |
1317 | - Tp::SimpleStatusSpecMap statuses; |
1318 | - statuses.insert(QLatin1String("available"), presenceOnline); |
1319 | - statuses.insert(QLatin1String("offline"), presenceOffline); |
1320 | - |
1321 | - simplePresenceIface->setStatuses(statuses); |
1322 | + presenceOffline.maySetOnSelf = true; |
1323 | + presenceOffline.canHaveMessage = true; |
1324 | + |
1325 | + Tp::SimpleStatusSpec presenceAway; |
1326 | + presenceAway.type = Tp::ConnectionPresenceTypeAway; |
1327 | + presenceAway.maySetOnSelf = true; |
1328 | + presenceAway.canHaveMessage = true; |
1329 | + |
1330 | + mStatuses.insert(QLatin1String("available"), presenceOnline); |
1331 | + mStatuses.insert(QLatin1String("offline"), presenceOffline); |
1332 | + mStatuses.insert(QLatin1String("away"), presenceAway); |
1333 | + mStatuses.insert(QLatin1String("simlocked"), presenceAway); |
1334 | + mStatuses.insert(QLatin1String("flightmode"), presenceOffline); |
1335 | + mStatuses.insert(QLatin1String("nosim"), presenceOffline); |
1336 | + mStatuses.insert(QLatin1String("nomodem"), presenceOffline); |
1337 | + mStatuses.insert(QLatin1String("registered"), presenceOnline); |
1338 | + mStatuses.insert(QLatin1String("roaming"), presenceOnline); |
1339 | + mStatuses.insert(QLatin1String("unregistered"), presenceAway); |
1340 | + mStatuses.insert(QLatin1String("denied"), presenceAway); |
1341 | + mStatuses.insert(QLatin1String("unknown"), presenceAway); |
1342 | + mStatuses.insert(QLatin1String("searching"), presenceAway); |
1343 | + |
1344 | + simplePresenceIface->setStatuses(mStatuses); |
1345 | mSelfPresence.type = Tp::ConnectionPresenceTypeOffline; |
1346 | - mRequestedSelfPresence.type = Tp::ConnectionPresenceTypeOffline; |
1347 | |
1348 | contactsIface = Tp::BaseConnectionContactsInterface::create(); |
1349 | contactsIface->setGetContactAttributesCallback(Tp::memFun(this,&MockConnection::getContactAttributes)); |
1350 | @@ -105,9 +121,40 @@ |
1351 | << TP_QT_IFACE_CONNECTION_INTERFACE_SIMPLE_PRESENCE); |
1352 | plugInterface(Tp::AbstractConnectionInterfacePtr::dynamicCast(contactsIface)); |
1353 | |
1354 | + // init custom emergency mode interface (not provided by telepathy |
1355 | + emergencyModeIface = BaseConnectionEmergencyModeInterface::create(); |
1356 | + emergencyModeIface->setEmergencyNumbersCallback(Tp::memFun(this,&MockConnection::emergencyNumbers)); |
1357 | + plugInterface(Tp::AbstractConnectionInterfacePtr::dynamicCast(emergencyModeIface)); |
1358 | + mEmergencyNumbers << "123" << "456" << "789"; |
1359 | + emergencyModeIface->setEmergencyNumbers(mEmergencyNumbers); |
1360 | + |
1361 | + // init custom voicemail interface (not provided by telepathy) |
1362 | + voicemailIface = BaseConnectionVoicemailInterface::create(); |
1363 | + voicemailIface->setVoicemailCountCallback(Tp::memFun(this,&MockConnection::voicemailCount)); |
1364 | + voicemailIface->setVoicemailIndicatorCallback(Tp::memFun(this,&MockConnection::voicemailIndicator)); |
1365 | + voicemailIface->setVoicemailNumberCallback(Tp::memFun(this,&MockConnection::voicemailNumber)); |
1366 | + voicemailIface->setVoicemailNumber(mVoicemailNumber); |
1367 | + plugInterface(Tp::AbstractConnectionInterfacePtr::dynamicCast(voicemailIface)); |
1368 | + voicemailIface->setVoicemailCount(mVoicemailCount); |
1369 | + voicemailIface->setVoicemailIndicator(mVoicemailIndicator); |
1370 | + mVoicemailNumber = "555"; |
1371 | + |
1372 | + supplementaryServicesIface = BaseConnectionUSSDInterface::create(); |
1373 | + supplementaryServicesIface->setInitiateCallback(Tp::memFun(this,&MockConnection::USSDInitiate)); |
1374 | + supplementaryServicesIface->setRespondCallback(Tp::memFun(this,&MockConnection::USSDRespond)); |
1375 | + supplementaryServicesIface->setCancelCallback(Tp::memFun(this,&MockConnection::USSDCancel)); |
1376 | + |
1377 | + static int serial = 0; |
1378 | + serial++; |
1379 | + supplementaryServicesIface->setSerial(QString("accountserial%1").arg(QString::number(serial))); |
1380 | + |
1381 | + plugInterface(Tp::AbstractConnectionInterfacePtr::dynamicCast(supplementaryServicesIface)); |
1382 | + |
1383 | mDBus = new MockConnectionDBus(this); |
1384 | +} |
1385 | |
1386 | - setOnline(true); |
1387 | +MockConnection::~MockConnection() |
1388 | +{ |
1389 | } |
1390 | |
1391 | void MockConnection::addMMSToService(const QString &path, const QVariantMap &properties, const QString &servicePath) |
1392 | @@ -143,16 +190,45 @@ |
1393 | #endif |
1394 | } |
1395 | |
1396 | -MockConnection::~MockConnection() |
1397 | +MockTextChannel *MockConnection::textChannelForRecipients(const QStringList &recipients) |
1398 | { |
1399 | + Q_FOREACH(MockTextChannel *channel, mTextChannels) { |
1400 | + QStringList channelRecipients = channel->recipients(); |
1401 | + if (channelRecipients.length() != recipients.length()) { |
1402 | + continue; |
1403 | + } |
1404 | + |
1405 | + bool ok = true; |
1406 | + Q_FOREACH(const QString &recipient, recipients) { |
1407 | + if (!channelRecipients.contains(recipient)) { |
1408 | + ok = false; |
1409 | + break; |
1410 | + } |
1411 | + } |
1412 | + |
1413 | + if (ok) { |
1414 | + return channel; |
1415 | + } |
1416 | + } |
1417 | + return 0; |
1418 | } |
1419 | |
1420 | uint MockConnection::setPresence(const QString& status, const QString& statusMessage, Tp::DBusError *error) |
1421 | { |
1422 | - qDebug() << "setPresence" << status; |
1423 | - if (status == "available") { |
1424 | - mRequestedSelfPresence.type = Tp::ConnectionPresenceTypeAvailable; |
1425 | + qDebug() << "setPresence" << status << statusMessage; |
1426 | + Tp::SimpleContactPresences presences; |
1427 | + if (!mStatuses.contains(status) || !mStatuses[status].maySetOnSelf) { |
1428 | + error->set(TP_QT_ERROR_INVALID_ARGUMENT, "Status not supported or cannot be set"); |
1429 | + return selfHandle(); |
1430 | } |
1431 | + |
1432 | + Tp::SimpleStatusSpec spec = mStatuses[status]; |
1433 | + mSelfPresence.status = status; |
1434 | + mSelfPresence.type = spec.type; |
1435 | + mSelfPresence.statusMessage = spec.canHaveMessage ? statusMessage : ""; |
1436 | + |
1437 | + presences[selfHandle()] = mSelfPresence; |
1438 | + simplePresenceIface->setPresences(presences); |
1439 | return selfHandle(); |
1440 | } |
1441 | |
1442 | @@ -190,8 +266,9 @@ |
1443 | |
1444 | uint MockConnection::newHandle(const QString &identifier) |
1445 | { |
1446 | - mHandles[++mHandleCount] = identifier; |
1447 | - return mHandleCount; |
1448 | + static int handleCount = 0; |
1449 | + mHandles[++handleCount] = identifier; |
1450 | + return handleCount; |
1451 | } |
1452 | |
1453 | QMap<QString, MockCallChannel *> MockConnection::callChannels() |
1454 | @@ -248,29 +325,44 @@ |
1455 | } |
1456 | |
1457 | Tp::BaseChannelPtr MockConnection::createTextChannel(uint targetHandleType, |
1458 | - uint targetHandle, Tp::DBusError *error) |
1459 | + uint targetHandle, |
1460 | + const QVariantMap &hints, |
1461 | + Tp::DBusError *error) |
1462 | { |
1463 | Q_UNUSED(targetHandleType); |
1464 | Q_UNUSED(error); |
1465 | |
1466 | - QString requestedId = mHandles.value(targetHandle); |
1467 | - |
1468 | - if (mTextChannels.contains(requestedId)) { |
1469 | - return mTextChannels[requestedId]->baseChannel(); |
1470 | - } |
1471 | - |
1472 | - MockTextChannel *channel = new MockTextChannel(this, requestedId, targetHandle); |
1473 | + if (hints.contains(TP_QT_IFACE_CHANNEL_INTERFACE_CONFERENCE + QLatin1String(".InitialInviteeHandles")) && |
1474 | + targetHandleType == Tp::HandleTypeNone && targetHandle == 0) { |
1475 | + |
1476 | + } |
1477 | + |
1478 | + QStringList recipients; |
1479 | + bool flash; |
1480 | + if (hints.contains(TP_QT_IFACE_CHANNEL_INTERFACE_CONFERENCE + QLatin1String(".InitialInviteeHandles"))) { |
1481 | + recipients << inspectHandles(Tp::HandleTypeContact, qdbus_cast<Tp::UIntList>(hints[TP_QT_IFACE_CHANNEL_INTERFACE_CONFERENCE + QLatin1String(".InitialInviteeHandles")]), error); |
1482 | + } else { |
1483 | + recipients << mHandles.value(targetHandle); |
1484 | + } |
1485 | + |
1486 | + if (hints.contains(TP_QT_IFACE_CHANNEL_INTERFACE_SMS + QLatin1String(".Flash"))) { |
1487 | + flash = hints[TP_QT_IFACE_CHANNEL_INTERFACE_SMS + QLatin1String(".Flash")].toBool(); |
1488 | + } |
1489 | + |
1490 | + // FIXME: test flash messages |
1491 | + MockTextChannel *channel = new MockTextChannel(this, recipients, targetHandle); |
1492 | QObject::connect(channel, SIGNAL(messageRead(QString)), SLOT(onMessageRead(QString))); |
1493 | QObject::connect(channel, SIGNAL(destroyed()), SLOT(onTextChannelClosed())); |
1494 | QObject::connect(channel, SIGNAL(messageSent(QString,QVariantMap)), SIGNAL(messageSent(QString,QVariantMap))); |
1495 | qDebug() << channel; |
1496 | - mTextChannels[requestedId] = channel; |
1497 | + mTextChannels << channel; |
1498 | return channel->baseChannel(); |
1499 | } |
1500 | |
1501 | void MockConnection::onMessageRead(const QString &id) |
1502 | { |
1503 | - // FIXME: implement |
1504 | + // FIXME: check what else to do |
1505 | + Q_EMIT messageRead(id); |
1506 | } |
1507 | |
1508 | void MockConnection::onConferenceCallChannelClosed() |
1509 | @@ -355,7 +447,7 @@ |
1510 | } |
1511 | |
1512 | if (channelType == TP_QT_IFACE_CHANNEL_TYPE_TEXT) { |
1513 | - return createTextChannel(targetHandleType, targetHandle, error); |
1514 | + return createTextChannel(targetHandleType, targetHandle, hints, error); |
1515 | } else if (channelType == TP_QT_IFACE_CHANNEL_TYPE_CALL) { |
1516 | return createCallChannel(targetHandleType, targetHandle, hints, error); |
1517 | } else { |
1518 | @@ -367,33 +459,36 @@ |
1519 | |
1520 | void MockConnection::placeIncomingMessage(const QString &message, const QVariantMap &info) |
1521 | { |
1522 | - const QString sender = info["Sender"].toString(); |
1523 | - // check if there is an open channel for this sender and use it |
1524 | - Q_FOREACH(const QString &id, mTextChannels.keys()) { |
1525 | - if (id == sender) { |
1526 | - mTextChannels[id]->messageReceived(message, info); |
1527 | - return; |
1528 | - } |
1529 | - } |
1530 | - |
1531 | - Tp::DBusError error; |
1532 | - bool yours; |
1533 | - uint handle = newHandle(sender); |
1534 | - ensureChannel(TP_QT_IFACE_CHANNEL_TYPE_TEXT,Tp::HandleTypeContact, handle, yours, handle, false, QVariantMap(), &error); |
1535 | - if(error.isValid()) { |
1536 | - qWarning() << "Error creating channel for incoming message" << error.name() << error.message(); |
1537 | - return; |
1538 | - } |
1539 | - mTextChannels[sender]->messageReceived(message, info); |
1540 | + QString sender = info["Sender"].toString(); |
1541 | + QStringList recipients = info["Recipients"].toStringList(); |
1542 | + |
1543 | + MockTextChannel *channel = textChannelForRecipients(recipients); |
1544 | + if (!channel) { |
1545 | + // request the channel |
1546 | + Tp::DBusError error; |
1547 | + bool yours; |
1548 | + uint handle = newHandle(sender); |
1549 | + ensureChannel(TP_QT_IFACE_CHANNEL_TYPE_TEXT,Tp::HandleTypeContact, handle, yours, handle, false, QVariantMap(), &error); |
1550 | + if(error.isValid()) { |
1551 | + qWarning() << "Error creating channel for incoming message" << error.name() << error.message(); |
1552 | + return; |
1553 | + } |
1554 | + |
1555 | + channel = textChannelForRecipients(recipients); |
1556 | + if (!channel) { |
1557 | + return; |
1558 | + } |
1559 | + } |
1560 | + |
1561 | + channel->messageReceived(message, info); |
1562 | } |
1563 | |
1564 | void MockConnection::onTextChannelClosed() |
1565 | { |
1566 | MockTextChannel *channel = static_cast<MockTextChannel*>(sender()); |
1567 | if (channel) { |
1568 | - QString key = mTextChannels.key(channel); |
1569 | - qDebug() << "text channel closed for number " << key; |
1570 | - mTextChannels.remove(key); |
1571 | + qDebug() << "text channel closed for recipients " << channel->recipients(); |
1572 | + mTextChannels.removeAll(channel); |
1573 | } |
1574 | } |
1575 | |
1576 | @@ -469,6 +564,76 @@ |
1577 | return channel->objectPath(); |
1578 | } |
1579 | |
1580 | +QStringList MockConnection::emergencyNumbers(Tp::DBusError *error) |
1581 | +{ |
1582 | + return mEmergencyNumbers; |
1583 | +} |
1584 | + |
1585 | +void MockConnection::setEmergencyNumbers(const QStringList &emergencyNumbers) |
1586 | +{ |
1587 | + mEmergencyNumbers = emergencyNumbers; |
1588 | + emergencyModeIface->setEmergencyNumbers(emergencyNumbers); |
1589 | +} |
1590 | + |
1591 | +bool MockConnection::voicemailIndicator(Tp::DBusError *error) |
1592 | +{ |
1593 | + return mVoicemailIndicator; |
1594 | +} |
1595 | + |
1596 | +void MockConnection::setVoicemailIndicator(bool visible) |
1597 | +{ |
1598 | + mVoicemailIndicator = visible; |
1599 | + voicemailIface->setVoicemailIndicator(visible); |
1600 | +} |
1601 | + |
1602 | +QString MockConnection::voicemailNumber(Tp::DBusError *error) |
1603 | +{ |
1604 | + return mVoicemailNumber; |
1605 | +} |
1606 | + |
1607 | +void MockConnection::setVoicemailNumber(const QString &number) |
1608 | +{ |
1609 | + mVoicemailNumber = number; |
1610 | + voicemailIface->setVoicemailNumber(mVoicemailNumber); |
1611 | +} |
1612 | + |
1613 | +uint MockConnection::voicemailCount(Tp::DBusError *error) |
1614 | +{ |
1615 | + return mVoicemailCount; |
1616 | +} |
1617 | + |
1618 | +void MockConnection::setVoicemailCount(int count) |
1619 | +{ |
1620 | + mVoicemailCount = count; |
1621 | + voicemailIface->setVoicemailCount(mVoicemailCount); |
1622 | +} |
1623 | + |
1624 | +void MockConnection::USSDInitiate(const QString &command, Tp::DBusError *error) |
1625 | +{ |
1626 | + // FIXME: implement |
1627 | +} |
1628 | + |
1629 | +void MockConnection::USSDRespond(const QString &reply, Tp::DBusError *error) |
1630 | +{ |
1631 | + // FIXME: implement |
1632 | +} |
1633 | + |
1634 | +void MockConnection::USSDCancel(Tp::DBusError *error) |
1635 | +{ |
1636 | + // FIXME: implement |
1637 | +} |
1638 | + |
1639 | +QString MockConnection::serial() |
1640 | +{ |
1641 | + return supplementaryServicesIface->serial(); |
1642 | +} |
1643 | + |
1644 | +QString MockConnection::uniqueName() const |
1645 | +{ |
1646 | + static int count = 0; |
1647 | + return QString("connection%1%2").arg((quintptr) this, 0, 16).arg(count++, 0, 16); |
1648 | +} |
1649 | + |
1650 | void MockConnection::hangupCall(const QString &callerId) |
1651 | { |
1652 | if (!mCallChannels.contains(callerId)) { |
1653 | |
1654 | === modified file 'tests/common/mock/connection.h' |
1655 | --- handler/tests/mock/connection.h 2014-03-20 21:03:26 +0000 |
1656 | +++ tests/common/mock/connection.h 2015-03-30 20:55:55 +0000 |
1657 | @@ -34,6 +34,9 @@ |
1658 | #include "textchannel.h" |
1659 | #include "callchannel.h" |
1660 | #include "dbustypes.h" |
1661 | +#include "emergencymodeiface.h" |
1662 | +#include "ussdiface.h" |
1663 | +#include "voicemailiface.h" |
1664 | |
1665 | class MockTextChannel; |
1666 | class MockCallChannel; |
1667 | @@ -65,9 +68,16 @@ |
1668 | uint newHandle(const QString &identifier); |
1669 | QMap<QString, MockCallChannel*> callChannels(); |
1670 | |
1671 | + // phone custom interfaces |
1672 | + BaseConnectionEmergencyModeInterfacePtr emergencyModeIface; |
1673 | + BaseConnectionVoicemailInterfacePtr voicemailIface; |
1674 | + BaseConnectionUSSDInterfacePtr supplementaryServicesIface; |
1675 | + |
1676 | uint ensureHandle(const QString &id); |
1677 | Tp::BaseChannelPtr createTextChannel(uint targetHandleType, |
1678 | - uint targetHandle, Tp::DBusError *error); |
1679 | + uint targetHandle, |
1680 | + const QVariantMap &hints, |
1681 | + Tp::DBusError *error); |
1682 | Tp::BaseChannelPtr createCallChannel(uint targetHandleType, |
1683 | uint targetHandle, |
1684 | const QVariantMap &hints, |
1685 | @@ -76,7 +86,27 @@ |
1686 | ~MockConnection(); |
1687 | |
1688 | QString placeCall(const QVariantMap &properties); |
1689 | + |
1690 | + QStringList emergencyNumbers(Tp::DBusError *error); |
1691 | + void setEmergencyNumbers(const QStringList &emergencyNumbers); |
1692 | + |
1693 | + bool voicemailIndicator(Tp::DBusError *error); |
1694 | + void setVoicemailIndicator(bool visible); |
1695 | + QString voicemailNumber(Tp::DBusError *error); |
1696 | + void setVoicemailNumber(const QString &number); |
1697 | + uint voicemailCount(Tp::DBusError *error); |
1698 | + void setVoicemailCount(int count); |
1699 | + void USSDInitiate(const QString &command, Tp::DBusError *error); |
1700 | + void USSDRespond(const QString &reply, Tp::DBusError *error); |
1701 | + void USSDCancel(Tp::DBusError *error); |
1702 | + QString serial(); |
1703 | + |
1704 | + // FIXME: there is a problem in telepathy-qt that connection object paths and services are not properly unregistered |
1705 | + // and thus if we gain the same memory address (and thus the same pointer) every time we reconnect, there might be some problems |
1706 | + QString uniqueName() const; |
1707 | + |
1708 | Q_SIGNALS: |
1709 | + void messageRead(const QString &messageId); |
1710 | void messageSent(const QString &message, const QVariantMap &info); |
1711 | void callReceived(const QString &callerId); |
1712 | void callEnded(const QString &callerId); |
1713 | @@ -102,20 +132,27 @@ |
1714 | |
1715 | private: |
1716 | void addMMSToService(const QString &path, const QVariantMap &properties, const QString &servicePath); |
1717 | + |
1718 | + MockTextChannel *textChannelForRecipients(const QStringList &recipients); |
1719 | + |
1720 | QMap<uint, QString> mHandles; |
1721 | + Tp::SimpleStatusSpecMap mStatuses; |
1722 | |
1723 | - QMap<QString, MockTextChannel*> mTextChannels; |
1724 | + QList<MockTextChannel*> mTextChannels; |
1725 | QMap<QString, MockCallChannel*> mCallChannels; |
1726 | QMap<QString, QString> mInitialCallStatus; |
1727 | |
1728 | QStringList mModems; |
1729 | - uint mHandleCount; |
1730 | Tp::SimplePresence mSelfPresence; |
1731 | - Tp::SimplePresence mRequestedSelfPresence; |
1732 | |
1733 | MockConnectionDBus *mDBus; |
1734 | QStringList mIncomingCalls; |
1735 | MockConferenceCallChannel *mConferenceCall; |
1736 | + |
1737 | + QStringList mEmergencyNumbers; |
1738 | + int mVoicemailCount; |
1739 | + bool mVoicemailIndicator; |
1740 | + QString mVoicemailNumber; |
1741 | }; |
1742 | |
1743 | #endif |
1744 | |
1745 | === added file 'tests/common/mock/emergencymodeiface.cpp' |
1746 | --- tests/common/mock/emergencymodeiface.cpp 1970-01-01 00:00:00 +0000 |
1747 | +++ tests/common/mock/emergencymodeiface.cpp 2015-03-30 20:55:55 +0000 |
1748 | @@ -0,0 +1,133 @@ |
1749 | +/** |
1750 | + * Copyright (C) 2013-2015 Canonical, Ltd. |
1751 | + * |
1752 | + * This program is free software: you can redistribute it and/or modify it under |
1753 | + * the terms of the GNU General Public License version 3, as published by |
1754 | + * the Free Software Foundation. |
1755 | + * |
1756 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
1757 | + * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, |
1758 | + * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1759 | + * General Public License for more details. |
1760 | + * |
1761 | + * You should have received a copy of the GNU General Public License |
1762 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1763 | + * |
1764 | + * Authors: Tiago Salem Herrmann <tiago.herrmann@canonical.com> |
1765 | + Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> |
1766 | + */ |
1767 | + |
1768 | +#include <QDebug> |
1769 | + |
1770 | +#include <TelepathyQt/Constants> |
1771 | +#include <TelepathyQt/DBusObject> |
1772 | + |
1773 | +#include "emergencymodeiface.h" |
1774 | + |
1775 | +BaseConnectionEmergencyModeInterface::Adaptee::Adaptee(BaseConnectionEmergencyModeInterface *interface) |
1776 | + : QObject(interface), |
1777 | + mInterface(interface) |
1778 | +{ |
1779 | +} |
1780 | + |
1781 | + |
1782 | +struct TP_QT_NO_EXPORT BaseConnectionEmergencyModeInterface::Private { |
1783 | + Private(BaseConnectionEmergencyModeInterface *parent) |
1784 | + : adaptee(new BaseConnectionEmergencyModeInterface::Adaptee(parent)) { |
1785 | + } |
1786 | + EmergencyNumbersCallback emergencyNumbersCB; |
1787 | + BaseConnectionEmergencyModeInterface::Adaptee *adaptee; |
1788 | + QString fakeEmergencyNumber; |
1789 | +}; |
1790 | + |
1791 | +BaseConnectionEmergencyModeInterface::Adaptee::~Adaptee() |
1792 | +{ |
1793 | +} |
1794 | + |
1795 | +void BaseConnectionEmergencyModeInterface::Adaptee::emergencyNumbers(const ConnectionInterfaceEmergencyModeAdaptor::EmergencyNumbersContextPtr &context) |
1796 | +{ |
1797 | + if (!mInterface->mPriv->emergencyNumbersCB.isValid()) { |
1798 | + context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); |
1799 | + return; |
1800 | + } |
1801 | + Tp::DBusError error; |
1802 | + QStringList numbers = mInterface->mPriv->emergencyNumbersCB(&error); |
1803 | + if (error.isValid()) { |
1804 | + context->setFinishedWithError(error.name(), error.message()); |
1805 | + return; |
1806 | + } |
1807 | + if (mInterface->mPriv->fakeEmergencyNumber.isEmpty()) { |
1808 | + context->setFinished(numbers); |
1809 | + } else { |
1810 | + context->setFinished(QStringList() << numbers << mInterface->mPriv->fakeEmergencyNumber); |
1811 | + } |
1812 | +} |
1813 | + |
1814 | +BaseConnectionEmergencyModeInterface::BaseConnectionEmergencyModeInterface() |
1815 | + : AbstractConnectionInterface(TP_QT_IFACE_CONNECTION_EMERGENCYMODE), |
1816 | + mPriv(new Private(this)) |
1817 | +{ |
1818 | +} |
1819 | + |
1820 | +BaseConnectionEmergencyModeInterface::~BaseConnectionEmergencyModeInterface() |
1821 | +{ |
1822 | + delete mPriv; |
1823 | +} |
1824 | + |
1825 | +void BaseConnectionEmergencyModeInterface::setEmergencyNumbersCallback(const EmergencyNumbersCallback &cb) |
1826 | +{ |
1827 | + mPriv->emergencyNumbersCB = cb; |
1828 | +} |
1829 | + |
1830 | +void BaseConnectionEmergencyModeInterface::setEmergencyNumbers(const QStringList &numbers) |
1831 | +{ |
1832 | + QStringList finalEmergencyList(numbers); |
1833 | + |
1834 | + if (!mPriv->fakeEmergencyNumber.isEmpty()) { |
1835 | + finalEmergencyList << mPriv->fakeEmergencyNumber; |
1836 | + } |
1837 | + |
1838 | + Q_EMIT mPriv->adaptee->emergencyNumbersChanged(finalEmergencyList); |
1839 | +} |
1840 | + |
1841 | +void BaseConnectionEmergencyModeInterface::setFakeEmergencyNumber(const QString &fakeEmergencyNumber) |
1842 | +{ |
1843 | + mPriv->fakeEmergencyNumber = fakeEmergencyNumber; |
1844 | +} |
1845 | + |
1846 | +QVariantMap BaseConnectionEmergencyModeInterface::immutableProperties() const |
1847 | +{ |
1848 | + QVariantMap map; |
1849 | + return map; |
1850 | +} |
1851 | + |
1852 | +void BaseConnectionEmergencyModeInterface::createAdaptor() |
1853 | +{ |
1854 | + (void) new ConnectionInterfaceEmergencyModeAdaptor(dbusObject()->dbusConnection(), |
1855 | + mPriv->adaptee, dbusObject()); |
1856 | +} |
1857 | + |
1858 | + |
1859 | +ConnectionInterfaceEmergencyModeAdaptor::ConnectionInterfaceEmergencyModeAdaptor(const QDBusConnection& bus, QObject* adaptee, QObject* parent) |
1860 | + : Tp::AbstractAdaptor(bus, adaptee, parent) |
1861 | +{ |
1862 | + connect(adaptee, SIGNAL(emergencyNumbersChanged(QStringList)), SIGNAL(EmergencyNumbersChanged(QStringList))); |
1863 | +} |
1864 | + |
1865 | +ConnectionInterfaceEmergencyModeAdaptor::~ConnectionInterfaceEmergencyModeAdaptor() |
1866 | +{ |
1867 | +} |
1868 | + |
1869 | +QStringList ConnectionInterfaceEmergencyModeAdaptor::EmergencyNumbers(const QDBusMessage& dbusMessage) |
1870 | +{ |
1871 | + if (!adaptee()->metaObject()->indexOfMethod("emergencyNumbers(ConnectionInterfaceEmergencyModeAdaptor::EmergencyNumbersContextPtr)") == -1) { |
1872 | + dbusConnection().send(dbusMessage.createErrorReply(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"))); |
1873 | + return QStringList(); |
1874 | + } |
1875 | + |
1876 | + EmergencyNumbersContextPtr ctx = EmergencyNumbersContextPtr( |
1877 | + new Tp::MethodInvocationContext< QStringList >(dbusConnection(), dbusMessage)); |
1878 | + QMetaObject::invokeMethod(adaptee(), "emergencyNumbers", |
1879 | + Q_ARG(ConnectionInterfaceEmergencyModeAdaptor::EmergencyNumbersContextPtr, ctx)); |
1880 | + return QStringList(); |
1881 | +} |
1882 | |
1883 | === added file 'tests/common/mock/emergencymodeiface.h' |
1884 | --- tests/common/mock/emergencymodeiface.h 1970-01-01 00:00:00 +0000 |
1885 | +++ tests/common/mock/emergencymodeiface.h 2015-03-30 20:55:55 +0000 |
1886 | @@ -0,0 +1,121 @@ |
1887 | +/** |
1888 | + * Copyright (C) 2013-2015 Canonical, Ltd. |
1889 | + * |
1890 | + * This program is free software: you can redistribute it and/or modify it under |
1891 | + * the terms of the GNU General Public License version 3, as published by |
1892 | + * the Free Software Foundation. |
1893 | + * |
1894 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
1895 | + * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, |
1896 | + * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1897 | + * General Public License for more details. |
1898 | + * |
1899 | + * You should have received a copy of the GNU General Public License |
1900 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1901 | + * |
1902 | + * Authors: Tiago Salem Herrmann <tiago.herrmann@canonical.com> |
1903 | + Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> |
1904 | + */ |
1905 | + |
1906 | +#ifndef OFONOEMERGENCYMODEIFACE_H |
1907 | +#define OFONOEMERGENCYMODEIFACE_H |
1908 | + |
1909 | +// telepathy-qt |
1910 | +#include <TelepathyQt/Constants> |
1911 | +#include <TelepathyQt/BaseConnection> |
1912 | +#include <TelepathyQt/AbstractAdaptor> |
1913 | +#include <TelepathyQt/DBusError> |
1914 | +#include <TelepathyQt/Callbacks> |
1915 | + |
1916 | +class BaseConnectionEmergencyModeInterface; |
1917 | + |
1918 | +typedef Tp::SharedPtr<BaseConnectionEmergencyModeInterface> BaseConnectionEmergencyModeInterfacePtr; |
1919 | + |
1920 | +#define TP_QT_IFACE_CONNECTION_EMERGENCYMODE "com.canonical.Telephony.EmergencyMode" |
1921 | + |
1922 | +class TP_QT_EXPORT BaseConnectionEmergencyModeInterface : public Tp::AbstractConnectionInterface |
1923 | +{ |
1924 | + Q_OBJECT |
1925 | + Q_DISABLE_COPY(BaseConnectionEmergencyModeInterface) |
1926 | + |
1927 | +public: |
1928 | + static BaseConnectionEmergencyModeInterfacePtr create() { |
1929 | + return BaseConnectionEmergencyModeInterfacePtr(new BaseConnectionEmergencyModeInterface()); |
1930 | + } |
1931 | + template<typename BaseConnectionEmergencyModeInterfaceSubclass> |
1932 | + static Tp::SharedPtr<BaseConnectionEmergencyModeInterfaceSubclass> create() { |
1933 | + return Tp::SharedPtr<BaseConnectionEmergencyModeInterfaceSubclass>( |
1934 | + new BaseConnectionEmergencyModeInterfaceSubclass()); |
1935 | + } |
1936 | + QVariantMap immutableProperties() const; |
1937 | + virtual ~BaseConnectionEmergencyModeInterface(); |
1938 | + |
1939 | + typedef Tp::Callback1<QStringList, Tp::DBusError*> EmergencyNumbersCallback; |
1940 | + void setEmergencyNumbersCallback(const EmergencyNumbersCallback &cb); |
1941 | + void setFakeEmergencyNumber(const QString &fakeEmergencyNumber); |
1942 | + |
1943 | +public Q_SLOTS: |
1944 | + void setEmergencyNumbers(const QStringList &numbers); |
1945 | + |
1946 | +protected: |
1947 | + BaseConnectionEmergencyModeInterface(); |
1948 | + |
1949 | +private: |
1950 | + void createAdaptor(); |
1951 | + |
1952 | + class Adaptee; |
1953 | + friend class Adaptee; |
1954 | + struct Private; |
1955 | + friend struct Private; |
1956 | + Private *mPriv; |
1957 | +}; |
1958 | + |
1959 | + |
1960 | +class TP_QT_EXPORT ConnectionInterfaceEmergencyModeAdaptor : public Tp::AbstractAdaptor |
1961 | +{ |
1962 | + Q_OBJECT |
1963 | + Q_CLASSINFO("D-Bus Interface", TP_QT_IFACE_CONNECTION_EMERGENCYMODE) |
1964 | + Q_CLASSINFO("D-Bus Introspection", "" |
1965 | +" <interface name=\"com.canonical.Telephony.EmergencyMode\">\n" |
1966 | +" <method name=\"EmergencyNumbers\">\n" |
1967 | +" <arg direction=\"out\" type=\"as\" name=\"emergencyNumbers\"/>\n" |
1968 | +" </method>\n" |
1969 | +" <signal name=\"EmergencyNumbersChanged\">\n" |
1970 | +" <arg type=\"as\" name=\"numbers\"/>\n" |
1971 | +" </signal>\n" |
1972 | +" </interface>\n" |
1973 | +"") |
1974 | + |
1975 | +public: |
1976 | + ConnectionInterfaceEmergencyModeAdaptor(const QDBusConnection& dbusConnection, QObject* adaptee, QObject* parent); |
1977 | + virtual ~ConnectionInterfaceEmergencyModeAdaptor(); |
1978 | + |
1979 | + typedef Tp::MethodInvocationContextPtr< QStringList > EmergencyNumbersContextPtr; |
1980 | + |
1981 | +public Q_SLOTS: // METHODS |
1982 | + QStringList EmergencyNumbers(const QDBusMessage& dbusMessage); |
1983 | + |
1984 | +Q_SIGNALS: // SIGNALS |
1985 | + void EmergencyNumbersChanged(const QStringList &numbers); |
1986 | +}; |
1987 | + |
1988 | + |
1989 | +class TP_QT_NO_EXPORT BaseConnectionEmergencyModeInterface::Adaptee : public QObject |
1990 | +{ |
1991 | + Q_OBJECT |
1992 | + |
1993 | +public: |
1994 | + Adaptee(BaseConnectionEmergencyModeInterface *interface); |
1995 | + ~Adaptee(); |
1996 | + |
1997 | +private Q_SLOTS: |
1998 | + void emergencyNumbers(const ConnectionInterfaceEmergencyModeAdaptor::EmergencyNumbersContextPtr &context); |
1999 | + |
2000 | +Q_SIGNALS: |
2001 | + void emergencyNumbersChanged(const QStringList &numbers); |
2002 | + |
2003 | +public: |
2004 | + BaseConnectionEmergencyModeInterface *mInterface; |
2005 | +}; |
2006 | + |
2007 | +#endif |
2008 | |
2009 | === modified file 'tests/common/mock/main.cpp' |
2010 | --- handler/tests/mock/main.cpp 2014-01-07 19:53:45 +0000 |
2011 | +++ tests/common/mock/main.cpp 2015-03-30 20:55:55 +0000 |
2012 | @@ -31,10 +31,17 @@ |
2013 | Tp::enableDebug(true); |
2014 | Tp::enableWarnings(true); |
2015 | |
2016 | + // create a standard protocol |
2017 | Tp::BaseProtocolPtr proto = Tp::BaseProtocol::create<Protocol>( |
2018 | QDBusConnection::sessionBus(), QLatin1String("mock")); |
2019 | + |
2020 | + // create a phone protocol |
2021 | + Tp::BaseProtocolPtr phoneProto = Tp::BaseProtocol::create<Protocol>( |
2022 | + QDBusConnection::sessionBus(), QLatin1String("ofono")); |
2023 | + |
2024 | Tp::BaseConnectionManagerPtr cm = Tp::BaseConnectionManager::create( |
2025 | QDBusConnection::sessionBus(), QLatin1String("mock")); |
2026 | + cm->addProtocol(phoneProto); |
2027 | cm->addProtocol(proto); |
2028 | cm->registerObject(); |
2029 | |
2030 | |
2031 | === modified file 'tests/common/mock/mockconnectiondbus.cpp' |
2032 | --- handler/tests/mock/mockconnectiondbus.cpp 2014-03-20 21:03:26 +0000 |
2033 | +++ tests/common/mock/mockconnectiondbus.cpp 2015-03-30 20:55:55 +0000 |
2034 | @@ -28,7 +28,9 @@ |
2035 | MockConnectionDBus::MockConnectionDBus(MockConnection *parent) : |
2036 | QObject(parent), mAdaptor(0), mConnection(parent) |
2037 | { |
2038 | - |
2039 | + connect(mConnection, |
2040 | + SIGNAL(messageRead(QString)), |
2041 | + SIGNAL(MessageRead(QString))); |
2042 | connect(mConnection, |
2043 | SIGNAL(messageSent(QString,QVariantMap)), |
2044 | SIGNAL(MessageSent(QString,QVariantMap))); |
2045 | @@ -50,10 +52,22 @@ |
2046 | connect(mConnection, |
2047 | SIGNAL(channelSplitted(QString)), |
2048 | SIGNAL(ChannelSplitted(QString))); |
2049 | + connect(mConnection, |
2050 | + SIGNAL(disconnected()), |
2051 | + SIGNAL(Disconnected())); |
2052 | + connect(mConnection, |
2053 | + SIGNAL(destroyed()), |
2054 | + SIGNAL(Destroyed())); |
2055 | qDBusRegisterMetaType<QList<QVariantMap> >(); |
2056 | + mObjectPath = "/com/canonical/MockConnection/" + mConnection->protocolName(); |
2057 | connectToBus(); |
2058 | } |
2059 | |
2060 | +MockConnectionDBus::~MockConnectionDBus() |
2061 | +{ |
2062 | + QDBusConnection::sessionBus().unregisterObject(mObjectPath, QDBusConnection::UnregisterTree); |
2063 | +} |
2064 | + |
2065 | bool MockConnectionDBus::connectToBus() |
2066 | { |
2067 | bool ok = QDBusConnection::sessionBus().registerService("com.canonical.MockConnection"); |
2068 | @@ -65,7 +79,7 @@ |
2069 | mAdaptor = new MockConnectionAdaptor(this); |
2070 | } |
2071 | |
2072 | - return QDBusConnection::sessionBus().registerObject("/com/canonical/MockConnection", this); |
2073 | + return QDBusConnection::sessionBus().registerObject(mObjectPath, this); |
2074 | } |
2075 | |
2076 | void MockConnectionDBus::PlaceIncomingMessage(const QString &message, const QVariantMap &properties) |
2077 | @@ -87,3 +101,39 @@ |
2078 | { |
2079 | mConnection->setCallState(phoneNumber, state); |
2080 | } |
2081 | + |
2082 | +void MockConnectionDBus::SetOnline(bool online) |
2083 | +{ |
2084 | + mConnection->setOnline(online); |
2085 | +} |
2086 | + |
2087 | +void MockConnectionDBus::SetPresence(const QString &status, const QString &statusMessage) |
2088 | +{ |
2089 | + Tp::DBusError error; |
2090 | + mConnection->setPresence(status, statusMessage, &error); |
2091 | +} |
2092 | + |
2093 | +void MockConnectionDBus::SetVoicemailIndicator(bool active) |
2094 | +{ |
2095 | + mConnection->setVoicemailIndicator(active); |
2096 | +} |
2097 | + |
2098 | +void MockConnectionDBus::SetVoicemailNumber(const QString &number) |
2099 | +{ |
2100 | + mConnection->setVoicemailNumber(number); |
2101 | +} |
2102 | + |
2103 | +void MockConnectionDBus::SetVoicemailCount(int count) |
2104 | +{ |
2105 | + mConnection->setVoicemailCount(count); |
2106 | +} |
2107 | + |
2108 | +void MockConnectionDBus::SetEmergencyNumbers(const QStringList &numbers) |
2109 | +{ |
2110 | + mConnection->setEmergencyNumbers(numbers); |
2111 | +} |
2112 | + |
2113 | +QString MockConnectionDBus::Serial() |
2114 | +{ |
2115 | + return mConnection->serial(); |
2116 | +} |
2117 | |
2118 | === modified file 'tests/common/mock/mockconnectiondbus.h' |
2119 | --- handler/tests/mock/mockconnectiondbus.h 2014-03-20 21:03:26 +0000 |
2120 | +++ tests/common/mock/mockconnectiondbus.h 2015-03-30 20:55:55 +0000 |
2121 | @@ -30,15 +30,30 @@ |
2122 | Q_OBJECT |
2123 | public: |
2124 | explicit MockConnectionDBus(MockConnection *parent); |
2125 | + ~MockConnectionDBus(); |
2126 | |
2127 | bool connectToBus(); |
2128 | void PlaceIncomingMessage(const QString &message, const QVariantMap &properties); |
2129 | QString PlaceCall(const QVariantMap &properties); |
2130 | void HangupCall(const QString &callerId); |
2131 | void SetCallState(const QString &phoneNumber, const QString &state); |
2132 | + void SetOnline(bool online); |
2133 | + void SetPresence(const QString &status, const QString &statusMessage); |
2134 | + |
2135 | + // voicemail stuff |
2136 | + void SetVoicemailIndicator(bool active); |
2137 | + void SetVoicemailNumber(const QString &number); |
2138 | + void SetVoicemailCount(int count); |
2139 | + |
2140 | + // emergency numbers stuff |
2141 | + void SetEmergencyNumbers(const QStringList &numbers); |
2142 | + |
2143 | + // USSD stuff |
2144 | + QString Serial(); |
2145 | |
2146 | Q_SIGNALS: |
2147 | // signals that will be relayed into the bus |
2148 | + void MessageRead(const QString &messageId); |
2149 | void MessageSent(const QString &mesasge, const QVariantMap &properties); |
2150 | void CallReceived(const QString &callerId); |
2151 | void CallEnded(const QString &callerId); |
2152 | @@ -47,9 +62,13 @@ |
2153 | void ChannelMerged(const QString &objectPath); |
2154 | void ChannelSplitted(const QString &objectPath); |
2155 | |
2156 | + void Disconnected(); |
2157 | + void Destroyed(); |
2158 | + |
2159 | private: |
2160 | MockConnectionAdaptor *mAdaptor; |
2161 | MockConnection *mConnection; |
2162 | + QString mObjectPath; |
2163 | }; |
2164 | |
2165 | #endif // MOCKCONNECTIONDBUS_H |
2166 | |
2167 | === modified file 'tests/common/mock/protocol.cpp' |
2168 | --- handler/tests/mock/protocol.cpp 2014-01-07 19:53:45 +0000 |
2169 | +++ tests/common/mock/protocol.cpp 2015-03-30 20:55:55 +0000 |
2170 | @@ -30,6 +30,19 @@ |
2171 | Tp::RequestableChannelClassSpec::audioCall()); |
2172 | |
2173 | setCreateConnectionCallback(memFun(this, &Protocol::createConnection)); |
2174 | + |
2175 | + Tp::ProtocolParameterList parameters; |
2176 | + Tp::ProtocolParameter parameter("modem-objpath", "s", 0); |
2177 | + parameters << parameter; |
2178 | + setParameters(parameters); |
2179 | + |
2180 | + addressingIface = Tp::BaseProtocolAddressingInterface::create(); |
2181 | + if (name == "ofono") { |
2182 | + addressingIface->setAddressableVCardFields(QStringList() << "tel"); |
2183 | + } else { |
2184 | + addressingIface->setAddressableVCardFields(QStringList() << "x-mock-im" << "x-sip"); |
2185 | + } |
2186 | + plugInterface(addressingIface); |
2187 | } |
2188 | |
2189 | Tp::BaseConnectionPtr Protocol::createConnection(const QVariantMap ¶meters, Tp::DBusError *error) { |
2190 | |
2191 | === modified file 'tests/common/mock/protocol.h' |
2192 | --- handler/tests/mock/protocol.h 2014-01-07 19:53:45 +0000 |
2193 | +++ tests/common/mock/protocol.h 2015-03-30 20:55:55 +0000 |
2194 | @@ -31,6 +31,7 @@ |
2195 | |
2196 | public: |
2197 | Protocol(const QDBusConnection &dbusConnection, const QString &name); |
2198 | + Tp::BaseProtocolAddressingInterfacePtr addressingIface; |
2199 | |
2200 | private: |
2201 | Tp::BaseConnectionPtr createConnection(const QVariantMap ¶meters, Tp::DBusError *error); |
2202 | |
2203 | === modified file 'tests/common/mock/speakeriface.h' |
2204 | --- handler/tests/mock/speakeriface.h 2014-03-13 17:11:09 +0000 |
2205 | +++ tests/common/mock/speakeriface.h 2015-03-30 20:55:55 +0000 |
2206 | @@ -1,19 +1,20 @@ |
2207 | /** |
2208 | - * Copyright (C) 2013 Canonical, Ltd. |
2209 | + * Copyright (C) 2013-2015 Canonical, Ltd. |
2210 | * |
2211 | * This program is free software: you can redistribute it and/or modify it under |
2212 | - * the terms of the GNU Lesser General Public License version 3, as published by |
2213 | + * the terms of the GNU General Public License version 3, as published by |
2214 | * the Free Software Foundation. |
2215 | * |
2216 | * This program is distributed in the hope that it will be useful, but WITHOUT |
2217 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, |
2218 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
2219 | - * Lesser General Public License for more details. |
2220 | + * General Public License for more details. |
2221 | * |
2222 | - * You should have received a copy of the GNU Lesser General Public License |
2223 | + * You should have received a copy of the GNU General Public License |
2224 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2225 | * |
2226 | * Authors: Tiago Salem Herrmann <tiago.herrmann@canonical.com> |
2227 | + Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> |
2228 | */ |
2229 | |
2230 | #ifndef OFONOSPEAKERIFACE_H |
2231 | |
2232 | === modified file 'tests/common/mock/textchannel.cpp' |
2233 | --- handler/tests/mock/textchannel.cpp 2014-01-07 19:53:45 +0000 |
2234 | +++ tests/common/mock/textchannel.cpp 2015-03-30 20:55:55 +0000 |
2235 | @@ -36,20 +36,24 @@ |
2236 | return argument; |
2237 | } |
2238 | |
2239 | -MockTextChannel::MockTextChannel(MockConnection *conn, QString phoneNumber, uint targetHandle, QObject *parent): |
2240 | +MockTextChannel::MockTextChannel(MockConnection *conn, QStringList recipients, uint targetHandle, QObject *parent): |
2241 | QObject(parent), |
2242 | mConnection(conn), |
2243 | - mPhoneNumber(phoneNumber), |
2244 | + mRecipients(recipients), |
2245 | mTargetHandle(targetHandle), |
2246 | mMessageCounter(1) |
2247 | { |
2248 | qDBusRegisterMetaType<AttachmentStruct>(); |
2249 | qDBusRegisterMetaType<AttachmentList>(); |
2250 | |
2251 | + Tp::HandleType type = recipients.count() > 1 ? Tp::HandleTypeNone : Tp::HandleTypeContact; |
2252 | + |
2253 | + |
2254 | Tp::BaseChannelPtr baseChannel = Tp::BaseChannel::create(mConnection, |
2255 | TP_QT_IFACE_CHANNEL_TYPE_TEXT, |
2256 | targetHandle, |
2257 | - Tp::HandleTypeContact); |
2258 | + type); |
2259 | + mBaseChannel = baseChannel; |
2260 | Tp::BaseChannelTextTypePtr textType = Tp::BaseChannelTextType::create(baseChannel.data()); |
2261 | baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(textType)); |
2262 | |
2263 | @@ -67,9 +71,15 @@ |
2264 | deliveryReportingSupport); |
2265 | |
2266 | mMessagesIface->setSendMessageCallback(Tp::memFun(this,&MockTextChannel::sendMessage)); |
2267 | - |
2268 | baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(mMessagesIface)); |
2269 | - mBaseChannel = baseChannel; |
2270 | + |
2271 | + // group stuff |
2272 | + mGroupIface = Tp::BaseChannelGroupInterface::create(Tp::ChannelGroupFlagCanAdd, conn->selfHandle()); |
2273 | + mGroupIface->setAddMembersCallback(Tp::memFun(this,&MockTextChannel::onAddMembers)); |
2274 | + mGroupIface->setRemoveMembersCallback(Tp::memFun(this,&MockTextChannel::onRemoveMembers)); |
2275 | + baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(mGroupIface)); |
2276 | + addMembers(recipients); |
2277 | + |
2278 | mTextChannel = Tp::BaseChannelTextTypePtr::dynamicCast(mBaseChannel->interface(TP_QT_IFACE_CHANNEL_TYPE_TEXT)); |
2279 | mTextChannel->setMessageAcknowledgedCallback(Tp::memFun(this,&MockTextChannel::messageAcknowledged)); |
2280 | QObject::connect(mBaseChannel.data(), SIGNAL(closed()), this, SLOT(deleteLater())); |
2281 | @@ -101,11 +111,20 @@ |
2282 | QString messageText = body["content"].variant().toString(); |
2283 | QVariantMap properties; |
2284 | properties["SentTime"] = QDateTime::currentDateTime().toString(Qt::ISODate); |
2285 | - properties["Recipients"] = QStringList() << mPhoneNumber; |
2286 | + properties["Recipients"] = mRecipients; |
2287 | properties["Id"] = id; |
2288 | |
2289 | Q_EMIT messageSent(messageText, properties); |
2290 | |
2291 | + QTimer *deliveryReportTimer = new QTimer(this); |
2292 | + deliveryReportTimer->setSingleShot(true); |
2293 | + deliveryReportTimer->setInterval(100); |
2294 | + connect(deliveryReportTimer, &QTimer::timeout, [id, deliveryReportTimer, this] { |
2295 | + this->placeDeliveryReport(id, "sent"); |
2296 | + deliveryReportTimer->deleteLater(); |
2297 | + }); |
2298 | + deliveryReportTimer->start(); |
2299 | + |
2300 | return id; |
2301 | } |
2302 | |
2303 | @@ -125,7 +144,8 @@ |
2304 | Tp::MessagePartList partList; |
2305 | Tp::MessagePart header; |
2306 | header["message-sender"] = QDBusVariant(mTargetHandle); |
2307 | - header["message-sender-id"] = QDBusVariant(mPhoneNumber); |
2308 | + // FIXME: fix it |
2309 | + header["message-sender-id"] = QDBusVariant(mRecipients.first()); |
2310 | header["message-type"] = QDBusVariant(Tp::ChannelTextMessageTypeDeliveryReport); |
2311 | header["delivery-status"] = QDBusVariant(delivery_status); |
2312 | header["delivery-token"] = QDBusVariant(messageId); |
2313 | @@ -145,7 +165,7 @@ |
2314 | header["message-token"] = QDBusVariant(info["SentTime"].toString() +"-" + QString::number(mMessageCounter++)); |
2315 | header["message-received"] = QDBusVariant(QDateTime::fromString(info["SentTime"].toString(), Qt::ISODate).toTime_t()); |
2316 | header["message-sender"] = QDBusVariant(mTargetHandle); |
2317 | - header["message-sender-id"] = QDBusVariant(mPhoneNumber); |
2318 | + header["message-sender-id"] = QDBusVariant(mRecipients.first()); |
2319 | header["message-type"] = QDBusVariant(Tp::ChannelTextMessageTypeNormal); |
2320 | partList << header << body; |
2321 | |
2322 | @@ -198,3 +218,45 @@ |
2323 | |
2324 | mTextChannel->addReceivedMessage(message); |
2325 | } |
2326 | + |
2327 | +void MockTextChannel::addMembers(QStringList recipients) |
2328 | +{ |
2329 | + Tp::UIntList handles; |
2330 | + Q_FOREACH(const QString &recipient, recipients) { |
2331 | + uint handle = mConnection->ensureHandle(recipient); |
2332 | + handles << handle; |
2333 | + if (!mRecipients.contains(recipient)) { |
2334 | + mRecipients << recipient; |
2335 | + } |
2336 | + if (!mMembers.contains(handle)) { |
2337 | + mMembers << handle; |
2338 | + } |
2339 | + } |
2340 | + mGroupIface->addMembers(handles, recipients); |
2341 | +} |
2342 | + |
2343 | +QStringList MockTextChannel::recipients() const |
2344 | +{ |
2345 | + return mRecipients; |
2346 | +} |
2347 | + |
2348 | +Tp::UIntList MockTextChannel::members() |
2349 | +{ |
2350 | + return mMembers; |
2351 | +} |
2352 | + |
2353 | +void MockTextChannel::onAddMembers(const Tp::UIntList &handles, const QString &message, Tp::DBusError *error) |
2354 | +{ |
2355 | + addMembers(mConnection->inspectHandles(Tp::HandleTypeContact, handles, error)); |
2356 | +} |
2357 | + |
2358 | +void MockTextChannel::onRemoveMembers(const Tp::UIntList &handles, const QString &message, Tp::DBusError *error) |
2359 | +{ |
2360 | + Q_FOREACH(uint handle, handles) { |
2361 | + Q_FOREACH(const QString &recipient, mConnection->inspectHandles(Tp::HandleTypeContact, Tp::UIntList() << handle, error)) { |
2362 | + mRecipients.removeAll(recipient); |
2363 | + } |
2364 | + mMembers.removeAll(handle); |
2365 | + } |
2366 | + mGroupIface->removeMembers(handles); |
2367 | +} |
2368 | |
2369 | === modified file 'tests/common/mock/textchannel.h' |
2370 | --- handler/tests/mock/textchannel.h 2014-01-07 19:53:45 +0000 |
2371 | +++ tests/common/mock/textchannel.h 2015-03-30 20:55:55 +0000 |
2372 | @@ -35,13 +35,19 @@ |
2373 | { |
2374 | Q_OBJECT |
2375 | public: |
2376 | - MockTextChannel(MockConnection *conn, QString phoneNumber, uint targetHandle, QObject *parent = 0); |
2377 | + MockTextChannel(MockConnection *conn, QStringList recipients, uint targetHandle, QObject *parent = 0); |
2378 | QString sendMessage(const Tp::MessagePartList& message, uint flags, Tp::DBusError* error); |
2379 | void messageReceived(const QString & message, const QVariantMap &info); |
2380 | Tp::BaseChannelPtr baseChannel(); |
2381 | void messageAcknowledged(const QString &id); |
2382 | void mmsReceived(const QString &id, const QVariantMap &properties); |
2383 | |
2384 | + void addMembers(QStringList recipients); |
2385 | + QStringList recipients() const; |
2386 | + Tp::UIntList members(); |
2387 | + void onAddMembers(const Tp::UIntList& handles, const QString& message, Tp::DBusError* error); |
2388 | + void onRemoveMembers(const Tp::UIntList& handles, const QString& message, Tp::DBusError* error); |
2389 | + |
2390 | public Q_SLOTS: |
2391 | void placeDeliveryReport(const QString &messageId, const QString &status); |
2392 | |
2393 | @@ -52,12 +58,14 @@ |
2394 | private: |
2395 | ~MockTextChannel(); |
2396 | Tp::BaseChannelPtr mBaseChannel; |
2397 | - QString mPhoneNumber; |
2398 | + QStringList mRecipients; |
2399 | MockConnection *mConnection; |
2400 | uint mTargetHandle; |
2401 | Tp::BaseChannelMessagesInterfacePtr mMessagesIface; |
2402 | + Tp::BaseChannelGroupInterfacePtr mGroupIface; |
2403 | Tp::BaseChannelTextTypePtr mTextChannel; |
2404 | uint mMessageCounter; |
2405 | + Tp::UIntList mMembers; |
2406 | }; |
2407 | |
2408 | #endif // MOCKTEXTCHANNEL_H |
2409 | |
2410 | === added file 'tests/common/mock/ussdiface.cpp' |
2411 | --- tests/common/mock/ussdiface.cpp 1970-01-01 00:00:00 +0000 |
2412 | +++ tests/common/mock/ussdiface.cpp 2015-03-30 20:55:55 +0000 |
2413 | @@ -0,0 +1,312 @@ |
2414 | +/** |
2415 | + * Copyright (C) 2013-2015 Canonical, Ltd. |
2416 | + * |
2417 | + * This program is free software: you can redistribute it and/or modify it under |
2418 | + * the terms of the GNU General Public License version 3, as published by |
2419 | + * the Free Software Foundation. |
2420 | + * |
2421 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
2422 | + * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, |
2423 | + * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
2424 | + * General Public License for more details. |
2425 | + * |
2426 | + * You should have received a copy of the GNU General Public License |
2427 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2428 | + * |
2429 | + * Authors: Tiago Salem Herrmann <tiago.herrmann@canonical.com> |
2430 | + Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> |
2431 | + */ |
2432 | + |
2433 | +#include <QDebug> |
2434 | + |
2435 | +#include <TelepathyQt/Constants> |
2436 | +#include <TelepathyQt/DBusObject> |
2437 | + |
2438 | +#include "ussdiface.h" |
2439 | + |
2440 | +// Conn.I.USSD |
2441 | +BaseConnectionUSSDInterface::Adaptee::Adaptee(BaseConnectionUSSDInterface *interface) |
2442 | + : QObject(interface), |
2443 | + mInterface(interface) |
2444 | +{ |
2445 | +} |
2446 | + |
2447 | + |
2448 | +struct TP_QT_NO_EXPORT BaseConnectionUSSDInterface::Private { |
2449 | + Private(BaseConnectionUSSDInterface *parent) |
2450 | + : adaptee(new BaseConnectionUSSDInterface::Adaptee(parent)) { |
2451 | + } |
2452 | + QString state; |
2453 | + QString serial; |
2454 | + InitiateCallback initiateCB; |
2455 | + RespondCallback respondCB; |
2456 | + CancelCallback cancelCB; |
2457 | + BaseConnectionUSSDInterface::Adaptee *adaptee; |
2458 | +}; |
2459 | + |
2460 | +BaseConnectionUSSDInterface::Adaptee::~Adaptee() |
2461 | +{ |
2462 | +} |
2463 | + |
2464 | +void BaseConnectionUSSDInterface::Adaptee::initiate(const QString &command, const ConnectionInterfaceUSSDAdaptor::InitiateContextPtr &context) |
2465 | +{ |
2466 | + if (!mInterface->mPriv->initiateCB.isValid()) { |
2467 | + context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); |
2468 | + return; |
2469 | + } |
2470 | + Tp::DBusError error; |
2471 | + mInterface->mPriv->initiateCB(command, &error); |
2472 | + if (error.isValid()) { |
2473 | + context->setFinishedWithError(error.name(), error.message()); |
2474 | + return; |
2475 | + } |
2476 | + context->setFinished(); |
2477 | +} |
2478 | + |
2479 | +void BaseConnectionUSSDInterface::Adaptee::respond(const QString &reply, const ConnectionInterfaceUSSDAdaptor::RespondContextPtr &context) |
2480 | +{ |
2481 | + if (!mInterface->mPriv->respondCB.isValid()) { |
2482 | + context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); |
2483 | + return; |
2484 | + } |
2485 | + Tp::DBusError error; |
2486 | + mInterface->mPriv->respondCB(reply, &error); |
2487 | + if (error.isValid()) { |
2488 | + context->setFinishedWithError(error.name(), error.message()); |
2489 | + return; |
2490 | + } |
2491 | + context->setFinished(); |
2492 | +} |
2493 | + |
2494 | +void BaseConnectionUSSDInterface::Adaptee::cancel(const ConnectionInterfaceUSSDAdaptor::CancelContextPtr &context) |
2495 | +{ |
2496 | + if (!mInterface->mPriv->cancelCB.isValid()) { |
2497 | + context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); |
2498 | + return; |
2499 | + } |
2500 | + Tp::DBusError error; |
2501 | + mInterface->mPriv->cancelCB(&error); |
2502 | + if (error.isValid()) { |
2503 | + context->setFinishedWithError(error.name(), error.message()); |
2504 | + return; |
2505 | + } |
2506 | + context->setFinished(); |
2507 | +} |
2508 | + |
2509 | +BaseConnectionUSSDInterface::BaseConnectionUSSDInterface() |
2510 | + : AbstractConnectionInterface(TP_QT_IFACE_CONNECTION_USSD), |
2511 | + mPriv(new Private(this)) |
2512 | +{ |
2513 | +} |
2514 | + |
2515 | +BaseConnectionUSSDInterface::~BaseConnectionUSSDInterface() |
2516 | +{ |
2517 | + delete mPriv; |
2518 | +} |
2519 | + |
2520 | +void BaseConnectionUSSDInterface::setInitiateCallback(const InitiateCallback &cb) |
2521 | +{ |
2522 | + mPriv->initiateCB = cb; |
2523 | +} |
2524 | + |
2525 | +void BaseConnectionUSSDInterface::setRespondCallback(const RespondCallback &cb) |
2526 | +{ |
2527 | + mPriv->respondCB = cb; |
2528 | +} |
2529 | + |
2530 | +void BaseConnectionUSSDInterface::setCancelCallback(const CancelCallback &cb) |
2531 | +{ |
2532 | + mPriv->cancelCB = cb; |
2533 | +} |
2534 | + |
2535 | +QString BaseConnectionUSSDInterface::state() const |
2536 | +{ |
2537 | + return mPriv->state; |
2538 | +} |
2539 | + |
2540 | +void BaseConnectionUSSDInterface::setSerial(const QString &serial) const |
2541 | +{ |
2542 | + mPriv->serial = serial; |
2543 | +} |
2544 | + |
2545 | + |
2546 | +QString BaseConnectionUSSDInterface::serial() const |
2547 | +{ |
2548 | + return mPriv->serial; |
2549 | +} |
2550 | + |
2551 | +void BaseConnectionUSSDInterface::StateChanged(const QString &state) |
2552 | +{ |
2553 | + mPriv->state = state; |
2554 | + Q_EMIT mPriv->adaptee->stateChanged(state); |
2555 | +} |
2556 | + |
2557 | +void BaseConnectionUSSDInterface::InitiateUSSDComplete(const QString &ussdResp) |
2558 | +{ |
2559 | + Q_EMIT mPriv->adaptee->initiateUSSDComplete(ussdResp); |
2560 | +} |
2561 | + |
2562 | +void BaseConnectionUSSDInterface::RespondComplete(bool success, const QString &ussdResp) |
2563 | +{ |
2564 | + Q_EMIT mPriv->adaptee->respondComplete(success, ussdResp); |
2565 | +} |
2566 | + |
2567 | +void BaseConnectionUSSDInterface::BarringComplete(const QString &ssOp, const QString &cbService, const QVariantMap &cbMap) |
2568 | +{ |
2569 | + Q_EMIT mPriv->adaptee->barringComplete(ssOp, cbService, cbMap); |
2570 | +} |
2571 | + |
2572 | +void BaseConnectionUSSDInterface::ForwardingComplete(const QString &ssOp, const QString &cfService, const QVariantMap &cfMap) |
2573 | +{ |
2574 | + Q_EMIT mPriv->adaptee->forwardingComplete(ssOp, cfService, cfMap); |
2575 | +} |
2576 | + |
2577 | +void BaseConnectionUSSDInterface::WaitingComplete(const QString &ssOp, const QVariantMap &cwMap) |
2578 | +{ |
2579 | + Q_EMIT mPriv->adaptee->waitingComplete(ssOp, cwMap); |
2580 | +} |
2581 | + |
2582 | +void BaseConnectionUSSDInterface::CallingLinePresentationComplete(const QString &ssOp, const QString &status) |
2583 | +{ |
2584 | + Q_EMIT mPriv->adaptee->callingLinePresentationComplete(ssOp, status); |
2585 | +} |
2586 | + |
2587 | +void BaseConnectionUSSDInterface::ConnectedLinePresentationComplete(const QString &ssOp, const QString &status) |
2588 | +{ |
2589 | + Q_EMIT mPriv->adaptee->connectedLinePresentationComplete(ssOp, status); |
2590 | +} |
2591 | + |
2592 | +void BaseConnectionUSSDInterface::CallingLineRestrictionComplete(const QString &ssOp, const QString &status) |
2593 | +{ |
2594 | + Q_EMIT mPriv->adaptee->callingLineRestrictionComplete(ssOp, status); |
2595 | +} |
2596 | + |
2597 | +void BaseConnectionUSSDInterface::ConnectedLineRestrictionComplete(const QString &ssOp, const QString &status) |
2598 | +{ |
2599 | + Q_EMIT mPriv->adaptee->connectedLineRestrictionComplete(ssOp, status); |
2600 | +} |
2601 | + |
2602 | +void BaseConnectionUSSDInterface::InitiateFailed() |
2603 | +{ |
2604 | + Q_EMIT mPriv->adaptee->initiateFailed(); |
2605 | +} |
2606 | + |
2607 | +void BaseConnectionUSSDInterface::NotificationReceived(const QString &message) |
2608 | +{ |
2609 | + Q_EMIT mPriv->adaptee->notificationReceived(message); |
2610 | +} |
2611 | + |
2612 | +void BaseConnectionUSSDInterface::RequestReceived(const QString &message) |
2613 | +{ |
2614 | + Q_EMIT mPriv->adaptee->requestReceived(message); |
2615 | +} |
2616 | + |
2617 | + |
2618 | +QVariantMap BaseConnectionUSSDInterface::immutableProperties() const |
2619 | +{ |
2620 | + QVariantMap map; |
2621 | + return map; |
2622 | +} |
2623 | + |
2624 | +void BaseConnectionUSSDInterface::createAdaptor() |
2625 | +{ |
2626 | + (void) new ConnectionInterfaceUSSDAdaptor(dbusObject()->dbusConnection(), |
2627 | + mPriv->adaptee, dbusObject()); |
2628 | +} |
2629 | + |
2630 | + |
2631 | +ConnectionInterfaceUSSDAdaptor::ConnectionInterfaceUSSDAdaptor(const QDBusConnection& bus, QObject* adaptee, QObject* parent) |
2632 | + : Tp::AbstractAdaptor(bus, adaptee, parent) |
2633 | +{ |
2634 | + connect(adaptee, SIGNAL(notificationReceived(const QString &)), SIGNAL(NotificationReceived(const QString &))); |
2635 | + connect(adaptee, SIGNAL(requestReceived(const QString &)), SIGNAL(RequestReceived(const QString &))); |
2636 | + |
2637 | + connect(adaptee, SIGNAL(initiateUSSDComplete(const QString &)), SIGNAL(InitiateUSSDComplete(const QString &))); |
2638 | + |
2639 | + connect(adaptee, SIGNAL(barringComplete(const QString &, const QString &, const QVariantMap &)), |
2640 | + SIGNAL(BarringComplete(const QString &, const QString &, const QVariantMap &))); |
2641 | + |
2642 | + connect(adaptee, SIGNAL(forwardingComplete(const QString &, const QString &, const QVariantMap &)), |
2643 | + SIGNAL(ForwardingComplete(const QString &, const QString &, const QVariantMap &))); |
2644 | + |
2645 | + connect(adaptee, SIGNAL(waitingComplete(const QString &, const QVariantMap &)), |
2646 | + SIGNAL(WaitingComplete(const QString &, const QVariantMap &))); |
2647 | + |
2648 | + connect(adaptee, SIGNAL(callingLinePresentationComplete(const QString &, const QString &)), |
2649 | + SIGNAL(CallingLinePresentationComplete(const QString &, const QString &))); |
2650 | + |
2651 | + connect(adaptee, SIGNAL(connectedLinePresentationComplete(const QString &, const QString &)), |
2652 | + SIGNAL(ConnectedLinePresentationComplete(const QString &, const QString &))); |
2653 | + |
2654 | + connect(adaptee, SIGNAL(callingLineRestrictionComplete(const QString &, const QString &)), |
2655 | + SIGNAL(CallingLineRestrictionComplete(const QString &, const QString &))); |
2656 | + |
2657 | + connect(adaptee, SIGNAL(connectedLineRestrictionComplete(const QString &, const QString &)), |
2658 | + SIGNAL(ConnectedLineRestrictionComplete(const QString &, const QString &))); |
2659 | + |
2660 | + connect(adaptee, SIGNAL(initiateFailed()), SIGNAL(InitiateFailed())); |
2661 | + |
2662 | + connect(adaptee, SIGNAL(stateChanged(const QString&)), SIGNAL(StateChanged(const QString&))); |
2663 | + |
2664 | + connect(adaptee, SIGNAL(respondComplete(bool, const QString &)), SIGNAL(RespondComplete(bool, const QString &))); |
2665 | +} |
2666 | + |
2667 | +ConnectionInterfaceUSSDAdaptor::~ConnectionInterfaceUSSDAdaptor() |
2668 | +{ |
2669 | +} |
2670 | + |
2671 | +void ConnectionInterfaceUSSDAdaptor::Initiate(const QString &command, const QDBusMessage& dbusMessage) |
2672 | +{ |
2673 | + if (!adaptee()->metaObject()->indexOfMethod("initiate(const QString &,ConnectionInterfaceUSSDAdaptor::InitiateContextPtr)") == -1) { |
2674 | + dbusConnection().send(dbusMessage.createErrorReply(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"))); |
2675 | + return; |
2676 | + } |
2677 | + |
2678 | + InitiateContextPtr ctx = InitiateContextPtr( |
2679 | + new Tp::MethodInvocationContext< >(dbusConnection(), dbusMessage)); |
2680 | + QMetaObject::invokeMethod(adaptee(), "initiate", |
2681 | + Q_ARG(QString, command), |
2682 | + Q_ARG(ConnectionInterfaceUSSDAdaptor::InitiateContextPtr, ctx)); |
2683 | + return; |
2684 | +} |
2685 | + |
2686 | +void ConnectionInterfaceUSSDAdaptor::Respond(const QString &reply, const QDBusMessage& dbusMessage) |
2687 | +{ |
2688 | + if (!adaptee()->metaObject()->indexOfMethod("respond(QConnectionInterfaceUSSDAdaptor::RespondContextPtr)") == -1) { |
2689 | + dbusConnection().send(dbusMessage.createErrorReply(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"))); |
2690 | + return; |
2691 | + } |
2692 | + |
2693 | + RespondContextPtr ctx = RespondContextPtr( |
2694 | + new Tp::MethodInvocationContext< >(dbusConnection(), dbusMessage)); |
2695 | + QMetaObject::invokeMethod(adaptee(), "respond", |
2696 | + Q_ARG(QString, reply), |
2697 | + Q_ARG(ConnectionInterfaceUSSDAdaptor::RespondContextPtr, ctx)); |
2698 | + return; |
2699 | +} |
2700 | + |
2701 | +void ConnectionInterfaceUSSDAdaptor::Cancel(const QDBusMessage& dbusMessage) |
2702 | +{ |
2703 | + if (!adaptee()->metaObject()->indexOfMethod("cancel(ConnectionInterfaceUSSDAdaptor::CancelContextPtr)") == -1) { |
2704 | + dbusConnection().send(dbusMessage.createErrorReply(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"))); |
2705 | + return; |
2706 | + } |
2707 | + |
2708 | + CancelContextPtr ctx = CancelContextPtr( |
2709 | + new Tp::MethodInvocationContext< >(dbusConnection(), dbusMessage)); |
2710 | + QMetaObject::invokeMethod(adaptee(), "cancel", |
2711 | + Q_ARG(ConnectionInterfaceUSSDAdaptor::CancelContextPtr, ctx)); |
2712 | + return; |
2713 | +} |
2714 | + |
2715 | +QString ConnectionInterfaceUSSDAdaptor::Serial() const |
2716 | +{ |
2717 | + return qvariant_cast< QString >(adaptee()->property("serial")); |
2718 | +} |
2719 | + |
2720 | + |
2721 | +QString ConnectionInterfaceUSSDAdaptor::State() const |
2722 | +{ |
2723 | + return qvariant_cast< QString >(adaptee()->property("state")); |
2724 | +} |
2725 | + |
2726 | |
2727 | === added file 'tests/common/mock/ussdiface.h' |
2728 | --- tests/common/mock/ussdiface.h 1970-01-01 00:00:00 +0000 |
2729 | +++ tests/common/mock/ussdiface.h 2015-03-30 20:55:55 +0000 |
2730 | @@ -0,0 +1,244 @@ |
2731 | +/** |
2732 | + * Copyright (C) 2013-2015 Canonical, Ltd. |
2733 | + * |
2734 | + * This program is free software: you can redistribute it and/or modify it under |
2735 | + * the terms of the GNU General Public License version 3, as published by |
2736 | + * the Free Software Foundation. |
2737 | + * |
2738 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
2739 | + * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, |
2740 | + * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
2741 | + * General Public License for more details. |
2742 | + * |
2743 | + * You should have received a copy of the GNU General Public License |
2744 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2745 | + * |
2746 | + * Authors: Tiago Salem Herrmann <tiago.herrmann@canonical.com> |
2747 | + Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> |
2748 | + */ |
2749 | + |
2750 | +#ifndef OFONOUSSDIFACE_H |
2751 | +#define OFONOUSSDIFACE_H |
2752 | + |
2753 | +// telepathy-qt |
2754 | +#include <TelepathyQt/Constants> |
2755 | +#include <TelepathyQt/BaseConnection> |
2756 | +#include <TelepathyQt/AbstractAdaptor> |
2757 | +#include <TelepathyQt/DBusError> |
2758 | +#include <TelepathyQt/Callbacks> |
2759 | + |
2760 | +class BaseConnectionUSSDInterface; |
2761 | + |
2762 | +typedef Tp::SharedPtr<BaseConnectionUSSDInterface> BaseConnectionUSSDInterfacePtr; |
2763 | + |
2764 | +#define TP_QT_IFACE_CONNECTION_USSD "com.canonical.Telephony.USSD" |
2765 | + |
2766 | +class TP_QT_EXPORT BaseConnectionUSSDInterface : public Tp::AbstractConnectionInterface |
2767 | +{ |
2768 | + Q_OBJECT |
2769 | + Q_DISABLE_COPY(BaseConnectionUSSDInterface) |
2770 | + |
2771 | +public: |
2772 | + static BaseConnectionUSSDInterfacePtr create() { |
2773 | + return BaseConnectionUSSDInterfacePtr(new BaseConnectionUSSDInterface()); |
2774 | + } |
2775 | + template<typename BaseConnectionUSSDInterfaceSubclass> |
2776 | + static Tp::SharedPtr<BaseConnectionUSSDInterfaceSubclass> create() { |
2777 | + return Tp::SharedPtr<BaseConnectionUSSDInterfaceSubclass>( |
2778 | + new BaseConnectionUSSDInterfaceSubclass()); |
2779 | + } |
2780 | + QVariantMap immutableProperties() const; |
2781 | + virtual ~BaseConnectionUSSDInterface(); |
2782 | + |
2783 | + typedef Tp::Callback2<void, const QString&, Tp::DBusError*> InitiateCallback; |
2784 | + void setInitiateCallback(const InitiateCallback &cb); |
2785 | + |
2786 | + typedef Tp::Callback2<void, const QString&, Tp::DBusError*> RespondCallback; |
2787 | + void setRespondCallback(const RespondCallback &cb); |
2788 | + |
2789 | + typedef Tp::Callback1<void, Tp::DBusError*> CancelCallback; |
2790 | + void setCancelCallback(const CancelCallback &cb); |
2791 | + |
2792 | + |
2793 | + QString state() const; |
2794 | + QString serial() const; |
2795 | + |
2796 | +public Q_SLOTS: |
2797 | + void NotificationReceived(const QString &message); |
2798 | + void RequestReceived(const QString &message); |
2799 | + |
2800 | + void InitiateUSSDComplete(const QString &ussdResp); |
2801 | + void RespondComplete(bool success, const QString &ussdResp); |
2802 | + void BarringComplete(const QString &ssOp, const QString &cbService, const QVariantMap &cbMap); |
2803 | + void ForwardingComplete(const QString &ssOp, const QString &cfService, const QVariantMap &cfMap); |
2804 | + void WaitingComplete(const QString &ssOp, const QVariantMap &cwMap); |
2805 | + void CallingLinePresentationComplete(const QString &ssOp, const QString &status); |
2806 | + void ConnectedLinePresentationComplete(const QString &ssOp, const QString &status); |
2807 | + void CallingLineRestrictionComplete(const QString &ssOp, const QString &status); |
2808 | + void ConnectedLineRestrictionComplete(const QString &ssOp, const QString &status); |
2809 | + void InitiateFailed(); |
2810 | + void StateChanged(const QString &state); |
2811 | + |
2812 | + void setSerial(const QString& serial) const; |
2813 | +protected: |
2814 | + BaseConnectionUSSDInterface(); |
2815 | + |
2816 | +private: |
2817 | + void createAdaptor(); |
2818 | + |
2819 | + class Adaptee; |
2820 | + friend class Adaptee; |
2821 | + struct Private; |
2822 | + friend struct Private; |
2823 | + Private *mPriv; |
2824 | +}; |
2825 | + |
2826 | + |
2827 | +class TP_QT_EXPORT ConnectionInterfaceUSSDAdaptor : public Tp::AbstractAdaptor |
2828 | +{ |
2829 | + Q_OBJECT |
2830 | + Q_CLASSINFO("D-Bus Interface", TP_QT_IFACE_CONNECTION_USSD) |
2831 | + Q_CLASSINFO("D-Bus Introspection", "" |
2832 | +" <interface name=\"com.canonical.Telephony.USSD\">\n" |
2833 | +" <property access=\"read\" type=\"s\" name=\"State\"/>\n" |
2834 | +" <property access=\"read\" type=\"s\" name=\"Serial\"/>\n" |
2835 | +" <method name=\"Initiate\">\n" |
2836 | +" <arg direction=\"in\" type=\"s\" name=\"command\"/>\n" |
2837 | +" </method>\n" |
2838 | +" <method name=\"Respond\">\n" |
2839 | +" <arg direction=\"in\" type=\"s\" name=\"reply\"/>\n" |
2840 | +" </method>\n" |
2841 | +" <method name=\"Cancel\" />\n" |
2842 | +" <signal name=\"NotificationReceived\">\n" |
2843 | +" <arg type=\"s\" name=\"message\"/>\n" |
2844 | +" </signal>\n" |
2845 | +" <signal name=\"RequestReceived\">\n" |
2846 | +" <arg type=\"s\" name=\"message\"/>\n" |
2847 | +" </signal>\n" |
2848 | +" <signal name=\"InitiateUSSDComplete\">\n" |
2849 | +" <arg type=\"s\" name=\"response\"/>\n" |
2850 | +" </signal>\n" |
2851 | +" <signal name=\"RespondComplete\">\n" |
2852 | +" <arg type=\"b\" name=\"success\"/>\n" |
2853 | +" <arg type=\"s\" name=\"response\"/>\n" |
2854 | +" </signal>\n" |
2855 | +" <signal name=\"BarringComplete\">\n" |
2856 | +" <arg type=\"s\" name=\"ssOp\"/>\n" |
2857 | +" <arg type=\"s\" name=\"cbService\"/>\n" |
2858 | +" <arg type=\"a{sv}\" name=\"cbMap\"/>\n" |
2859 | +" </signal>\n" |
2860 | +" <signal name=\"ForwardingComplete\">\n" |
2861 | +" <arg type=\"s\" name=\"ssOp\"/>\n" |
2862 | +" <arg type=\"s\" name=\"cfService\"/>\n" |
2863 | +" <arg type=\"a{sv}\" name=\"cfMap\"/>\n" |
2864 | +" </signal>\n" |
2865 | +" <signal name=\"WaitingComplete\">\n" |
2866 | +" <arg type=\"s\" name=\"ssOp\"/>\n" |
2867 | +" <arg type=\"a{sv}\" name=\"cwMap\"/>\n" |
2868 | +" </signal>\n" |
2869 | +" <signal name=\"CallingLinePresentationComplete\">\n" |
2870 | +" <arg type=\"s\" name=\"ssOp\"/>\n" |
2871 | +" <arg type=\"s\" name=\"status\"/>\n" |
2872 | +" </signal>\n" |
2873 | +" <signal name=\"ConnectedLinePresentationComplete\">\n" |
2874 | +" <arg type=\"s\" name=\"ssOp\"/>\n" |
2875 | +" <arg type=\"s\" name=\"status\"/>\n" |
2876 | +" </signal>\n" |
2877 | +" <signal name=\"CallingLineRestrictionComplete\">\n" |
2878 | +" <arg type=\"s\" name=\"ssOp\"/>\n" |
2879 | +" <arg type=\"s\" name=\"status\"/>\n" |
2880 | +" </signal>\n" |
2881 | +" <signal name=\"ConnectedLineRestrictionComplete\">\n" |
2882 | +" <arg type=\"s\" name=\"ssOp\"/>\n" |
2883 | +" <arg type=\"s\" name=\"status\"/>\n" |
2884 | +" </signal>\n" |
2885 | +" <signal name=\"InitiateFailed\" />\n" |
2886 | +" <signal name=\"StateChanged\">\n" |
2887 | +" <arg type=\"s\" name=\"state\"/>\n" |
2888 | +" </signal>\n" |
2889 | +" </interface>\n" |
2890 | +"") |
2891 | + Q_PROPERTY(QString State READ State) |
2892 | + Q_PROPERTY(QString Serial READ Serial) |
2893 | + |
2894 | +public: |
2895 | + ConnectionInterfaceUSSDAdaptor(const QDBusConnection& dbusConnection, QObject* adaptee, QObject* parent); |
2896 | + virtual ~ConnectionInterfaceUSSDAdaptor(); |
2897 | + |
2898 | + typedef Tp::MethodInvocationContextPtr< > InitiateContextPtr; |
2899 | + typedef Tp::MethodInvocationContextPtr< > RespondContextPtr; |
2900 | + typedef Tp::MethodInvocationContextPtr< > CancelContextPtr; |
2901 | + |
2902 | +public Q_SLOTS: // METHODS |
2903 | + void Initiate(const QString &command, const QDBusMessage& dbusMessage); |
2904 | + void Respond(const QString &reply, const QDBusMessage& dbusMessage); |
2905 | + void Cancel(const QDBusMessage& dbusMessage); |
2906 | + |
2907 | + QString State() const; |
2908 | + QString Serial() const; |
2909 | + |
2910 | +Q_SIGNALS: // SIGNALS |
2911 | + void NotificationReceived(const QString &message); |
2912 | + void RequestReceived(const QString &message); |
2913 | + |
2914 | + void InitiateUSSDComplete(const QString &ussdResp); |
2915 | + void RespondComplete(bool success, const QString &ussdResp); |
2916 | + void BarringComplete(const QString &ssOp, const QString &cbService, const QVariantMap &cbMap); |
2917 | + void ForwardingComplete(const QString &ssOp, const QString &cfService, const QVariantMap &cfMap); |
2918 | + void WaitingComplete(const QString &ssOp, const QVariantMap &cwMap); |
2919 | + void CallingLinePresentationComplete(const QString &ssOp, const QString &status); |
2920 | + void ConnectedLinePresentationComplete(const QString &ssOp, const QString &status); |
2921 | + void CallingLineRestrictionComplete(const QString &ssOp, const QString &status); |
2922 | + void ConnectedLineRestrictionComplete(const QString &ssOp, const QString &status); |
2923 | + void InitiateFailed(); |
2924 | + |
2925 | + void StateChanged(const QString &state); |
2926 | +}; |
2927 | + |
2928 | + |
2929 | +class TP_QT_NO_EXPORT BaseConnectionUSSDInterface::Adaptee : public QObject |
2930 | +{ |
2931 | + Q_OBJECT |
2932 | + Q_PROPERTY(QString state READ state) |
2933 | + Q_PROPERTY(QString serial READ serial) |
2934 | + |
2935 | +public: |
2936 | + Adaptee(BaseConnectionUSSDInterface *interface); |
2937 | + ~Adaptee(); |
2938 | + QString state() const |
2939 | + { |
2940 | + return mInterface->state(); |
2941 | + } |
2942 | + QString serial() const |
2943 | + { |
2944 | + return mInterface->serial(); |
2945 | + } |
2946 | + |
2947 | + |
2948 | +private Q_SLOTS: |
2949 | + void initiate(const QString &command, const ConnectionInterfaceUSSDAdaptor::InitiateContextPtr &context); |
2950 | + void respond(const QString &reply, const ConnectionInterfaceUSSDAdaptor::RespondContextPtr &context); |
2951 | + void cancel(const ConnectionInterfaceUSSDAdaptor::CancelContextPtr &context); |
2952 | + |
2953 | +Q_SIGNALS: |
2954 | + void notificationReceived(const QString &message); |
2955 | + void requestReceived(const QString &message); |
2956 | + |
2957 | + void initiateUSSDComplete(const QString &ussdResp); |
2958 | + void barringComplete(const QString &ssOp, const QString &cbService, const QVariantMap &cbMap); |
2959 | + void forwardingComplete(const QString &ssOp, const QString &cfService, const QVariantMap &cfMap); |
2960 | + void waitingComplete(const QString &ssOp, const QVariantMap &cwMap); |
2961 | + void callingLinePresentationComplete(const QString &ssOp, const QString &status); |
2962 | + void connectedLinePresentationComplete(const QString &ssOp, const QString &status); |
2963 | + void callingLineRestrictionComplete(const QString &ssOp, const QString &status); |
2964 | + void connectedLineRestrictionComplete(const QString &ssOp, const QString &status); |
2965 | + void initiateFailed(); |
2966 | + void respondComplete(bool success, const QString &response); |
2967 | + |
2968 | + void stateChanged(const QString &state); |
2969 | + |
2970 | +public: |
2971 | + BaseConnectionUSSDInterface *mInterface; |
2972 | +}; |
2973 | + |
2974 | +#endif |
2975 | |
2976 | === added file 'tests/common/mock/voicemailiface.cpp' |
2977 | --- tests/common/mock/voicemailiface.cpp 1970-01-01 00:00:00 +0000 |
2978 | +++ tests/common/mock/voicemailiface.cpp 2015-03-30 20:55:55 +0000 |
2979 | @@ -0,0 +1,202 @@ |
2980 | +/** |
2981 | + * Copyright (C) 2013-2015 Canonical, Ltd. |
2982 | + * |
2983 | + * This program is free software: you can redistribute it and/or modify it under |
2984 | + * the terms of the GNU General Public License version 3, as published by |
2985 | + * the Free Software Foundation. |
2986 | + * |
2987 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
2988 | + * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, |
2989 | + * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
2990 | + * General Public License for more details. |
2991 | + * |
2992 | + * You should have received a copy of the GNU General Public License |
2993 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2994 | + * |
2995 | + * Authors: Tiago Salem Herrmann <tiago.herrmann@canonical.com> |
2996 | + Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> |
2997 | + */ |
2998 | + |
2999 | +#include <QDebug> |
3000 | + |
3001 | +#include <TelepathyQt/Constants> |
3002 | +#include <TelepathyQt/DBusObject> |
3003 | + |
3004 | +#include "voicemailiface.h" |
3005 | + |
3006 | +// Conn.I.Voicemail |
3007 | +BaseConnectionVoicemailInterface::Adaptee::Adaptee(BaseConnectionVoicemailInterface *interface) |
3008 | + : QObject(interface), |
3009 | + mInterface(interface) |
3010 | +{ |
3011 | +} |
3012 | + |
3013 | + |
3014 | +struct TP_QT_NO_EXPORT BaseConnectionVoicemailInterface::Private { |
3015 | + Private(BaseConnectionVoicemailInterface *parent) |
3016 | + : adaptee(new BaseConnectionVoicemailInterface::Adaptee(parent)) { |
3017 | + } |
3018 | + VoicemailCountCallback voicemailCountCB; |
3019 | + VoicemailNumberCallback voicemailNumberCB; |
3020 | + VoicemailIndicatorCallback voicemailIndicatorCB; |
3021 | + BaseConnectionVoicemailInterface::Adaptee *adaptee; |
3022 | +}; |
3023 | + |
3024 | +BaseConnectionVoicemailInterface::Adaptee::~Adaptee() |
3025 | +{ |
3026 | +} |
3027 | + |
3028 | +void BaseConnectionVoicemailInterface::Adaptee::voicemailIndicator(const ConnectionInterfaceVoicemailAdaptor::VoicemailIndicatorContextPtr &context) |
3029 | +{ |
3030 | + if (!mInterface->mPriv->voicemailIndicatorCB.isValid()) { |
3031 | + context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); |
3032 | + return; |
3033 | + } |
3034 | + Tp::DBusError error; |
3035 | + bool active = mInterface->mPriv->voicemailIndicatorCB(&error); |
3036 | + if (error.isValid()) { |
3037 | + context->setFinishedWithError(error.name(), error.message()); |
3038 | + return; |
3039 | + } |
3040 | + context->setFinished(active); |
3041 | +} |
3042 | + |
3043 | +void BaseConnectionVoicemailInterface::Adaptee::voicemailNumber(const ConnectionInterfaceVoicemailAdaptor::VoicemailNumberContextPtr &context) |
3044 | +{ |
3045 | + if (!mInterface->mPriv->voicemailNumberCB.isValid()) { |
3046 | + context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); |
3047 | + return; |
3048 | + } |
3049 | + Tp::DBusError error; |
3050 | + QString number = mInterface->mPriv->voicemailNumberCB(&error); |
3051 | + if (error.isValid()) { |
3052 | + context->setFinishedWithError(error.name(), error.message()); |
3053 | + return; |
3054 | + } |
3055 | + context->setFinished(number); |
3056 | +} |
3057 | + |
3058 | +void BaseConnectionVoicemailInterface::Adaptee::voicemailCount(const ConnectionInterfaceVoicemailAdaptor::VoicemailCountContextPtr &context) |
3059 | +{ |
3060 | + if (!mInterface->mPriv->voicemailCountCB.isValid()) { |
3061 | + context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); |
3062 | + return; |
3063 | + } |
3064 | + Tp::DBusError error; |
3065 | + uint count = mInterface->mPriv->voicemailCountCB(&error); |
3066 | + if (error.isValid()) { |
3067 | + context->setFinishedWithError(error.name(), error.message()); |
3068 | + return; |
3069 | + } |
3070 | + context->setFinished(count); |
3071 | +} |
3072 | + |
3073 | + |
3074 | +BaseConnectionVoicemailInterface::BaseConnectionVoicemailInterface() |
3075 | + : AbstractConnectionInterface(TP_QT_IFACE_CONNECTION_VOICEMAIL), |
3076 | + mPriv(new Private(this)) |
3077 | +{ |
3078 | +} |
3079 | + |
3080 | +BaseConnectionVoicemailInterface::~BaseConnectionVoicemailInterface() |
3081 | +{ |
3082 | + delete mPriv; |
3083 | +} |
3084 | + |
3085 | +void BaseConnectionVoicemailInterface::setVoicemailIndicatorCallback(const VoicemailIndicatorCallback &cb) |
3086 | +{ |
3087 | + mPriv->voicemailIndicatorCB = cb; |
3088 | +} |
3089 | + |
3090 | +void BaseConnectionVoicemailInterface::setVoicemailNumberCallback(const VoicemailNumberCallback &cb) |
3091 | +{ |
3092 | + mPriv->voicemailNumberCB = cb; |
3093 | +} |
3094 | + |
3095 | +void BaseConnectionVoicemailInterface::setVoicemailCountCallback(const VoicemailCountCallback &cb) |
3096 | +{ |
3097 | + mPriv->voicemailCountCB = cb; |
3098 | +} |
3099 | + |
3100 | +void BaseConnectionVoicemailInterface::setVoicemailCount(int count) |
3101 | +{ |
3102 | + Q_EMIT mPriv->adaptee->voicemailCountChanged(uint(count)); |
3103 | +} |
3104 | + |
3105 | +void BaseConnectionVoicemailInterface::setVoicemailNumber(const QString &voicemailNumber) |
3106 | +{ |
3107 | + Q_EMIT mPriv->adaptee->voicemailNumberChanged(voicemailNumber); |
3108 | +} |
3109 | + |
3110 | +void BaseConnectionVoicemailInterface::setVoicemailIndicator(bool active) |
3111 | +{ |
3112 | + Q_EMIT mPriv->adaptee->voicemailIndicatorChanged(active); |
3113 | +} |
3114 | + |
3115 | +QVariantMap BaseConnectionVoicemailInterface::immutableProperties() const |
3116 | +{ |
3117 | + QVariantMap map; |
3118 | + return map; |
3119 | +} |
3120 | + |
3121 | +void BaseConnectionVoicemailInterface::createAdaptor() |
3122 | +{ |
3123 | + (void) new ConnectionInterfaceVoicemailAdaptor(dbusObject()->dbusConnection(), |
3124 | + mPriv->adaptee, dbusObject()); |
3125 | +} |
3126 | + |
3127 | + |
3128 | +ConnectionInterfaceVoicemailAdaptor::ConnectionInterfaceVoicemailAdaptor(const QDBusConnection& bus, QObject* adaptee, QObject* parent) |
3129 | + : Tp::AbstractAdaptor(bus, adaptee, parent) |
3130 | +{ |
3131 | + connect(adaptee, SIGNAL(voicemailCountChanged(uint)), SIGNAL(VoicemailCountChanged(uint))); |
3132 | + connect(adaptee, SIGNAL(voicemailIndicatorChanged(bool)), SIGNAL(VoicemailIndicatorChanged(bool))); |
3133 | + connect(adaptee, SIGNAL(voicemailNumberChanged(QString)), SIGNAL(VoicemailNumberChanged(QString))); |
3134 | +} |
3135 | + |
3136 | +ConnectionInterfaceVoicemailAdaptor::~ConnectionInterfaceVoicemailAdaptor() |
3137 | +{ |
3138 | +} |
3139 | + |
3140 | +bool ConnectionInterfaceVoicemailAdaptor::VoicemailIndicator(const QDBusMessage& dbusMessage) |
3141 | +{ |
3142 | + if (!adaptee()->metaObject()->indexOfMethod("voicemailIndicator(ConnectionInterfaceVoicemailAdaptor::VoicemailIndicatorContextPtr)") == -1) { |
3143 | + dbusConnection().send(dbusMessage.createErrorReply(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"))); |
3144 | + return bool(); |
3145 | + } |
3146 | + |
3147 | + VoicemailIndicatorContextPtr ctx = VoicemailIndicatorContextPtr( |
3148 | + new Tp::MethodInvocationContext< bool >(dbusConnection(), dbusMessage)); |
3149 | + QMetaObject::invokeMethod(adaptee(), "voicemailIndicator", |
3150 | + Q_ARG(ConnectionInterfaceVoicemailAdaptor::VoicemailIndicatorContextPtr, ctx)); |
3151 | + return bool(); |
3152 | +} |
3153 | + |
3154 | +QString ConnectionInterfaceVoicemailAdaptor::VoicemailNumber(const QDBusMessage& dbusMessage) |
3155 | +{ |
3156 | + if (!adaptee()->metaObject()->indexOfMethod("voicemailNumber(ConnectionInterfaceVoicemailAdaptor::VoicemailNumberContextPtr)") == -1) { |
3157 | + dbusConnection().send(dbusMessage.createErrorReply(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"))); |
3158 | + return QString(); |
3159 | + } |
3160 | + |
3161 | + VoicemailNumberContextPtr ctx = VoicemailNumberContextPtr( |
3162 | + new Tp::MethodInvocationContext< QString >(dbusConnection(), dbusMessage)); |
3163 | + QMetaObject::invokeMethod(adaptee(), "voicemailNumber", |
3164 | + Q_ARG(ConnectionInterfaceVoicemailAdaptor::VoicemailNumberContextPtr, ctx)); |
3165 | + return QString(); |
3166 | +} |
3167 | + |
3168 | +uint ConnectionInterfaceVoicemailAdaptor::VoicemailCount(const QDBusMessage& dbusMessage) |
3169 | +{ |
3170 | + if (!adaptee()->metaObject()->indexOfMethod("voicemailCount(ConnectionInterfaceVoicemailAdaptor::VoicemailCountContextPtr)") == -1) { |
3171 | + dbusConnection().send(dbusMessage.createErrorReply(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"))); |
3172 | + return uint(); |
3173 | + } |
3174 | + |
3175 | + VoicemailCountContextPtr ctx = VoicemailCountContextPtr( |
3176 | + new Tp::MethodInvocationContext< uint >(dbusConnection(), dbusMessage)); |
3177 | + QMetaObject::invokeMethod(adaptee(), "voicemailCount", |
3178 | + Q_ARG(ConnectionInterfaceVoicemailAdaptor::VoicemailCountContextPtr, ctx)); |
3179 | + return uint(); |
3180 | +} |
3181 | + |
3182 | |
3183 | === added file 'tests/common/mock/voicemailiface.h' |
3184 | --- tests/common/mock/voicemailiface.h 1970-01-01 00:00:00 +0000 |
3185 | +++ tests/common/mock/voicemailiface.h 2015-03-30 20:55:55 +0000 |
3186 | @@ -0,0 +1,150 @@ |
3187 | +/** |
3188 | + * Copyright (C) 2013-2015 Canonical, Ltd. |
3189 | + * |
3190 | + * This program is free software: you can redistribute it and/or modify it under |
3191 | + * the terms of the GNU General Public License version 3, as published by |
3192 | + * the Free Software Foundation. |
3193 | + * |
3194 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
3195 | + * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, |
3196 | + * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3197 | + * General Public License for more details. |
3198 | + * |
3199 | + * You should have received a copy of the GNU General Public License |
3200 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3201 | + * |
3202 | + * Authors: Tiago Salem Herrmann <tiago.herrmann@canonical.com> |
3203 | + Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> |
3204 | + */ |
3205 | + |
3206 | +#ifndef OFONOVOICEMAILIFACE_H |
3207 | +#define OFONOVOICEMAILIFACE_H |
3208 | + |
3209 | +// telepathy-qt |
3210 | +#include <TelepathyQt/Constants> |
3211 | +#include <TelepathyQt/BaseConnection> |
3212 | +#include <TelepathyQt/AbstractAdaptor> |
3213 | +#include <TelepathyQt/DBusError> |
3214 | +#include <TelepathyQt/Callbacks> |
3215 | + |
3216 | +class BaseConnectionVoicemailInterface; |
3217 | + |
3218 | +typedef Tp::SharedPtr<BaseConnectionVoicemailInterface> BaseConnectionVoicemailInterfacePtr; |
3219 | + |
3220 | +#define TP_QT_IFACE_CONNECTION_VOICEMAIL "com.canonical.Telephony.Voicemail" |
3221 | + |
3222 | +class TP_QT_EXPORT BaseConnectionVoicemailInterface : public Tp::AbstractConnectionInterface |
3223 | +{ |
3224 | + Q_OBJECT |
3225 | + Q_DISABLE_COPY(BaseConnectionVoicemailInterface) |
3226 | + |
3227 | +public: |
3228 | + static BaseConnectionVoicemailInterfacePtr create() { |
3229 | + return BaseConnectionVoicemailInterfacePtr(new BaseConnectionVoicemailInterface()); |
3230 | + } |
3231 | + template<typename BaseConnectionVoicemailInterfaceSubclass> |
3232 | + static Tp::SharedPtr<BaseConnectionVoicemailInterfaceSubclass> create() { |
3233 | + return Tp::SharedPtr<BaseConnectionVoicemailInterfaceSubclass>( |
3234 | + new BaseConnectionVoicemailInterfaceSubclass()); |
3235 | + } |
3236 | + QVariantMap immutableProperties() const; |
3237 | + virtual ~BaseConnectionVoicemailInterface(); |
3238 | + |
3239 | + typedef Tp::Callback1<uint, Tp::DBusError*> VoicemailCountCallback; |
3240 | + void setVoicemailCountCallback(const VoicemailCountCallback &cb); |
3241 | + |
3242 | + typedef Tp::Callback1<bool, Tp::DBusError*> VoicemailIndicatorCallback; |
3243 | + void setVoicemailIndicatorCallback(const VoicemailIndicatorCallback &cb); |
3244 | + |
3245 | + typedef Tp::Callback1<QString, Tp::DBusError*> VoicemailNumberCallback; |
3246 | + void setVoicemailNumberCallback(const VoicemailNumberCallback &cb); |
3247 | + |
3248 | +public Q_SLOTS: |
3249 | + void setVoicemailCount(int count); |
3250 | + void setVoicemailIndicator(bool active); |
3251 | + void setVoicemailNumber(const QString &voicemailNumber); |
3252 | + |
3253 | +protected: |
3254 | + BaseConnectionVoicemailInterface(); |
3255 | + |
3256 | +private: |
3257 | + void createAdaptor(); |
3258 | + |
3259 | + class Adaptee; |
3260 | + friend class Adaptee; |
3261 | + struct Private; |
3262 | + friend struct Private; |
3263 | + Private *mPriv; |
3264 | +}; |
3265 | + |
3266 | + |
3267 | +class TP_QT_EXPORT ConnectionInterfaceVoicemailAdaptor : public Tp::AbstractAdaptor |
3268 | +{ |
3269 | + Q_OBJECT |
3270 | + Q_CLASSINFO("D-Bus Interface", TP_QT_IFACE_CONNECTION_VOICEMAIL) |
3271 | + Q_CLASSINFO("D-Bus Introspection", "" |
3272 | +" <interface name=\"com.canonical.Telephony.Voicemail\">\n" |
3273 | +" <method name=\"VoicemailIndicator\">\n" |
3274 | +" <arg direction=\"out\" type=\"b\" name=\"voicemailIndicator\"/>\n" |
3275 | +" </method>\n" |
3276 | +" <method name=\"VoicemailNumber\">\n" |
3277 | +" <arg direction=\"out\" type=\"s\" name=\"voicemailNumber\"/>\n" |
3278 | +" </method>\n" |
3279 | +" <method name=\"VoicemailCount\">\n" |
3280 | +" <arg direction=\"out\" type=\"u\" name=\"voicemailCount\"/>\n" |
3281 | +" </method>\n" |
3282 | +" <signal name=\"VoicemailCountChanged\">\n" |
3283 | +" <arg type=\"u\" name=\"count\"/>\n" |
3284 | +" </signal>\n" |
3285 | +" <signal name=\"VoicemailIndicatorChanged\">\n" |
3286 | +" <arg type=\"b\" name=\"active\"/>\n" |
3287 | +" </signal>\n" |
3288 | +" <signal name=\"VoicemailNumberChanged\">\n" |
3289 | +" <arg type=\"s\" name=\"voicemailNumber\"/>\n" |
3290 | +" </signal>\n" |
3291 | +" </interface>\n" |
3292 | +"") |
3293 | + |
3294 | +public: |
3295 | + ConnectionInterfaceVoicemailAdaptor(const QDBusConnection& dbusConnection, QObject* adaptee, QObject* parent); |
3296 | + virtual ~ConnectionInterfaceVoicemailAdaptor(); |
3297 | + |
3298 | + typedef Tp::MethodInvocationContextPtr< bool > VoicemailIndicatorContextPtr; |
3299 | + typedef Tp::MethodInvocationContextPtr< QString > VoicemailNumberContextPtr; |
3300 | + typedef Tp::MethodInvocationContextPtr< uint > VoicemailCountContextPtr; |
3301 | + |
3302 | +public Q_SLOTS: // METHODS |
3303 | + bool VoicemailIndicator(const QDBusMessage& dbusMessage); |
3304 | + QString VoicemailNumber(const QDBusMessage& dbusMessage); |
3305 | + uint VoicemailCount(const QDBusMessage& dbusMessage); |
3306 | + |
3307 | +Q_SIGNALS: // SIGNALS |
3308 | + void VoicemailCountChanged(uint count); |
3309 | + void VoicemailIndicatorChanged(bool active); |
3310 | + void VoicemailNumberChanged(const QString &voicemailNumber); |
3311 | +}; |
3312 | + |
3313 | + |
3314 | +class TP_QT_NO_EXPORT BaseConnectionVoicemailInterface::Adaptee : public QObject |
3315 | +{ |
3316 | + Q_OBJECT |
3317 | + |
3318 | +public: |
3319 | + Adaptee(BaseConnectionVoicemailInterface *interface); |
3320 | + ~Adaptee(); |
3321 | + |
3322 | +private Q_SLOTS: |
3323 | + void voicemailIndicator(const ConnectionInterfaceVoicemailAdaptor::VoicemailIndicatorContextPtr &context); |
3324 | + void voicemailNumber(const ConnectionInterfaceVoicemailAdaptor::VoicemailNumberContextPtr &context); |
3325 | + void voicemailCount(const ConnectionInterfaceVoicemailAdaptor::VoicemailCountContextPtr &context); |
3326 | + |
3327 | +Q_SIGNALS: |
3328 | + void voicemailCountChanged(uint count); |
3329 | + void voicemailIndicatorChanged(bool active); |
3330 | + void voicemailNumberChanged(const QString &voicemailNumber); |
3331 | + |
3332 | +public: |
3333 | + BaseConnectionVoicemailInterface *mInterface; |
3334 | +}; |
3335 | + |
3336 | +#endif |
3337 | |
3338 | === renamed file 'handler/tests/mockcontroller.cpp' => 'tests/common/mockcontroller.cpp' |
3339 | --- handler/tests/mockcontroller.cpp 2014-03-20 21:03:26 +0000 |
3340 | +++ tests/common/mockcontroller.cpp 2015-03-30 20:55:55 +0000 |
3341 | @@ -21,27 +21,34 @@ |
3342 | #include "mockcontroller.h" |
3343 | #include <QDBusReply> |
3344 | |
3345 | -#define MOCK_SERVICE "com.canonical.MockConnection" |
3346 | -#define MOCK_OBJECT "/com/canonical/MockConnection" |
3347 | -#define MOCK_INTERFACE "com.canonical.MockConnection" |
3348 | - |
3349 | -MockController::MockController(QObject *parent) : |
3350 | - QObject(parent), |
3351 | - mMockInterface(MOCK_SERVICE, MOCK_OBJECT, MOCK_INTERFACE) |
3352 | -{ |
3353 | - QDBusConnection::sessionBus().connect(MOCK_SERVICE, MOCK_OBJECT, MOCK_INTERFACE, "MessageSent", this, SIGNAL(messageSent(QString, QVariantMap))); |
3354 | - QDBusConnection::sessionBus().connect(MOCK_SERVICE, MOCK_OBJECT, MOCK_INTERFACE, "CallReceived", this, SIGNAL(callReceived(QString))); |
3355 | - QDBusConnection::sessionBus().connect(MOCK_SERVICE, MOCK_OBJECT, MOCK_INTERFACE, "CallEnded", this, SIGNAL(callEnded(QString))); |
3356 | - QDBusConnection::sessionBus().connect(MOCK_SERVICE, MOCK_OBJECT, MOCK_INTERFACE, "CallStateChanged", this, SIGNAL(callStateChanged(QString,QString,QString))); |
3357 | - QDBusConnection::sessionBus().connect(MOCK_SERVICE, MOCK_OBJECT, MOCK_INTERFACE, "ConferenceCreated", this, SIGNAL(conferenceCreated(QString))); |
3358 | - QDBusConnection::sessionBus().connect(MOCK_SERVICE, MOCK_OBJECT, MOCK_INTERFACE, "ChannelMerged", this, SIGNAL(channelMerged(QString))); |
3359 | - QDBusConnection::sessionBus().connect(MOCK_SERVICE, MOCK_OBJECT, MOCK_INTERFACE, "ChannelSplitted", this, SIGNAL(channelSplitted(QString))); |
3360 | -} |
3361 | - |
3362 | -MockController *MockController::instance() |
3363 | -{ |
3364 | - static MockController *self = new MockController(); |
3365 | - return self; |
3366 | +static const QString mockService("com.canonical.MockConnection"); |
3367 | +static const QString mockObject("/com/canonical/MockConnection/%1"); |
3368 | +static const QString mockInterface("com.canonical.MockConnection"); |
3369 | + |
3370 | +MockController::MockController(const QString &protocol, QObject *parent) : |
3371 | + QObject(parent), mProtocol(protocol), mMockObject(mockObject.arg(protocol)), |
3372 | + mMockInterface(mockService, mockObject.arg(protocol), mockInterface) |
3373 | +{ |
3374 | + connect(&mMockInterface, SIGNAL(MessageRead(QString)), |
3375 | + this, SIGNAL(messageRead(QString))); |
3376 | + connect(&mMockInterface, SIGNAL(MessageSent(QString, QVariantMap)), |
3377 | + this, SIGNAL(messageSent(QString, QVariantMap))); |
3378 | + connect(&mMockInterface, SIGNAL(CallReceived(QString)), |
3379 | + this, SIGNAL(callReceived(QString))); |
3380 | + connect(&mMockInterface, SIGNAL(CallEnded(QString)), |
3381 | + this, SIGNAL(callEnded(QString))); |
3382 | + connect(&mMockInterface, SIGNAL(CallStateChanged(QString, QString, QString)), |
3383 | + this, SIGNAL(callStateChanged(QString,QString,QString))); |
3384 | + connect(&mMockInterface, SIGNAL(ConferenceCreated(QString)), |
3385 | + this, SIGNAL(conferenceCreated(QString))); |
3386 | + connect(&mMockInterface, SIGNAL(ChannelMerged(QString)), |
3387 | + this, SIGNAL(channelMerged(QString))); |
3388 | + connect(&mMockInterface, SIGNAL(ChannelSplitted(QString)), |
3389 | + this, SIGNAL(channelSplitted(QString))); |
3390 | + connect(&mMockInterface, SIGNAL(Disconnected()), |
3391 | + this, SIGNAL(disconnected())); |
3392 | + connect(&mMockInterface, SIGNAL(Destroyed()), |
3393 | + this, SIGNAL(connectionDestroyed())); |
3394 | } |
3395 | |
3396 | void MockController::placeIncomingMessage(const QString &message, const QVariantMap &properties) |
3397 | @@ -64,3 +71,43 @@ |
3398 | { |
3399 | mMockInterface.call("SetCallState", phoneNumber, state); |
3400 | } |
3401 | + |
3402 | +void MockController::setOnline(bool online) |
3403 | +{ |
3404 | + mMockInterface.call("SetOnline", online); |
3405 | +} |
3406 | + |
3407 | +void MockController::setPresence(const QString &status, const QString &statusMessage) |
3408 | +{ |
3409 | + mMockInterface.call("SetPresence", status, statusMessage); |
3410 | +} |
3411 | + |
3412 | +void MockController::setVoicemailNumber(const QString &number) |
3413 | +{ |
3414 | + mMockInterface.call("SetVoicemailNumber", number); |
3415 | +} |
3416 | + |
3417 | +void MockController::setVoicemailIndicator(bool active) |
3418 | +{ |
3419 | + mMockInterface.call("SetVoicemailIndicator", active); |
3420 | +} |
3421 | + |
3422 | +void MockController::setVoicemailCount(int count) |
3423 | +{ |
3424 | + mMockInterface.call("SetVoicemailCount", count); |
3425 | +} |
3426 | + |
3427 | +void MockController::setEmergencyNumbers(const QStringList &numbers) |
3428 | +{ |
3429 | + mMockInterface.call("SetEmergencyNumbers", numbers); |
3430 | +} |
3431 | + |
3432 | +QString MockController::serial() |
3433 | +{ |
3434 | + QDBusReply<QString> reply = mMockInterface.call("Serial"); |
3435 | + if (!reply.isValid()) { |
3436 | + return QString::null; |
3437 | + } |
3438 | + |
3439 | + return reply.value(); |
3440 | +} |
3441 | |
3442 | === renamed file 'handler/tests/mockcontroller.h' => 'tests/common/mockcontroller.h' |
3443 | --- handler/tests/mockcontroller.h 2014-03-20 21:03:26 +0000 |
3444 | +++ tests/common/mockcontroller.h 2015-03-30 20:55:55 +0000 |
3445 | @@ -28,9 +28,10 @@ |
3446 | { |
3447 | Q_OBJECT |
3448 | public: |
3449 | - static MockController *instance(); |
3450 | + explicit MockController(const QString &protocol, QObject *parent = 0); |
3451 | |
3452 | Q_SIGNALS: |
3453 | + void messageRead(const QString &messageId); |
3454 | void messageSent(const QString &message, const QVariantMap &properties); |
3455 | void callReceived(const QString &callerId); |
3456 | void callEnded(const QString &callerId); |
3457 | @@ -38,16 +39,32 @@ |
3458 | void conferenceCreated(const QString &objectPath); |
3459 | void channelMerged(const QString &objectPath); |
3460 | void channelSplitted(const QString &objectPath); |
3461 | + void disconnected(); |
3462 | + void connectionDestroyed(); |
3463 | |
3464 | public Q_SLOTS: |
3465 | void placeIncomingMessage(const QString &message, const QVariantMap &properties); |
3466 | QString placeCall(const QVariantMap &properties); |
3467 | void hangupCall(const QString &callerId); |
3468 | void setCallState(const QString &phoneNumber, const QString &state); |
3469 | + void setOnline(bool online); |
3470 | + void setPresence(const QString &status, const QString &statusMessage); |
3471 | + |
3472 | + // voicemail stuff |
3473 | + void setVoicemailNumber(const QString &number); |
3474 | + void setVoicemailIndicator(bool active); |
3475 | + void setVoicemailCount(int count); |
3476 | + |
3477 | + // emergency numbers stuff |
3478 | + void setEmergencyNumbers(const QStringList &numbers); |
3479 | + |
3480 | + // USSD stuff |
3481 | + QString serial(); |
3482 | |
3483 | private: |
3484 | - explicit MockController(QObject *parent = 0); |
3485 | QDBusInterface mMockInterface; |
3486 | + QString mProtocol; |
3487 | + QString mMockObject; |
3488 | }; |
3489 | |
3490 | #endif // MOCKCONTROLLER_H |
3491 | |
3492 | === added file 'tests/common/telepathytest.cpp' |
3493 | --- tests/common/telepathytest.cpp 1970-01-01 00:00:00 +0000 |
3494 | +++ tests/common/telepathytest.cpp 2015-03-30 20:55:55 +0000 |
3495 | @@ -0,0 +1,140 @@ |
3496 | +/* |
3497 | + * Copyright (C) 2015 Canonical, Ltd. |
3498 | + * |
3499 | + * This file is part of telephony-service. |
3500 | + * |
3501 | + * telephony-service is free software; you can redistribute it and/or modify |
3502 | + * it under the terms of the GNU General Public License as published by |
3503 | + * the Free Software Foundation; version 3. |
3504 | + * |
3505 | + * telephony-service is distributed in the hope that it will be useful, |
3506 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3507 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3508 | + * GNU General Public License for more details. |
3509 | + * |
3510 | + * You should have received a copy of the GNU General Public License |
3511 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3512 | + */ |
3513 | + |
3514 | +#include <QtCore/QObject> |
3515 | +#include <QtTest/QtTest> |
3516 | +#include <TelepathyQt/PendingAccount> |
3517 | +#include <TelepathyQt/PendingOperation> |
3518 | +#include <TelepathyQt/Account> |
3519 | +#include "telepathytest.h" |
3520 | +#include "telepathyhelper.h" |
3521 | +#include "accountentry.h" |
3522 | + |
3523 | +void TelepathyTest::initialize() |
3524 | +{ |
3525 | + Tp::registerTypes(); |
3526 | + |
3527 | + QSignalSpy spy(TelepathyHelper::instance(), SIGNAL(setupReady())); |
3528 | + QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, DEFAULT_TIMEOUT); |
3529 | + |
3530 | + // just in case, remove any existing account that might be a leftover from |
3531 | + // previous test runs |
3532 | + Q_FOREACH(const AccountEntry *account, TelepathyHelper::instance()->accounts()) { |
3533 | + QVERIFY(removeAccount(account->account())); |
3534 | + } |
3535 | + |
3536 | + // create an account manager instance to help testing |
3537 | + Tp::Features accountFeatures; |
3538 | + accountFeatures << Tp::Account::FeatureCore |
3539 | + << Tp::Account::FeatureProtocolInfo; |
3540 | + Tp::Features contactFeatures; |
3541 | + contactFeatures << Tp::Contact::FeatureAlias |
3542 | + << Tp::Contact::FeatureAvatarData |
3543 | + << Tp::Contact::FeatureAvatarToken |
3544 | + << Tp::Contact::FeatureCapabilities |
3545 | + << Tp::Contact::FeatureSimplePresence; |
3546 | + Tp::Features connectionFeatures; |
3547 | + connectionFeatures << Tp::Connection::FeatureCore |
3548 | + << Tp::Connection::FeatureSelfContact |
3549 | + << Tp::Connection::FeatureSimplePresence; |
3550 | + |
3551 | + Tp::ChannelFactoryPtr channelFactory = Tp::ChannelFactory::create(QDBusConnection::sessionBus()); |
3552 | + channelFactory->addCommonFeatures(Tp::Channel::FeatureCore); |
3553 | + |
3554 | + mAccountManager = Tp::AccountManager::create( |
3555 | + Tp::AccountFactory::create(QDBusConnection::sessionBus(), accountFeatures), |
3556 | + Tp::ConnectionFactory::create(QDBusConnection::sessionBus(), connectionFeatures), |
3557 | + channelFactory, |
3558 | + Tp::ContactFactory::create(contactFeatures)); |
3559 | + |
3560 | + mReady = false; |
3561 | + connect(mAccountManager->becomeReady(Tp::AccountManager::FeatureCore), |
3562 | + &Tp::PendingOperation::finished, [=]{ |
3563 | + mReady = true; |
3564 | + }); |
3565 | + |
3566 | + QTRY_VERIFY(mReady); |
3567 | + |
3568 | + // give some time for telepathy stuff to settle |
3569 | + QTest::qWait(1000); |
3570 | +} |
3571 | + |
3572 | +void TelepathyTest::doCleanup() |
3573 | +{ |
3574 | + // remove all accounts on every test to prevent garbage to go from one test to another |
3575 | + Q_FOREACH(const Tp::AccountPtr &account, mAccounts) { |
3576 | + QVERIFY(removeAccount(account)); |
3577 | + } |
3578 | + QVERIFY(mAccounts.isEmpty()); |
3579 | +} |
3580 | + |
3581 | + |
3582 | +Tp::AccountPtr TelepathyTest::addAccount(const QString &manager, const QString &protocol, const QString &displayName, const QVariantMap ¶meters) |
3583 | +{ |
3584 | + bool finished = false; |
3585 | + Tp::AccountPtr account; |
3586 | + connect(mAccountManager->createAccount(manager, protocol, displayName, parameters), &Tp::PendingOperation::finished, |
3587 | + [&](Tp::PendingOperation *op) { |
3588 | + Tp::PendingAccount *pa = qobject_cast<Tp::PendingAccount*>(op); |
3589 | + if (op->isError() || !pa) { |
3590 | + qCritical() << "Failed to create account:" << op->errorName() << op->errorMessage(); |
3591 | + finished = true; |
3592 | + return; |
3593 | + } |
3594 | + |
3595 | + account = pa->account(); |
3596 | + finished = true; |
3597 | + }); |
3598 | + |
3599 | + while (!finished) { |
3600 | + QTest::qWait(100); |
3601 | + } |
3602 | + mAccounts << account; |
3603 | + return account; |
3604 | +} |
3605 | + |
3606 | +bool TelepathyTest::removeAccount(const Tp::AccountPtr &account) |
3607 | +{ |
3608 | + bool success = false; |
3609 | + bool finished = false; |
3610 | + |
3611 | + connect(account->remove(), &Tp::PendingOperation::finished, |
3612 | + [&](Tp::PendingOperation *op) { |
3613 | + success = !op->isError(); |
3614 | + finished = true; |
3615 | + }); |
3616 | + |
3617 | + while (!finished) { |
3618 | + QTest::qWait(100); |
3619 | + } |
3620 | + if (success) { |
3621 | + mAccounts.removeAll(account); |
3622 | + } |
3623 | + return success; |
3624 | +} |
3625 | + |
3626 | + |
3627 | +QList<Tp::AccountPtr> TelepathyTest::accounts() const |
3628 | +{ |
3629 | + return mAccounts; |
3630 | +} |
3631 | + |
3632 | +void TelepathyTest::cleanup() |
3633 | +{ |
3634 | + doCleanup(); |
3635 | +} |
3636 | |
3637 | === added file 'tests/common/telepathytest.h' |
3638 | --- tests/common/telepathytest.h 1970-01-01 00:00:00 +0000 |
3639 | +++ tests/common/telepathytest.h 2015-03-30 20:55:55 +0000 |
3640 | @@ -0,0 +1,54 @@ |
3641 | +/* |
3642 | + * Copyright (C) 2015 Canonical, Ltd. |
3643 | + * |
3644 | + * This file is part of telephony-service. |
3645 | + * |
3646 | + * telephony-service is free software; you can redistribute it and/or modify |
3647 | + * it under the terms of the GNU General Public License as published by |
3648 | + * the Free Software Foundation; version 3. |
3649 | + * |
3650 | + * telephony-service is distributed in the hope that it will be useful, |
3651 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3652 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3653 | + * GNU General Public License for more details. |
3654 | + * |
3655 | + * You should have received a copy of the GNU General Public License |
3656 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3657 | + */ |
3658 | + |
3659 | +#ifndef TELEPATHYTEST_H |
3660 | +#define TELEPATHYTEST_H |
3661 | + |
3662 | +#include <QtCore/QObject> |
3663 | +#include <TelepathyQt/Account> |
3664 | +#include "telepathyhelper.h" |
3665 | + |
3666 | +#define DEFAULT_TIMEOUT 15000 |
3667 | + |
3668 | +class TelepathyTest : public QObject |
3669 | +{ |
3670 | + Q_OBJECT |
3671 | + |
3672 | +protected: |
3673 | + void initialize(); |
3674 | + void doCleanup(); |
3675 | + |
3676 | + // helper slots |
3677 | + void onAccountManagerReady(Tp::PendingOperation *op); |
3678 | + Tp::AccountPtr addAccount(const QString &manager, |
3679 | + const QString &protocol, |
3680 | + const QString &displayName, |
3681 | + const QVariantMap ¶meters = QVariantMap()); |
3682 | + bool removeAccount(const Tp::AccountPtr &account); |
3683 | + QList<Tp::AccountPtr> accounts() const; |
3684 | + |
3685 | +private Q_SLOTS: |
3686 | + void cleanup(); |
3687 | + |
3688 | +private: |
3689 | + Tp::AccountManagerPtr mAccountManager; |
3690 | + bool mReady; |
3691 | + QList<Tp::AccountPtr> mAccounts; |
3692 | +}; |
3693 | + |
3694 | +#endif //TELEPATHYTEST_H |
3695 | |
3696 | === renamed directory 'handler/tests' => 'tests/handler' |
3697 | === modified file 'tests/handler/CMakeLists.txt' |
3698 | --- handler/tests/CMakeLists.txt 2014-01-22 12:33:43 +0000 |
3699 | +++ tests/handler/CMakeLists.txt 2015-03-30 20:55:55 +0000 |
3700 | @@ -1,43 +1,9 @@ |
3701 | include_directories( |
3702 | ${CMAKE_CURRENT_BINARY_DIR} |
3703 | + ${CMAKE_CURRENT_SOURCE_DIR}/../common |
3704 | ${CMAKE_SOURCE_DIR} |
3705 | + ${CMAKE_SOURCE_DIR}/libtelephonyservice |
3706 | + ${TP_QT5_INCLUDE_DIRS} |
3707 | ) |
3708 | |
3709 | -macro(generate_test TESTNAME USE_DBUS) |
3710 | - add_executable(${TESTNAME} ${ARGN} ${TESTNAME}.cpp) |
3711 | - qt5_use_modules(${TESTNAME} Core DBus Test) |
3712 | - set(TEST_COMMAND ) |
3713 | - if (${USE_DBUS}) |
3714 | - set(TEST_COMMAND -p ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME} -p -xunitxml -p -o -p ${CMAKE_BINARY_DIR}/test_${TESTNAME}.xml) |
3715 | - add_test(${TESTNAME} ${DBUS_RUNNER} --keep-env |
3716 | - --task ${CMAKE_CURRENT_BINARY_DIR}/dbus-test-wrapper.sh ${TEST_COMMAND}) |
3717 | - else (${USE_DBUS}) |
3718 | - add_test(${TESTNAME} ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME} -xunitxml -o ${CMAKE_BINARY_DIR}/test_${TESTNAME}.xml) |
3719 | - endif(${USE_DBUS}) |
3720 | - # force telepathy not to use system approvers when available, |
3721 | - # also force usage of memory backend in history-service |
3722 | - set(TMPDIR "/tmp/telephony_service_test_home") |
3723 | - set(TEST_ENVIRONMENT "HOME=${TMPDIR};" |
3724 | - "HISTORY_SQLITE_DBPATH=:memory:;" |
3725 | - "XDG_CONFIG_HOME=${TMPDIR}; |
3726 | - XDG_DATA_HOME=${TMPDIR}; |
3727 | - XDG_CACHE_DIR=${TMPDIR}; |
3728 | - XDG_CACHE_HOME=${TMPDIR}; |
3729 | - XDG_DATA_DIRS=${TMPDIR}; |
3730 | - MC_ACCOUNT_DIR=${TMPDIR}; |
3731 | - MC_MANAGER_DIR=${TMPDIR}") |
3732 | - set_tests_properties(${TESTNAME} PROPERTIES |
3733 | - ENVIRONMENT "${TEST_ENVIRONMENT}" |
3734 | - TIMEOUT 30) |
3735 | - target_link_libraries(${TESTNAME} |
3736 | - ${TP_QT5_LIBRARIES} |
3737 | - ) |
3738 | -endmacro(generate_test) |
3739 | - |
3740 | -configure_file(dbus-test-wrapper.sh.in ${CMAKE_CURRENT_BINARY_DIR}/dbus-test-wrapper.sh) |
3741 | - |
3742 | -if (DBUS_RUNNER) |
3743 | - generate_test(HandlerTest True telepathyhelper.cpp handlercontroller.cpp mockcontroller.cpp approver.cpp) |
3744 | -endif(DBUS_RUNNER) |
3745 | - |
3746 | -add_subdirectory(mock) |
3747 | +generate_telepathy_test(HandlerTest SOURCES HandlerTest.cpp handlercontroller.cpp approver.cpp) |
3748 | |
3749 | === modified file 'tests/handler/HandlerTest.cpp' |
3750 | --- handler/tests/HandlerTest.cpp 2014-08-18 17:37:19 +0000 |
3751 | +++ tests/handler/HandlerTest.cpp 2015-03-30 20:55:55 +0000 |
3752 | @@ -1,5 +1,5 @@ |
3753 | /* |
3754 | - * Copyright (C) 2013 Canonical, Ltd. |
3755 | + * Copyright (C) 2013-2015 Canonical, Ltd. |
3756 | * |
3757 | * This file is part of telephony-service. |
3758 | * |
3759 | @@ -18,19 +18,22 @@ |
3760 | |
3761 | #include <QtCore/QObject> |
3762 | #include <QtTest/QtTest> |
3763 | +#include "telepathytest.h" |
3764 | #include "handlercontroller.h" |
3765 | #include "mockcontroller.h" |
3766 | #include "approver.h" |
3767 | +#include "accountentry.h" |
3768 | +#include "accountentryfactory.h" |
3769 | #include "telepathyhelper.h" |
3770 | |
3771 | -#define DEFAULT_TIMEOUT 15000 |
3772 | - |
3773 | -class HandlerTest : public QObject |
3774 | +class HandlerTest : public TelepathyTest |
3775 | { |
3776 | Q_OBJECT |
3777 | |
3778 | private Q_SLOTS: |
3779 | void initTestCase(); |
3780 | + void init(); |
3781 | + void cleanup(); |
3782 | void testMakingCalls(); |
3783 | void testHangUpCall(); |
3784 | void testCallHold(); |
3785 | @@ -42,34 +45,51 @@ |
3786 | private: |
3787 | void waitForCallActive(const QString &callerId); |
3788 | Approver *mApprover; |
3789 | + MockController *mMockController; |
3790 | + Tp::AccountPtr mTpAccount; |
3791 | }; |
3792 | |
3793 | void HandlerTest::initTestCase() |
3794 | { |
3795 | - QSignalSpy spy(TelepathyHelper::instance(), SIGNAL(accountReady())); |
3796 | - QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, DEFAULT_TIMEOUT); |
3797 | - QTRY_VERIFY_WITH_TIMEOUT(TelepathyHelper::instance()->connected(), DEFAULT_TIMEOUT); |
3798 | + initialize(); |
3799 | |
3800 | // register the approver |
3801 | mApprover = new Approver(this); |
3802 | TelepathyHelper::instance()->registerClient(mApprover, "TelephonyTestApprover"); |
3803 | // Tp-qt does not set registered status to approvers |
3804 | QTRY_VERIFY(QDBusConnection::sessionBus().interface()->isServiceRegistered(TELEPHONY_SERVICE_APPROVER)); |
3805 | - |
3806 | - // we need to wait in order to give telepathy time to notify about the approver |
3807 | - QTest::qWait(3000); |
3808 | +} |
3809 | + |
3810 | +void HandlerTest::init() |
3811 | +{ |
3812 | + mTpAccount = addAccount("mock", "mock", "the account"); |
3813 | + QVERIFY(!mTpAccount.isNull()); |
3814 | + QTRY_VERIFY(mTpAccount->isReady(Tp::Account::FeatureCore)); |
3815 | + |
3816 | + // make sure the connection is available |
3817 | + QTRY_VERIFY(!mTpAccount->connection().isNull()); |
3818 | + QTRY_COMPARE(mTpAccount->connection()->selfContact()->presence().type(), Tp::ConnectionPresenceTypeAvailable); |
3819 | + |
3820 | + // and create the mock controller |
3821 | + mMockController = new MockController("mock", this); |
3822 | +} |
3823 | + |
3824 | +void HandlerTest::cleanup() |
3825 | +{ |
3826 | + doCleanup(); |
3827 | + mMockController->deleteLater(); |
3828 | } |
3829 | |
3830 | void HandlerTest::testMakingCalls() |
3831 | { |
3832 | QString callerId("1234567"); |
3833 | - QSignalSpy callReceivedSpy(MockController::instance(), SIGNAL(callReceived(QString))); |
3834 | + QSignalSpy callReceivedSpy(mMockController, SIGNAL(callReceived(QString))); |
3835 | // FIXME: add support for multiple accounts |
3836 | - HandlerController::instance()->startCall(callerId, TelepathyHelper::instance()->accountId()); |
3837 | + HandlerController::instance()->startCall(callerId, mTpAccount->uniqueIdentifier()); |
3838 | QTRY_COMPARE(callReceivedSpy.count(), 1); |
3839 | QCOMPARE(callReceivedSpy.first().first().toString(), callerId); |
3840 | |
3841 | - MockController::instance()->hangupCall(callerId); |
3842 | + mMockController->hangupCall(callerId); |
3843 | } |
3844 | |
3845 | void HandlerTest::testHangUpCall() |
3846 | @@ -81,7 +101,7 @@ |
3847 | properties["State"] = "incoming"; |
3848 | |
3849 | QSignalSpy approverCallSpy(mApprover, SIGNAL(newCall())); |
3850 | - QString objectPath = MockController::instance()->placeCall(properties); |
3851 | + QString objectPath = mMockController->placeCall(properties); |
3852 | QVERIFY(!objectPath.isEmpty()); |
3853 | |
3854 | // wait for the channel to hit the approver |
3855 | @@ -91,7 +111,7 @@ |
3856 | waitForCallActive(callerId); |
3857 | |
3858 | // and finally request the hangup |
3859 | - QSignalSpy callEndedSpy(MockController::instance(), SIGNAL(callEnded(QString))); |
3860 | + QSignalSpy callEndedSpy(mMockController, SIGNAL(callEnded(QString))); |
3861 | HandlerController::instance()->hangUpCall(objectPath); |
3862 | QTRY_COMPARE(callEndedSpy.count(), 1); |
3863 | } |
3864 | @@ -105,7 +125,7 @@ |
3865 | properties["State"] = "incoming"; |
3866 | |
3867 | QSignalSpy approverCallSpy(mApprover, SIGNAL(newCall())); |
3868 | - QString objectPath = MockController::instance()->placeCall(properties); |
3869 | + QString objectPath = mMockController->placeCall(properties); |
3870 | QVERIFY(!objectPath.isEmpty()); |
3871 | |
3872 | // wait for the channel to hit the approver |
3873 | @@ -114,7 +134,7 @@ |
3874 | |
3875 | waitForCallActive(callerId); |
3876 | |
3877 | - QSignalSpy callStateSpy(MockController::instance(), SIGNAL(callStateChanged(QString,QString,QString))); |
3878 | + QSignalSpy callStateSpy(mMockController, SIGNAL(callStateChanged(QString,QString,QString))); |
3879 | |
3880 | // set the call on hold |
3881 | HandlerController::instance()->setHold(objectPath, true); |
3882 | @@ -127,7 +147,7 @@ |
3883 | QTRY_COMPARE(callStateSpy.count(), 1); |
3884 | QCOMPARE(callStateSpy.first()[2].toString(), QString("active")); |
3885 | |
3886 | - MockController::instance()->hangupCall(callerId); |
3887 | + mMockController->hangupCall(callerId); |
3888 | } |
3889 | |
3890 | void HandlerTest::testCallProperties() |
3891 | @@ -140,7 +160,7 @@ |
3892 | |
3893 | QSignalSpy approverCallSpy(mApprover, SIGNAL(newCall())); |
3894 | QSignalSpy handlerCallPropertiesSpy(HandlerController::instance(), SIGNAL(callPropertiesChanged(QString,QVariantMap))); |
3895 | - MockController::instance()->placeCall(properties); |
3896 | + mMockController->placeCall(properties); |
3897 | |
3898 | // wait for the channel to hit the approver |
3899 | QTRY_COMPARE(approverCallSpy.count(), 1); |
3900 | @@ -183,6 +203,7 @@ |
3901 | QCOMPARE(dtmfStringFromMethod, dtmfString); |
3902 | |
3903 | HandlerController::instance()->hangUpCall(objectPath); |
3904 | + QTest::qWait(500); |
3905 | } |
3906 | |
3907 | void HandlerTest::testConferenceCall() |
3908 | @@ -196,7 +217,7 @@ |
3909 | properties["State"] = "incoming"; |
3910 | |
3911 | QSignalSpy approverCallSpy(mApprover, SIGNAL(newCall())); |
3912 | - QString call1 = MockController::instance()->placeCall(properties); |
3913 | + QString call1 = mMockController->placeCall(properties); |
3914 | |
3915 | // wait for the channel to hit the approver |
3916 | QTRY_COMPARE(approverCallSpy.count(), 1); |
3917 | @@ -206,7 +227,7 @@ |
3918 | |
3919 | // make a second call |
3920 | properties["Caller"] = callerId2; |
3921 | - QString call2 = MockController::instance()->placeCall(properties); |
3922 | + QString call2 = mMockController->placeCall(properties); |
3923 | // wait for the channel to hit the approver |
3924 | QTRY_COMPARE(approverCallSpy.count(), 1); |
3925 | mApprover->acceptCall(); |
3926 | @@ -214,27 +235,27 @@ |
3927 | waitForCallActive(callerId2); |
3928 | |
3929 | // now create the conf call |
3930 | - QSignalSpy conferenceCreatedSpy(MockController::instance(), SIGNAL(conferenceCreated(QString))); |
3931 | + QSignalSpy conferenceCreatedSpy(mMockController, SIGNAL(conferenceCreated(QString))); |
3932 | HandlerController::instance()->createConferenceCall(QStringList() << call1 << call2); |
3933 | QTRY_COMPARE(conferenceCreatedSpy.count(), 1); |
3934 | QString conferenceObjectPath = conferenceCreatedSpy.first().first().toString(); |
3935 | |
3936 | // now place a third call and try to merge it |
3937 | properties["Caller"] = callerId3; |
3938 | - QString call3 = MockController::instance()->placeCall(properties); |
3939 | + QString call3 = mMockController->placeCall(properties); |
3940 | QTRY_COMPARE(approverCallSpy.count(), 1); |
3941 | mApprover->acceptCall(); |
3942 | approverCallSpy.clear(); |
3943 | waitForCallActive(callerId3); |
3944 | |
3945 | // merge that call on the conference |
3946 | - QSignalSpy channelMergedSpy(MockController::instance(), SIGNAL(channelMerged(QString))); |
3947 | + QSignalSpy channelMergedSpy(mMockController, SIGNAL(channelMerged(QString))); |
3948 | HandlerController::instance()->mergeCall(conferenceObjectPath, call3); |
3949 | QTRY_COMPARE(channelMergedSpy.count(), 1); |
3950 | QCOMPARE(channelMergedSpy.first().first().toString(), call3); |
3951 | |
3952 | // now try to split one of the channels |
3953 | - QSignalSpy channelSplittedSpy(MockController::instance(), SIGNAL(channelSplitted(QString))); |
3954 | + QSignalSpy channelSplittedSpy(mMockController, SIGNAL(channelSplitted(QString))); |
3955 | HandlerController::instance()->splitCall(call2); |
3956 | QTRY_COMPARE(channelSplittedSpy.count(), 1); |
3957 | QCOMPARE(channelSplittedSpy.first().first().toString(), call2); |
3958 | @@ -244,15 +265,18 @@ |
3959 | HandlerController::instance()->hangUpCall(call1); |
3960 | HandlerController::instance()->hangUpCall(call2); |
3961 | HandlerController::instance()->hangUpCall(call3); |
3962 | + |
3963 | + // just to make sure it is all done before removing the accounts |
3964 | + QTest::qWait(500); |
3965 | } |
3966 | |
3967 | void HandlerTest::testSendMessage() |
3968 | { |
3969 | QString recipient("22222222"); |
3970 | QString message("Hello, world!"); |
3971 | - QSignalSpy messageSentSpy(MockController::instance(), SIGNAL(messageSent(QString,QVariantMap))); |
3972 | + QSignalSpy messageSentSpy(mMockController, SIGNAL(messageSent(QString,QVariantMap))); |
3973 | // FIXME: add support for multiple accounts |
3974 | - HandlerController::instance()->sendMessage(recipient, message, TelepathyHelper::instance()->accountId()); |
3975 | + HandlerController::instance()->sendMessage(recipient, message, mTpAccount->uniqueIdentifier()); |
3976 | QTRY_COMPARE(messageSentSpy.count(), 1); |
3977 | QString sentMessage = messageSentSpy.first().first().toString(); |
3978 | QVariantMap messageProperties = messageSentSpy.first().last().value<QVariantMap>(); |
3979 | @@ -284,7 +308,7 @@ |
3980 | void HandlerTest::waitForCallActive(const QString &callerId) |
3981 | { |
3982 | // wait until the call state is "accepted" |
3983 | - QSignalSpy callStateSpy(MockController::instance(), SIGNAL(callStateChanged(QString,QString,QString))); |
3984 | + QSignalSpy callStateSpy(mMockController, SIGNAL(callStateChanged(QString,QString,QString))); |
3985 | QString state; |
3986 | QString objectPath; |
3987 | QString caller; |
3988 | |
3989 | === modified file 'tests/handler/approver.cpp' |
3990 | --- handler/tests/approver.cpp 2014-01-07 19:53:45 +0000 |
3991 | +++ tests/handler/approver.cpp 2015-03-30 20:55:55 +0000 |
3992 | @@ -115,6 +115,7 @@ |
3993 | if (dispatchOperation->possibleHandlers().contains(TELEPHONY_SERVICE_HANDLER)) { |
3994 | dispatchOperation->handleWith(TELEPHONY_SERVICE_HANDLER); |
3995 | mDispatchOps.removeAll(dispatchOperation); |
3996 | + break; |
3997 | } |
3998 | } |
3999 | } |
4000 | |
4001 | === renamed directory 'libtelephonyservice/tests' => 'tests/libtelephonyservice' |
4002 | === added file 'tests/libtelephonyservice/AccountEntryFactoryTest.cpp' |
4003 | --- tests/libtelephonyservice/AccountEntryFactoryTest.cpp 1970-01-01 00:00:00 +0000 |
4004 | +++ tests/libtelephonyservice/AccountEntryFactoryTest.cpp 2015-03-30 20:55:55 +0000 |
4005 | @@ -0,0 +1,67 @@ |
4006 | +/* |
4007 | + * Copyright (C) 2015 Canonical, Ltd. |
4008 | + * |
4009 | + * This file is part of telephony-service. |
4010 | + * |
4011 | + * telephony-service is free software; you can redistribute it and/or modify |
4012 | + * it under the terms of the GNU General Public License as published by |
4013 | + * the Free Software Foundation; version 3. |
4014 | + * |
4015 | + * telephony-service is distributed in the hope that it will be useful, |
4016 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4017 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4018 | + * GNU General Public License for more details. |
4019 | + * |
4020 | + * You should have received a copy of the GNU General Public License |
4021 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4022 | + */ |
4023 | + |
4024 | +#include <QtCore/QObject> |
4025 | +#include <QtTest/QtTest> |
4026 | +#include "telepathytest.h" |
4027 | +#include "accountentry.h" |
4028 | +#include "accountentryfactory.h" |
4029 | +#include "ofonoaccountentry.h" |
4030 | +#include "telepathyhelper.h" |
4031 | + |
4032 | +class AccountEntryFactoryTest : public TelepathyTest |
4033 | +{ |
4034 | + Q_OBJECT |
4035 | + |
4036 | +private Q_SLOTS: |
4037 | + void initTestCase(); |
4038 | + void testCorrectInstancesCreated(); |
4039 | + void testNullAccount(); |
4040 | +}; |
4041 | + |
4042 | +void AccountEntryFactoryTest::initTestCase() |
4043 | +{ |
4044 | + initialize(); |
4045 | +} |
4046 | + |
4047 | +void AccountEntryFactoryTest::testCorrectInstancesCreated() |
4048 | +{ |
4049 | + Tp::AccountPtr genericTpAccount = addAccount("mock", "mock", "generic"); |
4050 | + QVERIFY(!genericTpAccount.isNull()); |
4051 | + AccountEntry *genericAccount = AccountEntryFactory::createEntry(genericTpAccount, this); |
4052 | + QVERIFY(genericAccount); |
4053 | + QCOMPARE(genericAccount->type(), AccountEntry::GenericAccount); |
4054 | + QVERIFY(!qobject_cast<OfonoAccountEntry*>(genericAccount)); |
4055 | + |
4056 | + Tp::AccountPtr ofonoTpAccount = addAccount("mock", "ofono", "phone account"); |
4057 | + AccountEntry *ofonoAccount = AccountEntryFactory::createEntry(ofonoTpAccount, this); |
4058 | + QVERIFY(ofonoAccount); |
4059 | + QCOMPARE(ofonoAccount->type(), AccountEntry::PhoneAccount); |
4060 | + QVERIFY(qobject_cast<OfonoAccountEntry*>(ofonoAccount)); |
4061 | +} |
4062 | + |
4063 | +void AccountEntryFactoryTest::testNullAccount() |
4064 | +{ |
4065 | + AccountEntry *nullAccount = AccountEntryFactory::createEntry(Tp::AccountPtr(), this); |
4066 | + QVERIFY(nullAccount); |
4067 | + QVERIFY(nullAccount->accountId().isNull()); |
4068 | +} |
4069 | + |
4070 | + |
4071 | +QTEST_MAIN(AccountEntryFactoryTest) |
4072 | +#include "AccountEntryFactoryTest.moc" |
4073 | |
4074 | === added file 'tests/libtelephonyservice/AccountEntryTest.cpp' |
4075 | --- tests/libtelephonyservice/AccountEntryTest.cpp 1970-01-01 00:00:00 +0000 |
4076 | +++ tests/libtelephonyservice/AccountEntryTest.cpp 2015-03-30 20:55:55 +0000 |
4077 | @@ -0,0 +1,228 @@ |
4078 | +/* |
4079 | + * Copyright (C) 2015 Canonical, Ltd. |
4080 | + * |
4081 | + * This file is part of telephony-service. |
4082 | + * |
4083 | + * telephony-service is free software; you can redistribute it and/or modify |
4084 | + * it under the terms of the GNU General Public License as published by |
4085 | + * the Free Software Foundation; version 3. |
4086 | + * |
4087 | + * telephony-service is distributed in the hope that it will be useful, |
4088 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4089 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4090 | + * GNU General Public License for more details. |
4091 | + * |
4092 | + * You should have received a copy of the GNU General Public License |
4093 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4094 | + */ |
4095 | + |
4096 | +#include <QtCore/QObject> |
4097 | +#include <QtTest/QtTest> |
4098 | +#include "telepathytest.h" |
4099 | +#include "accountentry.h" |
4100 | +#include "accountentryfactory.h" |
4101 | +#include "telepathyhelper.h" |
4102 | +#include "mockcontroller.h" |
4103 | + |
4104 | +class AccountEntryTest : public TelepathyTest |
4105 | +{ |
4106 | + Q_OBJECT |
4107 | + |
4108 | +private Q_SLOTS: |
4109 | + void initTestCase(); |
4110 | + void init(); |
4111 | + void cleanup(); |
4112 | + void testAccountId(); |
4113 | + void testActive(); |
4114 | + void testDisplayName(); |
4115 | + void testStatus(); |
4116 | + void testStatusMessage(); |
4117 | + void testConnected(); |
4118 | + void testCompareIds_data(); |
4119 | + void testCompareIds(); |
4120 | + void testAddressableVCardFields(); |
4121 | + |
4122 | +private: |
4123 | + AccountEntry *mAccount; |
4124 | + Tp::AccountPtr mTpAccount; |
4125 | + AccountEntry *mNullAccount; |
4126 | + MockController *mMockController; |
4127 | +}; |
4128 | + |
4129 | +void AccountEntryTest::initTestCase() |
4130 | +{ |
4131 | + initialize(); |
4132 | + |
4133 | + // create a null account |
4134 | + mNullAccount = AccountEntryFactory::createEntry(Tp::AccountPtr(), this); |
4135 | +} |
4136 | + |
4137 | +void AccountEntryTest::init() |
4138 | +{ |
4139 | + mTpAccount = addAccount("mock", "mock", "the account"); |
4140 | + QVERIFY(!mTpAccount.isNull()); |
4141 | + QTRY_VERIFY(mTpAccount->isReady(Tp::Account::FeatureCore)); |
4142 | + |
4143 | + mAccount = AccountEntryFactory::createEntry(mTpAccount, this); |
4144 | + QVERIFY(mAccount); |
4145 | + |
4146 | + // make sure the connection is available |
4147 | + QTRY_VERIFY(!mTpAccount->connection().isNull()); |
4148 | + QTRY_COMPARE(mTpAccount->connection()->selfContact()->presence().type(), Tp::ConnectionPresenceTypeAvailable); |
4149 | + QTRY_VERIFY(mAccount->connected()); |
4150 | + |
4151 | + // and create the mock controller |
4152 | + mMockController = new MockController("mock", this); |
4153 | + |
4154 | + // just in case, wait some time |
4155 | + QTest::qWait(500); |
4156 | +} |
4157 | + |
4158 | +void AccountEntryTest::cleanup() |
4159 | +{ |
4160 | + doCleanup(); |
4161 | + |
4162 | + mAccount->deleteLater(); |
4163 | + mMockController->deleteLater(); |
4164 | +} |
4165 | + |
4166 | +void AccountEntryTest::testAccountId() |
4167 | +{ |
4168 | + QCOMPARE(mAccount->accountId(), mTpAccount->uniqueIdentifier()); |
4169 | + QVERIFY(mNullAccount->accountId().isNull()); |
4170 | +} |
4171 | + |
4172 | +void AccountEntryTest::testActive() |
4173 | +{ |
4174 | + QSignalSpy activeChangedSpy(mAccount, SIGNAL(activeChanged())); |
4175 | + |
4176 | + // the mock account is enabled/connected by default, so make sure it is like that |
4177 | + QVERIFY(mAccount->active()); |
4178 | + |
4179 | + // now set the account offline and see if the active flag changes correctly |
4180 | + mMockController->setOnline(false); |
4181 | + QTRY_VERIFY(!mAccount->active()); |
4182 | + QCOMPARE(activeChangedSpy.count(), 1); |
4183 | + |
4184 | + // now re-enable the account and check that the entry is updated |
4185 | + activeChangedSpy.clear(); |
4186 | + mMockController->setOnline(true); |
4187 | + QTRY_VERIFY(mAccount->active()); |
4188 | + QCOMPARE(activeChangedSpy.count(), 1); |
4189 | + |
4190 | + // check that for a null account active is false |
4191 | + QVERIFY(!mNullAccount->active()); |
4192 | +} |
4193 | + |
4194 | +void AccountEntryTest::testDisplayName() |
4195 | +{ |
4196 | + QSignalSpy displayNameChangedSpy(mAccount, SIGNAL(displayNameChanged())); |
4197 | + |
4198 | + // check that the value is correct already |
4199 | + QCOMPARE(mAccount->displayName(), mTpAccount->displayName()); |
4200 | + |
4201 | + // now try to set the display in the telepathy account directly and see that the entry gets updated |
4202 | + QString newDisplayName = "some other display name"; |
4203 | + mTpAccount->setDisplayName(newDisplayName); |
4204 | + QTRY_COMPARE(mAccount->displayName(), newDisplayName); |
4205 | + QCOMPARE(displayNameChangedSpy.count(), 1); |
4206 | + |
4207 | + // and try setting the display name in the entry itself |
4208 | + displayNameChangedSpy.clear(); |
4209 | + newDisplayName = "changing again"; |
4210 | + mAccount->setDisplayName(newDisplayName); |
4211 | + QTRY_COMPARE(mAccount->displayName(), newDisplayName); |
4212 | + QCOMPARE(displayNameChangedSpy.count(), 1); |
4213 | + QCOMPARE(mTpAccount->displayName(), newDisplayName); |
4214 | + |
4215 | + // check that for a null account the displayName is null |
4216 | + QVERIFY(mNullAccount->displayName().isNull()); |
4217 | +} |
4218 | + |
4219 | +void AccountEntryTest::testStatus() |
4220 | +{ |
4221 | + QSignalSpy statusChangedSpy(mAccount, SIGNAL(statusChanged())); |
4222 | + |
4223 | + // check that the value is correct already |
4224 | + QCOMPARE(mAccount->status(), mTpAccount->connection()->selfContact()->presence().status()); |
4225 | + |
4226 | + // and now set a new value |
4227 | + Tp::Presence presence(Tp::ConnectionPresenceTypeAway, "away", "away"); |
4228 | + mTpAccount->setRequestedPresence(presence); |
4229 | + |
4230 | + QTRY_COMPARE(mAccount->status(), QString("away")); |
4231 | + QCOMPARE(statusChangedSpy.count(), 1); |
4232 | + |
4233 | + // check that for a null account the status is null |
4234 | + QVERIFY(mNullAccount->status().isNull()); |
4235 | +} |
4236 | + |
4237 | +void AccountEntryTest::testStatusMessage() |
4238 | +{ |
4239 | + QSignalSpy statusMessageChangedSpy(mAccount, SIGNAL(statusMessageChanged())); |
4240 | + |
4241 | + // check that the value is correct already |
4242 | + QTRY_COMPARE(mAccount->statusMessage(), mTpAccount->connection()->selfContact()->presence().statusMessage()); |
4243 | + |
4244 | + // and now set a new value |
4245 | + QString statusMessage("I am online"); |
4246 | + Tp::Presence presence(Tp::ConnectionPresenceTypeAvailable, "available", statusMessage); |
4247 | + mTpAccount->setRequestedPresence(presence); |
4248 | + |
4249 | + QTRY_COMPARE(mAccount->statusMessage(), statusMessage); |
4250 | + QCOMPARE(statusMessageChangedSpy.count(), 1); |
4251 | + |
4252 | + // check that for a null account the displayName is null |
4253 | + QVERIFY(mNullAccount->statusMessage().isNull()); |
4254 | +} |
4255 | + |
4256 | +void AccountEntryTest::testConnected() |
4257 | +{ |
4258 | + QSignalSpy connectedChangedSpy(mAccount, SIGNAL(connectedChanged())); |
4259 | + |
4260 | + // the mock account is enabled/connected by default, so make sure it is like that |
4261 | + QVERIFY(mAccount->connected()); |
4262 | + |
4263 | + // now set the account offline and see if the active flag changes correctly |
4264 | + mMockController->setOnline(false); |
4265 | + QTRY_VERIFY(!mAccount->connected()); |
4266 | + QTRY_COMPARE(connectedChangedSpy.count(), 1); |
4267 | + |
4268 | + // now re-enable the account and check that the entry is updated |
4269 | + connectedChangedSpy.clear(); |
4270 | + mMockController->setOnline(true); |
4271 | + QTRY_VERIFY(mAccount->connected()); |
4272 | + QTRY_COMPARE(connectedChangedSpy.count(), 1); |
4273 | + |
4274 | + // check that for a null account the displayName is null |
4275 | + QVERIFY(!mNullAccount->connected()); |
4276 | +} |
4277 | + |
4278 | +void AccountEntryTest::testCompareIds_data() |
4279 | +{ |
4280 | + QTest::addColumn<QString>("first"); |
4281 | + QTest::addColumn<QString>("second"); |
4282 | + QTest::addColumn<bool>("expectedResult"); |
4283 | + |
4284 | + QTest::newRow("identical values") << "1234567" << "1234567" << true; |
4285 | + QTest::newRow("case difference") << "TestId" << "testid" << false; |
4286 | + QTest::newRow("phone prefix") << "1234567" << "1231234567" << false; |
4287 | +} |
4288 | + |
4289 | +void AccountEntryTest::testCompareIds() |
4290 | +{ |
4291 | + QFETCH(QString, first); |
4292 | + QFETCH(QString, second); |
4293 | + QFETCH(bool, expectedResult); |
4294 | + |
4295 | + QCOMPARE(mAccount->compareIds(first, second), expectedResult); |
4296 | +} |
4297 | + |
4298 | +void AccountEntryTest::testAddressableVCardFields() |
4299 | +{ |
4300 | + QVERIFY(!mAccount->addressableVCardFields().isEmpty()); |
4301 | + QCOMPARE(mAccount->addressableVCardFields(), mTpAccount->protocolInfo().addressableVCardFields()); |
4302 | +} |
4303 | + |
4304 | +QTEST_MAIN(AccountEntryTest) |
4305 | +#include "AccountEntryTest.moc" |
4306 | |
4307 | === modified file 'tests/libtelephonyservice/CMakeLists.txt' |
4308 | --- libtelephonyservice/tests/CMakeLists.txt 2014-07-01 16:05:21 +0000 |
4309 | +++ tests/libtelephonyservice/CMakeLists.txt 2015-03-30 20:55:55 +0000 |
4310 | @@ -1,44 +1,28 @@ |
4311 | +set(LIBTELEPHONYSERVICE_DIR ${CMAKE_SOURCE_DIR}/libtelephonyservice) |
4312 | include_directories( |
4313 | ${CMAKE_CURRENT_BINARY_DIR} |
4314 | - ${CMAKE_SOURCE_DIR}/libtelephonyservice |
4315 | + ${LIBTELEPHONYSERVICE_DIR} |
4316 | + ${TP_QT5_INCLUDE_DIRS} |
4317 | + ${CMAKE_SOURCE_DIR}/tests/common |
4318 | ) |
4319 | |
4320 | add_executable(GreeterContactsTestServerExe GreeterContactsTestServer.cpp) |
4321 | qt5_use_modules(GreeterContactsTestServerExe Core DBus) |
4322 | |
4323 | -add_executable(GreeterContactsTestExe GreeterContactsTest.cpp ../greetercontacts.cpp) |
4324 | -set_target_properties(GreeterContactsTestExe PROPERTIES COMPILE_DEFINITIONS "AS_BUSNAME=sessionBus;CMAKE_SOURCE_DIR=\"${CMAKE_SOURCE_DIR}\"") |
4325 | -qt5_use_modules(GreeterContactsTestExe Contacts Core DBus Test) |
4326 | - |
4327 | -add_test(NAME GreeterContactsTest |
4328 | - COMMAND env |
4329 | - -u LD_PRELOAD # fakeroot's preload doesn't play well with dbus-test-runner |
4330 | - -u LD_LIBRARY_PATH # fakeroot fills this too |
4331 | - XDG_SESSION_CLASS=greeter |
4332 | - XDG_GREETER_DATA_DIR=${CMAKE_BINARY_DIR}/Testing/Temporary |
4333 | - dbus-test-runner |
4334 | - --task ${CMAKE_CURRENT_BINARY_DIR}/GreeterContactsTestServerExe |
4335 | - --task-name server |
4336 | - --ignore-return |
4337 | - --task ${CMAKE_CURRENT_BINARY_DIR}/GreeterContactsTestExe |
4338 | - --task-name test |
4339 | - --wait-for org.freedesktop.Accounts |
4340 | - -p -xunitxml -p -o -p ${CMAKE_BINARY_DIR}/test_GreeterContactsTest.xml |
4341 | - DEPENDENCIES GreeterContactsTestServerExe GreeterContactsTestExe |
4342 | - ) |
4343 | - |
4344 | -macro(generate_tests) |
4345 | - foreach(test ${ARGN}) |
4346 | - add_executable(${test} ${test}.cpp) |
4347 | - qt5_use_modules(${test} Contacts Core DBus Qml Test) |
4348 | - target_link_libraries(${test} |
4349 | - telephonyservice |
4350 | - ) |
4351 | - add_test(${test} ${CMAKE_CURRENT_BINARY_DIR}/${test} -platform offscreen -xunitxml -o ${CMAKE_BINARY_DIR}/test_${test}.xml) |
4352 | - endforeach(test) |
4353 | -endmacro(generate_tests) |
4354 | - |
4355 | -generate_tests( |
4356 | - ContactUtilsTest |
4357 | - PhoneUtilsTest |
4358 | - ) |
4359 | +generate_test(GreeterContactsTest USE_DBUS |
4360 | + SOURCES GreeterContactsTest.cpp ${LIBTELEPHONYSERVICE_DIR}/greetercontacts.cpp |
4361 | + QT5_MODULES Contacts Core DBus Test |
4362 | + ENVIRONMENT XDG_SESSION_CLASS=greeter XDG_GREETER_DATA_DIR=${CMAKE_BINARY_DIR}/Testing/Temporary |
4363 | + TASKS --task env --ignore-return --task ${CMAKE_CURRENT_BINARY_DIR}/GreeterContactsTestServerExe --task-name server --ignore-return |
4364 | + WAIT_FOR org.freedesktop.Accounts) |
4365 | +set_target_properties(GreeterContactsTest PROPERTIES COMPILE_DEFINITIONS "AS_BUSNAME=sessionBus;CMAKE_SOURCE_DIR=\"${CMAKE_SOURCE_DIR}\"") |
4366 | +add_dependencies(GreeterContactsTest GreeterContactsTestServerExe) |
4367 | + |
4368 | +generate_test(ContactUtilsTest SOURCES ContactUtilsTest.cpp QT5_MODULES Contacts Core Test LIBRARIES telephonyservice USE_UI) |
4369 | +generate_test(PhoneUtilsTest SOURCES PhoneUtilsTest.cpp LIBRARIES telephonyservice USE_UI) |
4370 | + |
4371 | +generate_telepathy_test(AccountEntryFactoryTest SOURCES AccountEntryFactoryTest.cpp) |
4372 | +generate_telepathy_test(AccountEntryTest SOURCES AccountEntryTest.cpp) |
4373 | +generate_telepathy_test(ChatManagerTest SOURCES ChatManagerTest.cpp) |
4374 | +generate_telepathy_test(OfonoAccountEntryTest SOURCES OfonoAccountEntryTest.cpp) |
4375 | +generate_telepathy_test(TelepathyHelperTest SOURCES TelepathyHelperTest.cpp) |
4376 | |
4377 | === added file 'tests/libtelephonyservice/ChatManagerTest.cpp' |
4378 | --- tests/libtelephonyservice/ChatManagerTest.cpp 1970-01-01 00:00:00 +0000 |
4379 | +++ tests/libtelephonyservice/ChatManagerTest.cpp 2015-03-30 20:55:55 +0000 |
4380 | @@ -0,0 +1,177 @@ |
4381 | +/* |
4382 | + * Copyright (C) 2013-2015 Canonical, Ltd. |
4383 | + * |
4384 | + * This file is part of telephony-service. |
4385 | + * |
4386 | + * telephony-service is free software; you can redistribute it and/or modify |
4387 | + * it under the terms of the GNU General Public License as published by |
4388 | + * the Free Software Foundation; version 3. |
4389 | + * |
4390 | + * telephony-service is distributed in the hope that it will be useful, |
4391 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4392 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4393 | + * GNU General Public License for more details. |
4394 | + * |
4395 | + * You should have received a copy of the GNU General Public License |
4396 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4397 | + */ |
4398 | + |
4399 | +#include <QtCore/QObject> |
4400 | +#include <QtTest/QtTest> |
4401 | +#include "telepathytest.h" |
4402 | +#include "accountentry.h" |
4403 | +#include "chatmanager.h" |
4404 | +#include "telepathyhelper.h" |
4405 | +#include "mockcontroller.h" |
4406 | + |
4407 | +class ChatManagerTest : public TelepathyTest |
4408 | +{ |
4409 | + Q_OBJECT |
4410 | + |
4411 | +private Q_SLOTS: |
4412 | + void initTestCase(); |
4413 | + void init(); |
4414 | + void cleanup(); |
4415 | + void testSendMessage_data(); |
4416 | + void testSendMessage(); |
4417 | + void testMessageReceived(); |
4418 | + void testAcknowledgeMessages(); |
4419 | + |
4420 | +private: |
4421 | + Tp::AccountPtr mGenericTpAccount; |
4422 | + Tp::AccountPtr mPhoneTpAccount; |
4423 | + MockController *mGenericMockController; |
4424 | + MockController *mPhoneMockController; |
4425 | +}; |
4426 | + |
4427 | +void ChatManagerTest::initTestCase() |
4428 | +{ |
4429 | + initialize(); |
4430 | + |
4431 | + TelepathyHelper::instance()->registerChannelObserver(); |
4432 | + |
4433 | + // just give telepathy some time to register the observer |
4434 | + QTest::qWait(1000); |
4435 | +} |
4436 | + |
4437 | +void ChatManagerTest::init() |
4438 | +{ |
4439 | + // add two accounts |
4440 | + mGenericTpAccount = addAccount("mock", "mock", "the generic account"); |
4441 | + QTRY_VERIFY(!mGenericTpAccount->connection().isNull()); |
4442 | + |
4443 | + mPhoneTpAccount = addAccount("mock", "ofono", "the phone account"); |
4444 | + QTRY_VERIFY(!mPhoneTpAccount->connection().isNull()); |
4445 | + |
4446 | + // and create the mock controller |
4447 | + mGenericMockController = new MockController("mock", this); |
4448 | + mPhoneMockController = new MockController("ofono", this); |
4449 | +} |
4450 | + |
4451 | +void ChatManagerTest::cleanup() |
4452 | +{ |
4453 | + // the accounts are removed in the parent class. |
4454 | + doCleanup(); |
4455 | + |
4456 | + mGenericMockController->deleteLater(); |
4457 | + mPhoneMockController->deleteLater(); |
4458 | +} |
4459 | + |
4460 | +void ChatManagerTest::testSendMessage_data() |
4461 | +{ |
4462 | + QTest::addColumn<QStringList>("recipients"); |
4463 | + QTest::addColumn<QString>("message"); |
4464 | + QTest::addColumn<QString>("accountId"); |
4465 | + |
4466 | + QTest::newRow("message via the generic account") << (QStringList() << "recipient1") << QString("Hello world") << QString("mock/mock/account0"); |
4467 | + QTest::newRow("message via the phone account") << (QStringList() << "recipient2") << QString("Hello Phone World") << QString("mock/ofono/account0"); |
4468 | + QTest::newRow("multiple recipients") << (QStringList() << "123" << "456" << "789") << QString("Hi friends!") << QString("mock/mock/account0"); |
4469 | +} |
4470 | + |
4471 | +void ChatManagerTest::testSendMessage() |
4472 | +{ |
4473 | + QFETCH(QStringList, recipients); |
4474 | + QFETCH(QString, message); |
4475 | + QFETCH(QString, accountId); |
4476 | + |
4477 | + // just to make it easier, sort the recipients |
4478 | + qSort(recipients); |
4479 | + |
4480 | + MockController *controller = accountId.startsWith("mock/mock") ? mGenericMockController : mPhoneMockController; |
4481 | + QSignalSpy controllerMessageSentSpy(controller, SIGNAL(messageSent(QString,QVariantMap))); |
4482 | + QSignalSpy messageSentSpy(ChatManager::instance(), SIGNAL(messageSent(QStringList,QString))); |
4483 | + |
4484 | + ChatManager::instance()->sendMessage(recipients, message, accountId); |
4485 | + |
4486 | + QTRY_COMPARE(controllerMessageSentSpy.count(), 1); |
4487 | + QString messageText = controllerMessageSentSpy.first()[0].toString(); |
4488 | + QVariantMap messageProperties = controllerMessageSentSpy.first()[1].toMap(); |
4489 | + QStringList messageRecipients = messageProperties["Recipients"].toStringList(); |
4490 | + qSort(messageRecipients); |
4491 | + QCOMPARE(messageText, message); |
4492 | + QCOMPARE(messageRecipients, recipients); |
4493 | + |
4494 | + QTRY_COMPARE(messageSentSpy.count(), 1); |
4495 | + messageRecipients = messageSentSpy.first()[0].toStringList(); |
4496 | + qSort(messageRecipients); |
4497 | + messageText = messageSentSpy.first()[1].toString(); |
4498 | + QCOMPARE(messageText, message); |
4499 | + QCOMPARE(messageRecipients, recipients); |
4500 | +} |
4501 | + |
4502 | +void ChatManagerTest::testMessageReceived() |
4503 | +{ |
4504 | + QSignalSpy messageReceivedSpy(ChatManager::instance(), SIGNAL(messageReceived(QString,QString,QDateTime,QString,bool))); |
4505 | + |
4506 | + QVariantMap properties; |
4507 | + properties["Sender"] = "12345"; |
4508 | + properties["Recipients"] = (QStringList() << "12345"); |
4509 | + QString message("Hi there"); |
4510 | + mGenericMockController->placeIncomingMessage(message, properties); |
4511 | + |
4512 | + QTRY_COMPARE(messageReceivedSpy.count(), 1); |
4513 | + QString sender = messageReceivedSpy.first()[0].toString(); |
4514 | + QString receivedMessage = messageReceivedSpy.first()[1].toString(); |
4515 | + QCOMPARE(sender, properties["Sender"].toString()); |
4516 | + QCOMPARE(receivedMessage, message); |
4517 | +} |
4518 | + |
4519 | +void ChatManagerTest::testAcknowledgeMessages() |
4520 | +{ |
4521 | + QSignalSpy messageReceivedSpy(ChatManager::instance(), SIGNAL(messageReceived(QString,QString,QDateTime,QString,bool))); |
4522 | + |
4523 | + QVariantMap properties; |
4524 | + properties["Sender"] = "12345"; |
4525 | + properties["Recipients"] = (QStringList() << "12345"); |
4526 | + QStringList messages; |
4527 | + messages << "Hi there" << "How are you" << "Always look on the bright side of life"; |
4528 | + Q_FOREACH(const QString &message, messages) { |
4529 | + mGenericMockController->placeIncomingMessage(message, properties); |
4530 | + QTest::qWait(100); |
4531 | + } |
4532 | + QTRY_COMPARE(messageReceivedSpy.count(), messages.count()); |
4533 | + |
4534 | + QStringList messageIds; |
4535 | + for (int i = 0; i < messages.count(); ++i) { |
4536 | + QString messageId = messageReceivedSpy[i][3].toString(); |
4537 | + messageIds << messageId; |
4538 | + } |
4539 | + |
4540 | + QSignalSpy messageReadSpy(mGenericMockController, SIGNAL(messageRead(QString))); |
4541 | + Q_FOREACH(const QString &messageId, messageIds) { |
4542 | + ChatManager::instance()->acknowledgeMessage(properties["Recipients"].toStringList(), messageId, "mock/mock/account0"); |
4543 | + } |
4544 | + |
4545 | + QTRY_COMPARE(messageReadSpy.count(), messageIds.count()); |
4546 | + QStringList receivedIds; |
4547 | + for (int i = 0; i < messageReadSpy.count(); ++i) { |
4548 | + receivedIds << messageReadSpy[i][0].toString(); |
4549 | + } |
4550 | + |
4551 | + qSort(receivedIds); |
4552 | + qSort(messageIds); |
4553 | + QCOMPARE(receivedIds, messageIds); |
4554 | +} |
4555 | + |
4556 | +QTEST_MAIN(ChatManagerTest) |
4557 | +#include "ChatManagerTest.moc" |
4558 | |
4559 | === modified file 'tests/libtelephonyservice/ContactUtilsTest.cpp' |
4560 | --- libtelephonyservice/tests/ContactUtilsTest.cpp 2013-08-13 22:25:18 +0000 |
4561 | +++ tests/libtelephonyservice/ContactUtilsTest.cpp 2015-03-30 20:55:55 +0000 |
4562 | @@ -34,8 +34,6 @@ |
4563 | void testSharedManagerCreation(); |
4564 | }; |
4565 | |
4566 | - |
4567 | - |
4568 | void ContactUtilsTest::testFormatContactName_data() |
4569 | { |
4570 | QTest::addColumn<QString>("firstName"); |
4571 | |
4572 | === modified file 'tests/libtelephonyservice/GreeterContactsTest.cpp' |
4573 | --- libtelephonyservice/tests/GreeterContactsTest.cpp 2014-07-01 16:10:33 +0000 |
4574 | +++ tests/libtelephonyservice/GreeterContactsTest.cpp 2015-03-30 20:55:55 +0000 |
4575 | @@ -281,8 +281,7 @@ |
4576 | "com.canonical.TelephonyServiceApprover", |
4577 | QDBusConnection::sessionBus()); |
4578 | QSignalSpy spy(&iface, SIGNAL(InitialQueriesDone())); |
4579 | - QVERIFY(spy.wait()); |
4580 | - QCOMPARE(spy.count(), 1); |
4581 | + QTRY_COMPARE(spy.count(), 1); |
4582 | } |
4583 | |
4584 | void GreeterContactsTest::makeGreeterContacts() |
4585 | @@ -293,8 +292,7 @@ |
4586 | |
4587 | void GreeterContactsTest::waitForUpdatedSignal(bool convertedPath) |
4588 | { |
4589 | - QVERIFY(mSpy->wait()); |
4590 | - QCOMPARE(mSpy->count(), 1); |
4591 | + QTRY_COMPARE(mSpy->count(), 1); |
4592 | |
4593 | QList<QVariant> arguments = mSpy->takeFirst(); |
4594 | QContact expectedContact = makeTestContact(convertedPath); |
4595 | |
4596 | === modified file 'tests/libtelephonyservice/GreeterContactsTestServer.cpp' |
4597 | --- libtelephonyservice/tests/GreeterContactsTestServer.cpp 2014-07-01 16:05:21 +0000 |
4598 | +++ tests/libtelephonyservice/GreeterContactsTestServer.cpp 2015-03-30 20:55:55 +0000 |
4599 | @@ -24,7 +24,6 @@ |
4600 | #include <QStringList> |
4601 | #include <unistd.h> |
4602 | |
4603 | - |
4604 | #include <QDebug> |
4605 | bool listGetCalled = false; |
4606 | bool userGetCalled = false; |
4607 | |
4608 | === added file 'tests/libtelephonyservice/OfonoAccountEntryTest.cpp' |
4609 | --- tests/libtelephonyservice/OfonoAccountEntryTest.cpp 1970-01-01 00:00:00 +0000 |
4610 | +++ tests/libtelephonyservice/OfonoAccountEntryTest.cpp 2015-03-30 20:55:55 +0000 |
4611 | @@ -0,0 +1,273 @@ |
4612 | +/* |
4613 | + * Copyright (C) 2015 Canonical, Ltd. |
4614 | + * |
4615 | + * This file is part of telephony-service. |
4616 | + * |
4617 | + * telephony-service is free software; you can redistribute it and/or modify |
4618 | + * it under the terms of the GNU General Public License as published by |
4619 | + * the Free Software Foundation; version 3. |
4620 | + * |
4621 | + * telephony-service is distributed in the hope that it will be useful, |
4622 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4623 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4624 | + * GNU General Public License for more details. |
4625 | + * |
4626 | + * You should have received a copy of the GNU General Public License |
4627 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4628 | + */ |
4629 | + |
4630 | +#include <QtCore/QObject> |
4631 | +#include <QtTest/QtTest> |
4632 | +#include "telepathytest.h" |
4633 | +#include "ofonoaccountentry.h" |
4634 | +#include "accountentryfactory.h" |
4635 | +#include "mockcontroller.h" |
4636 | + |
4637 | +class OfonoAccountEntryTest : public TelepathyTest |
4638 | +{ |
4639 | + Q_OBJECT |
4640 | + |
4641 | +private Q_SLOTS: |
4642 | + void initTestCase(); |
4643 | + void init(); |
4644 | + void cleanup(); |
4645 | + void testAccountType(); |
4646 | + void testConnected(); |
4647 | + void testCompareIds_data(); |
4648 | + void testCompareIds(); |
4649 | + void testEmergencyNumbers(); |
4650 | + void testSerial(); |
4651 | + void testVoicemailIndicator(); |
4652 | + void testVoicemailNumber(); |
4653 | + void testVoicemailCount(); |
4654 | + void testSimLocked(); |
4655 | + void testEmergencyCallsAvailable_data(); |
4656 | + void testEmergencyCallsAvailable(); |
4657 | + void testNetworkName(); |
4658 | + void testAddressableVCardFields(); |
4659 | + |
4660 | +private: |
4661 | + OfonoAccountEntry *mAccount; |
4662 | + Tp::AccountPtr mTpAccount; |
4663 | + MockController *mMockController; |
4664 | +}; |
4665 | + |
4666 | +void OfonoAccountEntryTest::initTestCase() |
4667 | +{ |
4668 | + initialize(); |
4669 | +} |
4670 | + |
4671 | +void OfonoAccountEntryTest::init() |
4672 | +{ |
4673 | + mTpAccount = addAccount("mock", "ofono", "phone account"); |
4674 | + QVERIFY(!mTpAccount.isNull()); |
4675 | + QTRY_VERIFY(mTpAccount->isReady(Tp::Account::FeatureCore)); |
4676 | + |
4677 | + mAccount = qobject_cast<OfonoAccountEntry*>(AccountEntryFactory::createEntry(mTpAccount, this)); |
4678 | + QVERIFY(mAccount); |
4679 | + |
4680 | + // make sure the connection is available |
4681 | + QTRY_VERIFY(!mTpAccount->connection().isNull()); |
4682 | + QTRY_COMPARE(mTpAccount->connection()->selfContact()->presence().type(), Tp::ConnectionPresenceTypeAvailable); |
4683 | + QTRY_VERIFY(mAccount->connected()); |
4684 | + |
4685 | + // create the mock controller |
4686 | + mMockController = new MockController("ofono", this); |
4687 | + |
4688 | + // just in case, wait some time |
4689 | + QTest::qWait(500); |
4690 | +} |
4691 | + |
4692 | +void OfonoAccountEntryTest::cleanup() |
4693 | +{ |
4694 | + doCleanup(); |
4695 | + mAccount->deleteLater(); |
4696 | + mMockController->deleteLater(); |
4697 | +} |
4698 | + |
4699 | +void OfonoAccountEntryTest::testAccountType() |
4700 | +{ |
4701 | + QCOMPARE(mAccount->type(), AccountEntry::PhoneAccount); |
4702 | +} |
4703 | + |
4704 | +void OfonoAccountEntryTest::testConnected() |
4705 | +{ |
4706 | + // the mock account is enabled/connected by default, so make sure it is like that |
4707 | + QTRY_VERIFY(mAccount->connected()); |
4708 | + |
4709 | + // right now the ofono account connection status behave exactly like the generic class, |
4710 | + // but as the code path is different, test it again |
4711 | + QSignalSpy connectedChangedSpy(mAccount, SIGNAL(connectedChanged())); |
4712 | + |
4713 | + // now set the account offline and see if the active flag changes correctly |
4714 | + mMockController->setOnline(false); |
4715 | + QTRY_VERIFY(!mAccount->connected()); |
4716 | + QCOMPARE(connectedChangedSpy.count(), 1); |
4717 | + |
4718 | + // now re-enable the account and check that the entry is updated |
4719 | + connectedChangedSpy.clear(); |
4720 | + mMockController->setOnline(true); |
4721 | + QTRY_VERIFY(mAccount->connected()); |
4722 | + QCOMPARE(connectedChangedSpy.count(), 1); |
4723 | +} |
4724 | + |
4725 | +void OfonoAccountEntryTest::testCompareIds_data() |
4726 | +{ |
4727 | + QTest::addColumn<QString>("first"); |
4728 | + QTest::addColumn<QString>("second"); |
4729 | + QTest::addColumn<bool>("expectedResult"); |
4730 | + |
4731 | + QTest::newRow("identical values") << "1234567" << "1234567" << true; |
4732 | + QTest::newRow("case difference") << "TestId" << "testid" << false; |
4733 | + QTest::newRow("phone prefix") << "1234567" << "1231234567" << true; |
4734 | +} |
4735 | + |
4736 | +void OfonoAccountEntryTest::testCompareIds() |
4737 | +{ |
4738 | + QFETCH(QString, first); |
4739 | + QFETCH(QString, second); |
4740 | + QFETCH(bool, expectedResult); |
4741 | + |
4742 | + QCOMPARE(mAccount->compareIds(first, second), expectedResult); |
4743 | +} |
4744 | + |
4745 | +void OfonoAccountEntryTest::testEmergencyNumbers() |
4746 | +{ |
4747 | + QSignalSpy emergencyNumbersChangedSpy(mAccount, SIGNAL(emergencyNumbersChanged())); |
4748 | + |
4749 | + // check that the list is not empty at startup |
4750 | + QVERIFY(!mAccount->emergencyNumbers().isEmpty()); |
4751 | + |
4752 | + QStringList numbers; |
4753 | + numbers << "111" << "190" << "911"; |
4754 | + qSort(numbers); |
4755 | + mMockController->setEmergencyNumbers(numbers); |
4756 | + QTRY_COMPARE(emergencyNumbersChangedSpy.count(), 1); |
4757 | + |
4758 | + QStringList emergencyNumbers = mAccount->emergencyNumbers(); |
4759 | + qSort(emergencyNumbers); |
4760 | + |
4761 | + QCOMPARE(emergencyNumbers, numbers); |
4762 | +} |
4763 | + |
4764 | +void OfonoAccountEntryTest::testSerial() |
4765 | +{ |
4766 | + QTRY_COMPARE(mAccount->serial(), mMockController->serial()); |
4767 | +} |
4768 | + |
4769 | +void OfonoAccountEntryTest::testVoicemailIndicator() |
4770 | +{ |
4771 | + // voicemail indicator is off by default on the mock CM |
4772 | + QVERIFY(!mAccount->voicemailIndicator()); |
4773 | + |
4774 | + QSignalSpy voiceMailIndicatorSpy(mAccount, SIGNAL(voicemailIndicatorChanged())); |
4775 | + |
4776 | + // set to true |
4777 | + mMockController->setVoicemailIndicator(true); |
4778 | + QTRY_COMPARE(voiceMailIndicatorSpy.count(), 1); |
4779 | + QVERIFY(mAccount->voicemailIndicator()); |
4780 | + |
4781 | + // and set back to false |
4782 | + voiceMailIndicatorSpy.clear(); |
4783 | + mMockController->setVoicemailIndicator(false); |
4784 | + QTRY_COMPARE(voiceMailIndicatorSpy.count(), 1); |
4785 | + QVERIFY(!mAccount->voicemailIndicator()); |
4786 | +} |
4787 | + |
4788 | +void OfonoAccountEntryTest::testVoicemailNumber() |
4789 | +{ |
4790 | + QSignalSpy voicemailNumberSpy(mAccount, SIGNAL(voicemailNumberChanged())); |
4791 | + |
4792 | + // check that the number is not empty at startup |
4793 | + QVERIFY(!mAccount->voicemailNumber().isEmpty()); |
4794 | + |
4795 | + // try changing the number |
4796 | + QString number("12345"); |
4797 | + mMockController->setVoicemailNumber(number); |
4798 | + QTRY_COMPARE(voicemailNumberSpy.count(), 1); |
4799 | + QCOMPARE(mAccount->voicemailNumber(), number); |
4800 | +} |
4801 | + |
4802 | +void OfonoAccountEntryTest::testVoicemailCount() |
4803 | +{ |
4804 | + QSignalSpy voicemailCountSpy(mAccount, SIGNAL(voicemailCountChanged())); |
4805 | + |
4806 | + // check that the count is zero at startup |
4807 | + QCOMPARE((int)mAccount->voicemailCount(), 0); |
4808 | + |
4809 | + // set it to a bigger value |
4810 | + int count = 10; |
4811 | + mMockController->setVoicemailCount(count); |
4812 | + QTRY_COMPARE(voicemailCountSpy.count(), 1); |
4813 | + QCOMPARE((int)mAccount->voicemailCount(), count); |
4814 | + |
4815 | + // and back to zero |
4816 | + voicemailCountSpy.clear(); |
4817 | + mMockController->setVoicemailCount(0); |
4818 | + QTRY_COMPARE(voicemailCountSpy.count(), 1); |
4819 | + QCOMPARE((int)mAccount->voicemailCount(), 0); |
4820 | +} |
4821 | + |
4822 | +void OfonoAccountEntryTest::testSimLocked() |
4823 | +{ |
4824 | + QSignalSpy simLockedSpy(mAccount, SIGNAL(simLockedChanged())); |
4825 | + |
4826 | + // check that it is not locked by default |
4827 | + QVERIFY(!mAccount->simLocked()); |
4828 | + |
4829 | + // now try to set the status to simlocked |
4830 | + mMockController->setPresence("simlocked", "simlocked"); |
4831 | + QTRY_COMPARE(simLockedSpy.count(), 1); |
4832 | + QVERIFY(mAccount->simLocked()); |
4833 | +} |
4834 | + |
4835 | +void OfonoAccountEntryTest::testEmergencyCallsAvailable_data() |
4836 | +{ |
4837 | + QTest::addColumn<QString>("status"); |
4838 | + QTest::addColumn<bool>("available"); |
4839 | + |
4840 | + QTest::newRow("available") << "available" << true; |
4841 | + QTest::newRow("away") << "away" << true; |
4842 | + QTest::newRow("simlocked") << "simlocked" << true; |
4843 | + QTest::newRow("flightmode") << "flightmode" << false; |
4844 | + QTest::newRow("nosim") << "nosim" << true; |
4845 | + QTest::newRow("nomodem") << "nomodem" << false; |
4846 | + QTest::newRow("registered") << "registered" << true; |
4847 | + QTest::newRow("roaming") << "roaming" << true; |
4848 | + QTest::newRow("unregistered") << "unregistered" << true; |
4849 | + QTest::newRow("denied") << "denied" << true; |
4850 | + QTest::newRow("unknown") << "unknown" << true; |
4851 | + QTest::newRow("searching") << "searching" << true; |
4852 | +} |
4853 | + |
4854 | +void OfonoAccountEntryTest::testEmergencyCallsAvailable() |
4855 | +{ |
4856 | + QFETCH(QString, status); |
4857 | + QFETCH(bool, available); |
4858 | + |
4859 | + mMockController->setPresence(status, ""); |
4860 | + QTRY_COMPARE(mAccount->status(), status); |
4861 | + QCOMPARE(mAccount->emergencyCallsAvailable(), available); |
4862 | +} |
4863 | + |
4864 | +void OfonoAccountEntryTest::testNetworkName() |
4865 | +{ |
4866 | + QSignalSpy networkNameChangedSpy(mAccount, SIGNAL(statusMessageChanged())); |
4867 | + |
4868 | + // set the value |
4869 | + QString statusMessage("SomeNetwork"); |
4870 | + Tp::Presence presence(Tp::ConnectionPresenceTypeAvailable, "available", statusMessage); |
4871 | + mTpAccount->setRequestedPresence(presence); |
4872 | + |
4873 | + QTRY_COMPARE(mAccount->networkName(), statusMessage); |
4874 | + QCOMPARE(networkNameChangedSpy.count(), 1); |
4875 | +} |
4876 | + |
4877 | +void OfonoAccountEntryTest::testAddressableVCardFields() |
4878 | +{ |
4879 | + QVERIFY(!mAccount->addressableVCardFields().isEmpty()); |
4880 | + QCOMPARE(mAccount->addressableVCardFields(), mTpAccount->protocolInfo().addressableVCardFields()); |
4881 | +} |
4882 | + |
4883 | +QTEST_MAIN(OfonoAccountEntryTest) |
4884 | +#include "OfonoAccountEntryTest.moc" |
4885 | |
4886 | === added file 'tests/libtelephonyservice/TelepathyHelperTest.cpp' |
4887 | --- tests/libtelephonyservice/TelepathyHelperTest.cpp 1970-01-01 00:00:00 +0000 |
4888 | +++ tests/libtelephonyservice/TelepathyHelperTest.cpp 2015-03-30 20:55:55 +0000 |
4889 | @@ -0,0 +1,286 @@ |
4890 | +/* |
4891 | + * Copyright (C) 2015 Canonical, Ltd. |
4892 | + * |
4893 | + * This file is part of telephony-service. |
4894 | + * |
4895 | + * telephony-service is free software; you can redistribute it and/or modify |
4896 | + * it under the terms of the GNU General Public License as published by |
4897 | + * the Free Software Foundation; version 3. |
4898 | + * |
4899 | + * telephony-service is distributed in the hope that it will be useful, |
4900 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4901 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4902 | + * GNU General Public License for more details. |
4903 | + * |
4904 | + * You should have received a copy of the GNU General Public License |
4905 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4906 | + */ |
4907 | + |
4908 | +#include <QtCore/QObject> |
4909 | +#include <QtTest/QtTest> |
4910 | +#include <TelepathyQt/PendingAccount> |
4911 | +#include <TelepathyQt/PendingOperation> |
4912 | +#include <TelepathyQt/Account> |
4913 | +#include "telepathytest.h" |
4914 | +#include "accountentry.h" |
4915 | +#include "accountentryfactory.h" |
4916 | +#include "telepathyhelper.h" |
4917 | +#include "mockcontroller.h" |
4918 | + |
4919 | +class TelepathyHelperTest : public TelepathyTest |
4920 | +{ |
4921 | + Q_OBJECT |
4922 | + |
4923 | +private Q_SLOTS: |
4924 | + void initTestCase(); |
4925 | + void init(); |
4926 | + void cleanup(); |
4927 | + void testConnected(); |
4928 | + void testAccounts(); |
4929 | + void testAccountSorting(); |
4930 | + void testAccountIds(); |
4931 | + void testActiveAccounts(); |
4932 | + void testAccountForId(); |
4933 | + void testAccountForConnection(); |
4934 | + void testEmergencyCallsAvailable(); |
4935 | + |
4936 | +private: |
4937 | + Tp::AccountPtr mGenericTpAccount; |
4938 | + Tp::AccountPtr mPhoneTpAccount; |
4939 | + MockController *mGenericController; |
4940 | + MockController *mPhoneController; |
4941 | +}; |
4942 | + |
4943 | +void TelepathyHelperTest::initTestCase() |
4944 | +{ |
4945 | + initialize(); |
4946 | +} |
4947 | + |
4948 | +void TelepathyHelperTest::init() |
4949 | +{ |
4950 | + // add two accounts |
4951 | + mGenericTpAccount = addAccount("mock", "mock", "the generic account"); |
4952 | + QTRY_VERIFY(!mGenericTpAccount->connection().isNull()); |
4953 | + |
4954 | + mPhoneTpAccount = addAccount("mock", "ofono", "the phone account"); |
4955 | + QTRY_VERIFY(!mPhoneTpAccount->connection().isNull()); |
4956 | + |
4957 | + // and create the mock controller |
4958 | + mGenericController = new MockController("mock", this); |
4959 | + mPhoneController = new MockController("ofono", this); |
4960 | +} |
4961 | + |
4962 | +void TelepathyHelperTest::cleanup() |
4963 | +{ |
4964 | + // the accounts are removed in the parent class. |
4965 | + doCleanup(); |
4966 | + |
4967 | + mGenericController->deleteLater(); |
4968 | + mPhoneController->deleteLater(); |
4969 | +} |
4970 | + |
4971 | +void TelepathyHelperTest::testConnected() |
4972 | +{ |
4973 | + QSignalSpy connectedChangedSpy(TelepathyHelper::instance(), SIGNAL(connectedChanged())); |
4974 | + |
4975 | + // check that the default status is connected (always true for mock accounts) |
4976 | + QVERIFY(TelepathyHelper::instance()->connected()); |
4977 | + |
4978 | + // set one of the accounts offline and check that the connected status stays true |
4979 | + mGenericController->setOnline(false); |
4980 | + QTest::qWait(1000); |
4981 | + QCOMPARE(connectedChangedSpy.count(), 0); |
4982 | + QVERIFY(TelepathyHelper::instance()->connected()); |
4983 | + |
4984 | + // and set the other account as offline too. This time connected needs to change to false |
4985 | + mPhoneController->setOnline(false); |
4986 | + QTRY_COMPARE(connectedChangedSpy.count(), 1); |
4987 | + QVERIFY(!TelepathyHelper::instance()->connected()); |
4988 | + |
4989 | + // now set one of the accounts back online |
4990 | + connectedChangedSpy.clear(); |
4991 | + mPhoneController->setOnline(true); |
4992 | + QTRY_COMPARE(connectedChangedSpy.count(), 1); |
4993 | + QVERIFY(TelepathyHelper::instance()->connected()); |
4994 | + |
4995 | + // and the other one just in case |
4996 | + connectedChangedSpy.clear(); |
4997 | + mGenericController->setOnline(true); |
4998 | + QTest::qWait(1000); |
4999 | + QCOMPARE(connectedChangedSpy.count(), 0); |
5000 | + QVERIFY(TelepathyHelper::instance()->connected()); |
FAILED: Continuous integration, rev:1043 jenkins. qa.ubuntu. com/job/ telephony- service- ci/377/ jenkins. qa.ubuntu. com/job/ telephony- service- vivid-amd64- ci/45/console jenkins. qa.ubuntu. com/job/ telephony- service- vivid-armhf- ci/45/console jenkins. qa.ubuntu. com/job/ telephony- service- vivid-i386- ci/45/console
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/telephony- service- ci/377/ rebuild
http://