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