Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(712)

Side by Side Diff: ui/gfx/range/range_unittest.cc

Issue 24012002: Move Range code to gfx. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: d Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/range/range_mac_unittest.mm ('k') | ui/gfx/range/range_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "ui/base/range/range.h" 6 #include "ui/gfx/range/range.h"
7 7
8 TEST(RangeTest, EmptyInit) { 8 TEST(RangeTest, EmptyInit) {
9 ui::Range r; 9 gfx::Range r;
10 EXPECT_EQ(0U, r.start()); 10 EXPECT_EQ(0U, r.start());
11 EXPECT_EQ(0U, r.end()); 11 EXPECT_EQ(0U, r.end());
12 EXPECT_EQ(0U, r.length()); 12 EXPECT_EQ(0U, r.length());
13 EXPECT_FALSE(r.is_reversed()); 13 EXPECT_FALSE(r.is_reversed());
14 EXPECT_TRUE(r.is_empty()); 14 EXPECT_TRUE(r.is_empty());
15 EXPECT_TRUE(r.IsValid()); 15 EXPECT_TRUE(r.IsValid());
16 EXPECT_EQ(0U, r.GetMin()); 16 EXPECT_EQ(0U, r.GetMin());
17 EXPECT_EQ(0U, r.GetMax()); 17 EXPECT_EQ(0U, r.GetMax());
18 } 18 }
19 19
20 TEST(RangeTest, StartEndInit) { 20 TEST(RangeTest, StartEndInit) {
21 ui::Range r(10, 15); 21 gfx::Range r(10, 15);
22 EXPECT_EQ(10U, r.start()); 22 EXPECT_EQ(10U, r.start());
23 EXPECT_EQ(15U, r.end()); 23 EXPECT_EQ(15U, r.end());
24 EXPECT_EQ(5U, r.length()); 24 EXPECT_EQ(5U, r.length());
25 EXPECT_FALSE(r.is_reversed()); 25 EXPECT_FALSE(r.is_reversed());
26 EXPECT_FALSE(r.is_empty()); 26 EXPECT_FALSE(r.is_empty());
27 EXPECT_TRUE(r.IsValid()); 27 EXPECT_TRUE(r.IsValid());
28 EXPECT_EQ(10U, r.GetMin()); 28 EXPECT_EQ(10U, r.GetMin());
29 EXPECT_EQ(15U, r.GetMax()); 29 EXPECT_EQ(15U, r.GetMax());
30 } 30 }
31 31
32 TEST(RangeTest, StartEndReversedInit) { 32 TEST(RangeTest, StartEndReversedInit) {
33 ui::Range r(10, 5); 33 gfx::Range r(10, 5);
34 EXPECT_EQ(10U, r.start()); 34 EXPECT_EQ(10U, r.start());
35 EXPECT_EQ(5U, r.end()); 35 EXPECT_EQ(5U, r.end());
36 EXPECT_EQ(5U, r.length()); 36 EXPECT_EQ(5U, r.length());
37 EXPECT_TRUE(r.is_reversed()); 37 EXPECT_TRUE(r.is_reversed());
38 EXPECT_FALSE(r.is_empty()); 38 EXPECT_FALSE(r.is_empty());
39 EXPECT_TRUE(r.IsValid()); 39 EXPECT_TRUE(r.IsValid());
40 EXPECT_EQ(5U, r.GetMin()); 40 EXPECT_EQ(5U, r.GetMin());
41 EXPECT_EQ(10U, r.GetMax()); 41 EXPECT_EQ(10U, r.GetMax());
42 } 42 }
43 43
44 TEST(RangeTest, PositionInit) { 44 TEST(RangeTest, PositionInit) {
45 ui::Range r(12); 45 gfx::Range r(12);
46 EXPECT_EQ(12U, r.start()); 46 EXPECT_EQ(12U, r.start());
47 EXPECT_EQ(12U, r.end()); 47 EXPECT_EQ(12U, r.end());
48 EXPECT_EQ(0U, r.length()); 48 EXPECT_EQ(0U, r.length());
49 EXPECT_FALSE(r.is_reversed()); 49 EXPECT_FALSE(r.is_reversed());
50 EXPECT_TRUE(r.is_empty()); 50 EXPECT_TRUE(r.is_empty());
51 EXPECT_TRUE(r.IsValid()); 51 EXPECT_TRUE(r.IsValid());
52 EXPECT_EQ(12U, r.GetMin()); 52 EXPECT_EQ(12U, r.GetMin());
53 EXPECT_EQ(12U, r.GetMax()); 53 EXPECT_EQ(12U, r.GetMax());
54 } 54 }
55 55
56 TEST(RangeTest, InvalidRange) { 56 TEST(RangeTest, InvalidRange) {
57 ui::Range r(ui::Range::InvalidRange()); 57 gfx::Range r(gfx::Range::InvalidRange());
58 EXPECT_EQ(0U, r.length()); 58 EXPECT_EQ(0U, r.length());
59 EXPECT_EQ(r.start(), r.end()); 59 EXPECT_EQ(r.start(), r.end());
60 EXPECT_FALSE(r.is_reversed()); 60 EXPECT_FALSE(r.is_reversed());
61 EXPECT_TRUE(r.is_empty()); 61 EXPECT_TRUE(r.is_empty());
62 EXPECT_FALSE(r.IsValid()); 62 EXPECT_FALSE(r.IsValid());
63 } 63 }
64 64
65 TEST(RangeTest, Equality) { 65 TEST(RangeTest, Equality) {
66 ui::Range r1(10, 4); 66 gfx::Range r1(10, 4);
67 ui::Range r2(10, 4); 67 gfx::Range r2(10, 4);
68 ui::Range r3(10, 2); 68 gfx::Range r3(10, 2);
69 EXPECT_EQ(r1, r2); 69 EXPECT_EQ(r1, r2);
70 EXPECT_NE(r1, r3); 70 EXPECT_NE(r1, r3);
71 EXPECT_NE(r2, r3); 71 EXPECT_NE(r2, r3);
72 72
73 ui::Range r4(11, 4); 73 gfx::Range r4(11, 4);
74 EXPECT_NE(r1, r4); 74 EXPECT_NE(r1, r4);
75 EXPECT_NE(r2, r4); 75 EXPECT_NE(r2, r4);
76 EXPECT_NE(r3, r4); 76 EXPECT_NE(r3, r4);
77 77
78 ui::Range r5(12, 5); 78 gfx::Range r5(12, 5);
79 EXPECT_NE(r1, r5); 79 EXPECT_NE(r1, r5);
80 EXPECT_NE(r2, r5); 80 EXPECT_NE(r2, r5);
81 EXPECT_NE(r3, r5); 81 EXPECT_NE(r3, r5);
82 } 82 }
83 83
84 TEST(RangeTest, EqualsIgnoringDirection) { 84 TEST(RangeTest, EqualsIgnoringDirection) {
85 ui::Range r1(10, 5); 85 gfx::Range r1(10, 5);
86 ui::Range r2(5, 10); 86 gfx::Range r2(5, 10);
87 EXPECT_TRUE(r1.EqualsIgnoringDirection(r2)); 87 EXPECT_TRUE(r1.EqualsIgnoringDirection(r2));
88 } 88 }
89 89
90 TEST(RangeTest, SetStart) { 90 TEST(RangeTest, SetStart) {
91 ui::Range r(10, 20); 91 gfx::Range r(10, 20);
92 EXPECT_EQ(10U, r.start()); 92 EXPECT_EQ(10U, r.start());
93 EXPECT_EQ(10U, r.length()); 93 EXPECT_EQ(10U, r.length());
94 94
95 r.set_start(42); 95 r.set_start(42);
96 EXPECT_EQ(42U, r.start()); 96 EXPECT_EQ(42U, r.start());
97 EXPECT_EQ(20U, r.end()); 97 EXPECT_EQ(20U, r.end());
98 EXPECT_EQ(22U, r.length()); 98 EXPECT_EQ(22U, r.length());
99 EXPECT_TRUE(r.is_reversed()); 99 EXPECT_TRUE(r.is_reversed());
100 } 100 }
101 101
102 TEST(RangeTest, SetEnd) { 102 TEST(RangeTest, SetEnd) {
103 ui::Range r(10, 13); 103 gfx::Range r(10, 13);
104 EXPECT_EQ(10U, r.start()); 104 EXPECT_EQ(10U, r.start());
105 EXPECT_EQ(3U, r.length()); 105 EXPECT_EQ(3U, r.length());
106 106
107 r.set_end(20); 107 r.set_end(20);
108 EXPECT_EQ(10U, r.start()); 108 EXPECT_EQ(10U, r.start());
109 EXPECT_EQ(20U, r.end()); 109 EXPECT_EQ(20U, r.end());
110 EXPECT_EQ(10U, r.length()); 110 EXPECT_EQ(10U, r.length());
111 } 111 }
112 112
113 TEST(RangeTest, SetStartAndEnd) { 113 TEST(RangeTest, SetStartAndEnd) {
114 ui::Range r; 114 gfx::Range r;
115 r.set_end(5); 115 r.set_end(5);
116 r.set_start(1); 116 r.set_start(1);
117 EXPECT_EQ(1U, r.start()); 117 EXPECT_EQ(1U, r.start());
118 EXPECT_EQ(5U, r.end()); 118 EXPECT_EQ(5U, r.end());
119 EXPECT_EQ(4U, r.length()); 119 EXPECT_EQ(4U, r.length());
120 EXPECT_EQ(1U, r.GetMin()); 120 EXPECT_EQ(1U, r.GetMin());
121 EXPECT_EQ(5U, r.GetMax()); 121 EXPECT_EQ(5U, r.GetMax());
122 } 122 }
123 123
124 TEST(RangeTest, ReversedRange) { 124 TEST(RangeTest, ReversedRange) {
125 ui::Range r(10, 5); 125 gfx::Range r(10, 5);
126 EXPECT_EQ(10U, r.start()); 126 EXPECT_EQ(10U, r.start());
127 EXPECT_EQ(5U, r.end()); 127 EXPECT_EQ(5U, r.end());
128 EXPECT_EQ(5U, r.length()); 128 EXPECT_EQ(5U, r.length());
129 EXPECT_TRUE(r.is_reversed()); 129 EXPECT_TRUE(r.is_reversed());
130 EXPECT_TRUE(r.IsValid()); 130 EXPECT_TRUE(r.IsValid());
131 EXPECT_EQ(5U, r.GetMin()); 131 EXPECT_EQ(5U, r.GetMin());
132 EXPECT_EQ(10U, r.GetMax()); 132 EXPECT_EQ(10U, r.GetMax());
133 } 133 }
134 134
135 TEST(RangeTest, SetReversedRange) { 135 TEST(RangeTest, SetReversedRange) {
136 ui::Range r(10, 20); 136 gfx::Range r(10, 20);
137 r.set_start(25); 137 r.set_start(25);
138 EXPECT_EQ(25U, r.start()); 138 EXPECT_EQ(25U, r.start());
139 EXPECT_EQ(20U, r.end()); 139 EXPECT_EQ(20U, r.end());
140 EXPECT_EQ(5U, r.length()); 140 EXPECT_EQ(5U, r.length());
141 EXPECT_TRUE(r.is_reversed()); 141 EXPECT_TRUE(r.is_reversed());
142 EXPECT_TRUE(r.IsValid()); 142 EXPECT_TRUE(r.IsValid());
143 143
144 r.set_end(21); 144 r.set_end(21);
145 EXPECT_EQ(25U, r.start()); 145 EXPECT_EQ(25U, r.start());
146 EXPECT_EQ(21U, r.end()); 146 EXPECT_EQ(21U, r.end());
147 EXPECT_EQ(4U, r.length()); 147 EXPECT_EQ(4U, r.length());
148 EXPECT_TRUE(r.IsValid()); 148 EXPECT_TRUE(r.IsValid());
149 EXPECT_EQ(21U, r.GetMin()); 149 EXPECT_EQ(21U, r.GetMin());
150 EXPECT_EQ(25U, r.GetMax()); 150 EXPECT_EQ(25U, r.GetMax());
151 } 151 }
152 152
153 void TestContainsAndIntersects(const ui::Range& r1, 153 void TestContainsAndIntersects(const gfx::Range& r1,
154 const ui::Range& r2, 154 const gfx::Range& r2,
155 const ui::Range& r3) { 155 const gfx::Range& r3) {
156 EXPECT_TRUE(r1.Intersects(r1)); 156 EXPECT_TRUE(r1.Intersects(r1));
157 EXPECT_TRUE(r1.Contains(r1)); 157 EXPECT_TRUE(r1.Contains(r1));
158 EXPECT_EQ(ui::Range(10, 12), r1.Intersect(r1)); 158 EXPECT_EQ(gfx::Range(10, 12), r1.Intersect(r1));
159 159
160 EXPECT_FALSE(r1.Intersects(r2)); 160 EXPECT_FALSE(r1.Intersects(r2));
161 EXPECT_FALSE(r1.Contains(r2)); 161 EXPECT_FALSE(r1.Contains(r2));
162 EXPECT_TRUE(r1.Intersect(r2).is_empty()); 162 EXPECT_TRUE(r1.Intersect(r2).is_empty());
163 EXPECT_FALSE(r2.Intersects(r1)); 163 EXPECT_FALSE(r2.Intersects(r1));
164 EXPECT_FALSE(r2.Contains(r1)); 164 EXPECT_FALSE(r2.Contains(r1));
165 EXPECT_TRUE(r2.Intersect(r1).is_empty()); 165 EXPECT_TRUE(r2.Intersect(r1).is_empty());
166 166
167 EXPECT_TRUE(r1.Intersects(r3)); 167 EXPECT_TRUE(r1.Intersects(r3));
168 EXPECT_TRUE(r3.Intersects(r1)); 168 EXPECT_TRUE(r3.Intersects(r1));
169 EXPECT_TRUE(r3.Contains(r1)); 169 EXPECT_TRUE(r3.Contains(r1));
170 EXPECT_FALSE(r1.Contains(r3)); 170 EXPECT_FALSE(r1.Contains(r3));
171 EXPECT_EQ(ui::Range(10, 12), r1.Intersect(r3)); 171 EXPECT_EQ(gfx::Range(10, 12), r1.Intersect(r3));
172 EXPECT_EQ(ui::Range(10, 12), r3.Intersect(r1)); 172 EXPECT_EQ(gfx::Range(10, 12), r3.Intersect(r1));
173 173
174 EXPECT_TRUE(r2.Intersects(r3)); 174 EXPECT_TRUE(r2.Intersects(r3));
175 EXPECT_TRUE(r3.Intersects(r2)); 175 EXPECT_TRUE(r3.Intersects(r2));
176 EXPECT_FALSE(r3.Contains(r2)); 176 EXPECT_FALSE(r3.Contains(r2));
177 EXPECT_FALSE(r2.Contains(r3)); 177 EXPECT_FALSE(r2.Contains(r3));
178 EXPECT_EQ(ui::Range(5, 8), r2.Intersect(r3)); 178 EXPECT_EQ(gfx::Range(5, 8), r2.Intersect(r3));
179 EXPECT_EQ(ui::Range(5, 8), r3.Intersect(r2)); 179 EXPECT_EQ(gfx::Range(5, 8), r3.Intersect(r2));
180 } 180 }
181 181
182 TEST(RangeTest, ContainAndIntersect) { 182 TEST(RangeTest, ContainAndIntersect) {
183 { 183 {
184 SCOPED_TRACE("contain and intersect"); 184 SCOPED_TRACE("contain and intersect");
185 ui::Range r1(10, 12); 185 gfx::Range r1(10, 12);
186 ui::Range r2(1, 8); 186 gfx::Range r2(1, 8);
187 ui::Range r3(5, 12); 187 gfx::Range r3(5, 12);
188 TestContainsAndIntersects(r1, r2, r3); 188 TestContainsAndIntersects(r1, r2, r3);
189 } 189 }
190 { 190 {
191 SCOPED_TRACE("contain and intersect: reversed"); 191 SCOPED_TRACE("contain and intersect: reversed");
192 ui::Range r1(12, 10); 192 gfx::Range r1(12, 10);
193 ui::Range r2(8, 1); 193 gfx::Range r2(8, 1);
194 ui::Range r3(12, 5); 194 gfx::Range r3(12, 5);
195 TestContainsAndIntersects(r1, r2, r3); 195 TestContainsAndIntersects(r1, r2, r3);
196 } 196 }
197 // Invalid rect tests 197 // Invalid rect tests
198 ui::Range r1(10, 12); 198 gfx::Range r1(10, 12);
199 ui::Range r2(8, 1); 199 gfx::Range r2(8, 1);
200 ui::Range invalid = r1.Intersect(r2); 200 gfx::Range invalid = r1.Intersect(r2);
201 EXPECT_FALSE(invalid.IsValid()); 201 EXPECT_FALSE(invalid.IsValid());
202 EXPECT_FALSE(invalid.Contains(invalid)); 202 EXPECT_FALSE(invalid.Contains(invalid));
203 EXPECT_FALSE(invalid.Contains(r1)); 203 EXPECT_FALSE(invalid.Contains(r1));
204 EXPECT_FALSE(invalid.Intersects(invalid)); 204 EXPECT_FALSE(invalid.Intersects(invalid));
205 EXPECT_FALSE(invalid.Intersects(r1)); 205 EXPECT_FALSE(invalid.Intersects(r1));
206 EXPECT_FALSE(r1.Contains(invalid)); 206 EXPECT_FALSE(r1.Contains(invalid));
207 EXPECT_FALSE(r1.Intersects(invalid)); 207 EXPECT_FALSE(r1.Intersects(invalid));
208 } 208 }
OLDNEW
« no previous file with comments | « ui/gfx/range/range_mac_unittest.mm ('k') | ui/gfx/range/range_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698