~ci-train-bot/mir/mir-ubuntu-zesty-2735

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
/*
 * Copyright © 2016 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 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/>.
 *
 * Authored By: Nick Dedekind <nick.dedekind@canonical.com>
 */

#include "mir/scene/surface.h"
#include "mir/shell/persistent_surface_store.h"

#include "mir/test/doubles/wrap_shell_to_track_latest_surface.h"
#include "mir_test_framework/connected_client_with_a_surface.h"
#include "mir/test/fake_shared.h"

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

namespace msh = mir::shell;
namespace ms = mir::scene;
namespace mt = mir::test;
namespace mtd = mt::doubles;
namespace mtf = mir_test_framework;

using namespace testing;

namespace
{
struct TestPersistentSurfaceStore : mtf::ConnectedClientWithASurface
{
    void SetUp() override
    {
        server.wrap_shell([this](std::shared_ptr<msh::Shell> const& wrapped)
        {
            auto const msc = std::make_shared<mtd::WrapShellToTrackLatestSurface>(wrapped);
            shell = msc;
            return msc;
        });

        mtf::ConnectedClientWithASurface::SetUp();
    }

    void TearDown() override
    {
        shell.reset();
        mtf::ConnectedClientWithASurface::TearDown();
    }

    std::shared_ptr<ms::Surface> latest_shell_surface() const
    {
        auto const result = shell->latest_surface.lock();
        EXPECT_THAT(result, NotNull());
        return result;
    }

private:
    std::shared_ptr<mtd::WrapShellToTrackLatestSurface> shell;
};
}

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
TEST_F(TestPersistentSurfaceStore, server_and_client_persistent_id_matches)
{
    auto const shell_server_surface = latest_shell_surface();
    ASSERT_THAT(shell_server_surface, NotNull());

    MirPersistentId* client_surface_id = mir_window_request_persistent_id_sync(window);
    msh::PersistentSurfaceStore::Id server_surface_id = server.the_persistent_surface_store()->id_for_surface(shell_server_surface);

    std::string client_surface_id_string(mir_persistent_id_as_string(client_surface_id));

    ASSERT_THAT(server_surface_id.serialize_to_string(), Eq(client_surface_id_string));

    mir_persistent_id_release(client_surface_id);
}
#pragma GCC diagnostic pop