on daa5708 help sign in
unity8/tests/mocks/Unity/Application/ApplicationTestInterface.cpp
117 lines 4.0 kB history raw
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17#include "ApplicationInfo.h"
18#include "ApplicationTestInterface.h"
19#include "ApplicationManager.h"
20#include "SessionManager.h"
21#include "SurfaceManager.h"
22#include "Session.h"
23#include "MirSurfaceItem.h"
25#include <paths.h>
27#include <QtDBus/QtDBus>
29quint32 nextId = 0;
31ApplicationTestInterface::ApplicationTestInterface(QObject* parent)
32 : QDBusAbstractAdaptor(parent)
34 QDBusConnection connection = QDBusConnection::sessionBus();
35 connection.registerService("com.canonical.Unity8");
36 connection.registerObject("/com/canonical/Unity8/Mocks", parent);
39Session* ApplicationTestInterface::addChildSession(Session* existingSession, const QString& surfaceImage)
41 if (!existingSession) return nullptr;
43 QUrl screenshotUrl = QString("file://%1/Dash/graphics/phone/screenshots/%2@12.png")
44 .arg(qmlDirectory())
45 .arg(surfaceImage);
47 Session* session = SessionManager::singleton()->createSession(
48 QString("%1-Child%2").arg(existingSession->name())
49 .arg(existingSession->childSessions()->count()),
50 screenshotUrl);
51 existingSession->addChildSession(session);
52 session->createSurface();
54 return session;
57void ApplicationTestInterface::removeSession(Session* existingSession)
59 qDebug() << "ApplicationTestInterface::removeSession - " << existingSession;
61 if (existingSession)
62 existingSession->setLive(false);
65void ApplicationTestInterface::removeSurface(MirSurfaceItem* existingSurface)
67 qDebug() << "ApplicationTestInterface::removeSurface - " << existingSurface;
69 if (existingSurface)
70 existingSurface->setLive(false);
73quint32 ApplicationTestInterface::addChildSession(const QString& appId, quint32 existingSessionId, const QString& surfaceImage)
75 qDebug() << "ApplicationTestInterface::addChildSession to " << appId;
77 ApplicationInfo* application = ApplicationManager::singleton()->findApplication(appId);
78 if (!application) {
79 qDebug() << "ApplicationTestInterface::addChildSession - No application found for " << appId;
80 return 0;
81 }
83 Session* parentSession = nullptr;
84 if (m_childSessions.contains(existingSessionId)) {
85 parentSession = m_childSessions[existingSessionId];
86 } else if (application->session()) {
87 parentSession = application->session();
88 } else {
89 qDebug() << "ApplicationTestInterface::addChildSession - No session for " << appId << ":" << existingSessionId;
90 return 0;
91 }
93 QUrl screenshotUrl = QString("file://%1/Dash/graphics/phone/screenshots/%2@12.png")
94 .arg(qmlDirectory())
95 .arg(surfaceImage);
97 quint32 sessionId = ++nextId;
98 Session* session = SessionManager::singleton()->createSession(
99 QString("%1-Child%2").arg(parentSession->name())
100 .arg(parentSession->childSessions()->count()),
101 screenshotUrl);
102 parentSession->addChildSession(session);
103 session->createSurface();
104 m_childSessions[sessionId] = session;
106 return sessionId;
109void ApplicationTestInterface::removeSession(quint32 sessionId)
111 if (!m_childSessions.contains(sessionId)) {
112 qDebug() << "ApplicationTestInterface::removeSession - No added session for " << sessionId;
113 return;
114 }
115 Session* session = m_childSessions.take(sessionId);
116 removeSession(session);