OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <limits> | 5 #include <limits> |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 EXPECT_FLOAT_EQ( | 908 EXPECT_FLOAT_EQ( |
909 0.0f, f.ManhattanInternalDistance(gfx::RectF(-1.0f, 0.0f, 1.1f, 1.0f))); | 909 0.0f, f.ManhattanInternalDistance(gfx::RectF(-1.0f, 0.0f, 1.1f, 1.0f))); |
910 EXPECT_FLOAT_EQ( | 910 EXPECT_FLOAT_EQ( |
911 0.1f + kEpsilon, | 911 0.1f + kEpsilon, |
912 f.ManhattanInternalDistance(gfx::RectF(-1.5f, 0.0f, 1.4f, 1.0f))); | 912 f.ManhattanInternalDistance(gfx::RectF(-1.5f, 0.0f, 1.4f, 1.0f))); |
913 EXPECT_FLOAT_EQ( | 913 EXPECT_FLOAT_EQ( |
914 kEpsilon, | 914 kEpsilon, |
915 f.ManhattanInternalDistance(gfx::RectF(-1.5f, 0.0f, 1.5f, 1.0f))); | 915 f.ManhattanInternalDistance(gfx::RectF(-1.5f, 0.0f, 1.5f, 1.0f))); |
916 } | 916 } |
917 | 917 |
| 918 TEST(RectTest, IntegerOverflow) { |
| 919 int expected = 10; |
| 920 int large_number = std::numeric_limits<int>::max() - expected; |
| 921 |
| 922 Rect height_overflow(0, large_number, 100, 100); |
| 923 EXPECT_EQ(large_number, height_overflow.y()); |
| 924 EXPECT_EQ(expected, height_overflow.height()); |
| 925 |
| 926 Rect width_overflow(large_number, 0, 100, 100); |
| 927 EXPECT_EQ(large_number, width_overflow.x()); |
| 928 EXPECT_EQ(expected, width_overflow.width()); |
| 929 |
| 930 Rect size_height_overflow(Point(0, large_number), Size(100, 100)); |
| 931 EXPECT_EQ(large_number, size_height_overflow.y()); |
| 932 EXPECT_EQ(expected, size_height_overflow.height()); |
| 933 |
| 934 Rect size_width_overflow(Point(large_number, 0), Size(100, 100)); |
| 935 EXPECT_EQ(large_number, size_width_overflow.x()); |
| 936 EXPECT_EQ(expected, size_width_overflow.width()); |
| 937 |
| 938 Rect set_height_overflow(0, large_number, 100, 5); |
| 939 EXPECT_EQ(5, set_height_overflow.height()); |
| 940 set_height_overflow.set_height(100); |
| 941 EXPECT_EQ(expected, set_height_overflow.height()); |
| 942 |
| 943 Rect set_y_overflow(100, 100, 100, 100); |
| 944 EXPECT_EQ(100, set_y_overflow.height()); |
| 945 set_y_overflow.set_y(large_number); |
| 946 EXPECT_EQ(expected, set_y_overflow.height()); |
| 947 |
| 948 Rect set_width_overflow(large_number, 0, 5, 100); |
| 949 EXPECT_EQ(5, set_width_overflow.width()); |
| 950 set_width_overflow.set_width(100); |
| 951 EXPECT_EQ(expected, set_width_overflow.width()); |
| 952 |
| 953 Rect set_x_overflow(100, 100, 100, 100); |
| 954 EXPECT_EQ(100, set_x_overflow.width()); |
| 955 set_x_overflow.set_x(large_number); |
| 956 EXPECT_EQ(expected, set_x_overflow.width()); |
| 957 |
| 958 Point large_offset(large_number, large_number); |
| 959 Size size(100, 100); |
| 960 Size expected_size(10, 10); |
| 961 |
| 962 Rect set_origin_overflow(100, 100, 100, 100); |
| 963 EXPECT_EQ(size, set_origin_overflow.size()); |
| 964 set_origin_overflow.set_origin(large_offset); |
| 965 EXPECT_EQ(large_offset, set_origin_overflow.origin()); |
| 966 EXPECT_EQ(expected_size, set_origin_overflow.size()); |
| 967 |
| 968 Rect set_size_overflow(large_number, large_number, 5, 5); |
| 969 EXPECT_EQ(Size(5, 5), set_size_overflow.size()); |
| 970 set_size_overflow.set_size(size); |
| 971 EXPECT_EQ(large_offset, set_size_overflow.origin()); |
| 972 EXPECT_EQ(expected_size, set_size_overflow.size()); |
| 973 |
| 974 Rect set_rect_overflow; |
| 975 set_rect_overflow.SetRect(large_number, large_number, 100, 100); |
| 976 EXPECT_EQ(large_offset, set_rect_overflow.origin()); |
| 977 EXPECT_EQ(expected_size, set_rect_overflow.size()); |
| 978 |
| 979 Rect inset_overflow; |
| 980 inset_overflow.Inset(large_number, large_number, 100, 100); |
| 981 EXPECT_EQ(large_offset, inset_overflow.origin()); |
| 982 EXPECT_EQ(expected_size, inset_overflow.size()); |
| 983 |
| 984 Rect offset_overflow(0, 0, 100, 100); |
| 985 offset_overflow.Offset(large_number, large_number); |
| 986 EXPECT_EQ(large_offset, offset_overflow.origin()); |
| 987 EXPECT_EQ(expected_size, offset_overflow.size()); |
| 988 |
| 989 Rect operator_overflow(0, 0, 100, 100); |
| 990 operator_overflow += Vector2d(large_number, large_number); |
| 991 EXPECT_EQ(large_offset, operator_overflow.origin()); |
| 992 EXPECT_EQ(expected_size, operator_overflow.size()); |
| 993 } |
| 994 |
918 } // namespace gfx | 995 } // namespace gfx |
OLD | NEW |