diff options
author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2016-10-20 16:06:30 +0200 |
---|---|---|
committer | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2016-10-20 16:06:30 +0200 |
commit | 6d2a0aac08c8536d735d4d7407cfe28b8c053149 (patch) | |
tree | 21b8b92f8e5e598b2b38157beb3d918f3da6560d /tests/client | |
parent | bba640d9c189be19d66c6294873b6ab8ffa4efc3 (diff) | |
download | qmenumodel-6d2a0aac08c8536d735d4d7407cfe28b8c053149.tar.gz qmenumodel-6d2a0aac08c8536d735d4d7407cfe28b8c053149.tar.bz2 qmenumodel-6d2a0aac08c8536d735d4d7407cfe28b8c053149.zip |
ActionGroupTest: add test for activateByVariantString
Diffstat (limited to 'tests/client')
-rw-r--r-- | tests/client/actiongrouptest.cpp | 128 |
1 files changed, 65 insertions, 63 deletions
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 <QtTest> #include <QDebug> -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<QString, QVariant> 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<QString, QVariant> 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" |