Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / gfx / geometry / box_unittest.cc
blob449c50f9a48c1bd1d2b5cb2018ca0754c457c438
1 // Copyright 2013 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.
5 #include "base/basictypes.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "ui/gfx/geometry/box_f.h"
9 namespace gfx {
11 TEST(BoxTest, Constructors) {
12 EXPECT_EQ(BoxF(0.f, 0.f, 0.f, 0.f, 0.f, 0.f).ToString(),
13 BoxF().ToString());
14 EXPECT_EQ(BoxF(0.f, 0.f, 0.f, -3.f, -5.f, -7.f).ToString(),
15 BoxF().ToString());
17 EXPECT_EQ(BoxF(0.f, 0.f, 0.f, 3.f, 5.f, 7.f).ToString(),
18 BoxF(3.f, 5.f, 7.f).ToString());
19 EXPECT_EQ(BoxF(0.f, 0.f, 0.f, 0.f, 0.f, 0.f).ToString(),
20 BoxF(-3.f, -5.f, -7.f).ToString());
22 EXPECT_EQ(BoxF(2.f, 4.f, 6.f, 3.f, 5.f, 7.f).ToString(),
23 BoxF(Point3F(2.f, 4.f, 6.f), 3.f, 5.f, 7.f).ToString());
24 EXPECT_EQ(BoxF(2.f, 4.f, 6.f, 0.f, 0.f, 0.f).ToString(),
25 BoxF(Point3F(2.f, 4.f, 6.f), -3.f, -5.f, -7.f).ToString());
28 TEST(BoxTest, IsEmpty) {
29 EXPECT_TRUE(BoxF(0.f, 0.f, 0.f, 0.f, 0.f, 0.f).IsEmpty());
30 EXPECT_TRUE(BoxF(1.f, 2.f, 3.f, 0.f, 0.f, 0.f).IsEmpty());
32 EXPECT_TRUE(BoxF(0.f, 0.f, 0.f, 2.f, 0.f, 0.f).IsEmpty());
33 EXPECT_TRUE(BoxF(1.f, 2.f, 3.f, 2.f, 0.f, 0.f).IsEmpty());
34 EXPECT_TRUE(BoxF(0.f, 0.f, 0.f, 0.f, 2.f, 0.f).IsEmpty());
35 EXPECT_TRUE(BoxF(1.f, 2.f, 3.f, 0.f, 2.f, 0.f).IsEmpty());
36 EXPECT_TRUE(BoxF(0.f, 0.f, 0.f, 0.f, 0.f, 2.f).IsEmpty());
37 EXPECT_TRUE(BoxF(1.f, 2.f, 3.f, 0.f, 0.f, 2.f).IsEmpty());
39 EXPECT_FALSE(BoxF(0.f, 0.f, 0.f, 0.f, 2.f, 2.f).IsEmpty());
40 EXPECT_FALSE(BoxF(1.f, 2.f, 3.f, 0.f, 2.f, 2.f).IsEmpty());
41 EXPECT_FALSE(BoxF(0.f, 0.f, 0.f, 2.f, 0.f, 2.f).IsEmpty());
42 EXPECT_FALSE(BoxF(1.f, 2.f, 3.f, 2.f, 0.f, 2.f).IsEmpty());
43 EXPECT_FALSE(BoxF(0.f, 0.f, 0.f, 2.f, 2.f, 0.f).IsEmpty());
44 EXPECT_FALSE(BoxF(1.f, 2.f, 3.f, 2.f, 2.f, 0.f).IsEmpty());
46 EXPECT_FALSE(BoxF(0.f, 0.f, 0.f, 2.f, 2.f, 2.f).IsEmpty());
47 EXPECT_FALSE(BoxF(1.f, 2.f, 3.f, 2.f, 2.f, 2.f).IsEmpty());
50 TEST(BoxTest, Union) {
51 BoxF empty_box;
52 BoxF box1(0.f, 0.f, 0.f, 1.f, 1.f, 1.f);
53 BoxF box2(0.f, 0.f, 0.f, 4.f, 6.f, 8.f);
54 BoxF box3(3.f, 4.f, 5.f, 6.f, 4.f, 0.f);
56 EXPECT_EQ(empty_box.ToString(), UnionBoxes(empty_box, empty_box).ToString());
57 EXPECT_EQ(box1.ToString(), UnionBoxes(empty_box, box1).ToString());
58 EXPECT_EQ(box1.ToString(), UnionBoxes(box1, empty_box).ToString());
59 EXPECT_EQ(box2.ToString(), UnionBoxes(empty_box, box2).ToString());
60 EXPECT_EQ(box2.ToString(), UnionBoxes(box2, empty_box).ToString());
61 EXPECT_EQ(box3.ToString(), UnionBoxes(empty_box, box3).ToString());
62 EXPECT_EQ(box3.ToString(), UnionBoxes(box3, empty_box).ToString());
64 // box_1 is contained in box_2
65 EXPECT_EQ(box2.ToString(), UnionBoxes(box1, box2).ToString());
66 EXPECT_EQ(box2.ToString(), UnionBoxes(box2, box1).ToString());
68 // box_1 and box_3 are disjoint
69 EXPECT_EQ(BoxF(0.f, 0.f, 0.f, 9.f, 8.f, 5.f).ToString(),
70 UnionBoxes(box1, box3).ToString());
71 EXPECT_EQ(BoxF(0.f, 0.f, 0.f, 9.f, 8.f, 5.f).ToString(),
72 UnionBoxes(box3, box1).ToString());
74 // box_2 and box_3 intersect, but neither contains the other
75 EXPECT_EQ(BoxF(0.f, 0.f, 0.f, 9.f, 8.f, 8.f).ToString(),
76 UnionBoxes(box2, box3).ToString());
77 EXPECT_EQ(BoxF(0.f, 0.f, 0.f, 9.f, 8.f, 8.f).ToString(),
78 UnionBoxes(box3, box2).ToString());
81 TEST(BoxTest, ExpandTo) {
82 BoxF box1;
83 BoxF box2(0.f, 0.f, 0.f, 1.f, 1.f, 1.f);
84 BoxF box3(1.f, 1.f, 1.f, 0.f, 0.f, 0.f);
86 Point3F point1(0.5f, 0.5f, 0.5f);
87 Point3F point2(-0.5f, -0.5f, -0.5f);
89 BoxF expected1_1(0.f, 0.f, 0.f, 0.5f, 0.5f, 0.5f);
90 BoxF expected1_2(-0.5f, -0.5f, -0.5f, 1.f, 1.f, 1.f);
92 BoxF expected2_1 = box2;
93 BoxF expected2_2(-0.5f, -0.5f, -0.5f, 1.5f, 1.5f, 1.5f);
95 BoxF expected3_1(0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f);
96 BoxF expected3_2(-0.5f, -0.5f, -0.5f, 1.5f, 1.5f, 1.5f);
98 box1.ExpandTo(point1);
99 EXPECT_EQ(expected1_1.ToString(), box1.ToString());
100 box1.ExpandTo(point2);
101 EXPECT_EQ(expected1_2.ToString(), box1.ToString());
103 box2.ExpandTo(point1);
104 EXPECT_EQ(expected2_1.ToString(), box2.ToString());
105 box2.ExpandTo(point2);
106 EXPECT_EQ(expected2_2.ToString(), box2.ToString());
108 box3.ExpandTo(point1);
109 EXPECT_EQ(expected3_1.ToString(), box3.ToString());
110 box3.ExpandTo(point2);
111 EXPECT_EQ(expected3_2.ToString(), box3.ToString());
114 TEST(BoxTest, Scale) {
115 BoxF box1(2.f, 3.f, 4.f, 5.f, 6.f, 7.f);
117 EXPECT_EQ(BoxF().ToString(), ScaleBox(box1, 0.f).ToString());
118 EXPECT_EQ(box1.ToString(), ScaleBox(box1, 1.f).ToString());
119 EXPECT_EQ(BoxF(4.f, 12.f, 24.f, 10.f, 24.f, 42.f).ToString(),
120 ScaleBox(box1, 2.f, 4.f, 6.f).ToString());
122 BoxF box2 = box1;
123 box2.Scale(0.f);
124 EXPECT_EQ(BoxF().ToString(), box2.ToString());
126 box2 = box1;
127 box2.Scale(1.f);
128 EXPECT_EQ(box1.ToString(), box2.ToString());
130 box2.Scale(2.f, 4.f, 6.f);
131 EXPECT_EQ(BoxF(4.f, 12.f, 24.f, 10.f, 24.f, 42.f).ToString(),
132 box2.ToString());
135 TEST(BoxTest, Equals) {
136 EXPECT_TRUE(BoxF() == BoxF());
137 EXPECT_TRUE(BoxF(2.f, 3.f, 4.f, 6.f, 8.f, 10.f) ==
138 BoxF(2.f, 3.f, 4.f, 6.f, 8.f, 10.f));
139 EXPECT_FALSE(BoxF() == BoxF(0.f, 0.f, 0.f, 0.f, 0.f, 1.f));
140 EXPECT_FALSE(BoxF() == BoxF(0.f, 0.f, 0.f, 0.f, 1.f, 0.f));
141 EXPECT_FALSE(BoxF() == BoxF(0.f, 0.f, 0.f, 1.f, 0.f, 0.f));
142 EXPECT_FALSE(BoxF() == BoxF(0.f, 0.f, 1.f, 0.f, 0.f, 0.f));
143 EXPECT_FALSE(BoxF() == BoxF(0.f, 1.f, 0.f, 0.f, 0.f, 0.f));
144 EXPECT_FALSE(BoxF() == BoxF(1.f, 0.f, 0.f, 0.f, 0.f, 0.f));
147 TEST(BoxTest, NotEquals) {
148 EXPECT_FALSE(BoxF() != BoxF());
149 EXPECT_FALSE(BoxF(2.f, 3.f, 4.f, 6.f, 8.f, 10.f) !=
150 BoxF(2.f, 3.f, 4.f, 6.f, 8.f, 10.f));
151 EXPECT_TRUE(BoxF() != BoxF(0.f, 0.f, 0.f, 0.f, 0.f, 1.f));
152 EXPECT_TRUE(BoxF() != BoxF(0.f, 0.f, 0.f, 0.f, 1.f, 0.f));
153 EXPECT_TRUE(BoxF() != BoxF(0.f, 0.f, 0.f, 1.f, 0.f, 0.f));
154 EXPECT_TRUE(BoxF() != BoxF(0.f, 0.f, 1.f, 0.f, 0.f, 0.f));
155 EXPECT_TRUE(BoxF() != BoxF(0.f, 1.f, 0.f, 0.f, 0.f, 0.f));
156 EXPECT_TRUE(BoxF() != BoxF(1.f, 0.f, 0.f, 0.f, 0.f, 0.f));
160 TEST(BoxTest, Offset) {
161 BoxF box1(2.f, 3.f, 4.f, 5.f, 6.f, 7.f);
163 EXPECT_EQ(box1.ToString(), (box1 + Vector3dF(0.f, 0.f, 0.f)).ToString());
164 EXPECT_EQ(BoxF(3.f, 1.f, 0.f, 5.f, 6.f, 7.f).ToString(),
165 (box1 + Vector3dF(1.f, -2.f, -4.f)).ToString());
167 BoxF box2 = box1;
168 box2 += Vector3dF(0.f, 0.f, 0.f);
169 EXPECT_EQ(box1.ToString(), box2.ToString());
171 box2 += Vector3dF(1.f, -2.f, -4.f);
172 EXPECT_EQ(BoxF(3.f, 1.f, 0.f, 5.f, 6.f, 7.f).ToString(),
173 box2.ToString());
176 } // namespace gfx