Merge lp:~thomas-voss/dbus-cpp/switch_to_uint8_for_handling_byte_types into lp:dbus-cpp

Proposed by Thomas Voß
Status: Superseded
Proposed branch: lp:~thomas-voss/dbus-cpp/switch_to_uint8_for_handling_byte_types
Merge into: lp:dbus-cpp
Diff against target: 772 lines (+308/-91)
15 files modified
examples/ofono/main.cpp (+2/-2)
examples/upower/main.cpp (+2/-2)
include/core/dbus/codec.h (+0/-24)
include/core/dbus/helper/type_mapper.h (+9/-5)
include/core/dbus/impl/object.h (+11/-10)
include/core/dbus/impl/property.h (+9/-10)
include/core/dbus/interfaces/properties.h (+1/-1)
include/core/dbus/object.h (+3/-4)
include/core/dbus/property.h (+1/-1)
include/core/dbus/types/stl/map.h (+20/-4)
include/core/dbus/types/variant.h (+195/-13)
src/core/dbus/message.cpp (+1/-1)
src/core/dbus/message_p.h (+1/-0)
tests/codec_test.cpp (+48/-11)
tests/stl_codec_test.cpp (+5/-3)
To merge this branch: bzr merge lp:~thomas-voss/dbus-cpp/switch_to_uint8_for_handling_byte_types
Reviewer Review Type Date Requested Status
Ubuntu Phablet Team Pending
Review via email: mp+202384@code.launchpad.net

This proposal has been superseded by a proposal from 2014-01-20.

Commit message

Switch type for ArgumentType::byte to std::uint8_t as per DBus spec.

Description of the change

Switch type for ArgumentType::byte to std::uint8_t as per DBus spec.

To post a comment you must log in.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'examples/ofono/main.cpp'
2--- examples/ofono/main.cpp 2014-01-05 18:58:19 +0000
3+++ examples/ofono/main.cpp 2014-01-20 22:13:41 +0000
4@@ -55,7 +55,7 @@
5 return "IncomingMessage";
6 };
7 typedef MessageManager Interface;
8- typedef std::tuple<std::string, std::map<std::string, dbus::types::Variant<dbus::types::Any>>> ArgumentType;
9+ typedef std::tuple<std::string, std::map<std::string, dbus::types::Variant>> ArgumentType;
10 };
11 };
12 };
13@@ -70,7 +70,7 @@
14 return "CallAdded";
15 };
16 typedef VoiceCallManager Interface;
17- typedef std::tuple<dbus::types::ObjectPath, std::map<std::string, dbus::types::Variant<dbus::types::Any>>> ArgumentType;
18+ typedef std::tuple<dbus::types::ObjectPath, std::map<std::string, dbus::types::Variant>> ArgumentType;
19 };
20 };
21 };
22
23=== modified file 'examples/upower/main.cpp'
24--- examples/upower/main.cpp 2013-11-27 18:57:42 +0000
25+++ examples/upower/main.cpp 2014-01-20 22:13:41 +0000
26@@ -58,7 +58,7 @@
27 auto upower_object = upower->object_for_path(dbus::types::ObjectPath("/core/UPower"));
28
29 auto all_properties = upower_object->get_all_properties<core::UPower>();
30- std::for_each(all_properties.begin(), all_properties.end(), [](const std::pair<const std::string, dbus::types::Variant<dbus::types::Any>>& pair)
31+ std::for_each(all_properties.begin(), all_properties.end(), [](const std::pair<const std::string, dbus::types::Variant>& pair)
32 {
33 std::cout << pair.first << std::endl;
34 });
35@@ -181,7 +181,7 @@
36 std::cout << "\tRecallUrl: " << device->get_property<core::UPower::Device::Properties::RecallUrl>()->get() << std::endl;
37 std::cout << "-----------------------------------------------------------------------------------" << std::endl;
38 auto properties = device->get_all_properties<core::UPower::Device>();
39- std::for_each(properties.begin(), properties.end(), [](const std::pair<const std::string, dbus::types::Variant<dbus::types::Any>>& pair)
40+ std::for_each(properties.begin(), properties.end(), [](const std::pair<const std::string, dbus::types::Variant>& pair)
41 {
42 std::cout << "\t" << pair.first << std::endl;
43 });
44
45=== modified file 'include/core/dbus/codec.h'
46--- include/core/dbus/codec.h 2014-01-05 18:58:19 +0000
47+++ include/core/dbus/codec.h 2014-01-20 22:13:41 +0000
48@@ -292,30 +292,6 @@
49 };
50
51 /**
52- * @brief Template specialization for variant argument types.
53- */
54-template<typename T>
55-struct Codec<types::Variant<T>>
56-{
57- inline static void encode_argument(Message::Writer& out, const types::Variant<T>& value)
58- {
59- auto vw = out.open_variant(
60- types::Signature(helper::TypeMapper<T>::signature()));
61- {
62- Codec<T>::encode_argument(vw, value.get());
63- }
64- out.close_variant(std::move(vw));
65- }
66-
67- inline static void decode_argument(Message::Reader& in, types::Variant<T>& value)
68- {
69- auto vr = in.pop_variant(); T inner_value;
70- Codec<T>::decode_argument(vr, inner_value);
71- value.set(inner_value);
72- }
73-};
74-
75-/**
76 * @brief Template specialization for any argument types.
77 */
78 template<>
79
80=== modified file 'include/core/dbus/helper/type_mapper.h'
81--- include/core/dbus/helper/type_mapper.h 2013-11-27 18:57:42 +0000
82+++ include/core/dbus/helper/type_mapper.h 2014-01-20 22:13:41 +0000
83@@ -20,10 +20,10 @@
84
85 #include <core/dbus/argument_type.h>
86
87+#include <core/dbus/types/any.h>
88 #include <core/dbus/types/object_path.h>
89 #include <core/dbus/types/signature.h>
90 #include <core/dbus/types/unix_fd.h>
91-#include <core/dbus/types/variant.h>
92
93 #include <cstdint>
94
95@@ -37,6 +37,10 @@
96 {
97 namespace dbus
98 {
99+namespace types
100+{
101+class Variant;
102+}
103 namespace helper
104 {
105
106@@ -54,7 +58,7 @@
107 template<>
108 struct DBusTypeMapper<ArgumentType::byte>
109 {
110- typedef int8_t Type;
111+ typedef uint8_t Type;
112 };
113
114 template<>
115@@ -395,8 +399,8 @@
116 }
117 };
118
119-template<typename T>
120-struct TypeMapper<types::Variant<T>>
121+template<>
122+struct TypeMapper<types::Variant>
123 {
124 constexpr inline static ArgumentType type_value()
125 {
126@@ -413,7 +417,7 @@
127
128 inline static std::string signature()
129 {
130- return DBUS_TYPE_VARIANT_AS_STRING + TypeMapper<T>::signature();
131+ return DBUS_TYPE_VARIANT_AS_STRING;
132 }
133 };
134 }
135
136=== modified file 'include/core/dbus/impl/object.h'
137--- include/core/dbus/impl/object.h 2014-01-14 13:01:38 +0000
138+++ include/core/dbus/impl/object.h 2014-01-20 22:13:41 +0000
139@@ -80,8 +80,7 @@
140 msg,
141 Method::default_timeout());
142
143- Result<ResultType> result = Result<ResultType>::from_message(reply);
144- return result;
145+ return std::move(Result<ResultType>::from_message(reply));
146 }
147
148 template<typename Method, typename ResultType, typename... Args>
149@@ -175,13 +174,15 @@
150 }
151
152 template<typename Interface>
153-inline std::map<std::string, types::Variant<types::Any>>
154+inline std::map<std::string, types::Variant>
155 Object::get_all_properties()
156 {
157- return invoke_method_synchronously<
158- interfaces::Properties::GetAll,
159- std::map<std::string, types::Variant<types::Any>>
160- >(traits::Service<Interface>::interface_name()).value();
161+ return
162+ std::move(
163+ invoke_method_synchronously<
164+ interfaces::Properties::GetAll,
165+ std::map<std::string, types::Variant>
166+ >(traits::Service<Interface>::interface_name()).value());
167 }
168
169 template<typename SignalDescription>
170@@ -311,10 +312,10 @@
171 inline void Object::on_properties_changed(
172 const interfaces::Properties::Signals::PropertiesChanged::ArgumentType& arg)
173 {
174- auto interface = std::get<0>(arg);
175- auto changed_values = std::get<1>(arg);
176+ const auto& interface = std::get<0>(arg);
177+ const auto& changed_values = std::get<1>(arg);
178
179- for (auto value : changed_values)
180+ for (const auto& value : changed_values)
181 {
182 auto it = property_changed_vtable.find(std::make_tuple(interface, value.first));
183 if (it != property_changed_vtable.end())
184
185=== modified file 'include/core/dbus/impl/property.h'
186--- include/core/dbus/impl/property.h 2014-01-13 07:50:41 +0000
187+++ include/core/dbus/impl/property.h 2014-01-20 22:13:41 +0000
188@@ -29,8 +29,8 @@
189 if (parent->is_stub())
190 {
191 Super::mutable_get() = parent->invoke_method_synchronously<
192- interfaces::Properties::Get,
193- types::Variant<typename PropertyType::ValueType>
194+ interfaces::Properties::Get,
195+ types::TypedVariant<typename Property<PropertyType>::ValueType>
196 >(interface, name).value().get();
197 }
198 return Super::get();
199@@ -48,9 +48,9 @@
200 }
201
202 parent->invoke_method_synchronously<
203- interfaces::Properties::Set,
204- void
205- >(interface, name, types::Variant<ValueType>(new_value));
206+ interfaces::Properties::Set,
207+ void
208+ >(interface, name, types::TypedVariant<ValueType>(new_value));
209 }
210
211 Super::set(new_value);
212@@ -113,7 +113,7 @@
213 Property<PropertyType>::handle_get(const Message::Ptr& msg)
214 {
215 auto reply = Message::make_method_return(msg);
216- reply->writer() << types::Variant<ValueType>(Super::get());
217+ reply->writer() << types::TypedVariant<ValueType>(Super::get());
218
219 parent->parent->get_connection()->send(reply);
220 }
221@@ -133,7 +133,7 @@
222 return;
223 }
224
225- std::string s; types::Variant<ValueType> value;
226+ std::string s; types::TypedVariant<ValueType> value;
227 try
228 {
229 msg->reader() >> s >> s >> value;
230@@ -156,12 +156,11 @@
231
232 template<typename PropertyType>
233 void
234-Property<PropertyType>::handle_changed(const types::Variant<types::Any>& arg)
235+Property<PropertyType>::handle_changed(const types::Variant& arg)
236 {
237 try
238 {
239- typename PropertyType::ValueType value;
240- arg.get().reader() >> value;
241+ auto value = arg.as<typename PropertyType::ValueType>();
242 set(value);
243 }
244 catch (...)
245
246=== modified file 'include/core/dbus/interfaces/properties.h'
247--- include/core/dbus/interfaces/properties.h 2013-11-27 18:57:42 +0000
248+++ include/core/dbus/interfaces/properties.h 2014-01-20 22:13:41 +0000
249@@ -89,7 +89,7 @@
250 typedef Properties Interface;
251 typedef std::tuple<
252 std::string,
253- std::map<std::string, core::dbus::types::Variant<>>,
254+ std::map<std::string, core::dbus::types::Variant>,
255 std::vector<std::string>
256 > ArgumentType;
257 };
258
259=== modified file 'include/core/dbus/object.h'
260--- include/core/dbus/object.h 2014-01-14 13:01:38 +0000
261+++ include/core/dbus/object.h 2014-01-20 22:13:41 +0000
262@@ -66,7 +66,6 @@
263 {
264 class Any;
265 class ObjectPath;
266-template<typename T>
267 class Variant;
268 }
269 class MatchRule;
270@@ -131,8 +130,8 @@
271 * @brief Queries all properties in one go for the object.
272 */
273 template<typename Interface>
274- std::map<std::string, types::Variant<types::Any>>
275- inline get_all_properties();
276+ inline std::map<std::string, types::Variant>
277+ get_all_properties();
278
279 /**
280 * @brief Accesses a signal of the object.
281@@ -203,7 +202,7 @@
282 MessageRouter<PropertyKey> set_property_router;
283 std::map<
284 std::tuple<std::string, std::string>,
285- std::function<void(const types::Variant<types::Any>&)>
286+ std::function<void(const types::Variant&)>
287 > property_changed_vtable;
288 std::shared_ptr<
289 Signal<
290
291=== modified file 'include/core/dbus/property.h'
292--- include/core/dbus/property.h 2014-01-05 18:58:19 +0000
293+++ include/core/dbus/property.h 2014-01-20 22:13:41 +0000
294@@ -76,7 +76,7 @@
295
296 inline void handle_get(const Message::Ptr& msg);
297 inline void handle_set(const Message::Ptr& msg);
298- inline void handle_changed(const types::Variant<types::Any>& msg);
299+ inline void handle_changed(const types::Variant& msg);
300
301 std::shared_ptr<Object> parent;
302 std::string interface;
303
304=== modified file 'include/core/dbus/types/stl/map.h'
305--- include/core/dbus/types/stl/map.h 2014-01-13 12:02:23 +0000
306+++ include/core/dbus/types/stl/map.h 2014-01-20 22:13:41 +0000
307@@ -76,9 +76,25 @@
308 };
309 }
310 template<typename T, typename U>
311+struct Codec<std::pair<const T, U>>
312+{
313+ static void encode_argument(Message::Writer& out, const std::pair<const T, U>& arg)
314+ {
315+ Codec<typename std::decay<T>::type>::encode_argument(out, arg.first);
316+ Codec<typename std::decay<U>::type>::encode_argument(out, arg.second);
317+ }
318+
319+ static void decode_argument(Message::Reader& in, std::pair<T, U>& arg)
320+ {
321+ Codec<T>::decode_argument(in, arg.first);
322+ Codec<U>::decode_argument(in, arg.second);
323+ }
324+};
325+
326+template<typename T, typename U>
327 struct Codec<std::pair<T, U>>
328 {
329- static void encode_argument(Message::Writer& out, const std::pair<T, U>& arg)
330+ static void encode_argument(Message::Writer& out, const std::pair<const T, U>& arg)
331 {
332 Codec<typename std::decay<T>::type>::encode_argument(out, arg.first);
333 Codec<typename std::decay<U>::type>::encode_argument(out, arg.second);
334@@ -100,7 +116,7 @@
335 types::Signature(
336 helper::TypeMapper<typename std::map<T, U>::value_type>::signature()));
337 {
338- for (auto element : arg)
339+ for (const auto& element : arg)
340 {
341 auto de = aw.open_dict_entry();
342 {
343@@ -128,12 +144,12 @@
344 if (it == out.end())
345 {
346 bool inserted = false;
347- std::tie(std::ignore, inserted) = out.insert(v);
348+ std::tie(std::ignore, inserted) = out.insert(std::move(v));
349 if (!inserted)
350 throw std::runtime_error("Could not insert decoded element into map");
351 } else
352 {
353- it->second = v.second;
354+ it->second = std::move(v.second);
355 }
356 }
357 }
358
359=== modified file 'include/core/dbus/types/variant.h'
360--- include/core/dbus/types/variant.h 2013-11-27 18:57:42 +0000
361+++ include/core/dbus/types/variant.h 2014-01-20 22:13:41 +0000
362@@ -18,10 +18,15 @@
363 #ifndef CORE_DBUS_TYPES_VARIANT_H_
364 #define CORE_DBUS_TYPES_VARIANT_H_
365
366+#include <core/dbus/codec.h>
367+#include <core/dbus/message.h>
368+#include <core/dbus/helper/type_mapper.h>
369 #include <core/dbus/types/any.h>
370+#include <core/dbus/types/signature.h>
371
372 #include <cstring>
373
374+#include <functional>
375 #include <memory>
376 #include <stdexcept>
377
378@@ -31,32 +36,209 @@
379 {
380 namespace types
381 {
382-template<typename T = core::dbus::types::Any>
383 class Variant
384 {
385-public:
386- explicit Variant(const T& value = T()) : value(value)
387- {
388- }
389-
390- const T& get() const
391+protected:
392+ typedef std::function<void(dbus::Message::Writer&)> Encoder;
393+ typedef std::function<void(dbus::Message::Reader&)> Decoder;
394+
395+ inline Variant(const Encoder& encoder, const types::Signature& signature)
396+ : encoder(encoder),
397+ decoder(),
398+ signature_(signature)
399+ {
400+ }
401+
402+ inline Variant(const Decoder& decoder, const types::Signature& signature)
403+ : encoder(),
404+ decoder(decoder),
405+ signature_(signature)
406+ {
407+ }
408+public:
409+ template<typename T>
410+ static inline Variant encode(T t)
411+ {
412+ auto encoder = [t](dbus::Message::Writer& writer)
413+ {
414+ Codec<T>::encode_argument(writer, t);
415+ };
416+
417+ return std::move(
418+ Variant(
419+ encoder,
420+ types::Signature(
421+ core::dbus::helper::TypeMapper<T>::signature())));
422+ }
423+
424+ template<typename T>
425+ static inline Variant decode(T& t)
426+ {
427+ auto decoder = [&t](dbus::Message::Reader& reader)
428+ {
429+ Codec<T>::decode_argument(reader, t);
430+ };
431+
432+ return std::move(
433+ Variant(
434+ decoder,
435+ types::Signature(
436+ core::dbus::helper::TypeMapper<T>::signature())));
437+ }
438+
439+ inline Variant()
440+ {
441+ decoder = [this](dbus::Message::Reader& reader)
442+ {
443+ core::dbus::Codec<types::Any>::decode_argument(reader, any);
444+ };
445+ }
446+
447+ inline Variant(const Variant& rhs) = default;
448+
449+ inline Variant(Variant&& rhs)
450+ : encoder(std::move(rhs.encoder)),
451+ decoder(std::move(rhs.decoder)),
452+ any(std::move(rhs.any)),
453+ signature_(std::move(rhs.signature_))
454+ {
455+ }
456+
457+ virtual ~Variant() = default;
458+
459+ inline Variant& operator=(Variant&& rhs)
460+ {
461+ encoder = std::move(rhs.encoder);
462+ decoder = std::move(rhs.decoder);
463+ signature_ = std::move(rhs.signature_);
464+ any = std::move(rhs.any);
465+
466+ return *this;
467+ }
468+
469+ virtual void decode(Message::Reader& reader)
470+ {
471+ if (!decoder)
472+ throw std::runtime_error("Variant::decode: Missing a decoder specification.");
473+
474+ decoder(reader);
475+ }
476+
477+ virtual void encode(Message::Writer& writer) const
478+ {
479+ if (!encoder)
480+ throw std::runtime_error("Variant::encode: Missing an encoder specification.");
481+
482+ encoder(writer);
483+ }
484+
485+ virtual const types::Signature& signature() const
486+ {
487+ return signature_;
488+ }
489+
490+ template<typename T>
491+ T as() const
492+ {
493+ T result;
494+ any.reader() >> result;
495+
496+ return result;
497+ }
498+
499+protected:
500+ inline void set_encoder(const Encoder& encoder)
501+ {
502+ this->encoder = encoder;
503+ }
504+
505+ inline void set_decoder(const Decoder& decoder)
506+ {
507+ this->decoder = decoder;
508+ }
509+
510+ inline void set_signature(const types::Signature& signature)
511+ {
512+ this->signature_ = signature;
513+ }
514+
515+private:
516+ Encoder encoder;
517+ Decoder decoder;
518+ types::Any any;
519+ types::Signature signature_;
520+};
521+
522+template<typename T>
523+class TypedVariant : public Variant
524+{
525+public:
526+ explicit TypedVariant(const T& t = T()) : value(t)
527+ {
528+ auto decoder = [this](dbus::Message::Reader& reader)
529+ {
530+ Codec<T>::decode_argument(reader, value);
531+ };
532+
533+ auto encoder = [this](dbus::Message::Writer& writer)
534+ {
535+ Codec<T>::encode_argument(writer, value);
536+ };
537+
538+ set_decoder(decoder);
539+ set_encoder(encoder);
540+ set_signature(types::Signature{helper::TypeMapper<T>::signature()});
541+ }
542+
543+ inline const T& get() const
544 {
545 return value;
546 }
547
548- void set(const T& new_value)
549+ inline void set(const T& t)
550 {
551- value = new_value;
552+ value = t;
553 }
554
555- bool operator==(const Variant<T>& rhs) const
556- {
557- return value == rhs.value;
558- }
559 private:
560 T value;
561 };
562 }
563+/**
564+ * @brief Template specialization for variant argument types.
565+ */
566+template<>
567+struct Codec<types::Variant>
568+{
569+ inline static void encode_argument(Message::Writer& out, const types::Variant& variant)
570+ {
571+ auto vw = out.open_variant(variant.signature());
572+ {
573+ variant.encode(vw);
574+ }
575+ out.close_variant(std::move(vw));
576+ }
577+
578+ inline static void decode_argument(Message::Reader& in, types::Variant& variant)
579+ {
580+ auto vr = in.pop_variant();
581+ variant.decode(vr);
582+ }
583+};
584+
585+template<typename T>
586+struct Codec<types::TypedVariant<T>>
587+{
588+ inline static void encode_argument(Message::Writer& out, const types::TypedVariant<T>& variant)
589+ {
590+ Codec<types::Variant>::encode_argument(out, variant);
591+ }
592+
593+ inline static void decode_argument(Message::Reader& in, types::TypedVariant<T>& variant)
594+ {
595+ Codec<types::Variant>::decode_argument(in, variant);
596+ }
597+};
598 }
599 }
600 #endif // CORE_DBUS_TYPES_VARIANT_H_
601
602=== modified file 'src/core/dbus/message.cpp'
603--- src/core/dbus/message.cpp 2014-01-05 18:58:19 +0000
604+++ src/core/dbus/message.cpp 2014-01-20 22:13:41 +0000
605@@ -477,7 +477,7 @@
606 Writer w(d->msg);
607 if (!dbus_message_iter_open_container(
608 std::addressof(d->iter),
609- static_cast<int>(ArgumentType::structure),
610+ static_cast<int>(ArgumentType::dictionary_entry),
611 nullptr,
612 std::addressof(w.d->iter)))
613 throw std::runtime_error("Problem opening container");
614
615=== modified file 'src/core/dbus/message_p.h'
616--- src/core/dbus/message_p.h 2013-11-27 18:57:42 +0000
617+++ src/core/dbus/message_p.h 2014-01-20 22:13:41 +0000
618@@ -20,6 +20,7 @@
619
620 #include <core/dbus/message.h>
621
622+#include <cstring>
623 #include <sstream>
624
625 namespace core
626
627=== modified file 'tests/codec_test.cpp'
628--- tests/codec_test.cpp 2014-01-05 18:58:19 +0000
629+++ tests/codec_test.cpp 2014-01-20 22:13:41 +0000
630@@ -18,6 +18,7 @@
631
632 #include <core/dbus/codec.h>
633 #include <core/dbus/dbus.h>
634+#include <core/dbus/message_streaming_operators.h>
635 #include <core/dbus/helper/signature.h>
636
637 #include <core/dbus/types/any.h>
638@@ -43,7 +44,7 @@
639 TEST(Codec, BasicTypesMatchSizeAndAlignOfDBusTypes)
640 {
641 ::testing::StaticAssertTypeEq<dbus_bool_t, typename core::dbus::helper::DBusTypeMapper<core::dbus::ArgumentType::boolean>::Type>();
642- ::testing::StaticAssertTypeEq<int8_t, typename core::dbus::helper::DBusTypeMapper<core::dbus::ArgumentType::byte>::Type>();
643+ ::testing::StaticAssertTypeEq<uint8_t, typename core::dbus::helper::DBusTypeMapper<core::dbus::ArgumentType::byte>::Type>();
644 ::testing::StaticAssertTypeEq<int16_t, typename core::dbus::helper::DBusTypeMapper<core::dbus::ArgumentType::int16>::Type>();
645 ::testing::StaticAssertTypeEq<uint16_t, typename core::dbus::helper::DBusTypeMapper<core::dbus::ArgumentType::uint16>::Type>();
646 ::testing::StaticAssertTypeEq<int32_t, typename core::dbus::helper::DBusTypeMapper<core::dbus::ArgumentType::int32>::Type>();
647@@ -300,10 +301,10 @@
648 TEST(Variant, TypeMapperSpecializationReturnsCorrectValues)
649 {
650 namespace dbus = core::dbus;
651- ASSERT_EQ(dbus::ArgumentType::variant, dbus::helper::TypeMapper<dbus::types::Variant<double>>::type_value());
652+ ASSERT_EQ(dbus::ArgumentType::variant, dbus::helper::TypeMapper<dbus::types::Variant>::type_value());
653 ASSERT_TRUE(dbus::helper::TypeMapper<dbus::types::ObjectPath>::is_basic_type());
654 ASSERT_TRUE(dbus::helper::TypeMapper<dbus::types::ObjectPath>::requires_signature());
655- ASSERT_STREQ(DBUS_TYPE_VARIANT_AS_STRING DBUS_TYPE_DOUBLE_AS_STRING, dbus::helper::TypeMapper<dbus::types::Variant<double>>::signature().c_str());
656+ ASSERT_STREQ(DBUS_TYPE_VARIANT_AS_STRING, dbus::helper::TypeMapper<dbus::types::Variant>::signature().c_str());
657 }
658
659 TEST(Variant, EncodingAndDecodingWorksCorrectly)
660@@ -311,16 +312,20 @@
661 namespace dbus = core::dbus;
662
663 typedef dbus::types::Struct<std::tuple<double, double, std::int32_t>> Struct;
664- Struct my_struct = Struct{std::make_tuple(42., 42., 56)};
665
666- const dbus::types::Variant<Struct> expected_value {my_struct};
667+ const Struct expected_value = Struct{std::make_tuple(42., 42., 56)};
668 auto msg = a_method_call();
669- auto writer = msg->writer();
670-
671- ASSERT_NO_THROW(dbus::encode_argument(writer, expected_value););
672-
673+ {
674+ auto writer = msg->writer();
675+ ASSERT_NO_THROW(dbus::encode_argument(writer, dbus::types::Variant::encode(expected_value)););
676+ }
677 auto reader = msg->reader();
678- ASSERT_EQ(expected_value, dbus::decode_argument<dbus::types::Variant<Struct>>(reader));
679+ Struct my_struct;
680+ auto variant = std::move(dbus::types::Variant::decode(my_struct));
681+ dbus::decode_argument<dbus::types::Variant>(
682+ reader,
683+ variant);
684+ ASSERT_EQ(expected_value, my_struct);
685 }
686
687 TEST(Signature, TypeMapperSpecializationReturnsCorrectValues)
688@@ -359,7 +364,7 @@
689
690 {
691 auto writer = msg->writer();
692- auto array = writer.open_array(dbus::types::Signature{"(sv)"});
693+ auto array = writer.open_array(dbus::types::Signature{"{sv}"});
694 for(unsigned int i = 0; i < 5; i++)
695 {
696 auto entry = array.open_dict_entry();
697@@ -393,3 +398,35 @@
698
699 EXPECT_EQ(5, counter);
700 }
701+
702+TEST(Properties, DictionaryMappingToVariantsIsEncodedCorrectlyWithMap)
703+{
704+ namespace dbus = core::dbus;
705+
706+ const std::string key{"key"};
707+
708+ auto msg = a_method_call();
709+
710+ {
711+ std::map<std::string, dbus::types::Variant> map;
712+
713+ map["key1"] = dbus::types::Variant::encode<std::uint32_t>(1);
714+ map["key2"] = dbus::types::Variant::encode<std::uint32_t>(2);
715+ map["key3"] = dbus::types::Variant::encode<std::uint32_t>(3);
716+ map["key4"] = dbus::types::Variant::encode<std::uint32_t>(4);
717+ map["key5"] = dbus::types::Variant::encode<std::uint32_t>(5);
718+
719+ msg->writer() << map;
720+ }
721+
722+ auto reader = msg->reader();
723+ std::map<std::string, dbus::types::Variant> map;
724+ reader >> map;
725+
726+ EXPECT_EQ(5, map.size());
727+ EXPECT_EQ(1, map.at("key1").as<std::uint32_t>());
728+ EXPECT_EQ(2, map.at("key2").as<std::uint32_t>());
729+ EXPECT_EQ(3, map.at("key3").as<std::uint32_t>());
730+ EXPECT_EQ(4, map.at("key4").as<std::uint32_t>());
731+ EXPECT_EQ(5, map.at("key5").as<std::uint32_t>());
732+}
733
734=== modified file 'tests/stl_codec_test.cpp'
735--- tests/stl_codec_test.cpp 2014-01-07 15:57:23 +0000
736+++ tests/stl_codec_test.cpp 2014-01-20 22:13:41 +0000
737@@ -19,6 +19,8 @@
738 #include <core/dbus/dbus.h>
739 #include <core/dbus/message_streaming_operators.h>
740
741+#include <core/dbus/types/variant.h>
742+
743 #include <core/dbus/types/stl/map.h>
744 #include <core/dbus/types/stl/string.h>
745 #include <core/dbus/types/stl/tuple.h>
746@@ -66,7 +68,7 @@
747
748 {
749 auto writer = msg->writer();
750- auto array = writer.open_array(dbus::types::Signature{"(sv)"});
751+ auto array = writer.open_array(dbus::types::Signature{"{sv}"});
752 for(unsigned int i = 0; i < 5; i++)
753 {
754 auto entry = array.open_dict_entry();
755@@ -84,7 +86,7 @@
756
757 unsigned int counter = 0;
758
759- std::map<std::string, dbus::types::Variant<dbus::types::Any>> result;
760+ std::map<std::string, dbus::types::Variant> result;
761 msg->reader() >> result;
762
763 EXPECT_EQ(5, result.size());
764@@ -92,7 +94,7 @@
765 for (const auto& element : result)
766 {
767 EXPECT_EQ(std::to_string(counter), element.first);
768- EXPECT_EQ(counter, element.second.get().reader().pop_uint32());
769+ EXPECT_EQ(counter, element.second.as<std::uint32_t>());
770
771 counter++;
772 }

Subscribers

People subscribed via source and target branches