[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [knotifications] tests: Add a manual test for Unity launchers
From:       Kai Uwe Broulik <null () kde ! org>
Date:       2016-12-31 12:56:01
Message-ID: E1cNJCb-0001X6-Rb () code ! kde ! org
[Download RAW message or body]

Git commit ed01d6958ebe2fed63e7ff9ea9d51e083c3bcda0 by Kai Uwe Broulik.
Committed on 31/12/2016 at 12:54.
Pushed by broulik into branch 'master'.

Add a manual test for Unity launchers

This utility allows to test and simulate unity launchers since dbus-send cannot handle
"variant maps" (a{sv}) required by this API.

    unitylaunchertest org.kde.dolphin --progress 50
    unitylaunchertest org.kde.kwrite --count 3
    unitylaunchertest org.kde.konsole --urgent

Differential Revision: https://phabricator.kde.org/D3821

M  +1    -0    tests/CMakeLists.txt
A  +91   -0    tests/unitylaunchertest.cpp     [License: LGPL (v2+)]

https://commits.kde.org/knotifications/ed01d6958ebe2fed63e7ff9ea9d51e083c3bcda0

diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 295ca24..eac110a 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -19,6 +19,7 @@ endmacro()
 knotifications_executable_tests(
     knotificationrestrictionstest
     kpassivepopuptest
+    unitylaunchertest
     kstatusnotifieritemtest
     knotificationdbustest
 )
diff --git a/tests/unitylaunchertest.cpp b/tests/unitylaunchertest.cpp
new file mode 100644
index 0000000..aa1cf66
--- /dev/null
+++ b/tests/unitylaunchertest.cpp
@@ -0,0 +1,91 @@
+/*
+    Copyright 2016 Kai Uwe Broulik <kde@privat.broulik.de>
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library 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
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+*/
+
+#include <QCoreApplication>
+#include <QCommandLineParser>
+#include <QDBusConnection>
+#include <QDBusMessage>
+#include <QTimer>
+
+#include <QDebug>
+
+int main(int argc, char *argv[])
+{
+    QCoreApplication app(argc, argv);
+
+    QCommandLineParser parser;
+    parser.addHelpOption();
+    parser.addVersionOption();
+
+    // for simplicity we'll just send along progress-visible true whenever progress is set and otherwise \
false +    QCommandLineOption progressOption(QStringLiteral("progress"), QStringLiteral("Show progress, \
0-100"), QStringLiteral("progress")); +    parser.addOption(progressOption);
+    // same for count
+    QCommandLineOption countOption(QStringLiteral("count"), QStringLiteral("Show count badge, number"), \
QStringLiteral("count")); +    parser.addOption(countOption);
+
+    QCommandLineOption urgentOption(QStringLiteral("urgent"), QStringLiteral("Set urgent hint, flash \
task bar entry")); +    parser.addOption(urgentOption);
+
+    parser.addPositionalArgument(QStringLiteral("desktop-filename"), QStringLiteral("Desktop file name \
for the application")); +
+    parser.process(app);
+
+    if (parser.positionalArguments().count() != 1) {
+        parser.showHelp(1); // never returns
+    }
+
+    QString launcherId = parser.positionalArguments().constFirst();
+    if (!launcherId.startsWith(QLatin1String("application://"))) {
+        launcherId.prepend(QLatin1String("application://"));
+    }
+    if (!launcherId.endsWith(QLatin1String(".desktop"))) {
+        launcherId.append(QLatin1String(".desktop"));
+    }
+
+    QVariantMap properties;
+
+    if (parser.isSet(progressOption)) {
+        properties.insert(QStringLiteral("progress"), parser.value(progressOption).toInt() / 100.0);
+        properties.insert(QStringLiteral("progress-visible"), true);
+    } else {
+        properties.insert(QStringLiteral("progress-visible"), false);
+    }
+
+    if (parser.isSet(countOption)) {
+        properties.insert(QStringLiteral("count"), parser.value(countOption).toInt());
+        properties.insert(QStringLiteral("count-visible"), true);
+    } else {
+        properties.insert(QStringLiteral("count-visible"), false);
+    }
+
+    properties.insert(QStringLiteral("urgent"), parser.isSet(urgentOption));
+
+    QDBusMessage message = \
QDBusMessage::createSignal(QStringLiteral("/org/knotifications/UnityLauncherTest"), +                     \
QStringLiteral("com.canonical.Unity.LauncherEntry"), +                                                    \
QStringLiteral("Update")); +    message.setArguments({launcherId, properties});
+    QDBusConnection::sessionBus().send(message);
+
+    // FIXME can we detect that the message was sent to the bus?
+    QTimer::singleShot(500, &app, QCoreApplication::quit);
+
+    return app.exec();
+}
+


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic