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
|
/*
* Copyright © 2020 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: Alan Griffiths <alan@octopull.co.uk>
*/
#include "relative_pointer_unstable_v1.h"
#include "helpers.h"
#include "in_process_server.h"
#include <gmock/gmock.h>
using testing::AnyNumber;
using testing::IsTrue;
using testing::NotNull;
using testing::_;
using namespace wlcs;
namespace
{
auto const any_width = 300;
auto const any_height = 300;
auto const nw_middle_x = any_width / 2;
auto const nw_middle_y = any_height / 2;
struct RelativePointer : StartedInProcessServer
{
// Create a client with a surface and a cursor centered on the surface
Client a_client{the_server()};
Surface a_surface{a_client.create_visible_surface(any_width, any_height)};
Pointer cursor = the_server().create_pointer();
ZwpRelativePointerManagerV1 manager{a_client};
ZwpRelativePointerV1 pointer{manager, a_client.the_pointer()};
void SetUp() override
{
StartedInProcessServer::SetUp();
// Get the surface in a known position with the cursor over it
the_server().move_surface_to(a_surface, 0, 0);
cursor.move_to(nw_middle_x, nw_middle_y);
}
void TearDown() override
{
a_client.roundtrip();
StartedInProcessServer::TearDown();
}
};
}
TEST_F(RelativePointer, can_get_relative_pointer)
{
EXPECT_THAT(pointer, NotNull());
}
TEST_F(RelativePointer, relative_pointer_gets_movement)
{
auto const move_x = any_width/6;
auto const move_y = any_height/6;
EXPECT_CALL(pointer, relative_motion(_, _,
wl_fixed_from_int(move_x), wl_fixed_from_int(move_y),
wl_fixed_from_int(move_x), wl_fixed_from_int(move_y))).Times(1);
cursor.move_by(move_x, move_y);
}
// #1959
TEST_F(RelativePointer, default_pointer_still_gets_movement)
{
auto const move_x = any_width/6;
auto const move_y = any_height/6;
EXPECT_CALL(pointer, relative_motion(_, _, _, _, _, _)).Times(AnyNumber());
bool moved = false;
a_client.add_pointer_motion_notification([&](auto...) { moved = true; return true; });
cursor.move_by(move_x, move_y);
a_client.roundtrip();
EXPECT_THAT(moved, IsTrue());
}
|