mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-31 03:27:40 +01:00
Add a really basic unit test for MPRIS1
This commit is contained in:
parent
e18409ebf4
commit
12da941885
@ -31,13 +31,27 @@
|
||||
|
||||
namespace mpris {
|
||||
|
||||
Mpris1::Mpris1(PlayerInterface* player, ArtLoader* art_loader, QObject* parent)
|
||||
: QObject(parent)
|
||||
const char* Mpris1::kDefaultDbusServiceName = "org.mpris.clementine";
|
||||
|
||||
Mpris1::Mpris1(PlayerInterface* player, ArtLoader* art_loader, QObject* parent,
|
||||
const QString& dbus_service_name)
|
||||
: QObject(parent),
|
||||
dbus_service_name_(dbus_service_name),
|
||||
root_(NULL),
|
||||
player_(NULL),
|
||||
tracklist_(NULL)
|
||||
{
|
||||
qDBusRegisterMetaType<DBusStatus>();
|
||||
qDBusRegisterMetaType<Version>();
|
||||
|
||||
QDBusConnection::sessionBus().registerService("org.mpris.clementine");
|
||||
if (dbus_service_name_.isEmpty()) {
|
||||
dbus_service_name_ = kDefaultDbusServiceName;
|
||||
}
|
||||
|
||||
if (!QDBusConnection::sessionBus().registerService(dbus_service_name_)) {
|
||||
qWarning() << "Failed to register" << dbus_service_name_ << "on the session bus";
|
||||
return;
|
||||
}
|
||||
|
||||
root_ = new Mpris1Root(player, this);
|
||||
player_ = new Mpris1Player(player, this);
|
||||
@ -47,6 +61,10 @@ Mpris1::Mpris1(PlayerInterface* player, ArtLoader* art_loader, QObject* parent)
|
||||
player_, SLOT(CurrentSongChanged(Song,QString)));
|
||||
}
|
||||
|
||||
Mpris1::~Mpris1() {
|
||||
QDBusConnection::sessionBus().unregisterService(dbus_service_name_);
|
||||
}
|
||||
|
||||
Mpris1Root::Mpris1Root(PlayerInterface* player, QObject* parent)
|
||||
: QObject(parent), player_(player) {
|
||||
new MprisRoot(this);
|
||||
|
@ -79,7 +79,9 @@ class Mpris1 : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Mpris1(PlayerInterface* player, ArtLoader* art_loader, QObject* parent = 0);
|
||||
Mpris1(PlayerInterface* player, ArtLoader* art_loader, QObject* parent = 0,
|
||||
const QString& dbus_service_name = QString());
|
||||
~Mpris1();
|
||||
|
||||
static QVariantMap GetMetadata(const Song& song);
|
||||
|
||||
@ -88,6 +90,10 @@ public:
|
||||
Mpris1TrackList* tracklist() const { return tracklist_; }
|
||||
|
||||
private:
|
||||
static const char* kDefaultDbusServiceName;
|
||||
|
||||
QString dbus_service_name_;
|
||||
|
||||
Mpris1Root* root_;
|
||||
Mpris1Player* player_;
|
||||
Mpris1TrackList* tracklist_;
|
||||
|
@ -42,6 +42,7 @@ set(TESTUTILS-SOURCES
|
||||
test_utils.cpp
|
||||
mock_networkaccessmanager.cpp
|
||||
mock_taglib.cpp
|
||||
mock_player.cpp
|
||||
mock_playlistitem.cpp
|
||||
)
|
||||
|
||||
@ -114,6 +115,7 @@ add_test_file(organiseformat_test.cpp false)
|
||||
add_test_file(playlist_test.cpp true)
|
||||
add_test_file(plsparser_test.cpp false)
|
||||
add_test_file(python_test.cpp true)
|
||||
add_test_file(mpris1_test.cpp false)
|
||||
add_test_file(scopedtransaction_test.cpp false)
|
||||
add_test_file(songloader_test.cpp false)
|
||||
add_test_file(songplaylistitem_test.cpp false)
|
||||
|
5
tests/mock_player.cpp
Normal file
5
tests/mock_player.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
#include "mock_player.h"
|
||||
|
||||
MockPlayer::MockPlayer()
|
||||
{
|
||||
}
|
64
tests/mock_player.h
Normal file
64
tests/mock_player.h
Normal file
@ -0,0 +1,64 @@
|
||||
/* This file is part of Clementine.
|
||||
Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
|
||||
Clementine 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MOCK_PLAYER_H
|
||||
#define MOCK_PLAYER_H
|
||||
|
||||
#include "core/player.h"
|
||||
#include "core/song.h"
|
||||
#include "core/settingsprovider.h"
|
||||
#include "library/sqlrow.h"
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
class MockPlayer : public PlayerInterface {
|
||||
public:
|
||||
MockPlayer();
|
||||
|
||||
MOCK_CONST_METHOD0(engine, EngineBase*());
|
||||
MOCK_CONST_METHOD0(GetState, Engine::State());
|
||||
MOCK_CONST_METHOD0(GetVolume, int());
|
||||
|
||||
MOCK_CONST_METHOD0(GetCurrentItem, PlaylistItemPtr());
|
||||
MOCK_CONST_METHOD1(GetItemAt, PlaylistItemPtr(int));
|
||||
MOCK_CONST_METHOD0(playlists, PlaylistManager*());
|
||||
|
||||
MOCK_METHOD0(ReloadSettings, void());
|
||||
|
||||
MOCK_METHOD3(PlayAt, void(int, Engine::TrackChangeType, bool));
|
||||
MOCK_METHOD0(PlayPause, void());
|
||||
|
||||
MOCK_METHOD0(Next, void());
|
||||
|
||||
MOCK_METHOD0(Previous, void());
|
||||
MOCK_METHOD1(SetVolume, void(int));
|
||||
MOCK_METHOD0(VolumeUp, void());
|
||||
MOCK_METHOD0(VolumeDown, void());
|
||||
MOCK_METHOD1(SeekTo, void(int));
|
||||
MOCK_METHOD0(SeekForward, void());
|
||||
MOCK_METHOD0(SeekBackward, void());
|
||||
MOCK_METHOD1(HandleSpecialLoad, void(const PlaylistItem::SpecialLoadResult&));
|
||||
MOCK_METHOD1(CurrentMetadataChanged, void(const Song&));
|
||||
|
||||
MOCK_METHOD0(Mute, void());
|
||||
MOCK_METHOD0(Pause, void());
|
||||
MOCK_METHOD0(Stop, void());
|
||||
MOCK_METHOD0(Play, void());
|
||||
MOCK_METHOD0(ShowOSD, void());
|
||||
};
|
||||
|
||||
#endif // MOCK_PLAYER_H
|
68
tests/mpris1_test.cpp
Normal file
68
tests/mpris1_test.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
/* This file is part of Clementine.
|
||||
Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
|
||||
Clementine 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "core/encoding.h"
|
||||
#include "core/mpris1.h"
|
||||
#include "core/song.h"
|
||||
#include "radio/fixlastfm.h"
|
||||
#include <lastfm/Track>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "test_utils.h"
|
||||
#include "mock_player.h"
|
||||
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusConnectionInterface>
|
||||
#include <QTemporaryFile>
|
||||
#include <QTextCodec>
|
||||
|
||||
#include <id3v2tag.h>
|
||||
|
||||
namespace {
|
||||
|
||||
class Mpris1Test : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() {
|
||||
}
|
||||
|
||||
QString service_name() const {
|
||||
return "org.clementine.unittest" +
|
||||
QString::number(QCoreApplication::applicationPid());
|
||||
}
|
||||
|
||||
MockPlayer player_;
|
||||
};
|
||||
|
||||
|
||||
TEST_F(Mpris1Test, CreatesDBusService) {
|
||||
EXPECT_FALSE(QDBusConnection::sessionBus().interface()->
|
||||
isServiceRegistered(service_name()));
|
||||
|
||||
boost::scoped_ptr<mpris::Mpris1> mpris(
|
||||
new mpris::Mpris1(&player_, NULL, NULL, service_name()));
|
||||
EXPECT_TRUE(QDBusConnection::sessionBus().interface()->
|
||||
isServiceRegistered(service_name()));
|
||||
|
||||
mpris.reset();
|
||||
EXPECT_FALSE(QDBusConnection::sessionBus().interface()->
|
||||
isServiceRegistered(service_name()));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
Loading…
x
Reference in New Issue
Block a user