aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-rw-r--r--libqmenumodel/src/converter.cpp28
-rw-r--r--tests/client/CMakeLists.txt8
-rw-r--r--tests/client/convertertest.cpp28
-rw-r--r--tests/client/modeltest.cpp6
-rwxr-xr-xtests/client/script_modeltest.py1
6 files changed, 68 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7f60630..f3799b3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -32,6 +32,7 @@ endif()
add_subdirectory(libqmenumodel)
# Tests Tools
+OPTION(TEST_XML_OUTPUT "Print test results on xml files" ON)
if(NOT DBUS_RUNNER)
message(STATUS "dbus-test-runner not found tests disabled.")
else()
diff --git a/libqmenumodel/src/converter.cpp b/libqmenumodel/src/converter.cpp
index 75733ce..6c2411c 100644
--- a/libqmenumodel/src/converter.cpp
+++ b/libqmenumodel/src/converter.cpp
@@ -51,8 +51,21 @@ QVariant Converter::toQVariant(GVariant *value)
}
result.setValue(qmap);
+ } else if (g_variant_type_is_tuple(type)) {
+ gsize size = g_variant_n_children(value);
+ QVariantList vlist;
+
+ for (gsize i=0; i < size; i++) {
+ GVariant *v = g_variant_get_child_value(value, i);
+ if (v) {
+ vlist << toQVariant(v);
+ g_variant_unref(v);
+ }
+ }
+
+ result.setValue(vlist);
} else {
- qWarning() << "Unsupported GVariant value";
+ qWarning() << "Unsupported GVariant value" << (char*) type;
}
/* TODO: implement convertions to others types
@@ -64,7 +77,6 @@ QVariant Converter::toQVariant(GVariant *value)
* G_VARIANT_TYPE_BASIC
* G_VARIANT_TYPE_MAYBE
* G_VARIANT_TYPE_ARRAY
- * G_VARIANT_TYPE_TUPLE
* G_VARIANT_TYPE_UNIT
* G_VARIANT_TYPE_DICT_ENTRY
* G_VARIANT_TYPE_DICTIONARY
@@ -72,7 +84,6 @@ QVariant Converter::toQVariant(GVariant *value)
* G_VARIANT_TYPE_BYTESTRING
* G_VARIANT_TYPE_OBJECT_PATH_ARRAY
* G_VARIANT_TYPE_BYTESTRING_ARRAY
- * G_VARIANT_TYPE_VARDICT
*/
return result;
@@ -137,6 +148,17 @@ GVariant* Converter::toGVariant(const QVariant &value)
g_variant_builder_unref(b);
break;
}
+ case QVariant::List:
+ {
+ QVariantList lst = value.toList();
+ GVariant **vars = g_new(GVariant*, lst.size());
+ for (int i=0; i < lst.size(); i++) {
+ vars[i] = toGVariant(lst[i]);
+ }
+ result = g_variant_new_tuple(vars, lst.size());
+ g_free(vars);
+ break;
+ }
default:
result = ::toGVariant(value.typeName(), value);
}
diff --git a/tests/client/CMakeLists.txt b/tests/client/CMakeLists.txt
index d946fad..392437c 100644
--- a/tests/client/CMakeLists.txt
+++ b/tests/client/CMakeLists.txt
@@ -8,9 +8,15 @@ macro(declare_test testname)
${GIO_LDFLAGS}
)
+ if(TEST_XML_OUTPUT)
+ set(TEST_ARGS -p -xunitxml -p -o -p test_${testname}.xml)
+ else()
+ set(TEST_ARGS "")
+ endif()
+
add_test(${testname}
${DBUS_RUNNER}
- --task ${CMAKE_CURRENT_BINARY_DIR}/${testname} -p -xunitxml -p -o -p test_${testname}.xml --task-name Client
+ --task ${CMAKE_CURRENT_BINARY_DIR}/${testname} ${TEST_ARGS} --task-name Client
--task ${CMAKE_CURRENT_SOURCE_DIR}/script_${testname}.py --task-name Server
--ignore-return)
set_tests_properties(${testname} PROPERTIES
diff --git a/tests/client/convertertest.cpp b/tests/client/convertertest.cpp
index 5301653..f382332 100644
--- a/tests/client/convertertest.cpp
+++ b/tests/client/convertertest.cpp
@@ -88,6 +88,34 @@ private Q_SLOTS:
// Map
QVERIFY(compare(QVariantMap(), G_VARIANT_TYPE_VARDICT));
+
+ }
+
+ void testTupleConversion()
+ {
+ QVariantList qTuple;
+ qTuple << 1 << "2" << 3.3;
+
+ GVariant *gTuple = Converter::toGVariant(qTuple);
+ QVERIFY(g_variant_type_is_tuple(g_variant_get_type(gTuple)));
+ QCOMPARE(g_variant_n_children(gTuple), (gsize)3);
+
+ GVariant *v = g_variant_get_child_value(gTuple, 0);
+ int v0 = g_variant_get_int32(v);
+ QCOMPARE(v0, 1);
+ g_variant_unref(v);
+
+ v = g_variant_get_child_value(gTuple, 1);
+ const gchar *v1 = g_variant_get_string(v, NULL);
+ QCOMPARE(QString(v1), QString("2"));
+ g_variant_unref(v);
+
+ v = g_variant_get_child_value(gTuple, 2);
+ gdouble v2 = g_variant_get_double(v);
+ QCOMPARE(v2, 3.3);
+ g_variant_unref(v);
+
+ g_variant_unref(gTuple);
}
};
diff --git a/tests/client/modeltest.cpp b/tests/client/modeltest.cpp
index 0aa4b52..bc5d95e 100644
--- a/tests/client/modeltest.cpp
+++ b/tests/client/modeltest.cpp
@@ -231,6 +231,12 @@ private Q_SLOTS:
QCOMPARE(v.type(), QVariant::String);
QCOMPARE(v.toString(), QString("dança"));
+ // Tuple
+ v = extra["tuple"];
+ QVariantList lst;
+ lst << "1" << 2 << 3.3;
+ QCOMPARE(v.type(), QVariant::List);
+ QCOMPARE(v.toList(), lst);
}
/*
diff --git a/tests/client/script_modeltest.py b/tests/client/script_modeltest.py
index 72c294c..9f5df9c 100755
--- a/tests/client/script_modeltest.py
+++ b/tests/client/script_modeltest.py
@@ -24,6 +24,7 @@ al.appendItem("Menu0", "Menu0Act", None, None, {'x-boolean' : GLib.Variant('b',
'x-string' : GLib.Variant('s', '42'),
'x-utf8' : GLib.Variant('s', 'dança'),
'x-map' : GLib.Variant('a{sv}', pmap),
+ 'x-tuple' : GLib.Variant('(sid)', ("1", 2, 3.3)),
})
al.appendItem("Menu1", "Menu1Act")