Merge lp:~pete-woods/unity-api/add-signal-managers into lp:unity-api
- add-signal-managers
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Pete Woods |
Approved revision: | 299 |
Merged at revision: | 282 |
Proposed branch: | lp:~pete-woods/unity-api/add-signal-managers |
Merge into: | lp:unity-api |
Prerequisite: | lp:~pete-woods/unity-api/add-glib-assigner-class |
Diff against target: |
491 lines (+325/-0) 11 files modified
debian/control (+1/-0) include/unity/util/GObjectMemory.h (+33/-0) include/unity/util/GioMemory.h (+72/-0) include/unity/util/GlibMemory.h (+28/-0) include/unity/util/ResourcePtr.h (+10/-0) test/gtest/unity/util/CMakeLists.txt (+1/-0) test/gtest/unity/util/GObjectMemory/GObjectMemory_test.cpp (+34/-0) test/gtest/unity/util/GioMemory/CMakeLists.txt (+30/-0) test/gtest/unity/util/GioMemory/GioMemory_test.cpp (+114/-0) test/headers/CMakeLists.txt (+1/-0) test/headers/includechecker.py (+1/-0) |
To merge this branch: | bzr merge lp:~pete-woods/unity-api/add-signal-managers |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Unity8 CI Bot | continuous-integration | Needs Fixing | |
Michi Henning (community) | Approve | ||
Review via email: mp+320961@code.launchpad.net |
Commit message
unity::util - Add glib signal managers
Description of the change
unity::util - Add glib signal managers
Unity8 CI Bot (unity8-ci-bot) wrote : | # |
Unity8 CI Bot (unity8-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:295
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Michi Henning (michihenning) wrote : | # |
This looks sensible to me. I'd prefer if someone with more glib mojo than me could top-approve though.
- 294. By Pete Woods
-
Fix null assignment behaviour in assigner classes
- 295. By Pete Woods
-
Tweak docs
Unity8 CI Bot (unity8-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:297
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
- 296. By Pete Woods
-
Fix whitespace error
- 298. By Pete Woods
-
Fix up tests, use libqtdbustest for temporary test bus
- 299. By Pete Woods
-
Add docs
Unity8 CI Bot (unity8-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:298
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
Preview Diff
1 | === modified file 'debian/control' | |||
2 | --- debian/control 2016-12-23 09:14:43 +0000 | |||
3 | +++ debian/control 2017-04-04 09:34:42 +0000 | |||
4 | @@ -14,6 +14,7 @@ | |||
5 | 14 | graphviz, | 14 | graphviz, |
6 | 15 | libglib2.0-dev, | 15 | libglib2.0-dev, |
7 | 16 | libgtest-dev, | 16 | libgtest-dev, |
8 | 17 | libqtdbustest1-dev, | ||
9 | 17 | pkg-config, | 18 | pkg-config, |
10 | 18 | python3:any, | 19 | python3:any, |
11 | 19 | qt5-default, | 20 | qt5-default, |
12 | 20 | 21 | ||
13 | === modified file 'include/unity/util/GObjectMemory.h' | |||
14 | --- include/unity/util/GObjectMemory.h 2017-04-04 09:34:42 +0000 | |||
15 | +++ include/unity/util/GObjectMemory.h 2017-04-04 09:34:42 +0000 | |||
16 | @@ -24,6 +24,8 @@ | |||
17 | 24 | #include <stdexcept> | 24 | #include <stdexcept> |
18 | 25 | #include <glib-object.h> | 25 | #include <glib-object.h> |
19 | 26 | 26 | ||
20 | 27 | #include <unity/util/ResourcePtr.h> | ||
21 | 28 | |||
22 | 27 | namespace unity | 29 | namespace unity |
23 | 28 | { | 30 | { |
24 | 29 | 31 | ||
25 | @@ -109,6 +111,20 @@ | |||
26 | 109 | SP& smart_ptr_; | 111 | SP& smart_ptr_; |
27 | 110 | }; | 112 | }; |
28 | 111 | 113 | ||
29 | 114 | template <typename T> | ||
30 | 115 | struct GObjectSignalUnsubscriber | ||
31 | 116 | { | ||
32 | 117 | void operator()(gulong handle) noexcept | ||
33 | 118 | { | ||
34 | 119 | if (handle != 0 && G_IS_OBJECT(obj_.get())) | ||
35 | 120 | { | ||
36 | 121 | g_signal_handler_disconnect(obj_.get(), handle); | ||
37 | 122 | } | ||
38 | 123 | } | ||
39 | 124 | |||
40 | 125 | GObjectSPtr<T> obj_; | ||
41 | 126 | }; | ||
42 | 127 | |||
43 | 112 | } | 128 | } |
44 | 113 | 129 | ||
45 | 114 | /** | 130 | /** |
46 | @@ -187,6 +203,23 @@ | |||
47 | 187 | return internal::GObjectAssigner<SP>(smart_ptr); | 203 | return internal::GObjectAssigner<SP>(smart_ptr); |
48 | 188 | } | 204 | } |
49 | 189 | 205 | ||
50 | 206 | template<typename T> | ||
51 | 207 | using GObjectSignalConnection = ResourcePtr<gulong, internal::GObjectSignalUnsubscriber<T>>; | ||
52 | 208 | |||
53 | 209 | /** | ||
54 | 210 | \brief Simple wrapper to manage the lifecycle of GObject signal connections. | ||
55 | 211 | |||
56 | 212 | When 'nameConnection_' goes out of scope or is dealloc'ed, the source will be removed: | ||
57 | 213 | \code{.cpp} | ||
58 | 214 | GObjectSignalConnection<FooBar> nameConnection_; | ||
59 | 215 | nameConnection_ = gobject_signal_connection(g_signal_connect(o.get(), "notify::name", G_CALLBACK(on_notify_name), this), o); | ||
60 | 216 | \endcode | ||
61 | 217 | */ | ||
62 | 218 | template <typename T> | ||
63 | 219 | inline GObjectSignalConnection<T> gobject_signal_connection(gulong id, const GObjectSPtr<T>& obj) | ||
64 | 220 | { | ||
65 | 221 | return GObjectSignalConnection<T>(id, internal::GObjectSignalUnsubscriber<T>{obj}); | ||
66 | 222 | } | ||
67 | 190 | 223 | ||
68 | 191 | } // namespace until | 224 | } // namespace until |
69 | 192 | 225 | ||
70 | 193 | 226 | ||
71 | === added file 'include/unity/util/GioMemory.h' | |||
72 | --- include/unity/util/GioMemory.h 1970-01-01 00:00:00 +0000 | |||
73 | +++ include/unity/util/GioMemory.h 2017-04-04 09:34:42 +0000 | |||
74 | @@ -0,0 +1,72 @@ | |||
75 | 1 | /* | ||
76 | 2 | * Copyright (C) 2013-2017 Canonical Ltd. | ||
77 | 3 | * | ||
78 | 4 | * This program is free software: you can redistribute it and/or modify | ||
79 | 5 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
80 | 6 | * published by the Free Software Foundation. | ||
81 | 7 | * | ||
82 | 8 | * This program is distributed in the hope that it will be useful, | ||
83 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
84 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
85 | 11 | * GNU Lesser General Public License for more details. | ||
86 | 12 | * | ||
87 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
88 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
89 | 15 | * | ||
90 | 16 | * Authored by: Pete Woods <pete.woods@canonical.com> | ||
91 | 17 | */ | ||
92 | 18 | |||
93 | 19 | #ifndef UNITY_UTIL_GIOMEMORY_H | ||
94 | 20 | #define UNITY_UTIL_GIOMEMORY_H | ||
95 | 21 | |||
96 | 22 | #include <gio/gio.h> | ||
97 | 23 | |||
98 | 24 | #include <unity/util/GObjectMemory.h> | ||
99 | 25 | |||
100 | 26 | namespace unity | ||
101 | 27 | { | ||
102 | 28 | |||
103 | 29 | namespace util | ||
104 | 30 | { | ||
105 | 31 | |||
106 | 32 | namespace internal | ||
107 | 33 | { | ||
108 | 34 | struct GDBusSignalUnsubscriber | ||
109 | 35 | { | ||
110 | 36 | public: | ||
111 | 37 | void operator()(guint handle) noexcept | ||
112 | 38 | { | ||
113 | 39 | if (handle != 0 && G_IS_OBJECT(bus_.get())) | ||
114 | 40 | { | ||
115 | 41 | g_dbus_connection_signal_unsubscribe(bus_.get(), handle); | ||
116 | 42 | } | ||
117 | 43 | } | ||
118 | 44 | |||
119 | 45 | GObjectSPtr<GDBusConnection> bus_; | ||
120 | 46 | }; | ||
121 | 47 | |||
122 | 48 | } | ||
123 | 49 | |||
124 | 50 | typedef ResourcePtr<guint, internal::GDBusSignalUnsubscriber> GDBusSignalConnection; | ||
125 | 51 | |||
126 | 52 | /** | ||
127 | 53 | \brief Simple wrapper to manage the lifecycle of manual GDBus signal connections. | ||
128 | 54 | |||
129 | 55 | When 'signalConnection_' goes out of scope or is dealloc'ed, the connection will be removed: | ||
130 | 56 | \code{.cpp} | ||
131 | 57 | GDBusSignalConnection signalConnection_; | ||
132 | 58 | |||
133 | 59 | signalConnection_ = gdbus_signal_connection( | ||
134 | 60 | g_dbus_connection_signal_subscribe(bus.get(), nullptr, "org.does.not.exist", nullptr, "/does/not/exist", nullptr, G_DBUS_SIGNAL_FLAGS_NONE, on_dbus_signal, this, nullptr), bus); | ||
135 | 61 | \endcode | ||
136 | 62 | */ | ||
137 | 63 | inline GDBusSignalConnection gdbus_signal_connection(guint id, GObjectSPtr<GDBusConnection> bus) noexcept | ||
138 | 64 | { | ||
139 | 65 | return GDBusSignalConnection(id, internal::GDBusSignalUnsubscriber{bus}); | ||
140 | 66 | } | ||
141 | 67 | |||
142 | 68 | } // namespace until | ||
143 | 69 | |||
144 | 70 | } // namespace unity | ||
145 | 71 | |||
146 | 72 | #endif | ||
147 | 0 | 73 | ||
148 | === modified file 'include/unity/util/GlibMemory.h' | |||
149 | --- include/unity/util/GlibMemory.h 2017-04-04 09:34:42 +0000 | |||
150 | +++ include/unity/util/GlibMemory.h 2017-04-04 09:34:42 +0000 | |||
151 | @@ -24,6 +24,8 @@ | |||
152 | 24 | #include <memory> | 24 | #include <memory> |
153 | 25 | #include <glib.h> | 25 | #include <glib.h> |
154 | 26 | 26 | ||
155 | 27 | #include <unity/util/ResourcePtr.h> | ||
156 | 28 | |||
157 | 27 | namespace unity | 29 | namespace unity |
158 | 28 | { | 30 | { |
159 | 29 | 31 | ||
160 | @@ -83,6 +85,17 @@ | |||
161 | 83 | SP& smart_ptr_; | 85 | SP& smart_ptr_; |
162 | 84 | }; | 86 | }; |
163 | 85 | 87 | ||
164 | 88 | struct GSourceUnsubscriber | ||
165 | 89 | { | ||
166 | 90 | void operator()(guint tag) noexcept | ||
167 | 91 | { | ||
168 | 92 | if (tag != 0) | ||
169 | 93 | { | ||
170 | 94 | g_source_remove(tag); | ||
171 | 95 | } | ||
172 | 96 | } | ||
173 | 97 | }; | ||
174 | 98 | |||
175 | 86 | } | 99 | } |
176 | 87 | 100 | ||
177 | 88 | #define UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(TypeName, func) \ | 101 | #define UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(TypeName, func) \ |
178 | @@ -156,6 +169,21 @@ | |||
179 | 156 | return internal::GlibAssigner<SP>(smart_ptr); | 169 | return internal::GlibAssigner<SP>(smart_ptr); |
180 | 157 | } | 170 | } |
181 | 158 | 171 | ||
182 | 172 | using GSourceManager = ResourcePtr<guint, internal::GSourceUnsubscriber>; | ||
183 | 173 | |||
184 | 174 | /** | ||
185 | 175 | \brief Simple wrapper to manage the lifecycle of sources. | ||
186 | 176 | |||
187 | 177 | When 'timer' goes out of scope or is dealloc'ed, the source will be removed: | ||
188 | 178 | \code{.cpp} | ||
189 | 179 | auto timer = g_source_manager(g_timeout_add(5000, on_timeout, nullptr)); | ||
190 | 180 | \endcode | ||
191 | 181 | */ | ||
192 | 182 | inline GSourceManager g_source_manager(guint id) | ||
193 | 183 | { | ||
194 | 184 | return GSourceManager(id, internal::GSourceUnsubscriber()); | ||
195 | 185 | } | ||
196 | 186 | |||
197 | 159 | /** | 187 | /** |
198 | 160 | * Below here is some hackery to extract the matching deleters for all built in glib types. | 188 | * Below here is some hackery to extract the matching deleters for all built in glib types. |
199 | 161 | */ | 189 | */ |
200 | 162 | 190 | ||
201 | === modified file 'include/unity/util/ResourcePtr.h' | |||
202 | --- include/unity/util/ResourcePtr.h 2014-06-25 23:46:22 +0000 | |||
203 | +++ include/unity/util/ResourcePtr.h 2017-04-04 09:34:42 +0000 | |||
204 | @@ -20,6 +20,7 @@ | |||
205 | 20 | #define UNITY_UTIL_RESOURCEPTR_H | 20 | #define UNITY_UTIL_RESOURCEPTR_H |
206 | 21 | 21 | ||
207 | 22 | #include <mutex> | 22 | #include <mutex> |
208 | 23 | #include <type_traits> | ||
209 | 23 | 24 | ||
210 | 24 | namespace unity | 25 | namespace unity |
211 | 25 | { | 26 | { |
212 | @@ -135,6 +136,7 @@ | |||
213 | 135 | */ | 136 | */ |
214 | 136 | typedef D deleter_type; | 137 | typedef D deleter_type; |
215 | 137 | 138 | ||
216 | 139 | ResourcePtr(); | ||
217 | 138 | explicit ResourcePtr(D d); | 140 | explicit ResourcePtr(D d); |
218 | 139 | ResourcePtr(R r, D d); | 141 | ResourcePtr(R r, D d); |
219 | 140 | ResourcePtr(ResourcePtr&& r); | 142 | ResourcePtr(ResourcePtr&& r); |
220 | @@ -175,6 +177,14 @@ | |||
221 | 175 | typedef LockAdopter<decltype(m_)> AdoptLock; | 177 | typedef LockAdopter<decltype(m_)> AdoptLock; |
222 | 176 | }; | 178 | }; |
223 | 177 | 179 | ||
224 | 180 | template<typename R, typename D> | ||
225 | 181 | ResourcePtr<R, D>::ResourcePtr() | ||
226 | 182 | : initialized_(false) | ||
227 | 183 | { | ||
228 | 184 | static_assert(!std::is_pointer<deleter_type>::value, | ||
229 | 185 | "constructed with null function pointer deleter"); | ||
230 | 186 | } | ||
231 | 187 | |||
232 | 178 | /** | 188 | /** |
233 | 179 | Constructs a ResourcePtr with the specified deleter. No resource is held, so a call to has_resource() | 189 | Constructs a ResourcePtr with the specified deleter. No resource is held, so a call to has_resource() |
234 | 180 | after constructing a ResourcePtr this way returns <code>false</code>. | 190 | after constructing a ResourcePtr this way returns <code>false</code>. |
235 | 181 | 191 | ||
236 | === modified file 'test/gtest/unity/util/CMakeLists.txt' | |||
237 | --- test/gtest/unity/util/CMakeLists.txt 2017-01-19 13:52:32 +0000 | |||
238 | +++ test/gtest/unity/util/CMakeLists.txt 2017-04-04 09:34:42 +0000 | |||
239 | @@ -1,6 +1,7 @@ | |||
240 | 1 | add_subdirectory(Daemon) | 1 | add_subdirectory(Daemon) |
241 | 2 | add_subdirectory(DefinesPtrs) | 2 | add_subdirectory(DefinesPtrs) |
242 | 3 | add_subdirectory(FileIO) | 3 | add_subdirectory(FileIO) |
243 | 4 | add_subdirectory(GioMemory) | ||
244 | 4 | add_subdirectory(GlibMemory) | 5 | add_subdirectory(GlibMemory) |
245 | 5 | add_subdirectory(GObjectMemory) | 6 | add_subdirectory(GObjectMemory) |
246 | 6 | add_subdirectory(IniParser) | 7 | add_subdirectory(IniParser) |
247 | 7 | 8 | ||
248 | === modified file 'test/gtest/unity/util/GObjectMemory/GObjectMemory_test.cpp' | |||
249 | --- test/gtest/unity/util/GObjectMemory/GObjectMemory_test.cpp 2017-04-04 09:34:42 +0000 | |||
250 | +++ test/gtest/unity/util/GObjectMemory/GObjectMemory_test.cpp 2017-04-04 09:34:42 +0000 | |||
251 | @@ -54,6 +54,8 @@ | |||
252 | 54 | 54 | ||
253 | 55 | void foo_bar_assigner_null(FooBar** in); | 55 | void foo_bar_assigner_null(FooBar** in); |
254 | 56 | 56 | ||
255 | 57 | void foo_bar_set_name(FooBar* fooBar, const gchar* const name); | ||
256 | 58 | |||
257 | 57 | G_END_DECLS | 59 | G_END_DECLS |
258 | 58 | 60 | ||
259 | 59 | // private implementation | 61 | // private implementation |
260 | @@ -197,6 +199,11 @@ | |||
261 | 197 | } | 199 | } |
262 | 198 | } | 200 | } |
263 | 199 | 201 | ||
264 | 202 | void foo_bar_set_name(FooBar* fooBar, const gchar* const name) | ||
265 | 203 | { | ||
266 | 204 | g_object_set(fooBar, "name", name, nullptr); | ||
267 | 205 | } | ||
268 | 206 | |||
269 | 200 | // | 207 | // |
270 | 201 | // Test cases | 208 | // Test cases |
271 | 202 | // | 209 | // |
272 | @@ -213,6 +220,22 @@ | |||
273 | 213 | { | 220 | { |
274 | 214 | DELETED_OBJECTS.clear(); | 221 | DELETED_OBJECTS.clear(); |
275 | 215 | } | 222 | } |
276 | 223 | |||
277 | 224 | static void on_notify_name(GObject *object, GParamSpec *, gpointer user_data) | ||
278 | 225 | { | ||
279 | 226 | static_cast<GObjectMemoryTest*>(user_data)->onNotifyName(object); | ||
280 | 227 | } | ||
281 | 228 | |||
282 | 229 | void onNotifyName(GObject *object) | ||
283 | 230 | { | ||
284 | 231 | gcharUPtr name; | ||
285 | 232 | g_object_get(object, "name", assign_glib(name), nullptr); | ||
286 | 233 | nameChanges_.emplace_back(name.get()); | ||
287 | 234 | } | ||
288 | 235 | |||
289 | 236 | list<string> nameChanges_; | ||
290 | 237 | |||
291 | 238 | GObjectSignalConnection<FooBar> nameConnection_; | ||
292 | 216 | }; | 239 | }; |
293 | 217 | 240 | ||
294 | 218 | TEST_F(GObjectMemoryTest, trivial) | 241 | TEST_F(GObjectMemoryTest, trivial) |
295 | @@ -496,6 +519,17 @@ | |||
296 | 496 | EXPECT_EQ(list<Deleted>({{"hi", 6}, {"bye", 7}}), DELETED_OBJECTS); | 519 | EXPECT_EQ(list<Deleted>({{"hi", 6}, {"bye", 7}}), DELETED_OBJECTS); |
297 | 497 | } | 520 | } |
298 | 498 | 521 | ||
299 | 522 | TEST_F(GObjectMemoryTest, signals) | ||
300 | 523 | { | ||
301 | 524 | auto o(share_gobject(foo_bar_new_full("hi", 1))); | ||
302 | 525 | nameConnection_ = gobject_signal_connection(g_signal_connect(o.get(), "notify::name", G_CALLBACK(on_notify_name), this), o); | ||
303 | 526 | foo_bar_set_name(o.get(), "change1"); | ||
304 | 527 | nameConnection_.dealloc(); | ||
305 | 528 | foo_bar_set_name(o.get(), "change2"); | ||
306 | 529 | |||
307 | 530 | EXPECT_EQ(list<string>{"change1"}, nameChanges_); | ||
308 | 531 | } | ||
309 | 532 | |||
310 | 499 | typedef pair<const char*, guint> GObjectMemoryMakeSharedTestParam; | 533 | typedef pair<const char*, guint> GObjectMemoryMakeSharedTestParam; |
311 | 500 | 534 | ||
312 | 501 | class GObjectMemoryMakeHelperMethodsTest: public testing::TestWithParam<GObjectMemoryMakeSharedTestParam> | 535 | class GObjectMemoryMakeHelperMethodsTest: public testing::TestWithParam<GObjectMemoryMakeSharedTestParam> |
313 | 502 | 536 | ||
314 | === added directory 'test/gtest/unity/util/GioMemory' | |||
315 | === added file 'test/gtest/unity/util/GioMemory/CMakeLists.txt' | |||
316 | --- test/gtest/unity/util/GioMemory/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
317 | +++ test/gtest/unity/util/GioMemory/CMakeLists.txt 2017-04-04 09:34:42 +0000 | |||
318 | @@ -0,0 +1,30 @@ | |||
319 | 1 | pkg_check_modules(GIO REQUIRED gio-2.0) | ||
320 | 2 | pkg_check_modules(QDBUSTEST REQUIRED libqtdbustest-1) | ||
321 | 3 | |||
322 | 4 | find_package(Qt5Core REQUIRED) | ||
323 | 5 | find_package(Qt5DBus REQUIRED) | ||
324 | 6 | |||
325 | 7 | include_directories( | ||
326 | 8 | ${Qt5Core_INCLUDE_DIRS} | ||
327 | 9 | ${Qt5DBus_INCLUDE_DIRS} | ||
328 | 10 | ${GIO_INCLUDE_DIRS} | ||
329 | 11 | ${QDBUSTEST_INCLUDE_DIRS} | ||
330 | 12 | ) | ||
331 | 13 | |||
332 | 14 | add_definitions( | ||
333 | 15 | -DQT_NO_KEYWORDS=1 | ||
334 | 16 | ) | ||
335 | 17 | |||
336 | 18 | add_executable(GioMemory_test | ||
337 | 19 | GioMemory_test.cpp | ||
338 | 20 | ) | ||
339 | 21 | |||
340 | 22 | target_link_libraries(GioMemory_test | ||
341 | 23 | ${TESTLIBS} | ||
342 | 24 | ${GIO_LDFLAGS} | ||
343 | 25 | ${QDBUSTEST_LDFLAGS} | ||
344 | 26 | Qt5::Core | ||
345 | 27 | Qt5::DBus | ||
346 | 28 | ) | ||
347 | 29 | |||
348 | 30 | add_test(GioMemory_test GioMemory_test) | ||
349 | 0 | 31 | ||
350 | === added file 'test/gtest/unity/util/GioMemory/GioMemory_test.cpp' | |||
351 | --- test/gtest/unity/util/GioMemory/GioMemory_test.cpp 1970-01-01 00:00:00 +0000 | |||
352 | +++ test/gtest/unity/util/GioMemory/GioMemory_test.cpp 2017-04-04 09:34:42 +0000 | |||
353 | @@ -0,0 +1,114 @@ | |||
354 | 1 | /* | ||
355 | 2 | * Copyright (C) 2017 Canonical Ltd. | ||
356 | 3 | * | ||
357 | 4 | * This program is free software: you can redistribute it and/or modify | ||
358 | 5 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
359 | 6 | * published by the Free Software Foundation. | ||
360 | 7 | * | ||
361 | 8 | * This program is distributed in the hope that it will be useful, | ||
362 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
363 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
364 | 11 | * GNU Lesser General Public License for more details. | ||
365 | 12 | * | ||
366 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
367 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
368 | 15 | * | ||
369 | 16 | * Authored by: Pete Woods <pete.woods@canonical.com> | ||
370 | 17 | */ | ||
371 | 18 | |||
372 | 19 | #include <unity/util/GioMemory.h> | ||
373 | 20 | #include <unity/util/GlibMemory.h> | ||
374 | 21 | #include <libqtdbustest/DBusTestRunner.h> | ||
375 | 22 | #include <gtest/gtest.h> | ||
376 | 23 | #include <list> | ||
377 | 24 | #include <string> | ||
378 | 25 | |||
379 | 26 | using namespace std; | ||
380 | 27 | using namespace unity::util; | ||
381 | 28 | using namespace QtDBusTest; | ||
382 | 29 | |||
383 | 30 | namespace | ||
384 | 31 | { | ||
385 | 32 | |||
386 | 33 | class GioMemoryTest: public testing::Test | ||
387 | 34 | { | ||
388 | 35 | protected: | ||
389 | 36 | static void SetUpTestCase() | ||
390 | 37 | { | ||
391 | 38 | g_log_set_always_fatal((GLogLevelFlags) (G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL)); | ||
392 | 39 | } | ||
393 | 40 | |||
394 | 41 | static void on_dbus_signal(GDBusConnection *, const gchar *, const gchar *, const gchar *, const gchar *signal_name, GVariant *, gpointer user_data) | ||
395 | 42 | { | ||
396 | 43 | static_cast<GioMemoryTest*>(user_data)->onDbusSignal(signal_name); | ||
397 | 44 | } | ||
398 | 45 | |||
399 | 46 | void onDbusSignal(const gchar *signal_name) | ||
400 | 47 | { | ||
401 | 48 | signals_.emplace_back(signal_name); | ||
402 | 49 | g_main_loop_quit(mainloop_.get()); | ||
403 | 50 | } | ||
404 | 51 | |||
405 | 52 | static gboolean on_timeout(gpointer user_data) | ||
406 | 53 | { | ||
407 | 54 | return static_cast<GioMemoryTest*>(user_data)->onTimeout(); | ||
408 | 55 | } | ||
409 | 56 | |||
410 | 57 | gboolean onTimeout() | ||
411 | 58 | { | ||
412 | 59 | g_main_loop_quit(mainloop_.get()); | ||
413 | 60 | return G_SOURCE_CONTINUE; | ||
414 | 61 | } | ||
415 | 62 | |||
416 | 63 | static GObjectSPtr<GDBusConnection> getSessionBus() | ||
417 | 64 | { | ||
418 | 65 | auto address = unique_glib(g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SESSION, nullptr, nullptr)); | ||
419 | 66 | |||
420 | 67 | auto bus = unique_gobject( | ||
421 | 68 | g_dbus_connection_new_for_address_sync(address.get(), (GDBusConnectionFlags) (G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT | G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION), nullptr, | ||
422 | 69 | nullptr, nullptr)); | ||
423 | 70 | |||
424 | 71 | g_dbus_connection_set_exit_on_close(bus.get(), FALSE); | ||
425 | 72 | |||
426 | 73 | return bus; | ||
427 | 74 | } | ||
428 | 75 | |||
429 | 76 | DBusTestRunner dbusTestRunner; | ||
430 | 77 | |||
431 | 78 | GDBusSignalConnection signalConnection_; | ||
432 | 79 | |||
433 | 80 | GMainLoopSPtr mainloop_; | ||
434 | 81 | |||
435 | 82 | list<string> signals_; | ||
436 | 83 | }; | ||
437 | 84 | |||
438 | 85 | |||
439 | 86 | TEST_F(GioMemoryTest, signals) | ||
440 | 87 | { | ||
441 | 88 | mainloop_ = share_glib(g_main_loop_new(nullptr, false)); | ||
442 | 89 | |||
443 | 90 | auto bus = getSessionBus(); | ||
444 | 91 | ASSERT_TRUE(bool(bus)); | ||
445 | 92 | |||
446 | 93 | signalConnection_ = gdbus_signal_connection( | ||
447 | 94 | g_dbus_connection_signal_subscribe(bus.get(), nullptr, "org.does.not.exist", nullptr, "/does/not/exist", nullptr, G_DBUS_SIGNAL_FLAGS_NONE, on_dbus_signal, this, nullptr), bus); | ||
448 | 95 | |||
449 | 96 | g_dbus_connection_emit_signal(bus.get(), nullptr, "/does/not/exist", "org.does.not.exist", "hello", nullptr, nullptr); | ||
450 | 97 | { | ||
451 | 98 | auto timer = g_source_manager(g_timeout_add(5000, on_timeout, this)); | ||
452 | 99 | g_main_loop_run(mainloop_.get()); | ||
453 | 100 | EXPECT_EQ(list<string>{"hello"}, signals_); | ||
454 | 101 | } | ||
455 | 102 | signals_.clear(); | ||
456 | 103 | |||
457 | 104 | signalConnection_.dealloc(); | ||
458 | 105 | |||
459 | 106 | g_dbus_connection_emit_signal(bus.get(), nullptr, "/does/not/exist", "org.does.not.exist", "hello", nullptr, nullptr); | ||
460 | 107 | { | ||
461 | 108 | auto timer = g_source_manager(g_timeout_add(5000, on_timeout, this)); | ||
462 | 109 | g_main_loop_run(mainloop_.get()); | ||
463 | 110 | EXPECT_TRUE(signals_.empty()); | ||
464 | 111 | } | ||
465 | 112 | } | ||
466 | 113 | |||
467 | 114 | } | ||
468 | 0 | 115 | ||
469 | === modified file 'test/headers/CMakeLists.txt' | |||
470 | --- test/headers/CMakeLists.txt 2017-01-19 13:52:32 +0000 | |||
471 | +++ test/headers/CMakeLists.txt 2017-04-04 09:34:42 +0000 | |||
472 | @@ -11,6 +11,7 @@ | |||
473 | 11 | ) | 11 | ) |
474 | 12 | 12 | ||
475 | 13 | set(exclusions | 13 | set(exclusions |
476 | 14 | "GioMemory.h" | ||
477 | 14 | "GlibMemory.h" | 15 | "GlibMemory.h" |
478 | 15 | "GObjectMemory.h" | 16 | "GObjectMemory.h" |
479 | 16 | ) | 17 | ) |
480 | 17 | 18 | ||
481 | === modified file 'test/headers/includechecker.py' | |||
482 | --- test/headers/includechecker.py 2017-01-19 13:52:32 +0000 | |||
483 | +++ test/headers/includechecker.py 2017-04-04 09:34:42 +0000 | |||
484 | @@ -38,6 +38,7 @@ | |||
485 | 38 | 'unity/shell': { 'Qt' }, # Anything under unity/shell can include anything starting with Qt | 38 | 'unity/shell': { 'Qt' }, # Anything under unity/shell can include anything starting with Qt |
486 | 39 | 'unity/util/GObjectMemory': { 'glib' }, # The unity/util/GObjectMemory header can include anything starting with glib | 39 | 'unity/util/GObjectMemory': { 'glib' }, # The unity/util/GObjectMemory header can include anything starting with glib |
487 | 40 | 'unity/util/GlibMemory': { 'glib' }, # The unity/util/GlibMemory header can include anything starting with glib | 40 | 'unity/util/GlibMemory': { 'glib' }, # The unity/util/GlibMemory header can include anything starting with glib |
488 | 41 | 'unity/util/GioMemory': { 'glib' }, # The unity/util/GioMemory header can include anything starting with glib | ||
489 | 41 | } | 42 | } |
490 | 42 | 43 | ||
491 | 43 | def check_file(filename, permitted_includes): | 44 | def check_file(filename, permitted_includes): |
FAILED: Continuous integration, rev:294 /unity8- jenkins. ubuntu. com/job/ lp-unity- api-ci/ 164/ /unity8- jenkins. ubuntu. com/job/ build/4690/ console /unity8- jenkins. ubuntu. com/job/ build-0- fetch/4718 /unity8- jenkins. ubuntu. com/job/ build-2- binpkg/ arch=amd64, release= xenial+ overlay/ 4540/console /unity8- jenkins. ubuntu. com/job/ build-2- binpkg/ arch=amd64, release= zesty/4540/ console /unity8- jenkins. ubuntu. com/job/ build-2- binpkg/ arch=armhf, release= xenial+ overlay/ 4540/console /unity8- jenkins. ubuntu. com/job/ build-2- binpkg/ arch=armhf, release= zesty/4540/ console /unity8- jenkins. ubuntu. com/job/ build-2- binpkg/ arch=i386, release= xenial+ overlay/ 4540/console /unity8- jenkins. ubuntu. com/job/ build-2- binpkg/ arch=i386, release= zesty/4540/ console
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
Click here to trigger a rebuild: /unity8- jenkins. ubuntu. com/job/ lp-unity- api-ci/ 164/rebuild
https:/