aboutsummaryrefslogtreecommitdiff
path: root/tests/client/convertertest.cpp
diff options
context:
space:
mode:
authorRenato Araujo Oliveira Filho <renato.filho@canonical.com>2012-09-14 16:11:28 -0300
committerRenato Araujo Oliveira Filho <renato.filho@canonical.com>2012-09-14 16:11:28 -0300
commitebe349e1d96b28e31c29b3e563da1a65fb176e39 (patch)
treebe1271f3d09159fa9f1a44b96fc62cff9cb3b72e /tests/client/convertertest.cpp
parent2b9cf1654e8eb602f70e14246c3c583962ce7254 (diff)
downloadqmenumodel-ebe349e1d96b28e31c29b3e563da1a65fb176e39.tar.gz
qmenumodel-ebe349e1d96b28e31c29b3e563da1a65fb176e39.tar.bz2
qmenumodel-ebe349e1d96b28e31c29b3e563da1a65fb176e39.zip
Created function to convert from QVariant to GVariant.
Moved QStateAction controler from QACtionGroup.
Diffstat (limited to 'tests/client/convertertest.cpp')
-rw-r--r--tests/client/convertertest.cpp91
1 files changed, 91 insertions, 0 deletions
diff --git a/tests/client/convertertest.cpp b/tests/client/convertertest.cpp
new file mode 100644
index 0000000..496b62a
--- /dev/null
+++ b/tests/client/convertertest.cpp
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2012 Canonical Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Renato Araujo Oliveira Filho <renato@canonical.com>
+ */
+
+#include "converter.h"
+
+#include <QObject>
+#include <QtTestGui>
+#include <QDebug>
+
+class ConverterTest : public QObject
+{
+ Q_OBJECT
+
+private:
+ bool compare(const QVariant &qv, const GVariantType *type)
+ {
+ bool result;
+ 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()
+ << "Result:" << (const char*) g_variant_get_type(gv)
+ << "Expected:"<< (const char*) type;
+ }
+ g_variant_unref(gv);
+ return result;
+ }
+
+private Q_SLOTS:
+
+
+ /*
+ * Test converter QVariant to GVariant
+ */
+ void testToGVariant()
+ {
+ // Boolean
+ QVERIFY(compare(QVariant(true), G_VARIANT_TYPE_BOOLEAN));
+
+ // Byte
+ QVERIFY(compare(QVariant::fromValue<uchar>(42), G_VARIANT_TYPE_BYTE));
+
+ // Int16
+ QVERIFY(compare(QVariant::fromValue<short>(-42), G_VARIANT_TYPE_INT16));
+
+ // UInt16
+ QVERIFY(compare(QVariant::fromValue<ushort>(-42), G_VARIANT_TYPE_UINT16));
+
+ // Int32
+ QVERIFY(compare(QVariant(-42), G_VARIANT_TYPE_INT32));
+
+ // UInt32
+ QVERIFY(compare(QVariant((uint)42), G_VARIANT_TYPE_UINT32));
+
+ // Int64
+ QVERIFY(compare(QVariant::fromValue<long>(-42), G_VARIANT_TYPE_INT64));
+
+ // UInt64
+ QVERIFY(compare(QVariant::fromValue<ulong>(42), G_VARIANT_TYPE_UINT64));
+
+ // Double
+ QVERIFY(compare(QVariant((double)42.42), G_VARIANT_TYPE_DOUBLE));
+
+ // String
+ QVERIFY(compare(QVariant(QString("42")), G_VARIANT_TYPE_STRING));
+
+ // ByteArray
+ QVERIFY(compare(QVariant(QByteArray("42")), G_VARIANT_TYPE_BYTESTRING));
+ }
+
+};
+
+QTEST_MAIN(ConverterTest)
+
+#include "convertertest.moc"