diff options
author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2016-10-26 14:58:18 +0200 |
---|---|---|
committer | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2016-10-26 14:58:18 +0200 |
commit | 352a7702cca19608712423e6ca2c91f491e79013 (patch) | |
tree | d4dc1f2cb95a3fac7056d68cd40075d5ac4b5116 /tests/client | |
parent | 210cae9ff99fc5bbb206b904c8c7bfa2736f503f (diff) | |
download | qmenumodel-352a7702cca19608712423e6ca2c91f491e79013.tar.gz qmenumodel-352a7702cca19608712423e6ca2c91f491e79013.tar.bz2 qmenumodel-352a7702cca19608712423e6ca2c91f491e79013.zip |
converterTest: add content conversions back and further from gvariant
Diffstat (limited to 'tests/client')
-rw-r--r-- | tests/client/convertertest.cpp | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/tests/client/convertertest.cpp b/tests/client/convertertest.cpp index bc10f10..43127a7 100644 --- a/tests/client/convertertest.cpp +++ b/tests/client/convertertest.cpp @@ -156,7 +156,6 @@ private Q_SLOTS: void testConvertToGVariantAndBack() { QFETCH(QVariant, value); - QFETCH(QGVariantType, expectedType); GVariant *gv = Converter::toGVariant(value); QVERIFY(gv != NULL); @@ -291,6 +290,8 @@ private Q_SLOTS: QTest::newRow("List") << QGVariant(g_variant_new("ai", builder)) << (unsigned) QVariant::List; g_variant_builder_unref(builder); + QTest::newRow("Tuple") << QGVariant(g_variant_new("(i)", 53)) << (unsigned) QVariant::List; + const gchar *byteArray[] = {"42", "53", NULL}; QTest::newRow("ByteArrayList") << QGVariant(g_variant_new_bytestring_array(byteArray, -1)) << (unsigned) QMetaType::QByteArrayList; QTest::newRow("String List") << QGVariant(g_variant_new_strv(byteArray, -1)) << (unsigned) QVariant::StringList; @@ -304,6 +305,47 @@ private Q_SLOTS: QVERIFY(compare(value, (QVariant::Type) expectedType)); } + void testConvertToQVariantAndBack_data() + { + testConvertToQVariant_data(); + } + + void testConvertToQVariantAndBack() + { + QFETCH(QGVariant, value); + + QVariant qv = Converter::toQVariant(value); + QVERIFY(qv.isValid()); + + GVariant *gv = Converter::toGVariant(qv); + gboolean equals = g_variant_equal(value, gv); + + if (!equals && qv.type() == QVariant::List) { + QVERIFY(g_variant_type_is_array(g_variant_get_type(value))); + QVERIFY(g_variant_type_is_tuple(g_variant_get_type(gv))); + + gsize vsize = g_variant_n_children(value); + QCOMPARE(vsize, g_variant_n_children(gv)); + + for (gsize i = 0; i < vsize; ++i) { + equals = g_variant_equal(g_variant_get_child_value(value, i), g_variant_get_child_value(gv, i)); + if (!equals) + break; + } + } + + if (!equals) { + gchar *vs = g_variant_print(value, TRUE); + gchar *gvs = g_variant_print(gv, TRUE); + qWarning() << "Values do not match. Old" << vs << "converted" << gvs; + g_free(vs); + g_free(gvs); + } + + g_variant_unref(gv); + QVERIFY(equals != FALSE); + } + void testConvertToQVariantFromString_data() { QTest::addColumn<QString>("value"); |