diff options
Diffstat (limited to 'tests/client/convertertest.cpp')
-rw-r--r-- | tests/client/convertertest.cpp | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/tests/client/convertertest.cpp b/tests/client/convertertest.cpp index cd791c7..9e13ccb 100644 --- a/tests/client/convertertest.cpp +++ b/tests/client/convertertest.cpp @@ -28,13 +28,11 @@ extern "C" { #include <QtTest> #include <QDebug> -class QGVariantType : public QObject +class QGVariantType { - Q_OBJECT public: QGVariantType() : type(NULL) {} QGVariantType(const GVariantType *gvtype) : type(gvtype) {} - QGVariantType(const QGVariantType &other) : type(other.type) {} const GVariantType *getType() const { return type; } operator const GVariantType*() const { return type; } @@ -43,14 +41,13 @@ private: }; Q_DECLARE_METATYPE(QGVariantType); -class QGVariant : public QObject +class QGVariant { - Q_OBJECT public: QGVariant() : variant(NULL) {} ~QGVariant() { if (variant) g_variant_unref(variant); } QGVariant(GVariant *gv) : variant(g_variant_ref_sink(gv)) {} - QGVariant(const QGVariant &other) : variant(g_variant_ref_sink(other.variant)) {} + QGVariant(const QGVariant &other) : QGVariant(other.variant) {} GVariant *gvariant() const { return variant; } operator GVariant*() const { return variant; } @@ -104,6 +101,7 @@ private: << "Expected:"<< g_variant_type_peek_string(expected_type); } g_variant_unref(gv); + g_variant_type_free(expected_type); return result; } @@ -130,9 +128,16 @@ private Q_SLOTS: QTest::newRow("UInt64") << QVariant::fromValue<qulonglong>(42) << QGVariantType(G_VARIANT_TYPE_UINT64); QTest::newRow("Double") << QVariant((double)42.42) << QGVariantType(G_VARIANT_TYPE_DOUBLE); QTest::newRow("String") << QVariant(QString("42")) << QGVariantType(G_VARIANT_TYPE_STRING); + QTest::newRow("String List") << QVariant(QStringList({"42", "42"})) << QGVariantType(G_VARIANT_TYPE_STRING_ARRAY); QTest::newRow("ByteArray") << QVariant(QByteArray("42")) << QGVariantType(G_VARIANT_TYPE_BYTESTRING); QTest::newRow("Map") << QVariant(QVariantMap()) << QGVariantType(G_VARIANT_TYPE_VARDICT); + QTest::newRow("Map Filled") << QVariant(QVariantMap({{"fooBar", 0xdeadbeef}})) << QGVariantType(G_VARIANT_TYPE_VARDICT); QTest::newRow("List") << QVariant(QVariantList()) << QGVariantType(G_VARIANT_TYPE_UNIT); + QTest::newRow("List Filled") << QVariant(QVariantList({"fooBar", 0xdeadbeef})) << QGVariantType(G_VARIANT_TYPE("(su)")); + + QVariant result; + result.setValue(QByteArrayList({"42", "53"})); + QTest::newRow("ByteArrayList") << result << QGVariantType(G_VARIANT_TYPE_BYTESTRING_ARRAY); } void testConvertToGVariant() @@ -242,17 +247,22 @@ private Q_SLOTS: QTest::newRow("UInt64") << QGVariant(g_variant_new_uint64(53)) << (unsigned) QVariant::ULongLong; QTest::newRow("Double") << QGVariant(g_variant_new_double(53.3)) << (unsigned) QVariant::Double; QTest::newRow("String") << QGVariant(g_variant_new_string("53")) << (unsigned) QVariant::String; + QTest::newRow("Byte string") << QGVariant(g_variant_new_bytestring("53")) << (unsigned) QVariant::ByteArray; QTest::newRow("Tuple") << QGVariant(g_variant_new("(si)", "foo", 53)) << (unsigned) QVariant::List; - GVariantBuilder* builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); - g_variant_builder_add(builder, "{sv}", "fooo", g_variant_new_variant(g_variant_new_int64(53))); - QTest::newRow("Map") << QGVariant(g_variant_new("a{sv}", builder)) << (unsigned) QVariant::Map; + GVariantBuilder* builder = g_variant_builder_new(G_VARIANT_TYPE_VARDICT); + g_variant_builder_add(builder, "{sv}", "fooo", g_variant_new_int64(53)); + QTest::newRow("Map") << QGVariant(g_variant_builder_end(builder)) << (unsigned) QVariant::Map; g_variant_builder_unref(builder); builder = g_variant_builder_new(G_VARIANT_TYPE("ai")); g_variant_builder_add(builder, "i", g_variant_new_int32(53)); QTest::newRow("List") << QGVariant(g_variant_new("ai", builder)) << (unsigned) QVariant::List; g_variant_builder_unref(builder); + + 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; } void testConvertToQVariant() @@ -279,9 +289,12 @@ private Q_SLOTS: QTest::newRow("Double") << "double 65" << (unsigned) QVariant::Double; QTest::newRow("String") << "string '65'" << (unsigned) QVariant::String; QTest::newRow("String simple") << "\"65\"" << (unsigned) QVariant::String; + QTest::newRow("String List") << "['foo', 'bar']" << (unsigned) QVariant::StringList; + QTest::newRow("Byte string") << "b'fooo'" << (unsigned) QVariant::ByteArray; QTest::newRow("Map") << "{'foo': <65>}" << (unsigned) QVariant::Map; QTest::newRow("List") << "[65, 66]" << (unsigned) QVariant::List; QTest::newRow("Tuple") << "('foo', 65)" << (unsigned) QVariant::List; + QTest::newRow("ByteArrayList") << "[b'foo', b'bar']" << (unsigned) QMetaType::QByteArrayList; } void testConvertToQVariantFromString() |