~alan-griffiths/miral/fix-1645284

« back to all changes in this revision

Viewing changes to miral-qt/tests/framework/mock_task_controller.cpp

  • Committer: Alan Griffiths
  • Date: 2016-11-07 17:59:19 UTC
  • mfrom: (436.1.1 miral2)
  • Revision ID: alan@octopull.co.uk-20161107175919-stbb64i7j1htgog2
[miral-qt] delete all as qtmir work on MirAL has shifted to lp:~unity-team/qtmir/miral-qt-integration and this is a needless distration

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2015 Canonical, Ltd.
3
 
 *
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.
7
 
 *
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.
12
 
 *
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/>.
15
 
 */
16
 
 
17
 
#include "mock_application_info.h"
18
 
#include "mock_task_controller.h"
19
 
 
20
 
namespace qtmir
21
 
{
22
 
 
23
 
MockTaskController::MockTaskController()
24
 
{
25
 
    using namespace ::testing;
26
 
 
27
 
    ON_CALL(*this, appIdHasProcessId(_, _))
28
 
            .WillByDefault(
29
 
                Invoke(this, &MockTaskController::doAppIdHasProcessId));
30
 
 
31
 
    ON_CALL(*this, getInfoForApp(_))
32
 
            .WillByDefault(
33
 
                Invoke(this, &MockTaskController::doGetInfoForApp));
34
 
 
35
 
    ON_CALL(*this, stop(_))
36
 
            .WillByDefault(
37
 
                Invoke(this, &MockTaskController::doStop));
38
 
 
39
 
    ON_CALL(*this, start(_, _))
40
 
            .WillByDefault(
41
 
                Invoke(this, &MockTaskController::doStart));
42
 
 
43
 
    ON_CALL(*this, suspend(_))
44
 
            .WillByDefault(
45
 
                Invoke(this, &MockTaskController::doSuspend));
46
 
 
47
 
    ON_CALL(*this, resume(_))
48
 
            .WillByDefault(
49
 
                Invoke(this, &MockTaskController::doResume));
50
 
}
51
 
 
52
 
MockTaskController::~MockTaskController()
53
 
{
54
 
 
55
 
}
56
 
 
57
 
 
58
 
bool MockTaskController::doAppIdHasProcessId(const QString &appId, pid_t pid)
59
 
{
60
 
    auto it = children.find(appId);
61
 
    if (it == children.end())
62
 
        return false;
63
 
 
64
 
    return it->pid() == pid;
65
 
}
66
 
 
67
 
 
68
 
QSharedPointer<qtmir::ApplicationInfo> MockTaskController::doGetInfoForApp(const QString& appId) const
69
 
{
70
 
    return QSharedPointer<qtmir::ApplicationInfo>(new testing::NiceMock<MockApplicationInfo>(appId));
71
 
}
72
 
 
73
 
 
74
 
bool MockTaskController::doStop(const QString &appId)
75
 
{
76
 
    Q_UNUSED(appId);
77
 
 
78
 
    return false;
79
 
}
80
 
 
81
 
 
82
 
bool MockTaskController::doStart(const QString &appId, const QStringList &args)
83
 
{
84
 
    Q_UNUSED(args);
85
 
 
86
 
    auto child = core::posix::fork([]()
87
 
    {
88
 
        while (true);
89
 
 
90
 
        return core::posix::exit::Status::success;
91
 
    }, core::posix::StandardStream::empty);
92
 
 
93
 
    if (child.pid() > 0)
94
 
    {
95
 
        children.insert(appId, child);
96
 
        return true;
97
 
    }
98
 
 
99
 
    return false;
100
 
}
101
 
 
102
 
 
103
 
bool MockTaskController::doSuspend(const QString &appId)
104
 
{
105
 
    Q_UNUSED(appId);
106
 
 
107
 
    return false;
108
 
}
109
 
 
110
 
bool MockTaskController::doResume(const QString &appId)
111
 
{
112
 
    Q_UNUSED(appId);
113
 
 
114
 
    return false;
115
 
}
116
 
 
117
 
} // namespace qtmir