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 ApplicationController
31
MOCK_METHOD1(primaryPidForAppId, pid_t(const QString& appId));
32
MOCK_METHOD2(appIdHasProcessId, bool(pid_t, const QString&));
34
MOCK_METHOD1(stopApplicationWithAppId, bool(const QString&));
35
MOCK_METHOD2(startApplicationWithAppIdAndArgs, bool(const QString&, const QStringList&));
37
MockApplicationController()
39
using namespace ::testing;
40
ON_CALL(*this, primaryPidForAppId(_))
42
Invoke(this, &MockApplicationController::doPrimaryPidForAppId));
44
ON_CALL(*this, appIdHasProcessId(_, _))
46
Invoke(this, &MockApplicationController::doAppIdHasProcessId));
48
ON_CALL(*this, stopApplicationWithAppId(_))
50
Invoke(this, &MockApplicationController::doStopApplicationWithAppId));
52
ON_CALL(*this, startApplicationWithAppIdAndArgs(_, _))
54
Invoke(this, &MockApplicationController::doStartApplicationWithAppIdAndArgs));
57
pid_t doPrimaryPidForAppId(const QString& appId)
59
auto it = children.find(appId);
60
if (it == children.end())
66
bool doAppIdHasProcessId(pid_t pid, const QString& appId)
68
auto it = children.find(appId);
69
if (it == children.end())
72
return it->pid() == pid;
75
bool doStopApplicationWithAppId(const QString& appId)
82
bool doStartApplicationWithAppIdAndArgs(const QString& appId, const QStringList& args)
86
auto child = core::posix::fork([]()
90
return core::posix::exit::Status::success;
91
}, core::posix::StandardStream::empty);
95
children.insert(appId, child);
102
QMap<QString, core::posix::ChildProcess> children;
106
#endif // MOCK_APPLICATION_CONTROLLER_H