File: test_platform.cpp

package info (click to toggle)
mir 2.20.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,636 kB
  • sloc: cpp: 174,574; xml: 13,422; ansic: 8,221; python: 1,337; sh: 874; makefile: 216; javascript: 37
file content (86 lines) | stat: -rw-r--r-- 3,009 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
/*
 * 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 <gtest/gtest.h>
#include <gmock/gmock.h>

#include "mir/graphics/platform.h"
#include "src/platforms/virtual/platform.h"
#include "mir/test/doubles/mock_egl.h"

#include "mir/shared_library.h"
#include "src/server/report/null/display_report.h"

namespace mg = mir::graphics;
namespace mtd = mir::test::doubles;
namespace mgv = mir::graphics::virt;
namespace geom = mir::geometry;
using namespace testing;

namespace
{

class VirtualGraphicsPlatformTest : public ::testing::Test
{
public:
    std::shared_ptr<mg::DisplayPlatform> create_platform()
    {
        mgv::VirtualOutputConfig config({{1280, 1024}});
        return std::make_shared<mgv::Platform>(
            std::make_shared<mir::report::null::DisplayReport>(),
            std::vector<mgv::VirtualOutputConfig>{config});
    }

protected:
    virtual void SetUp()
    {
        mock_egl.provide_egl_extensions();
    }

    testing::NiceMock<mtd::MockEGL> mock_egl;
    EGLDisplay fake_display{reinterpret_cast<EGLDisplay>(0xabcd)};
};

TEST_F(VirtualGraphicsPlatformTest, lone_config_has_one_output_size_when_provided_one_output_size)
{
    auto configs = mgv::Platform::parse_output_sizes({"1280x1024"});
    EXPECT_THAT(configs, ElementsAre(
        mgv::VirtualOutputConfig(std::vector<geom::Size>{{1280, 1024}})));
}

TEST_F(VirtualGraphicsPlatformTest, multiple_output_sizes_are_set_correctly_when_multiple_are_provided)
{
    auto config = mgv::Platform::parse_output_sizes({"1280x1024:800x600"});
    EXPECT_THAT(config, ElementsAre(
        mgv::VirtualOutputConfig(std::vector<geom::Size>{geom::Size{1280, 1024}, geom::Size{800, 600}})));
}

TEST_F(VirtualGraphicsPlatformTest, can_acquire_interface_for_cpu_addressable_display_provider)
{
    auto platform = create_platform();
    EXPECT_TRUE(platform->acquire_provider<mg::CPUAddressableDisplayProvider>() != nullptr);
}

TEST_F(VirtualGraphicsPlatformTest, output_size_parsing_throws_on_bad_input)
{
    // X11's tests check the remaining cases here. These are the only cases that do not overlap with X11's.
    using namespace ::testing;
    EXPECT_THROW(mgv::Platform::parse_output_sizes({"1280"}), std::runtime_error) << "No height or 'x'";
    EXPECT_THROW(mgv::Platform::parse_output_sizes({"1280x"}), std::runtime_error) << "No height";
    EXPECT_THROW(mgv::Platform::parse_output_sizes({"x1280"}), std::runtime_error) << "No width";
}

}