diff options
author | Alex Merry <dev@randomguy3.me.uk> | 2011-11-01 15:05:43 +0000 |
---|---|---|
committer | Alex Merry <dev@randomguy3.me.uk> | 2011-11-01 15:05:43 +0000 |
commit | a3031aea445a095c14c772e383e088b35c2be707 (patch) | |
tree | e6d851cc4683ec6ea1e6bc9860aef2b07938b33c | |
parent | d1dcef6bf53f3a00a17be0d067f14ddbe5d16b32 (diff) |
Start on implementation of Player interface tester
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | mpris2/playerinterfacetest.cpp | 120 | ||||
-rw-r--r-- | mpris2/playerinterfacetest.h | 46 |
3 files changed, 168 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b32709..bbdd637 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ set (mpristester_SRCS mpris2/interfacetest.cpp mpris2/rootinterfacetest.cpp mpris2/roottestwidget.cpp + mpris2/playerinterfacetest.cpp mpris2/testconsole.cpp ) qt4_wrap_cpp (mpristester_SRCS @@ -21,6 +22,7 @@ qt4_wrap_cpp (mpristester_SRCS mpris2/interfacetest.h mpris2/rootinterfacetest.h mpris2/roottestwidget.h + mpris2/playerinterfacetest.h mpris2/testconsole.h ) qt4_wrap_ui (mpristester_SRCS diff --git a/mpris2/playerinterfacetest.cpp b/mpris2/playerinterfacetest.cpp new file mode 100644 index 0000000..8d9949d --- /dev/null +++ b/mpris2/playerinterfacetest.cpp @@ -0,0 +1,120 @@ +/* + * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + + +#include "playerinterfacetest.h" + +#include <QDBusInterface> +#include <QDBusMessage> +#include <QDBusReply> + +#define MPRIS2_PLAYER_IFACE "org.mpris.MediaPlayer2.Player" + +using namespace Mpris2; + +PlayerInterfaceTest::PlayerInterfaceTest(const QString& service, QObject* parent) + : InterfaceTest(MPRIS2_PLAYER_IFACE, service, parent) +{ +} + +PlayerInterfaceTest::~PlayerInterfaceTest() +{ +} + +void PlayerInterfaceTest::checkUpdatedProperty(const QString& propName) +{ + +} + +void PlayerInterfaceTest::checkProps(const QVariantMap& oldProps) +{ + checkPropValid("CanControl", QVariant::Bool, oldProps); + checkControlProp("CanGoNext", oldProps); + checkControlProp("CanGoPrevious", oldProps); + checkControlProp("CanPlay", oldProps); + checkControlProp("CanPause", oldProps); + checkControlProp("CanSeek", oldProps); + if (properties().contains("Shuffle")) { + checkPropValid("Shuffle", QVariant::Bool, oldProps); + } else { + emit interfaceInfo(Property, "Shuffle", + "Optional property not implemented"); + } + checkVolume(oldProps); + checkPlaybackStatus(oldProps); + if (properties().contains("LoopStatus")) { + checkLoopStatus(oldProps); + } else { + emit interfaceInfo(Property, "LoopStatus", + "Optional property not implemented"); + } +} + +void PlayerInterfaceTest::checkControlProp(const QString& propName, const QVariantMap& oldProps) +{ + if (!checkPropValid(propName, QVariant::Bool, oldProps)) + return; + bool canControl = properties().value("CanControl").toBool(); + if (!canControl && properties().value(propName).toBool()) { + emit interfaceError(Property, propName, + "Value is true when CanControl is false"); + } +} + +void PlayerInterfaceTest::checkVolume(const QVariantMap& oldProps) +{ + if (!checkPropValid("Volume", QVariant::Double, oldProps)) + return; + if (properties().value("Volume").toDouble() < 0.0) { + emit interfaceError(Property, "Volume", + "Volume cannot be negative"); + } + if (properties().value("Volume").toDouble() > 1.0) { + emit interfaceWarning(Property, "Volume", + "Volume is greater than 1.0"); + } +} + +void PlayerInterfaceTest::checkLoopStatus(const QVariantMap& oldProps) +{ + if (!properties().contains("LoopStatus")) + return; + if (!checkPropValid("LoopStatus", QVariant::String, oldProps)) + return; + QString loopStatus = properties().value("LoopStatus").toString(); + if (loopStatus != "None" && + loopStatus != "Track" && + loopStatus != "Playlist") + { + emit interfaceError(Property, "LoopStatus", + "Invalid value: '" + loopStatus + "'"); + } +} + +void PlayerInterfaceTest::checkPlaybackStatus(const QVariantMap& oldProps) +{ + if (!checkPropValid("PlaybackStatus", QVariant::String, oldProps)) + return; + QString playbackStatus = properties().value("PlaybackStatus").toString(); + if (playbackStatus != "None" && + playbackStatus != "Track" && + playbackStatus != "Playlist") + { + emit interfaceError(Property, "PlaybackStatus", + "Invalid value: '" + playbackStatus + "'"); + } +} diff --git a/mpris2/playerinterfacetest.h b/mpris2/playerinterfacetest.h new file mode 100644 index 0000000..900e72d --- /dev/null +++ b/mpris2/playerinterfacetest.h @@ -0,0 +1,46 @@ +/* + * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef MPRIS2_PLAYERINTERFACETEST_H +#define MPRIS2_PLAYERINTERFACETEST_H + +#include <../../home/alex/src/mpristester/mpris2/interfacetest.h> + + +namespace Mpris2 { + class PlayerInterfaceTest : public InterfaceTest + { + Q_OBJECT + + public: + PlayerInterfaceTest(const QString& service, QObject* parent = 0); + virtual ~PlayerInterfaceTest(); + + protected: + virtual void checkUpdatedProperty(const QString& propName); + virtual void checkProps(const QVariantMap& oldProps = QVariantMap()); + + private: + void checkControlProp(const QString& propName, const QVariantMap& oldProps = QVariantMap()); + void checkVolume(const QVariantMap& oldProps = QVariantMap()); + void checkLoopStatus(const QVariantMap& oldProps = QVariantMap()); + void checkPlaybackStatus(const QVariantMap& oldProps = QVariantMap()); + }; +} + +#endif // MPRIS2_PLAYERINTERFACETEST_H |