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

Side by Side Diff: ui/gfx/geometry/size_unittest.cc

Issue 2354783004: Fix overflow/underflow in gfx geometry once and for all (Closed)
Patch Set: Remove accessibility test changes Created 4 years, 2 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
« no previous file with comments | « ui/gfx/geometry/size.cc ('k') | ui/gfx/geometry/vector2d.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/gfx/geometry/size.h" 6 #include "ui/gfx/geometry/size.h"
7 #include "ui/gfx/geometry/size_conversions.h" 7 #include "ui/gfx/geometry/size_conversions.h"
8 #include "ui/gfx/geometry/size_f.h" 8 #include "ui/gfx/geometry/size_f.h"
9 9
10 namespace gfx { 10 namespace gfx {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 a.SetToMin(SizeF(8.5f, 10.5f)); 115 a.SetToMin(SizeF(8.5f, 10.5f));
116 EXPECT_EQ(SizeF(8.5f, 10.5f).ToString(), a.ToString()); 116 EXPECT_EQ(SizeF(8.5f, 10.5f).ToString(), a.ToString());
117 a.SetToMin(SizeF(11.5f, 9.5f)); 117 a.SetToMin(SizeF(11.5f, 9.5f));
118 EXPECT_EQ(SizeF(8.5f, 9.5f).ToString(), a.ToString()); 118 EXPECT_EQ(SizeF(8.5f, 9.5f).ToString(), a.ToString());
119 a.SetToMin(SizeF(7.5f, 11.5f)); 119 a.SetToMin(SizeF(7.5f, 11.5f));
120 EXPECT_EQ(SizeF(7.5f, 9.5f).ToString(), a.ToString()); 120 EXPECT_EQ(SizeF(7.5f, 9.5f).ToString(), a.ToString());
121 a.SetToMin(SizeF(3.5f, 5.5f)); 121 a.SetToMin(SizeF(3.5f, 5.5f));
122 EXPECT_EQ(SizeF(3.5f, 5.5f).ToString(), a.ToString()); 122 EXPECT_EQ(SizeF(3.5f, 5.5f).ToString(), a.ToString());
123 } 123 }
124 124
125 TEST(SizeTest, Enlarge) {
126 Size test(3, 4);
127 test.Enlarge(5, -8);
128 EXPECT_EQ(test, Size(8, -4));
129 }
130
131 TEST(SizeTest, IntegerOverflow) {
132 int int_max = std::numeric_limits<int>::max();
133 int int_min = std::numeric_limits<int>::min();
134
135 Size max_size(int_max, int_max);
136 Size min_size(int_min, int_min);
137 Size test;
138
139 test = Size();
140 test.Enlarge(int_max, int_max);
141 EXPECT_EQ(test, max_size);
142
143 test = Size();
144 test.Enlarge(int_min, int_min);
145 EXPECT_EQ(test, min_size);
146
147 test = Size(10, 20);
148 test.Enlarge(int_max, int_max);
149 EXPECT_EQ(test, max_size);
150
151 test = Size(-10, -20);
152 test.Enlarge(int_min, int_min);
153 EXPECT_EQ(test, min_size);
154 }
155
125 } // namespace gfx 156 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/geometry/size.cc ('k') | ui/gfx/geometry/vector2d.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698