~lukas-kde/miral/shellchrome-windowinfo

« back to all changes in this revision

Viewing changes to miral-qt/tests/mirserver/ScreensModel/stub_display.h

  • Committer: Larry Price
  • Date: 2016-09-13 16:19:29 UTC
  • mto: (330.4.1 miral)
  • mto: This revision was merged to the branch mainline in revision 352.
  • Revision ID: larry.price@canonical.com-20160913161929-vs9ka1capmljq1es
Removing miral-qt from release branch, updating copyright file, and adding GPL3 license to root dir

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
 
#ifndef STUB_DISPLAY_H
18
 
#define STUB_DISPLAY_H
19
 
 
20
 
#include "mock_display.h"
21
 
#include "mock_gl_display_buffer.h"
22
 
#include "mock_display_configuration.h"
23
 
 
24
 
#include <mir/compositor/display_listener.h>
25
 
 
26
 
namespace mg = mir::graphics;
27
 
namespace geom = mir::geometry;
28
 
 
29
 
class StubDisplayConfiguration : public MockDisplayConfiguration
30
 
{
31
 
public:
32
 
    StubDisplayConfiguration(const std::vector<mg::DisplayConfigurationOutput> &config)
33
 
        : m_config(config)
34
 
    {}
35
 
 
36
 
    void for_each_output(std::function<void(mg::DisplayConfigurationOutput const&)> f) const override
37
 
    {
38
 
        for (auto config : m_config) {
39
 
            f(config);
40
 
        }
41
 
    }
42
 
 
43
 
    
44
 
    std::unique_ptr<mg::DisplayConfiguration> clone() const override
45
 
    {
46
 
        return std::make_unique<MockDisplayConfiguration>();
47
 
    }
48
 
 
49
 
private:
50
 
    const std::vector<mg::DisplayConfigurationOutput> m_config;
51
 
};
52
 
 
53
 
 
54
 
class StubDisplaySyncGroup : public MockDisplaySyncGroup
55
 
{
56
 
public:
57
 
    StubDisplaySyncGroup(MockGLDisplayBuffer *buffer) : buffer(buffer) {}
58
 
 
59
 
    void for_each_display_buffer(std::function<void(mg::DisplayBuffer&)> const& f) override
60
 
    {
61
 
        f(*buffer);
62
 
    }
63
 
    std::chrono::milliseconds recommended_sleep() const override
64
 
    {
65
 
        std::chrono::milliseconds one{1};
66
 
        return one;
67
 
    }
68
 
private:
69
 
    MockGLDisplayBuffer *buffer;
70
 
};
71
 
 
72
 
 
73
 
class StubDisplay : public MockDisplay
74
 
{
75
 
public:
76
 
    // Note, GMock cannot mock functions which return non-copyable objects, so stubbing needed
77
 
    std::unique_ptr<mg::DisplayConfiguration> configuration() const override
78
 
    {
79
 
        return std::unique_ptr<mg::DisplayConfiguration>(
80
 
            new StubDisplayConfiguration(m_config)
81
 
        );
82
 
    }
83
 
 
84
 
    void for_each_display_sync_group(std::function<void(mg::DisplaySyncGroup&)> const& f) override
85
 
    {
86
 
        for (auto displayBuffer : m_displayBuffers) {
87
 
            StubDisplaySyncGroup b(displayBuffer);
88
 
            f(b);
89
 
        }
90
 
    }
91
 
 
92
 
    void setFakeConfiguration(std::vector<mg::DisplayConfigurationOutput> &config,
93
 
                              std::vector<MockGLDisplayBuffer*> &displayBuffers)
94
 
    {
95
 
        m_config = config;
96
 
        m_displayBuffers = displayBuffers;
97
 
    }
98
 
 
99
 
private:
100
 
    std::vector<mg::DisplayConfigurationOutput> m_config;
101
 
    std::vector<MockGLDisplayBuffer*> m_displayBuffers;
102
 
};
103
 
 
104
 
class StubDisplayListener : public mir::compositor::DisplayListener
105
 
{
106
 
    void add_display(mir::geometry::Rectangle const& /*area*/) override {};
107
 
 
108
 
    void remove_display(mir::geometry::Rectangle const& /*area*/) override {};
109
 
};
110
 
 
111
 
#endif // STUB_DISPLAY_H