gio: lint police, using DCHECK_EQ, EXPECT_LT
This CL applies git cl lint recommendations for
arc::input_overlay involving preferring DCHECK_EQ instead of DCHECK.
The CL also makes use of EXPECT_LT whenever possible and reuses the
already defined var |kEpsilon| to compare floating point operations.
Bug: None
Test: affected unit_tests pass.
Change-Id: I8fc775612dd95885fc0fa24c3be830276f0144a6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4032572
Commit-Queue: David Jacobo <djacobo@chromium.org>
Auto-Submit: David Jacobo <djacobo@chromium.org>
Reviewed-by: Cici Ruan <cuicuiruan@google.com>
Cr-Commit-Position: refs/heads/main@{#1072588}
diff --git a/chrome/browser/ash/arc/input_overlay/actions/action_tap.cc b/chrome/browser/ash/arc/input_overlay/actions/action_tap.cc
index 8583373..edc26af 100644
--- a/chrome/browser/ash/arc/input_overlay/actions/action_tap.cc
+++ b/chrome/browser/ash/arc/input_overlay/actions/action_tap.cc
@@ -26,7 +26,7 @@
std::unique_ptr<ActionLabel> CreateActionLabel(InputElement& input_element) {
std::unique_ptr<ActionLabel> label;
if (IsKeyboardBound(input_element)) {
- DCHECK(input_element.keys().size() == 1);
+ DCHECK_EQ(1u, input_element.keys().size());
label = ActionLabel::CreateTextActionLabel(
GetDisplayText(input_element.keys()[0]));
} else if (IsMouseBound(input_element)) {
@@ -140,7 +140,7 @@
}
void ChildPreferredSizeChanged(View* child) override {
- DCHECK(labels_.size() == 1);
+ DCHECK_EQ(1u, labels_.size());
if (static_cast<ActionLabel*>(child) != labels_[0])
return;
diff --git a/chrome/browser/ash/arc/input_overlay/actions/position_unittest.cc b/chrome/browser/ash/arc/input_overlay/actions/position_unittest.cc
index 198d2f3..e4427fc 100644
--- a/chrome/browser/ash/arc/input_overlay/actions/position_unittest.cc
+++ b/chrome/browser/ash/arc/input_overlay/actions/position_unittest.cc
@@ -264,8 +264,8 @@
auto json_value = base::JSONReader::ReadAndReturnValueWithError(kValidJson);
EXPECT_TRUE(json_value.has_value() && json_value->is_dict());
EXPECT_TRUE(pos->ParseFromJson(*json_value));
- EXPECT_TRUE(pos->anchor() == gfx::PointF(0, 0));
- EXPECT_TRUE(pos->anchor_to_target() == gfx::Vector2dF(0.5, 0.5));
+ EXPECT_EQ(pos->anchor(), gfx::PointF(0, 0));
+ EXPECT_EQ(pos->anchor_to_target(), gfx::Vector2dF(0.5, 0.5));
pos.reset();
// Parse valid Json without anchor point.
@@ -274,8 +274,8 @@
base::JSONReader::ReadAndReturnValueWithError(kValidJsonNoAnchorPoint);
EXPECT_TRUE(json_value.has_value() && json_value->is_dict());
EXPECT_TRUE(pos->ParseFromJson(*json_value));
- EXPECT_TRUE(pos->anchor() == gfx::PointF(0, 0));
- EXPECT_TRUE(pos->anchor_to_target() == gfx::Vector2dF(0.1796875, 0.25));
+ EXPECT_EQ(pos->anchor(), gfx::PointF(0, 0));
+ EXPECT_EQ(pos->anchor_to_target(), gfx::Vector2dF(0.1796875, 0.25));
pos.reset();
// Parse invalid Json with wrong anchor point.
@@ -324,9 +324,9 @@
base::JSONReader::ReadAndReturnValueWithError(kValidJsonAspectRatio);
EXPECT_TRUE(json_value.has_value() && json_value->is_dict());
EXPECT_TRUE(pos->ParseFromJson(*json_value));
- EXPECT_TRUE(std::abs(*pos->aspect_ratio() - 1.5) < kEpsilon);
- EXPECT_TRUE(std::abs(*pos->x_on_y() - 0.8) < kEpsilon);
- EXPECT_TRUE(std::abs(*pos->y_on_x() - 0.6) < kEpsilon);
+ EXPECT_LT(std::abs(*pos->aspect_ratio() - 1.5), kEpsilon);
+ EXPECT_LT(std::abs(*pos->x_on_y() - 0.8), kEpsilon);
+ EXPECT_LT(std::abs(*pos->y_on_x() - 0.6), kEpsilon);
// Parse invalid Json for aspect ration dependent position - missing x_on_y.
pos = std::make_unique<Position>(PositionType::kDependent);
@@ -341,7 +341,7 @@
base::JSONReader::ReadAndReturnValueWithError(kValidJsonHeightDependent);
EXPECT_TRUE(json_value.has_value() && json_value->is_dict());
EXPECT_TRUE(pos->ParseFromJson(*json_value));
- EXPECT_TRUE(std::abs(*pos->x_on_y() - 0.8) < kEpsilon);
+ EXPECT_LT(std::abs(*pos->x_on_y() - 0.8), kEpsilon);
// Parse invalid Json for non-aspect-ratio-dependent position - present both
// x_on_y and y_on_x.
@@ -365,7 +365,7 @@
pos->ParseFromJson(*json_value);
auto bounds = gfx::RectF(200, 400);
auto target = pos->CalculatePosition(bounds);
- EXPECT_TRUE(target == gfx::PointF(100, 200));
+ EXPECT_EQ(target, gfx::PointF(100, 200));
pos.reset();
// Calculate the target position with anchor point at the bottom-right corner.
@@ -374,13 +374,13 @@
kJsonCalculateTargetUpperLeft);
pos->ParseFromJson(*json_value);
target = pos->CalculatePosition(bounds);
- EXPECT_TRUE(std::abs(target.x() - 40) < 0.0001);
- EXPECT_TRUE(std::abs(target.y() - 80) < 0.0001);
+ EXPECT_LT(std::abs(target.x() - 40), kEpsilon);
+ EXPECT_LT(std::abs(target.y() - 80), kEpsilon);
bounds.set_width(300);
bounds.set_height(400);
target = pos->CalculatePosition(bounds);
- EXPECT_TRUE(std::abs(target.x() - 60) < 0.0001);
- EXPECT_TRUE(std::abs(target.y() - 80) < 0.0001);
+ EXPECT_LT(std::abs(target.x() - 60), kEpsilon);
+ EXPECT_LT(std::abs(target.y() - 80), kEpsilon);
pos.reset();
}
@@ -393,14 +393,14 @@
pos->ParseFromJson(*json_value);
auto bounds = gfx::RectF(200, 400);
auto target = pos->CalculatePosition(bounds);
- EXPECT_TRUE(std::abs(target.x() - 160) < kEpsilon);
- EXPECT_TRUE(std::abs(target.y() - 200) < kEpsilon);
+ EXPECT_LT(std::abs(target.x() - 160), kEpsilon);
+ EXPECT_LT(std::abs(target.y() - 200), kEpsilon);
// Give a height which may calculate the x value outside of the window bounds.
// The result x should be inside of the window bounds.
bounds.set_height(600);
target = pos->CalculatePosition(bounds);
- EXPECT_TRUE(std::abs(target.x() - 199) < kEpsilon);
- EXPECT_TRUE(std::abs(target.y() - 300) < kEpsilon);
+ EXPECT_LT(std::abs(target.x() - 199), kEpsilon);
+ EXPECT_LT(std::abs(target.y() - 300), kEpsilon);
// Parse the position with anchor on the bottom-right corner.
pos = std::make_unique<Position>(PositionType::kDependent);
@@ -409,14 +409,14 @@
pos->ParseFromJson(*json_value);
bounds.set_height(400);
target = pos->CalculatePosition(bounds);
- EXPECT_TRUE(std::abs(target.x() - 40) < kEpsilon);
- EXPECT_TRUE(std::abs(target.y() - 200) < kEpsilon);
+ EXPECT_LT(std::abs(target.x() - 40), kEpsilon);
+ EXPECT_LT(std::abs(target.y() - 200), kEpsilon);
// Give a height which may calculate the x value outside of the window bounds.
// The result x should be inside of the window bounds.
bounds.set_height(600);
target = pos->CalculatePosition(bounds);
- EXPECT_TRUE(std::abs(target.x()) < kEpsilon);
- EXPECT_TRUE(std::abs(target.y() - 300) < kEpsilon);
+ EXPECT_LT(std::abs(target.x()), kEpsilon);
+ EXPECT_LT(std::abs(target.y() - 300), kEpsilon);
// Parse the position with anchor on the bottom-left corner.
pos = std::make_unique<Position>(PositionType::kDependent);
@@ -425,8 +425,8 @@
pos->ParseFromJson(*json_value);
bounds.set_height(400);
target = pos->CalculatePosition(bounds);
- EXPECT_TRUE(std::abs(target.x() - 160) < kEpsilon);
- EXPECT_TRUE(std::abs(target.y() - 200) < kEpsilon);
+ EXPECT_LT(std::abs(target.x() - 160), kEpsilon);
+ EXPECT_LT(std::abs(target.y() - 200), kEpsilon);
// Parse the position with anchor on the top-right corner.
pos = std::make_unique<Position>(PositionType::kDependent);
@@ -435,8 +435,8 @@
pos->ParseFromJson(*json_value);
bounds.set_height(400);
target = pos->CalculatePosition(bounds);
- EXPECT_TRUE(std::abs(target.x() - 40) < kEpsilon);
- EXPECT_TRUE(std::abs(target.y() - 200) < kEpsilon);
+ EXPECT_LT(std::abs(target.x() - 40), kEpsilon);
+ EXPECT_LT(std::abs(target.y() - 200), kEpsilon);
}
TEST(PositionTest, TestCalculatePositionWidthDependent) {
@@ -448,14 +448,14 @@
pos->ParseFromJson(*json_value);
auto bounds = gfx::RectF(200, 400);
auto target = pos->CalculatePosition(bounds);
- EXPECT_TRUE(std::abs(target.x() - 100) < kEpsilon);
- EXPECT_TRUE(std::abs(target.y() - 80) < kEpsilon);
+ EXPECT_LT(std::abs(target.x() - 100), kEpsilon);
+ EXPECT_LT(std::abs(target.y() - 80), kEpsilon);
// Give a width which may calculate the y value outside of the window bounds.
// The result y should be inside of the window bounds.
bounds.set_width(1200);
target = pos->CalculatePosition(bounds);
- EXPECT_TRUE(std::abs(target.x() - 600) < kEpsilon);
- EXPECT_TRUE(std::abs(target.y() - 399) < kEpsilon);
+ EXPECT_LT(std::abs(target.x() - 600), kEpsilon);
+ EXPECT_LT(std::abs(target.y() - 399), kEpsilon);
// Parse the position with anchor on the bottom-right corner.
pos = std::make_unique<Position>(PositionType::kDependent);
@@ -464,14 +464,14 @@
pos->ParseFromJson(*json_value);
bounds.set_width(200);
target = pos->CalculatePosition(bounds);
- EXPECT_TRUE(std::abs(target.x() - 100) < kEpsilon);
- EXPECT_TRUE(std::abs(target.y() - 320) < kEpsilon);
+ EXPECT_LT(std::abs(target.x() - 100), kEpsilon);
+ EXPECT_LT(std::abs(target.y() - 320), kEpsilon);
// Give a width which may calculate the y value outside of the window bounds.
// The result y should be inside of the window bounds.
bounds.set_width(1200);
target = pos->CalculatePosition(bounds);
- EXPECT_TRUE(std::abs(target.x() - 600) < kEpsilon);
- EXPECT_TRUE(std::abs(target.y()) < kEpsilon);
+ EXPECT_LT(std::abs(target.x() - 600), kEpsilon);
+ EXPECT_LT(std::abs(target.y()), kEpsilon);
// Parse the position with anchor on the bottom-left corner.
pos = std::make_unique<Position>(PositionType::kDependent);
@@ -480,8 +480,8 @@
pos->ParseFromJson(*json_value);
bounds.set_width(200);
target = pos->CalculatePosition(bounds);
- EXPECT_TRUE(std::abs(target.x() - 100) < kEpsilon);
- EXPECT_TRUE(std::abs(target.y() - 320) < kEpsilon);
+ EXPECT_LT(std::abs(target.x() - 100), kEpsilon);
+ EXPECT_LT(std::abs(target.y() - 320), kEpsilon);
// Parse the position with anchor on the top-right corner.
pos = std::make_unique<Position>(PositionType::kDependent);
@@ -490,8 +490,8 @@
pos->ParseFromJson(*json_value);
bounds.set_width(200);
target = pos->CalculatePosition(bounds);
- EXPECT_TRUE(std::abs(target.x() - 100) < kEpsilon);
- EXPECT_TRUE(std::abs(target.y() - 80) < kEpsilon);
+ EXPECT_LT(std::abs(target.x() - 100), kEpsilon);
+ EXPECT_LT(std::abs(target.y() - 80), kEpsilon);
}
TEST(PositionTest, TestCalculatePositionAspectRatioDependent) {
@@ -502,12 +502,12 @@
pos->ParseFromJson(*json_value);
auto bounds = gfx::RectF(200, 400);
auto target = pos->CalculatePosition(bounds);
- EXPECT_TRUE(std::abs(target.x() - 100) < kEpsilon);
- EXPECT_TRUE(std::abs(target.y() - 60) < kEpsilon);
+ EXPECT_LT(std::abs(target.x() - 100), kEpsilon);
+ EXPECT_LT(std::abs(target.y() - 60), kEpsilon);
bounds.set_width(800);
target = pos->CalculatePosition(bounds);
- EXPECT_TRUE(std::abs(target.x() - 160) < kEpsilon);
- EXPECT_TRUE(std::abs(target.y() - 200) < kEpsilon);
+ EXPECT_LT(std::abs(target.x() - 160), kEpsilon);
+ EXPECT_LT(std::abs(target.y() - 200), kEpsilon);
}
TEST(PositionTest, TestPositionEquality) {
diff --git a/chrome/browser/ash/arc/input_overlay/touch_injector_unittest.cc b/chrome/browser/ash/arc/input_overlay/touch_injector_unittest.cc
index 6c23cd7..a9a26b6 100644
--- a/chrome/browser/ash/arc/input_overlay/touch_injector_unittest.cc
+++ b/chrome/browser/ash/arc/input_overlay/touch_injector_unittest.cc
@@ -563,11 +563,11 @@
// Press key A and generate touch down and move left event.
event_generator_->PressKey(ui::VKEY_A, ui::EF_NONE, 1 /* keyboard id */);
- EXPECT_TRUE(*(action->touch_id()) == 0);
+ EXPECT_EQ(0, *(action->touch_id()));
EXPECT_TRUE(event_capturer_.key_events().empty());
// Wait for touch move event.
task_environment()->FastForwardBy(kSendTouchMoveDelay);
- EXPECT_TRUE((int)event_capturer_.touch_events().size() == 2);
+ EXPECT_EQ(2u, event_capturer_.touch_events().size());
// Generate touch down event.
auto* event = event_capturer_.touch_events()[0].get();
EXPECT_EQ(ui::EventType::ET_TOUCH_PRESSED, event->type());
@@ -586,7 +586,7 @@
// Press key W (move left + up) and generate touch move (up and left) event.
event_generator_->PressKey(ui::VKEY_W, ui::EF_NONE, 1);
- EXPECT_TRUE((int)event_capturer_.touch_events().size() == 3);
+ EXPECT_EQ(3u, event_capturer_.touch_events().size());
event = event_capturer_.touch_events()[2].get();
EXPECT_EQ(ui::EventType::ET_TOUCH_MOVED, event->type());
auto expectW = gfx::PointF(expectA);
@@ -595,7 +595,7 @@
// Release key A and generate touch move up event (Key W is still pressed).
event_generator_->ReleaseKey(ui::VKEY_A, ui::EF_NONE, 1);
- EXPECT_TRUE((int)event_capturer_.touch_events().size() == 4);
+ EXPECT_EQ(4u, event_capturer_.touch_events().size());
event = event_capturer_.touch_events()[3].get();
EXPECT_EQ(ui::EventType::ET_TOUCH_MOVED, event->type());
expectW = gfx::PointF(expect);
@@ -604,7 +604,7 @@
// Press key D and generate touch move (up and right) event.
event_generator_->PressKey(ui::VKEY_D, ui::EF_NONE, 1);
- EXPECT_TRUE((int)event_capturer_.touch_events().size() == 5);
+ EXPECT_EQ(5u, event_capturer_.touch_events().size());
event = event_capturer_.touch_events()[4].get();
EXPECT_EQ(ui::EventType::ET_TOUCH_MOVED, event->type());
auto expectD = gfx::PointF(expectW);
@@ -614,7 +614,7 @@
// Release key W and generate touch move (right) event (Key D is still
// pressed).
event_generator_->ReleaseKey(ui::VKEY_W, ui::EF_NONE, 1);
- EXPECT_TRUE((int)event_capturer_.touch_events().size() == 6);
+ EXPECT_EQ(6u, event_capturer_.touch_events().size());
event = event_capturer_.touch_events()[5].get();
EXPECT_EQ(ui::EventType::ET_TOUCH_MOVED, event->type());
expectD = gfx::PointF(expect);
@@ -623,7 +623,7 @@
// Release key D and generate touch release event.
event_generator_->ReleaseKey(ui::VKEY_D, ui::EF_NONE, 1);
- EXPECT_TRUE((int)event_capturer_.touch_events().size() == 7);
+ EXPECT_EQ(7u, event_capturer_.touch_events().size());
event = event_capturer_.touch_events()[6].get();
EXPECT_EQ(ui::EventType::ET_TOUCH_RELEASED, event->type());
EXPECT_POINTF_NEAR(expectD, event->root_location_f(), kTolerance);
@@ -631,10 +631,10 @@
// Press A again, it should repeat the same as previous result.
event_generator_->PressKey(ui::VKEY_A, ui::EF_NONE, 1 /* keyboard id */);
- EXPECT_TRUE(*(action->touch_id()) == 0);
+ EXPECT_EQ(0, *(action->touch_id()));
EXPECT_TRUE(event_capturer_.key_events().empty());
task_environment()->FastForwardBy(kSendTouchMoveDelay);
- EXPECT_TRUE((int)event_capturer_.touch_events().size() == 2);
+ EXPECT_EQ(2u, event_capturer_.touch_events().size());
// Generate touch down event.
event = event_capturer_.touch_events()[0].get();
EXPECT_EQ(ui::EventType::ET_TOUCH_PRESSED, event->type());