Debian Codegraph @

tests/service-mocks/media-player-mpris-mock/main.cpp

raw
1 /*
2 * Copyright (C) 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Author: Xavi Garcia <[email protected]>
17 */
18 #include <QtDBus/QDBusConnection>
19 #include <QtDBus/QDBusConnectionInterface>
20
21 #include <string>
22
23 #include "MediaPlayerMprisDefs.h"
24 #include "MediaPlayerMprisMock.h"
25 #include "MediaPlayerMprisMockAdaptor.h"
26 #include "MediaPlayer2MockAdaptor.h"
27
28 using namespace ayatana::indicators::testing;
29
30 int main(int argc, char *argv[])
31 {
32 if (argc != 2)
33 {
34 qWarning() << "usage: " << argv[0] << "TEST_PLAYER_NAME";
35 return 1;
36 }
37 QString playerName = QString(argv[1]);
38
39 QCoreApplication app(argc, argv);
40 QString playerService = QString("org.mpris.MediaPlayer2.") + playerName;
41 QDBusConnection connection = QDBusConnection::sessionBus();
42 if (!connection.interface()->isServiceRegistered(playerService))
43 {
44 auto service = new MediaPlayerMprisMock(playerName, &app);
45 new PlayerAdaptor(service);
46 new MediaPlayer2Adaptor(service);
47
48 if (!connection.registerService(playerService))
49 {
50 qDebug() << connection.lastError();
51 qFatal("Could not register MediaPlayerMprisMock service.");
52 }
53
54 if (!connection.registerObject("/org/mpris/MediaPlayer2", service))
55 {
56 qFatal("Could not register MediaPlayerMprisMock object.");
57 }
58 }
59 else
60 {
61 qDebug() << "Service is already registered!.";
62 }
63 return app.exec();
64 }