File: render_scene_into_surface.cpp

package info (click to toggle)
mir 2.25.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,104 kB
  • sloc: cpp: 192,777; xml: 13,784; ansic: 8,207; python: 1,304; sh: 794; makefile: 258
file content (123 lines) | stat: -rw-r--r-- 3,391 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
 * Copyright © Canonical Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 or 3 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "render_scene_into_surface.h"

#include <miral/test_server.h>
#include <gtest/gtest.h>
#include <gmock/gmock.h>

#include <mir/server.h>
#include <mir/compositor/scene.h>
#include <mir/compositor/scene_element.h>
#include <mir/graphics/renderable.h>
#include <mir/scene/surface.h>

namespace mtf = mir_test_framework;

using namespace testing;
using namespace miral;


class RenderSceneIntoSurfaceTest : public TestServer
{
public:
    RenderSceneIntoSurfaceTest()
    {
        start_server_in_setup = false;
        add_to_environment("MIR_SERVER_PLATFORM_DISPLAY_LIBS", "mir:virtual");
        add_to_environment("MIR_SERVER_VIRTUAL_OUTPUT", "800x600");
    }

    void SetUp() override
    {
        TestServer::SetUp();
        add_server_init(render_scene_into_surface);
    }

    RenderSceneIntoSurface render_scene_into_surface;

};

TEST_F(RenderSceneIntoSurfaceTest, set_capture_area_before_starting)
{
    render_scene_into_surface.capture_area(Rectangle(
        Point(100, 100),
        Size(200, 200)
    ));

    start_server();
    auto const scene = server().the_scene();
    auto const elements = scene->scene_elements_for(this);
    EXPECT_THAT(elements.size(), Eq(1));
    auto const& element = elements.at(0);
    EXPECT_THAT(element->renderable()->screen_position(), Eq(Rectangle(
        Point(0, 0),
        Size(200, 200)
    )));
}

TEST_F(RenderSceneIntoSurfaceTest, set_capture_area_after_starting)
{
    start_server();
    render_scene_into_surface.capture_area(Rectangle(
        Point(100, 100),
        Size(200, 200)
    ));
    auto const scene = server().the_scene();
    auto const elements = scene->scene_elements_for(this);
    EXPECT_THAT(elements.size(), Eq(1));
    auto const& element = elements.at(0);
    EXPECT_THAT(element->renderable()->screen_position(), Eq(Rectangle(
        Point(100, 100),
        Size(200, 200)
    )));
}

TEST_F(RenderSceneIntoSurfaceTest, set_overlay_cursor_before_starting)
{
    render_scene_into_surface.overlay_cursor(true);
    start_server();
}

TEST_F(RenderSceneIntoSurfaceTest, set_overlay_cursor_after_starting)
{
    add_start_callback([&]
    {
        render_scene_into_surface.overlay_cursor(true);
    });
    start_server();
}

TEST_F(RenderSceneIntoSurfaceTest, on_surface_ready_callback_called)
{
    bool called = false;
    render_scene_into_surface.on_surface_ready([&](auto const&)
    {
        called = true;
    });
    start_server();
    EXPECT_THAT(called, Eq(true));
}

TEST_F(RenderSceneIntoSurfaceTest, surface_never_contains_point)
{
    render_scene_into_surface.on_surface_ready([&](std::shared_ptr<mir::scene::Surface> const&surface)
    {
       EXPECT_THAT(surface->input_area_contains(Point(0, 0)), Eq(false));
    });
    start_server();
}