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

Proposed by Gustavo Pichorim Boiko
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
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://code.launchpad.net/~boiko/telephony-service/support_non_phone_accounts/+merge/251796

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

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

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

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

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

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

To post a comment you must log in.
1043. By Gustavo Pichorim Boiko

Revert pot file changes.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1044. By Gustavo Pichorim Boiko

Test the custom interfaces used for the telephony stuff (voicemail, emergency numbers and serial)

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
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.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
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.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1053. By Gustavo Pichorim Boiko

Merge latest changes from parent branch.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1054. By Gustavo Pichorim Boiko

Launch the tests using xvfb-run.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
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.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1056. By Gustavo Pichorim Boiko

Add some waiting time to prevent races.

1057. By Gustavo Pichorim Boiko

Clear the temporary directory every time.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
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.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1061. By Gustavo Pichorim Boiko

Add more debugging to figure out what is going on.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1062. By Gustavo Pichorim Boiko

Merge latest changes from parent branch.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1063. By Gustavo Pichorim Boiko

Increase some timeouts in a hope they fix the tests.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
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.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
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.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1069. By Gustavo Pichorim Boiko

Some more stability fixes.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1070. By Gustavo Pichorim Boiko

Remove dbus monitor.

1071. By Gustavo Pichorim Boiko

Merge latest changes from parent branch.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1072. By Gustavo Pichorim Boiko

Output test results both in xunitxml and stdout plain text.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
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.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Tiago Salem Herrmann (tiagosh) :
review: Needs Fixing
Revision history for this message
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.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
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.

Revision history for this message
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

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '.bzrignore'
--- .bzrignore 2014-01-07 19:53:45 +0000
+++ .bzrignore 2015-03-30 20:55:55 +0000
@@ -32,19 +32,22 @@
32handler/handleradaptor.*32handler/handleradaptor.*
33indicator/*.desktop33indicator/*.desktop
34indicator/*.service34indicator/*.service
35indicator/NotificationsInterface.*
3536
36Testing37Testing
37Ubuntu/Telephony/tests/*Test
38Ubuntu/Telephony/qmldir38Ubuntu/Telephony/qmldir
39libtelephonyservice/tests/*Test
40CTestTestfile.cmake39CTestTestfile.cmake
41test_*.xml40test_*.xml
41cmake_uninstall.cmake
4242
43coverage*43coverage*
4444
45po/*.gmo45po/*.gmo
4646
47handler/tests/HandlerTest47tests/*/*Test
48handler/tests/dbus-test-wrapper.sh48tests/common/dbus-test-wrapper.sh
49handler/tests/mock/mockconnectionadaptor.*49tests/common/mock/mockconnectionadaptor.*
50handler/tests/mock/telepathy-mock50tests/common/mock/telepathy-mock
51tests/Ubuntu.Telephony/ContactWatcherTest
52tests/libtelephonyservice/GreeterContactsTestExe
53tests/libtelephonyservice/GreeterContactsTestServerExe
5154
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2014-08-05 20:04:00 +0000
+++ CMakeLists.txt 2015-03-30 20:55:55 +0000
@@ -9,23 +9,6 @@
9include(CheckIncludeFileCXX)9include(CheckIncludeFileCXX)
10include(CheckIncludeFile)10include(CheckIncludeFile)
1111
12include(EnableCoverageReport)
13#####################################################################
14# Enable code coverage calculation with gcov/gcovr/lcov
15# Usage:
16# * Switch build type to coverage (use ccmake or cmake-gui)
17# * Invoke make, make test, make coverage
18# * Find html report in subdir coveragereport
19# * Find xml report feasible for jenkins in coverage.xml
20#####################################################################
21IF(CMAKE_BUILD_TYPE MATCHES [cC][oO][vV][eE][rR][aA][gG][eE])
22 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftest-coverage -fprofile-arcs" )
23 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftest-coverage -fprofile-arcs" )
24 SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -coverage" )
25 SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -coverage" )
26 ENABLE_COVERAGE_REPORT(TARGETS ${PHONE_APP})
27ENDIF(CMAKE_BUILD_TYPE MATCHES [cC][oO][vV][eE][rR][aA][gG][eE])
28
29# Instruct CMake to run moc automatically when needed.12# Instruct CMake to run moc automatically when needed.
30set(CMAKE_AUTOMOC ON)13set(CMAKE_AUTOMOC ON)
3114
@@ -36,8 +19,6 @@
36 add_definitions(-DUSE_UBUNTU_PLATFORM_API)19 add_definitions(-DUSE_UBUNTU_PLATFORM_API)
37endif (USE_UBUNTU_PLATFORM_API)20endif (USE_UBUNTU_PLATFORM_API)
3821
39find_program(DBUS_RUNNER dbus-test-runner)
40
41set(TELEPHONY_SERVICE_DIR ${CMAKE_INSTALL_DATADIR}/telephony-service)22set(TELEPHONY_SERVICE_DIR ${CMAKE_INSTALL_DATADIR}/telephony-service)
4223
43configure_file(config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h @ONLY)24configure_file(config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h @ONLY)
@@ -81,6 +62,14 @@
81 ${CMAKE_CURRENT_SOURCE_DIR}62 ${CMAKE_CURRENT_SOURCE_DIR}
82 )63 )
8364
65# generate a macro to make it easier to enable coverage support on targets
66function(ENABLE_COVERAGE)
67 get_directory_property(COVERAGE_TARGETS DIRECTORY ${CMAKE_SOURCE_DIR} COVERAGE_TARGETS)
68 list(APPEND COVERAGE_TARGETS ${ARGN})
69 MESSAGE(STATUS "Enabling coverage report for target(s): ${ARGN}")
70 set_property(DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY COVERAGE_TARGETS ${COVERAGE_TARGETS})
71endfunction()
72
84enable_testing()73enable_testing()
8574
86add_definitions(-std=c++11)75add_definitions(-std=c++11)
@@ -98,3 +87,24 @@
98add_subdirectory(tools)87add_subdirectory(tools)
99add_subdirectory(icons)88add_subdirectory(icons)
100add_subdirectory(po)89add_subdirectory(po)
90add_subdirectory(tests)
91
92include(EnableCoverageReport)
93#####################################################################
94# Enable code coverage calculation with gcov/gcovr/lcov
95# Usage:
96# * Switch build type to coverage (use ccmake or cmake-gui)
97# * Invoke make, make test, make coverage
98# * Find html report in subdir coveragereport
99# * Find xml report feasible for jenkins in coverage.xml
100#####################################################################
101IF(CMAKE_BUILD_TYPE MATCHES [cC][oO][vV][eE][rR][aA][gG][eE])
102 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftest-coverage -fprofile-arcs" )
103 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftest-coverage -fprofile-arcs" )
104 SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -coverage" )
105 SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -coverage" )
106 GET_DIRECTORY_PROPERTY(COVERAGE_TARGETS DIRECTORY ${CMAKE_SOURCE_DIR} COVERAGE_TARGETS)
107 ENABLE_COVERAGE_REPORT(TARGETS ${COVERAGE_TARGETS})
108ENDIF(CMAKE_BUILD_TYPE MATCHES [cC][oO][vV][eE][rR][aA][gG][eE])
109
110
101111
=== modified file 'Ubuntu/Telephony/CMakeLists.txt'
--- Ubuntu/Telephony/CMakeLists.txt 2014-04-23 20:55:13 +0000
+++ Ubuntu/Telephony/CMakeLists.txt 2015-03-30 20:55:55 +0000
@@ -19,10 +19,11 @@
19 telephonyservice19 telephonyservice
20 )20 )
2121
22enable_coverage(telephonyservice-qml)
23
22configure_file(qmldir.in ${CMAKE_CURRENT_BINARY_DIR}/qmldir)24configure_file(qmldir.in ${CMAKE_CURRENT_BINARY_DIR}/qmldir)
23set(PLUGIN_DIR ${QT_INSTALL_QML}/Ubuntu/Telephony)25set(PLUGIN_DIR ${QT_INSTALL_QML}/Ubuntu/Telephony)
24install(TARGETS telephonyservice-qml DESTINATION ${PLUGIN_DIR})26install(TARGETS telephonyservice-qml DESTINATION ${PLUGIN_DIR})
25install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qmldir DESTINATION ${PLUGIN_DIR})27install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qmldir DESTINATION ${PLUGIN_DIR})
2628
27add_subdirectory(PhoneNumber)29add_subdirectory(PhoneNumber)
28add_subdirectory(tests)
2930
=== modified file 'Ubuntu/Telephony/contactwatcher.cpp'
--- Ubuntu/Telephony/contactwatcher.cpp 2015-03-30 20:55:55 +0000
+++ Ubuntu/Telephony/contactwatcher.cpp 2015-03-30 20:55:55 +0000
@@ -219,6 +219,10 @@
219void ContactWatcher::setAddressableFields(const QStringList &fields)219void ContactWatcher::setAddressableFields(const QStringList &fields)
220{220{
221 mAddressableFields = fields;221 mAddressableFields = fields;
222 // if the addressable fields is empty, fall back to matching phone numbers
223 if (mAddressableFields.isEmpty()) {
224 mAddressableFields << "tel";
225 }
222 Q_EMIT addressableFieldsChanged();226 Q_EMIT addressableFieldsChanged();
223227
224 startSearching();228 startSearching();
225229
=== modified file 'approver/CMakeLists.txt'
--- approver/CMakeLists.txt 2014-07-06 16:19:49 +0000
+++ approver/CMakeLists.txt 2015-03-30 20:55:55 +0000
@@ -25,6 +25,8 @@
25 telephonyservice25 telephonyservice
26 )26 )
2727
28enable_coverage(telephony-service-approver)
29
28configure_file(org.freedesktop.Telepathy.Client.TelephonyServiceApprover.service.in org.freedesktop.Telepathy.Client.TelephonyServiceApprover.service)30configure_file(org.freedesktop.Telepathy.Client.TelephonyServiceApprover.service.in org.freedesktop.Telepathy.Client.TelephonyServiceApprover.service)
29install(TARGETS telephony-service-approver RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})31install(TARGETS telephony-service-approver RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
30install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.freedesktop.Telepathy.Client.TelephonyServiceApprover.service DESTINATION share/dbus-1/services)32install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.freedesktop.Telepathy.Client.TelephonyServiceApprover.service DESTINATION share/dbus-1/services)
3133
=== added file 'cmake/modules/GenerateTest.cmake'
--- cmake/modules/GenerateTest.cmake 1970-01-01 00:00:00 +0000
+++ cmake/modules/GenerateTest.cmake 2015-03-30 20:55:55 +0000
@@ -0,0 +1,133 @@
1#
2# Copyright (C) 2015 Canonical, Ltd.
3#
4# Authors:
5# Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>
6#
7# This file is part of telephony-service.
8#
9# telephony-service is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation; version 3.
12#
13# telephony-service is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21
22include(CMakeParseArguments)
23find_program(DBUS_RUNNER dbus-test-runner)
24
25function(generate_test TESTNAME)
26 set(options USE_DBUS USE_UI)
27 set(oneValueArgs TIMEOUT WORKING_DIRECTORY QML_TEST WAIT_FOR)
28 set(multiValueArgs TASKS LIBRARIES QT5_MODULES SOURCES ENVIRONMENT)
29 cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
30
31 MESSAGE(STATUS "Adding test: ${TESTNAME}")
32
33 # set reasonable defaults for the arguments
34 if (NOT DEFINED ARG_WORKING_DIRECTORY)
35 set(ARG_WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
36 endif ()
37
38 if (NOT DEFINED ARG_TIMEOUT)
39 set(ARG_TIMEOUT 60)
40 endif ()
41
42 if (NOT DEFINED ARG_QT5_MODULES)
43 set(ARG_QT5_MODULES Core Test)
44 endif ()
45
46 if (${ARG_USE_UI})
47 if (${ARG_USE_DBUS})
48 set(PLATFORM -p -platform -p offscreen)
49 else ()
50 set(PLATFORM -platform offscreen)
51 endif ()
52 endif()
53
54 # Generate QML tests
55 if (DEFINED ARG_QML_TEST)
56 add_test(NAME ${TESTNAME}
57 WORKING_DIRECTORY ${ARG_WORKING_DIRECTORY}
58 COMMAND qmltestrunner -platform offscreen -import ${CMAKE_BINARY_DIR} -input ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_QML_TEST})
59 set_tests_properties(${TESTNAME} PROPERTIES ENVIRONMENT "QT_QPA_FONTDIR=${CMAKE_BINARY_DIR}")
60 else ()
61 # For sanity checking, make sure DBUS_RUNNER is available for DBUS tests
62 if (${ARG_USE_DBUS} AND "${DBUS_RUNNER}" STREQUAL "")
63 message(WARNING "Test ${TESTNAME} disabled because dbus-test-runner was not found.")
64 return()
65 endif ()
66
67 # No QML test, regular binary compiled test.
68 add_executable(${TESTNAME} ${ARG_SOURCES})
69 qt5_use_modules(${TESTNAME} ${ARG_QT5_MODULES})
70
71 if (${ARG_USE_DBUS})
72 execute_process(COMMAND mktemp -d OUTPUT_VARIABLE TMPDIR)
73 string(REPLACE "\n" "" TMPDIR ${TMPDIR})
74
75 if (NOT DEFINED ARG_ENVIRONMENT)
76 set(ARG_ENVIRONMENT HOME=${TMPDIR}
77 HISTORY_SQLITE_DBPATH=:memory:
78 MC_ACCOUNT_DIR=${TMPDIR}
79 MC_MANAGER_DIR=${TMPDIR})
80 endif ()
81
82 set(TEST_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME} ${PLATFORM} -p -o -p -,txt -p -o -p ${CMAKE_BINARY_DIR}/test_${TESTNAME}.xml,xunitxml)
83 if (DEFINED ARG_WAIT_FOR)
84 SET(TEST_COMMAND ${TEST_COMMAND} --wait-for ${ARG_WAIT_FOR})
85 endif ()
86
87 add_test(${TESTNAME} ${DBUS_RUNNER} --keep-env --dbus-config=${CMAKE_BINARY_DIR}/tests/common/dbus-session.conf --max-wait=${ARG_TIMEOUT}
88 ${ARG_TASKS} --task ${TEST_COMMAND} --task-name ${TESTNAME})
89 else ()
90 add_test(${TESTNAME} ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME} ${PLATFORM} -o -,txt -o ${CMAKE_BINARY_DIR}/test_${TESTNAME}.xml,xunitxml)
91 endif()
92
93 set_tests_properties(${TESTNAME} PROPERTIES
94 ENVIRONMENT "${ARG_ENVIRONMENT}"
95 TIMEOUT ${ARG_TIMEOUT})
96 if (DEFINED ARG_LIBRARIES)
97 target_link_libraries(${TESTNAME}
98 ${ARG_LIBRARIES})
99 endif ()
100
101 enable_coverage(${TESTNAME})
102 endif ()
103endfunction(generate_test)
104
105function(generate_telepathy_test TESTNAME)
106 set(options "")
107 set(oneValueArgs "")
108 set(multiValueArgs TASKS LIBRARIES QT5_MODULES)
109 cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
110
111 set(TASKS --task gnome-keyring-daemon -p -r -p -d --task-name gnome-keyring --ignore-return
112 --task /usr/lib/dconf/dconf-service --task-name dconf-service --ignore-return
113 --task dconf -p write -p /org/gnome/empathy/use-conn -p false --task-name dconf-write --wait-for ca.desrt.dconf --ignore-return
114 --task /usr/lib/telepathy/mission-control-5 --task-name mission-control --wait-for ca.desrt.dconf --ignore-return
115 --task ${CMAKE_BINARY_DIR}/tests/common/mock/telepathy-mock --task-name telepathy-mock --wait-for org.freedesktop.Telepathy.MissionControl5 --ignore-return
116 # FIXME: maybe it would be better to decide whether to run the handler in a per-test basis?
117 --task ${CMAKE_BINARY_DIR}/handler/telephony-service-handler --task-name telephony-service-handler --wait-for org.freedesktop.Telepathy.ConnectionManager.mock --ignore-return
118 ${ARG_TASKS})
119
120 if (NOT DEFINED ARG_LIBRARIES)
121 set(ARG_LIBRARIES ${TP_QT5_LIBRARIES} telephonyservice mockcontroller telepathytest)
122 endif(NOT DEFINED ARG_LIBRARIES)
123
124 if (NOT DEFINED ARG_QT5_MODULES)
125 set(ARG_QT5_MODULES Core DBus Test Qml)
126 endif (NOT DEFINED ARG_QT5_MODULES)
127 generate_test(${TESTNAME} ${ARGN}
128 TASKS ${TASKS}
129 LIBRARIES ${ARG_LIBRARIES}
130 QT5_MODULES ${ARG_QT5_MODULES}
131 USE_DBUS USE_UI
132 WAIT_FOR org.freedesktop.Telepathy.Client.TelephonyServiceHandler)
133endfunction(generate_telepathy_test)
0134
=== modified file 'handler/CMakeLists.txt'
--- handler/CMakeLists.txt 2014-08-05 20:04:00 +0000
+++ handler/CMakeLists.txt 2015-03-30 20:55:55 +0000
@@ -26,6 +26,8 @@
26 telephonyservice26 telephonyservice
27 )27 )
2828
29enable_coverage(telephony-service-handler)
30
29configure_file(com.canonical.TelephonyServiceHandler.service.in com.canonical.TelephonyServiceHandler.service)31configure_file(com.canonical.TelephonyServiceHandler.service.in com.canonical.TelephonyServiceHandler.service)
30configure_file(org.freedesktop.Telepathy.Client.TelephonyServiceHandler.service.in org.freedesktop.Telepathy.Client.TelephonyServiceHandler.service)32configure_file(org.freedesktop.Telepathy.Client.TelephonyServiceHandler.service.in org.freedesktop.Telepathy.Client.TelephonyServiceHandler.service)
3133
@@ -33,9 +35,3 @@
33install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.freedesktop.Telepathy.Client.TelephonyServiceHandler.service DESTINATION share/dbus-1/services)35install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.freedesktop.Telepathy.Client.TelephonyServiceHandler.service DESTINATION share/dbus-1/services)
34install(FILES ${CMAKE_CURRENT_BINARY_DIR}/com.canonical.TelephonyServiceHandler.service DESTINATION share/dbus-1/services)36install(FILES ${CMAKE_CURRENT_BINARY_DIR}/com.canonical.TelephonyServiceHandler.service DESTINATION share/dbus-1/services)
35install(FILES TelephonyServiceHandler.client DESTINATION share/telepathy/clients)37install(FILES TelephonyServiceHandler.client DESTINATION share/telepathy/clients)
36
37if(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc*")
38 message(STATUS "Tests disabled on ppc")
39else()
40 add_subdirectory(tests)
41endif()
4238
=== modified file 'handler/handler.cpp'
--- handler/handler.cpp 2015-02-09 20:32:32 +0000
+++ handler/handler.cpp 2015-03-30 20:55:55 +0000
@@ -97,6 +97,7 @@
97 specList << TelepathyHelper::audioConferenceSpec();97 specList << TelepathyHelper::audioConferenceSpec();
98 specList << Tp::ChannelClassSpec::audioCall();98 specList << Tp::ChannelClassSpec::audioCall();
99 specList << Tp::ChannelClassSpec::textChat();99 specList << Tp::ChannelClassSpec::textChat();
100 specList << Tp::ChannelClassSpec::unnamedTextChat();
100101
101 return specList;102 return specList;
102}103}
103104
=== removed file 'handler/tests/dbus-test-wrapper.sh.in'
--- handler/tests/dbus-test-wrapper.sh.in 2014-03-27 13:26:31 +0000
+++ handler/tests/dbus-test-wrapper.sh.in 1970-01-01 00:00:00 +0000
@@ -1,35 +0,0 @@
1#!/bin/sh -x
2
3# export the home folder to somewhere in /tmp
4TMPDIR=/tmp/telephony_service_test_home
5rm -rf $TMPDIR
6mkdir -p $TMPDIR
7export HOME=$TMPDIR
8
9# now run gnome-keyring
10gnome-keyring-daemon -r -d
11
12# we need to set this otherwise mission-control doesn't work properly
13dconf write /org/gnome/empathy/use-conn false
14
15# start the mock connection manager
16@CMAKE_CURRENT_BINARY_DIR@/mock/telepathy-mock &
17MOCK_PID=$!
18
19# wait 1 sec for the mock to start up
20sleep 1
21
22mc-tool add mock/mock account0
23
24@CMAKE_CURRENT_BINARY_DIR@/../telephony-service-handler &
25
26HANDLER_PID=$!
27
28$@
29RESULT=$?
30
31# FIXME: check the variables and things that should not be started
32kill -9 $HANDLER_PID
33kill -9 $MOCK_PID
34
35return $RESULT
360
=== removed file 'handler/tests/telepathyhelper.cpp'
--- handler/tests/telepathyhelper.cpp 2014-01-07 19:53:45 +0000
+++ handler/tests/telepathyhelper.cpp 1970-01-01 00:00:00 +0000
@@ -1,279 +0,0 @@
1/**
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Tiago Salem Herrmann <tiago.herrmann@canonical.com>
18 * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>
19 */
20
21#include "telepathyhelper.h"
22#include <TelepathyQt/AbstractClient>
23#include <TelepathyQt/AccountSet>
24#include <TelepathyQt/ClientRegistrar>
25#include <TelepathyQt/PendingReady>
26#include <TelepathyQt/PendingAccount>
27
28TelepathyHelper::TelepathyHelper(QObject *parent)
29 : QObject(parent),
30 //mChannelObserver(0),
31 mFirstTime(true),
32 mConnected(false),
33 mHandlerInterface(0)
34{
35 Tp::registerTypes();
36
37 mAccountFeatures << Tp::Account::FeatureCore;
38 mContactFeatures << Tp::Contact::FeatureAlias
39 << Tp::Contact::FeatureAvatarData
40 << Tp::Contact::FeatureAvatarToken
41 << Tp::Contact::FeatureCapabilities
42 << Tp::Contact::FeatureSimplePresence;
43 mConnectionFeatures << Tp::Connection::FeatureCore
44 << Tp::Connection::FeatureSelfContact
45 << Tp::Connection::FeatureSimplePresence;
46
47 Tp::ChannelFactoryPtr channelFactory = Tp::ChannelFactory::create(QDBusConnection::sessionBus());
48 channelFactory->addCommonFeatures(Tp::Channel::FeatureCore);
49
50 mAccountManager = Tp::AccountManager::create(
51 Tp::AccountFactory::create(QDBusConnection::sessionBus(), mAccountFeatures),
52 Tp::ConnectionFactory::create(QDBusConnection::sessionBus(), mConnectionFeatures),
53 channelFactory,
54 Tp::ContactFactory::create(mContactFeatures));
55
56 connect(mAccountManager->becomeReady(Tp::AccountManager::FeatureCore),
57 SIGNAL(finished(Tp::PendingOperation*)),
58 SLOT(onAccountManagerReady(Tp::PendingOperation*)));
59
60 mClientRegistrar = Tp::ClientRegistrar::create(mAccountManager);
61}
62
63TelepathyHelper::~TelepathyHelper()
64{
65}
66
67TelepathyHelper *TelepathyHelper::instance()
68{
69 static TelepathyHelper* helper = new TelepathyHelper();
70 return helper;
71}
72
73QString TelepathyHelper::accountId() const
74{
75 if (mAccount) {
76 return mAccount->uniqueIdentifier();
77 }
78 return QString();
79}
80
81Tp::AccountPtr TelepathyHelper::account() const
82{
83 return mAccount;
84}
85
86/*
87ChannelObserver *TelepathyHelper::channelObserver() const
88{
89 return mChannelObserver;
90}
91*/
92
93bool TelepathyHelper::connected() const
94{
95 return mConnected;
96}
97
98/*
99void TelepathyHelper::registerChannelObserver(const QString &observerName)
100{
101 QString name = observerName;
102
103 if (name.isEmpty()) {
104 name = "TelephonyPluginObserver";
105 }
106
107 if (mChannelObserver) {
108 mChannelObserver->deleteLater();
109 }
110
111 mChannelObserver = new ChannelObserver(this);
112 registerClient(mChannelObserver, name);
113
114 // messages
115 connect(mChannelObserver, SIGNAL(textChannelAvailable(Tp::TextChannelPtr)),
116 ChatManager::instance(), SLOT(onTextChannelAvailable(Tp::TextChannelPtr)));
117
118 // calls
119 connect(mChannelObserver, SIGNAL(callChannelAvailable(Tp::CallChannelPtr)),
120 CallManager::instance(), SLOT(onCallChannelAvailable(Tp::CallChannelPtr)));
121
122 Q_EMIT channelObserverCreated(mChannelObserver);
123}
124
125void TelepathyHelper::unregisterChannelObserver()
126{
127 Tp::AbstractClientPtr clientPtr(mChannelObserver);
128 if (clientPtr) {
129 mClientRegistrar->unregisterClient(clientPtr);
130 }
131 mChannelObserver->deleteLater();
132 mChannelObserver = NULL;
133 Q_EMIT channelObserverUnregistered();
134}
135*/
136
137QStringList TelepathyHelper::supportedProtocols() const
138{
139 QStringList protocols;
140 protocols << "mock";
141 return protocols;
142}
143
144void TelepathyHelper::initializeAccount()
145{
146 // watch for account state and connection changes
147 connect(mAccount.data(),
148 SIGNAL(stateChanged(bool)),
149 SLOT(onAccountStateChanged(bool)));
150 connect(mAccount.data(),
151 SIGNAL(connectionChanged(const Tp::ConnectionPtr&)),
152 SLOT(onAccountConnectionChanged(const Tp::ConnectionPtr&)));
153
154 // and make sure it is enabled and connected
155 if (!mAccount->isEnabled()) {
156 ensureAccountEnabled();
157 } else {
158 ensureAccountConnected();
159 }
160}
161
162void TelepathyHelper::ensureAccountEnabled()
163{
164 mAccount->setConnectsAutomatically(true);
165 connect(mAccount->setEnabled(true),
166 SIGNAL(finished(Tp::PendingOperation*)),
167 SLOT(onAccountEnabled(Tp::PendingOperation*)));
168}
169
170void TelepathyHelper::ensureAccountConnected()
171{
172 // if the account is not connected, request it to connect
173 if (!mAccount->connection() || mAccount->connectionStatus() != Tp::ConnectionStatusConnected) {
174 Tp::Presence presence(Tp::ConnectionPresenceTypeAvailable, "available", "online");
175 mAccount->setRequestedPresence(presence);
176 } else {
177 watchSelfContactPresence();
178 }
179
180 if (mFirstTime) {
181 Q_EMIT accountReady();
182 mFirstTime = false;
183 }
184}
185
186void TelepathyHelper::watchSelfContactPresence()
187{
188 if (mAccount.isNull() || mAccount->connection().isNull()) {
189 return;
190 }
191
192 connect(mAccount->connection()->selfContact().data(),
193 SIGNAL(presenceChanged(Tp::Presence)),
194 SLOT(onPresenceChanged(Tp::Presence)));
195 onPresenceChanged(mAccount->connection()->selfContact()->presence());
196}
197
198void TelepathyHelper::registerClient(Tp::AbstractClient *client, QString name)
199{
200 Tp::AbstractClientPtr clientPtr(client);
201 bool succeeded = mClientRegistrar->registerClient(clientPtr, name);
202 if (!succeeded) {
203 name.append("%1");
204 int count = 0;
205 // limit the number of registered clients to 20, that should be a safe margin
206 while (!succeeded && count < 20) {
207 succeeded = mClientRegistrar->registerClient(clientPtr, name.arg(++count));
208 if (succeeded) {
209 name = name.arg(count);
210 }
211 }
212 }
213
214 if (succeeded) {
215 QObject *object = dynamic_cast<QObject*>(client);
216 if (object) {
217 object->setProperty("clientName", TP_QT_IFACE_CLIENT + "." + name );
218 }
219 }
220}
221
222void TelepathyHelper::onAccountManagerReady(Tp::PendingOperation *op)
223{
224 Q_UNUSED(op)
225
226 Tp::AccountSetPtr accountSet;
227 // try to find an account of the one of supported protocols
228 Q_FOREACH(const QString &protocol, supportedProtocols()) {
229 accountSet = mAccountManager->accountsByProtocol(protocol);
230 if (accountSet->accounts().count() > 0) {
231 break;
232 }
233 }
234
235 if (accountSet->accounts().count() == 0) {
236 qCritical() << "No compatible telepathy account found!";
237 return;
238 }
239
240 mAccount = accountSet->accounts()[0];
241
242 // in case we have more than one account, the first one to show on the list is going to be used
243 if (accountSet->accounts().count() > 1) {
244 qWarning() << "There are more than just one account of type" << mAccount->protocolName();
245 }
246
247 Q_EMIT accountIdChanged();
248
249 initializeAccount();
250}
251
252void TelepathyHelper::onAccountEnabled(Tp::PendingOperation *op)
253{
254 // we might need to do more stuff once the account is enabled, but making sure it is connected is a good start
255 ensureAccountConnected();
256}
257
258void TelepathyHelper::onAccountStateChanged(bool enabled)
259{
260 if (!enabled) {
261 ensureAccountEnabled();
262 }
263}
264
265void TelepathyHelper::onAccountConnectionChanged(const Tp::ConnectionPtr &connection)
266{
267 if (connection.isNull()) {
268 ensureAccountConnected();
269 } else {
270 watchSelfContactPresence();
271 }
272 Q_EMIT connectionChanged();
273}
274
275void TelepathyHelper::onPresenceChanged(const Tp::Presence &presence)
276{
277 mConnected = (presence.type() == Tp::ConnectionPresenceTypeAvailable);
278 Q_EMIT connectedChanged();
279}
2800
=== removed file 'handler/tests/telepathyhelper.h'
--- handler/tests/telepathyhelper.h 2014-06-27 17:45:58 +0000
+++ handler/tests/telepathyhelper.h 1970-01-01 00:00:00 +0000
@@ -1,95 +0,0 @@
1/**
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Tiago Salem Herrmann <tiago.herrmann@canonical.com>
18 * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>
19 */
20
21#ifndef TELEPATHYHELPER_H
22#define TELEPATHYHELPER_H
23
24#include <QObject>
25#include <TelepathyQt/AccountManager>
26#include <TelepathyQt/Contact>
27#include <TelepathyQt/Connection>
28#include <TelepathyQt/ConnectionManager>
29#include <TelepathyQt/Types>
30//#include "channelobserver.h"
31
32#define CANONICAL_TELEPHONY_VOICEMAIL_IFACE "com.canonical.Telephony.Voicemail"
33#define CANONICAL_TELEPHONY_SPEAKER_IFACE "com.canonical.Telephony.Speaker"
34#define CANONICAL_TELEPHONY_EMERGENCYMODE_IFACE "com.canonical.Telephony.EmergencyMode"
35
36class TelepathyHelper : public QObject
37{
38 Q_OBJECT
39 Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
40 Q_PROPERTY(QString accountId READ accountId NOTIFY accountIdChanged)
41
42public:
43 ~TelepathyHelper();
44
45 static TelepathyHelper *instance();
46 Tp::AccountPtr account() const;
47 //ChannelObserver *channelObserver() const;
48
49 bool connected() const;
50 QString accountId() const;
51
52 void registerClient(Tp::AbstractClient *client, QString name);
53
54Q_SIGNALS:
55 //void channelObserverCreated(ChannelObserver *observer);
56 //void channelObserverUnregistered();
57 void accountReady();
58 void connectionChanged();
59 void connectedChanged();
60 void accountIdChanged();
61
62public Q_SLOTS:
63 //Q_INVOKABLE void registerChannelObserver(const QString &observerName = QString::null);
64 //Q_INVOKABLE void unregisterChannelObserver();
65
66protected:
67 QStringList supportedProtocols() const;
68 void initializeAccount();
69 void ensureAccountEnabled();
70 void ensureAccountConnected();
71 void watchSelfContactPresence();
72
73private Q_SLOTS:
74 void onAccountManagerReady(Tp::PendingOperation *op);
75 void onAccountEnabled(Tp::PendingOperation *op);
76 void onAccountStateChanged(bool enabled);
77 void onAccountConnectionChanged(const Tp::ConnectionPtr &connection);
78 void onPresenceChanged(const Tp::Presence &presence);
79
80private:
81 explicit TelepathyHelper(QObject *parent = 0);
82 Tp::AccountManagerPtr mAccountManager;
83 Tp::Features mAccountManagerFeatures;
84 Tp::Features mAccountFeatures;
85 Tp::Features mContactFeatures;
86 Tp::Features mConnectionFeatures;
87 Tp::ClientRegistrarPtr mClientRegistrar;
88 Tp::AccountPtr mAccount;
89 //ChannelObserver *mChannelObserver;
90 bool mFirstTime;
91 bool mConnected;
92 QDBusInterface *mHandlerInterface;
93};
94
95#endif // TELEPATHYHELPER_H
960
=== modified file 'indicator/CMakeLists.txt'
--- indicator/CMakeLists.txt 2014-04-07 19:21:14 +0000
+++ indicator/CMakeLists.txt 2015-03-30 20:55:55 +0000
@@ -47,6 +47,8 @@
47 telephonyservice47 telephonyservice
48 )48 )
4949
50enable_coverage(telephony-service-indicator)
51
50configure_file(org.freedesktop.Telepathy.Client.TelephonyServiceIndicator.service.in org.freedesktop.Telepathy.Client.TelephonyServiceIndicator.service)52configure_file(org.freedesktop.Telepathy.Client.TelephonyServiceIndicator.service.in org.freedesktop.Telepathy.Client.TelephonyServiceIndicator.service)
51install(TARGETS telephony-service-indicator RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})53install(TARGETS telephony-service-indicator RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
52install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.freedesktop.Telepathy.Client.TelephonyServiceIndicator.service DESTINATION share/dbus-1/services)54install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.freedesktop.Telepathy.Client.TelephonyServiceIndicator.service DESTINATION share/dbus-1/services)
5355
=== modified file 'libtelephonyservice/CMakeLists.txt'
--- libtelephonyservice/CMakeLists.txt 2015-03-30 20:55:55 +0000
+++ libtelephonyservice/CMakeLists.txt 2015-03-30 20:55:55 +0000
@@ -38,4 +38,4 @@
3838
39qt5_use_modules(telephonyservice Contacts Core DBus Feedback Multimedia Qml Quick)39qt5_use_modules(telephonyservice Contacts Core DBus Feedback Multimedia Qml Quick)
4040
41add_subdirectory(tests)41enable_coverage(telephonyservice)
4242
=== modified file 'libtelephonyservice/accountentry.cpp'
--- libtelephonyservice/accountentry.cpp 2015-03-30 20:55:55 +0000
+++ libtelephonyservice/accountentry.cpp 2015-03-30 20:55:55 +0000
@@ -41,7 +41,8 @@
4141
42bool AccountEntry::active() const42bool AccountEntry::active() const
43{43{
44 return (!mAccount->connection().isNull() &&44 return (!mAccount.isNull() &&
45 !mAccount->connection().isNull() &&
45 !mAccount->connection()->selfContact().isNull() &&46 !mAccount->connection()->selfContact().isNull() &&
46 mAccount->connection()->selfContact()->presence().type() != Tp::ConnectionPresenceTypeOffline);47 mAccount->connection()->selfContact()->presence().type() != Tp::ConnectionPresenceTypeOffline);
47}48}
@@ -70,10 +71,7 @@
70 return QString::null;71 return QString::null;
71 }72 }
72 Tp::Presence presence = mAccount->connection()->selfContact()->presence();73 Tp::Presence presence = mAccount->connection()->selfContact()->presence();
73 if (presence.type() == Tp::ConnectionPresenceTypeAvailable) {74 return presence.statusMessage();
74 return presence.statusMessage();
75 }
76 return QString::null;
77}75}
7876
79QString AccountEntry::selfContactId() const77QString AccountEntry::selfContactId() const
@@ -147,6 +145,10 @@
147 SIGNAL(connectionChanged(Tp::ConnectionPtr)),145 SIGNAL(connectionChanged(Tp::ConnectionPtr)),
148 SLOT(onConnectionChanged()));146 SLOT(onConnectionChanged()));
149147
148 connect(this,
149 SIGNAL(connectedChanged()),
150 SIGNAL(activeChanged()));
151
150 // and make sure it is enabled and connected152 // and make sure it is enabled and connected
151 if (!mAccount->isEnabled()) {153 if (!mAccount->isEnabled()) {
152 QTimer::singleShot(0, this, SLOT(ensureEnabled()));154 QTimer::singleShot(0, this, SLOT(ensureEnabled()));
@@ -203,15 +205,12 @@
203 Q_EMIT statusMessageChanged();205 Q_EMIT statusMessageChanged();
204 Q_EMIT connectedChanged();206 Q_EMIT connectedChanged();
205 Q_EMIT selfContactIdChanged();207 Q_EMIT selfContactIdChanged();
206 Q_EMIT activeChanged();
207}208}
208209
209void AccountEntry::onConnectionChanged()210void AccountEntry::onConnectionChanged()
210{211{
211 if (!mAccount->connection()) {212 if (!mAccount->connection()) {
212213 // ensure the account gets connected
213
214 // and ensure the account gets connected
215 ensureConnected();214 ensureConnected();
216 } else {215 } else {
217 mConnectionInfo.busName = mAccount->connection()->busName();216 mConnectionInfo.busName = mAccount->connection()->busName();
@@ -226,5 +225,4 @@
226225
227 Q_EMIT connectedChanged();226 Q_EMIT connectedChanged();
228 Q_EMIT selfContactIdChanged();227 Q_EMIT selfContactIdChanged();
229 Q_EMIT activeChanged();
230}228}
231229
=== modified file 'libtelephonyservice/accountentryfactory.cpp'
--- libtelephonyservice/accountentryfactory.cpp 2015-03-30 20:55:55 +0000
+++ libtelephonyservice/accountentryfactory.cpp 2015-03-30 20:55:55 +0000
@@ -25,7 +25,7 @@
2525
26AccountEntry *AccountEntryFactory::createEntry(const Tp::AccountPtr &account, QObject *parent)26AccountEntry *AccountEntryFactory::createEntry(const Tp::AccountPtr &account, QObject *parent)
27{27{
28 QString protocol = account->protocolName();28 QString protocol = account.isNull() ? "" : account->protocolName();
2929
30 // FIXME: check what other accounts need extra properties/methods30 // FIXME: check what other accounts need extra properties/methods
31 if (protocol == "ofono") {31 if (protocol == "ofono") {
@@ -34,7 +34,3 @@
3434
35 return new AccountEntry(account, parent);35 return new AccountEntry(account, parent);
36}36}
37
38AccountEntryFactory::AccountEntryFactory()
39{
40}
4137
=== modified file 'libtelephonyservice/accountentryfactory.h'
--- libtelephonyservice/accountentryfactory.h 2015-03-30 20:55:55 +0000
+++ libtelephonyservice/accountentryfactory.h 2015-03-30 20:55:55 +0000
@@ -31,8 +31,6 @@
31public:31public:
32 static AccountEntry *createEntry(const Tp::AccountPtr &account, QObject *parent = 0);32 static AccountEntry *createEntry(const Tp::AccountPtr &account, QObject *parent = 0);
3333
34private:
35 explicit AccountEntryFactory();
36};34};
3735
38#endif // ACCOUNTENTRYFACTORY_H36#endif // ACCOUNTENTRYFACTORY_H
3937
=== modified file 'libtelephonyservice/channelobserver.cpp'
--- libtelephonyservice/channelobserver.cpp 2015-02-09 20:32:32 +0000
+++ libtelephonyservice/channelobserver.cpp 2015-03-30 20:55:55 +0000
@@ -38,6 +38,7 @@
38 specList << TelepathyHelper::audioConferenceSpec();38 specList << TelepathyHelper::audioConferenceSpec();
39 specList << Tp::ChannelClassSpec::audioCall();39 specList << Tp::ChannelClassSpec::audioCall();
40 specList << Tp::ChannelClassSpec::textChat();40 specList << Tp::ChannelClassSpec::textChat();
41 specList << Tp::ChannelClassSpec::unnamedTextChat();
4142
42 return specList;43 return specList;
43}44}
4445
=== modified file 'libtelephonyservice/chatmanager.cpp'
--- libtelephonyservice/chatmanager.cpp 2015-03-30 20:55:55 +0000
+++ libtelephonyservice/chatmanager.cpp 2015-03-30 20:55:55 +0000
@@ -26,6 +26,7 @@
26#include "dbustypes.h"26#include "dbustypes.h"
27#include "accountentry.h"27#include "accountentry.h"
2828
29#include <TelepathyQt/Contact>
29#include <TelepathyQt/ContactManager>30#include <TelepathyQt/ContactManager>
30#include <TelepathyQt/PendingContacts>31#include <TelepathyQt/PendingContacts>
31#include <QDBusArgument>32#include <QDBusArgument>
@@ -114,6 +115,7 @@
114115
115void ChatManager::sendMessage(const QStringList &recipients, const QString &message, const QString &accountId)116void ChatManager::sendMessage(const QStringList &recipients, const QString &message, const QString &accountId)
116{117{
118 // FIXME: this probably should be handle internally by telepathy-ofono
117 if (recipients.size() > 1 && TelepathyHelper::instance()->mmsGroupChat()) {119 if (recipients.size() > 1 && TelepathyHelper::instance()->mmsGroupChat()) {
118 sendMMS(recipients, message, QVariant(), accountId);120 sendMMS(recipients, message, QVariant(), accountId);
119 return;121 return;
@@ -173,9 +175,12 @@
173 return;175 return;
174 }176 }
175177
176 if (!channel->targetContact().isNull()) {178 QStringList recipients;
177 Q_EMIT messageSent(channel->targetContact()->id(), sentMessage.text());179 Q_FOREACH(const Tp::ContactPtr &contact, channel->groupContacts(false)) {
180 recipients << contact->id();
178 }181 }
182
183 Q_EMIT messageSent(recipients, sentMessage.text());
179}184}
180185
181void ChatManager::acknowledgeMessage(const QStringList &recipients, const QString &messageId, const QString &accountId)186void ChatManager::acknowledgeMessage(const QStringList &recipients, const QString &messageId, const QString &accountId)
182187
=== modified file 'libtelephonyservice/chatmanager.h'
--- libtelephonyservice/chatmanager.h 2015-03-30 20:55:55 +0000
+++ libtelephonyservice/chatmanager.h 2015-03-30 20:55:55 +0000
@@ -38,8 +38,8 @@
38 Q_INVOKABLE void sendMMS(const QStringList &recipients, const QString &message, const QVariant &attachments, const QString &accountId = QString:: null);38 Q_INVOKABLE void sendMMS(const QStringList &recipients, const QString &message, const QVariant &attachments, const QString &accountId = QString:: null);
3939
40Q_SIGNALS:40Q_SIGNALS:
41 void messageReceived(const QString &recipient, const QString &message, const QDateTime &timestamp, const QString &messageId, bool unread);41 void messageReceived(const QString &sender, const QString &message, const QDateTime &timestamp, const QString &messageId, bool unread);
42 void messageSent(const QString &recipient, const QString &message);42 void messageSent(const QStringList &recipients, const QString &message);
4343
44public Q_SLOTS:44public Q_SLOTS:
45 void onTextChannelAvailable(Tp::TextChannelPtr channel);45 void onTextChannelAvailable(Tp::TextChannelPtr channel);
4646
=== modified file 'libtelephonyservice/ofonoaccountentry.cpp'
--- libtelephonyservice/ofonoaccountentry.cpp 2015-03-30 20:55:55 +0000
+++ libtelephonyservice/ofonoaccountentry.cpp 2015-03-30 20:55:55 +0000
@@ -203,6 +203,5 @@
203 mSerial = ussdIface.property("Serial").toString();203 mSerial = ussdIface.property("Serial").toString();
204 }204 }
205205
206 Q_EMIT simLockedChanged();
207 Q_EMIT serialChanged();206 Q_EMIT serialChanged();
208}207}
209208
=== modified file 'libtelephonyservice/telepathyhelper.cpp'
--- libtelephonyservice/telepathyhelper.cpp 2015-03-30 20:55:55 +0000
+++ libtelephonyservice/telepathyhelper.cpp 2015-03-30 20:55:55 +0000
@@ -247,10 +247,7 @@
247247
248void TelepathyHelper::unregisterChannelObserver()248void TelepathyHelper::unregisterChannelObserver()
249{249{
250 Tp::AbstractClientPtr clientPtr(mChannelObserver);250 unregisterClient(mChannelObserver);
251 if (clientPtr) {
252 mClientRegistrar->unregisterClient(clientPtr);
253 }
254 mChannelObserver->deleteLater();251 mChannelObserver->deleteLater();
255 mChannelObserver = NULL;252 mChannelObserver = NULL;
256 Q_EMIT channelObserverUnregistered();253 Q_EMIT channelObserverUnregistered();
@@ -315,6 +312,15 @@
315 return succeeded;312 return succeeded;
316}313}
317314
315bool TelepathyHelper::unregisterClient(Tp::AbstractClient *client)
316{
317 Tp::AbstractClientPtr clientPtr(client);
318 if (clientPtr) {
319 return mClientRegistrar->unregisterClient(clientPtr);
320 }
321 return false;
322}
323
318AccountEntry *TelepathyHelper::accountForConnection(const Tp::ConnectionPtr &connection) const324AccountEntry *TelepathyHelper::accountForConnection(const Tp::ConnectionPtr &connection) const
319{325{
320 if (connection.isNull()) {326 if (connection.isNull()) {
@@ -401,7 +407,7 @@
401 Q_FOREACH(AccountEntry *account, mAccounts) {407 Q_FOREACH(AccountEntry *account, mAccounts) {
402 QString modemObjName = account->account()->parameters().value("modem-objpath").toString();408 QString modemObjName = account->account()->parameters().value("modem-objpath").toString();
403 if (modemObjName.isEmpty()) {409 if (modemObjName.isEmpty()) {
404 sortedOtherAccounts[account->displayName()] = account;410 sortedOtherAccounts[account->accountId()] = account;
405 } else {411 } else {
406 sortedOfonoAccounts[modemObjName] = account;412 sortedOfonoAccounts[modemObjName] = account;
407 }413 }
408414
=== modified file 'libtelephonyservice/telepathyhelper.h'
--- libtelephonyservice/telepathyhelper.h 2015-02-09 20:32:32 +0000
+++ libtelephonyservice/telepathyhelper.h 2015-03-30 20:55:55 +0000
@@ -87,6 +87,7 @@
87 Q_INVOKABLE void unlockSimCards() const;87 Q_INVOKABLE void unlockSimCards() const;
8888
89 bool registerClient(Tp::AbstractClient *client, QString name);89 bool registerClient(Tp::AbstractClient *client, QString name);
90 bool unregisterClient(Tp::AbstractClient *client);
9091
91 // pre-populated channel class specs for conferences92 // pre-populated channel class specs for conferences
92 static Tp::ChannelClassSpec audioConferenceSpec();93 static Tp::ChannelClassSpec audioConferenceSpec();
9394
=== added directory 'tests'
=== added file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/CMakeLists.txt 2015-03-30 20:55:55 +0000
@@ -0,0 +1,6 @@
1include (GenerateTest)
2
3add_subdirectory(common)
4add_subdirectory(handler)
5add_subdirectory(libtelephonyservice)
6add_subdirectory(Ubuntu.Telephony)
07
=== renamed directory 'Ubuntu/Telephony/tests' => 'tests/Ubuntu.Telephony'
=== modified file 'tests/Ubuntu.Telephony/CMakeLists.txt'
--- Ubuntu/Telephony/tests/CMakeLists.txt 2014-07-11 21:30:21 +0000
+++ tests/Ubuntu.Telephony/CMakeLists.txt 2015-03-30 20:55:55 +0000
@@ -1,35 +1,19 @@
1include_directories(1include_directories(
2 ${CMAKE_CURRENT_BINARY_DIR}2 ${CMAKE_CURRENT_BINARY_DIR}
3 ${CMAKE_SOURCE_DIR}/Ubuntu/Telephony3 ${CMAKE_SOURCE_DIR}/Ubuntu/Telephony
4 )4 ${CMAKE_SOURCE_DIR}/libtelephonyservice
55 )
6macro(generate_tests)6
7 foreach(test ${ARGN})7set(SOURCE_DIR ${CMAKE_SOURCE_DIR}/Ubuntu/Telephony)
8 add_executable(${test} ${test}.cpp)8generate_test(ContactWatcherTest USE_UI
9 qt5_use_modules(${test} Contacts Core DBus Qml Test)9 SOURCES ContactWatcherTest.cpp
10 target_link_libraries(${test}10 LIBRARIES telephonyservice-qml
11 telephonyservice-qml11 QT5_MODULES Contacts Core DBus Qml Test)
12 )12
13 add_test(${test} ${CMAKE_CURRENT_BINARY_DIR}/${test} -platform offscreen -xunitxml -o ${CMAKE_BINARY_DIR}/test_${test}.xml)13generate_test(context_properties QML_TEST tst_contextProperties.qml)
14 endforeach(test)14generate_test(phonenumber_field QML_TEST tst_PhoneNumberField.qml)
15endmacro(generate_tests)15generate_test(phonenumber_input QML_TEST tst_PhoneNumberInput.qml)
1616generate_test(phonenumber_utils QML_TEST tst_PhoneNumberPhoneUtils.qml)
17macro(DECLARE_QML_TEST TST_NAME TST_QML_FILE)
18 add_test(NAME ${TST_NAME}
19 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
20 COMMAND xvfb-run -a -s "-screen 0 1024x768x24" qmltestrunner -import ${CMAKE_BINARY_DIR} -input ${CMAKE_CURRENT_SOURCE_DIR}/${TST_QML_FILE}
21 )
22endmacro()
23
24
25generate_tests(
26 ContactWatcherTest
27 )
28
29declare_qml_test("context_properties" tst_contextProperties.qml)
30declare_qml_test("phonenumber_field" tst_PhoneNumberField.qml)
31declare_qml_test("phonenumber_input" tst_PhoneNumberInput.qml)
32declare_qml_test("phonenumber_utils" tst_PhoneNumberPhoneUtils.qml)
3317
34# make the files visible on qtcreator18# make the files visible on qtcreator
35file(GLOB QML_TESTS *.qml *.js)19file(GLOB QML_TESTS *.qml *.js)
3620
=== modified file 'tests/Ubuntu.Telephony/ContactWatcherTest.cpp'
--- Ubuntu/Telephony/tests/ContactWatcherTest.cpp 2015-03-30 20:55:55 +0000
+++ tests/Ubuntu.Telephony/ContactWatcherTest.cpp 2015-03-30 20:55:55 +0000
@@ -438,6 +438,11 @@
438 watcher.setAddressableFields(addressableFields);438 watcher.setAddressableFields(addressableFields);
439 QCOMPARE(addressableFieldsSpy.count(), 1);439 QCOMPARE(addressableFieldsSpy.count(), 1);
440 QCOMPARE(watcher.addressableFields(), addressableFields);440 QCOMPARE(watcher.addressableFields(), addressableFields);
441
442 // set the addressable fields to an empty value and make sure it falls back to "tel"
443 watcher.setAddressableFields(QStringList());
444 QCOMPARE(watcher.addressableFields().count(), 1);
445 QCOMPARE(watcher.addressableFields()[0], QString("tel"));
441}446}
442447
443void ContactWatcherTest::testExtendedFieldMatch()448void ContactWatcherTest::testExtendedFieldMatch()
444449
=== added directory 'tests/common'
=== added file 'tests/common/CMakeLists.txt'
--- tests/common/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/common/CMakeLists.txt 2015-03-30 20:55:55 +0000
@@ -0,0 +1,14 @@
1include_directories(${TP_QT5_INCLUDE_DIRS}
2 ${CMAKE_SOURCE_DIR}/libtelephonyservice)
3
4configure_file(dbus-session.conf.in ${CMAKE_CURRENT_BINARY_DIR}/dbus-session.conf)
5
6add_library(mockcontroller STATIC mockcontroller.cpp mockcontroller.h)
7qt5_use_modules(mockcontroller Core DBus)
8
9add_library(telepathytest STATIC telepathytest.cpp telepathytest.h)
10qt5_use_modules(telepathytest Core DBus)
11target_link_libraries(telepathytest telephonyservice ${TP_QT5_LIBRARIES})
12
13add_subdirectory(mock)
14add_subdirectory(dbus-services)
015
=== added directory 'tests/common/dbus-services'
=== added file 'tests/common/dbus-services/CMakeLists.txt'
--- tests/common/dbus-services/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/common/dbus-services/CMakeLists.txt 2015-03-30 20:55:55 +0000
@@ -0,0 +1,9 @@
1# copy the services we want to use
2set(DBUS_SERVICES_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/dbus-1/services)
3
4file(COPY ${DBUS_SERVICES_DIR}/org.freedesktop.Telepathy.MissionControl5.service
5 DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
6file(COPY ${DBUS_SERVICES_DIR}/org.freedesktop.Telepathy.AccountManager.service
7 DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
8file(COPY ${DBUS_SERVICES_DIR}/ca.desrt.dconf.service
9 DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
010
=== added file 'tests/common/dbus-session.conf.in'
--- tests/common/dbus-session.conf.in 1970-01-01 00:00:00 +0000
+++ tests/common/dbus-session.conf.in 2015-03-30 20:55:55 +0000
@@ -0,0 +1,42 @@
1<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
2 "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
3<busconfig>
4 <type>session</type>
5
6 <!-- If we fork, keep the user's original umask to avoid affecting
7 the behavior of child processes. -->
8 <keep_umask/>
9
10 <listen>unix:tmpdir=/tmp</listen>
11
12 <servicedir>@CMAKE_CURRENT_BINARY_DIR@/dbus-services</servicedir>
13
14 <policy context="default">
15 <!-- Allow everything to be sent -->
16 <allow send_destination="*" eavesdrop="true"/>
17 <!-- Allow everything to be received -->
18 <allow eavesdrop="true"/>
19 <!-- Allow anyone to own anything -->
20 <allow own="*"/>
21 </policy>
22
23 <!-- raise the service start timeout to 40 seconds as it can timeout
24 on the live cd on slow machines -->
25 <limit name="service_start_timeout">60000</limit>
26
27 <!-- the memory limits are 1G instead of say 4G because they can't exceed 32-bit signed int max -->
28 <limit name="max_incoming_bytes">1000000000</limit>
29 <limit name="max_outgoing_bytes">1000000000</limit>
30 <limit name="max_message_size">1000000000</limit>
31 <limit name="service_start_timeout">120000</limit>
32 <limit name="auth_timeout">240000</limit>
33 <limit name="max_completed_connections">100000</limit>
34 <limit name="max_incomplete_connections">10000</limit>
35 <limit name="max_connections_per_user">100000</limit>
36 <limit name="max_pending_service_starts">10000</limit>
37 <limit name="max_names_per_connection">50000</limit>
38 <limit name="max_match_rules_per_connection">50000</limit>
39 <limit name="max_replies_per_connection">50000</limit>
40 <limit name="reply_timeout">300000</limit>
41
42</busconfig>
043
=== renamed directory 'handler/tests/mock' => 'tests/common/mock'
=== modified file 'tests/common/mock/CMakeLists.txt'
--- handler/tests/mock/CMakeLists.txt 2014-03-13 17:11:09 +0000
+++ tests/common/mock/CMakeLists.txt 2015-03-30 20:55:55 +0000
@@ -4,11 +4,14 @@
4 ${Qt5DBus_INCLUDE_DIRS}4 ${Qt5DBus_INCLUDE_DIRS}
5 ${CMAKE_CURRENT_BINARY_DIR}5 ${CMAKE_CURRENT_BINARY_DIR}
6 ${CMAKE_CURRENT_SOURCE_DIR}6 ${CMAKE_CURRENT_SOURCE_DIR}
7 ${CMAKE_SOURCE_DIR}/libtelephonyservice
7 )8 )
89
9find_library(TELEPATHY_QT5_SERVICE_LIBRARIES telepathy-qt5-service)10find_library(TELEPATHY_QT5_SERVICE_LIBRARIES telepathy-qt5-service)
1011
11set(mock_SRCS main.cpp protocol.cpp connection.cpp textchannel.cpp callchannel.cpp conferencecallchannel.cpp mockconnectiondbus.cpp speakeriface.cpp)12set(mock_SRCS main.cpp protocol.cpp connection.cpp textchannel.cpp callchannel.cpp
13 conferencecallchannel.cpp mockconnectiondbus.cpp speakeriface.cpp
14 emergencymodeiface.cpp ussdiface.cpp voicemailiface.cpp)
12qt5_add_dbus_adaptor(mock_SRCS MockConnection.xml mockconnectiondbus.h MockConnectionDBus)15qt5_add_dbus_adaptor(mock_SRCS MockConnection.xml mockconnectiondbus.h MockConnectionDBus)
1316
14add_executable(telepathy-mock ${mock_SRCS})17add_executable(telepathy-mock ${mock_SRCS})
1518
=== modified file 'tests/common/mock/MockConnection.xml'
--- handler/tests/mock/MockConnection.xml 2014-03-20 21:03:26 +0000
+++ tests/common/mock/MockConnection.xml 2015-03-30 20:55:55 +0000
@@ -38,6 +38,55 @@
38 <arg name="phoneNumber" type="s" direction="in"/>38 <arg name="phoneNumber" type="s" direction="in"/>
39 <arg name="status" type="s" direction="in"/>39 <arg name="status" type="s" direction="in"/>
40 </method>40 </method>
41 <method name="SetOnline">
42 <dox:d><![CDATA[
43 Set the account online/offline
44 ]]></dox:d>
45 <arg name="online" type="b" direction="in"/>
46 </method>
47 <method name="SetPresence">
48 <dox:d><![CDATA[
49 Set the requested presence
50 ]]></dox:d>
51 <arg name="status" type="s" direction="in"/>
52 <arg name="statusMessage" type="s" direction="in"/>
53 </method>
54 <method name="SetVoicemailIndicator">
55 <dox:d><![CDATA[
56 Set the voicemail indicator on/off
57 ]]></dox:d>
58 <arg name="active" type="b" direction="in"/>
59 </method>
60 <method name="SetVoicemailNumber">
61 <dox:d><![CDATA[
62 Set the voicemail number
63 ]]></dox:d>
64 <arg name="number" type="s" direction="in"/>
65 </method>
66 <method name="SetVoicemailCount">
67 <dox:d><![CDATA[
68 Set the voicemail count
69 ]]></dox:d>
70 <arg name="count" type="i" direction="in"/>
71 </method>
72 <method name="SetEmergencyNumbers">
73 <dox:d><![CDATA[
74 Set the emergency numbers
75 ]]></dox:d>
76 <arg name="numbers" type="as" direction="in"/>
77 </method>
78 <method name="Serial">
79 <dox:d><![CDATA[
80 Get the USSD serial
81 ]]></dox:d>
82 <arg name="value" type="s" direction="out"/>
83 </method>
84 <signal name="MessageRead">
85 <dox:d><![CDATA[
86 A message was acknowledged
87 ]]></dox:d>
88 <arg name="messageId" type="s"/>
89 </signal>
41 <signal name="MessageSent">90 <signal name="MessageSent">
42 <dox:d><![CDATA[91 <dox:d><![CDATA[
43 A message was sent from the client.92 A message was sent from the client.
@@ -45,6 +94,7 @@
45 <arg name="message" type="s"/>94 <arg name="message" type="s"/>
46 <arg name="properties" type="a{sv}"/>95 <arg name="properties" type="a{sv}"/>
47 <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="QVariantMap"/>96 <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="QVariantMap"/>
97 <annotation name="org.qtproject.QtDBus.QtTypeName.Out1" value="QVariantMap"/>
48 </signal>98 </signal>
49 <signal name="CallReceived">99 <signal name="CallReceived">
50 <dox:d><![CDATA[100 <dox:d><![CDATA[
@@ -84,5 +134,15 @@
84 ]]></dox:d>134 ]]></dox:d>
85 <arg name="objectPath" type="s"/>135 <arg name="objectPath" type="s"/>
86 </signal>136 </signal>
137 <signal name="Disconnected">
138 <dox:d><![CDATA[
139 The account was disconnected
140 ]]></dox:d>
141 </signal>
142 <signal name="Destroyed">
143 <dox:d><![CDATA[
144 The connection object was destroyed
145 ]]></dox:d>
146 </signal>
87 </interface>147 </interface>
88</node>148</node>
89149
=== modified file 'tests/common/mock/callchannel.cpp'
--- handler/tests/mock/callchannel.cpp 2014-03-20 21:03:26 +0000
+++ tests/common/mock/callchannel.cpp 2015-03-30 20:55:55 +0000
@@ -172,7 +172,7 @@
172{172{
173 qDebug() << "call channel closed";173 qDebug() << "call channel closed";
174 // TODO - for some reason the object is not being removed174 // TODO - for some reason the object is not being removed
175 mConnection->dbusConnection().unregisterObject(mObjPath, QDBusConnection::UnregisterTree);175 mConnection->dbusConnection().unregisterObject(mBaseChannel->objectPath(), QDBusConnection::UnregisterTree);
176}176}
177177
178Tp::BaseChannelPtr MockCallChannel::baseChannel()178Tp::BaseChannelPtr MockCallChannel::baseChannel()
179179
=== modified file 'tests/common/mock/connection.cpp'
--- handler/tests/mock/connection.cpp 2014-04-03 16:38:01 +0000
+++ tests/common/mock/connection.cpp 2015-03-30 20:55:55 +0000
@@ -36,7 +36,7 @@
36 const QString &protocolName,36 const QString &protocolName,
37 const QVariantMap &parameters) :37 const QVariantMap &parameters) :
38 Tp::BaseConnection(dbusConnection, cmName, protocolName, parameters),38 Tp::BaseConnection(dbusConnection, cmName, protocolName, parameters),
39 mHandleCount(0), mConferenceCall(0)39 mConferenceCall(0), mVoicemailIndicator(false), mVoicemailCount(0)
40{40{
41 setSelfHandle(newHandle("<SelfHandle>"));41 setSelfHandle(newHandle("<SelfHandle>"));
4242
@@ -54,6 +54,7 @@
54 text.fixedProperties[TP_QT_IFACE_CHANNEL+".TargetHandleType"] = Tp::HandleTypeContact;54 text.fixedProperties[TP_QT_IFACE_CHANNEL+".TargetHandleType"] = Tp::HandleTypeContact;
55 text.allowedProperties.append(TP_QT_IFACE_CHANNEL+".TargetHandle");55 text.allowedProperties.append(TP_QT_IFACE_CHANNEL+".TargetHandle");
56 text.allowedProperties.append(TP_QT_IFACE_CHANNEL+".TargetID");56 text.allowedProperties.append(TP_QT_IFACE_CHANNEL+".TargetID");
57 text.allowedProperties.append(TP_QT_IFACE_CHANNEL_INTERFACE_CONFERENCE + QLatin1String(".InitialInviteeHandles"));
5758
58 // set requestable call channel properties59 // set requestable call channel properties
59 Tp::RequestableChannelClass call;60 Tp::RequestableChannelClass call;
@@ -77,26 +78,41 @@
77 // init presence interface78 // init presence interface
78 simplePresenceIface = Tp::BaseConnectionSimplePresenceInterface::create();79 simplePresenceIface = Tp::BaseConnectionSimplePresenceInterface::create();
79 simplePresenceIface->setSetPresenceCallback(Tp::memFun(this,&MockConnection::setPresence));80 simplePresenceIface->setSetPresenceCallback(Tp::memFun(this,&MockConnection::setPresence));
81 simplePresenceIface->setMaxmimumStatusMessageLength(255);
80 plugInterface(Tp::AbstractConnectionInterfacePtr::dynamicCast(simplePresenceIface));82 plugInterface(Tp::AbstractConnectionInterfacePtr::dynamicCast(simplePresenceIface));
8183
82 // Set Presence84 // Set Presence
83 Tp::SimpleStatusSpec presenceOnline;85 Tp::SimpleStatusSpec presenceOnline;
84 presenceOnline.type = Tp::ConnectionPresenceTypeAvailable;86 presenceOnline.type = Tp::ConnectionPresenceTypeAvailable;
85 presenceOnline.maySetOnSelf = true;87 presenceOnline.maySetOnSelf = true;
86 presenceOnline.canHaveMessage = false;88 presenceOnline.canHaveMessage = true;
8789
88 Tp::SimpleStatusSpec presenceOffline;90 Tp::SimpleStatusSpec presenceOffline;
89 presenceOffline.type = Tp::ConnectionPresenceTypeOffline;91 presenceOffline.type = Tp::ConnectionPresenceTypeOffline;
90 presenceOffline.maySetOnSelf = false;92 presenceOffline.maySetOnSelf = true;
91 presenceOffline.canHaveMessage = false;93 presenceOffline.canHaveMessage = true;
9294
93 Tp::SimpleStatusSpecMap statuses;95 Tp::SimpleStatusSpec presenceAway;
94 statuses.insert(QLatin1String("available"), presenceOnline);96 presenceAway.type = Tp::ConnectionPresenceTypeAway;
95 statuses.insert(QLatin1String("offline"), presenceOffline);97 presenceAway.maySetOnSelf = true;
9698 presenceAway.canHaveMessage = true;
97 simplePresenceIface->setStatuses(statuses);99
100 mStatuses.insert(QLatin1String("available"), presenceOnline);
101 mStatuses.insert(QLatin1String("offline"), presenceOffline);
102 mStatuses.insert(QLatin1String("away"), presenceAway);
103 mStatuses.insert(QLatin1String("simlocked"), presenceAway);
104 mStatuses.insert(QLatin1String("flightmode"), presenceOffline);
105 mStatuses.insert(QLatin1String("nosim"), presenceOffline);
106 mStatuses.insert(QLatin1String("nomodem"), presenceOffline);
107 mStatuses.insert(QLatin1String("registered"), presenceOnline);
108 mStatuses.insert(QLatin1String("roaming"), presenceOnline);
109 mStatuses.insert(QLatin1String("unregistered"), presenceAway);
110 mStatuses.insert(QLatin1String("denied"), presenceAway);
111 mStatuses.insert(QLatin1String("unknown"), presenceAway);
112 mStatuses.insert(QLatin1String("searching"), presenceAway);
113
114 simplePresenceIface->setStatuses(mStatuses);
98 mSelfPresence.type = Tp::ConnectionPresenceTypeOffline;115 mSelfPresence.type = Tp::ConnectionPresenceTypeOffline;
99 mRequestedSelfPresence.type = Tp::ConnectionPresenceTypeOffline;
100116
101 contactsIface = Tp::BaseConnectionContactsInterface::create();117 contactsIface = Tp::BaseConnectionContactsInterface::create();
102 contactsIface->setGetContactAttributesCallback(Tp::memFun(this,&MockConnection::getContactAttributes));118 contactsIface->setGetContactAttributesCallback(Tp::memFun(this,&MockConnection::getContactAttributes));
@@ -105,9 +121,40 @@
105 << TP_QT_IFACE_CONNECTION_INTERFACE_SIMPLE_PRESENCE);121 << TP_QT_IFACE_CONNECTION_INTERFACE_SIMPLE_PRESENCE);
106 plugInterface(Tp::AbstractConnectionInterfacePtr::dynamicCast(contactsIface));122 plugInterface(Tp::AbstractConnectionInterfacePtr::dynamicCast(contactsIface));
107123
124 // init custom emergency mode interface (not provided by telepathy
125 emergencyModeIface = BaseConnectionEmergencyModeInterface::create();
126 emergencyModeIface->setEmergencyNumbersCallback(Tp::memFun(this,&MockConnection::emergencyNumbers));
127 plugInterface(Tp::AbstractConnectionInterfacePtr::dynamicCast(emergencyModeIface));
128 mEmergencyNumbers << "123" << "456" << "789";
129 emergencyModeIface->setEmergencyNumbers(mEmergencyNumbers);
130
131 // init custom voicemail interface (not provided by telepathy)
132 voicemailIface = BaseConnectionVoicemailInterface::create();
133 voicemailIface->setVoicemailCountCallback(Tp::memFun(this,&MockConnection::voicemailCount));
134 voicemailIface->setVoicemailIndicatorCallback(Tp::memFun(this,&MockConnection::voicemailIndicator));
135 voicemailIface->setVoicemailNumberCallback(Tp::memFun(this,&MockConnection::voicemailNumber));
136 voicemailIface->setVoicemailNumber(mVoicemailNumber);
137 plugInterface(Tp::AbstractConnectionInterfacePtr::dynamicCast(voicemailIface));
138 voicemailIface->setVoicemailCount(mVoicemailCount);
139 voicemailIface->setVoicemailIndicator(mVoicemailIndicator);
140 mVoicemailNumber = "555";
141
142 supplementaryServicesIface = BaseConnectionUSSDInterface::create();
143 supplementaryServicesIface->setInitiateCallback(Tp::memFun(this,&MockConnection::USSDInitiate));
144 supplementaryServicesIface->setRespondCallback(Tp::memFun(this,&MockConnection::USSDRespond));
145 supplementaryServicesIface->setCancelCallback(Tp::memFun(this,&MockConnection::USSDCancel));
146
147 static int serial = 0;
148 serial++;
149 supplementaryServicesIface->setSerial(QString("accountserial%1").arg(QString::number(serial)));
150
151 plugInterface(Tp::AbstractConnectionInterfacePtr::dynamicCast(supplementaryServicesIface));
152
108 mDBus = new MockConnectionDBus(this);153 mDBus = new MockConnectionDBus(this);
154}
109155
110 setOnline(true);156MockConnection::~MockConnection()
157{
111}158}
112159
113void MockConnection::addMMSToService(const QString &path, const QVariantMap &properties, const QString &servicePath)160void MockConnection::addMMSToService(const QString &path, const QVariantMap &properties, const QString &servicePath)
@@ -143,16 +190,45 @@
143#endif190#endif
144}191}
145192
146MockConnection::~MockConnection()193MockTextChannel *MockConnection::textChannelForRecipients(const QStringList &recipients)
147{194{
195 Q_FOREACH(MockTextChannel *channel, mTextChannels) {
196 QStringList channelRecipients = channel->recipients();
197 if (channelRecipients.length() != recipients.length()) {
198 continue;
199 }
200
201 bool ok = true;
202 Q_FOREACH(const QString &recipient, recipients) {
203 if (!channelRecipients.contains(recipient)) {
204 ok = false;
205 break;
206 }
207 }
208
209 if (ok) {
210 return channel;
211 }
212 }
213 return 0;
148}214}
149215
150uint MockConnection::setPresence(const QString& status, const QString& statusMessage, Tp::DBusError *error)216uint MockConnection::setPresence(const QString& status, const QString& statusMessage, Tp::DBusError *error)
151{217{
152 qDebug() << "setPresence" << status;218 qDebug() << "setPresence" << status << statusMessage;
153 if (status == "available") {219 Tp::SimpleContactPresences presences;
154 mRequestedSelfPresence.type = Tp::ConnectionPresenceTypeAvailable;220 if (!mStatuses.contains(status) || !mStatuses[status].maySetOnSelf) {
221 error->set(TP_QT_ERROR_INVALID_ARGUMENT, "Status not supported or cannot be set");
222 return selfHandle();
155 }223 }
224
225 Tp::SimpleStatusSpec spec = mStatuses[status];
226 mSelfPresence.status = status;
227 mSelfPresence.type = spec.type;
228 mSelfPresence.statusMessage = spec.canHaveMessage ? statusMessage : "";
229
230 presences[selfHandle()] = mSelfPresence;
231 simplePresenceIface->setPresences(presences);
156 return selfHandle();232 return selfHandle();
157}233}
158234
@@ -190,8 +266,9 @@
190266
191uint MockConnection::newHandle(const QString &identifier)267uint MockConnection::newHandle(const QString &identifier)
192{268{
193 mHandles[++mHandleCount] = identifier;269 static int handleCount = 0;
194 return mHandleCount;270 mHandles[++handleCount] = identifier;
271 return handleCount;
195}272}
196273
197QMap<QString, MockCallChannel *> MockConnection::callChannels()274QMap<QString, MockCallChannel *> MockConnection::callChannels()
@@ -248,29 +325,44 @@
248}325}
249326
250Tp::BaseChannelPtr MockConnection::createTextChannel(uint targetHandleType,327Tp::BaseChannelPtr MockConnection::createTextChannel(uint targetHandleType,
251 uint targetHandle, Tp::DBusError *error)328 uint targetHandle,
329 const QVariantMap &hints,
330 Tp::DBusError *error)
252{331{
253 Q_UNUSED(targetHandleType);332 Q_UNUSED(targetHandleType);
254 Q_UNUSED(error);333 Q_UNUSED(error);
255334
256 QString requestedId = mHandles.value(targetHandle);335 if (hints.contains(TP_QT_IFACE_CHANNEL_INTERFACE_CONFERENCE + QLatin1String(".InitialInviteeHandles")) &&
257336 targetHandleType == Tp::HandleTypeNone && targetHandle == 0) {
258 if (mTextChannels.contains(requestedId)) {337
259 return mTextChannels[requestedId]->baseChannel();338 }
260 }339
261340 QStringList recipients;
262 MockTextChannel *channel = new MockTextChannel(this, requestedId, targetHandle);341 bool flash;
342 if (hints.contains(TP_QT_IFACE_CHANNEL_INTERFACE_CONFERENCE + QLatin1String(".InitialInviteeHandles"))) {
343 recipients << inspectHandles(Tp::HandleTypeContact, qdbus_cast<Tp::UIntList>(hints[TP_QT_IFACE_CHANNEL_INTERFACE_CONFERENCE + QLatin1String(".InitialInviteeHandles")]), error);
344 } else {
345 recipients << mHandles.value(targetHandle);
346 }
347
348 if (hints.contains(TP_QT_IFACE_CHANNEL_INTERFACE_SMS + QLatin1String(".Flash"))) {
349 flash = hints[TP_QT_IFACE_CHANNEL_INTERFACE_SMS + QLatin1String(".Flash")].toBool();
350 }
351
352 // FIXME: test flash messages
353 MockTextChannel *channel = new MockTextChannel(this, recipients, targetHandle);
263 QObject::connect(channel, SIGNAL(messageRead(QString)), SLOT(onMessageRead(QString)));354 QObject::connect(channel, SIGNAL(messageRead(QString)), SLOT(onMessageRead(QString)));
264 QObject::connect(channel, SIGNAL(destroyed()), SLOT(onTextChannelClosed()));355 QObject::connect(channel, SIGNAL(destroyed()), SLOT(onTextChannelClosed()));
265 QObject::connect(channel, SIGNAL(messageSent(QString,QVariantMap)), SIGNAL(messageSent(QString,QVariantMap)));356 QObject::connect(channel, SIGNAL(messageSent(QString,QVariantMap)), SIGNAL(messageSent(QString,QVariantMap)));
266 qDebug() << channel;357 qDebug() << channel;
267 mTextChannels[requestedId] = channel;358 mTextChannels << channel;
268 return channel->baseChannel();359 return channel->baseChannel();
269}360}
270361
271void MockConnection::onMessageRead(const QString &id)362void MockConnection::onMessageRead(const QString &id)
272{363{
273 // FIXME: implement364 // FIXME: check what else to do
365 Q_EMIT messageRead(id);
274}366}
275367
276void MockConnection::onConferenceCallChannelClosed()368void MockConnection::onConferenceCallChannelClosed()
@@ -355,7 +447,7 @@
355 }447 }
356448
357 if (channelType == TP_QT_IFACE_CHANNEL_TYPE_TEXT) {449 if (channelType == TP_QT_IFACE_CHANNEL_TYPE_TEXT) {
358 return createTextChannel(targetHandleType, targetHandle, error);450 return createTextChannel(targetHandleType, targetHandle, hints, error);
359 } else if (channelType == TP_QT_IFACE_CHANNEL_TYPE_CALL) {451 } else if (channelType == TP_QT_IFACE_CHANNEL_TYPE_CALL) {
360 return createCallChannel(targetHandleType, targetHandle, hints, error);452 return createCallChannel(targetHandleType, targetHandle, hints, error);
361 } else {453 } else {
@@ -367,33 +459,36 @@
367459
368void MockConnection::placeIncomingMessage(const QString &message, const QVariantMap &info)460void MockConnection::placeIncomingMessage(const QString &message, const QVariantMap &info)
369{461{
370 const QString sender = info["Sender"].toString();462 QString sender = info["Sender"].toString();
371 // check if there is an open channel for this sender and use it463 QStringList recipients = info["Recipients"].toStringList();
372 Q_FOREACH(const QString &id, mTextChannels.keys()) {464
373 if (id == sender) {465 MockTextChannel *channel = textChannelForRecipients(recipients);
374 mTextChannels[id]->messageReceived(message, info);466 if (!channel) {
375 return;467 // request the channel
376 }468 Tp::DBusError error;
377 }469 bool yours;
378470 uint handle = newHandle(sender);
379 Tp::DBusError error;471 ensureChannel(TP_QT_IFACE_CHANNEL_TYPE_TEXT,Tp::HandleTypeContact, handle, yours, handle, false, QVariantMap(), &error);
380 bool yours;472 if(error.isValid()) {
381 uint handle = newHandle(sender);473 qWarning() << "Error creating channel for incoming message" << error.name() << error.message();
382 ensureChannel(TP_QT_IFACE_CHANNEL_TYPE_TEXT,Tp::HandleTypeContact, handle, yours, handle, false, QVariantMap(), &error);474 return;
383 if(error.isValid()) {475 }
384 qWarning() << "Error creating channel for incoming message" << error.name() << error.message();476
385 return;477 channel = textChannelForRecipients(recipients);
386 }478 if (!channel) {
387 mTextChannels[sender]->messageReceived(message, info);479 return;
480 }
481 }
482
483 channel->messageReceived(message, info);
388}484}
389485
390void MockConnection::onTextChannelClosed()486void MockConnection::onTextChannelClosed()
391{487{
392 MockTextChannel *channel = static_cast<MockTextChannel*>(sender());488 MockTextChannel *channel = static_cast<MockTextChannel*>(sender());
393 if (channel) {489 if (channel) {
394 QString key = mTextChannels.key(channel);490 qDebug() << "text channel closed for recipients " << channel->recipients();
395 qDebug() << "text channel closed for number " << key;491 mTextChannels.removeAll(channel);
396 mTextChannels.remove(key);
397 }492 }
398}493}
399494
@@ -469,6 +564,76 @@
469 return channel->objectPath();564 return channel->objectPath();
470}565}
471566
567QStringList MockConnection::emergencyNumbers(Tp::DBusError *error)
568{
569 return mEmergencyNumbers;
570}
571
572void MockConnection::setEmergencyNumbers(const QStringList &emergencyNumbers)
573{
574 mEmergencyNumbers = emergencyNumbers;
575 emergencyModeIface->setEmergencyNumbers(emergencyNumbers);
576}
577
578bool MockConnection::voicemailIndicator(Tp::DBusError *error)
579{
580 return mVoicemailIndicator;
581}
582
583void MockConnection::setVoicemailIndicator(bool visible)
584{
585 mVoicemailIndicator = visible;
586 voicemailIface->setVoicemailIndicator(visible);
587}
588
589QString MockConnection::voicemailNumber(Tp::DBusError *error)
590{
591 return mVoicemailNumber;
592}
593
594void MockConnection::setVoicemailNumber(const QString &number)
595{
596 mVoicemailNumber = number;
597 voicemailIface->setVoicemailNumber(mVoicemailNumber);
598}
599
600uint MockConnection::voicemailCount(Tp::DBusError *error)
601{
602 return mVoicemailCount;
603}
604
605void MockConnection::setVoicemailCount(int count)
606{
607 mVoicemailCount = count;
608 voicemailIface->setVoicemailCount(mVoicemailCount);
609}
610
611void MockConnection::USSDInitiate(const QString &command, Tp::DBusError *error)
612{
613 // FIXME: implement
614}
615
616void MockConnection::USSDRespond(const QString &reply, Tp::DBusError *error)
617{
618 // FIXME: implement
619}
620
621void MockConnection::USSDCancel(Tp::DBusError *error)
622{
623 // FIXME: implement
624}
625
626QString MockConnection::serial()
627{
628 return supplementaryServicesIface->serial();
629}
630
631QString MockConnection::uniqueName() const
632{
633 static int count = 0;
634 return QString("connection%1%2").arg((quintptr) this, 0, 16).arg(count++, 0, 16);
635}
636
472void MockConnection::hangupCall(const QString &callerId)637void MockConnection::hangupCall(const QString &callerId)
473{638{
474 if (!mCallChannels.contains(callerId)) {639 if (!mCallChannels.contains(callerId)) {
475640
=== modified file 'tests/common/mock/connection.h'
--- handler/tests/mock/connection.h 2014-03-20 21:03:26 +0000
+++ tests/common/mock/connection.h 2015-03-30 20:55:55 +0000
@@ -34,6 +34,9 @@
34#include "textchannel.h"34#include "textchannel.h"
35#include "callchannel.h"35#include "callchannel.h"
36#include "dbustypes.h"36#include "dbustypes.h"
37#include "emergencymodeiface.h"
38#include "ussdiface.h"
39#include "voicemailiface.h"
3740
38class MockTextChannel;41class MockTextChannel;
39class MockCallChannel;42class MockCallChannel;
@@ -65,9 +68,16 @@
65 uint newHandle(const QString &identifier);68 uint newHandle(const QString &identifier);
66 QMap<QString, MockCallChannel*> callChannels();69 QMap<QString, MockCallChannel*> callChannels();
6770
71 // phone custom interfaces
72 BaseConnectionEmergencyModeInterfacePtr emergencyModeIface;
73 BaseConnectionVoicemailInterfacePtr voicemailIface;
74 BaseConnectionUSSDInterfacePtr supplementaryServicesIface;
75
68 uint ensureHandle(const QString &id);76 uint ensureHandle(const QString &id);
69 Tp::BaseChannelPtr createTextChannel(uint targetHandleType,77 Tp::BaseChannelPtr createTextChannel(uint targetHandleType,
70 uint targetHandle, Tp::DBusError *error);78 uint targetHandle,
79 const QVariantMap &hints,
80 Tp::DBusError *error);
71 Tp::BaseChannelPtr createCallChannel(uint targetHandleType,81 Tp::BaseChannelPtr createCallChannel(uint targetHandleType,
72 uint targetHandle,82 uint targetHandle,
73 const QVariantMap &hints,83 const QVariantMap &hints,
@@ -76,7 +86,27 @@
76 ~MockConnection();86 ~MockConnection();
7787
78 QString placeCall(const QVariantMap &properties);88 QString placeCall(const QVariantMap &properties);
89
90 QStringList emergencyNumbers(Tp::DBusError *error);
91 void setEmergencyNumbers(const QStringList &emergencyNumbers);
92
93 bool voicemailIndicator(Tp::DBusError *error);
94 void setVoicemailIndicator(bool visible);
95 QString voicemailNumber(Tp::DBusError *error);
96 void setVoicemailNumber(const QString &number);
97 uint voicemailCount(Tp::DBusError *error);
98 void setVoicemailCount(int count);
99 void USSDInitiate(const QString &command, Tp::DBusError *error);
100 void USSDRespond(const QString &reply, Tp::DBusError *error);
101 void USSDCancel(Tp::DBusError *error);
102 QString serial();
103
104 // FIXME: there is a problem in telepathy-qt that connection object paths and services are not properly unregistered
105 // and thus if we gain the same memory address (and thus the same pointer) every time we reconnect, there might be some problems
106 QString uniqueName() const;
107
79Q_SIGNALS:108Q_SIGNALS:
109 void messageRead(const QString &messageId);
80 void messageSent(const QString &message, const QVariantMap &info);110 void messageSent(const QString &message, const QVariantMap &info);
81 void callReceived(const QString &callerId);111 void callReceived(const QString &callerId);
82 void callEnded(const QString &callerId);112 void callEnded(const QString &callerId);
@@ -102,20 +132,27 @@
102132
103private:133private:
104 void addMMSToService(const QString &path, const QVariantMap &properties, const QString &servicePath);134 void addMMSToService(const QString &path, const QVariantMap &properties, const QString &servicePath);
135
136 MockTextChannel *textChannelForRecipients(const QStringList &recipients);
137
105 QMap<uint, QString> mHandles;138 QMap<uint, QString> mHandles;
139 Tp::SimpleStatusSpecMap mStatuses;
106140
107 QMap<QString, MockTextChannel*> mTextChannels;141 QList<MockTextChannel*> mTextChannels;
108 QMap<QString, MockCallChannel*> mCallChannels;142 QMap<QString, MockCallChannel*> mCallChannels;
109 QMap<QString, QString> mInitialCallStatus;143 QMap<QString, QString> mInitialCallStatus;
110144
111 QStringList mModems;145 QStringList mModems;
112 uint mHandleCount;
113 Tp::SimplePresence mSelfPresence;146 Tp::SimplePresence mSelfPresence;
114 Tp::SimplePresence mRequestedSelfPresence;
115147
116 MockConnectionDBus *mDBus;148 MockConnectionDBus *mDBus;
117 QStringList mIncomingCalls;149 QStringList mIncomingCalls;
118 MockConferenceCallChannel *mConferenceCall;150 MockConferenceCallChannel *mConferenceCall;
151
152 QStringList mEmergencyNumbers;
153 int mVoicemailCount;
154 bool mVoicemailIndicator;
155 QString mVoicemailNumber;
119};156};
120157
121#endif158#endif
122159
=== added file 'tests/common/mock/emergencymodeiface.cpp'
--- tests/common/mock/emergencymodeiface.cpp 1970-01-01 00:00:00 +0000
+++ tests/common/mock/emergencymodeiface.cpp 2015-03-30 20:55:55 +0000
@@ -0,0 +1,133 @@
1/**
2 * Copyright (C) 2013-2015 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Tiago Salem Herrmann <tiago.herrmann@canonical.com>
17 Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>
18 */
19
20#include <QDebug>
21
22#include <TelepathyQt/Constants>
23#include <TelepathyQt/DBusObject>
24
25#include "emergencymodeiface.h"
26
27BaseConnectionEmergencyModeInterface::Adaptee::Adaptee(BaseConnectionEmergencyModeInterface *interface)
28 : QObject(interface),
29 mInterface(interface)
30{
31}
32
33
34struct TP_QT_NO_EXPORT BaseConnectionEmergencyModeInterface::Private {
35 Private(BaseConnectionEmergencyModeInterface *parent)
36 : adaptee(new BaseConnectionEmergencyModeInterface::Adaptee(parent)) {
37 }
38 EmergencyNumbersCallback emergencyNumbersCB;
39 BaseConnectionEmergencyModeInterface::Adaptee *adaptee;
40 QString fakeEmergencyNumber;
41};
42
43BaseConnectionEmergencyModeInterface::Adaptee::~Adaptee()
44{
45}
46
47void BaseConnectionEmergencyModeInterface::Adaptee::emergencyNumbers(const ConnectionInterfaceEmergencyModeAdaptor::EmergencyNumbersContextPtr &context)
48{
49 if (!mInterface->mPriv->emergencyNumbersCB.isValid()) {
50 context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"));
51 return;
52 }
53 Tp::DBusError error;
54 QStringList numbers = mInterface->mPriv->emergencyNumbersCB(&error);
55 if (error.isValid()) {
56 context->setFinishedWithError(error.name(), error.message());
57 return;
58 }
59 if (mInterface->mPriv->fakeEmergencyNumber.isEmpty()) {
60 context->setFinished(numbers);
61 } else {
62 context->setFinished(QStringList() << numbers << mInterface->mPriv->fakeEmergencyNumber);
63 }
64}
65
66BaseConnectionEmergencyModeInterface::BaseConnectionEmergencyModeInterface()
67 : AbstractConnectionInterface(TP_QT_IFACE_CONNECTION_EMERGENCYMODE),
68 mPriv(new Private(this))
69{
70}
71
72BaseConnectionEmergencyModeInterface::~BaseConnectionEmergencyModeInterface()
73{
74 delete mPriv;
75}
76
77void BaseConnectionEmergencyModeInterface::setEmergencyNumbersCallback(const EmergencyNumbersCallback &cb)
78{
79 mPriv->emergencyNumbersCB = cb;
80}
81
82void BaseConnectionEmergencyModeInterface::setEmergencyNumbers(const QStringList &numbers)
83{
84 QStringList finalEmergencyList(numbers);
85
86 if (!mPriv->fakeEmergencyNumber.isEmpty()) {
87 finalEmergencyList << mPriv->fakeEmergencyNumber;
88 }
89
90 Q_EMIT mPriv->adaptee->emergencyNumbersChanged(finalEmergencyList);
91}
92
93void BaseConnectionEmergencyModeInterface::setFakeEmergencyNumber(const QString &fakeEmergencyNumber)
94{
95 mPriv->fakeEmergencyNumber = fakeEmergencyNumber;
96}
97
98QVariantMap BaseConnectionEmergencyModeInterface::immutableProperties() const
99{
100 QVariantMap map;
101 return map;
102}
103
104void BaseConnectionEmergencyModeInterface::createAdaptor()
105{
106 (void) new ConnectionInterfaceEmergencyModeAdaptor(dbusObject()->dbusConnection(),
107 mPriv->adaptee, dbusObject());
108}
109
110
111ConnectionInterfaceEmergencyModeAdaptor::ConnectionInterfaceEmergencyModeAdaptor(const QDBusConnection& bus, QObject* adaptee, QObject* parent)
112 : Tp::AbstractAdaptor(bus, adaptee, parent)
113{
114 connect(adaptee, SIGNAL(emergencyNumbersChanged(QStringList)), SIGNAL(EmergencyNumbersChanged(QStringList)));
115}
116
117ConnectionInterfaceEmergencyModeAdaptor::~ConnectionInterfaceEmergencyModeAdaptor()
118{
119}
120
121QStringList ConnectionInterfaceEmergencyModeAdaptor::EmergencyNumbers(const QDBusMessage& dbusMessage)
122{
123 if (!adaptee()->metaObject()->indexOfMethod("emergencyNumbers(ConnectionInterfaceEmergencyModeAdaptor::EmergencyNumbersContextPtr)") == -1) {
124 dbusConnection().send(dbusMessage.createErrorReply(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")));
125 return QStringList();
126 }
127
128 EmergencyNumbersContextPtr ctx = EmergencyNumbersContextPtr(
129 new Tp::MethodInvocationContext< QStringList >(dbusConnection(), dbusMessage));
130 QMetaObject::invokeMethod(adaptee(), "emergencyNumbers",
131 Q_ARG(ConnectionInterfaceEmergencyModeAdaptor::EmergencyNumbersContextPtr, ctx));
132 return QStringList();
133}
0134
=== added file 'tests/common/mock/emergencymodeiface.h'
--- tests/common/mock/emergencymodeiface.h 1970-01-01 00:00:00 +0000
+++ tests/common/mock/emergencymodeiface.h 2015-03-30 20:55:55 +0000
@@ -0,0 +1,121 @@
1/**
2 * Copyright (C) 2013-2015 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Tiago Salem Herrmann <tiago.herrmann@canonical.com>
17 Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>
18 */
19
20#ifndef OFONOEMERGENCYMODEIFACE_H
21#define OFONOEMERGENCYMODEIFACE_H
22
23// telepathy-qt
24#include <TelepathyQt/Constants>
25#include <TelepathyQt/BaseConnection>
26#include <TelepathyQt/AbstractAdaptor>
27#include <TelepathyQt/DBusError>
28#include <TelepathyQt/Callbacks>
29
30class BaseConnectionEmergencyModeInterface;
31
32typedef Tp::SharedPtr<BaseConnectionEmergencyModeInterface> BaseConnectionEmergencyModeInterfacePtr;
33
34#define TP_QT_IFACE_CONNECTION_EMERGENCYMODE "com.canonical.Telephony.EmergencyMode"
35
36class TP_QT_EXPORT BaseConnectionEmergencyModeInterface : public Tp::AbstractConnectionInterface
37{
38 Q_OBJECT
39 Q_DISABLE_COPY(BaseConnectionEmergencyModeInterface)
40
41public:
42 static BaseConnectionEmergencyModeInterfacePtr create() {
43 return BaseConnectionEmergencyModeInterfacePtr(new BaseConnectionEmergencyModeInterface());
44 }
45 template<typename BaseConnectionEmergencyModeInterfaceSubclass>
46 static Tp::SharedPtr<BaseConnectionEmergencyModeInterfaceSubclass> create() {
47 return Tp::SharedPtr<BaseConnectionEmergencyModeInterfaceSubclass>(
48 new BaseConnectionEmergencyModeInterfaceSubclass());
49 }
50 QVariantMap immutableProperties() const;
51 virtual ~BaseConnectionEmergencyModeInterface();
52
53 typedef Tp::Callback1<QStringList, Tp::DBusError*> EmergencyNumbersCallback;
54 void setEmergencyNumbersCallback(const EmergencyNumbersCallback &cb);
55 void setFakeEmergencyNumber(const QString &fakeEmergencyNumber);
56
57public Q_SLOTS:
58 void setEmergencyNumbers(const QStringList &numbers);
59
60protected:
61 BaseConnectionEmergencyModeInterface();
62
63private:
64 void createAdaptor();
65
66 class Adaptee;
67 friend class Adaptee;
68 struct Private;
69 friend struct Private;
70 Private *mPriv;
71};
72
73
74class TP_QT_EXPORT ConnectionInterfaceEmergencyModeAdaptor : public Tp::AbstractAdaptor
75{
76 Q_OBJECT
77 Q_CLASSINFO("D-Bus Interface", TP_QT_IFACE_CONNECTION_EMERGENCYMODE)
78 Q_CLASSINFO("D-Bus Introspection", ""
79" <interface name=\"com.canonical.Telephony.EmergencyMode\">\n"
80" <method name=\"EmergencyNumbers\">\n"
81" <arg direction=\"out\" type=\"as\" name=\"emergencyNumbers\"/>\n"
82" </method>\n"
83" <signal name=\"EmergencyNumbersChanged\">\n"
84" <arg type=\"as\" name=\"numbers\"/>\n"
85" </signal>\n"
86" </interface>\n"
87"")
88
89public:
90 ConnectionInterfaceEmergencyModeAdaptor(const QDBusConnection& dbusConnection, QObject* adaptee, QObject* parent);
91 virtual ~ConnectionInterfaceEmergencyModeAdaptor();
92
93 typedef Tp::MethodInvocationContextPtr< QStringList > EmergencyNumbersContextPtr;
94
95public Q_SLOTS: // METHODS
96 QStringList EmergencyNumbers(const QDBusMessage& dbusMessage);
97
98Q_SIGNALS: // SIGNALS
99 void EmergencyNumbersChanged(const QStringList &numbers);
100};
101
102
103class TP_QT_NO_EXPORT BaseConnectionEmergencyModeInterface::Adaptee : public QObject
104{
105 Q_OBJECT
106
107public:
108 Adaptee(BaseConnectionEmergencyModeInterface *interface);
109 ~Adaptee();
110
111private Q_SLOTS:
112 void emergencyNumbers(const ConnectionInterfaceEmergencyModeAdaptor::EmergencyNumbersContextPtr &context);
113
114Q_SIGNALS:
115 void emergencyNumbersChanged(const QStringList &numbers);
116
117public:
118 BaseConnectionEmergencyModeInterface *mInterface;
119};
120
121#endif
0122
=== modified file 'tests/common/mock/main.cpp'
--- handler/tests/mock/main.cpp 2014-01-07 19:53:45 +0000
+++ tests/common/mock/main.cpp 2015-03-30 20:55:55 +0000
@@ -31,10 +31,17 @@
31 Tp::enableDebug(true);31 Tp::enableDebug(true);
32 Tp::enableWarnings(true);32 Tp::enableWarnings(true);
3333
34 // create a standard protocol
34 Tp::BaseProtocolPtr proto = Tp::BaseProtocol::create<Protocol>(35 Tp::BaseProtocolPtr proto = Tp::BaseProtocol::create<Protocol>(
35 QDBusConnection::sessionBus(), QLatin1String("mock"));36 QDBusConnection::sessionBus(), QLatin1String("mock"));
37
38 // create a phone protocol
39 Tp::BaseProtocolPtr phoneProto = Tp::BaseProtocol::create<Protocol>(
40 QDBusConnection::sessionBus(), QLatin1String("ofono"));
41
36 Tp::BaseConnectionManagerPtr cm = Tp::BaseConnectionManager::create(42 Tp::BaseConnectionManagerPtr cm = Tp::BaseConnectionManager::create(
37 QDBusConnection::sessionBus(), QLatin1String("mock"));43 QDBusConnection::sessionBus(), QLatin1String("mock"));
44 cm->addProtocol(phoneProto);
38 cm->addProtocol(proto);45 cm->addProtocol(proto);
39 cm->registerObject();46 cm->registerObject();
4047
4148
=== modified file 'tests/common/mock/mockconnectiondbus.cpp'
--- handler/tests/mock/mockconnectiondbus.cpp 2014-03-20 21:03:26 +0000
+++ tests/common/mock/mockconnectiondbus.cpp 2015-03-30 20:55:55 +0000
@@ -28,7 +28,9 @@
28MockConnectionDBus::MockConnectionDBus(MockConnection *parent) :28MockConnectionDBus::MockConnectionDBus(MockConnection *parent) :
29 QObject(parent), mAdaptor(0), mConnection(parent)29 QObject(parent), mAdaptor(0), mConnection(parent)
30{30{
3131 connect(mConnection,
32 SIGNAL(messageRead(QString)),
33 SIGNAL(MessageRead(QString)));
32 connect(mConnection,34 connect(mConnection,
33 SIGNAL(messageSent(QString,QVariantMap)),35 SIGNAL(messageSent(QString,QVariantMap)),
34 SIGNAL(MessageSent(QString,QVariantMap)));36 SIGNAL(MessageSent(QString,QVariantMap)));
@@ -50,10 +52,22 @@
50 connect(mConnection,52 connect(mConnection,
51 SIGNAL(channelSplitted(QString)),53 SIGNAL(channelSplitted(QString)),
52 SIGNAL(ChannelSplitted(QString)));54 SIGNAL(ChannelSplitted(QString)));
55 connect(mConnection,
56 SIGNAL(disconnected()),
57 SIGNAL(Disconnected()));
58 connect(mConnection,
59 SIGNAL(destroyed()),
60 SIGNAL(Destroyed()));
53 qDBusRegisterMetaType<QList<QVariantMap> >();61 qDBusRegisterMetaType<QList<QVariantMap> >();
62 mObjectPath = "/com/canonical/MockConnection/" + mConnection->protocolName();
54 connectToBus();63 connectToBus();
55}64}
5665
66MockConnectionDBus::~MockConnectionDBus()
67{
68 QDBusConnection::sessionBus().unregisterObject(mObjectPath, QDBusConnection::UnregisterTree);
69}
70
57bool MockConnectionDBus::connectToBus()71bool MockConnectionDBus::connectToBus()
58{72{
59 bool ok = QDBusConnection::sessionBus().registerService("com.canonical.MockConnection");73 bool ok = QDBusConnection::sessionBus().registerService("com.canonical.MockConnection");
@@ -65,7 +79,7 @@
65 mAdaptor = new MockConnectionAdaptor(this);79 mAdaptor = new MockConnectionAdaptor(this);
66 }80 }
6781
68 return QDBusConnection::sessionBus().registerObject("/com/canonical/MockConnection", this);82 return QDBusConnection::sessionBus().registerObject(mObjectPath, this);
69}83}
7084
71void MockConnectionDBus::PlaceIncomingMessage(const QString &message, const QVariantMap &properties)85void MockConnectionDBus::PlaceIncomingMessage(const QString &message, const QVariantMap &properties)
@@ -87,3 +101,39 @@
87{101{
88 mConnection->setCallState(phoneNumber, state);102 mConnection->setCallState(phoneNumber, state);
89}103}
104
105void MockConnectionDBus::SetOnline(bool online)
106{
107 mConnection->setOnline(online);
108}
109
110void MockConnectionDBus::SetPresence(const QString &status, const QString &statusMessage)
111{
112 Tp::DBusError error;
113 mConnection->setPresence(status, statusMessage, &error);
114}
115
116void MockConnectionDBus::SetVoicemailIndicator(bool active)
117{
118 mConnection->setVoicemailIndicator(active);
119}
120
121void MockConnectionDBus::SetVoicemailNumber(const QString &number)
122{
123 mConnection->setVoicemailNumber(number);
124}
125
126void MockConnectionDBus::SetVoicemailCount(int count)
127{
128 mConnection->setVoicemailCount(count);
129}
130
131void MockConnectionDBus::SetEmergencyNumbers(const QStringList &numbers)
132{
133 mConnection->setEmergencyNumbers(numbers);
134}
135
136QString MockConnectionDBus::Serial()
137{
138 return mConnection->serial();
139}
90140
=== modified file 'tests/common/mock/mockconnectiondbus.h'
--- handler/tests/mock/mockconnectiondbus.h 2014-03-20 21:03:26 +0000
+++ tests/common/mock/mockconnectiondbus.h 2015-03-30 20:55:55 +0000
@@ -30,15 +30,30 @@
30 Q_OBJECT30 Q_OBJECT
31public:31public:
32 explicit MockConnectionDBus(MockConnection *parent);32 explicit MockConnectionDBus(MockConnection *parent);
33 ~MockConnectionDBus();
3334
34 bool connectToBus();35 bool connectToBus();
35 void PlaceIncomingMessage(const QString &message, const QVariantMap &properties);36 void PlaceIncomingMessage(const QString &message, const QVariantMap &properties);
36 QString PlaceCall(const QVariantMap &properties);37 QString PlaceCall(const QVariantMap &properties);
37 void HangupCall(const QString &callerId);38 void HangupCall(const QString &callerId);
38 void SetCallState(const QString &phoneNumber, const QString &state);39 void SetCallState(const QString &phoneNumber, const QString &state);
40 void SetOnline(bool online);
41 void SetPresence(const QString &status, const QString &statusMessage);
42
43 // voicemail stuff
44 void SetVoicemailIndicator(bool active);
45 void SetVoicemailNumber(const QString &number);
46 void SetVoicemailCount(int count);
47
48 // emergency numbers stuff
49 void SetEmergencyNumbers(const QStringList &numbers);
50
51 // USSD stuff
52 QString Serial();
3953
40Q_SIGNALS:54Q_SIGNALS:
41 // signals that will be relayed into the bus55 // signals that will be relayed into the bus
56 void MessageRead(const QString &messageId);
42 void MessageSent(const QString &mesasge, const QVariantMap &properties);57 void MessageSent(const QString &mesasge, const QVariantMap &properties);
43 void CallReceived(const QString &callerId);58 void CallReceived(const QString &callerId);
44 void CallEnded(const QString &callerId);59 void CallEnded(const QString &callerId);
@@ -47,9 +62,13 @@
47 void ChannelMerged(const QString &objectPath);62 void ChannelMerged(const QString &objectPath);
48 void ChannelSplitted(const QString &objectPath);63 void ChannelSplitted(const QString &objectPath);
4964
65 void Disconnected();
66 void Destroyed();
67
50private:68private:
51 MockConnectionAdaptor *mAdaptor;69 MockConnectionAdaptor *mAdaptor;
52 MockConnection *mConnection;70 MockConnection *mConnection;
71 QString mObjectPath;
53};72};
5473
55#endif // MOCKCONNECTIONDBUS_H74#endif // MOCKCONNECTIONDBUS_H
5675
=== modified file 'tests/common/mock/protocol.cpp'
--- handler/tests/mock/protocol.cpp 2014-01-07 19:53:45 +0000
+++ tests/common/mock/protocol.cpp 2015-03-30 20:55:55 +0000
@@ -30,6 +30,19 @@
30 Tp::RequestableChannelClassSpec::audioCall());30 Tp::RequestableChannelClassSpec::audioCall());
3131
32 setCreateConnectionCallback(memFun(this, &Protocol::createConnection));32 setCreateConnectionCallback(memFun(this, &Protocol::createConnection));
33
34 Tp::ProtocolParameterList parameters;
35 Tp::ProtocolParameter parameter("modem-objpath", "s", 0);
36 parameters << parameter;
37 setParameters(parameters);
38
39 addressingIface = Tp::BaseProtocolAddressingInterface::create();
40 if (name == "ofono") {
41 addressingIface->setAddressableVCardFields(QStringList() << "tel");
42 } else {
43 addressingIface->setAddressableVCardFields(QStringList() << "x-mock-im" << "x-sip");
44 }
45 plugInterface(addressingIface);
33}46}
3447
35Tp::BaseConnectionPtr Protocol::createConnection(const QVariantMap &parameters, Tp::DBusError *error) {48Tp::BaseConnectionPtr Protocol::createConnection(const QVariantMap &parameters, Tp::DBusError *error) {
3649
=== modified file 'tests/common/mock/protocol.h'
--- handler/tests/mock/protocol.h 2014-01-07 19:53:45 +0000
+++ tests/common/mock/protocol.h 2015-03-30 20:55:55 +0000
@@ -31,6 +31,7 @@
3131
32public:32public:
33 Protocol(const QDBusConnection &dbusConnection, const QString &name);33 Protocol(const QDBusConnection &dbusConnection, const QString &name);
34 Tp::BaseProtocolAddressingInterfacePtr addressingIface;
3435
35private:36private:
36 Tp::BaseConnectionPtr createConnection(const QVariantMap &parameters, Tp::DBusError *error);37 Tp::BaseConnectionPtr createConnection(const QVariantMap &parameters, Tp::DBusError *error);
3738
=== modified file 'tests/common/mock/speakeriface.h'
--- handler/tests/mock/speakeriface.h 2014-03-13 17:11:09 +0000
+++ tests/common/mock/speakeriface.h 2015-03-30 20:55:55 +0000
@@ -1,19 +1,20 @@
1/**1/**
2 * Copyright (C) 2013 Canonical, Ltd.2 * Copyright (C) 2013-2015 Canonical, Ltd.
3 *3 *
4 * This program is free software: you can redistribute it and/or modify it under4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by5 * the terms of the GNU General Public License version 3, as published by
6 * the Free Software Foundation.6 * the Free Software Foundation.
7 *7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.11 * General Public License for more details.
12 *12 *
13 * You should have received a copy of the GNU Lesser General Public License13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *15 *
16 * Authors: Tiago Salem Herrmann <tiago.herrmann@canonical.com>16 * Authors: Tiago Salem Herrmann <tiago.herrmann@canonical.com>
17 Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>
17 */18 */
1819
19#ifndef OFONOSPEAKERIFACE_H20#ifndef OFONOSPEAKERIFACE_H
2021
=== modified file 'tests/common/mock/textchannel.cpp'
--- handler/tests/mock/textchannel.cpp 2014-01-07 19:53:45 +0000
+++ tests/common/mock/textchannel.cpp 2015-03-30 20:55:55 +0000
@@ -36,20 +36,24 @@
36 return argument;36 return argument;
37}37}
3838
39MockTextChannel::MockTextChannel(MockConnection *conn, QString phoneNumber, uint targetHandle, QObject *parent):39MockTextChannel::MockTextChannel(MockConnection *conn, QStringList recipients, uint targetHandle, QObject *parent):
40 QObject(parent),40 QObject(parent),
41 mConnection(conn),41 mConnection(conn),
42 mPhoneNumber(phoneNumber),42 mRecipients(recipients),
43 mTargetHandle(targetHandle),43 mTargetHandle(targetHandle),
44 mMessageCounter(1)44 mMessageCounter(1)
45{45{
46 qDBusRegisterMetaType<AttachmentStruct>();46 qDBusRegisterMetaType<AttachmentStruct>();
47 qDBusRegisterMetaType<AttachmentList>();47 qDBusRegisterMetaType<AttachmentList>();
4848
49 Tp::HandleType type = recipients.count() > 1 ? Tp::HandleTypeNone : Tp::HandleTypeContact;
50
51
49 Tp::BaseChannelPtr baseChannel = Tp::BaseChannel::create(mConnection,52 Tp::BaseChannelPtr baseChannel = Tp::BaseChannel::create(mConnection,
50 TP_QT_IFACE_CHANNEL_TYPE_TEXT,53 TP_QT_IFACE_CHANNEL_TYPE_TEXT,
51 targetHandle,54 targetHandle,
52 Tp::HandleTypeContact);55 type);
56 mBaseChannel = baseChannel;
53 Tp::BaseChannelTextTypePtr textType = Tp::BaseChannelTextType::create(baseChannel.data());57 Tp::BaseChannelTextTypePtr textType = Tp::BaseChannelTextType::create(baseChannel.data());
54 baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(textType));58 baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(textType));
5559
@@ -67,9 +71,15 @@
67 deliveryReportingSupport);71 deliveryReportingSupport);
6872
69 mMessagesIface->setSendMessageCallback(Tp::memFun(this,&MockTextChannel::sendMessage));73 mMessagesIface->setSendMessageCallback(Tp::memFun(this,&MockTextChannel::sendMessage));
70
71 baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(mMessagesIface));74 baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(mMessagesIface));
72 mBaseChannel = baseChannel;75
76 // group stuff
77 mGroupIface = Tp::BaseChannelGroupInterface::create(Tp::ChannelGroupFlagCanAdd, conn->selfHandle());
78 mGroupIface->setAddMembersCallback(Tp::memFun(this,&MockTextChannel::onAddMembers));
79 mGroupIface->setRemoveMembersCallback(Tp::memFun(this,&MockTextChannel::onRemoveMembers));
80 baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(mGroupIface));
81 addMembers(recipients);
82
73 mTextChannel = Tp::BaseChannelTextTypePtr::dynamicCast(mBaseChannel->interface(TP_QT_IFACE_CHANNEL_TYPE_TEXT));83 mTextChannel = Tp::BaseChannelTextTypePtr::dynamicCast(mBaseChannel->interface(TP_QT_IFACE_CHANNEL_TYPE_TEXT));
74 mTextChannel->setMessageAcknowledgedCallback(Tp::memFun(this,&MockTextChannel::messageAcknowledged));84 mTextChannel->setMessageAcknowledgedCallback(Tp::memFun(this,&MockTextChannel::messageAcknowledged));
75 QObject::connect(mBaseChannel.data(), SIGNAL(closed()), this, SLOT(deleteLater()));85 QObject::connect(mBaseChannel.data(), SIGNAL(closed()), this, SLOT(deleteLater()));
@@ -101,11 +111,20 @@
101 QString messageText = body["content"].variant().toString();111 QString messageText = body["content"].variant().toString();
102 QVariantMap properties;112 QVariantMap properties;
103 properties["SentTime"] = QDateTime::currentDateTime().toString(Qt::ISODate);113 properties["SentTime"] = QDateTime::currentDateTime().toString(Qt::ISODate);
104 properties["Recipients"] = QStringList() << mPhoneNumber;114 properties["Recipients"] = mRecipients;
105 properties["Id"] = id;115 properties["Id"] = id;
106116
107 Q_EMIT messageSent(messageText, properties);117 Q_EMIT messageSent(messageText, properties);
108118
119 QTimer *deliveryReportTimer = new QTimer(this);
120 deliveryReportTimer->setSingleShot(true);
121 deliveryReportTimer->setInterval(100);
122 connect(deliveryReportTimer, &QTimer::timeout, [id, deliveryReportTimer, this] {
123 this->placeDeliveryReport(id, "sent");
124 deliveryReportTimer->deleteLater();
125 });
126 deliveryReportTimer->start();
127
109 return id;128 return id;
110}129}
111130
@@ -125,7 +144,8 @@
125 Tp::MessagePartList partList;144 Tp::MessagePartList partList;
126 Tp::MessagePart header;145 Tp::MessagePart header;
127 header["message-sender"] = QDBusVariant(mTargetHandle);146 header["message-sender"] = QDBusVariant(mTargetHandle);
128 header["message-sender-id"] = QDBusVariant(mPhoneNumber);147 // FIXME: fix it
148 header["message-sender-id"] = QDBusVariant(mRecipients.first());
129 header["message-type"] = QDBusVariant(Tp::ChannelTextMessageTypeDeliveryReport);149 header["message-type"] = QDBusVariant(Tp::ChannelTextMessageTypeDeliveryReport);
130 header["delivery-status"] = QDBusVariant(delivery_status);150 header["delivery-status"] = QDBusVariant(delivery_status);
131 header["delivery-token"] = QDBusVariant(messageId);151 header["delivery-token"] = QDBusVariant(messageId);
@@ -145,7 +165,7 @@
145 header["message-token"] = QDBusVariant(info["SentTime"].toString() +"-" + QString::number(mMessageCounter++));165 header["message-token"] = QDBusVariant(info["SentTime"].toString() +"-" + QString::number(mMessageCounter++));
146 header["message-received"] = QDBusVariant(QDateTime::fromString(info["SentTime"].toString(), Qt::ISODate).toTime_t());166 header["message-received"] = QDBusVariant(QDateTime::fromString(info["SentTime"].toString(), Qt::ISODate).toTime_t());
147 header["message-sender"] = QDBusVariant(mTargetHandle);167 header["message-sender"] = QDBusVariant(mTargetHandle);
148 header["message-sender-id"] = QDBusVariant(mPhoneNumber);168 header["message-sender-id"] = QDBusVariant(mRecipients.first());
149 header["message-type"] = QDBusVariant(Tp::ChannelTextMessageTypeNormal);169 header["message-type"] = QDBusVariant(Tp::ChannelTextMessageTypeNormal);
150 partList << header << body;170 partList << header << body;
151171
@@ -198,3 +218,45 @@
198218
199 mTextChannel->addReceivedMessage(message);219 mTextChannel->addReceivedMessage(message);
200}220}
221
222void MockTextChannel::addMembers(QStringList recipients)
223{
224 Tp::UIntList handles;
225 Q_FOREACH(const QString &recipient, recipients) {
226 uint handle = mConnection->ensureHandle(recipient);
227 handles << handle;
228 if (!mRecipients.contains(recipient)) {
229 mRecipients << recipient;
230 }
231 if (!mMembers.contains(handle)) {
232 mMembers << handle;
233 }
234 }
235 mGroupIface->addMembers(handles, recipients);
236}
237
238QStringList MockTextChannel::recipients() const
239{
240 return mRecipients;
241}
242
243Tp::UIntList MockTextChannel::members()
244{
245 return mMembers;
246}
247
248void MockTextChannel::onAddMembers(const Tp::UIntList &handles, const QString &message, Tp::DBusError *error)
249{
250 addMembers(mConnection->inspectHandles(Tp::HandleTypeContact, handles, error));
251}
252
253void MockTextChannel::onRemoveMembers(const Tp::UIntList &handles, const QString &message, Tp::DBusError *error)
254{
255 Q_FOREACH(uint handle, handles) {
256 Q_FOREACH(const QString &recipient, mConnection->inspectHandles(Tp::HandleTypeContact, Tp::UIntList() << handle, error)) {
257 mRecipients.removeAll(recipient);
258 }
259 mMembers.removeAll(handle);
260 }
261 mGroupIface->removeMembers(handles);
262}
201263
=== modified file 'tests/common/mock/textchannel.h'
--- handler/tests/mock/textchannel.h 2014-01-07 19:53:45 +0000
+++ tests/common/mock/textchannel.h 2015-03-30 20:55:55 +0000
@@ -35,13 +35,19 @@
35{35{
36 Q_OBJECT36 Q_OBJECT
37public:37public:
38 MockTextChannel(MockConnection *conn, QString phoneNumber, uint targetHandle, QObject *parent = 0);38 MockTextChannel(MockConnection *conn, QStringList recipients, uint targetHandle, QObject *parent = 0);
39 QString sendMessage(const Tp::MessagePartList& message, uint flags, Tp::DBusError* error);39 QString sendMessage(const Tp::MessagePartList& message, uint flags, Tp::DBusError* error);
40 void messageReceived(const QString & message, const QVariantMap &info);40 void messageReceived(const QString & message, const QVariantMap &info);
41 Tp::BaseChannelPtr baseChannel();41 Tp::BaseChannelPtr baseChannel();
42 void messageAcknowledged(const QString &id);42 void messageAcknowledged(const QString &id);
43 void mmsReceived(const QString &id, const QVariantMap &properties);43 void mmsReceived(const QString &id, const QVariantMap &properties);
4444
45 void addMembers(QStringList recipients);
46 QStringList recipients() const;
47 Tp::UIntList members();
48 void onAddMembers(const Tp::UIntList& handles, const QString& message, Tp::DBusError* error);
49 void onRemoveMembers(const Tp::UIntList& handles, const QString& message, Tp::DBusError* error);
50
45public Q_SLOTS:51public Q_SLOTS:
46 void placeDeliveryReport(const QString &messageId, const QString &status);52 void placeDeliveryReport(const QString &messageId, const QString &status);
4753
@@ -52,12 +58,14 @@
52private:58private:
53 ~MockTextChannel();59 ~MockTextChannel();
54 Tp::BaseChannelPtr mBaseChannel;60 Tp::BaseChannelPtr mBaseChannel;
55 QString mPhoneNumber;61 QStringList mRecipients;
56 MockConnection *mConnection;62 MockConnection *mConnection;
57 uint mTargetHandle;63 uint mTargetHandle;
58 Tp::BaseChannelMessagesInterfacePtr mMessagesIface;64 Tp::BaseChannelMessagesInterfacePtr mMessagesIface;
65 Tp::BaseChannelGroupInterfacePtr mGroupIface;
59 Tp::BaseChannelTextTypePtr mTextChannel;66 Tp::BaseChannelTextTypePtr mTextChannel;
60 uint mMessageCounter;67 uint mMessageCounter;
68 Tp::UIntList mMembers;
61};69};
6270
63#endif // MOCKTEXTCHANNEL_H71#endif // MOCKTEXTCHANNEL_H
6472
=== added file 'tests/common/mock/ussdiface.cpp'
--- tests/common/mock/ussdiface.cpp 1970-01-01 00:00:00 +0000
+++ tests/common/mock/ussdiface.cpp 2015-03-30 20:55:55 +0000
@@ -0,0 +1,312 @@
1/**
2 * Copyright (C) 2013-2015 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Tiago Salem Herrmann <tiago.herrmann@canonical.com>
17 Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>
18 */
19
20#include <QDebug>
21
22#include <TelepathyQt/Constants>
23#include <TelepathyQt/DBusObject>
24
25#include "ussdiface.h"
26
27// Conn.I.USSD
28BaseConnectionUSSDInterface::Adaptee::Adaptee(BaseConnectionUSSDInterface *interface)
29 : QObject(interface),
30 mInterface(interface)
31{
32}
33
34
35struct TP_QT_NO_EXPORT BaseConnectionUSSDInterface::Private {
36 Private(BaseConnectionUSSDInterface *parent)
37 : adaptee(new BaseConnectionUSSDInterface::Adaptee(parent)) {
38 }
39 QString state;
40 QString serial;
41 InitiateCallback initiateCB;
42 RespondCallback respondCB;
43 CancelCallback cancelCB;
44 BaseConnectionUSSDInterface::Adaptee *adaptee;
45};
46
47BaseConnectionUSSDInterface::Adaptee::~Adaptee()
48{
49}
50
51void BaseConnectionUSSDInterface::Adaptee::initiate(const QString &command, const ConnectionInterfaceUSSDAdaptor::InitiateContextPtr &context)
52{
53 if (!mInterface->mPriv->initiateCB.isValid()) {
54 context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"));
55 return;
56 }
57 Tp::DBusError error;
58 mInterface->mPriv->initiateCB(command, &error);
59 if (error.isValid()) {
60 context->setFinishedWithError(error.name(), error.message());
61 return;
62 }
63 context->setFinished();
64}
65
66void BaseConnectionUSSDInterface::Adaptee::respond(const QString &reply, const ConnectionInterfaceUSSDAdaptor::RespondContextPtr &context)
67{
68 if (!mInterface->mPriv->respondCB.isValid()) {
69 context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"));
70 return;
71 }
72 Tp::DBusError error;
73 mInterface->mPriv->respondCB(reply, &error);
74 if (error.isValid()) {
75 context->setFinishedWithError(error.name(), error.message());
76 return;
77 }
78 context->setFinished();
79}
80
81void BaseConnectionUSSDInterface::Adaptee::cancel(const ConnectionInterfaceUSSDAdaptor::CancelContextPtr &context)
82{
83 if (!mInterface->mPriv->cancelCB.isValid()) {
84 context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"));
85 return;
86 }
87 Tp::DBusError error;
88 mInterface->mPriv->cancelCB(&error);
89 if (error.isValid()) {
90 context->setFinishedWithError(error.name(), error.message());
91 return;
92 }
93 context->setFinished();
94}
95
96BaseConnectionUSSDInterface::BaseConnectionUSSDInterface()
97 : AbstractConnectionInterface(TP_QT_IFACE_CONNECTION_USSD),
98 mPriv(new Private(this))
99{
100}
101
102BaseConnectionUSSDInterface::~BaseConnectionUSSDInterface()
103{
104 delete mPriv;
105}
106
107void BaseConnectionUSSDInterface::setInitiateCallback(const InitiateCallback &cb)
108{
109 mPriv->initiateCB = cb;
110}
111
112void BaseConnectionUSSDInterface::setRespondCallback(const RespondCallback &cb)
113{
114 mPriv->respondCB = cb;
115}
116
117void BaseConnectionUSSDInterface::setCancelCallback(const CancelCallback &cb)
118{
119 mPriv->cancelCB = cb;
120}
121
122QString BaseConnectionUSSDInterface::state() const
123{
124 return mPriv->state;
125}
126
127void BaseConnectionUSSDInterface::setSerial(const QString &serial) const
128{
129 mPriv->serial = serial;
130}
131
132
133QString BaseConnectionUSSDInterface::serial() const
134{
135 return mPriv->serial;
136}
137
138void BaseConnectionUSSDInterface::StateChanged(const QString &state)
139{
140 mPriv->state = state;
141 Q_EMIT mPriv->adaptee->stateChanged(state);
142}
143
144void BaseConnectionUSSDInterface::InitiateUSSDComplete(const QString &ussdResp)
145{
146 Q_EMIT mPriv->adaptee->initiateUSSDComplete(ussdResp);
147}
148
149void BaseConnectionUSSDInterface::RespondComplete(bool success, const QString &ussdResp)
150{
151 Q_EMIT mPriv->adaptee->respondComplete(success, ussdResp);
152}
153
154void BaseConnectionUSSDInterface::BarringComplete(const QString &ssOp, const QString &cbService, const QVariantMap &cbMap)
155{
156 Q_EMIT mPriv->adaptee->barringComplete(ssOp, cbService, cbMap);
157}
158
159void BaseConnectionUSSDInterface::ForwardingComplete(const QString &ssOp, const QString &cfService, const QVariantMap &cfMap)
160{
161 Q_EMIT mPriv->adaptee->forwardingComplete(ssOp, cfService, cfMap);
162}
163
164void BaseConnectionUSSDInterface::WaitingComplete(const QString &ssOp, const QVariantMap &cwMap)
165{
166 Q_EMIT mPriv->adaptee->waitingComplete(ssOp, cwMap);
167}
168
169void BaseConnectionUSSDInterface::CallingLinePresentationComplete(const QString &ssOp, const QString &status)
170{
171 Q_EMIT mPriv->adaptee->callingLinePresentationComplete(ssOp, status);
172}
173
174void BaseConnectionUSSDInterface::ConnectedLinePresentationComplete(const QString &ssOp, const QString &status)
175{
176 Q_EMIT mPriv->adaptee->connectedLinePresentationComplete(ssOp, status);
177}
178
179void BaseConnectionUSSDInterface::CallingLineRestrictionComplete(const QString &ssOp, const QString &status)
180{
181 Q_EMIT mPriv->adaptee->callingLineRestrictionComplete(ssOp, status);
182}
183
184void BaseConnectionUSSDInterface::ConnectedLineRestrictionComplete(const QString &ssOp, const QString &status)
185{
186 Q_EMIT mPriv->adaptee->connectedLineRestrictionComplete(ssOp, status);
187}
188
189void BaseConnectionUSSDInterface::InitiateFailed()
190{
191 Q_EMIT mPriv->adaptee->initiateFailed();
192}
193
194void BaseConnectionUSSDInterface::NotificationReceived(const QString &message)
195{
196 Q_EMIT mPriv->adaptee->notificationReceived(message);
197}
198
199void BaseConnectionUSSDInterface::RequestReceived(const QString &message)
200{
201 Q_EMIT mPriv->adaptee->requestReceived(message);
202}
203
204
205QVariantMap BaseConnectionUSSDInterface::immutableProperties() const
206{
207 QVariantMap map;
208 return map;
209}
210
211void BaseConnectionUSSDInterface::createAdaptor()
212{
213 (void) new ConnectionInterfaceUSSDAdaptor(dbusObject()->dbusConnection(),
214 mPriv->adaptee, dbusObject());
215}
216
217
218ConnectionInterfaceUSSDAdaptor::ConnectionInterfaceUSSDAdaptor(const QDBusConnection& bus, QObject* adaptee, QObject* parent)
219 : Tp::AbstractAdaptor(bus, adaptee, parent)
220{
221 connect(adaptee, SIGNAL(notificationReceived(const QString &)), SIGNAL(NotificationReceived(const QString &)));
222 connect(adaptee, SIGNAL(requestReceived(const QString &)), SIGNAL(RequestReceived(const QString &)));
223
224 connect(adaptee, SIGNAL(initiateUSSDComplete(const QString &)), SIGNAL(InitiateUSSDComplete(const QString &)));
225
226 connect(adaptee, SIGNAL(barringComplete(const QString &, const QString &, const QVariantMap &)),
227 SIGNAL(BarringComplete(const QString &, const QString &, const QVariantMap &)));
228
229 connect(adaptee, SIGNAL(forwardingComplete(const QString &, const QString &, const QVariantMap &)),
230 SIGNAL(ForwardingComplete(const QString &, const QString &, const QVariantMap &)));
231
232 connect(adaptee, SIGNAL(waitingComplete(const QString &, const QVariantMap &)),
233 SIGNAL(WaitingComplete(const QString &, const QVariantMap &)));
234
235 connect(adaptee, SIGNAL(callingLinePresentationComplete(const QString &, const QString &)),
236 SIGNAL(CallingLinePresentationComplete(const QString &, const QString &)));
237
238 connect(adaptee, SIGNAL(connectedLinePresentationComplete(const QString &, const QString &)),
239 SIGNAL(ConnectedLinePresentationComplete(const QString &, const QString &)));
240
241 connect(adaptee, SIGNAL(callingLineRestrictionComplete(const QString &, const QString &)),
242 SIGNAL(CallingLineRestrictionComplete(const QString &, const QString &)));
243
244 connect(adaptee, SIGNAL(connectedLineRestrictionComplete(const QString &, const QString &)),
245 SIGNAL(ConnectedLineRestrictionComplete(const QString &, const QString &)));
246
247 connect(adaptee, SIGNAL(initiateFailed()), SIGNAL(InitiateFailed()));
248
249 connect(adaptee, SIGNAL(stateChanged(const QString&)), SIGNAL(StateChanged(const QString&)));
250
251 connect(adaptee, SIGNAL(respondComplete(bool, const QString &)), SIGNAL(RespondComplete(bool, const QString &)));
252}
253
254ConnectionInterfaceUSSDAdaptor::~ConnectionInterfaceUSSDAdaptor()
255{
256}
257
258void ConnectionInterfaceUSSDAdaptor::Initiate(const QString &command, const QDBusMessage& dbusMessage)
259{
260 if (!adaptee()->metaObject()->indexOfMethod("initiate(const QString &,ConnectionInterfaceUSSDAdaptor::InitiateContextPtr)") == -1) {
261 dbusConnection().send(dbusMessage.createErrorReply(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")));
262 return;
263 }
264
265 InitiateContextPtr ctx = InitiateContextPtr(
266 new Tp::MethodInvocationContext< >(dbusConnection(), dbusMessage));
267 QMetaObject::invokeMethod(adaptee(), "initiate",
268 Q_ARG(QString, command),
269 Q_ARG(ConnectionInterfaceUSSDAdaptor::InitiateContextPtr, ctx));
270 return;
271}
272
273void ConnectionInterfaceUSSDAdaptor::Respond(const QString &reply, const QDBusMessage& dbusMessage)
274{
275 if (!adaptee()->metaObject()->indexOfMethod("respond(QConnectionInterfaceUSSDAdaptor::RespondContextPtr)") == -1) {
276 dbusConnection().send(dbusMessage.createErrorReply(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")));
277 return;
278 }
279
280 RespondContextPtr ctx = RespondContextPtr(
281 new Tp::MethodInvocationContext< >(dbusConnection(), dbusMessage));
282 QMetaObject::invokeMethod(adaptee(), "respond",
283 Q_ARG(QString, reply),
284 Q_ARG(ConnectionInterfaceUSSDAdaptor::RespondContextPtr, ctx));
285 return;
286}
287
288void ConnectionInterfaceUSSDAdaptor::Cancel(const QDBusMessage& dbusMessage)
289{
290 if (!adaptee()->metaObject()->indexOfMethod("cancel(ConnectionInterfaceUSSDAdaptor::CancelContextPtr)") == -1) {
291 dbusConnection().send(dbusMessage.createErrorReply(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")));
292 return;
293 }
294
295 CancelContextPtr ctx = CancelContextPtr(
296 new Tp::MethodInvocationContext< >(dbusConnection(), dbusMessage));
297 QMetaObject::invokeMethod(adaptee(), "cancel",
298 Q_ARG(ConnectionInterfaceUSSDAdaptor::CancelContextPtr, ctx));
299 return;
300}
301
302QString ConnectionInterfaceUSSDAdaptor::Serial() const
303{
304 return qvariant_cast< QString >(adaptee()->property("serial"));
305}
306
307
308QString ConnectionInterfaceUSSDAdaptor::State() const
309{
310 return qvariant_cast< QString >(adaptee()->property("state"));
311}
312
0313
=== added file 'tests/common/mock/ussdiface.h'
--- tests/common/mock/ussdiface.h 1970-01-01 00:00:00 +0000
+++ tests/common/mock/ussdiface.h 2015-03-30 20:55:55 +0000
@@ -0,0 +1,244 @@
1/**
2 * Copyright (C) 2013-2015 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Tiago Salem Herrmann <tiago.herrmann@canonical.com>
17 Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>
18 */
19
20#ifndef OFONOUSSDIFACE_H
21#define OFONOUSSDIFACE_H
22
23// telepathy-qt
24#include <TelepathyQt/Constants>
25#include <TelepathyQt/BaseConnection>
26#include <TelepathyQt/AbstractAdaptor>
27#include <TelepathyQt/DBusError>
28#include <TelepathyQt/Callbacks>
29
30class BaseConnectionUSSDInterface;
31
32typedef Tp::SharedPtr<BaseConnectionUSSDInterface> BaseConnectionUSSDInterfacePtr;
33
34#define TP_QT_IFACE_CONNECTION_USSD "com.canonical.Telephony.USSD"
35
36class TP_QT_EXPORT BaseConnectionUSSDInterface : public Tp::AbstractConnectionInterface
37{
38 Q_OBJECT
39 Q_DISABLE_COPY(BaseConnectionUSSDInterface)
40
41public:
42 static BaseConnectionUSSDInterfacePtr create() {
43 return BaseConnectionUSSDInterfacePtr(new BaseConnectionUSSDInterface());
44 }
45 template<typename BaseConnectionUSSDInterfaceSubclass>
46 static Tp::SharedPtr<BaseConnectionUSSDInterfaceSubclass> create() {
47 return Tp::SharedPtr<BaseConnectionUSSDInterfaceSubclass>(
48 new BaseConnectionUSSDInterfaceSubclass());
49 }
50 QVariantMap immutableProperties() const;
51 virtual ~BaseConnectionUSSDInterface();
52
53 typedef Tp::Callback2<void, const QString&, Tp::DBusError*> InitiateCallback;
54 void setInitiateCallback(const InitiateCallback &cb);
55
56 typedef Tp::Callback2<void, const QString&, Tp::DBusError*> RespondCallback;
57 void setRespondCallback(const RespondCallback &cb);
58
59 typedef Tp::Callback1<void, Tp::DBusError*> CancelCallback;
60 void setCancelCallback(const CancelCallback &cb);
61
62
63 QString state() const;
64 QString serial() const;
65
66public Q_SLOTS:
67 void NotificationReceived(const QString &message);
68 void RequestReceived(const QString &message);
69
70 void InitiateUSSDComplete(const QString &ussdResp);
71 void RespondComplete(bool success, const QString &ussdResp);
72 void BarringComplete(const QString &ssOp, const QString &cbService, const QVariantMap &cbMap);
73 void ForwardingComplete(const QString &ssOp, const QString &cfService, const QVariantMap &cfMap);
74 void WaitingComplete(const QString &ssOp, const QVariantMap &cwMap);
75 void CallingLinePresentationComplete(const QString &ssOp, const QString &status);
76 void ConnectedLinePresentationComplete(const QString &ssOp, const QString &status);
77 void CallingLineRestrictionComplete(const QString &ssOp, const QString &status);
78 void ConnectedLineRestrictionComplete(const QString &ssOp, const QString &status);
79 void InitiateFailed();
80 void StateChanged(const QString &state);
81
82 void setSerial(const QString& serial) const;
83protected:
84 BaseConnectionUSSDInterface();
85
86private:
87 void createAdaptor();
88
89 class Adaptee;
90 friend class Adaptee;
91 struct Private;
92 friend struct Private;
93 Private *mPriv;
94};
95
96
97class TP_QT_EXPORT ConnectionInterfaceUSSDAdaptor : public Tp::AbstractAdaptor
98{
99 Q_OBJECT
100 Q_CLASSINFO("D-Bus Interface", TP_QT_IFACE_CONNECTION_USSD)
101 Q_CLASSINFO("D-Bus Introspection", ""
102" <interface name=\"com.canonical.Telephony.USSD\">\n"
103" <property access=\"read\" type=\"s\" name=\"State\"/>\n"
104" <property access=\"read\" type=\"s\" name=\"Serial\"/>\n"
105" <method name=\"Initiate\">\n"
106" <arg direction=\"in\" type=\"s\" name=\"command\"/>\n"
107" </method>\n"
108" <method name=\"Respond\">\n"
109" <arg direction=\"in\" type=\"s\" name=\"reply\"/>\n"
110" </method>\n"
111" <method name=\"Cancel\" />\n"
112" <signal name=\"NotificationReceived\">\n"
113" <arg type=\"s\" name=\"message\"/>\n"
114" </signal>\n"
115" <signal name=\"RequestReceived\">\n"
116" <arg type=\"s\" name=\"message\"/>\n"
117" </signal>\n"
118" <signal name=\"InitiateUSSDComplete\">\n"
119" <arg type=\"s\" name=\"response\"/>\n"
120" </signal>\n"
121" <signal name=\"RespondComplete\">\n"
122" <arg type=\"b\" name=\"success\"/>\n"
123" <arg type=\"s\" name=\"response\"/>\n"
124" </signal>\n"
125" <signal name=\"BarringComplete\">\n"
126" <arg type=\"s\" name=\"ssOp\"/>\n"
127" <arg type=\"s\" name=\"cbService\"/>\n"
128" <arg type=\"a{sv}\" name=\"cbMap\"/>\n"
129" </signal>\n"
130" <signal name=\"ForwardingComplete\">\n"
131" <arg type=\"s\" name=\"ssOp\"/>\n"
132" <arg type=\"s\" name=\"cfService\"/>\n"
133" <arg type=\"a{sv}\" name=\"cfMap\"/>\n"
134" </signal>\n"
135" <signal name=\"WaitingComplete\">\n"
136" <arg type=\"s\" name=\"ssOp\"/>\n"
137" <arg type=\"a{sv}\" name=\"cwMap\"/>\n"
138" </signal>\n"
139" <signal name=\"CallingLinePresentationComplete\">\n"
140" <arg type=\"s\" name=\"ssOp\"/>\n"
141" <arg type=\"s\" name=\"status\"/>\n"
142" </signal>\n"
143" <signal name=\"ConnectedLinePresentationComplete\">\n"
144" <arg type=\"s\" name=\"ssOp\"/>\n"
145" <arg type=\"s\" name=\"status\"/>\n"
146" </signal>\n"
147" <signal name=\"CallingLineRestrictionComplete\">\n"
148" <arg type=\"s\" name=\"ssOp\"/>\n"
149" <arg type=\"s\" name=\"status\"/>\n"
150" </signal>\n"
151" <signal name=\"ConnectedLineRestrictionComplete\">\n"
152" <arg type=\"s\" name=\"ssOp\"/>\n"
153" <arg type=\"s\" name=\"status\"/>\n"
154" </signal>\n"
155" <signal name=\"InitiateFailed\" />\n"
156" <signal name=\"StateChanged\">\n"
157" <arg type=\"s\" name=\"state\"/>\n"
158" </signal>\n"
159" </interface>\n"
160"")
161 Q_PROPERTY(QString State READ State)
162 Q_PROPERTY(QString Serial READ Serial)
163
164public:
165 ConnectionInterfaceUSSDAdaptor(const QDBusConnection& dbusConnection, QObject* adaptee, QObject* parent);
166 virtual ~ConnectionInterfaceUSSDAdaptor();
167
168 typedef Tp::MethodInvocationContextPtr< > InitiateContextPtr;
169 typedef Tp::MethodInvocationContextPtr< > RespondContextPtr;
170 typedef Tp::MethodInvocationContextPtr< > CancelContextPtr;
171
172public Q_SLOTS: // METHODS
173 void Initiate(const QString &command, const QDBusMessage& dbusMessage);
174 void Respond(const QString &reply, const QDBusMessage& dbusMessage);
175 void Cancel(const QDBusMessage& dbusMessage);
176
177 QString State() const;
178 QString Serial() const;
179
180Q_SIGNALS: // SIGNALS
181 void NotificationReceived(const QString &message);
182 void RequestReceived(const QString &message);
183
184 void InitiateUSSDComplete(const QString &ussdResp);
185 void RespondComplete(bool success, const QString &ussdResp);
186 void BarringComplete(const QString &ssOp, const QString &cbService, const QVariantMap &cbMap);
187 void ForwardingComplete(const QString &ssOp, const QString &cfService, const QVariantMap &cfMap);
188 void WaitingComplete(const QString &ssOp, const QVariantMap &cwMap);
189 void CallingLinePresentationComplete(const QString &ssOp, const QString &status);
190 void ConnectedLinePresentationComplete(const QString &ssOp, const QString &status);
191 void CallingLineRestrictionComplete(const QString &ssOp, const QString &status);
192 void ConnectedLineRestrictionComplete(const QString &ssOp, const QString &status);
193 void InitiateFailed();
194
195 void StateChanged(const QString &state);
196};
197
198
199class TP_QT_NO_EXPORT BaseConnectionUSSDInterface::Adaptee : public QObject
200{
201 Q_OBJECT
202 Q_PROPERTY(QString state READ state)
203 Q_PROPERTY(QString serial READ serial)
204
205public:
206 Adaptee(BaseConnectionUSSDInterface *interface);
207 ~Adaptee();
208 QString state() const
209 {
210 return mInterface->state();
211 }
212 QString serial() const
213 {
214 return mInterface->serial();
215 }
216
217
218private Q_SLOTS:
219 void initiate(const QString &command, const ConnectionInterfaceUSSDAdaptor::InitiateContextPtr &context);
220 void respond(const QString &reply, const ConnectionInterfaceUSSDAdaptor::RespondContextPtr &context);
221 void cancel(const ConnectionInterfaceUSSDAdaptor::CancelContextPtr &context);
222
223Q_SIGNALS:
224 void notificationReceived(const QString &message);
225 void requestReceived(const QString &message);
226
227 void initiateUSSDComplete(const QString &ussdResp);
228 void barringComplete(const QString &ssOp, const QString &cbService, const QVariantMap &cbMap);
229 void forwardingComplete(const QString &ssOp, const QString &cfService, const QVariantMap &cfMap);
230 void waitingComplete(const QString &ssOp, const QVariantMap &cwMap);
231 void callingLinePresentationComplete(const QString &ssOp, const QString &status);
232 void connectedLinePresentationComplete(const QString &ssOp, const QString &status);
233 void callingLineRestrictionComplete(const QString &ssOp, const QString &status);
234 void connectedLineRestrictionComplete(const QString &ssOp, const QString &status);
235 void initiateFailed();
236 void respondComplete(bool success, const QString &response);
237
238 void stateChanged(const QString &state);
239
240public:
241 BaseConnectionUSSDInterface *mInterface;
242};
243
244#endif
0245
=== added file 'tests/common/mock/voicemailiface.cpp'
--- tests/common/mock/voicemailiface.cpp 1970-01-01 00:00:00 +0000
+++ tests/common/mock/voicemailiface.cpp 2015-03-30 20:55:55 +0000
@@ -0,0 +1,202 @@
1/**
2 * Copyright (C) 2013-2015 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Tiago Salem Herrmann <tiago.herrmann@canonical.com>
17 Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>
18 */
19
20#include <QDebug>
21
22#include <TelepathyQt/Constants>
23#include <TelepathyQt/DBusObject>
24
25#include "voicemailiface.h"
26
27// Conn.I.Voicemail
28BaseConnectionVoicemailInterface::Adaptee::Adaptee(BaseConnectionVoicemailInterface *interface)
29 : QObject(interface),
30 mInterface(interface)
31{
32}
33
34
35struct TP_QT_NO_EXPORT BaseConnectionVoicemailInterface::Private {
36 Private(BaseConnectionVoicemailInterface *parent)
37 : adaptee(new BaseConnectionVoicemailInterface::Adaptee(parent)) {
38 }
39 VoicemailCountCallback voicemailCountCB;
40 VoicemailNumberCallback voicemailNumberCB;
41 VoicemailIndicatorCallback voicemailIndicatorCB;
42 BaseConnectionVoicemailInterface::Adaptee *adaptee;
43};
44
45BaseConnectionVoicemailInterface::Adaptee::~Adaptee()
46{
47}
48
49void BaseConnectionVoicemailInterface::Adaptee::voicemailIndicator(const ConnectionInterfaceVoicemailAdaptor::VoicemailIndicatorContextPtr &context)
50{
51 if (!mInterface->mPriv->voicemailIndicatorCB.isValid()) {
52 context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"));
53 return;
54 }
55 Tp::DBusError error;
56 bool active = mInterface->mPriv->voicemailIndicatorCB(&error);
57 if (error.isValid()) {
58 context->setFinishedWithError(error.name(), error.message());
59 return;
60 }
61 context->setFinished(active);
62}
63
64void BaseConnectionVoicemailInterface::Adaptee::voicemailNumber(const ConnectionInterfaceVoicemailAdaptor::VoicemailNumberContextPtr &context)
65{
66 if (!mInterface->mPriv->voicemailNumberCB.isValid()) {
67 context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"));
68 return;
69 }
70 Tp::DBusError error;
71 QString number = mInterface->mPriv->voicemailNumberCB(&error);
72 if (error.isValid()) {
73 context->setFinishedWithError(error.name(), error.message());
74 return;
75 }
76 context->setFinished(number);
77}
78
79void BaseConnectionVoicemailInterface::Adaptee::voicemailCount(const ConnectionInterfaceVoicemailAdaptor::VoicemailCountContextPtr &context)
80{
81 if (!mInterface->mPriv->voicemailCountCB.isValid()) {
82 context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"));
83 return;
84 }
85 Tp::DBusError error;
86 uint count = mInterface->mPriv->voicemailCountCB(&error);
87 if (error.isValid()) {
88 context->setFinishedWithError(error.name(), error.message());
89 return;
90 }
91 context->setFinished(count);
92}
93
94
95BaseConnectionVoicemailInterface::BaseConnectionVoicemailInterface()
96 : AbstractConnectionInterface(TP_QT_IFACE_CONNECTION_VOICEMAIL),
97 mPriv(new Private(this))
98{
99}
100
101BaseConnectionVoicemailInterface::~BaseConnectionVoicemailInterface()
102{
103 delete mPriv;
104}
105
106void BaseConnectionVoicemailInterface::setVoicemailIndicatorCallback(const VoicemailIndicatorCallback &cb)
107{
108 mPriv->voicemailIndicatorCB = cb;
109}
110
111void BaseConnectionVoicemailInterface::setVoicemailNumberCallback(const VoicemailNumberCallback &cb)
112{
113 mPriv->voicemailNumberCB = cb;
114}
115
116void BaseConnectionVoicemailInterface::setVoicemailCountCallback(const VoicemailCountCallback &cb)
117{
118 mPriv->voicemailCountCB = cb;
119}
120
121void BaseConnectionVoicemailInterface::setVoicemailCount(int count)
122{
123 Q_EMIT mPriv->adaptee->voicemailCountChanged(uint(count));
124}
125
126void BaseConnectionVoicemailInterface::setVoicemailNumber(const QString &voicemailNumber)
127{
128 Q_EMIT mPriv->adaptee->voicemailNumberChanged(voicemailNumber);
129}
130
131void BaseConnectionVoicemailInterface::setVoicemailIndicator(bool active)
132{
133 Q_EMIT mPriv->adaptee->voicemailIndicatorChanged(active);
134}
135
136QVariantMap BaseConnectionVoicemailInterface::immutableProperties() const
137{
138 QVariantMap map;
139 return map;
140}
141
142void BaseConnectionVoicemailInterface::createAdaptor()
143{
144 (void) new ConnectionInterfaceVoicemailAdaptor(dbusObject()->dbusConnection(),
145 mPriv->adaptee, dbusObject());
146}
147
148
149ConnectionInterfaceVoicemailAdaptor::ConnectionInterfaceVoicemailAdaptor(const QDBusConnection& bus, QObject* adaptee, QObject* parent)
150 : Tp::AbstractAdaptor(bus, adaptee, parent)
151{
152 connect(adaptee, SIGNAL(voicemailCountChanged(uint)), SIGNAL(VoicemailCountChanged(uint)));
153 connect(adaptee, SIGNAL(voicemailIndicatorChanged(bool)), SIGNAL(VoicemailIndicatorChanged(bool)));
154 connect(adaptee, SIGNAL(voicemailNumberChanged(QString)), SIGNAL(VoicemailNumberChanged(QString)));
155}
156
157ConnectionInterfaceVoicemailAdaptor::~ConnectionInterfaceVoicemailAdaptor()
158{
159}
160
161bool ConnectionInterfaceVoicemailAdaptor::VoicemailIndicator(const QDBusMessage& dbusMessage)
162{
163 if (!adaptee()->metaObject()->indexOfMethod("voicemailIndicator(ConnectionInterfaceVoicemailAdaptor::VoicemailIndicatorContextPtr)") == -1) {
164 dbusConnection().send(dbusMessage.createErrorReply(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")));
165 return bool();
166 }
167
168 VoicemailIndicatorContextPtr ctx = VoicemailIndicatorContextPtr(
169 new Tp::MethodInvocationContext< bool >(dbusConnection(), dbusMessage));
170 QMetaObject::invokeMethod(adaptee(), "voicemailIndicator",
171 Q_ARG(ConnectionInterfaceVoicemailAdaptor::VoicemailIndicatorContextPtr, ctx));
172 return bool();
173}
174
175QString ConnectionInterfaceVoicemailAdaptor::VoicemailNumber(const QDBusMessage& dbusMessage)
176{
177 if (!adaptee()->metaObject()->indexOfMethod("voicemailNumber(ConnectionInterfaceVoicemailAdaptor::VoicemailNumberContextPtr)") == -1) {
178 dbusConnection().send(dbusMessage.createErrorReply(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")));
179 return QString();
180 }
181
182 VoicemailNumberContextPtr ctx = VoicemailNumberContextPtr(
183 new Tp::MethodInvocationContext< QString >(dbusConnection(), dbusMessage));
184 QMetaObject::invokeMethod(adaptee(), "voicemailNumber",
185 Q_ARG(ConnectionInterfaceVoicemailAdaptor::VoicemailNumberContextPtr, ctx));
186 return QString();
187}
188
189uint ConnectionInterfaceVoicemailAdaptor::VoicemailCount(const QDBusMessage& dbusMessage)
190{
191 if (!adaptee()->metaObject()->indexOfMethod("voicemailCount(ConnectionInterfaceVoicemailAdaptor::VoicemailCountContextPtr)") == -1) {
192 dbusConnection().send(dbusMessage.createErrorReply(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")));
193 return uint();
194 }
195
196 VoicemailCountContextPtr ctx = VoicemailCountContextPtr(
197 new Tp::MethodInvocationContext< uint >(dbusConnection(), dbusMessage));
198 QMetaObject::invokeMethod(adaptee(), "voicemailCount",
199 Q_ARG(ConnectionInterfaceVoicemailAdaptor::VoicemailCountContextPtr, ctx));
200 return uint();
201}
202
0203
=== added file 'tests/common/mock/voicemailiface.h'
--- tests/common/mock/voicemailiface.h 1970-01-01 00:00:00 +0000
+++ tests/common/mock/voicemailiface.h 2015-03-30 20:55:55 +0000
@@ -0,0 +1,150 @@
1/**
2 * Copyright (C) 2013-2015 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Tiago Salem Herrmann <tiago.herrmann@canonical.com>
17 Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>
18 */
19
20#ifndef OFONOVOICEMAILIFACE_H
21#define OFONOVOICEMAILIFACE_H
22
23// telepathy-qt
24#include <TelepathyQt/Constants>
25#include <TelepathyQt/BaseConnection>
26#include <TelepathyQt/AbstractAdaptor>
27#include <TelepathyQt/DBusError>
28#include <TelepathyQt/Callbacks>
29
30class BaseConnectionVoicemailInterface;
31
32typedef Tp::SharedPtr<BaseConnectionVoicemailInterface> BaseConnectionVoicemailInterfacePtr;
33
34#define TP_QT_IFACE_CONNECTION_VOICEMAIL "com.canonical.Telephony.Voicemail"
35
36class TP_QT_EXPORT BaseConnectionVoicemailInterface : public Tp::AbstractConnectionInterface
37{
38 Q_OBJECT
39 Q_DISABLE_COPY(BaseConnectionVoicemailInterface)
40
41public:
42 static BaseConnectionVoicemailInterfacePtr create() {
43 return BaseConnectionVoicemailInterfacePtr(new BaseConnectionVoicemailInterface());
44 }
45 template<typename BaseConnectionVoicemailInterfaceSubclass>
46 static Tp::SharedPtr<BaseConnectionVoicemailInterfaceSubclass> create() {
47 return Tp::SharedPtr<BaseConnectionVoicemailInterfaceSubclass>(
48 new BaseConnectionVoicemailInterfaceSubclass());
49 }
50 QVariantMap immutableProperties() const;
51 virtual ~BaseConnectionVoicemailInterface();
52
53 typedef Tp::Callback1<uint, Tp::DBusError*> VoicemailCountCallback;
54 void setVoicemailCountCallback(const VoicemailCountCallback &cb);
55
56 typedef Tp::Callback1<bool, Tp::DBusError*> VoicemailIndicatorCallback;
57 void setVoicemailIndicatorCallback(const VoicemailIndicatorCallback &cb);
58
59 typedef Tp::Callback1<QString, Tp::DBusError*> VoicemailNumberCallback;
60 void setVoicemailNumberCallback(const VoicemailNumberCallback &cb);
61
62public Q_SLOTS:
63 void setVoicemailCount(int count);
64 void setVoicemailIndicator(bool active);
65 void setVoicemailNumber(const QString &voicemailNumber);
66
67protected:
68 BaseConnectionVoicemailInterface();
69
70private:
71 void createAdaptor();
72
73 class Adaptee;
74 friend class Adaptee;
75 struct Private;
76 friend struct Private;
77 Private *mPriv;
78};
79
80
81class TP_QT_EXPORT ConnectionInterfaceVoicemailAdaptor : public Tp::AbstractAdaptor
82{
83 Q_OBJECT
84 Q_CLASSINFO("D-Bus Interface", TP_QT_IFACE_CONNECTION_VOICEMAIL)
85 Q_CLASSINFO("D-Bus Introspection", ""
86" <interface name=\"com.canonical.Telephony.Voicemail\">\n"
87" <method name=\"VoicemailIndicator\">\n"
88" <arg direction=\"out\" type=\"b\" name=\"voicemailIndicator\"/>\n"
89" </method>\n"
90" <method name=\"VoicemailNumber\">\n"
91" <arg direction=\"out\" type=\"s\" name=\"voicemailNumber\"/>\n"
92" </method>\n"
93" <method name=\"VoicemailCount\">\n"
94" <arg direction=\"out\" type=\"u\" name=\"voicemailCount\"/>\n"
95" </method>\n"
96" <signal name=\"VoicemailCountChanged\">\n"
97" <arg type=\"u\" name=\"count\"/>\n"
98" </signal>\n"
99" <signal name=\"VoicemailIndicatorChanged\">\n"
100" <arg type=\"b\" name=\"active\"/>\n"
101" </signal>\n"
102" <signal name=\"VoicemailNumberChanged\">\n"
103" <arg type=\"s\" name=\"voicemailNumber\"/>\n"
104" </signal>\n"
105" </interface>\n"
106"")
107
108public:
109 ConnectionInterfaceVoicemailAdaptor(const QDBusConnection& dbusConnection, QObject* adaptee, QObject* parent);
110 virtual ~ConnectionInterfaceVoicemailAdaptor();
111
112 typedef Tp::MethodInvocationContextPtr< bool > VoicemailIndicatorContextPtr;
113 typedef Tp::MethodInvocationContextPtr< QString > VoicemailNumberContextPtr;
114 typedef Tp::MethodInvocationContextPtr< uint > VoicemailCountContextPtr;
115
116public Q_SLOTS: // METHODS
117 bool VoicemailIndicator(const QDBusMessage& dbusMessage);
118 QString VoicemailNumber(const QDBusMessage& dbusMessage);
119 uint VoicemailCount(const QDBusMessage& dbusMessage);
120
121Q_SIGNALS: // SIGNALS
122 void VoicemailCountChanged(uint count);
123 void VoicemailIndicatorChanged(bool active);
124 void VoicemailNumberChanged(const QString &voicemailNumber);
125};
126
127
128class TP_QT_NO_EXPORT BaseConnectionVoicemailInterface::Adaptee : public QObject
129{
130 Q_OBJECT
131
132public:
133 Adaptee(BaseConnectionVoicemailInterface *interface);
134 ~Adaptee();
135
136private Q_SLOTS:
137 void voicemailIndicator(const ConnectionInterfaceVoicemailAdaptor::VoicemailIndicatorContextPtr &context);
138 void voicemailNumber(const ConnectionInterfaceVoicemailAdaptor::VoicemailNumberContextPtr &context);
139 void voicemailCount(const ConnectionInterfaceVoicemailAdaptor::VoicemailCountContextPtr &context);
140
141Q_SIGNALS:
142 void voicemailCountChanged(uint count);
143 void voicemailIndicatorChanged(bool active);
144 void voicemailNumberChanged(const QString &voicemailNumber);
145
146public:
147 BaseConnectionVoicemailInterface *mInterface;
148};
149
150#endif
0151
=== renamed file 'handler/tests/mockcontroller.cpp' => 'tests/common/mockcontroller.cpp'
--- handler/tests/mockcontroller.cpp 2014-03-20 21:03:26 +0000
+++ tests/common/mockcontroller.cpp 2015-03-30 20:55:55 +0000
@@ -21,27 +21,34 @@
21#include "mockcontroller.h"21#include "mockcontroller.h"
22#include <QDBusReply>22#include <QDBusReply>
2323
24#define MOCK_SERVICE "com.canonical.MockConnection"24static const QString mockService("com.canonical.MockConnection");
25#define MOCK_OBJECT "/com/canonical/MockConnection"25static const QString mockObject("/com/canonical/MockConnection/%1");
26#define MOCK_INTERFACE "com.canonical.MockConnection"26static const QString mockInterface("com.canonical.MockConnection");
2727
28MockController::MockController(QObject *parent) :28MockController::MockController(const QString &protocol, QObject *parent) :
29 QObject(parent),29 QObject(parent), mProtocol(protocol), mMockObject(mockObject.arg(protocol)),
30 mMockInterface(MOCK_SERVICE, MOCK_OBJECT, MOCK_INTERFACE)30 mMockInterface(mockService, mockObject.arg(protocol), mockInterface)
31{31{
32 QDBusConnection::sessionBus().connect(MOCK_SERVICE, MOCK_OBJECT, MOCK_INTERFACE, "MessageSent", this, SIGNAL(messageSent(QString, QVariantMap)));32 connect(&mMockInterface, SIGNAL(MessageRead(QString)),
33 QDBusConnection::sessionBus().connect(MOCK_SERVICE, MOCK_OBJECT, MOCK_INTERFACE, "CallReceived", this, SIGNAL(callReceived(QString)));33 this, SIGNAL(messageRead(QString)));
34 QDBusConnection::sessionBus().connect(MOCK_SERVICE, MOCK_OBJECT, MOCK_INTERFACE, "CallEnded", this, SIGNAL(callEnded(QString)));34 connect(&mMockInterface, SIGNAL(MessageSent(QString, QVariantMap)),
35 QDBusConnection::sessionBus().connect(MOCK_SERVICE, MOCK_OBJECT, MOCK_INTERFACE, "CallStateChanged", this, SIGNAL(callStateChanged(QString,QString,QString)));35 this, SIGNAL(messageSent(QString, QVariantMap)));
36 QDBusConnection::sessionBus().connect(MOCK_SERVICE, MOCK_OBJECT, MOCK_INTERFACE, "ConferenceCreated", this, SIGNAL(conferenceCreated(QString)));36 connect(&mMockInterface, SIGNAL(CallReceived(QString)),
37 QDBusConnection::sessionBus().connect(MOCK_SERVICE, MOCK_OBJECT, MOCK_INTERFACE, "ChannelMerged", this, SIGNAL(channelMerged(QString)));37 this, SIGNAL(callReceived(QString)));
38 QDBusConnection::sessionBus().connect(MOCK_SERVICE, MOCK_OBJECT, MOCK_INTERFACE, "ChannelSplitted", this, SIGNAL(channelSplitted(QString)));38 connect(&mMockInterface, SIGNAL(CallEnded(QString)),
39}39 this, SIGNAL(callEnded(QString)));
4040 connect(&mMockInterface, SIGNAL(CallStateChanged(QString, QString, QString)),
41MockController *MockController::instance()41 this, SIGNAL(callStateChanged(QString,QString,QString)));
42{42 connect(&mMockInterface, SIGNAL(ConferenceCreated(QString)),
43 static MockController *self = new MockController();43 this, SIGNAL(conferenceCreated(QString)));
44 return self;44 connect(&mMockInterface, SIGNAL(ChannelMerged(QString)),
45 this, SIGNAL(channelMerged(QString)));
46 connect(&mMockInterface, SIGNAL(ChannelSplitted(QString)),
47 this, SIGNAL(channelSplitted(QString)));
48 connect(&mMockInterface, SIGNAL(Disconnected()),
49 this, SIGNAL(disconnected()));
50 connect(&mMockInterface, SIGNAL(Destroyed()),
51 this, SIGNAL(connectionDestroyed()));
45}52}
4653
47void MockController::placeIncomingMessage(const QString &message, const QVariantMap &properties)54void MockController::placeIncomingMessage(const QString &message, const QVariantMap &properties)
@@ -64,3 +71,43 @@
64{71{
65 mMockInterface.call("SetCallState", phoneNumber, state);72 mMockInterface.call("SetCallState", phoneNumber, state);
66}73}
74
75void MockController::setOnline(bool online)
76{
77 mMockInterface.call("SetOnline", online);
78}
79
80void MockController::setPresence(const QString &status, const QString &statusMessage)
81{
82 mMockInterface.call("SetPresence", status, statusMessage);
83}
84
85void MockController::setVoicemailNumber(const QString &number)
86{
87 mMockInterface.call("SetVoicemailNumber", number);
88}
89
90void MockController::setVoicemailIndicator(bool active)
91{
92 mMockInterface.call("SetVoicemailIndicator", active);
93}
94
95void MockController::setVoicemailCount(int count)
96{
97 mMockInterface.call("SetVoicemailCount", count);
98}
99
100void MockController::setEmergencyNumbers(const QStringList &numbers)
101{
102 mMockInterface.call("SetEmergencyNumbers", numbers);
103}
104
105QString MockController::serial()
106{
107 QDBusReply<QString> reply = mMockInterface.call("Serial");
108 if (!reply.isValid()) {
109 return QString::null;
110 }
111
112 return reply.value();
113}
67114
=== renamed file 'handler/tests/mockcontroller.h' => 'tests/common/mockcontroller.h'
--- handler/tests/mockcontroller.h 2014-03-20 21:03:26 +0000
+++ tests/common/mockcontroller.h 2015-03-30 20:55:55 +0000
@@ -28,9 +28,10 @@
28{28{
29 Q_OBJECT29 Q_OBJECT
30public:30public:
31 static MockController *instance();31 explicit MockController(const QString &protocol, QObject *parent = 0);
3232
33Q_SIGNALS:33Q_SIGNALS:
34 void messageRead(const QString &messageId);
34 void messageSent(const QString &message, const QVariantMap &properties);35 void messageSent(const QString &message, const QVariantMap &properties);
35 void callReceived(const QString &callerId);36 void callReceived(const QString &callerId);
36 void callEnded(const QString &callerId);37 void callEnded(const QString &callerId);
@@ -38,16 +39,32 @@
38 void conferenceCreated(const QString &objectPath);39 void conferenceCreated(const QString &objectPath);
39 void channelMerged(const QString &objectPath);40 void channelMerged(const QString &objectPath);
40 void channelSplitted(const QString &objectPath);41 void channelSplitted(const QString &objectPath);
42 void disconnected();
43 void connectionDestroyed();
4144
42public Q_SLOTS:45public Q_SLOTS:
43 void placeIncomingMessage(const QString &message, const QVariantMap &properties);46 void placeIncomingMessage(const QString &message, const QVariantMap &properties);
44 QString placeCall(const QVariantMap &properties);47 QString placeCall(const QVariantMap &properties);
45 void hangupCall(const QString &callerId);48 void hangupCall(const QString &callerId);
46 void setCallState(const QString &phoneNumber, const QString &state);49 void setCallState(const QString &phoneNumber, const QString &state);
50 void setOnline(bool online);
51 void setPresence(const QString &status, const QString &statusMessage);
52
53 // voicemail stuff
54 void setVoicemailNumber(const QString &number);
55 void setVoicemailIndicator(bool active);
56 void setVoicemailCount(int count);
57
58 // emergency numbers stuff
59 void setEmergencyNumbers(const QStringList &numbers);
60
61 // USSD stuff
62 QString serial();
4763
48private:64private:
49 explicit MockController(QObject *parent = 0);
50 QDBusInterface mMockInterface;65 QDBusInterface mMockInterface;
66 QString mProtocol;
67 QString mMockObject;
51};68};
5269
53#endif // MOCKCONTROLLER_H70#endif // MOCKCONTROLLER_H
5471
=== added file 'tests/common/telepathytest.cpp'
--- tests/common/telepathytest.cpp 1970-01-01 00:00:00 +0000
+++ tests/common/telepathytest.cpp 2015-03-30 20:55:55 +0000
@@ -0,0 +1,140 @@
1/*
2 * Copyright (C) 2015 Canonical, Ltd.
3 *
4 * This file is part of telephony-service.
5 *
6 * telephony-service is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * telephony-service is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <QtCore/QObject>
20#include <QtTest/QtTest>
21#include <TelepathyQt/PendingAccount>
22#include <TelepathyQt/PendingOperation>
23#include <TelepathyQt/Account>
24#include "telepathytest.h"
25#include "telepathyhelper.h"
26#include "accountentry.h"
27
28void TelepathyTest::initialize()
29{
30 Tp::registerTypes();
31
32 QSignalSpy spy(TelepathyHelper::instance(), SIGNAL(setupReady()));
33 QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, DEFAULT_TIMEOUT);
34
35 // just in case, remove any existing account that might be a leftover from
36 // previous test runs
37 Q_FOREACH(const AccountEntry *account, TelepathyHelper::instance()->accounts()) {
38 QVERIFY(removeAccount(account->account()));
39 }
40
41 // create an account manager instance to help testing
42 Tp::Features accountFeatures;
43 accountFeatures << Tp::Account::FeatureCore
44 << Tp::Account::FeatureProtocolInfo;
45 Tp::Features contactFeatures;
46 contactFeatures << Tp::Contact::FeatureAlias
47 << Tp::Contact::FeatureAvatarData
48 << Tp::Contact::FeatureAvatarToken
49 << Tp::Contact::FeatureCapabilities
50 << Tp::Contact::FeatureSimplePresence;
51 Tp::Features connectionFeatures;
52 connectionFeatures << Tp::Connection::FeatureCore
53 << Tp::Connection::FeatureSelfContact
54 << Tp::Connection::FeatureSimplePresence;
55
56 Tp::ChannelFactoryPtr channelFactory = Tp::ChannelFactory::create(QDBusConnection::sessionBus());
57 channelFactory->addCommonFeatures(Tp::Channel::FeatureCore);
58
59 mAccountManager = Tp::AccountManager::create(
60 Tp::AccountFactory::create(QDBusConnection::sessionBus(), accountFeatures),
61 Tp::ConnectionFactory::create(QDBusConnection::sessionBus(), connectionFeatures),
62 channelFactory,
63 Tp::ContactFactory::create(contactFeatures));
64
65 mReady = false;
66 connect(mAccountManager->becomeReady(Tp::AccountManager::FeatureCore),
67 &Tp::PendingOperation::finished, [=]{
68 mReady = true;
69 });
70
71 QTRY_VERIFY(mReady);
72
73 // give some time for telepathy stuff to settle
74 QTest::qWait(1000);
75}
76
77void TelepathyTest::doCleanup()
78{
79 // remove all accounts on every test to prevent garbage to go from one test to another
80 Q_FOREACH(const Tp::AccountPtr &account, mAccounts) {
81 QVERIFY(removeAccount(account));
82 }
83 QVERIFY(mAccounts.isEmpty());
84}
85
86
87Tp::AccountPtr TelepathyTest::addAccount(const QString &manager, const QString &protocol, const QString &displayName, const QVariantMap &parameters)
88{
89 bool finished = false;
90 Tp::AccountPtr account;
91 connect(mAccountManager->createAccount(manager, protocol, displayName, parameters), &Tp::PendingOperation::finished,
92 [&](Tp::PendingOperation *op) {
93 Tp::PendingAccount *pa = qobject_cast<Tp::PendingAccount*>(op);
94 if (op->isError() || !pa) {
95 qCritical() << "Failed to create account:" << op->errorName() << op->errorMessage();
96 finished = true;
97 return;
98 }
99
100 account = pa->account();
101 finished = true;
102 });
103
104 while (!finished) {
105 QTest::qWait(100);
106 }
107 mAccounts << account;
108 return account;
109}
110
111bool TelepathyTest::removeAccount(const Tp::AccountPtr &account)
112{
113 bool success = false;
114 bool finished = false;
115
116 connect(account->remove(), &Tp::PendingOperation::finished,
117 [&](Tp::PendingOperation *op) {
118 success = !op->isError();
119 finished = true;
120 });
121
122 while (!finished) {
123 QTest::qWait(100);
124 }
125 if (success) {
126 mAccounts.removeAll(account);
127 }
128 return success;
129}
130
131
132QList<Tp::AccountPtr> TelepathyTest::accounts() const
133{
134 return mAccounts;
135}
136
137void TelepathyTest::cleanup()
138{
139 doCleanup();
140}
0141
=== added file 'tests/common/telepathytest.h'
--- tests/common/telepathytest.h 1970-01-01 00:00:00 +0000
+++ tests/common/telepathytest.h 2015-03-30 20:55:55 +0000
@@ -0,0 +1,54 @@
1/*
2 * Copyright (C) 2015 Canonical, Ltd.
3 *
4 * This file is part of telephony-service.
5 *
6 * telephony-service is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * telephony-service is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef TELEPATHYTEST_H
20#define TELEPATHYTEST_H
21
22#include <QtCore/QObject>
23#include <TelepathyQt/Account>
24#include "telepathyhelper.h"
25
26#define DEFAULT_TIMEOUT 15000
27
28class TelepathyTest : public QObject
29{
30 Q_OBJECT
31
32protected:
33 void initialize();
34 void doCleanup();
35
36 // helper slots
37 void onAccountManagerReady(Tp::PendingOperation *op);
38 Tp::AccountPtr addAccount(const QString &manager,
39 const QString &protocol,
40 const QString &displayName,
41 const QVariantMap &parameters = QVariantMap());
42 bool removeAccount(const Tp::AccountPtr &account);
43 QList<Tp::AccountPtr> accounts() const;
44
45private Q_SLOTS:
46 void cleanup();
47
48private:
49 Tp::AccountManagerPtr mAccountManager;
50 bool mReady;
51 QList<Tp::AccountPtr> mAccounts;
52};
53
54#endif //TELEPATHYTEST_H
055
=== renamed directory 'handler/tests' => 'tests/handler'
=== modified file 'tests/handler/CMakeLists.txt'
--- handler/tests/CMakeLists.txt 2014-01-22 12:33:43 +0000
+++ tests/handler/CMakeLists.txt 2015-03-30 20:55:55 +0000
@@ -1,43 +1,9 @@
1include_directories(1include_directories(
2 ${CMAKE_CURRENT_BINARY_DIR}2 ${CMAKE_CURRENT_BINARY_DIR}
3 ${CMAKE_CURRENT_SOURCE_DIR}/../common
3 ${CMAKE_SOURCE_DIR}4 ${CMAKE_SOURCE_DIR}
5 ${CMAKE_SOURCE_DIR}/libtelephonyservice
6 ${TP_QT5_INCLUDE_DIRS}
4 )7 )
58
6macro(generate_test TESTNAME USE_DBUS)9generate_telepathy_test(HandlerTest SOURCES HandlerTest.cpp handlercontroller.cpp approver.cpp)
7 add_executable(${TESTNAME} ${ARGN} ${TESTNAME}.cpp)
8 qt5_use_modules(${TESTNAME} Core DBus Test)
9 set(TEST_COMMAND )
10 if (${USE_DBUS})
11 set(TEST_COMMAND -p ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME} -p -xunitxml -p -o -p ${CMAKE_BINARY_DIR}/test_${TESTNAME}.xml)
12 add_test(${TESTNAME} ${DBUS_RUNNER} --keep-env
13 --task ${CMAKE_CURRENT_BINARY_DIR}/dbus-test-wrapper.sh ${TEST_COMMAND})
14 else (${USE_DBUS})
15 add_test(${TESTNAME} ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME} -xunitxml -o ${CMAKE_BINARY_DIR}/test_${TESTNAME}.xml)
16 endif(${USE_DBUS})
17 # force telepathy not to use system approvers when available,
18 # also force usage of memory backend in history-service
19 set(TMPDIR "/tmp/telephony_service_test_home")
20 set(TEST_ENVIRONMENT "HOME=${TMPDIR};"
21 "HISTORY_SQLITE_DBPATH=:memory:;"
22 "XDG_CONFIG_HOME=${TMPDIR};
23 XDG_DATA_HOME=${TMPDIR};
24 XDG_CACHE_DIR=${TMPDIR};
25 XDG_CACHE_HOME=${TMPDIR};
26 XDG_DATA_DIRS=${TMPDIR};
27 MC_ACCOUNT_DIR=${TMPDIR};
28 MC_MANAGER_DIR=${TMPDIR}")
29 set_tests_properties(${TESTNAME} PROPERTIES
30 ENVIRONMENT "${TEST_ENVIRONMENT}"
31 TIMEOUT 30)
32 target_link_libraries(${TESTNAME}
33 ${TP_QT5_LIBRARIES}
34 )
35endmacro(generate_test)
36
37configure_file(dbus-test-wrapper.sh.in ${CMAKE_CURRENT_BINARY_DIR}/dbus-test-wrapper.sh)
38
39if (DBUS_RUNNER)
40 generate_test(HandlerTest True telepathyhelper.cpp handlercontroller.cpp mockcontroller.cpp approver.cpp)
41endif(DBUS_RUNNER)
42
43add_subdirectory(mock)
4410
=== modified file 'tests/handler/HandlerTest.cpp'
--- handler/tests/HandlerTest.cpp 2014-08-18 17:37:19 +0000
+++ tests/handler/HandlerTest.cpp 2015-03-30 20:55:55 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright (C) 2013 Canonical, Ltd.2 * Copyright (C) 2013-2015 Canonical, Ltd.
3 *3 *
4 * This file is part of telephony-service.4 * This file is part of telephony-service.
5 *5 *
@@ -18,19 +18,22 @@
1818
19#include <QtCore/QObject>19#include <QtCore/QObject>
20#include <QtTest/QtTest>20#include <QtTest/QtTest>
21#include "telepathytest.h"
21#include "handlercontroller.h"22#include "handlercontroller.h"
22#include "mockcontroller.h"23#include "mockcontroller.h"
23#include "approver.h"24#include "approver.h"
25#include "accountentry.h"
26#include "accountentryfactory.h"
24#include "telepathyhelper.h"27#include "telepathyhelper.h"
2528
26#define DEFAULT_TIMEOUT 1500029class HandlerTest : public TelepathyTest
27
28class HandlerTest : public QObject
29{30{
30 Q_OBJECT31 Q_OBJECT
3132
32private Q_SLOTS:33private Q_SLOTS:
33 void initTestCase();34 void initTestCase();
35 void init();
36 void cleanup();
34 void testMakingCalls();37 void testMakingCalls();
35 void testHangUpCall();38 void testHangUpCall();
36 void testCallHold();39 void testCallHold();
@@ -42,34 +45,51 @@
42private:45private:
43 void waitForCallActive(const QString &callerId);46 void waitForCallActive(const QString &callerId);
44 Approver *mApprover;47 Approver *mApprover;
48 MockController *mMockController;
49 Tp::AccountPtr mTpAccount;
45};50};
4651
47void HandlerTest::initTestCase()52void HandlerTest::initTestCase()
48{53{
49 QSignalSpy spy(TelepathyHelper::instance(), SIGNAL(accountReady()));54 initialize();
50 QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, DEFAULT_TIMEOUT);
51 QTRY_VERIFY_WITH_TIMEOUT(TelepathyHelper::instance()->connected(), DEFAULT_TIMEOUT);
5255
53 // register the approver56 // register the approver
54 mApprover = new Approver(this);57 mApprover = new Approver(this);
55 TelepathyHelper::instance()->registerClient(mApprover, "TelephonyTestApprover");58 TelepathyHelper::instance()->registerClient(mApprover, "TelephonyTestApprover");
56 // Tp-qt does not set registered status to approvers59 // Tp-qt does not set registered status to approvers
57 QTRY_VERIFY(QDBusConnection::sessionBus().interface()->isServiceRegistered(TELEPHONY_SERVICE_APPROVER));60 QTRY_VERIFY(QDBusConnection::sessionBus().interface()->isServiceRegistered(TELEPHONY_SERVICE_APPROVER));
5861}
59 // we need to wait in order to give telepathy time to notify about the approver62
60 QTest::qWait(3000);63void HandlerTest::init()
64{
65 mTpAccount = addAccount("mock", "mock", "the account");
66 QVERIFY(!mTpAccount.isNull());
67 QTRY_VERIFY(mTpAccount->isReady(Tp::Account::FeatureCore));
68
69 // make sure the connection is available
70 QTRY_VERIFY(!mTpAccount->connection().isNull());
71 QTRY_COMPARE(mTpAccount->connection()->selfContact()->presence().type(), Tp::ConnectionPresenceTypeAvailable);
72
73 // and create the mock controller
74 mMockController = new MockController("mock", this);
75}
76
77void HandlerTest::cleanup()
78{
79 doCleanup();
80 mMockController->deleteLater();
61}81}
6282
63void HandlerTest::testMakingCalls()83void HandlerTest::testMakingCalls()
64{84{
65 QString callerId("1234567");85 QString callerId("1234567");
66 QSignalSpy callReceivedSpy(MockController::instance(), SIGNAL(callReceived(QString)));86 QSignalSpy callReceivedSpy(mMockController, SIGNAL(callReceived(QString)));
67 // FIXME: add support for multiple accounts87 // FIXME: add support for multiple accounts
68 HandlerController::instance()->startCall(callerId, TelepathyHelper::instance()->accountId());88 HandlerController::instance()->startCall(callerId, mTpAccount->uniqueIdentifier());
69 QTRY_COMPARE(callReceivedSpy.count(), 1);89 QTRY_COMPARE(callReceivedSpy.count(), 1);
70 QCOMPARE(callReceivedSpy.first().first().toString(), callerId);90 QCOMPARE(callReceivedSpy.first().first().toString(), callerId);
7191
72 MockController::instance()->hangupCall(callerId);92 mMockController->hangupCall(callerId);
73}93}
7494
75void HandlerTest::testHangUpCall()95void HandlerTest::testHangUpCall()
@@ -81,7 +101,7 @@
81 properties["State"] = "incoming";101 properties["State"] = "incoming";
82102
83 QSignalSpy approverCallSpy(mApprover, SIGNAL(newCall()));103 QSignalSpy approverCallSpy(mApprover, SIGNAL(newCall()));
84 QString objectPath = MockController::instance()->placeCall(properties);104 QString objectPath = mMockController->placeCall(properties);
85 QVERIFY(!objectPath.isEmpty());105 QVERIFY(!objectPath.isEmpty());
86106
87 // wait for the channel to hit the approver107 // wait for the channel to hit the approver
@@ -91,7 +111,7 @@
91 waitForCallActive(callerId);111 waitForCallActive(callerId);
92112
93 // and finally request the hangup113 // and finally request the hangup
94 QSignalSpy callEndedSpy(MockController::instance(), SIGNAL(callEnded(QString)));114 QSignalSpy callEndedSpy(mMockController, SIGNAL(callEnded(QString)));
95 HandlerController::instance()->hangUpCall(objectPath);115 HandlerController::instance()->hangUpCall(objectPath);
96 QTRY_COMPARE(callEndedSpy.count(), 1);116 QTRY_COMPARE(callEndedSpy.count(), 1);
97}117}
@@ -105,7 +125,7 @@
105 properties["State"] = "incoming";125 properties["State"] = "incoming";
106126
107 QSignalSpy approverCallSpy(mApprover, SIGNAL(newCall()));127 QSignalSpy approverCallSpy(mApprover, SIGNAL(newCall()));
108 QString objectPath = MockController::instance()->placeCall(properties);128 QString objectPath = mMockController->placeCall(properties);
109 QVERIFY(!objectPath.isEmpty());129 QVERIFY(!objectPath.isEmpty());
110130
111 // wait for the channel to hit the approver131 // wait for the channel to hit the approver
@@ -114,7 +134,7 @@
114134
115 waitForCallActive(callerId);135 waitForCallActive(callerId);
116136
117 QSignalSpy callStateSpy(MockController::instance(), SIGNAL(callStateChanged(QString,QString,QString)));137 QSignalSpy callStateSpy(mMockController, SIGNAL(callStateChanged(QString,QString,QString)));
118138
119 // set the call on hold139 // set the call on hold
120 HandlerController::instance()->setHold(objectPath, true);140 HandlerController::instance()->setHold(objectPath, true);
@@ -127,7 +147,7 @@
127 QTRY_COMPARE(callStateSpy.count(), 1);147 QTRY_COMPARE(callStateSpy.count(), 1);
128 QCOMPARE(callStateSpy.first()[2].toString(), QString("active"));148 QCOMPARE(callStateSpy.first()[2].toString(), QString("active"));
129149
130 MockController::instance()->hangupCall(callerId);150 mMockController->hangupCall(callerId);
131}151}
132152
133void HandlerTest::testCallProperties()153void HandlerTest::testCallProperties()
@@ -140,7 +160,7 @@
140160
141 QSignalSpy approverCallSpy(mApprover, SIGNAL(newCall()));161 QSignalSpy approverCallSpy(mApprover, SIGNAL(newCall()));
142 QSignalSpy handlerCallPropertiesSpy(HandlerController::instance(), SIGNAL(callPropertiesChanged(QString,QVariantMap)));162 QSignalSpy handlerCallPropertiesSpy(HandlerController::instance(), SIGNAL(callPropertiesChanged(QString,QVariantMap)));
143 MockController::instance()->placeCall(properties);163 mMockController->placeCall(properties);
144164
145 // wait for the channel to hit the approver165 // wait for the channel to hit the approver
146 QTRY_COMPARE(approverCallSpy.count(), 1);166 QTRY_COMPARE(approverCallSpy.count(), 1);
@@ -183,6 +203,7 @@
183 QCOMPARE(dtmfStringFromMethod, dtmfString);203 QCOMPARE(dtmfStringFromMethod, dtmfString);
184204
185 HandlerController::instance()->hangUpCall(objectPath);205 HandlerController::instance()->hangUpCall(objectPath);
206 QTest::qWait(500);
186}207}
187208
188void HandlerTest::testConferenceCall()209void HandlerTest::testConferenceCall()
@@ -196,7 +217,7 @@
196 properties["State"] = "incoming";217 properties["State"] = "incoming";
197218
198 QSignalSpy approverCallSpy(mApprover, SIGNAL(newCall()));219 QSignalSpy approverCallSpy(mApprover, SIGNAL(newCall()));
199 QString call1 = MockController::instance()->placeCall(properties);220 QString call1 = mMockController->placeCall(properties);
200221
201 // wait for the channel to hit the approver222 // wait for the channel to hit the approver
202 QTRY_COMPARE(approverCallSpy.count(), 1);223 QTRY_COMPARE(approverCallSpy.count(), 1);
@@ -206,7 +227,7 @@
206227
207 // make a second call228 // make a second call
208 properties["Caller"] = callerId2;229 properties["Caller"] = callerId2;
209 QString call2 = MockController::instance()->placeCall(properties);230 QString call2 = mMockController->placeCall(properties);
210 // wait for the channel to hit the approver231 // wait for the channel to hit the approver
211 QTRY_COMPARE(approverCallSpy.count(), 1);232 QTRY_COMPARE(approverCallSpy.count(), 1);
212 mApprover->acceptCall();233 mApprover->acceptCall();
@@ -214,27 +235,27 @@
214 waitForCallActive(callerId2);235 waitForCallActive(callerId2);
215236
216 // now create the conf call237 // now create the conf call
217 QSignalSpy conferenceCreatedSpy(MockController::instance(), SIGNAL(conferenceCreated(QString)));238 QSignalSpy conferenceCreatedSpy(mMockController, SIGNAL(conferenceCreated(QString)));
218 HandlerController::instance()->createConferenceCall(QStringList() << call1 << call2);239 HandlerController::instance()->createConferenceCall(QStringList() << call1 << call2);
219 QTRY_COMPARE(conferenceCreatedSpy.count(), 1);240 QTRY_COMPARE(conferenceCreatedSpy.count(), 1);
220 QString conferenceObjectPath = conferenceCreatedSpy.first().first().toString();241 QString conferenceObjectPath = conferenceCreatedSpy.first().first().toString();
221242
222 // now place a third call and try to merge it243 // now place a third call and try to merge it
223 properties["Caller"] = callerId3;244 properties["Caller"] = callerId3;
224 QString call3 = MockController::instance()->placeCall(properties);245 QString call3 = mMockController->placeCall(properties);
225 QTRY_COMPARE(approverCallSpy.count(), 1);246 QTRY_COMPARE(approverCallSpy.count(), 1);
226 mApprover->acceptCall();247 mApprover->acceptCall();
227 approverCallSpy.clear();248 approverCallSpy.clear();
228 waitForCallActive(callerId3);249 waitForCallActive(callerId3);
229250
230 // merge that call on the conference251 // merge that call on the conference
231 QSignalSpy channelMergedSpy(MockController::instance(), SIGNAL(channelMerged(QString)));252 QSignalSpy channelMergedSpy(mMockController, SIGNAL(channelMerged(QString)));
232 HandlerController::instance()->mergeCall(conferenceObjectPath, call3);253 HandlerController::instance()->mergeCall(conferenceObjectPath, call3);
233 QTRY_COMPARE(channelMergedSpy.count(), 1);254 QTRY_COMPARE(channelMergedSpy.count(), 1);
234 QCOMPARE(channelMergedSpy.first().first().toString(), call3);255 QCOMPARE(channelMergedSpy.first().first().toString(), call3);
235256
236 // now try to split one of the channels257 // now try to split one of the channels
237 QSignalSpy channelSplittedSpy(MockController::instance(), SIGNAL(channelSplitted(QString)));258 QSignalSpy channelSplittedSpy(mMockController, SIGNAL(channelSplitted(QString)));
238 HandlerController::instance()->splitCall(call2);259 HandlerController::instance()->splitCall(call2);
239 QTRY_COMPARE(channelSplittedSpy.count(), 1);260 QTRY_COMPARE(channelSplittedSpy.count(), 1);
240 QCOMPARE(channelSplittedSpy.first().first().toString(), call2);261 QCOMPARE(channelSplittedSpy.first().first().toString(), call2);
@@ -244,15 +265,18 @@
244 HandlerController::instance()->hangUpCall(call1);265 HandlerController::instance()->hangUpCall(call1);
245 HandlerController::instance()->hangUpCall(call2);266 HandlerController::instance()->hangUpCall(call2);
246 HandlerController::instance()->hangUpCall(call3);267 HandlerController::instance()->hangUpCall(call3);
268
269 // just to make sure it is all done before removing the accounts
270 QTest::qWait(500);
247}271}
248272
249void HandlerTest::testSendMessage()273void HandlerTest::testSendMessage()
250{274{
251 QString recipient("22222222");275 QString recipient("22222222");
252 QString message("Hello, world!");276 QString message("Hello, world!");
253 QSignalSpy messageSentSpy(MockController::instance(), SIGNAL(messageSent(QString,QVariantMap)));277 QSignalSpy messageSentSpy(mMockController, SIGNAL(messageSent(QString,QVariantMap)));
254 // FIXME: add support for multiple accounts278 // FIXME: add support for multiple accounts
255 HandlerController::instance()->sendMessage(recipient, message, TelepathyHelper::instance()->accountId());279 HandlerController::instance()->sendMessage(recipient, message, mTpAccount->uniqueIdentifier());
256 QTRY_COMPARE(messageSentSpy.count(), 1);280 QTRY_COMPARE(messageSentSpy.count(), 1);
257 QString sentMessage = messageSentSpy.first().first().toString();281 QString sentMessage = messageSentSpy.first().first().toString();
258 QVariantMap messageProperties = messageSentSpy.first().last().value<QVariantMap>();282 QVariantMap messageProperties = messageSentSpy.first().last().value<QVariantMap>();
@@ -284,7 +308,7 @@
284void HandlerTest::waitForCallActive(const QString &callerId)308void HandlerTest::waitForCallActive(const QString &callerId)
285{309{
286 // wait until the call state is "accepted"310 // wait until the call state is "accepted"
287 QSignalSpy callStateSpy(MockController::instance(), SIGNAL(callStateChanged(QString,QString,QString)));311 QSignalSpy callStateSpy(mMockController, SIGNAL(callStateChanged(QString,QString,QString)));
288 QString state;312 QString state;
289 QString objectPath;313 QString objectPath;
290 QString caller;314 QString caller;
291315
=== modified file 'tests/handler/approver.cpp'
--- handler/tests/approver.cpp 2014-01-07 19:53:45 +0000
+++ tests/handler/approver.cpp 2015-03-30 20:55:55 +0000
@@ -115,6 +115,7 @@
115 if (dispatchOperation->possibleHandlers().contains(TELEPHONY_SERVICE_HANDLER)) {115 if (dispatchOperation->possibleHandlers().contains(TELEPHONY_SERVICE_HANDLER)) {
116 dispatchOperation->handleWith(TELEPHONY_SERVICE_HANDLER);116 dispatchOperation->handleWith(TELEPHONY_SERVICE_HANDLER);
117 mDispatchOps.removeAll(dispatchOperation);117 mDispatchOps.removeAll(dispatchOperation);
118 break;
118 }119 }
119 }120 }
120 }121 }
121122
=== renamed directory 'libtelephonyservice/tests' => 'tests/libtelephonyservice'
=== added file 'tests/libtelephonyservice/AccountEntryFactoryTest.cpp'
--- tests/libtelephonyservice/AccountEntryFactoryTest.cpp 1970-01-01 00:00:00 +0000
+++ tests/libtelephonyservice/AccountEntryFactoryTest.cpp 2015-03-30 20:55:55 +0000
@@ -0,0 +1,67 @@
1/*
2 * Copyright (C) 2015 Canonical, Ltd.
3 *
4 * This file is part of telephony-service.
5 *
6 * telephony-service is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * telephony-service is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <QtCore/QObject>
20#include <QtTest/QtTest>
21#include "telepathytest.h"
22#include "accountentry.h"
23#include "accountentryfactory.h"
24#include "ofonoaccountentry.h"
25#include "telepathyhelper.h"
26
27class AccountEntryFactoryTest : public TelepathyTest
28{
29 Q_OBJECT
30
31private Q_SLOTS:
32 void initTestCase();
33 void testCorrectInstancesCreated();
34 void testNullAccount();
35};
36
37void AccountEntryFactoryTest::initTestCase()
38{
39 initialize();
40}
41
42void AccountEntryFactoryTest::testCorrectInstancesCreated()
43{
44 Tp::AccountPtr genericTpAccount = addAccount("mock", "mock", "generic");
45 QVERIFY(!genericTpAccount.isNull());
46 AccountEntry *genericAccount = AccountEntryFactory::createEntry(genericTpAccount, this);
47 QVERIFY(genericAccount);
48 QCOMPARE(genericAccount->type(), AccountEntry::GenericAccount);
49 QVERIFY(!qobject_cast<OfonoAccountEntry*>(genericAccount));
50
51 Tp::AccountPtr ofonoTpAccount = addAccount("mock", "ofono", "phone account");
52 AccountEntry *ofonoAccount = AccountEntryFactory::createEntry(ofonoTpAccount, this);
53 QVERIFY(ofonoAccount);
54 QCOMPARE(ofonoAccount->type(), AccountEntry::PhoneAccount);
55 QVERIFY(qobject_cast<OfonoAccountEntry*>(ofonoAccount));
56}
57
58void AccountEntryFactoryTest::testNullAccount()
59{
60 AccountEntry *nullAccount = AccountEntryFactory::createEntry(Tp::AccountPtr(), this);
61 QVERIFY(nullAccount);
62 QVERIFY(nullAccount->accountId().isNull());
63}
64
65
66QTEST_MAIN(AccountEntryFactoryTest)
67#include "AccountEntryFactoryTest.moc"
068
=== added file 'tests/libtelephonyservice/AccountEntryTest.cpp'
--- tests/libtelephonyservice/AccountEntryTest.cpp 1970-01-01 00:00:00 +0000
+++ tests/libtelephonyservice/AccountEntryTest.cpp 2015-03-30 20:55:55 +0000
@@ -0,0 +1,228 @@
1/*
2 * Copyright (C) 2015 Canonical, Ltd.
3 *
4 * This file is part of telephony-service.
5 *
6 * telephony-service is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * telephony-service is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <QtCore/QObject>
20#include <QtTest/QtTest>
21#include "telepathytest.h"
22#include "accountentry.h"
23#include "accountentryfactory.h"
24#include "telepathyhelper.h"
25#include "mockcontroller.h"
26
27class AccountEntryTest : public TelepathyTest
28{
29 Q_OBJECT
30
31private Q_SLOTS:
32 void initTestCase();
33 void init();
34 void cleanup();
35 void testAccountId();
36 void testActive();
37 void testDisplayName();
38 void testStatus();
39 void testStatusMessage();
40 void testConnected();
41 void testCompareIds_data();
42 void testCompareIds();
43 void testAddressableVCardFields();
44
45private:
46 AccountEntry *mAccount;
47 Tp::AccountPtr mTpAccount;
48 AccountEntry *mNullAccount;
49 MockController *mMockController;
50};
51
52void AccountEntryTest::initTestCase()
53{
54 initialize();
55
56 // create a null account
57 mNullAccount = AccountEntryFactory::createEntry(Tp::AccountPtr(), this);
58}
59
60void AccountEntryTest::init()
61{
62 mTpAccount = addAccount("mock", "mock", "the account");
63 QVERIFY(!mTpAccount.isNull());
64 QTRY_VERIFY(mTpAccount->isReady(Tp::Account::FeatureCore));
65
66 mAccount = AccountEntryFactory::createEntry(mTpAccount, this);
67 QVERIFY(mAccount);
68
69 // make sure the connection is available
70 QTRY_VERIFY(!mTpAccount->connection().isNull());
71 QTRY_COMPARE(mTpAccount->connection()->selfContact()->presence().type(), Tp::ConnectionPresenceTypeAvailable);
72 QTRY_VERIFY(mAccount->connected());
73
74 // and create the mock controller
75 mMockController = new MockController("mock", this);
76
77 // just in case, wait some time
78 QTest::qWait(500);
79}
80
81void AccountEntryTest::cleanup()
82{
83 doCleanup();
84
85 mAccount->deleteLater();
86 mMockController->deleteLater();
87}
88
89void AccountEntryTest::testAccountId()
90{
91 QCOMPARE(mAccount->accountId(), mTpAccount->uniqueIdentifier());
92 QVERIFY(mNullAccount->accountId().isNull());
93}
94
95void AccountEntryTest::testActive()
96{
97 QSignalSpy activeChangedSpy(mAccount, SIGNAL(activeChanged()));
98
99 // the mock account is enabled/connected by default, so make sure it is like that
100 QVERIFY(mAccount->active());
101
102 // now set the account offline and see if the active flag changes correctly
103 mMockController->setOnline(false);
104 QTRY_VERIFY(!mAccount->active());
105 QCOMPARE(activeChangedSpy.count(), 1);
106
107 // now re-enable the account and check that the entry is updated
108 activeChangedSpy.clear();
109 mMockController->setOnline(true);
110 QTRY_VERIFY(mAccount->active());
111 QCOMPARE(activeChangedSpy.count(), 1);
112
113 // check that for a null account active is false
114 QVERIFY(!mNullAccount->active());
115}
116
117void AccountEntryTest::testDisplayName()
118{
119 QSignalSpy displayNameChangedSpy(mAccount, SIGNAL(displayNameChanged()));
120
121 // check that the value is correct already
122 QCOMPARE(mAccount->displayName(), mTpAccount->displayName());
123
124 // now try to set the display in the telepathy account directly and see that the entry gets updated
125 QString newDisplayName = "some other display name";
126 mTpAccount->setDisplayName(newDisplayName);
127 QTRY_COMPARE(mAccount->displayName(), newDisplayName);
128 QCOMPARE(displayNameChangedSpy.count(), 1);
129
130 // and try setting the display name in the entry itself
131 displayNameChangedSpy.clear();
132 newDisplayName = "changing again";
133 mAccount->setDisplayName(newDisplayName);
134 QTRY_COMPARE(mAccount->displayName(), newDisplayName);
135 QCOMPARE(displayNameChangedSpy.count(), 1);
136 QCOMPARE(mTpAccount->displayName(), newDisplayName);
137
138 // check that for a null account the displayName is null
139 QVERIFY(mNullAccount->displayName().isNull());
140}
141
142void AccountEntryTest::testStatus()
143{
144 QSignalSpy statusChangedSpy(mAccount, SIGNAL(statusChanged()));
145
146 // check that the value is correct already
147 QCOMPARE(mAccount->status(), mTpAccount->connection()->selfContact()->presence().status());
148
149 // and now set a new value
150 Tp::Presence presence(Tp::ConnectionPresenceTypeAway, "away", "away");
151 mTpAccount->setRequestedPresence(presence);
152
153 QTRY_COMPARE(mAccount->status(), QString("away"));
154 QCOMPARE(statusChangedSpy.count(), 1);
155
156 // check that for a null account the status is null
157 QVERIFY(mNullAccount->status().isNull());
158}
159
160void AccountEntryTest::testStatusMessage()
161{
162 QSignalSpy statusMessageChangedSpy(mAccount, SIGNAL(statusMessageChanged()));
163
164 // check that the value is correct already
165 QTRY_COMPARE(mAccount->statusMessage(), mTpAccount->connection()->selfContact()->presence().statusMessage());
166
167 // and now set a new value
168 QString statusMessage("I am online");
169 Tp::Presence presence(Tp::ConnectionPresenceTypeAvailable, "available", statusMessage);
170 mTpAccount->setRequestedPresence(presence);
171
172 QTRY_COMPARE(mAccount->statusMessage(), statusMessage);
173 QCOMPARE(statusMessageChangedSpy.count(), 1);
174
175 // check that for a null account the displayName is null
176 QVERIFY(mNullAccount->statusMessage().isNull());
177}
178
179void AccountEntryTest::testConnected()
180{
181 QSignalSpy connectedChangedSpy(mAccount, SIGNAL(connectedChanged()));
182
183 // the mock account is enabled/connected by default, so make sure it is like that
184 QVERIFY(mAccount->connected());
185
186 // now set the account offline and see if the active flag changes correctly
187 mMockController->setOnline(false);
188 QTRY_VERIFY(!mAccount->connected());
189 QTRY_COMPARE(connectedChangedSpy.count(), 1);
190
191 // now re-enable the account and check that the entry is updated
192 connectedChangedSpy.clear();
193 mMockController->setOnline(true);
194 QTRY_VERIFY(mAccount->connected());
195 QTRY_COMPARE(connectedChangedSpy.count(), 1);
196
197 // check that for a null account the displayName is null
198 QVERIFY(!mNullAccount->connected());
199}
200
201void AccountEntryTest::testCompareIds_data()
202{
203 QTest::addColumn<QString>("first");
204 QTest::addColumn<QString>("second");
205 QTest::addColumn<bool>("expectedResult");
206
207 QTest::newRow("identical values") << "1234567" << "1234567" << true;
208 QTest::newRow("case difference") << "TestId" << "testid" << false;
209 QTest::newRow("phone prefix") << "1234567" << "1231234567" << false;
210}
211
212void AccountEntryTest::testCompareIds()
213{
214 QFETCH(QString, first);
215 QFETCH(QString, second);
216 QFETCH(bool, expectedResult);
217
218 QCOMPARE(mAccount->compareIds(first, second), expectedResult);
219}
220
221void AccountEntryTest::testAddressableVCardFields()
222{
223 QVERIFY(!mAccount->addressableVCardFields().isEmpty());
224 QCOMPARE(mAccount->addressableVCardFields(), mTpAccount->protocolInfo().addressableVCardFields());
225}
226
227QTEST_MAIN(AccountEntryTest)
228#include "AccountEntryTest.moc"
0229
=== modified file 'tests/libtelephonyservice/CMakeLists.txt'
--- libtelephonyservice/tests/CMakeLists.txt 2014-07-01 16:05:21 +0000
+++ tests/libtelephonyservice/CMakeLists.txt 2015-03-30 20:55:55 +0000
@@ -1,44 +1,28 @@
1set(LIBTELEPHONYSERVICE_DIR ${CMAKE_SOURCE_DIR}/libtelephonyservice)
1include_directories(2include_directories(
2 ${CMAKE_CURRENT_BINARY_DIR}3 ${CMAKE_CURRENT_BINARY_DIR}
3 ${CMAKE_SOURCE_DIR}/libtelephonyservice4 ${LIBTELEPHONYSERVICE_DIR}
5 ${TP_QT5_INCLUDE_DIRS}
6 ${CMAKE_SOURCE_DIR}/tests/common
4 )7 )
58
6add_executable(GreeterContactsTestServerExe GreeterContactsTestServer.cpp)9add_executable(GreeterContactsTestServerExe GreeterContactsTestServer.cpp)
7qt5_use_modules(GreeterContactsTestServerExe Core DBus)10qt5_use_modules(GreeterContactsTestServerExe Core DBus)
811
9add_executable(GreeterContactsTestExe GreeterContactsTest.cpp ../greetercontacts.cpp)12generate_test(GreeterContactsTest USE_DBUS
10set_target_properties(GreeterContactsTestExe PROPERTIES COMPILE_DEFINITIONS "AS_BUSNAME=sessionBus;CMAKE_SOURCE_DIR=\"${CMAKE_SOURCE_DIR}\"")13 SOURCES GreeterContactsTest.cpp ${LIBTELEPHONYSERVICE_DIR}/greetercontacts.cpp
11qt5_use_modules(GreeterContactsTestExe Contacts Core DBus Test)14 QT5_MODULES Contacts Core DBus Test
1215 ENVIRONMENT XDG_SESSION_CLASS=greeter XDG_GREETER_DATA_DIR=${CMAKE_BINARY_DIR}/Testing/Temporary
13add_test(NAME GreeterContactsTest16 TASKS --task env --ignore-return --task ${CMAKE_CURRENT_BINARY_DIR}/GreeterContactsTestServerExe --task-name server --ignore-return
14 COMMAND env17 WAIT_FOR org.freedesktop.Accounts)
15 -u LD_PRELOAD # fakeroot's preload doesn't play well with dbus-test-runner18set_target_properties(GreeterContactsTest PROPERTIES COMPILE_DEFINITIONS "AS_BUSNAME=sessionBus;CMAKE_SOURCE_DIR=\"${CMAKE_SOURCE_DIR}\"")
16 -u LD_LIBRARY_PATH # fakeroot fills this too19add_dependencies(GreeterContactsTest GreeterContactsTestServerExe)
17 XDG_SESSION_CLASS=greeter20
18 XDG_GREETER_DATA_DIR=${CMAKE_BINARY_DIR}/Testing/Temporary21generate_test(ContactUtilsTest SOURCES ContactUtilsTest.cpp QT5_MODULES Contacts Core Test LIBRARIES telephonyservice USE_UI)
19 dbus-test-runner22generate_test(PhoneUtilsTest SOURCES PhoneUtilsTest.cpp LIBRARIES telephonyservice USE_UI)
20 --task ${CMAKE_CURRENT_BINARY_DIR}/GreeterContactsTestServerExe23
21 --task-name server24generate_telepathy_test(AccountEntryFactoryTest SOURCES AccountEntryFactoryTest.cpp)
22 --ignore-return25generate_telepathy_test(AccountEntryTest SOURCES AccountEntryTest.cpp)
23 --task ${CMAKE_CURRENT_BINARY_DIR}/GreeterContactsTestExe26generate_telepathy_test(ChatManagerTest SOURCES ChatManagerTest.cpp)
24 --task-name test27generate_telepathy_test(OfonoAccountEntryTest SOURCES OfonoAccountEntryTest.cpp)
25 --wait-for org.freedesktop.Accounts28generate_telepathy_test(TelepathyHelperTest SOURCES TelepathyHelperTest.cpp)
26 -p -xunitxml -p -o -p ${CMAKE_BINARY_DIR}/test_GreeterContactsTest.xml
27 DEPENDENCIES GreeterContactsTestServerExe GreeterContactsTestExe
28 )
29
30macro(generate_tests)
31 foreach(test ${ARGN})
32 add_executable(${test} ${test}.cpp)
33 qt5_use_modules(${test} Contacts Core DBus Qml Test)
34 target_link_libraries(${test}
35 telephonyservice
36 )
37 add_test(${test} ${CMAKE_CURRENT_BINARY_DIR}/${test} -platform offscreen -xunitxml -o ${CMAKE_BINARY_DIR}/test_${test}.xml)
38 endforeach(test)
39endmacro(generate_tests)
40
41generate_tests(
42 ContactUtilsTest
43 PhoneUtilsTest
44 )
4529
=== added file 'tests/libtelephonyservice/ChatManagerTest.cpp'
--- tests/libtelephonyservice/ChatManagerTest.cpp 1970-01-01 00:00:00 +0000
+++ tests/libtelephonyservice/ChatManagerTest.cpp 2015-03-30 20:55:55 +0000
@@ -0,0 +1,177 @@
1/*
2 * Copyright (C) 2013-2015 Canonical, Ltd.
3 *
4 * This file is part of telephony-service.
5 *
6 * telephony-service is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * telephony-service is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <QtCore/QObject>
20#include <QtTest/QtTest>
21#include "telepathytest.h"
22#include "accountentry.h"
23#include "chatmanager.h"
24#include "telepathyhelper.h"
25#include "mockcontroller.h"
26
27class ChatManagerTest : public TelepathyTest
28{
29 Q_OBJECT
30
31private Q_SLOTS:
32 void initTestCase();
33 void init();
34 void cleanup();
35 void testSendMessage_data();
36 void testSendMessage();
37 void testMessageReceived();
38 void testAcknowledgeMessages();
39
40private:
41 Tp::AccountPtr mGenericTpAccount;
42 Tp::AccountPtr mPhoneTpAccount;
43 MockController *mGenericMockController;
44 MockController *mPhoneMockController;
45};
46
47void ChatManagerTest::initTestCase()
48{
49 initialize();
50
51 TelepathyHelper::instance()->registerChannelObserver();
52
53 // just give telepathy some time to register the observer
54 QTest::qWait(1000);
55}
56
57void ChatManagerTest::init()
58{
59 // add two accounts
60 mGenericTpAccount = addAccount("mock", "mock", "the generic account");
61 QTRY_VERIFY(!mGenericTpAccount->connection().isNull());
62
63 mPhoneTpAccount = addAccount("mock", "ofono", "the phone account");
64 QTRY_VERIFY(!mPhoneTpAccount->connection().isNull());
65
66 // and create the mock controller
67 mGenericMockController = new MockController("mock", this);
68 mPhoneMockController = new MockController("ofono", this);
69}
70
71void ChatManagerTest::cleanup()
72{
73 // the accounts are removed in the parent class.
74 doCleanup();
75
76 mGenericMockController->deleteLater();
77 mPhoneMockController->deleteLater();
78}
79
80void ChatManagerTest::testSendMessage_data()
81{
82 QTest::addColumn<QStringList>("recipients");
83 QTest::addColumn<QString>("message");
84 QTest::addColumn<QString>("accountId");
85
86 QTest::newRow("message via the generic account") << (QStringList() << "recipient1") << QString("Hello world") << QString("mock/mock/account0");
87 QTest::newRow("message via the phone account") << (QStringList() << "recipient2") << QString("Hello Phone World") << QString("mock/ofono/account0");
88 QTest::newRow("multiple recipients") << (QStringList() << "123" << "456" << "789") << QString("Hi friends!") << QString("mock/mock/account0");
89}
90
91void ChatManagerTest::testSendMessage()
92{
93 QFETCH(QStringList, recipients);
94 QFETCH(QString, message);
95 QFETCH(QString, accountId);
96
97 // just to make it easier, sort the recipients
98 qSort(recipients);
99
100 MockController *controller = accountId.startsWith("mock/mock") ? mGenericMockController : mPhoneMockController;
101 QSignalSpy controllerMessageSentSpy(controller, SIGNAL(messageSent(QString,QVariantMap)));
102 QSignalSpy messageSentSpy(ChatManager::instance(), SIGNAL(messageSent(QStringList,QString)));
103
104 ChatManager::instance()->sendMessage(recipients, message, accountId);
105
106 QTRY_COMPARE(controllerMessageSentSpy.count(), 1);
107 QString messageText = controllerMessageSentSpy.first()[0].toString();
108 QVariantMap messageProperties = controllerMessageSentSpy.first()[1].toMap();
109 QStringList messageRecipients = messageProperties["Recipients"].toStringList();
110 qSort(messageRecipients);
111 QCOMPARE(messageText, message);
112 QCOMPARE(messageRecipients, recipients);
113
114 QTRY_COMPARE(messageSentSpy.count(), 1);
115 messageRecipients = messageSentSpy.first()[0].toStringList();
116 qSort(messageRecipients);
117 messageText = messageSentSpy.first()[1].toString();
118 QCOMPARE(messageText, message);
119 QCOMPARE(messageRecipients, recipients);
120}
121
122void ChatManagerTest::testMessageReceived()
123{
124 QSignalSpy messageReceivedSpy(ChatManager::instance(), SIGNAL(messageReceived(QString,QString,QDateTime,QString,bool)));
125
126 QVariantMap properties;
127 properties["Sender"] = "12345";
128 properties["Recipients"] = (QStringList() << "12345");
129 QString message("Hi there");
130 mGenericMockController->placeIncomingMessage(message, properties);
131
132 QTRY_COMPARE(messageReceivedSpy.count(), 1);
133 QString sender = messageReceivedSpy.first()[0].toString();
134 QString receivedMessage = messageReceivedSpy.first()[1].toString();
135 QCOMPARE(sender, properties["Sender"].toString());
136 QCOMPARE(receivedMessage, message);
137}
138
139void ChatManagerTest::testAcknowledgeMessages()
140{
141 QSignalSpy messageReceivedSpy(ChatManager::instance(), SIGNAL(messageReceived(QString,QString,QDateTime,QString,bool)));
142
143 QVariantMap properties;
144 properties["Sender"] = "12345";
145 properties["Recipients"] = (QStringList() << "12345");
146 QStringList messages;
147 messages << "Hi there" << "How are you" << "Always look on the bright side of life";
148 Q_FOREACH(const QString &message, messages) {
149 mGenericMockController->placeIncomingMessage(message, properties);
150 QTest::qWait(100);
151 }
152 QTRY_COMPARE(messageReceivedSpy.count(), messages.count());
153
154 QStringList messageIds;
155 for (int i = 0; i < messages.count(); ++i) {
156 QString messageId = messageReceivedSpy[i][3].toString();
157 messageIds << messageId;
158 }
159
160 QSignalSpy messageReadSpy(mGenericMockController, SIGNAL(messageRead(QString)));
161 Q_FOREACH(const QString &messageId, messageIds) {
162 ChatManager::instance()->acknowledgeMessage(properties["Recipients"].toStringList(), messageId, "mock/mock/account0");
163 }
164
165 QTRY_COMPARE(messageReadSpy.count(), messageIds.count());
166 QStringList receivedIds;
167 for (int i = 0; i < messageReadSpy.count(); ++i) {
168 receivedIds << messageReadSpy[i][0].toString();
169 }
170
171 qSort(receivedIds);
172 qSort(messageIds);
173 QCOMPARE(receivedIds, messageIds);
174}
175
176QTEST_MAIN(ChatManagerTest)
177#include "ChatManagerTest.moc"
0178
=== modified file 'tests/libtelephonyservice/ContactUtilsTest.cpp'
--- libtelephonyservice/tests/ContactUtilsTest.cpp 2013-08-13 22:25:18 +0000
+++ tests/libtelephonyservice/ContactUtilsTest.cpp 2015-03-30 20:55:55 +0000
@@ -34,8 +34,6 @@
34 void testSharedManagerCreation();34 void testSharedManagerCreation();
35};35};
3636
37
38
39void ContactUtilsTest::testFormatContactName_data()37void ContactUtilsTest::testFormatContactName_data()
40{38{
41 QTest::addColumn<QString>("firstName");39 QTest::addColumn<QString>("firstName");
4240
=== modified file 'tests/libtelephonyservice/GreeterContactsTest.cpp'
--- libtelephonyservice/tests/GreeterContactsTest.cpp 2014-07-01 16:10:33 +0000
+++ tests/libtelephonyservice/GreeterContactsTest.cpp 2015-03-30 20:55:55 +0000
@@ -281,8 +281,7 @@
281 "com.canonical.TelephonyServiceApprover",281 "com.canonical.TelephonyServiceApprover",
282 QDBusConnection::sessionBus());282 QDBusConnection::sessionBus());
283 QSignalSpy spy(&iface, SIGNAL(InitialQueriesDone()));283 QSignalSpy spy(&iface, SIGNAL(InitialQueriesDone()));
284 QVERIFY(spy.wait());284 QTRY_COMPARE(spy.count(), 1);
285 QCOMPARE(spy.count(), 1);
286}285}
287286
288void GreeterContactsTest::makeGreeterContacts()287void GreeterContactsTest::makeGreeterContacts()
@@ -293,8 +292,7 @@
293292
294void GreeterContactsTest::waitForUpdatedSignal(bool convertedPath)293void GreeterContactsTest::waitForUpdatedSignal(bool convertedPath)
295{294{
296 QVERIFY(mSpy->wait());295 QTRY_COMPARE(mSpy->count(), 1);
297 QCOMPARE(mSpy->count(), 1);
298296
299 QList<QVariant> arguments = mSpy->takeFirst();297 QList<QVariant> arguments = mSpy->takeFirst();
300 QContact expectedContact = makeTestContact(convertedPath);298 QContact expectedContact = makeTestContact(convertedPath);
301299
=== modified file 'tests/libtelephonyservice/GreeterContactsTestServer.cpp'
--- libtelephonyservice/tests/GreeterContactsTestServer.cpp 2014-07-01 16:05:21 +0000
+++ tests/libtelephonyservice/GreeterContactsTestServer.cpp 2015-03-30 20:55:55 +0000
@@ -24,7 +24,6 @@
24#include <QStringList>24#include <QStringList>
25#include <unistd.h>25#include <unistd.h>
2626
27
28#include <QDebug>27#include <QDebug>
29bool listGetCalled = false;28bool listGetCalled = false;
30bool userGetCalled = false;29bool userGetCalled = false;
3130
=== added file 'tests/libtelephonyservice/OfonoAccountEntryTest.cpp'
--- tests/libtelephonyservice/OfonoAccountEntryTest.cpp 1970-01-01 00:00:00 +0000
+++ tests/libtelephonyservice/OfonoAccountEntryTest.cpp 2015-03-30 20:55:55 +0000
@@ -0,0 +1,273 @@
1/*
2 * Copyright (C) 2015 Canonical, Ltd.
3 *
4 * This file is part of telephony-service.
5 *
6 * telephony-service is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * telephony-service is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <QtCore/QObject>
20#include <QtTest/QtTest>
21#include "telepathytest.h"
22#include "ofonoaccountentry.h"
23#include "accountentryfactory.h"
24#include "mockcontroller.h"
25
26class OfonoAccountEntryTest : public TelepathyTest
27{
28 Q_OBJECT
29
30private Q_SLOTS:
31 void initTestCase();
32 void init();
33 void cleanup();
34 void testAccountType();
35 void testConnected();
36 void testCompareIds_data();
37 void testCompareIds();
38 void testEmergencyNumbers();
39 void testSerial();
40 void testVoicemailIndicator();
41 void testVoicemailNumber();
42 void testVoicemailCount();
43 void testSimLocked();
44 void testEmergencyCallsAvailable_data();
45 void testEmergencyCallsAvailable();
46 void testNetworkName();
47 void testAddressableVCardFields();
48
49private:
50 OfonoAccountEntry *mAccount;
51 Tp::AccountPtr mTpAccount;
52 MockController *mMockController;
53};
54
55void OfonoAccountEntryTest::initTestCase()
56{
57 initialize();
58}
59
60void OfonoAccountEntryTest::init()
61{
62 mTpAccount = addAccount("mock", "ofono", "phone account");
63 QVERIFY(!mTpAccount.isNull());
64 QTRY_VERIFY(mTpAccount->isReady(Tp::Account::FeatureCore));
65
66 mAccount = qobject_cast<OfonoAccountEntry*>(AccountEntryFactory::createEntry(mTpAccount, this));
67 QVERIFY(mAccount);
68
69 // make sure the connection is available
70 QTRY_VERIFY(!mTpAccount->connection().isNull());
71 QTRY_COMPARE(mTpAccount->connection()->selfContact()->presence().type(), Tp::ConnectionPresenceTypeAvailable);
72 QTRY_VERIFY(mAccount->connected());
73
74 // create the mock controller
75 mMockController = new MockController("ofono", this);
76
77 // just in case, wait some time
78 QTest::qWait(500);
79}
80
81void OfonoAccountEntryTest::cleanup()
82{
83 doCleanup();
84 mAccount->deleteLater();
85 mMockController->deleteLater();
86}
87
88void OfonoAccountEntryTest::testAccountType()
89{
90 QCOMPARE(mAccount->type(), AccountEntry::PhoneAccount);
91}
92
93void OfonoAccountEntryTest::testConnected()
94{
95 // the mock account is enabled/connected by default, so make sure it is like that
96 QTRY_VERIFY(mAccount->connected());
97
98 // right now the ofono account connection status behave exactly like the generic class,
99 // but as the code path is different, test it again
100 QSignalSpy connectedChangedSpy(mAccount, SIGNAL(connectedChanged()));
101
102 // now set the account offline and see if the active flag changes correctly
103 mMockController->setOnline(false);
104 QTRY_VERIFY(!mAccount->connected());
105 QCOMPARE(connectedChangedSpy.count(), 1);
106
107 // now re-enable the account and check that the entry is updated
108 connectedChangedSpy.clear();
109 mMockController->setOnline(true);
110 QTRY_VERIFY(mAccount->connected());
111 QCOMPARE(connectedChangedSpy.count(), 1);
112}
113
114void OfonoAccountEntryTest::testCompareIds_data()
115{
116 QTest::addColumn<QString>("first");
117 QTest::addColumn<QString>("second");
118 QTest::addColumn<bool>("expectedResult");
119
120 QTest::newRow("identical values") << "1234567" << "1234567" << true;
121 QTest::newRow("case difference") << "TestId" << "testid" << false;
122 QTest::newRow("phone prefix") << "1234567" << "1231234567" << true;
123}
124
125void OfonoAccountEntryTest::testCompareIds()
126{
127 QFETCH(QString, first);
128 QFETCH(QString, second);
129 QFETCH(bool, expectedResult);
130
131 QCOMPARE(mAccount->compareIds(first, second), expectedResult);
132}
133
134void OfonoAccountEntryTest::testEmergencyNumbers()
135{
136 QSignalSpy emergencyNumbersChangedSpy(mAccount, SIGNAL(emergencyNumbersChanged()));
137
138 // check that the list is not empty at startup
139 QVERIFY(!mAccount->emergencyNumbers().isEmpty());
140
141 QStringList numbers;
142 numbers << "111" << "190" << "911";
143 qSort(numbers);
144 mMockController->setEmergencyNumbers(numbers);
145 QTRY_COMPARE(emergencyNumbersChangedSpy.count(), 1);
146
147 QStringList emergencyNumbers = mAccount->emergencyNumbers();
148 qSort(emergencyNumbers);
149
150 QCOMPARE(emergencyNumbers, numbers);
151}
152
153void OfonoAccountEntryTest::testSerial()
154{
155 QTRY_COMPARE(mAccount->serial(), mMockController->serial());
156}
157
158void OfonoAccountEntryTest::testVoicemailIndicator()
159{
160 // voicemail indicator is off by default on the mock CM
161 QVERIFY(!mAccount->voicemailIndicator());
162
163 QSignalSpy voiceMailIndicatorSpy(mAccount, SIGNAL(voicemailIndicatorChanged()));
164
165 // set to true
166 mMockController->setVoicemailIndicator(true);
167 QTRY_COMPARE(voiceMailIndicatorSpy.count(), 1);
168 QVERIFY(mAccount->voicemailIndicator());
169
170 // and set back to false
171 voiceMailIndicatorSpy.clear();
172 mMockController->setVoicemailIndicator(false);
173 QTRY_COMPARE(voiceMailIndicatorSpy.count(), 1);
174 QVERIFY(!mAccount->voicemailIndicator());
175}
176
177void OfonoAccountEntryTest::testVoicemailNumber()
178{
179 QSignalSpy voicemailNumberSpy(mAccount, SIGNAL(voicemailNumberChanged()));
180
181 // check that the number is not empty at startup
182 QVERIFY(!mAccount->voicemailNumber().isEmpty());
183
184 // try changing the number
185 QString number("12345");
186 mMockController->setVoicemailNumber(number);
187 QTRY_COMPARE(voicemailNumberSpy.count(), 1);
188 QCOMPARE(mAccount->voicemailNumber(), number);
189}
190
191void OfonoAccountEntryTest::testVoicemailCount()
192{
193 QSignalSpy voicemailCountSpy(mAccount, SIGNAL(voicemailCountChanged()));
194
195 // check that the count is zero at startup
196 QCOMPARE((int)mAccount->voicemailCount(), 0);
197
198 // set it to a bigger value
199 int count = 10;
200 mMockController->setVoicemailCount(count);
201 QTRY_COMPARE(voicemailCountSpy.count(), 1);
202 QCOMPARE((int)mAccount->voicemailCount(), count);
203
204 // and back to zero
205 voicemailCountSpy.clear();
206 mMockController->setVoicemailCount(0);
207 QTRY_COMPARE(voicemailCountSpy.count(), 1);
208 QCOMPARE((int)mAccount->voicemailCount(), 0);
209}
210
211void OfonoAccountEntryTest::testSimLocked()
212{
213 QSignalSpy simLockedSpy(mAccount, SIGNAL(simLockedChanged()));
214
215 // check that it is not locked by default
216 QVERIFY(!mAccount->simLocked());
217
218 // now try to set the status to simlocked
219 mMockController->setPresence("simlocked", "simlocked");
220 QTRY_COMPARE(simLockedSpy.count(), 1);
221 QVERIFY(mAccount->simLocked());
222}
223
224void OfonoAccountEntryTest::testEmergencyCallsAvailable_data()
225{
226 QTest::addColumn<QString>("status");
227 QTest::addColumn<bool>("available");
228
229 QTest::newRow("available") << "available" << true;
230 QTest::newRow("away") << "away" << true;
231 QTest::newRow("simlocked") << "simlocked" << true;
232 QTest::newRow("flightmode") << "flightmode" << false;
233 QTest::newRow("nosim") << "nosim" << true;
234 QTest::newRow("nomodem") << "nomodem" << false;
235 QTest::newRow("registered") << "registered" << true;
236 QTest::newRow("roaming") << "roaming" << true;
237 QTest::newRow("unregistered") << "unregistered" << true;
238 QTest::newRow("denied") << "denied" << true;
239 QTest::newRow("unknown") << "unknown" << true;
240 QTest::newRow("searching") << "searching" << true;
241}
242
243void OfonoAccountEntryTest::testEmergencyCallsAvailable()
244{
245 QFETCH(QString, status);
246 QFETCH(bool, available);
247
248 mMockController->setPresence(status, "");
249 QTRY_COMPARE(mAccount->status(), status);
250 QCOMPARE(mAccount->emergencyCallsAvailable(), available);
251}
252
253void OfonoAccountEntryTest::testNetworkName()
254{
255 QSignalSpy networkNameChangedSpy(mAccount, SIGNAL(statusMessageChanged()));
256
257 // set the value
258 QString statusMessage("SomeNetwork");
259 Tp::Presence presence(Tp::ConnectionPresenceTypeAvailable, "available", statusMessage);
260 mTpAccount->setRequestedPresence(presence);
261
262 QTRY_COMPARE(mAccount->networkName(), statusMessage);
263 QCOMPARE(networkNameChangedSpy.count(), 1);
264}
265
266void OfonoAccountEntryTest::testAddressableVCardFields()
267{
268 QVERIFY(!mAccount->addressableVCardFields().isEmpty());
269 QCOMPARE(mAccount->addressableVCardFields(), mTpAccount->protocolInfo().addressableVCardFields());
270}
271
272QTEST_MAIN(OfonoAccountEntryTest)
273#include "OfonoAccountEntryTest.moc"
0274
=== added file 'tests/libtelephonyservice/TelepathyHelperTest.cpp'
--- tests/libtelephonyservice/TelepathyHelperTest.cpp 1970-01-01 00:00:00 +0000
+++ tests/libtelephonyservice/TelepathyHelperTest.cpp 2015-03-30 20:55:55 +0000
@@ -0,0 +1,286 @@
1/*
2 * Copyright (C) 2015 Canonical, Ltd.
3 *
4 * This file is part of telephony-service.
5 *
6 * telephony-service is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * telephony-service is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <QtCore/QObject>
20#include <QtTest/QtTest>
21#include <TelepathyQt/PendingAccount>
22#include <TelepathyQt/PendingOperation>
23#include <TelepathyQt/Account>
24#include "telepathytest.h"
25#include "accountentry.h"
26#include "accountentryfactory.h"
27#include "telepathyhelper.h"
28#include "mockcontroller.h"
29
30class TelepathyHelperTest : public TelepathyTest
31{
32 Q_OBJECT
33
34private Q_SLOTS:
35 void initTestCase();
36 void init();
37 void cleanup();
38 void testConnected();
39 void testAccounts();
40 void testAccountSorting();
41 void testAccountIds();
42 void testActiveAccounts();
43 void testAccountForId();
44 void testAccountForConnection();
45 void testEmergencyCallsAvailable();
46
47private:
48 Tp::AccountPtr mGenericTpAccount;
49 Tp::AccountPtr mPhoneTpAccount;
50 MockController *mGenericController;
51 MockController *mPhoneController;
52};
53
54void TelepathyHelperTest::initTestCase()
55{
56 initialize();
57}
58
59void TelepathyHelperTest::init()
60{
61 // add two accounts
62 mGenericTpAccount = addAccount("mock", "mock", "the generic account");
63 QTRY_VERIFY(!mGenericTpAccount->connection().isNull());
64
65 mPhoneTpAccount = addAccount("mock", "ofono", "the phone account");
66 QTRY_VERIFY(!mPhoneTpAccount->connection().isNull());
67
68 // and create the mock controller
69 mGenericController = new MockController("mock", this);
70 mPhoneController = new MockController("ofono", this);
71}
72
73void TelepathyHelperTest::cleanup()
74{
75 // the accounts are removed in the parent class.
76 doCleanup();
77
78 mGenericController->deleteLater();
79 mPhoneController->deleteLater();
80}
81
82void TelepathyHelperTest::testConnected()
83{
84 QSignalSpy connectedChangedSpy(TelepathyHelper::instance(), SIGNAL(connectedChanged()));
85
86 // check that the default status is connected (always true for mock accounts)
87 QVERIFY(TelepathyHelper::instance()->connected());
88
89 // set one of the accounts offline and check that the connected status stays true
90 mGenericController->setOnline(false);
91 QTest::qWait(1000);
92 QCOMPARE(connectedChangedSpy.count(), 0);
93 QVERIFY(TelepathyHelper::instance()->connected());
94
95 // and set the other account as offline too. This time connected needs to change to false
96 mPhoneController->setOnline(false);
97 QTRY_COMPARE(connectedChangedSpy.count(), 1);
98 QVERIFY(!TelepathyHelper::instance()->connected());
99
100 // now set one of the accounts back online
101 connectedChangedSpy.clear();
102 mPhoneController->setOnline(true);
103 QTRY_COMPARE(connectedChangedSpy.count(), 1);
104 QVERIFY(TelepathyHelper::instance()->connected());
105
106 // and the other one just in case
107 connectedChangedSpy.clear();
108 mGenericController->setOnline(true);
109 QTest::qWait(1000);
110 QCOMPARE(connectedChangedSpy.count(), 0);
111 QVERIFY(TelepathyHelper::instance()->connected());
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches