OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/geometry/insets.h" | 5 #include "ui/gfx/geometry/insets.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "ui/gfx/geometry/insets_f.h" |
8 | 9 |
9 TEST(InsetsTest, InsetsDefault) { | 10 TEST(InsetsTest, InsetsDefault) { |
10 gfx::Insets insets; | 11 gfx::Insets insets; |
11 EXPECT_EQ(0, insets.top()); | 12 EXPECT_EQ(0, insets.top()); |
12 EXPECT_EQ(0, insets.left()); | 13 EXPECT_EQ(0, insets.left()); |
13 EXPECT_EQ(0, insets.bottom()); | 14 EXPECT_EQ(0, insets.bottom()); |
14 EXPECT_EQ(0, insets.right()); | 15 EXPECT_EQ(0, insets.right()); |
15 EXPECT_EQ(0, insets.width()); | 16 EXPECT_EQ(0, insets.width()); |
16 EXPECT_EQ(0, insets.height()); | 17 EXPECT_EQ(0, insets.height()); |
17 EXPECT_TRUE(insets.IsEmpty()); | 18 EXPECT_TRUE(insets.IsEmpty()); |
(...skipping 12 matching lines...) Expand all Loading... |
30 | 31 |
31 TEST(InsetsTest, Set) { | 32 TEST(InsetsTest, Set) { |
32 gfx::Insets insets; | 33 gfx::Insets insets; |
33 insets.Set(1, 2, 3, 4); | 34 insets.Set(1, 2, 3, 4); |
34 EXPECT_EQ(1, insets.top()); | 35 EXPECT_EQ(1, insets.top()); |
35 EXPECT_EQ(2, insets.left()); | 36 EXPECT_EQ(2, insets.left()); |
36 EXPECT_EQ(3, insets.bottom()); | 37 EXPECT_EQ(3, insets.bottom()); |
37 EXPECT_EQ(4, insets.right()); | 38 EXPECT_EQ(4, insets.right()); |
38 } | 39 } |
39 | 40 |
40 TEST(InsetsTest, Add) { | 41 TEST(InsetsTest, Operators) { |
41 gfx::Insets insets; | 42 gfx::Insets insets; |
42 insets.Set(1, 2, 3, 4); | 43 insets.Set(1, 2, 3, 4); |
43 insets += gfx::Insets(5, 6, 7, 8); | 44 insets += gfx::Insets(5, 6, 7, 8); |
44 EXPECT_EQ(6, insets.top()); | 45 EXPECT_EQ(6, insets.top()); |
45 EXPECT_EQ(8, insets.left()); | 46 EXPECT_EQ(8, insets.left()); |
46 EXPECT_EQ(10, insets.bottom()); | 47 EXPECT_EQ(10, insets.bottom()); |
47 EXPECT_EQ(12, insets.right()); | 48 EXPECT_EQ(12, insets.right()); |
| 49 |
| 50 insets -= gfx::Insets(-1, 0, 1, 2); |
| 51 EXPECT_EQ(7, insets.top()); |
| 52 EXPECT_EQ(8, insets.left()); |
| 53 EXPECT_EQ(9, insets.bottom()); |
| 54 EXPECT_EQ(10, insets.right()); |
| 55 |
| 56 insets = gfx::Insets(10, 10, 10, 10) + gfx::Insets(5, 5, 0, -20); |
| 57 EXPECT_EQ(15, insets.top()); |
| 58 EXPECT_EQ(15, insets.left()); |
| 59 EXPECT_EQ(10, insets.bottom()); |
| 60 EXPECT_EQ(-10, insets.right()); |
| 61 |
| 62 insets = gfx::Insets(10, 10, 10, 10) - gfx::Insets(5, 5, 0, -20); |
| 63 EXPECT_EQ(5, insets.top()); |
| 64 EXPECT_EQ(5, insets.left()); |
| 65 EXPECT_EQ(10, insets.bottom()); |
| 66 EXPECT_EQ(30, insets.right()); |
| 67 } |
| 68 |
| 69 TEST(InsetsFTest, Operators) { |
| 70 gfx::InsetsF insets; |
| 71 insets.Set(1.f, 2.5f, 3.3f, 4.1f); |
| 72 insets += gfx::InsetsF(5.8f, 6.7f, 7.6f, 8.5f); |
| 73 EXPECT_FLOAT_EQ(6.8f, insets.top()); |
| 74 EXPECT_FLOAT_EQ(9.2f, insets.left()); |
| 75 EXPECT_FLOAT_EQ(10.9f, insets.bottom()); |
| 76 EXPECT_FLOAT_EQ(12.6f, insets.right()); |
| 77 |
| 78 insets -= gfx::InsetsF(-1.f, 0, 1.1f, 2.2f); |
| 79 EXPECT_FLOAT_EQ(7.8f, insets.top()); |
| 80 EXPECT_FLOAT_EQ(9.2f, insets.left()); |
| 81 EXPECT_FLOAT_EQ(9.8f, insets.bottom()); |
| 82 EXPECT_FLOAT_EQ(10.4f, insets.right()); |
| 83 |
| 84 insets = gfx::InsetsF(10, 10.1f, 10.01f, 10.001f) + |
| 85 gfx::InsetsF(5.5f, 5.f, 0, -20.2f); |
| 86 EXPECT_FLOAT_EQ(15.5f, insets.top()); |
| 87 EXPECT_FLOAT_EQ(15.1f, insets.left()); |
| 88 EXPECT_FLOAT_EQ(10.01f, insets.bottom()); |
| 89 EXPECT_FLOAT_EQ(-10.199f, insets.right()); |
| 90 |
| 91 insets = gfx::InsetsF(10, 10.1f, 10.01f, 10.001f) - |
| 92 gfx::InsetsF(5.5f, 5.f, 0, -20.2f); |
| 93 EXPECT_FLOAT_EQ(4.5f, insets.top()); |
| 94 EXPECT_FLOAT_EQ(5.1f, insets.left()); |
| 95 EXPECT_FLOAT_EQ(10.01f, insets.bottom()); |
| 96 EXPECT_FLOAT_EQ(30.201f, insets.right()); |
48 } | 97 } |
49 | 98 |
50 TEST(InsetsTest, Equality) { | 99 TEST(InsetsTest, Equality) { |
51 gfx::Insets insets1; | 100 gfx::Insets insets1; |
52 insets1.Set(1, 2, 3, 4); | 101 insets1.Set(1, 2, 3, 4); |
53 gfx::Insets insets2; | 102 gfx::Insets insets2; |
54 // Test operator== and operator!=. | 103 // Test operator== and operator!=. |
55 EXPECT_FALSE(insets1 == insets2); | 104 EXPECT_FALSE(insets1 == insets2); |
56 EXPECT_TRUE(insets1 != insets2); | 105 EXPECT_TRUE(insets1 != insets2); |
57 | 106 |
58 insets2.Set(1, 2, 3, 4); | 107 insets2.Set(1, 2, 3, 4); |
59 EXPECT_TRUE(insets1 == insets2); | 108 EXPECT_TRUE(insets1 == insets2); |
60 EXPECT_FALSE(insets1 != insets2); | 109 EXPECT_FALSE(insets1 != insets2); |
61 } | 110 } |
62 | 111 |
63 TEST(InsetsTest, ToString) { | 112 TEST(InsetsTest, ToString) { |
64 gfx::Insets insets(1, 2, 3, 4); | 113 gfx::Insets insets(1, 2, 3, 4); |
65 EXPECT_EQ("1,2,3,4", insets.ToString()); | 114 EXPECT_EQ("1,2,3,4", insets.ToString()); |
66 } | 115 } |
OLD | NEW |