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

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

Powered by Google App Engine
This is Rietveld 408576698