From bba640d9c189be19d66c6294873b6ab8ffa4efc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 20 Oct 2016 12:22:05 +0200 Subject: ActionGroupTest: split tests depending on they need the helper script or not And cleanup units --- tests/client/actiongrouptest.cpp | 101 +++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 47 deletions(-) (limited to 'tests') diff --git a/tests/client/actiongrouptest.cpp b/tests/client/actiongrouptest.cpp index d187ea7..cc43245 100644 --- a/tests/client/actiongrouptest.cpp +++ b/tests/client/actiongrouptest.cpp @@ -27,26 +27,15 @@ #include #include -class ActionGroupTest : public QObject +class ActionGroupTestBase : public QObject { Q_OBJECT -private: - DBusMenuScript m_script; +protected: QDBusMenuModel m_model; QDBusActionGroup m_actionGroup; -private Q_SLOTS: - void initTestCase() - { - QVERIFY(m_script.connect()); - } - - void cleanupTestCase() - { - m_script.quit(); - } - - void init() +protected Q_SLOTS: + virtual void init() { m_model.stop(); m_model.setBusType(DBusEnums::SessionBus); @@ -59,11 +48,6 @@ private Q_SLOTS: m_actionGroup.setObjectPath(MENU_OBJECT_PATH); } - void cleanup() - { - m_script.unpublishMenu(); - } - /* * Test if the propety busType handle correct integer values */ @@ -88,27 +72,57 @@ private Q_SLOTS: */ void testServiceAppear() { - m_model.start(); - m_actionGroup.start(); QCOMPARE(m_actionGroup.status(), DBusEnums::Connecting); // Make menu available + DBusMenuScript m_script; + m_script.connect(); m_script.publishMenu(); QCOMPARE(m_actionGroup.status(), DBusEnums::Connected); } +}; - /* - * Test if QDBusActionGroup change to correct state after DBus - * service disappear - */ - void testServiceDisappear() +class ActionGroupTestWithScript : public ActionGroupTestBase +{ + Q_OBJECT +private: + DBusMenuScript m_script; + +private Q_SLOTS: + void initTestCase() + { + QVERIFY(m_script.connect()); + } + + void cleanupTestCase() { + m_script.quit(); + } + + void init() + { + ActionGroupTestBase::init(); + + // start model m_model.start(); m_actionGroup.start(); // Make menu available m_script.publishMenu(); + } + + void cleanup() + { + m_script.unpublishMenu(); + } + + /* + * Test if QDBusActionGroup change to correct state after DBus + * service disappear + */ + void testServiceDisappear() + { QCOMPARE(m_actionGroup.status(), DBusEnums::Connected); // Append menus @@ -127,12 +141,7 @@ private Q_SLOTS: */ void testActiveAction() { - // start model - m_model.start(); - m_actionGroup.start(); - - // Make menu available - m_script.publishMenu(); + // Append 2 menus m_script.walk(2); // Get Action @@ -158,12 +167,7 @@ private Q_SLOTS: */ void testRemoveAction() { - // start model - m_model.start(); - m_actionGroup.start(); - - // Make menu available and append 2 menus - m_script.publishMenu(); + // Append 2 menus m_script.walk(2); // Get Action @@ -183,13 +187,6 @@ private Q_SLOTS: */ void testActionIsValid() { - // start model - m_model.start(); - m_actionGroup.start(); - - // Make menu available and append 2 menus - m_script.publishMenu(); - // Get invalid Action QStateAction *act = m_actionGroup.action(QString("Menu1Act")); QVERIFY(act); @@ -204,6 +201,16 @@ private Q_SLOTS: } }; -QTEST_MAIN(ActionGroupTest) +int main(int argc, char *argv[]) +{ + ActionGroupTestBase baseTests; + ActionGroupTestWithScript scriptTests; + + QApplication a(argc, argv); + int baseTestsResults = QTest::qExec(&baseTests); + int scriptTestsResults = QTest::qExec(&scriptTests); + + return std::max(baseTestsResults, scriptTestsResults); +} #include "actiongrouptest.moc" -- cgit v1.2.3 From 6d2a0aac08c8536d735d4d7407cfe28b8c053149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 20 Oct 2016 16:06:30 +0200 Subject: ActionGroupTest: add test for activateByVariantString --- tests/client/actiongrouptest.cpp | 128 ++++++++++++++++++++------------------- 1 file changed, 65 insertions(+), 63 deletions(-) (limited to 'tests') diff --git a/tests/client/actiongrouptest.cpp b/tests/client/actiongrouptest.cpp index cc43245..3ab329c 100644 --- a/tests/client/actiongrouptest.cpp +++ b/tests/client/actiongrouptest.cpp @@ -27,15 +27,28 @@ #include #include -class ActionGroupTestBase : public QObject +class ActionGroupTest : public QObject { Q_OBJECT -protected: +private: QDBusMenuModel m_model; QDBusActionGroup m_actionGroup; + DBusMenuScript m_script; + + void getMenuAction(QStateAction **act, int index) + { + // Append 2 menus + m_script.walk(2); -protected Q_SLOTS: - virtual void init() + // Get Action + QVariant action = m_model.data(m_model.index(index, 0), QMenuModel::Action); + QVERIFY(action.isValid()); + *act = m_actionGroup.action(action.toString()); + QVERIFY(act); + } + +private Q_SLOTS: + void init() { m_model.stop(); m_model.setBusType(DBusEnums::SessionBus); @@ -46,6 +59,28 @@ protected Q_SLOTS: m_actionGroup.setBusType(DBusEnums::SessionBus); m_actionGroup.setBusName(MENU_SERVICE_NAME); m_actionGroup.setObjectPath(MENU_OBJECT_PATH); + + // start model + m_model.start(); + m_actionGroup.start(); + + // Make menu available + m_script.publishMenu(); + } + + void initTestCase() + { + QVERIFY(m_script.connect()); + } + + void cleanupTestCase() + { + m_script.quit(); + } + + void cleanup() + { + m_script.unpublishMenu(); } /* @@ -72,50 +107,15 @@ protected Q_SLOTS: */ void testServiceAppear() { + m_script.unpublishMenu(); QCOMPARE(m_actionGroup.status(), DBusEnums::Connecting); // Make menu available - DBusMenuScript m_script; m_script.connect(); m_script.publishMenu(); QCOMPARE(m_actionGroup.status(), DBusEnums::Connected); } -}; - -class ActionGroupTestWithScript : public ActionGroupTestBase -{ - Q_OBJECT -private: - DBusMenuScript m_script; - -private Q_SLOTS: - void initTestCase() - { - QVERIFY(m_script.connect()); - } - - void cleanupTestCase() - { - m_script.quit(); - } - - void init() - { - ActionGroupTestBase::init(); - - // start model - m_model.start(); - m_actionGroup.start(); - - // Make menu available - m_script.publishMenu(); - } - - void cleanup() - { - m_script.unpublishMenu(); - } /* * Test if QDBusActionGroup change to correct state after DBus @@ -136,30 +136,42 @@ private Q_SLOTS: QCOMPARE(m_actionGroup.status(), DBusEnums::Disconnected); } + void testActionName() + { + QStateAction *act; + getMenuAction(&act, 1); + QCOMPARE(act->property("name").toString(), QString("Menu1Act")); + } + /* * Test if Action::trigger active the action over DBus */ - void testActiveAction() + void testStringActionActivation() { - // Append 2 menus - m_script.walk(2); + QStateAction *act; + getMenuAction(&act, 1); + act->activate(QVariant("42")); - // Get Action - QVariant action = m_model.data(m_model.index(1, 0), QMenuModel::Action); - QVERIFY(action.isValid()); - QStateAction *act = m_actionGroup.action(action.toString()); - QVERIFY(act); + // wait for dbus propagation + QTest::qWait(500); - // test action name - QCOMPARE(act->property("name").toString(), QString("Menu1Act")); + QPair result = m_script.popActivatedAction(); + QCOMPARE(result.first, QString("Menu1Act")); + QCOMPARE(result.second.toString(), QString("42")); + } + + void testStringActionActivationByVariantString() + { + QStateAction *act; + getMenuAction(&act, 1); + act->activateByVariantString("\"53\""); - act->activate(QVariant("42")); // wait for dbus propagation QTest::qWait(500); QPair result = m_script.popActivatedAction(); QCOMPARE(result.first, QString("Menu1Act")); - QCOMPARE(result.second.toString(), QString("42")); + QCOMPARE(result.second.toString(), QString("53")); } /* @@ -201,16 +213,6 @@ private Q_SLOTS: } }; -int main(int argc, char *argv[]) -{ - ActionGroupTestBase baseTests; - ActionGroupTestWithScript scriptTests; - - QApplication a(argc, argv); - int baseTestsResults = QTest::qExec(&baseTests); - int scriptTestsResults = QTest::qExec(&scriptTests); - - return std::max(baseTestsResults, scriptTestsResults); -} +QTEST_MAIN(ActionGroupTest); #include "actiongrouptest.moc" -- cgit v1.2.3 From 81e73a200ead6b9eee4d86a0a0484c184b1ee758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Sat, 22 Oct 2016 18:21:35 +0200 Subject: ConverterTest: use data in the testSchemaConvert --- tests/client/convertertest.cpp | 46 ++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 15 deletions(-) (limited to 'tests') diff --git a/tests/client/convertertest.cpp b/tests/client/convertertest.cpp index 6f0f949..1f930df 100644 --- a/tests/client/convertertest.cpp +++ b/tests/client/convertertest.cpp @@ -179,41 +179,57 @@ private Q_SLOTS: g_variant_unref(gTuple); } - void testSchemaConvert() + void testSchemaConvert_data() { - // convert to integer - compareWithSchema(QVariant::fromValue(1), "i"); - compareWithSchema(QVariant::fromValue(1.1), "i"); + QTest::addColumn("value"); + QTest::addColumn("schema"); // convert to integer - compareWithSchema(QVariant::fromValue(true), "b"); - compareWithSchema(QVariant::fromValue(1), "b"); + QTest::newRow("integer") << QVariant::fromValue(1) << "i"; + QTest::newRow("integer from double") << QVariant::fromValue(1.1) << "i"; + + // convert to bool + QTest::newRow("bool") << QVariant::fromValue(true) << "b"; + QTest::newRow("bool from int") << QVariant::fromValue(1) << "b"; // convert to double - compareWithSchema(QVariant::fromValue(1.0), "d"); - compareWithSchema(QVariant::fromValue(1), "d"); + QTest::newRow("double") << QVariant::fromValue(1.0) << "d"; + QTest::newRow("double from int") << QVariant::fromValue(1) << "d"; // convert to string - compareWithSchema(QVariant::fromValue(1), "s"); - compareWithSchema(QVariant::fromValue(1.1), "s"); + QTest::newRow("string") << QVariant::fromValue("FoooBar") << "x"; + QTest::newRow("string from int") << QVariant::fromValue(1) << "s"; + QTest::newRow("string from double") << QVariant::fromValue(1.1) << "s"; // convert to tuple - compareWithSchema(QVariantList() << QVariant::fromValue(true) << QVariant::fromValue(1) << QVariant::fromValue(1) << QVariant::fromValue("test1"), "(bdis)"); + auto list = QVariantList() << QVariant::fromValue(true) << QVariant::fromValue(1) << QVariant::fromValue(1) << QVariant::fromValue("test1"); + QTest::newRow("tuple") << QVariant(list) << "(bdis)"; // convert to array - compareWithSchema(QVariantList() << QVariant::fromValue(1) << QVariant::fromValue(1), "ad"); - compareWithSchema(QVariantList() << QVariant::fromValue("test1") << QVariant::fromValue("test2"), "as"); + list = QVariantList() << QVariant::fromValue(1) << QVariant::fromValue(1); + QTest::newRow("int list") << QVariant(list) << "ad"; + list = QVariantList() << QVariant::fromValue("test1") << QVariant::fromValue("test2"); + QTest::newRow("string list") << QVariant(list) << "as"; // convert to array of tuple QVariantList si1(QVariantList() << QVariant::fromValue("test1") << QVariant::fromValue(1)); QVariantList si2(QVariantList() << QVariant::fromValue("test1") << QVariant::fromValue(1)); - compareWithSchema(QVariantList() << QVariant::fromValue(si1) << QVariant::fromValue(si2), "a(sd)"); + list = QVariantList() << QVariant::fromValue(si1) << QVariant::fromValue(si2); + QTest::newRow("array of tuple") << QVariant(list) << "a(sd)"; // convert to vardict QVariantMap map; map["test1"] = QVariant::fromValue(1); map["test2"] = QVariant::fromValue(1); - compareWithSchema(map, "a{sv}"); + QTest::newRow("map") << QVariant(map) << "a{sv}"; + } + + void testSchemaConvert() + { + QFETCH(QVariant, value); + QFETCH(QString, schema); + + compareWithSchema(value, schema); } }; -- cgit v1.2.3 From 00ddb5fcb1b738480e161a47a319fd6b3470b2c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Sat, 22 Oct 2016 18:40:29 +0200 Subject: convertertest: repeat tests using test data --- tests/client/convertertest.cpp | 107 ++++++++++------------------------------- 1 file changed, 26 insertions(+), 81 deletions(-) (limited to 'tests') diff --git a/tests/client/convertertest.cpp b/tests/client/convertertest.cpp index 1f930df..05656ed 100644 --- a/tests/client/convertertest.cpp +++ b/tests/client/convertertest.cpp @@ -68,88 +68,33 @@ private Q_SLOTS: * Test converter QVariant to GVariant */ - void testBooleanToGVariant() + void testConvertToGVariant_data() { - // Boolean - QVERIFY(compare(QVariant(true), G_VARIANT_TYPE_BOOLEAN)); - } - - void testByteToGVariant() - { - // Byte - QVERIFY(compare(QVariant::fromValue(42), G_VARIANT_TYPE_BYTE)); - } - - void testInt16ToGVariant() - { - // Int16 - QVERIFY(compare(QVariant::fromValue(-42), G_VARIANT_TYPE_INT16)); - } - - void testUInt16ToGVariant() - { - // UInt16 - QVERIFY(compare(QVariant::fromValue(-42), G_VARIANT_TYPE_UINT16)); - } - - void testInt32ToGVariant() - { - // Int32 - QVERIFY(compare(QVariant(-42), G_VARIANT_TYPE_INT32)); - } - - void testUInt32ToGVariant() - { - // UInt32 - QVERIFY(compare(QVariant((uint)42), G_VARIANT_TYPE_UINT32)); - } - - void testInt64ToGVariant() - { - // Int64 - QVERIFY(compare(QVariant::fromValue(-42), G_VARIANT_TYPE_INT64)); - } - - void testUInt64ToGVariant() - { - // UInt64 - QVERIFY(compare(QVariant::fromValue(42), G_VARIANT_TYPE_UINT64)); - } - - void testQlongLongToGVariant() - { - // Int64 - QVERIFY(compare(QVariant::fromValue(-42), G_VARIANT_TYPE_INT64)); - } - - void testUQlongLongToGVariant() - { - // UInt64 - QVERIFY(compare(QVariant::fromValue(42), G_VARIANT_TYPE_UINT64)); - } - - void testDoubleToGVariant() - { - // Double - QVERIFY(compare(QVariant((double)42.42), G_VARIANT_TYPE_DOUBLE)); - } - - void testStringToGVariant() - { - // String - QVERIFY(compare(QVariant(QString("42")), G_VARIANT_TYPE_STRING)); - } - - void testByteArrayToGVariant() + QTest::addColumn("value"); + QTest::addColumn("expectedType"); + + QTest::newRow("Boolean") << QVariant(true) << reinterpret_cast(G_VARIANT_TYPE_BOOLEAN); + QTest::newRow("Byte") << QVariant::fromValue(42) << reinterpret_cast(G_VARIANT_TYPE_BYTE); + QTest::newRow("Int16") << QVariant::fromValue(-42) << reinterpret_cast(G_VARIANT_TYPE_INT16); + QTest::newRow("UInt16") << QVariant::fromValue(-42) << reinterpret_cast(G_VARIANT_TYPE_UINT16); + QTest::newRow("Int32") << QVariant(-42) << reinterpret_cast(G_VARIANT_TYPE_INT32); + QTest::newRow("UInt32") << QVariant((uint)42) << reinterpret_cast(G_VARIANT_TYPE_UINT32); + QTest::newRow("Int64") << QVariant::fromValue(-42) << reinterpret_cast(G_VARIANT_TYPE_INT64); + QTest::newRow("UInt64") << QVariant::fromValue(42) << reinterpret_cast(G_VARIANT_TYPE_UINT64); + QTest::newRow("Int64") << QVariant::fromValue(-42) << reinterpret_cast(G_VARIANT_TYPE_INT64); + QTest::newRow("UInt64") << QVariant::fromValue(42) << reinterpret_cast(G_VARIANT_TYPE_UINT64); + QTest::newRow("Double") << QVariant((double)42.42) << reinterpret_cast(G_VARIANT_TYPE_DOUBLE); + QTest::newRow("String") << QVariant(QString("42")) << reinterpret_cast(G_VARIANT_TYPE_STRING); + QTest::newRow("ByteArray") << QVariant(QByteArray("42")) << reinterpret_cast(G_VARIANT_TYPE_BYTESTRING); + QTest::newRow("Map") << QVariant(QVariantMap()) << reinterpret_cast(G_VARIANT_TYPE_VARDICT); + } + + void testConvertToGVariant() { - // ByteArray - QVERIFY(compare(QVariant(QByteArray("42")), G_VARIANT_TYPE_BYTESTRING)); - } + QFETCH(QVariant, value); + QFETCH(QString, expectedType); - void testMapToGVariant() - { - // Map - QVERIFY(compare(QVariantMap(), G_VARIANT_TYPE_VARDICT)); + QVERIFY(compare(value, g_variant_type_new(expectedType.toUtf8().data()))); } void testTupleConversion() @@ -179,7 +124,7 @@ private Q_SLOTS: g_variant_unref(gTuple); } - void testSchemaConvert_data() + void testConvertToGVariantWithSchema_data() { QTest::addColumn("value"); QTest::addColumn("schema"); @@ -224,7 +169,7 @@ private Q_SLOTS: QTest::newRow("map") << QVariant(map) << "a{sv}"; } - void testSchemaConvert() + void testConvertToGVariantWithSchema() { QFETCH(QVariant, value); QFETCH(QString, schema); -- cgit v1.2.3 From 4b495fc2651d2626a5fd0bf1c19263ad4b11ce8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Sat, 22 Oct 2016 18:54:58 +0200 Subject: convertertest: create QGVariantType wrapper to avoid reinterperating a QString --- tests/client/convertertest.cpp | 54 +++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 19 deletions(-) (limited to 'tests') diff --git a/tests/client/convertertest.cpp b/tests/client/convertertest.cpp index 05656ed..9e563cd 100644 --- a/tests/client/convertertest.cpp +++ b/tests/client/convertertest.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2012 Canonical Ltd. + * Copyright 2012-2016 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 @@ -15,6 +15,7 @@ * * Authors: * Renato Araujo Oliveira Filho + * Marco Trevisan */ extern "C" { @@ -27,6 +28,21 @@ extern "C" { #include #include +class QGVariantType : public QObject +{ + Q_OBJECT +public: + QGVariantType() : type(nullptr) {} + 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; } + +private: + const GVariantType *type; +}; +Q_DECLARE_METATYPE(QGVariantType); + class ConverterTest : public QObject { Q_OBJECT @@ -71,30 +87,30 @@ private Q_SLOTS: void testConvertToGVariant_data() { QTest::addColumn("value"); - QTest::addColumn("expectedType"); - - QTest::newRow("Boolean") << QVariant(true) << reinterpret_cast(G_VARIANT_TYPE_BOOLEAN); - QTest::newRow("Byte") << QVariant::fromValue(42) << reinterpret_cast(G_VARIANT_TYPE_BYTE); - QTest::newRow("Int16") << QVariant::fromValue(-42) << reinterpret_cast(G_VARIANT_TYPE_INT16); - QTest::newRow("UInt16") << QVariant::fromValue(-42) << reinterpret_cast(G_VARIANT_TYPE_UINT16); - QTest::newRow("Int32") << QVariant(-42) << reinterpret_cast(G_VARIANT_TYPE_INT32); - QTest::newRow("UInt32") << QVariant((uint)42) << reinterpret_cast(G_VARIANT_TYPE_UINT32); - QTest::newRow("Int64") << QVariant::fromValue(-42) << reinterpret_cast(G_VARIANT_TYPE_INT64); - QTest::newRow("UInt64") << QVariant::fromValue(42) << reinterpret_cast(G_VARIANT_TYPE_UINT64); - QTest::newRow("Int64") << QVariant::fromValue(-42) << reinterpret_cast(G_VARIANT_TYPE_INT64); - QTest::newRow("UInt64") << QVariant::fromValue(42) << reinterpret_cast(G_VARIANT_TYPE_UINT64); - QTest::newRow("Double") << QVariant((double)42.42) << reinterpret_cast(G_VARIANT_TYPE_DOUBLE); - QTest::newRow("String") << QVariant(QString("42")) << reinterpret_cast(G_VARIANT_TYPE_STRING); - QTest::newRow("ByteArray") << QVariant(QByteArray("42")) << reinterpret_cast(G_VARIANT_TYPE_BYTESTRING); - QTest::newRow("Map") << QVariant(QVariantMap()) << reinterpret_cast(G_VARIANT_TYPE_VARDICT); + QTest::addColumn("expectedType"); + + QTest::newRow("Boolean") << QVariant(true) << QGVariantType(G_VARIANT_TYPE_BOOLEAN); + QTest::newRow("Byte") << QVariant::fromValue(42) << QGVariantType(G_VARIANT_TYPE_BYTE); + QTest::newRow("Int16") << QVariant::fromValue(-42) << QGVariantType(G_VARIANT_TYPE_INT16); + QTest::newRow("UInt16") << QVariant::fromValue(-42) << QGVariantType(G_VARIANT_TYPE_UINT16); + QTest::newRow("Int32") << QVariant(-42) << QGVariantType(G_VARIANT_TYPE_INT32); + QTest::newRow("UInt32") << QVariant((uint)42) << QGVariantType(G_VARIANT_TYPE_UINT32); + QTest::newRow("Int64") << QVariant::fromValue(-42) << QGVariantType(G_VARIANT_TYPE_INT64); + QTest::newRow("UInt64") << QVariant::fromValue(42) << QGVariantType(G_VARIANT_TYPE_UINT64); + QTest::newRow("Int64") << QVariant::fromValue(-42) << QGVariantType(G_VARIANT_TYPE_INT64); + QTest::newRow("UInt64") << QVariant::fromValue(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("ByteArray") << QVariant(QByteArray("42")) << QGVariantType(G_VARIANT_TYPE_BYTESTRING); + QTest::newRow("Map") << QVariant(QVariantMap()) << QGVariantType(G_VARIANT_TYPE_VARDICT); } void testConvertToGVariant() { QFETCH(QVariant, value); - QFETCH(QString, expectedType); + QFETCH(QGVariantType, expectedType); - QVERIFY(compare(value, g_variant_type_new(expectedType.toUtf8().data()))); + QVERIFY(compare(value, expectedType)); } void testTupleConversion() -- cgit v1.2.3 From 3d2c260f804273e5a65f27a379f4ad74407ee921 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Sat, 22 Oct 2016 19:00:49 +0200 Subject: remove deprecated g_type_init() calls --- tests/client/actiongrouptest.cpp | 1 + tests/client/cachetest.cpp | 5 ----- tests/client/convertertest.cpp | 4 ++-- tests/client/modelsignalstest.cpp | 5 ----- tests/client/treetest.cpp | 5 ----- 5 files changed, 3 insertions(+), 17 deletions(-) (limited to 'tests') diff --git a/tests/client/actiongrouptest.cpp b/tests/client/actiongrouptest.cpp index 3ab329c..425f97c 100644 --- a/tests/client/actiongrouptest.cpp +++ b/tests/client/actiongrouptest.cpp @@ -43,6 +43,7 @@ private: // Get Action QVariant action = m_model.data(m_model.index(index, 0), QMenuModel::Action); QVERIFY(action.isValid()); + printf("aCTION IS %s\n",action.toString().toUtf8().data()); *act = m_actionGroup.action(action.toString()); QVERIFY(act); } diff --git a/tests/client/cachetest.cpp b/tests/client/cachetest.cpp index 22fe5d3..8ad65af 100644 --- a/tests/client/cachetest.cpp +++ b/tests/client/cachetest.cpp @@ -77,11 +77,6 @@ class CacheTest : public QObject Q_OBJECT private Q_SLOTS: - void initTestCase() - { - g_type_init(); - } - // Verify that normal menu items are not cached (only sub-menus are) void testCacheContents() { diff --git a/tests/client/convertertest.cpp b/tests/client/convertertest.cpp index 9e563cd..ddb6aa2 100644 --- a/tests/client/convertertest.cpp +++ b/tests/client/convertertest.cpp @@ -32,7 +32,7 @@ class QGVariantType : public QObject { Q_OBJECT public: - QGVariantType() : type(nullptr) {} + QGVariantType() : type(NULL) {} QGVariantType(const GVariantType *gvtype) : type(gvtype) {} QGVariantType(const QGVariantType &other) : type(other.type) {} const GVariantType *getType() const { return type; } @@ -163,7 +163,7 @@ private Q_SLOTS: QTest::newRow("string from double") << QVariant::fromValue(1.1) << "s"; // convert to tuple - auto list = QVariantList() << QVariant::fromValue(true) << QVariant::fromValue(1) << QVariant::fromValue(1) << QVariant::fromValue("test1"); + QVariantList list = QVariantList() << QVariant::fromValue(true) << QVariant::fromValue(1) << QVariant::fromValue(1) << QVariant::fromValue("test1"); QTest::newRow("tuple") << QVariant(list) << "(bdis)"; // convert to array diff --git a/tests/client/modelsignalstest.cpp b/tests/client/modelsignalstest.cpp index 40a76c6..3064778 100644 --- a/tests/client/modelsignalstest.cpp +++ b/tests/client/modelsignalstest.cpp @@ -192,11 +192,6 @@ class ModelSignalsTest : public QObject { Q_OBJECT private Q_SLOTS: - void initTestCase() - { - g_type_init(); - } - /* * Test if the model state still correct before and after insert a new row */ diff --git a/tests/client/treetest.cpp b/tests/client/treetest.cpp index b6fec3c..81399f7 100644 --- a/tests/client/treetest.cpp +++ b/tests/client/treetest.cpp @@ -62,11 +62,6 @@ class TreeTest : public QObject Q_OBJECT private Q_SLOTS: - void initTestCase() - { - g_type_init(); - } - void testMenuBuild() { TestModel menu; -- cgit v1.2.3 From 7f78a2c234dd017b19de1a43c0fac12a15326be4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Mon, 24 Oct 2016 20:46:51 +0200 Subject: converterTest: QVERIFY comparison return value --- tests/client/actiongrouptest.cpp | 1 - tests/client/convertertest.cpp | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/client/actiongrouptest.cpp b/tests/client/actiongrouptest.cpp index 425f97c..3ab329c 100644 --- a/tests/client/actiongrouptest.cpp +++ b/tests/client/actiongrouptest.cpp @@ -43,7 +43,6 @@ private: // Get Action QVariant action = m_model.data(m_model.index(index, 0), QMenuModel::Action); QVERIFY(action.isValid()); - printf("aCTION IS %s\n",action.toString().toUtf8().data()); *act = m_actionGroup.action(action.toString()); QVERIFY(act); } diff --git a/tests/client/convertertest.cpp b/tests/client/convertertest.cpp index ddb6aa2..636c299 100644 --- a/tests/client/convertertest.cpp +++ b/tests/client/convertertest.cpp @@ -158,7 +158,7 @@ private Q_SLOTS: QTest::newRow("double from int") << QVariant::fromValue(1) << "d"; // convert to string - QTest::newRow("string") << QVariant::fromValue("FoooBar") << "x"; + QTest::newRow("string") << QVariant::fromValue("FoooBar") << "s"; QTest::newRow("string from int") << QVariant::fromValue(1) << "s"; QTest::newRow("string from double") << QVariant::fromValue(1.1) << "s"; @@ -190,7 +190,7 @@ private Q_SLOTS: QFETCH(QVariant, value); QFETCH(QString, schema); - compareWithSchema(value, schema); + QVERIFY(compareWithSchema(value, schema)); } }; -- cgit v1.2.3 From abc65a4bd4bf3957b47367da58783265773b5bb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Mon, 24 Oct 2016 21:02:38 +0200 Subject: convertertest: add tests for converting to QVariant --- tests/client/convertertest.cpp | 66 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/client/convertertest.cpp b/tests/client/convertertest.cpp index 636c299..10c3b4c 100644 --- a/tests/client/convertertest.cpp +++ b/tests/client/convertertest.cpp @@ -43,6 +43,22 @@ private: }; Q_DECLARE_METATYPE(QGVariantType); +class QGVariant : public QObject +{ + 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)) {} + GVariant *gvariant() const { return variant; } + operator GVariant*() const { return variant; } + +private: + GVariant *variant; +}; +Q_DECLARE_METATYPE(QGVariant); + class ConverterTest : public QObject { Q_OBJECT @@ -55,8 +71,21 @@ private: 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; + << "Result:" << g_variant_type_peek_string(g_variant_get_type(gv)) + << "Expected:"<< g_variant_type_peek_string(type); + } + g_variant_unref(gv); + return result; + } + bool compare(GVariant *gv, const QVariant::Type type) + { + g_variant_ref_sink(gv); + const QVariant& qv = Converter::toQVariant(gv); + bool result = (qv.type() == type); + if (!result) { + qWarning() << "types are different: GVariant:" << g_variant_type_peek_string(g_variant_get_type(gv)) + << "Result:" << qv.type() + << "Expected:"<< type; } g_variant_unref(gv); return result; @@ -71,8 +100,8 @@ private: 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; + << "Result:" << g_variant_type_peek_string(g_variant_get_type(gv)) + << "Expected:"<< g_variant_type_peek_string(expected_type); } g_variant_unref(gv); return result; @@ -193,6 +222,35 @@ private Q_SLOTS: QVERIFY(compareWithSchema(value, schema)); } + /* + * Test converter GVariant to QVariant + */ + + void testConvertToQVariant_data() + { + QTest::addColumn("value"); + QTest::addColumn("expectedType"); + + QTest::newRow("Boolean") << QGVariant(g_variant_new_boolean(TRUE)) << (unsigned) QVariant::Bool; + QTest::newRow("Byte") << QGVariant(g_variant_new_byte(53)) << (unsigned) QMetaType::UChar; + QTest::newRow("Int16") << QGVariant(g_variant_new_int16(-53)) << (unsigned) QMetaType::Short; + QTest::newRow("UInt16") << QGVariant(g_variant_new_uint16(53)) << (unsigned) QMetaType::UShort; + QTest::newRow("Int32") << QGVariant(g_variant_new_int32(-53)) << (unsigned) QVariant::Int; + QTest::newRow("UInt32") << QGVariant(g_variant_new_uint32(53)) << (unsigned) QVariant::UInt; + QTest::newRow("Int64") << QGVariant(g_variant_new_int64(-53)) << (unsigned) QVariant::LongLong; + 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; + } + + void testConvertToQVariant() + { + QFETCH(QGVariant, value); + QFETCH(unsigned, expectedType); + + QVERIFY(compare(value, (QVariant::Type) expectedType)); + } + }; QTEST_MAIN(ConverterTest) -- cgit v1.2.3 From 3bcc60fe180a27a63ccc7a4b0635454316e37748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Mon, 24 Oct 2016 21:13:30 +0200 Subject: converterTest: add tests for toQVariantFromVariantString --- tests/client/convertertest.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tests') diff --git a/tests/client/convertertest.cpp b/tests/client/convertertest.cpp index 10c3b4c..fe72181 100644 --- a/tests/client/convertertest.cpp +++ b/tests/client/convertertest.cpp @@ -251,6 +251,32 @@ private Q_SLOTS: QVERIFY(compare(value, (QVariant::Type) expectedType)); } + void testConvertToQVariantFromString_data() + { + QTest::addColumn("value"); + QTest::addColumn("expectedType"); + + QTest::newRow("Boolean") << "true" << (unsigned) QVariant::Bool; + QTest::newRow("Byte") << "byte 0xFF" << (unsigned) QMetaType::UChar; + QTest::newRow("Int16") << "int16 65" << (unsigned) QMetaType::Short; + QTest::newRow("UInt16") << "uint16 65" << (unsigned) QMetaType::UShort; + QTest::newRow("Int32") << "int32 65" << (unsigned) QVariant::Int; + QTest::newRow("UInt32") << "uint32 65" << (unsigned) QVariant::UInt; + QTest::newRow("Int64") << "int64 65" << (unsigned) QVariant::LongLong; + QTest::newRow("UInt64") << "uint64 65" << (unsigned) QVariant::ULongLong; + QTest::newRow("Double") << "double 65" << (unsigned) QVariant::Double; + QTest::newRow("String") << "string '65'" << (unsigned) QVariant::String; + QTest::newRow("String simple") << "\"65\"" << (unsigned) QVariant::String; + } + + void testConvertToQVariantFromString() + { + QFETCH(QString, value); + QFETCH(unsigned, expectedType); + + QCOMPARE(Converter::toQVariantFromVariantString(value).type(), (QVariant::Type) expectedType); + } + }; QTEST_MAIN(ConverterTest) -- cgit v1.2.3 From 3509321d765b02355e3e207050bb137b48eade44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Mon, 24 Oct 2016 21:21:48 +0200 Subject: Add conversion tests for maps and lists to QVariant --- tests/client/convertertest.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests') diff --git a/tests/client/convertertest.cpp b/tests/client/convertertest.cpp index fe72181..1a3bce8 100644 --- a/tests/client/convertertest.cpp +++ b/tests/client/convertertest.cpp @@ -241,6 +241,16 @@ 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; + + 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; + 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); } void testConvertToQVariant() @@ -267,6 +277,8 @@ 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("Map") << "{'foo': <65>}" << (unsigned) QVariant::Map; + QTest::newRow("List") << "[65, 66]" << (unsigned) QVariant::List; } void testConvertToQVariantFromString() -- cgit v1.2.3 From c314929116d21057b5fae27c4a929c75d17d6183 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 25 Oct 2016 13:37:07 +0200 Subject: ConverterTest: add checks for tuples and lists --- tests/client/convertertest.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/client/convertertest.cpp b/tests/client/convertertest.cpp index 1a3bce8..cd791c7 100644 --- a/tests/client/convertertest.cpp +++ b/tests/client/convertertest.cpp @@ -132,6 +132,7 @@ private Q_SLOTS: QTest::newRow("String") << QVariant(QString("42")) << QGVariantType(G_VARIANT_TYPE_STRING); QTest::newRow("ByteArray") << QVariant(QByteArray("42")) << QGVariantType(G_VARIANT_TYPE_BYTESTRING); QTest::newRow("Map") << QVariant(QVariantMap()) << QGVariantType(G_VARIANT_TYPE_VARDICT); + QTest::newRow("List") << QVariant(QVariantList()) << QGVariantType(G_VARIANT_TYPE_UNIT); } void testConvertToGVariant() @@ -241,6 +242,7 @@ 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("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))); @@ -279,6 +281,7 @@ private Q_SLOTS: QTest::newRow("String simple") << "\"65\"" << (unsigned) QVariant::String; QTest::newRow("Map") << "{'foo': <65>}" << (unsigned) QVariant::Map; QTest::newRow("List") << "[65, 66]" << (unsigned) QVariant::List; + QTest::newRow("Tuple") << "('foo', 65)" << (unsigned) QVariant::List; } void testConvertToQVariantFromString() -- cgit v1.2.3