Merge lp:~attente/content-hub/content-hub-glib-2 into lp:content-hub

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
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/mir-content-hub) that needs this for copy-paste support.

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
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2016-08-23 20:17:57 +0000
+++ CMakeLists.txt 2016-11-23 14:51:34 +0000
@@ -114,8 +114,14 @@
114set(exec_prefix ${prefix}/bin)114set(exec_prefix ${prefix}/bin)
115set(libdir ${prefix}/${CMAKE_INSTALL_LIBDIR})115set(libdir ${prefix}/${CMAKE_INSTALL_LIBDIR})
116set(pkg-name "libcontent-hub")116set(pkg-name "libcontent-hub")
117set(glib-pkg-name "libcontent-hub-glib")
117configure_file(libcontent-hub.pc.in libcontent-hub.pc @ONLY)118configure_file(libcontent-hub.pc.in libcontent-hub.pc @ONLY)
118install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libcontent-hub.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)119configure_file(libcontent-hub-glib.pc.in libcontent-hub-glib.pc @ONLY)
120install(FILES
121 ${CMAKE_CURRENT_BINARY_DIR}/libcontent-hub.pc
122 ${CMAKE_CURRENT_BINARY_DIR}/libcontent-hub-glib.pc
123 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
124)
119125
120# There's no nice way to format this. Thanks CMake.126# There's no nice way to format this. Thanks CMake.
121add_test(LGPL-required127add_test(LGPL-required
122128
=== modified file 'debian/control'
--- debian/control 2016-10-25 18:45:11 +0000
+++ debian/control 2016-11-23 14:51:34 +0000
@@ -59,6 +59,20 @@
59 securely and efficiently exchange content.59 securely and efficiently exchange content.
60 This package includes the content sharing libraries.60 This package includes the content sharing libraries.
6161
62Package: libcontent-hub-glib0
63Section: libs
64Architecture: any
65Multi-Arch: same
66Pre-Depends: ${misc:Pre-Depends},
67Depends: ${misc:Depends},
68 ${shlibs:Depends},
69Suggests: content-hub
70Description: content sharing/picking library - GLib bindings
71 Content sharing/picking infrastructure and service, designed to allow apps to
72 securely and efficiently exchange content.
73 .
74 This package includes GLib bindings of the content sharing libraries.
75
62Package: libcontent-hub-dev76Package: libcontent-hub-dev
63Section: libdevel77Section: libdevel
64Architecture: any78Architecture: any
@@ -68,6 +82,15 @@
68Description: content sharing development files82Description: content sharing development files
69 All the development headers and libraries for the content hub83 All the development headers and libraries for the content hub
7084
85Package: libcontent-hub-glib-dev
86Section: libdevel
87Architecture: any
88Multi-Arch: same
89Depends: libcontent-hub-glib0 (= ${binary:Version}),
90 ${misc:Depends},
91Description: content sharing development files - GLib bindings
92 GLib bindings of the development headers and libraries for the content hub
93
71Package: qtdeclarative5-ubuntu-content194Package: qtdeclarative5-ubuntu-content1
72Section: libs95Section: libs
73Architecture: any96Architecture: any
7497
=== modified file 'debian/libcontent-hub-dev.install'
--- debian/libcontent-hub-dev.install 2013-09-30 21:28:46 +0000
+++ debian/libcontent-hub-dev.install 2016-11-23 14:51:34 +0000
@@ -1,3 +1,3 @@
1usr/include1usr/include/com/ubuntu/content/*.h
2usr/lib/*/libcontent-hub.so2usr/lib/*/libcontent-hub.so
3usr/lib/*/pkgconfig3usr/lib/*/pkgconfig/libcontent-hub.pc
44
=== added file 'debian/libcontent-hub-glib-dev.install'
--- debian/libcontent-hub-glib-dev.install 1970-01-01 00:00:00 +0000
+++ debian/libcontent-hub-glib-dev.install 2016-11-23 14:51:34 +0000
@@ -0,0 +1,3 @@
1usr/include/com/ubuntu/content/glib/*
2usr/lib/*/libcontent-hub-glib.so
3usr/lib/*/pkgconfig/libcontent-hub-glib.pc
04
=== added file 'debian/libcontent-hub-glib0.install'
--- debian/libcontent-hub-glib0.install 1970-01-01 00:00:00 +0000
+++ debian/libcontent-hub-glib0.install 2016-11-23 14:51:34 +0000
@@ -0,0 +1,1 @@
1usr/lib/*/libcontent-hub-glib.so.*
02
=== modified file 'debian/libcontent-hub0.install'
--- debian/libcontent-hub0.install 2013-08-26 21:58:01 +0000
+++ debian/libcontent-hub0.install 2016-11-23 14:51:34 +0000
@@ -1,1 +1,1 @@
1usr/lib/*/lib*.so.*1usr/lib/*/libcontent-hub.so.*
22
=== added file 'libcontent-hub-glib.pc.in'
--- libcontent-hub-glib.pc.in 1970-01-01 00:00:00 +0000
+++ libcontent-hub-glib.pc.in 2016-11-23 14:51:34 +0000
@@ -0,0 +1,11 @@
1prefix=@prefix@
2exec_prefix=@exec_prefix@
3libdir=@libdir@
4includedir=${prefix}/include
5
6Name: @glib-pkg-name@
7Description: content sharing/picking library - GLib bindings
8Version: @CONTENT_HUB_VERSION@
9Libs: -L${libdir} -lcontent-hub-glib
10Cflags: -I${includedir}
11Requires: gio-2.0
012
=== modified file 'src/com/ubuntu/content/CMakeLists.txt'
--- src/com/ubuntu/content/CMakeLists.txt 2016-09-22 18:10:11 +0000
+++ src/com/ubuntu/content/CMakeLists.txt 2016-11-23 14:51:34 +0000
@@ -28,6 +28,8 @@
28 ${UBUNTU_DOWNLOAD_MANAGER_INCLUDE_DIRS}28 ${UBUNTU_DOWNLOAD_MANAGER_INCLUDE_DIRS}
29 ${NOTIFY_INCLUDE_DIRS}29 ${NOTIFY_INCLUDE_DIRS}
30 ${APPARMOR_INCLUDE_DIRS}30 ${APPARMOR_INCLUDE_DIRS}
31 ${GLIB_INCLUDE_DIRS}
32 ${GIO_INCLUDE_DIRS}
31)33)
3234
33qt5_add_dbus_interface(35qt5_add_dbus_interface(
@@ -120,8 +122,66 @@
120 ${APPARMOR_LDFLAGS}122 ${APPARMOR_LDFLAGS}
121)123)
122124
123install(125find_program(
124 TARGETS content-hub126 GDBUS_CODEGEN
127 gdbus-codegen
128)
129
130set(
131 DBUS_XML
132 ${CMAKE_CURRENT_SOURCE_DIR}/detail/com.ubuntu.content.Handler.xml
133 ${CMAKE_CURRENT_SOURCE_DIR}/detail/com.ubuntu.content.Paste.xml
134 ${CMAKE_CURRENT_SOURCE_DIR}/detail/com.ubuntu.content.Service.xml
135 ${CMAKE_CURRENT_SOURCE_DIR}/detail/com.ubuntu.content.Transfer.xml
136)
137
138set(
139 DBUS_ANNOTATIONS
140 --annotate com.ubuntu.content.dbus.Paste.Charge\(\)[mimeData] org.gtk.GDBus.C.ForceGVariant true
141 --annotate com.ubuntu.content.dbus.Paste.MimeData\(\)[mimeData] org.gtk.GDBus.C.ForceGVariant true
142 --annotate com.ubuntu.content.dbus.Service.CreatePaste\(\)[mimeData] org.gtk.GDBus.C.ForceGVariant true
143 --annotate com.ubuntu.content.dbus.Service.GetLatestPasteData\(\)[mimeData] org.gtk.GDBus.C.ForceGVariant true
144 --annotate com.ubuntu.content.dbus.Service.GetPasteData\(\)[mimeData] org.gtk.GDBus.C.ForceGVariant true
145)
146
147add_custom_command(
148 OUTPUT glib/content-hub-glib.h glib/content-hub-glib.c
149 COMMAND ${CMAKE_COMMAND} -E make_directory glib
150 COMMAND ${GDBUS_CODEGEN}
151 --interface-prefix com.ubuntu.content.dbus
152 --generate-c-code glib/content-hub-glib
153 --c-namespace ContentHub
154 ${DBUS_ANNOTATIONS}
155 ${DBUS_XML}
156 DEPENDS ${DBUS_XML}
157 VERBATIM
158)
159
160add_library(
161 content-hub-glib SHARED
162 glib/content-hub-glib.h
163 glib/content-hub-glib.c
164)
165
166target_link_libraries(
167 content-hub-glib
168 ${GIO_LIBRARIES}
169)
170
171set_target_properties(
172 content-hub-glib
173 PROPERTIES
174 VERSION ${CONTENT_HUB_VERSION_MAJOR}.${CONTENT_HUB_VERSION_MINOR}.${CONTENT_HUB_VERSION_PATCH}
175 SOVERSION ${CONTENT_HUB_VERSION_MAJOR}
176)
177
178install(
179 FILES ${CMAKE_CURRENT_BINARY_DIR}/glib/content-hub-glib.h
180 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/com/ubuntu/content/glib
181)
182
183install(
184 TARGETS content-hub content-hub-glib
125 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}185 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
126 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}186 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
127)187)
128188
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2015-09-23 14:45:09 +0000
+++ tests/CMakeLists.txt 2016-11-23 14:51:34 +0000
@@ -30,6 +30,7 @@
30 ${LIBERTINE_INCLUDE_DIRS}30 ${LIBERTINE_INCLUDE_DIRS}
31 ${UBUNTU_LAUNCH_INCLUDE_DIRS}31 ${UBUNTU_LAUNCH_INCLUDE_DIRS}
32 ${CMAKE_BINARY_DIR}/src32 ${CMAKE_BINARY_DIR}/src
33 ${CMAKE_BINARY_DIR}/src/com/ubuntu/content
33 ${GMOCK_INCLUDE_DIR}34 ${GMOCK_INCLUDE_DIR}
34 ${GTEST_INCLUDE_DIR}35 ${GTEST_INCLUDE_DIR}
35)36)
3637
=== modified file 'tests/acceptance-tests/CMakeLists.txt'
--- tests/acceptance-tests/CMakeLists.txt 2016-11-23 14:27:28 +0000
+++ tests/acceptance-tests/CMakeLists.txt 2016-11-23 14:51:34 +0000
@@ -80,6 +80,12 @@
80 ${MOCS}80 ${MOCS}
81)81)
8282
83add_executable(
84 glib_test
85 glib_test.cpp
86 ${MOCS}
87)
88
83qt5_use_modules(app_hub_communication_default_source Core Gui DBus Test)89qt5_use_modules(app_hub_communication_default_source Core Gui DBus Test)
84qt5_use_modules(app_hub_communication_known_sources Core Gui DBus Test)90qt5_use_modules(app_hub_communication_known_sources Core Gui DBus Test)
85qt5_use_modules(app_hub_communication_stores Core Gui DBus Test)91qt5_use_modules(app_hub_communication_stores Core Gui DBus Test)
@@ -89,6 +95,7 @@
89qt5_use_modules(test_utils Core Test)95qt5_use_modules(test_utils Core Test)
90qt5_use_modules(test_hook Core Gui DBus Test)96qt5_use_modules(test_hook Core Gui DBus Test)
91qt5_use_modules(mimedata_test Core Test)97qt5_use_modules(mimedata_test Core Test)
98qt5_use_modules(glib_test Core Gui DBus Test)
9299
93target_link_libraries(app_hub_communication_stores content-hub gmock gtest gtest_main)100target_link_libraries(app_hub_communication_stores content-hub gmock gtest gtest_main)
94target_link_libraries(app_hub_communication_default_source content-hub gmock gtest gtest_main)101target_link_libraries(app_hub_communication_default_source content-hub gmock gtest gtest_main)
@@ -101,6 +108,7 @@
101target_link_libraries(test_types content-hub gmock gtest gtest_main)108target_link_libraries(test_types content-hub gmock gtest gtest_main)
102target_link_libraries(test_hook content-hub gmock gtest gtest_main ${GSETTINGS_LDFLAGS})109target_link_libraries(test_hook content-hub gmock gtest gtest_main ${GSETTINGS_LDFLAGS})
103target_link_libraries(mimedata_test content-hub gmock gtest gtest_main)110target_link_libraries(mimedata_test content-hub gmock gtest gtest_main)
111target_link_libraries(glib_test content-hub-glib content-hub gmock gtest gtest_main)
104112
105add_test(NAME app_hub_communication_default_source COMMAND dbus-test-runner --task ${CMAKE_CURRENT_BINARY_DIR}/app_hub_communication_default_source)113add_test(NAME app_hub_communication_default_source COMMAND dbus-test-runner --task ${CMAKE_CURRENT_BINARY_DIR}/app_hub_communication_default_source)
106add_test(NAME app_hub_communication_known_sources COMMAND dbus-test-runner --task ${CMAKE_CURRENT_BINARY_DIR}/app_hub_communication_known_sources)114add_test(NAME app_hub_communication_known_sources COMMAND dbus-test-runner --task ${CMAKE_CURRENT_BINARY_DIR}/app_hub_communication_known_sources)
@@ -112,6 +120,7 @@
112add_test(NAME test_types COMMAND dbus-test-runner --task ${CMAKE_CURRENT_BINARY_DIR}/test_types)120add_test(NAME test_types COMMAND dbus-test-runner --task ${CMAKE_CURRENT_BINARY_DIR}/test_types)
113add_test(NAME test_hook COMMAND dbus-test-runner --task ${CMAKE_CURRENT_BINARY_DIR}/test_hook)121add_test(NAME test_hook COMMAND dbus-test-runner --task ${CMAKE_CURRENT_BINARY_DIR}/test_hook)
114add_test(NAME mimedata_test COMMAND mimedata_test)122add_test(NAME mimedata_test COMMAND mimedata_test)
123add_test(NAME glib_test COMMAND dbus-test-runner --task ${CMAKE_CURRENT_BINARY_DIR}/glib_test)
115124
116SET_TESTS_PROPERTIES(app_hub_communication_stores125SET_TESTS_PROPERTIES(app_hub_communication_stores
117 PROPERTIES ENVIRONMENT "CONTENT_HUB_TESTING=1")126 PROPERTIES ENVIRONMENT "CONTENT_HUB_TESTING=1")
@@ -133,6 +142,8 @@
133 PROPERTIES ENVIRONMENT "CONTENT_HUB_TESTING=1")142 PROPERTIES ENVIRONMENT "CONTENT_HUB_TESTING=1")
134SET_TESTS_PROPERTIES(mimedata_test143SET_TESTS_PROPERTIES(mimedata_test
135 PROPERTIES ENVIRONMENT "CONTENT_HUB_TESTING=1")144 PROPERTIES ENVIRONMENT "CONTENT_HUB_TESTING=1")
145SET_TESTS_PROPERTIES(glib_test
146 PROPERTIES ENVIRONMENT "CONTENT_HUB_TESTING=1")
136147
137set_target_properties(148set_target_properties(
138 test_hook149 test_hook
139150
=== added file 'tests/acceptance-tests/glib_test.cpp'
--- tests/acceptance-tests/glib_test.cpp 1970-01-01 00:00:00 +0000
+++ tests/acceptance-tests/glib_test.cpp 2016-11-23 14:51:34 +0000
@@ -0,0 +1,314 @@
1/*
2 * Copyright © 2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: William Hua <william.hua@canonical.com>
17 */
18
19/* modified from app_hub_communication_paste.cpp */
20
21#include "app_manager_mock.h"
22#include "test_harness.h"
23#include "../cross_process_sync.h"
24#include "../fork_and_run.h"
25
26#include <com/ubuntu/content/hub.h>
27#include <com/ubuntu/content/item.h>
28#include <com/ubuntu/content/paste.h>
29
30#include "com/ubuntu/content/detail/peer_registry.h"
31#include "com/ubuntu/content/detail/service.h"
32#include "com/ubuntu/content/serviceadaptor.h"
33
34#include <gmock/gmock.h>
35#include <gtest/gtest.h>
36
37#include <QCoreApplication>
38#include <QtDBus/QDBusConnection>
39#include <QStandardPaths>
40#include <QTemporaryDir>
41#include <QtTest/QTest>
42
43#include <thread>
44
45#include <cstring>
46#include <gio/gio.h>
47
48#include "glib/content-hub-glib.h"
49
50namespace cua = com::ubuntu::ApplicationManager;
51namespace cuc = com::ubuntu::content;
52namespace cucd = com::ubuntu::content::detail;
53
54QString service_name{"com.ubuntu.content.dbus.Service"};
55
56struct MockedPeerRegistry : public cucd::PeerRegistry
57{
58 MockedPeerRegistry() : cucd::PeerRegistry()
59 {
60 using namespace ::testing;
61
62 ON_CALL(*this, default_source_for_type(_)).WillByDefault(Return(cuc::Peer::unknown()));
63 ON_CALL(*this, install_default_source_for_type(_,_)).WillByDefault(Return(false));
64 ON_CALL(*this, install_source_for_type(_,_)).WillByDefault(Return(false));
65 }
66
67 MOCK_METHOD1(default_source_for_type, cuc::Peer(cuc::Type t));
68 MOCK_METHOD1(enumerate_known_peers, void(const std::function<void(const cuc::Peer&)>&));
69 MOCK_METHOD2(enumerate_known_sources_for_type, void(cuc::Type, const std::function<void(const cuc::Peer&)>&));
70 MOCK_METHOD2(enumerate_known_destinations_for_type, void(cuc::Type, const std::function<void(const cuc::Peer&)>&));
71 MOCK_METHOD2(enumerate_known_shares_for_type, void(cuc::Type, const std::function<void(const cuc::Peer&)>&));
72 MOCK_METHOD2(install_default_source_for_type, bool(cuc::Type, cuc::Peer));
73 MOCK_METHOD2(install_source_for_type, bool(cuc::Type, cuc::Peer));
74 MOCK_METHOD2(install_destination_for_type, bool(cuc::Type, cuc::Peer));
75 MOCK_METHOD2(install_share_for_type, bool(cuc::Type, cuc::Peer));
76 MOCK_METHOD1(remove_peer, bool(cuc::Peer));
77 MOCK_METHOD1(peer_is_legacy, bool(QString));
78};
79
80static const gchar *SERVICE_NAME = "com.ubuntu.content.dbus.Service";
81static const gchar *SERVICE_PATH = "/";
82static const gchar *APPLICATION_ID = "com.ubuntu.content.glib_test";
83static const gchar *HANDLER_PATH = "/com/ubuntu/content/handler";
84static const gchar *SURFACE_ID = "01234567-0123-0123-0123-0123456789ab";
85
86static const gchar * const PASTE_FORMATS[] =
87{
88 "text/plain",
89 "text/html",
90 NULL
91};
92
93static const gint N_PASTE_FORMATS = sizeof (PASTE_FORMATS) / sizeof (PASTE_FORMATS[0]) - 1;
94
95static const gchar PASTE_DATA[] =
96 "text/plain"
97 "plain text"
98 "text/html"
99 "<p>html text</p>";
100
101static const gint N_PASTE_DATA = sizeof (PASTE_DATA) / sizeof (PASTE_DATA[0]) - 1;
102
103static gboolean pasteboard_changed;
104
105static void
106pasteboard_changed_cb (ContentHubService *service,
107 gpointer user_data)
108{
109 GMainLoop *main_loop = (GMainLoop *) user_data;
110
111 pasteboard_changed = TRUE;
112
113 g_main_loop_quit (main_loop);
114}
115
116static gboolean
117timed_out_cb (gpointer user_data)
118{
119 GMainLoop *main_loop = (GMainLoop *) user_data;
120
121 g_main_loop_quit (main_loop);
122
123 return G_SOURCE_CONTINUE;
124}
125
126static void
127set_paste (ContentHubService *service)
128{
129 GMainLoop *main_loop;
130 guint timeout_id;
131
132 g_assert_false (pasteboard_changed);
133
134 main_loop = g_main_loop_new (NULL, FALSE);
135 timeout_id = g_timeout_add (1000, timed_out_cb, main_loop);
136
137 g_signal_connect (
138 service,
139 "pasteboard-changed",
140 G_CALLBACK (pasteboard_changed_cb),
141 main_loop);
142
143 g_assert_true (
144 content_hub_service_call_create_paste_sync (
145 service,
146 APPLICATION_ID,
147 SURFACE_ID,
148 g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, PASTE_DATA, sizeof (PASTE_DATA) - 1, sizeof (guchar)),
149 PASTE_FORMATS,
150 NULL,
151 NULL,
152 NULL));
153
154 g_main_loop_run (main_loop);
155 g_source_remove (timeout_id);
156 g_clear_pointer (&main_loop, g_main_loop_unref);
157
158 g_assert_true (pasteboard_changed);
159
160 pasteboard_changed = FALSE;
161}
162
163static void
164get_paste (ContentHubService *service)
165{
166 gchar **formats;
167 GVariant *variant;
168 gconstpointer data;
169 gsize size;
170 gint i;
171
172 g_assert_true (
173 content_hub_service_call_paste_formats_sync (
174 service,
175 &formats,
176 NULL,
177 NULL));
178
179 g_assert_cmpint (g_strv_length (formats), ==, N_PASTE_FORMATS);
180
181 for (i = 0; i < N_PASTE_FORMATS; i++)
182 g_assert_cmpstr (formats[i], ==, PASTE_FORMATS[i]);
183
184 g_strfreev (formats);
185
186 g_assert_true (
187 content_hub_service_call_get_latest_paste_data_sync (
188 service,
189 SURFACE_ID,
190 &variant,
191 NULL,
192 NULL));
193
194 data = g_variant_get_fixed_array (variant, &size, sizeof (guchar));
195
196 g_assert_cmpint (size, ==, N_PASTE_DATA);
197 g_assert_cmpint (memcmp (data, PASTE_DATA, N_PASTE_DATA), ==, 0);
198}
199
200int
201glib_test (int argc,
202 char *argv[])
203{
204 GDBusConnection *session;
205 ContentHubService *service;
206 ContentHubHandler *handler;
207
208 session = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
209
210 service = content_hub_service_proxy_new_sync (
211 session,
212 G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES,
213 SERVICE_NAME,
214 SERVICE_PATH,
215 NULL,
216 NULL);
217
218 g_assert_nonnull (service);
219
220 handler = content_hub_handler_skeleton_new ();
221
222 g_assert_true (
223 g_dbus_interface_skeleton_export (
224 G_DBUS_INTERFACE_SKELETON (handler),
225 session,
226 HANDLER_PATH,
227 NULL));
228
229 g_object_unref (session);
230
231 g_assert_true (
232 content_hub_service_call_register_import_export_handler_sync (
233 service,
234 APPLICATION_ID,
235 HANDLER_PATH,
236 NULL,
237 NULL));
238
239 g_assert_true (
240 content_hub_service_call_handler_active_sync (
241 service,
242 APPLICATION_ID,
243 NULL,
244 NULL));
245
246 set_paste (service);
247 get_paste (service);
248
249 g_assert_true (
250 content_hub_service_call_quit_sync (
251 service,
252 NULL,
253 NULL));
254
255 g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (handler));
256 g_object_unref (handler);
257 g_object_unref (service);
258
259 return 0;
260}
261
262/* modified from app_hub_communication_paste.cpp */
263
264TEST(GLib, glib_test)
265{
266 using namespace ::testing;
267
268 test::CrossProcessSync sync;
269
270 auto parent = [&sync]()
271 {
272 int argc = 0;
273 QCoreApplication app{argc, nullptr};
274
275 QDBusConnection connection = QDBusConnection::sessionBus();
276
277 auto mock = new ::testing::NiceMock<MockedPeerRegistry>{};
278
279 QSharedPointer<cucd::PeerRegistry> registry{mock};
280 auto app_manager = QSharedPointer<cua::ApplicationManager>(new MockedAppManager());
281 cucd::Service implementation(connection, registry, app_manager, &app);
282 new ServiceAdaptor(std::addressof(implementation));
283
284 ASSERT_TRUE(connection.registerService(service_name));
285 ASSERT_TRUE(connection.registerObject("/", std::addressof(implementation)));
286
287 sync.signal_ready();
288
289 app.exec();
290
291 connection.unregisterObject("/");
292 connection.unregisterService(service_name);
293 };
294
295 auto child = [&sync]()
296 {
297 int argc = 0;
298 QCoreApplication app(argc, nullptr);
299
300 sync.wait_for_signal_ready();
301
302 test::TestHarness harness;
303 harness.add_test_case([]()
304 {
305 char arg0[] = "glib_test";
306 char *argv[] = { arg0 };
307
308 EXPECT_EQ(0, glib_test(1, argv));
309 });
310 EXPECT_EQ(0, QTest::qExec(std::addressof(harness)));
311 };
312
313 EXPECT_EQ(EXIT_SUCCESS, test::fork_and_run(child, parent));
314}

Subscribers

People subscribed via source and target branches