Merge lp:~townsend/unity/fix-lp1243529 into lp:unity

Proposed by Christopher Townsend
Status: Merged
Approved by: Brandon Schaefer
Approved revision: no longer in the source branch.
Merged at revision: 3581
Proposed branch: lp:~townsend/unity/fix-lp1243529
Merge into: lp:unity
Diff against target: 218 lines (+60/-41)
3 files modified
CMakeLists.txt (+1/-1)
debian/control (+2/-2)
unity-shared/DebugDBusInterface.cpp (+57/-38)
To merge this branch: bzr merge lp:~townsend/unity/fix-lp1243529
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Brandon Schaefer (community) Approve
Review via email: mp+192381@code.launchpad.net

Commit message

Support libxpathselect1.4.

Description of the change

Support libxpathselect1.4. This comes from https://code.launchpad.net/~3v1n0/unity/xpathselect-1.4/+merge/186092 and is basically just rev. 3507 of his branch to make things simple for now.

To post a comment you must log in.
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

Cool, LGTM

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

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 2013-10-14 11:16:33 +0000
3+++ CMakeLists.txt 2013-10-23 17:56:46 +0000
4@@ -233,7 +233,7 @@
5 nux-4.0>=4.0.1
6 sigc++-2.0
7 unity-misc>=0.4.0
8- xpathselect>=1.2
9+ xpathselect=1.4
10 zeitgeist-2.0
11 )
12
13
14=== modified file 'debian/control'
15--- debian/control 2013-09-27 12:26:20 +0000
16+++ debian/control 2013-10-23 17:56:46 +0000
17@@ -48,7 +48,7 @@
18 libxcb-icccm4-dev,
19 libxfixes-dev (>= 1:5.0.1-1),
20 libxi-dev (>= 2:1.7.1.901),
21- libxpathselect-dev (>=1.3),
22+ libxpathselect-dev (>=1.4),
23 libzeitgeist-2.0-dev,
24 pkg-config,
25 python (>= 2.7),
26@@ -178,7 +178,7 @@
27 python-testtools,
28 python-xdg,
29 python-xlib,
30- libxpathselect1.3 (>= 1.3),
31+ libxpathselect1.4 (>= 1.4),
32 Description: Autopiloted tests for Unity
33 We test Unity automatically through autopilot, a framework which enables us
34 to trigger keyboard and mouse events on the fly as well as introspecting
35
36=== modified file 'unity-shared/DebugDBusInterface.cpp'
37--- unity-shared/DebugDBusInterface.cpp 2013-05-14 02:25:47 +0000
38+++ unity-shared/DebugDBusInterface.cpp 2013-10-23 17:56:46 +0000
39@@ -17,18 +17,11 @@
40 * Authored by: Alex Launi <alex.launi@canonical.com>
41 */
42
43-#include <queue>
44-#include <iostream>
45 #include <fstream>
46 #include <sstream>
47-#include <iostream>
48 #include <boost/algorithm/string.hpp>
49-#include <boost/algorithm/string/split.hpp>
50-#include <boost/algorithm/string/classification.hpp>
51-#include <boost/bind.hpp>
52 #include <NuxCore/Logger.h>
53 #include <NuxCore/LoggingWriter.h>
54-#include <xpathselect/node.h>
55 #include <xpathselect/xpathselect.h>
56 #include <dlfcn.h>
57
58@@ -46,16 +39,21 @@
59 namespace local
60 {
61 std::ofstream output_file;
62- void* xpathselect_driver_ = NULL;
63+ void* xpathselect_driver_ = nullptr;
64
65- class IntrospectableAdapter: public xpathselect::Node
66+ class IntrospectableAdapter : public std::enable_shared_from_this<IntrospectableAdapter>, public xpathselect::Node
67 {
68 public:
69 typedef std::shared_ptr<IntrospectableAdapter> Ptr;
70- IntrospectableAdapter(Introspectable* node, std::string const& parent_path)
71- : node_(node)
72+ IntrospectableAdapter(Introspectable* node, IntrospectableAdapter::Ptr const& parent = nullptr)
73+ : node_(node)
74+ , parent_(parent)
75+ , full_path_((parent_ ? parent_->GetPath() : "") + "/" + GetName())
76+ {}
77+
78+ int32_t GetId() const
79 {
80- full_path_ = parent_path + "/" + GetName();
81+ return GPOINTER_TO_INT(node_);
82 }
83
84 std::string GetName() const
85@@ -68,6 +66,27 @@
86 return full_path_;
87 }
88
89+ Node::Ptr GetParent() const
90+ {
91+ return parent_;
92+ }
93+
94+ virtual bool MatchBooleanProperty(const std::string& name, bool value) const
95+ {
96+ return false;
97+ }
98+
99+ virtual bool MatchIntegerProperty(const std::string& name, int32_t value) const
100+ {
101+ return false;
102+ }
103+
104+ virtual bool MatchStringProperty(const std::string& name, const std::string& value) const
105+ {
106+ return false;
107+ }
108+
109+
110 bool MatchProperty(const std::string& name, const std::string& value) const
111 {
112 bool matches = false;
113@@ -77,7 +96,7 @@
114 g_variant_builder_add(&child_builder, "{sv}", "id", g_variant_new_uint64(node_->GetIntrospectionId()));
115 node_->AddProperties(&child_builder);
116 GVariant* prop_dict = g_variant_builder_end(&child_builder);
117- GVariant *prop_value = g_variant_lookup_value(prop_dict, name.c_str(), NULL);
118+ GVariant* prop_value = g_variant_lookup_value(prop_dict, name.c_str(), NULL);
119
120 if (prop_value != NULL)
121 {
122@@ -100,10 +119,7 @@
123 case G_VARIANT_CLASS_BOOLEAN:
124 {
125 std::string value = boost::to_upper_copy(value);
126- bool p = value == "TRUE" ||
127- value == "ON" ||
128- value == "YES" ||
129- value == "1";
130+ bool p = value == "TRUE" || value == "ON" || value == "YES" || value == "1";
131 matches = (g_variant_get_boolean(prop_value) == p);
132 }
133 break;
134@@ -183,30 +199,34 @@
135 std::vector<xpathselect::Node::Ptr> Children() const
136 {
137 std::vector<xpathselect::Node::Ptr> children;
138- for(auto child: node_->GetIntrospectableChildren())
139- {
140- children.push_back(std::make_shared<IntrospectableAdapter>(child, GetPath() ));
141- }
142+ auto const& this_ptr = std::const_pointer_cast<IntrospectableAdapter>(shared_from_this());
143+ for(auto const& child: node_->GetIntrospectableChildren())
144+ children.push_back(std::make_shared<IntrospectableAdapter>(child, this_ptr));
145+
146 return children;
147-
148- }
149-
150+ }
151+
152+ Introspectable* Node() const
153+ {
154+ return node_;
155+ }
156+
157+ private:
158 Introspectable* node_;
159- private:
160+ IntrospectableAdapter::Ptr parent_;
161 std::string full_path_;
162 };
163
164- xpathselect::NodeList select_nodes(local::IntrospectableAdapter::Ptr root,
165- std::string const& query)
166+ xpathselect::NodeVector select_nodes(IntrospectableAdapter::Ptr const& root, std::string const& query)
167 {
168- if (xpathselect_driver_ == NULL)
169- xpathselect_driver_ = dlopen("libxpathselect.so.1.3", RTLD_LAZY);
170+ if (!xpathselect_driver_)
171+ xpathselect_driver_ = dlopen("libxpathselect.so.1.4", RTLD_LAZY);
172
173 if (xpathselect_driver_)
174 {
175- typedef decltype(&xpathselect::SelectNodes) entry_t;
176+ typedef decltype(&xpathselect::SelectNodes) select_nodes_t;
177 dlerror();
178- entry_t entry_point = (entry_t) dlsym(xpathselect_driver_, "SelectNodes");
179+ auto SelectNodes = reinterpret_cast<select_nodes_t>(dlsym(xpathselect_driver_, "SelectNodes"));
180 const char* err = dlerror();
181 if (err)
182 {
183@@ -214,7 +234,7 @@
184 }
185 else
186 {
187- return entry_point(root, query);
188+ return SelectNodes(root, query);
189 }
190 }
191 else
192@@ -223,7 +243,7 @@
193 }
194
195 // Fallen through here as we've hit an error
196- return xpathselect::NodeList();
197+ return xpathselect::NodeVector();
198 }
199
200 // This needs to be called at destruction to cleanup the dlopen
201@@ -355,13 +375,12 @@
202 GVariantBuilder builder;
203 g_variant_builder_init(&builder, G_VARIANT_TYPE("a(sv)"));
204
205- local::IntrospectableAdapter::Ptr root_node = std::make_shared<local::IntrospectableAdapter>(_parent_introspectable, std::string());
206- auto nodes = local::select_nodes(root_node, query);
207- for (auto n : nodes)
208+ auto root_node = std::make_shared<local::IntrospectableAdapter>(_parent_introspectable);
209+ for (auto const& n : local::select_nodes(root_node, query))
210 {
211- auto p = std::static_pointer_cast<local::IntrospectableAdapter>(n);
212+ auto p = std::static_pointer_cast<local::IntrospectableAdapter const>(n);
213 if (p)
214- g_variant_builder_add(&builder, "(sv)", p->GetPath().c_str(), p->node_->Introspect());
215+ g_variant_builder_add(&builder, "(sv)", p->GetPath().c_str(), p->Node()->Introspect());
216 }
217
218 return g_variant_new("(a(sv))", &builder);