2
* Copyright (C) 2013 Canonical, Ltd.
4
* This program is free software: you can redistribute it and/or modify it under
5
* the terms of the GNU Lesser General Public License version 3, as published by
6
* the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but WITHOUT
9
* ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10
* SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
* Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
#ifndef MOCK_APPLICATION_CONTROLLER_H
19
#define MOCK_APPLICATION_CONTROLLER_H
21
#include <Unity/Application/applicationcontroller.h>
23
#include <core/posix/fork.h>
25
#include <gmock/gmock.h>
29
struct MockApplicationController : public qtmir::ApplicationController
31
MOCK_METHOD1(primaryPidForAppId, pid_t(const QString& appId));
32
MOCK_METHOD2(appIdHasProcessId, bool(pid_t, const QString&));
33
MOCK_CONST_METHOD1(findDesktopFileForAppId, QFileInfo(const QString &appId));
35
MOCK_METHOD1(stopApplicationWithAppId, bool(const QString&));
36
MOCK_METHOD2(startApplicationWithAppIdAndArgs, bool(const QString&, const QStringList&));
38
MockApplicationController()
40
using namespace ::testing;
41
ON_CALL(*this, primaryPidForAppId(_))
43
Invoke(this, &MockApplicationController::doPrimaryPidForAppId));
45
ON_CALL(*this, appIdHasProcessId(_, _))
47
Invoke(this, &MockApplicationController::doAppIdHasProcessId));
49
ON_CALL(*this, findDesktopFileForAppId(_))
51
Invoke(this, &MockApplicationController::doFindDesktopFileForAppId));
53
ON_CALL(*this, stopApplicationWithAppId(_))
55
Invoke(this, &MockApplicationController::doStopApplicationWithAppId));
57
ON_CALL(*this, startApplicationWithAppIdAndArgs(_, _))
59
Invoke(this, &MockApplicationController::doStartApplicationWithAppIdAndArgs));
62
pid_t doPrimaryPidForAppId(const QString& appId)
64
auto it = children.find(appId);
65
if (it == children.end())
71
bool doAppIdHasProcessId(pid_t pid, const QString& appId)
73
auto it = children.find(appId);
74
if (it == children.end())
77
return it->pid() == pid;
80
QFileInfo doFindDesktopFileForAppId(const QString& appId) const
82
QString path = QString("/usr/share/applications/%1.desktop").arg(appId);
83
return QFileInfo(path);
86
bool doStopApplicationWithAppId(const QString& appId)
93
bool doStartApplicationWithAppIdAndArgs(const QString& appId, const QStringList& args)
97
auto child = core::posix::fork([]()
101
return core::posix::exit::Status::success;
102
}, core::posix::StandardStream::empty);
106
children.insert(appId, child);
113
QMap<QString, core::posix::ChildProcess> children;
115
} // namespace testing
117
#endif // MOCK_APPLICATION_CONTROLLER_H