~raof/mir/link-platforms-against-mirplatform

« back to all changes in this revision

Viewing changes to tests/unit-tests/examples/test_demo_compositor.cpp

scene: Throw when inactive compositor ids are passed to the rendering tracker

This MP also introduces a regression test for bug #1359487.

Approved by PS Jenkins bot, Kevin DuBois, Alberto Aguirre.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2014 Canonical Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License version 3 as
 
6
 * published by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>
 
17
 */
 
18
 
 
19
#include "examples/demo-shell/demo_compositor.h"
 
20
 
 
21
#include "mir/geometry/rectangle.h"
 
22
#include "src/server/scene/surface_stack.h"
 
23
#include "src/server/scene/basic_surface.h"
 
24
#include "src/server/report/null_report_factory.h"
 
25
 
 
26
#include "mir_test_doubles/mock_gl.h"
 
27
#include "mir_test_doubles/stub_display_buffer.h"
 
28
#include "mir_test_doubles/stub_gl_program_factory.h"
 
29
#include "mir_test_doubles/stub_buffer_stream.h"
 
30
#include "mir_test_doubles/null_surface_configurator.h"
 
31
#include "mir_test/fake_shared.h"
 
32
 
 
33
#include <gtest/gtest.h>
 
34
#include <gmock/gmock.h>
 
35
 
 
36
namespace mtd = mir::test::doubles;
 
37
namespace geom = mir::geometry;
 
38
namespace me = mir::examples;
 
39
namespace mt = mir::test;
 
40
namespace ms = mir::scene;
 
41
 
 
42
namespace
 
43
{
 
44
 
 
45
struct DemoCompositor : testing::Test
 
46
{
 
47
    DemoCompositor()
 
48
    {
 
49
        using namespace testing;
 
50
 
 
51
        surface_stack.add_surface(
 
52
            mt::fake_shared(stub_surface),
 
53
            ms::DepthId{0},
 
54
            mir::input::InputReceptionMode::normal);
 
55
 
 
56
        post_surface_buffer();
 
57
    }
 
58
 
 
59
    void post_surface_buffer()
 
60
    {
 
61
        mir::graphics::Buffer* old_buffer;
 
62
 
 
63
        stub_surface.swap_buffers(
 
64
            nullptr,
 
65
            [&old_buffer] (mir::graphics::Buffer* buffer)
 
66
            {
 
67
                old_buffer = buffer;
 
68
            });
 
69
 
 
70
        stub_surface.swap_buffers(
 
71
            old_buffer,
 
72
            [] (mir::graphics::Buffer*) {});
 
73
    }
 
74
 
 
75
    testing::NiceMock<mtd::MockGL> mock_gl;
 
76
    mtd::StubDisplayBuffer stub_display_buffer{
 
77
        geom::Rectangle{{0,0}, {1000,1000}}};
 
78
    mir::scene::SurfaceStack surface_stack{mir::report::null_scene_report()};
 
79
    mtd::StubGLProgramFactory stub_factory;
 
80
    ms::BasicSurface stub_surface{
 
81
        std::string("stub"),
 
82
        geom::Rectangle{{0,0},{100,100}},
 
83
        false,
 
84
        std::make_shared<mtd::StubBufferStream>(),
 
85
        std::shared_ptr<mir::input::InputChannel>(),
 
86
        std::shared_ptr<mir::input::InputSender>(),
 
87
        std::make_shared<mtd::NullSurfaceConfigurator>(),
 
88
        std::shared_ptr<mir::graphics::CursorImage>(),
 
89
        mir::report::null_scene_report()};
 
90
 
 
91
    me::DemoCompositor demo_compositor{
 
92
        stub_display_buffer,
 
93
        mt::fake_shared(surface_stack),
 
94
        stub_factory,
 
95
        mir::report::null_compositor_report()};
 
96
};
 
97
 
 
98
}
 
99
 
 
100
// Regression test for https://bugs.launchpad.net/mir/+bug/1359487
 
101
TEST_F(DemoCompositor, sets_surface_visibility)
 
102
{
 
103
    using namespace testing;
 
104
 
 
105
    demo_compositor.composite();
 
106
 
 
107
    EXPECT_THAT(
 
108
        stub_surface.query(mir_surface_attrib_visibility),
 
109
        Eq(mir_surface_visibility_exposed));
 
110
 
 
111
    stub_surface.hide();
 
112
 
 
113
    demo_compositor.composite();
 
114
 
 
115
    EXPECT_THAT(
 
116
        stub_surface.query(mir_surface_attrib_visibility),
 
117
        Eq(mir_surface_visibility_occluded));
 
118
}