aboutsummaryrefslogtreecommitdiff
path: root/tests/client/convertertest.cpp
diff options
context:
space:
mode:
authorNick Dedekind <nicholas.dedekind@gmail.com>2013-08-27 17:47:45 +0100
committerNick Dedekind <nicholas.dedekind@gmail.com>2013-08-27 17:47:45 +0100
commit8cc3f9af6063a7256936da9813b6917023b1f626 (patch)
treeda44d4e1d373a7045e6c881df6c52908cc2c75dc /tests/client/convertertest.cpp
parentebace67d14edcd8e0e4d3d1ebe5e54e2b59270b3 (diff)
parent8977be59b11dfd6b5117ed85c962b792c3e7cf77 (diff)
downloadqmenumodel-8cc3f9af6063a7256936da9813b6917023b1f626.tar.gz
qmenumodel-8cc3f9af6063a7256936da9813b6917023b1f626.tar.bz2
qmenumodel-8cc3f9af6063a7256936da9813b6917023b1f626.zip
merged with trunk
Diffstat (limited to 'tests/client/convertertest.cpp')
-rw-r--r--tests/client/convertertest.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/client/convertertest.cpp b/tests/client/convertertest.cpp
index f382332..db2807f 100644
--- a/tests/client/convertertest.cpp
+++ b/tests/client/convertertest.cpp
@@ -45,6 +45,22 @@ private:
g_variant_unref(gv);
return result;
}
+ bool compareWithSchema(const QVariant &qv, const QString strType)
+ {
+ GVariantType* expected_type;
+ expected_type = g_variant_type_new(strType.toUtf8().data());
+
+ bool result;
+ GVariant *gv = Converter::toGVariantWithSchema(qv, strType.toUtf8().data());
+ result = g_variant_type_equal(g_variant_get_type(gv), expected_type);
+ if (!result) {
+ qWarning() << "types are different: QVariant:" << qv.typeName()
+ << "Result:" << (const char*) g_variant_get_type(gv)
+ << "Expected:"<< (const char*) expected_type;
+ }
+ g_variant_unref(gv);
+ return result;
+ }
private Q_SLOTS:
@@ -118,6 +134,43 @@ private Q_SLOTS:
g_variant_unref(gTuple);
}
+ void testSchemaConvert()
+ {
+ // convert to integer
+ compareWithSchema(QVariant::fromValue<int>(1), "i");
+ compareWithSchema(QVariant::fromValue<double>(1.1), "i");
+
+ // convert to integer
+ compareWithSchema(QVariant::fromValue<bool>(true), "b");
+ compareWithSchema(QVariant::fromValue<int>(1), "b");
+
+ // convert to double
+ compareWithSchema(QVariant::fromValue<double>(1.0), "d");
+ compareWithSchema(QVariant::fromValue<int>(1), "d");
+
+ // convert to string
+ compareWithSchema(QVariant::fromValue<int>(1), "s");
+ compareWithSchema(QVariant::fromValue<double>(1.1), "s");
+
+ // convert to tuple
+ compareWithSchema(QVariantList() << QVariant::fromValue<bool>(true) << QVariant::fromValue<int>(1) << QVariant::fromValue<int>(1) << QVariant::fromValue<QString>("test1"), "(bdis)");
+
+ // convert to array
+ compareWithSchema(QVariantList() << QVariant::fromValue<int>(1) << QVariant::fromValue<int>(1), "ad");
+ compareWithSchema(QVariantList() << QVariant::fromValue<QString>("test1") << QVariant::fromValue<QString>("test2"), "as");
+
+ // convert to array of tuple
+ QVariantList si1(QVariantList() << QVariant::fromValue<QString>("test1") << QVariant::fromValue<int>(1));
+ QVariantList si2(QVariantList() << QVariant::fromValue<QString>("test1") << QVariant::fromValue<int>(1));
+ compareWithSchema(QVariantList() << QVariant::fromValue(si1) << QVariant::fromValue(si2), "a(sd)");
+
+ // convert to vardict
+ QVariantMap map;
+ map["test1"] = QVariant::fromValue<int>(1);
+ map["test2"] = QVariant::fromValue<double>(1);
+ compareWithSchema(map, "a{sv}");
+ }
+
};
QTEST_MAIN(ConverterTest)