diff options
author | Stephen Kelly <stephen.kelly@kdab.com> | 2013-09-08 12:08:22 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-09 21:28:41 +0200 |
commit | a1898f4466518bf3e1b6e9154eec05ecf9d909e3 (patch) | |
tree | 7bd00c197258d89038aa9e03941e326d174571a9 /tests/auto | |
parent | 7fb3906d4e7cec7c69feee007b8393c9c2a3a316 (diff) |
Metatype: Remove the need for runtime-registration of 3rd party containers.
Replace that need with a macro so that registration of the
container helper conversions is done at the time of registration
of the container (usually when it is put into a QVariant).
Change-Id: I823fb3fdbce306ebc9f146675ac43724cec678d5
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index eab2ba4f36..a532407ad4 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -2278,23 +2278,26 @@ public: template<typename T> struct SequentialContainer { + typedef T value_type; + typedef const T* const_iterator; T t; + const_iterator begin() const { return &t; } + const_iterator end() const { return &t + 1; } }; template<typename T, typename U> -struct AssociativeContainer +struct AssociativeContainer : public std::map<T, U> { - T t; - U u; }; } Q_DECLARE_SMART_POINTER_METATYPE(MyNS::SmartPointer) -Q_DECLARE_METATYPE_TEMPLATE_1ARG(MyNS::SequentialContainer) -Q_DECLARE_METATYPE_TEMPLATE_2ARG(MyNS::AssociativeContainer) +Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE(MyNS::SequentialContainer) +Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE(MyNS::AssociativeContainer) +// Test that explicit declaration does not degrade features. Q_DECLARE_METATYPE(MyNS::SmartPointer<int>) void tst_QVariant::qvariant_cast_QObject_wrapper() @@ -2311,8 +2314,6 @@ void tst_QVariant::qvariant_cast_QObject_wrapper() MyNS::SequentialContainer<int> sc; sc.t = 47; MyNS::AssociativeContainer<int, short> ac; - ac.t = 42; - ac.u = 5; QVariant::fromValue(sc); QVariant::fromValue(ac); @@ -3538,9 +3539,11 @@ struct ContainerAPI<Container, QString> #ifdef TEST_FORWARD_LIST #include <forward_list> + +Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE(std::forward_list) + +// Test that explicit declaration does not degrade features. Q_DECLARE_METATYPE(std::forward_list<int>) -Q_DECLARE_METATYPE(std::forward_list<QVariant>) -Q_DECLARE_METATYPE(std::forward_list<QString>) template<typename Value_Type> struct ContainerAPI<std::forward_list<Value_Type> > @@ -3624,6 +3627,9 @@ struct KeyGetter<std::map<T, U> > #ifdef TEST_UNORDERED_MAP #include <unordered_map> typedef std::unordered_map<int, bool> StdUnorderedMap_int_bool; + +Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE(std::unordered_map) + Q_DECLARE_METATYPE(StdUnorderedMap_int_bool) template<typename T, typename U> @@ -3718,9 +3724,6 @@ void tst_QVariant::iterateContainerElements() TEST_SEQUENTIAL_ITERATION(std::list, QString) #ifdef TEST_FORWARD_LIST - qRegisterSequentialConverter<std::forward_list<int> >(); - qRegisterSequentialConverter<std::forward_list<QVariant> >(); - qRegisterSequentialConverter<std::forward_list<QString> >(); TEST_SEQUENTIAL_ITERATION(std::forward_list, int) TEST_SEQUENTIAL_ITERATION(std::forward_list, QVariant) TEST_SEQUENTIAL_ITERATION(std::forward_list, QString) @@ -3758,7 +3761,6 @@ void tst_QVariant::iterateContainerElements() TEST_ASSOCIATIVE_ITERATION(QMap, int, bool) TEST_ASSOCIATIVE_ITERATION(std::map, int, bool) #ifdef TEST_UNORDERED_MAP - qRegisterAssociativeConverter<StdUnorderedMap_int_bool>(); TEST_ASSOCIATIVE_ITERATION(std::unordered_map, int, bool) #endif } |