forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Eliminate duplicated code when dealing with pointer data (flutter#36822)
* add methods * add empty test * add unit test * Update licenses_flutter * add const * size -> get length * add boundary checks * add tests * remove death test since it says "Death tests use fork(), which is unsafe particularly in a threaded context."
- Loading branch information
Showing
9 changed files
with
94 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "flutter/lib/ui/window/pointer_data.h" | ||
|
||
#include <cstring> | ||
|
||
#include "gtest/gtest.h" | ||
#include "pointer_data_packet.h" | ||
|
||
namespace flutter { | ||
namespace testing { | ||
|
||
void CreateSimpleSimulatedPointerData(PointerData& data, // NOLINT | ||
PointerData::Change change, | ||
int64_t device, | ||
double dx, | ||
double dy, | ||
int64_t buttons) { | ||
data.time_stamp = 0; | ||
data.change = change; | ||
data.kind = PointerData::DeviceKind::kTouch; | ||
data.signal_kind = PointerData::SignalKind::kNone; | ||
data.device = device; | ||
data.pointer_identifier = 0; | ||
data.physical_x = dx; | ||
data.physical_y = dy; | ||
data.physical_delta_x = 0.0; | ||
data.physical_delta_y = 0.0; | ||
data.buttons = buttons; | ||
data.obscured = 0; | ||
data.synthesized = 0; | ||
data.pressure = 0.0; | ||
data.pressure_min = 0.0; | ||
data.pressure_max = 0.0; | ||
data.distance = 0.0; | ||
data.distance_max = 0.0; | ||
data.size = 0.0; | ||
data.radius_major = 0.0; | ||
data.radius_minor = 0.0; | ||
data.radius_min = 0.0; | ||
data.radius_max = 0.0; | ||
data.orientation = 0.0; | ||
data.tilt = 0.0; | ||
data.platformData = 0; | ||
data.scroll_delta_x = 0.0; | ||
data.scroll_delta_y = 0.0; | ||
} | ||
|
||
TEST(PointerDataPacketTest, CanGetPointerData) { | ||
auto packet = std::make_unique<PointerDataPacket>(1); | ||
PointerData data; | ||
CreateSimpleSimulatedPointerData(data, PointerData::Change::kAdd, 1, 2.0, 3.0, | ||
4); | ||
packet->SetPointerData(0, data); | ||
|
||
PointerData data_recovered = packet->GetPointerData(0); | ||
ASSERT_EQ(data_recovered.physical_x, 2.0); | ||
ASSERT_EQ(data_recovered.physical_y, 3.0); | ||
} | ||
|
||
TEST(PointerDataPacketTest, CanGetLength) { | ||
auto packet = std::make_unique<PointerDataPacket>(6); | ||
ASSERT_EQ(packet->GetLength(), (size_t)6); | ||
} | ||
|
||
} // namespace testing | ||
} // namespace flutter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters