Merge lp:~attente/content-hub/content-hub-glib-2 into lp:content-hub
- content-hub-glib-2
- Merge into trunk
Proposed by
William Hua
Status: | Superseded | ||||
---|---|---|---|---|---|
Proposed branch: | lp:~attente/content-hub/content-hub-glib-2 | ||||
Merge into: | lp:content-hub | ||||
Prerequisite: | lp:~ken-vandine/content-hub/dbus_test_runner | ||||
Diff against target: |
570 lines (+436/-6) 11 files modified
CMakeLists.txt (+7/-1) debian/control (+23/-0) debian/libcontent-hub-dev.install (+2/-2) debian/libcontent-hub-glib-dev.install (+3/-0) debian/libcontent-hub-glib0.install (+1/-0) debian/libcontent-hub0.install (+1/-1) libcontent-hub-glib.pc.in (+11/-0) src/com/ubuntu/content/CMakeLists.txt (+62/-2) tests/CMakeLists.txt (+1/-0) tests/acceptance-tests/CMakeLists.txt (+11/-0) tests/acceptance-tests/glib_test.cpp (+314/-0) |
||||
To merge this branch: | bzr merge lp:~attente/content-hub/content-hub-glib-2 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ken VanDine | Pending | ||
Review via email: mp+311443@code.launchpad.net |
This proposal has been superseded by a proposal from 2016-11-23.
Commit message
Add GLib bindings (LP: #1624437)
Description of the change
Add GLib bindings (LP: #1624437)
There's a GTK branch (wip/attente/
To post a comment you must log in.
- 309. By William Hua
-
Merge lp:content-hub
- 310. By William Hua
-
Fix build failure on zesty due to googletest 1.8. Also refactored
tests/acceptance-tests/ CMakeLists. txt to make adding tests less
cumbersome. (LP: #1644062) - 311. By William Hua
-
Group the commands better
Unmerged revisions
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'CMakeLists.txt' | |||
2 | --- CMakeLists.txt 2016-08-23 20:17:57 +0000 | |||
3 | +++ CMakeLists.txt 2016-11-23 14:51:34 +0000 | |||
4 | @@ -114,8 +114,14 @@ | |||
5 | 114 | set(exec_prefix ${prefix}/bin) | 114 | set(exec_prefix ${prefix}/bin) |
6 | 115 | set(libdir ${prefix}/${CMAKE_INSTALL_LIBDIR}) | 115 | set(libdir ${prefix}/${CMAKE_INSTALL_LIBDIR}) |
7 | 116 | set(pkg-name "libcontent-hub") | 116 | set(pkg-name "libcontent-hub") |
8 | 117 | set(glib-pkg-name "libcontent-hub-glib") | ||
9 | 117 | configure_file(libcontent-hub.pc.in libcontent-hub.pc @ONLY) | 118 | configure_file(libcontent-hub.pc.in libcontent-hub.pc @ONLY) |
11 | 118 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libcontent-hub.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) | 119 | configure_file(libcontent-hub-glib.pc.in libcontent-hub-glib.pc @ONLY) |
12 | 120 | install(FILES | ||
13 | 121 | ${CMAKE_CURRENT_BINARY_DIR}/libcontent-hub.pc | ||
14 | 122 | ${CMAKE_CURRENT_BINARY_DIR}/libcontent-hub-glib.pc | ||
15 | 123 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig | ||
16 | 124 | ) | ||
17 | 119 | 125 | ||
18 | 120 | # There's no nice way to format this. Thanks CMake. | 126 | # There's no nice way to format this. Thanks CMake. |
19 | 121 | add_test(LGPL-required | 127 | add_test(LGPL-required |
20 | 122 | 128 | ||
21 | === modified file 'debian/control' | |||
22 | --- debian/control 2016-10-25 18:45:11 +0000 | |||
23 | +++ debian/control 2016-11-23 14:51:34 +0000 | |||
24 | @@ -59,6 +59,20 @@ | |||
25 | 59 | securely and efficiently exchange content. | 59 | securely and efficiently exchange content. |
26 | 60 | This package includes the content sharing libraries. | 60 | This package includes the content sharing libraries. |
27 | 61 | 61 | ||
28 | 62 | Package: libcontent-hub-glib0 | ||
29 | 63 | Section: libs | ||
30 | 64 | Architecture: any | ||
31 | 65 | Multi-Arch: same | ||
32 | 66 | Pre-Depends: ${misc:Pre-Depends}, | ||
33 | 67 | Depends: ${misc:Depends}, | ||
34 | 68 | ${shlibs:Depends}, | ||
35 | 69 | Suggests: content-hub | ||
36 | 70 | Description: content sharing/picking library - GLib bindings | ||
37 | 71 | Content sharing/picking infrastructure and service, designed to allow apps to | ||
38 | 72 | securely and efficiently exchange content. | ||
39 | 73 | . | ||
40 | 74 | This package includes GLib bindings of the content sharing libraries. | ||
41 | 75 | |||
42 | 62 | Package: libcontent-hub-dev | 76 | Package: libcontent-hub-dev |
43 | 63 | Section: libdevel | 77 | Section: libdevel |
44 | 64 | Architecture: any | 78 | Architecture: any |
45 | @@ -68,6 +82,15 @@ | |||
46 | 68 | Description: content sharing development files | 82 | Description: content sharing development files |
47 | 69 | All the development headers and libraries for the content hub | 83 | All the development headers and libraries for the content hub |
48 | 70 | 84 | ||
49 | 85 | Package: libcontent-hub-glib-dev | ||
50 | 86 | Section: libdevel | ||
51 | 87 | Architecture: any | ||
52 | 88 | Multi-Arch: same | ||
53 | 89 | Depends: libcontent-hub-glib0 (= ${binary:Version}), | ||
54 | 90 | ${misc:Depends}, | ||
55 | 91 | Description: content sharing development files - GLib bindings | ||
56 | 92 | GLib bindings of the development headers and libraries for the content hub | ||
57 | 93 | |||
58 | 71 | Package: qtdeclarative5-ubuntu-content1 | 94 | Package: qtdeclarative5-ubuntu-content1 |
59 | 72 | Section: libs | 95 | Section: libs |
60 | 73 | Architecture: any | 96 | Architecture: any |
61 | 74 | 97 | ||
62 | === modified file 'debian/libcontent-hub-dev.install' | |||
63 | --- debian/libcontent-hub-dev.install 2013-09-30 21:28:46 +0000 | |||
64 | +++ debian/libcontent-hub-dev.install 2016-11-23 14:51:34 +0000 | |||
65 | @@ -1,3 +1,3 @@ | |||
67 | 1 | usr/include | 1 | usr/include/com/ubuntu/content/*.h |
68 | 2 | usr/lib/*/libcontent-hub.so | 2 | usr/lib/*/libcontent-hub.so |
70 | 3 | usr/lib/*/pkgconfig | 3 | usr/lib/*/pkgconfig/libcontent-hub.pc |
71 | 4 | 4 | ||
72 | === added file 'debian/libcontent-hub-glib-dev.install' | |||
73 | --- debian/libcontent-hub-glib-dev.install 1970-01-01 00:00:00 +0000 | |||
74 | +++ debian/libcontent-hub-glib-dev.install 2016-11-23 14:51:34 +0000 | |||
75 | @@ -0,0 +1,3 @@ | |||
76 | 1 | usr/include/com/ubuntu/content/glib/* | ||
77 | 2 | usr/lib/*/libcontent-hub-glib.so | ||
78 | 3 | usr/lib/*/pkgconfig/libcontent-hub-glib.pc | ||
79 | 0 | 4 | ||
80 | === added file 'debian/libcontent-hub-glib0.install' | |||
81 | --- debian/libcontent-hub-glib0.install 1970-01-01 00:00:00 +0000 | |||
82 | +++ debian/libcontent-hub-glib0.install 2016-11-23 14:51:34 +0000 | |||
83 | @@ -0,0 +1,1 @@ | |||
84 | 1 | usr/lib/*/libcontent-hub-glib.so.* | ||
85 | 0 | 2 | ||
86 | === modified file 'debian/libcontent-hub0.install' | |||
87 | --- debian/libcontent-hub0.install 2013-08-26 21:58:01 +0000 | |||
88 | +++ debian/libcontent-hub0.install 2016-11-23 14:51:34 +0000 | |||
89 | @@ -1,1 +1,1 @@ | |||
91 | 1 | usr/lib/*/lib*.so.* | 1 | usr/lib/*/libcontent-hub.so.* |
92 | 2 | 2 | ||
93 | === added file 'libcontent-hub-glib.pc.in' | |||
94 | --- libcontent-hub-glib.pc.in 1970-01-01 00:00:00 +0000 | |||
95 | +++ libcontent-hub-glib.pc.in 2016-11-23 14:51:34 +0000 | |||
96 | @@ -0,0 +1,11 @@ | |||
97 | 1 | prefix=@prefix@ | ||
98 | 2 | exec_prefix=@exec_prefix@ | ||
99 | 3 | libdir=@libdir@ | ||
100 | 4 | includedir=${prefix}/include | ||
101 | 5 | |||
102 | 6 | Name: @glib-pkg-name@ | ||
103 | 7 | Description: content sharing/picking library - GLib bindings | ||
104 | 8 | Version: @CONTENT_HUB_VERSION@ | ||
105 | 9 | Libs: -L${libdir} -lcontent-hub-glib | ||
106 | 10 | Cflags: -I${includedir} | ||
107 | 11 | Requires: gio-2.0 | ||
108 | 0 | 12 | ||
109 | === modified file 'src/com/ubuntu/content/CMakeLists.txt' | |||
110 | --- src/com/ubuntu/content/CMakeLists.txt 2016-09-22 18:10:11 +0000 | |||
111 | +++ src/com/ubuntu/content/CMakeLists.txt 2016-11-23 14:51:34 +0000 | |||
112 | @@ -28,6 +28,8 @@ | |||
113 | 28 | ${UBUNTU_DOWNLOAD_MANAGER_INCLUDE_DIRS} | 28 | ${UBUNTU_DOWNLOAD_MANAGER_INCLUDE_DIRS} |
114 | 29 | ${NOTIFY_INCLUDE_DIRS} | 29 | ${NOTIFY_INCLUDE_DIRS} |
115 | 30 | ${APPARMOR_INCLUDE_DIRS} | 30 | ${APPARMOR_INCLUDE_DIRS} |
116 | 31 | ${GLIB_INCLUDE_DIRS} | ||
117 | 32 | ${GIO_INCLUDE_DIRS} | ||
118 | 31 | ) | 33 | ) |
119 | 32 | 34 | ||
120 | 33 | qt5_add_dbus_interface( | 35 | qt5_add_dbus_interface( |
121 | @@ -120,8 +122,66 @@ | |||
122 | 120 | ${APPARMOR_LDFLAGS} | 122 | ${APPARMOR_LDFLAGS} |
123 | 121 | ) | 123 | ) |
124 | 122 | 124 | ||
127 | 123 | install( | 125 | find_program( |
128 | 124 | TARGETS content-hub | 126 | GDBUS_CODEGEN |
129 | 127 | gdbus-codegen | ||
130 | 128 | ) | ||
131 | 129 | |||
132 | 130 | set( | ||
133 | 131 | DBUS_XML | ||
134 | 132 | ${CMAKE_CURRENT_SOURCE_DIR}/detail/com.ubuntu.content.Handler.xml | ||
135 | 133 | ${CMAKE_CURRENT_SOURCE_DIR}/detail/com.ubuntu.content.Paste.xml | ||
136 | 134 | ${CMAKE_CURRENT_SOURCE_DIR}/detail/com.ubuntu.content.Service.xml | ||
137 | 135 | ${CMAKE_CURRENT_SOURCE_DIR}/detail/com.ubuntu.content.Transfer.xml | ||
138 | 136 | ) | ||
139 | 137 | |||
140 | 138 | set( | ||
141 | 139 | DBUS_ANNOTATIONS | ||
142 | 140 | --annotate com.ubuntu.content.dbus.Paste.Charge\(\)[mimeData] org.gtk.GDBus.C.ForceGVariant true | ||
143 | 141 | --annotate com.ubuntu.content.dbus.Paste.MimeData\(\)[mimeData] org.gtk.GDBus.C.ForceGVariant true | ||
144 | 142 | --annotate com.ubuntu.content.dbus.Service.CreatePaste\(\)[mimeData] org.gtk.GDBus.C.ForceGVariant true | ||
145 | 143 | --annotate com.ubuntu.content.dbus.Service.GetLatestPasteData\(\)[mimeData] org.gtk.GDBus.C.ForceGVariant true | ||
146 | 144 | --annotate com.ubuntu.content.dbus.Service.GetPasteData\(\)[mimeData] org.gtk.GDBus.C.ForceGVariant true | ||
147 | 145 | ) | ||
148 | 146 | |||
149 | 147 | add_custom_command( | ||
150 | 148 | OUTPUT glib/content-hub-glib.h glib/content-hub-glib.c | ||
151 | 149 | COMMAND ${CMAKE_COMMAND} -E make_directory glib | ||
152 | 150 | COMMAND ${GDBUS_CODEGEN} | ||
153 | 151 | --interface-prefix com.ubuntu.content.dbus | ||
154 | 152 | --generate-c-code glib/content-hub-glib | ||
155 | 153 | --c-namespace ContentHub | ||
156 | 154 | ${DBUS_ANNOTATIONS} | ||
157 | 155 | ${DBUS_XML} | ||
158 | 156 | DEPENDS ${DBUS_XML} | ||
159 | 157 | VERBATIM | ||
160 | 158 | ) | ||
161 | 159 | |||
162 | 160 | add_library( | ||
163 | 161 | content-hub-glib SHARED | ||
164 | 162 | glib/content-hub-glib.h | ||
165 | 163 | glib/content-hub-glib.c | ||
166 | 164 | ) | ||
167 | 165 | |||
168 | 166 | target_link_libraries( | ||
169 | 167 | content-hub-glib | ||
170 | 168 | ${GIO_LIBRARIES} | ||
171 | 169 | ) | ||
172 | 170 | |||
173 | 171 | set_target_properties( | ||
174 | 172 | content-hub-glib | ||
175 | 173 | PROPERTIES | ||
176 | 174 | VERSION ${CONTENT_HUB_VERSION_MAJOR}.${CONTENT_HUB_VERSION_MINOR}.${CONTENT_HUB_VERSION_PATCH} | ||
177 | 175 | SOVERSION ${CONTENT_HUB_VERSION_MAJOR} | ||
178 | 176 | ) | ||
179 | 177 | |||
180 | 178 | install( | ||
181 | 179 | FILES ${CMAKE_CURRENT_BINARY_DIR}/glib/content-hub-glib.h | ||
182 | 180 | DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/com/ubuntu/content/glib | ||
183 | 181 | ) | ||
184 | 182 | |||
185 | 183 | install( | ||
186 | 184 | TARGETS content-hub content-hub-glib | ||
187 | 125 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | 185 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
188 | 126 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | 186 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
189 | 127 | ) | 187 | ) |
190 | 128 | 188 | ||
191 | === modified file 'tests/CMakeLists.txt' | |||
192 | --- tests/CMakeLists.txt 2015-09-23 14:45:09 +0000 | |||
193 | +++ tests/CMakeLists.txt 2016-11-23 14:51:34 +0000 | |||
194 | @@ -30,6 +30,7 @@ | |||
195 | 30 | ${LIBERTINE_INCLUDE_DIRS} | 30 | ${LIBERTINE_INCLUDE_DIRS} |
196 | 31 | ${UBUNTU_LAUNCH_INCLUDE_DIRS} | 31 | ${UBUNTU_LAUNCH_INCLUDE_DIRS} |
197 | 32 | ${CMAKE_BINARY_DIR}/src | 32 | ${CMAKE_BINARY_DIR}/src |
198 | 33 | ${CMAKE_BINARY_DIR}/src/com/ubuntu/content | ||
199 | 33 | ${GMOCK_INCLUDE_DIR} | 34 | ${GMOCK_INCLUDE_DIR} |
200 | 34 | ${GTEST_INCLUDE_DIR} | 35 | ${GTEST_INCLUDE_DIR} |
201 | 35 | ) | 36 | ) |
202 | 36 | 37 | ||
203 | === modified file 'tests/acceptance-tests/CMakeLists.txt' | |||
204 | --- tests/acceptance-tests/CMakeLists.txt 2016-11-23 14:27:28 +0000 | |||
205 | +++ tests/acceptance-tests/CMakeLists.txt 2016-11-23 14:51:34 +0000 | |||
206 | @@ -80,6 +80,12 @@ | |||
207 | 80 | ${MOCS} | 80 | ${MOCS} |
208 | 81 | ) | 81 | ) |
209 | 82 | 82 | ||
210 | 83 | add_executable( | ||
211 | 84 | glib_test | ||
212 | 85 | glib_test.cpp | ||
213 | 86 | ${MOCS} | ||
214 | 87 | ) | ||
215 | 88 | |||
216 | 83 | qt5_use_modules(app_hub_communication_default_source Core Gui DBus Test) | 89 | qt5_use_modules(app_hub_communication_default_source Core Gui DBus Test) |
217 | 84 | qt5_use_modules(app_hub_communication_known_sources Core Gui DBus Test) | 90 | qt5_use_modules(app_hub_communication_known_sources Core Gui DBus Test) |
218 | 85 | qt5_use_modules(app_hub_communication_stores Core Gui DBus Test) | 91 | qt5_use_modules(app_hub_communication_stores Core Gui DBus Test) |
219 | @@ -89,6 +95,7 @@ | |||
220 | 89 | qt5_use_modules(test_utils Core Test) | 95 | qt5_use_modules(test_utils Core Test) |
221 | 90 | qt5_use_modules(test_hook Core Gui DBus Test) | 96 | qt5_use_modules(test_hook Core Gui DBus Test) |
222 | 91 | qt5_use_modules(mimedata_test Core Test) | 97 | qt5_use_modules(mimedata_test Core Test) |
223 | 98 | qt5_use_modules(glib_test Core Gui DBus Test) | ||
224 | 92 | 99 | ||
225 | 93 | target_link_libraries(app_hub_communication_stores content-hub gmock gtest gtest_main) | 100 | target_link_libraries(app_hub_communication_stores content-hub gmock gtest gtest_main) |
226 | 94 | target_link_libraries(app_hub_communication_default_source content-hub gmock gtest gtest_main) | 101 | target_link_libraries(app_hub_communication_default_source content-hub gmock gtest gtest_main) |
227 | @@ -101,6 +108,7 @@ | |||
228 | 101 | target_link_libraries(test_types content-hub gmock gtest gtest_main) | 108 | target_link_libraries(test_types content-hub gmock gtest gtest_main) |
229 | 102 | target_link_libraries(test_hook content-hub gmock gtest gtest_main ${GSETTINGS_LDFLAGS}) | 109 | target_link_libraries(test_hook content-hub gmock gtest gtest_main ${GSETTINGS_LDFLAGS}) |
230 | 103 | target_link_libraries(mimedata_test content-hub gmock gtest gtest_main) | 110 | target_link_libraries(mimedata_test content-hub gmock gtest gtest_main) |
231 | 111 | target_link_libraries(glib_test content-hub-glib content-hub gmock gtest gtest_main) | ||
232 | 104 | 112 | ||
233 | 105 | add_test(NAME app_hub_communication_default_source COMMAND dbus-test-runner --task ${CMAKE_CURRENT_BINARY_DIR}/app_hub_communication_default_source) | 113 | add_test(NAME app_hub_communication_default_source COMMAND dbus-test-runner --task ${CMAKE_CURRENT_BINARY_DIR}/app_hub_communication_default_source) |
234 | 106 | add_test(NAME app_hub_communication_known_sources COMMAND dbus-test-runner --task ${CMAKE_CURRENT_BINARY_DIR}/app_hub_communication_known_sources) | 114 | add_test(NAME app_hub_communication_known_sources COMMAND dbus-test-runner --task ${CMAKE_CURRENT_BINARY_DIR}/app_hub_communication_known_sources) |
235 | @@ -112,6 +120,7 @@ | |||
236 | 112 | add_test(NAME test_types COMMAND dbus-test-runner --task ${CMAKE_CURRENT_BINARY_DIR}/test_types) | 120 | add_test(NAME test_types COMMAND dbus-test-runner --task ${CMAKE_CURRENT_BINARY_DIR}/test_types) |
237 | 113 | add_test(NAME test_hook COMMAND dbus-test-runner --task ${CMAKE_CURRENT_BINARY_DIR}/test_hook) | 121 | add_test(NAME test_hook COMMAND dbus-test-runner --task ${CMAKE_CURRENT_BINARY_DIR}/test_hook) |
238 | 114 | add_test(NAME mimedata_test COMMAND mimedata_test) | 122 | add_test(NAME mimedata_test COMMAND mimedata_test) |
239 | 123 | add_test(NAME glib_test COMMAND dbus-test-runner --task ${CMAKE_CURRENT_BINARY_DIR}/glib_test) | ||
240 | 115 | 124 | ||
241 | 116 | SET_TESTS_PROPERTIES(app_hub_communication_stores | 125 | SET_TESTS_PROPERTIES(app_hub_communication_stores |
242 | 117 | PROPERTIES ENVIRONMENT "CONTENT_HUB_TESTING=1") | 126 | PROPERTIES ENVIRONMENT "CONTENT_HUB_TESTING=1") |
243 | @@ -133,6 +142,8 @@ | |||
244 | 133 | PROPERTIES ENVIRONMENT "CONTENT_HUB_TESTING=1") | 142 | PROPERTIES ENVIRONMENT "CONTENT_HUB_TESTING=1") |
245 | 134 | SET_TESTS_PROPERTIES(mimedata_test | 143 | SET_TESTS_PROPERTIES(mimedata_test |
246 | 135 | PROPERTIES ENVIRONMENT "CONTENT_HUB_TESTING=1") | 144 | PROPERTIES ENVIRONMENT "CONTENT_HUB_TESTING=1") |
247 | 145 | SET_TESTS_PROPERTIES(glib_test | ||
248 | 146 | PROPERTIES ENVIRONMENT "CONTENT_HUB_TESTING=1") | ||
249 | 136 | 147 | ||
250 | 137 | set_target_properties( | 148 | set_target_properties( |
251 | 138 | test_hook | 149 | test_hook |
252 | 139 | 150 | ||
253 | === added file 'tests/acceptance-tests/glib_test.cpp' | |||
254 | --- tests/acceptance-tests/glib_test.cpp 1970-01-01 00:00:00 +0000 | |||
255 | +++ tests/acceptance-tests/glib_test.cpp 2016-11-23 14:51:34 +0000 | |||
256 | @@ -0,0 +1,314 @@ | |||
257 | 1 | /* | ||
258 | 2 | * Copyright © 2016 Canonical Ltd. | ||
259 | 3 | * | ||
260 | 4 | * This program is free software: you can redistribute it and/or modify | ||
261 | 5 | * it under the terms of the GNU General Public License version 3 as | ||
262 | 6 | * published by the Free Software Foundation. | ||
263 | 7 | * | ||
264 | 8 | * This program is distributed in the hope that it will be useful, | ||
265 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
266 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
267 | 11 | * GNU Lesser General Public License for more details. | ||
268 | 12 | * | ||
269 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
270 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
271 | 15 | * | ||
272 | 16 | * Authored by: William Hua <william.hua@canonical.com> | ||
273 | 17 | */ | ||
274 | 18 | |||
275 | 19 | /* modified from app_hub_communication_paste.cpp */ | ||
276 | 20 | |||
277 | 21 | #include "app_manager_mock.h" | ||
278 | 22 | #include "test_harness.h" | ||
279 | 23 | #include "../cross_process_sync.h" | ||
280 | 24 | #include "../fork_and_run.h" | ||
281 | 25 | |||
282 | 26 | #include <com/ubuntu/content/hub.h> | ||
283 | 27 | #include <com/ubuntu/content/item.h> | ||
284 | 28 | #include <com/ubuntu/content/paste.h> | ||
285 | 29 | |||
286 | 30 | #include "com/ubuntu/content/detail/peer_registry.h" | ||
287 | 31 | #include "com/ubuntu/content/detail/service.h" | ||
288 | 32 | #include "com/ubuntu/content/serviceadaptor.h" | ||
289 | 33 | |||
290 | 34 | #include <gmock/gmock.h> | ||
291 | 35 | #include <gtest/gtest.h> | ||
292 | 36 | |||
293 | 37 | #include <QCoreApplication> | ||
294 | 38 | #include <QtDBus/QDBusConnection> | ||
295 | 39 | #include <QStandardPaths> | ||
296 | 40 | #include <QTemporaryDir> | ||
297 | 41 | #include <QtTest/QTest> | ||
298 | 42 | |||
299 | 43 | #include <thread> | ||
300 | 44 | |||
301 | 45 | #include <cstring> | ||
302 | 46 | #include <gio/gio.h> | ||
303 | 47 | |||
304 | 48 | #include "glib/content-hub-glib.h" | ||
305 | 49 | |||
306 | 50 | namespace cua = com::ubuntu::ApplicationManager; | ||
307 | 51 | namespace cuc = com::ubuntu::content; | ||
308 | 52 | namespace cucd = com::ubuntu::content::detail; | ||
309 | 53 | |||
310 | 54 | QString service_name{"com.ubuntu.content.dbus.Service"}; | ||
311 | 55 | |||
312 | 56 | struct MockedPeerRegistry : public cucd::PeerRegistry | ||
313 | 57 | { | ||
314 | 58 | MockedPeerRegistry() : cucd::PeerRegistry() | ||
315 | 59 | { | ||
316 | 60 | using namespace ::testing; | ||
317 | 61 | |||
318 | 62 | ON_CALL(*this, default_source_for_type(_)).WillByDefault(Return(cuc::Peer::unknown())); | ||
319 | 63 | ON_CALL(*this, install_default_source_for_type(_,_)).WillByDefault(Return(false)); | ||
320 | 64 | ON_CALL(*this, install_source_for_type(_,_)).WillByDefault(Return(false)); | ||
321 | 65 | } | ||
322 | 66 | |||
323 | 67 | MOCK_METHOD1(default_source_for_type, cuc::Peer(cuc::Type t)); | ||
324 | 68 | MOCK_METHOD1(enumerate_known_peers, void(const std::function<void(const cuc::Peer&)>&)); | ||
325 | 69 | MOCK_METHOD2(enumerate_known_sources_for_type, void(cuc::Type, const std::function<void(const cuc::Peer&)>&)); | ||
326 | 70 | MOCK_METHOD2(enumerate_known_destinations_for_type, void(cuc::Type, const std::function<void(const cuc::Peer&)>&)); | ||
327 | 71 | MOCK_METHOD2(enumerate_known_shares_for_type, void(cuc::Type, const std::function<void(const cuc::Peer&)>&)); | ||
328 | 72 | MOCK_METHOD2(install_default_source_for_type, bool(cuc::Type, cuc::Peer)); | ||
329 | 73 | MOCK_METHOD2(install_source_for_type, bool(cuc::Type, cuc::Peer)); | ||
330 | 74 | MOCK_METHOD2(install_destination_for_type, bool(cuc::Type, cuc::Peer)); | ||
331 | 75 | MOCK_METHOD2(install_share_for_type, bool(cuc::Type, cuc::Peer)); | ||
332 | 76 | MOCK_METHOD1(remove_peer, bool(cuc::Peer)); | ||
333 | 77 | MOCK_METHOD1(peer_is_legacy, bool(QString)); | ||
334 | 78 | }; | ||
335 | 79 | |||
336 | 80 | static const gchar *SERVICE_NAME = "com.ubuntu.content.dbus.Service"; | ||
337 | 81 | static const gchar *SERVICE_PATH = "/"; | ||
338 | 82 | static const gchar *APPLICATION_ID = "com.ubuntu.content.glib_test"; | ||
339 | 83 | static const gchar *HANDLER_PATH = "/com/ubuntu/content/handler"; | ||
340 | 84 | static const gchar *SURFACE_ID = "01234567-0123-0123-0123-0123456789ab"; | ||
341 | 85 | |||
342 | 86 | static const gchar * const PASTE_FORMATS[] = | ||
343 | 87 | { | ||
344 | 88 | "text/plain", | ||
345 | 89 | "text/html", | ||
346 | 90 | NULL | ||
347 | 91 | }; | ||
348 | 92 | |||
349 | 93 | static const gint N_PASTE_FORMATS = sizeof (PASTE_FORMATS) / sizeof (PASTE_FORMATS[0]) - 1; | ||
350 | 94 | |||
351 | 95 | static const gchar PASTE_DATA[] = | ||
352 | 96 | "text/plain" | ||
353 | 97 | "plain text" | ||
354 | 98 | "text/html" | ||
355 | 99 | "<p>html text</p>"; | ||
356 | 100 | |||
357 | 101 | static const gint N_PASTE_DATA = sizeof (PASTE_DATA) / sizeof (PASTE_DATA[0]) - 1; | ||
358 | 102 | |||
359 | 103 | static gboolean pasteboard_changed; | ||
360 | 104 | |||
361 | 105 | static void | ||
362 | 106 | pasteboard_changed_cb (ContentHubService *service, | ||
363 | 107 | gpointer user_data) | ||
364 | 108 | { | ||
365 | 109 | GMainLoop *main_loop = (GMainLoop *) user_data; | ||
366 | 110 | |||
367 | 111 | pasteboard_changed = TRUE; | ||
368 | 112 | |||
369 | 113 | g_main_loop_quit (main_loop); | ||
370 | 114 | } | ||
371 | 115 | |||
372 | 116 | static gboolean | ||
373 | 117 | timed_out_cb (gpointer user_data) | ||
374 | 118 | { | ||
375 | 119 | GMainLoop *main_loop = (GMainLoop *) user_data; | ||
376 | 120 | |||
377 | 121 | g_main_loop_quit (main_loop); | ||
378 | 122 | |||
379 | 123 | return G_SOURCE_CONTINUE; | ||
380 | 124 | } | ||
381 | 125 | |||
382 | 126 | static void | ||
383 | 127 | set_paste (ContentHubService *service) | ||
384 | 128 | { | ||
385 | 129 | GMainLoop *main_loop; | ||
386 | 130 | guint timeout_id; | ||
387 | 131 | |||
388 | 132 | g_assert_false (pasteboard_changed); | ||
389 | 133 | |||
390 | 134 | main_loop = g_main_loop_new (NULL, FALSE); | ||
391 | 135 | timeout_id = g_timeout_add (1000, timed_out_cb, main_loop); | ||
392 | 136 | |||
393 | 137 | g_signal_connect ( | ||
394 | 138 | service, | ||
395 | 139 | "pasteboard-changed", | ||
396 | 140 | G_CALLBACK (pasteboard_changed_cb), | ||
397 | 141 | main_loop); | ||
398 | 142 | |||
399 | 143 | g_assert_true ( | ||
400 | 144 | content_hub_service_call_create_paste_sync ( | ||
401 | 145 | service, | ||
402 | 146 | APPLICATION_ID, | ||
403 | 147 | SURFACE_ID, | ||
404 | 148 | g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, PASTE_DATA, sizeof (PASTE_DATA) - 1, sizeof (guchar)), | ||
405 | 149 | PASTE_FORMATS, | ||
406 | 150 | NULL, | ||
407 | 151 | NULL, | ||
408 | 152 | NULL)); | ||
409 | 153 | |||
410 | 154 | g_main_loop_run (main_loop); | ||
411 | 155 | g_source_remove (timeout_id); | ||
412 | 156 | g_clear_pointer (&main_loop, g_main_loop_unref); | ||
413 | 157 | |||
414 | 158 | g_assert_true (pasteboard_changed); | ||
415 | 159 | |||
416 | 160 | pasteboard_changed = FALSE; | ||
417 | 161 | } | ||
418 | 162 | |||
419 | 163 | static void | ||
420 | 164 | get_paste (ContentHubService *service) | ||
421 | 165 | { | ||
422 | 166 | gchar **formats; | ||
423 | 167 | GVariant *variant; | ||
424 | 168 | gconstpointer data; | ||
425 | 169 | gsize size; | ||
426 | 170 | gint i; | ||
427 | 171 | |||
428 | 172 | g_assert_true ( | ||
429 | 173 | content_hub_service_call_paste_formats_sync ( | ||
430 | 174 | service, | ||
431 | 175 | &formats, | ||
432 | 176 | NULL, | ||
433 | 177 | NULL)); | ||
434 | 178 | |||
435 | 179 | g_assert_cmpint (g_strv_length (formats), ==, N_PASTE_FORMATS); | ||
436 | 180 | |||
437 | 181 | for (i = 0; i < N_PASTE_FORMATS; i++) | ||
438 | 182 | g_assert_cmpstr (formats[i], ==, PASTE_FORMATS[i]); | ||
439 | 183 | |||
440 | 184 | g_strfreev (formats); | ||
441 | 185 | |||
442 | 186 | g_assert_true ( | ||
443 | 187 | content_hub_service_call_get_latest_paste_data_sync ( | ||
444 | 188 | service, | ||
445 | 189 | SURFACE_ID, | ||
446 | 190 | &variant, | ||
447 | 191 | NULL, | ||
448 | 192 | NULL)); | ||
449 | 193 | |||
450 | 194 | data = g_variant_get_fixed_array (variant, &size, sizeof (guchar)); | ||
451 | 195 | |||
452 | 196 | g_assert_cmpint (size, ==, N_PASTE_DATA); | ||
453 | 197 | g_assert_cmpint (memcmp (data, PASTE_DATA, N_PASTE_DATA), ==, 0); | ||
454 | 198 | } | ||
455 | 199 | |||
456 | 200 | int | ||
457 | 201 | glib_test (int argc, | ||
458 | 202 | char *argv[]) | ||
459 | 203 | { | ||
460 | 204 | GDBusConnection *session; | ||
461 | 205 | ContentHubService *service; | ||
462 | 206 | ContentHubHandler *handler; | ||
463 | 207 | |||
464 | 208 | session = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); | ||
465 | 209 | |||
466 | 210 | service = content_hub_service_proxy_new_sync ( | ||
467 | 211 | session, | ||
468 | 212 | G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES, | ||
469 | 213 | SERVICE_NAME, | ||
470 | 214 | SERVICE_PATH, | ||
471 | 215 | NULL, | ||
472 | 216 | NULL); | ||
473 | 217 | |||
474 | 218 | g_assert_nonnull (service); | ||
475 | 219 | |||
476 | 220 | handler = content_hub_handler_skeleton_new (); | ||
477 | 221 | |||
478 | 222 | g_assert_true ( | ||
479 | 223 | g_dbus_interface_skeleton_export ( | ||
480 | 224 | G_DBUS_INTERFACE_SKELETON (handler), | ||
481 | 225 | session, | ||
482 | 226 | HANDLER_PATH, | ||
483 | 227 | NULL)); | ||
484 | 228 | |||
485 | 229 | g_object_unref (session); | ||
486 | 230 | |||
487 | 231 | g_assert_true ( | ||
488 | 232 | content_hub_service_call_register_import_export_handler_sync ( | ||
489 | 233 | service, | ||
490 | 234 | APPLICATION_ID, | ||
491 | 235 | HANDLER_PATH, | ||
492 | 236 | NULL, | ||
493 | 237 | NULL)); | ||
494 | 238 | |||
495 | 239 | g_assert_true ( | ||
496 | 240 | content_hub_service_call_handler_active_sync ( | ||
497 | 241 | service, | ||
498 | 242 | APPLICATION_ID, | ||
499 | 243 | NULL, | ||
500 | 244 | NULL)); | ||
501 | 245 | |||
502 | 246 | set_paste (service); | ||
503 | 247 | get_paste (service); | ||
504 | 248 | |||
505 | 249 | g_assert_true ( | ||
506 | 250 | content_hub_service_call_quit_sync ( | ||
507 | 251 | service, | ||
508 | 252 | NULL, | ||
509 | 253 | NULL)); | ||
510 | 254 | |||
511 | 255 | g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (handler)); | ||
512 | 256 | g_object_unref (handler); | ||
513 | 257 | g_object_unref (service); | ||
514 | 258 | |||
515 | 259 | return 0; | ||
516 | 260 | } | ||
517 | 261 | |||
518 | 262 | /* modified from app_hub_communication_paste.cpp */ | ||
519 | 263 | |||
520 | 264 | TEST(GLib, glib_test) | ||
521 | 265 | { | ||
522 | 266 | using namespace ::testing; | ||
523 | 267 | |||
524 | 268 | test::CrossProcessSync sync; | ||
525 | 269 | |||
526 | 270 | auto parent = [&sync]() | ||
527 | 271 | { | ||
528 | 272 | int argc = 0; | ||
529 | 273 | QCoreApplication app{argc, nullptr}; | ||
530 | 274 | |||
531 | 275 | QDBusConnection connection = QDBusConnection::sessionBus(); | ||
532 | 276 | |||
533 | 277 | auto mock = new ::testing::NiceMock<MockedPeerRegistry>{}; | ||
534 | 278 | |||
535 | 279 | QSharedPointer<cucd::PeerRegistry> registry{mock}; | ||
536 | 280 | auto app_manager = QSharedPointer<cua::ApplicationManager>(new MockedAppManager()); | ||
537 | 281 | cucd::Service implementation(connection, registry, app_manager, &app); | ||
538 | 282 | new ServiceAdaptor(std::addressof(implementation)); | ||
539 | 283 | |||
540 | 284 | ASSERT_TRUE(connection.registerService(service_name)); | ||
541 | 285 | ASSERT_TRUE(connection.registerObject("/", std::addressof(implementation))); | ||
542 | 286 | |||
543 | 287 | sync.signal_ready(); | ||
544 | 288 | |||
545 | 289 | app.exec(); | ||
546 | 290 | |||
547 | 291 | connection.unregisterObject("/"); | ||
548 | 292 | connection.unregisterService(service_name); | ||
549 | 293 | }; | ||
550 | 294 | |||
551 | 295 | auto child = [&sync]() | ||
552 | 296 | { | ||
553 | 297 | int argc = 0; | ||
554 | 298 | QCoreApplication app(argc, nullptr); | ||
555 | 299 | |||
556 | 300 | sync.wait_for_signal_ready(); | ||
557 | 301 | |||
558 | 302 | test::TestHarness harness; | ||
559 | 303 | harness.add_test_case([]() | ||
560 | 304 | { | ||
561 | 305 | char arg0[] = "glib_test"; | ||
562 | 306 | char *argv[] = { arg0 }; | ||
563 | 307 | |||
564 | 308 | EXPECT_EQ(0, glib_test(1, argv)); | ||
565 | 309 | }); | ||
566 | 310 | EXPECT_EQ(0, QTest::qExec(std::addressof(harness))); | ||
567 | 311 | }; | ||
568 | 312 | |||
569 | 313 | EXPECT_EQ(EXIT_SUCCESS, test::fork_and_run(child, parent)); | ||
570 | 314 | } |