Merge lp:~pete-woods/unity-api/glibmemory-typedefs into lp:unity-api

Proposed by Pete Woods
Status: Merged
Approved by: Charles Kerr
Approved revision: 272
Merged at revision: 272
Proposed branch: lp:~pete-woods/unity-api/glibmemory-typedefs
Merge into: lp:unity-api
Diff against target: 123 lines (+49/-10)
3 files modified
debian/changelog (+7/-0)
include/unity/util/GlibMemory.h (+6/-4)
test/gtest/unity/util/GlibMemory/GlibMemory_test.cpp (+36/-6)
To merge this branch: bzr merge lp:~pete-woods/unity-api/glibmemory-typedefs
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
Xavi Garcia (community) Approve
Unity8 CI Bot continuous-integration Approve
Review via email: mp+317621@code.launchpad.net

Commit message

unity::util - Add typedef macros to GlibMemory to make method and member variable definitions easier.

Description of the change

unity::util - Add typedef macros to GlibMemory to make method and member variable definitions easier.

To post a comment you must log in.
Revision history for this message
Unity8 CI Bot (unity8-ci-bot) wrote :

PASSED: Continuous integration, rev:272
https://unity8-jenkins.ubuntu.com/job/lp-unity-api-ci/139/
Executed test runs:
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build/4132
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-0-fetch/4160
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/4000
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/4000/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/4000
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/4000/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/4000
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/4000/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/4000
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/4000/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/4000
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/4000/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/4000
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/4000/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://unity8-jenkins.ubuntu.com/job/lp-unity-api-ci/139/rebuild

review: Approve (continuous-integration)
Revision history for this message
Xavi Garcia (xavi-garcia-mena) wrote :

LGTM

review: Approve
Revision history for this message
Charles Kerr (charlesk) wrote :

nice

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2017-02-06 09:11:04 +0000
3+++ debian/changelog 2017-02-17 13:43:11 +0000
4@@ -1,3 +1,10 @@
5+unity-api (8.3-0ubuntu1) UNRELEASED; urgency=medium
6+
7+ * unity::util - Add typedef macros to GlibMemory to make method
8+ and member variable definitions easier.
9+
10+ -- Pete <pete.woods@canonical.com> Fri, 17 Feb 2017 13:27:28 +0000
11+
12 unity-api (8.2+17.04.20170206-0ubuntu1) zesty; urgency=medium
13
14 [ Daniel d'Andrada ]
15
16=== modified file 'include/unity/util/GlibMemory.h'
17--- include/unity/util/GlibMemory.h 2017-01-19 13:52:32 +0000
18+++ include/unity/util/GlibMemory.h 2017-02-17 13:43:11 +0000
19@@ -31,13 +31,15 @@
20 #pragma push_macro("G_DEFINE_AUTOPTR_CLEANUP_FUNC")
21 #undef G_DEFINE_AUTOPTR_CLEANUP_FUNC
22 #define G_DEFINE_AUTOPTR_CLEANUP_FUNC(TypeName, func) \
23-inline std::shared_ptr<TypeName> share_glib(TypeName* ptr) \
24+typedef std::shared_ptr<TypeName> TypeName##SPtr; \
25+inline TypeName##SPtr share_glib(TypeName* ptr) \
26 { \
27- return std::shared_ptr<TypeName>(ptr, &func); \
28+ return TypeName##SPtr(ptr, &func); \
29 } \
30-inline std::unique_ptr<TypeName, decltype(&func)> unique_glib(TypeName* ptr) \
31+typedef std::unique_ptr<TypeName, decltype(&func)> TypeName##UPtr; \
32+inline TypeName##UPtr unique_glib(TypeName* ptr) \
33 { \
34- return std::unique_ptr<TypeName, decltype(&func)>(ptr, &func); \
35+ return TypeName##UPtr(ptr, &func); \
36 }
37
38 #pragma push_macro("G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC")
39
40=== modified file 'test/gtest/unity/util/GlibMemory/GlibMemory_test.cpp'
41--- test/gtest/unity/util/GlibMemory/GlibMemory_test.cpp 2017-01-19 13:52:32 +0000
42+++ test/gtest/unity/util/GlibMemory/GlibMemory_test.cpp 2017-02-17 13:43:11 +0000
43@@ -54,24 +54,54 @@
44 // Note that we don't g_free the data, because it's a reference to a static string
45 values.emplace(string((gchar*) data));
46 }
47+
48+ static GKeyFileUPtr newGKeyFile()
49+ {
50+ return unique_glib(g_key_file_new());
51+ }
52+
53+ static GVariantUPtr newGVariant(const gchar* const value)
54+ {
55+ return unique_glib(g_variant_new_string(value));
56+ }
57+
58+ static GHashTableUPtr newGHashTable()
59+ {
60+ return unique_glib(g_hash_table_new_full(g_str_hash, g_str_equal, deleteKey, deleteValue));
61+ }
62+
63+ static GKeyFileSPtr sharedGKeyFile()
64+ {
65+ return share_glib(g_key_file_new());
66+ }
67+
68+ static GVariantSPtr sharedGVariant(const gchar* const value)
69+ {
70+ return share_glib(g_variant_new_string(value));
71+ }
72+
73+ static GHashTableSPtr sharedGHashTable()
74+ {
75+ return share_glib(g_hash_table_new_full(g_str_hash, g_str_equal, deleteKey, deleteValue));
76+ }
77 };
78
79 TEST_F(GlibMemoryTest, Unique)
80 {
81 {
82- auto gkf = unique_glib(g_key_file_new());
83+ auto gkf = newGKeyFile();
84 g_key_file_set_boolean(gkf.get(), "group", "key", TRUE);
85 EXPECT_EQ(TRUE, g_key_file_get_boolean(gkf.get(), "group", "key", NULL));
86 }
87
88 {
89- auto variant = unique_glib(g_variant_new_string("hello"));
90+ auto variant = newGVariant("hello");
91 EXPECT_STREQ("hello", g_variant_get_string(variant.get(), NULL));
92 }
93
94 {
95 {
96- auto hash = unique_glib(g_hash_table_new_full(g_str_hash, g_str_equal, deleteKey, deleteValue));
97+ auto hash = newGHashTable();
98 g_hash_table_insert(hash.get(), (gpointer) "hello", (gpointer) "there");
99 g_hash_table_insert(hash.get(), (gpointer) "hash", (gpointer) "world");
100 }
101@@ -83,19 +113,19 @@
102 TEST_F(GlibMemoryTest, Share)
103 {
104 {
105- auto gkf = share_glib(g_key_file_new());
106+ auto gkf = sharedGKeyFile();
107 g_key_file_set_boolean(gkf.get(), "group", "key", TRUE);
108 EXPECT_EQ(TRUE, g_key_file_get_boolean(gkf.get(), "group", "key", NULL));
109 }
110
111 {
112- auto variant = share_glib(g_variant_new_string("hello"));
113+ auto variant = sharedGVariant("hello");
114 EXPECT_STREQ("hello", g_variant_get_string(variant.get(), NULL));
115 }
116
117 {
118 {
119- auto hash = share_glib(g_hash_table_new_full(g_str_hash, g_str_equal, deleteKey, deleteValue));
120+ auto hash = sharedGHashTable();
121 g_hash_table_insert(hash.get(), (gpointer) "hello", (gpointer) "there");
122 g_hash_table_insert(hash.get(), (gpointer) "hash", (gpointer) "world");
123 }

Subscribers

People subscribed via source and target branches

to all changes: