~mterry/unity-scope-click/snap-root

« back to all changes in this revision

Viewing changes to libclickscope/tests/mock_ual.h

  • Committer: Bileto Bot
  • Author(s): Rodney Dawes
  • Date: 2016-09-22 15:31:55 UTC
  • mfrom: (465.2.18 ual-apps)
  • Revision ID: ci-train-bot@canonical.com-20160922153155-ldrge17jk6anr2hl
Switch to UAL and libclick for listing installed apps. (LP: #1317274)

Approved by: Charles Kerr, unity-api-1-bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2016 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
 * In addition, as a special exception, the copyright holders give
 
17
 * permission to link the code of portions of this program with the
 
18
 * OpenSSL library under certain conditions as described in each
 
19
 * individual source file, and distribute linked combinations
 
20
 * including the two.
 
21
 * You must obey the GNU General Public License in all respects
 
22
 * for all of the code used other than OpenSSL.  If you modify
 
23
 * file(s) with this exception, you may extend this exception to your
 
24
 * version of the file(s), but you are not obligated to do so.  If you
 
25
 * do not wish to do so, delete this exception statement from your
 
26
 * version.  If you delete this exception statement from all source
 
27
 * files in the program, then also delete it here.
 
28
 */
 
29
 
 
30
#include <ubuntu-app-launch/registry.h>
 
31
 
 
32
namespace ual = ubuntu::app_launch;
 
33
 
 
34
#include <gtest/gtest.h>
 
35
#include <gmock/gmock.h>
 
36
 
 
37
using namespace ::testing;
 
38
 
 
39
namespace
 
40
{
 
41
 
 
42
    class MockUALRegistry : public ual::Registry {
 
43
    public:
 
44
        MockUALRegistry()
 
45
        {
 
46
        }
 
47
 
 
48
        MOCK_METHOD1(installedApps, std::list<std::shared_ptr<ual::Application>>(std::shared_ptr<ual::Registry>));
 
49
    };
 
50
 
 
51
    class MockUALApplication : public ual::Application {
 
52
    public:
 
53
        class MockInfo;
 
54
        class MockInstance;
 
55
 
 
56
        MockUALApplication(const ual::AppID& app_id,
 
57
                           const std::shared_ptr<MockInfo>& info = {})
 
58
            : m_app_id(app_id),
 
59
              m_info(info)
 
60
        {
 
61
        }
 
62
 
 
63
        ual::AppID appId()
 
64
        {
 
65
            return m_app_id;
 
66
        }
 
67
 
 
68
        std::shared_ptr<ual::Application::Info> info()
 
69
        {
 
70
            return m_info;
 
71
        }
 
72
 
 
73
        static std::shared_ptr<MockUALApplication> create(ual::AppID app_id,
 
74
                                                          std::shared_ptr<MockInfo> info = {})
 
75
        {
 
76
            std::shared_ptr<MockUALApplication> result{new MockUALApplication(app_id, info)};
 
77
            return result;
 
78
        }
 
79
 
 
80
        class MockInfo : public ual::Application::Info
 
81
        {
 
82
        public:
 
83
            MockInfo(const std::string& title,
 
84
                     const std::string& description,
 
85
                     const std::string& iconPath)
 
86
                : m_name(ual::Application::Info::Name::from_raw(title)),
 
87
                m_description(ual::Application::Info::Description::from_raw(description)),
 
88
                m_iconPath(ual::Application::Info::IconPath::from_raw(iconPath)),
 
89
                m_defaultDept(ual::Application::Info::DefaultDepartment::from_raw("")),
 
90
                m_ssPath(ual::Application::Info::IconPath::from_raw("")),
 
91
                m_keywords(ual::Application::Info::Keywords::from_raw(std::vector<std::string>{}))
 
92
            {
 
93
                DefaultValue<const ual::Application::Info::DefaultDepartment&>::Set(m_defaultDept);
 
94
                DefaultValue<const ual::Application::Info::IconPath&>::Set(m_ssPath);
 
95
                DefaultValue<const ual::Application::Info::Keywords&>::Set(m_keywords);
 
96
            }
 
97
 
 
98
            const ual::Application::Info::Name& name()
 
99
            {
 
100
                return m_name;
 
101
            }
 
102
 
 
103
            const ual::Application::Info::Description& description()
 
104
            {
 
105
                return m_description;
 
106
            }
 
107
 
 
108
            const ual::Application::Info::IconPath& iconPath()
 
109
            {
 
110
                return m_iconPath;
 
111
            }
 
112
 
 
113
            MOCK_METHOD0(defaultDepartment, const ual::Application::Info::DefaultDepartment&());
 
114
            MOCK_METHOD0(screenshotPath, const ual::Application::Info::IconPath&());
 
115
            MOCK_METHOD0(keywords, const ual::Application::Info::Keywords&());
 
116
 
 
117
            MOCK_METHOD0(splash, ual::Application::Info::Splash());
 
118
            MOCK_METHOD0(supportedOrientations, ual::Application::Info::Orientations());
 
119
            MOCK_METHOD0(rotatesWindowContents, ual::Application::Info::RotatesWindow());
 
120
            MOCK_METHOD0(supportsUbuntuLifecycle, ual::Application::Info::UbuntuLifecycle());
 
121
 
 
122
        private:
 
123
            ual::Application::Info::Name m_name;
 
124
            ual::Application::Info::Description m_description;
 
125
            ual::Application::Info::IconPath m_iconPath;
 
126
            ual::Application::Info::DefaultDepartment m_defaultDept;
 
127
            ual::Application::Info::IconPath m_ssPath;
 
128
            ual::Application::Info::Keywords m_keywords;
 
129
        };
 
130
 
 
131
        class MockInstance : public ual::Application::Instance
 
132
        {
 
133
        public:
 
134
            MOCK_METHOD0(isRunning, bool());
 
135
            MOCK_METHOD0(logPath, std::string());
 
136
            MOCK_METHOD0(primaryPid, pid_t());
 
137
            MOCK_METHOD1(hasPid, bool(pid_t));
 
138
            MOCK_METHOD0(pids, std::vector<pid_t>());
 
139
            MOCK_METHOD0(pause, void());
 
140
            MOCK_METHOD0(resume, void());
 
141
            MOCK_METHOD0(stop, void());
 
142
        };
 
143
 
 
144
        MOCK_METHOD0(hasInstances, bool());
 
145
        MOCK_METHOD0(instances, std::vector<std::shared_ptr<ual::Application::Instance>>());
 
146
        MOCK_METHOD1(launch, std::shared_ptr<ual::Application::Instance>(const std::vector<ual::Application::URL>&));
 
147
        MOCK_METHOD1(launchTest, std::shared_ptr<ual::Application::Instance>(const std::vector<ual::Application::URL>&));
 
148
 
 
149
    private:
 
150
        ual::AppID m_app_id;
 
151
        std::shared_ptr<MockInfo> m_info;
 
152
    };
 
153
 
 
154
} // namespace
 
155