From a98d5486c37d68e1c1ce8fc1b6ad0a9018dd534d Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Mon, 15 Oct 2012 17:22:27 -0300 Subject: Created unit test for QVariantMap conversion; --- tests/client/convertertest.cpp | 6 ++++-- tests/client/modeltest.cpp | 10 ++++++++++ tests/client/script_modeltest.py | 9 ++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/client/convertertest.cpp b/tests/client/convertertest.cpp index 72b6a87..633ecf1 100644 --- a/tests/client/convertertest.cpp +++ b/tests/client/convertertest.cpp @@ -35,7 +35,7 @@ private: bool compare(const QVariant &qv, const GVariantType *type) { bool result; - GVariant *gv = Converter::toGVariant(qv); + GVariant *gv = Converter::toGVariant(qv); result = g_variant_type_equal(g_variant_get_type(gv), type); if (!result) { qWarning() << "types are different: QVariant:" << qv.typeName() @@ -48,7 +48,6 @@ private: private Q_SLOTS: - /* * Test converter QVariant to GVariant */ @@ -86,6 +85,9 @@ private Q_SLOTS: // ByteArray QVERIFY(compare(QVariant(QByteArray("42")), G_VARIANT_TYPE_BYTESTRING)); + + // Map + QVERIFY(compare(QVariantMap(), G_VARIANT_TYPE_VARDICT)); } }; diff --git a/tests/client/modeltest.cpp b/tests/client/modeltest.cpp index 9f6ee76..ebcec34 100644 --- a/tests/client/modeltest.cpp +++ b/tests/client/modeltest.cpp @@ -202,6 +202,16 @@ private Q_SLOTS: v = extra["string"]; QCOMPARE(v.type(), QVariant::String); QCOMPARE(v.toString(), QString("42")); + + // Map + v = extra["map"]; + QVariantMap map; + map.insert("int64", QVariant::fromValue(-42)); + map.insert("string", "42"); + map.insert("double", 42.42); + + QCOMPARE(v.type(), QVariant::Map); + QCOMPARE(v.toMap(), map); } }; diff --git a/tests/client/script_modeltest.py b/tests/client/script_modeltest.py index db4e28b..95df442 100755 --- a/tests/client/script_modeltest.py +++ b/tests/client/script_modeltest.py @@ -5,6 +5,12 @@ from gi.repository import GLib from menuscript import Script, ActionList, MENU_OBJECT_PATH al = ActionList(MENU_OBJECT_PATH) + +# create map +pmap = {'int64' : GLib.Variant('x', -42), + 'string': GLib.Variant('s', u'42'), + 'double': GLib.Variant('d', 42.42)} + al.appendItem("Menu0", "Menu0Act", None, None, {'x-boolean' : GLib.Variant('b', True), 'x-byte' : GLib.Variant('y', 42), 'x-int16' : GLib.Variant('n', -42), @@ -14,7 +20,8 @@ al.appendItem("Menu0", "Menu0Act", None, None, {'x-boolean' : GLib.Variant('b', 'x-int64' : GLib.Variant('x', -42), 'x-uint64' : GLib.Variant('t', 42), 'x-double' : GLib.Variant('d', 42.42), - 'x-string' : GLib.Variant('s', u'42') + 'x-string' : GLib.Variant('s', u'42'), + 'x-map' : GLib.Variant('a{sv}', pmap), }) al.appendItem("Menu1", "Menu1Act") -- cgit v1.2.3