OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/macros.h" |
| 6 #include "cc/base/index_rect.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 |
| 9 namespace cc { |
| 10 |
| 11 TEST(IndexRectTest, NumIndices) { |
| 12 struct NumIndicesCase { |
| 13 int left; |
| 14 int right; |
| 15 int top; |
| 16 int bottom; |
| 17 int num_indices_x; |
| 18 int num_indices_y; |
| 19 } num_indices_cases[] = {{-10, 10, -10, 10, 21, 21}, |
| 20 {0, 5, 0, 10, 6, 11}, |
| 21 {1, 2, 3, 4, 2, 2}, |
| 22 {0, 0, 0, 0, 1, 1}, |
| 23 {10, 10, 10, 10, 1, 1}}; |
| 24 |
| 25 for (size_t i = 0; i < arraysize(num_indices_cases); ++i) { |
| 26 const NumIndicesCase& value = num_indices_cases[i]; |
| 27 IndexRect rect(value.left, value.right, value.top, value.bottom); |
| 28 EXPECT_EQ(value.num_indices_x, rect.num_indices_x()); |
| 29 EXPECT_EQ(value.num_indices_y, rect.num_indices_y()); |
| 30 } |
| 31 } |
| 32 |
| 33 TEST(IndexRectTest, ClampTo) { |
| 34 struct Indices { |
| 35 int left; |
| 36 int right; |
| 37 int top; |
| 38 int bottom; |
| 39 }; |
| 40 |
| 41 struct ClampToCase { |
| 42 Indices first; |
| 43 Indices second; |
| 44 Indices expected; |
| 45 bool valid; |
| 46 } clamp_to_cases[] = {{{0, 5, 0, 5}, {0, 5, 0, 5}, {0, 5, 0, 5}, true}, |
| 47 {{0, 10, 0, 10}, {0, 5, 0, 5}, {0, 5, 0, 5}, true}, |
| 48 {{0, 5, 0, 5}, {0, 10, 0, 10}, {0, 5, 0, 5}, true}, |
| 49 {{-10, 5, -10, 5}, {0, 10, 0, 10}, {0, 5, 0, 5}, true}, |
| 50 {{0, 5, 0, 5}, {10, 20, 10, 20}, {0, 0, 0, 0}, false}}; |
| 51 |
| 52 for (size_t i = 0; i < arraysize(clamp_to_cases); ++i) { |
| 53 const ClampToCase& value = clamp_to_cases[i]; |
| 54 IndexRect first(value.first.left, value.first.right, value.first.top, |
| 55 value.first.bottom); |
| 56 IndexRect second(value.second.left, value.second.right, value.second.top, |
| 57 value.second.bottom); |
| 58 IndexRect expected(value.expected.left, value.expected.right, |
| 59 value.expected.top, value.expected.bottom); |
| 60 |
| 61 first.ClampTo(second); |
| 62 EXPECT_EQ(value.valid, first.is_valid()); |
| 63 |
| 64 if (value.valid) |
| 65 EXPECT_EQ(expected, first); |
| 66 } |
| 67 } |
| 68 |
| 69 TEST(IndexRectTest, Contains) { |
| 70 struct ContainsCase { |
| 71 int left; |
| 72 int right; |
| 73 int top; |
| 74 int bottom; |
| 75 int index_x; |
| 76 int index_y; |
| 77 bool contained; |
| 78 } contains_cases[] = { |
| 79 {-10, 10, -10, 10, -10, -10, true}, {-10, 10, -10, 10, 0, 0, true}, |
| 80 {-10, 10, -10, 10, 10, 10, true}, {-10, 10, -10, 10, 5, 5, true}, |
| 81 {-10, 10, -10, 10, -5, -5, true}, {-10, 10, -10, 10, -20, -20, false}, |
| 82 {-10, 10, -10, 10, 20, 20, false}, {-10, 10, -10, 10, 20, 5, false}, |
| 83 {-10, 10, -10, 10, 5, 20, false}}; |
| 84 |
| 85 for (size_t i = 0; i < arraysize(contains_cases); ++i) { |
| 86 const ContainsCase& value = contains_cases[i]; |
| 87 IndexRect rect(value.left, value.right, value.top, value.bottom); |
| 88 EXPECT_EQ(value.contained, rect.Contains(value.index_x, value.index_y)); |
| 89 } |
| 90 } |
| 91 |
| 92 TEST(IndexRectTest, Equals) { |
| 93 EXPECT_TRUE(IndexRect(0, 0, 0, 0) == IndexRect(0, 0, 0, 0)); |
| 94 EXPECT_FALSE(IndexRect(0, 0, 0, 0) == IndexRect(0, 0, 0, 1)); |
| 95 EXPECT_TRUE(IndexRect(0, 0, 0, 0) != IndexRect(0, 0, 0, 1)); |
| 96 EXPECT_FALSE(IndexRect(0, 0, 0, 0) != IndexRect(0, 0, 0, 0)); |
| 97 } |
| 98 |
| 99 } // namespace cc |
OLD | NEW |