Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corefx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis "D.C." Dietrich <dennisdietrich@users.noreply.github.com>2017-02-07 19:44:18 +0300
committerTarek Mahmoud Sayed <tarekms@microsoft.com>2017-02-07 19:44:18 +0300
commit8f824ba00f5656436f7063da49fb0ac94eff8566 (patch)
treeb713833014fffd8206f5628c66fd9a2e6013527f /src/System.Drawing.Primitives/tests
parentb9e51257e5409f77af2cb3d2566593e97eefba7a (diff)
Marking code as unchecked (pt 2) (#15885)
Marking code that may intentionally lead to over or underflows with unchecked in preparation of turning on CheckForOverflowUnderflow for all projects (issue #3140)
Diffstat (limited to 'src/System.Drawing.Primitives/tests')
-rw-r--r--src/System.Drawing.Primitives/tests/PointTests.cs24
-rw-r--r--src/System.Drawing.Primitives/tests/RectangleTests.cs39
-rw-r--r--src/System.Drawing.Primitives/tests/SizeFTests.cs2
-rw-r--r--src/System.Drawing.Primitives/tests/SizeTests.cs21
4 files changed, 57 insertions, 29 deletions
diff --git a/src/System.Drawing.Primitives/tests/PointTests.cs b/src/System.Drawing.Primitives/tests/PointTests.cs
index 0f38a0ca64..520cd7c491 100644
--- a/src/System.Drawing.Primitives/tests/PointTests.cs
+++ b/src/System.Drawing.Primitives/tests/PointTests.cs
@@ -35,7 +35,7 @@ namespace System.Drawing.PrimitivesTests
public void SingleIntConstructorTest(int x)
{
Point p1 = new Point(x);
- Point p2 = new Point((short)(x & 0xFFFF), (short)((x >> 16) & 0xFFFF));
+ Point p2 = new Point(unchecked((short)(x & 0xFFFF)), unchecked((short)((x >> 16) & 0xFFFF)));
Assert.Equal(p1, p2);
}
@@ -98,11 +98,14 @@ namespace System.Drawing.PrimitivesTests
[InlineData(0, 0)]
public void ArithmeticTest(int x, int y)
{
- Point p = new Point(x, y);
+ Point addExpected, subExpected, p = new Point(x, y);
Size s = new Size(y, x);
- Point addExpected = new Point(x + y, y + x);
- Point subExpected = new Point(x - y, y - x);
+ unchecked
+ {
+ addExpected = new Point(x + y, y + x);
+ subExpected = new Point(x - y, y - x);
+ }
Assert.Equal(addExpected, p + s);
Assert.Equal(subExpected, p - s);
@@ -118,9 +121,14 @@ namespace System.Drawing.PrimitivesTests
public void PointFMathematicalTest(float x, float y)
{
PointF pf = new PointF(x, y);
- Point pCeiling = new Point((int)Math.Ceiling(x), (int)Math.Ceiling(y));
- Point pTruncate = new Point((int)x, (int)y);
- Point pRound = new Point((int)Math.Round(x), (int)Math.Round(y));
+ Point pCeiling, pTruncate, pRound;
+
+ unchecked
+ {
+ pCeiling = new Point((int)Math.Ceiling(x), (int)Math.Ceiling(y));
+ pTruncate = new Point((int)x, (int)y);
+ pRound = new Point((int)Math.Round(x), (int)Math.Round(y));
+ }
Assert.Equal(pCeiling, Point.Ceiling(pf));
Assert.Equal(pRound, Point.Round(pf));
@@ -139,7 +147,7 @@ namespace System.Drawing.PrimitivesTests
p1.Offset(p2);
- Assert.Equal(p2.X + p2.Y, p1.X);
+ Assert.Equal(unchecked(p2.X + p2.Y), p1.X);
Assert.Equal(p1.X, p1.Y);
p2.Offset(x, y);
diff --git a/src/System.Drawing.Primitives/tests/RectangleTests.cs b/src/System.Drawing.Primitives/tests/RectangleTests.cs
index b5bf6a0805..c04cdab224 100644
--- a/src/System.Drawing.Primitives/tests/RectangleTests.cs
+++ b/src/System.Drawing.Primitives/tests/RectangleTests.cs
@@ -35,7 +35,7 @@ namespace System.Drawing.PrimitivesTest
[InlineData(0, int.MinValue, 0, int.MaxValue)]
public void FromLTRBTest(int left, int top, int right, int bottom)
{
- Rectangle rect1 = new Rectangle(left, top, right - left, bottom - top);
+ Rectangle rect1 = new Rectangle(left, top, unchecked(right - left), unchecked(bottom - top));
Rectangle rect2 = Rectangle.FromLTRB(left, top, right, bottom);
Assert.Equal(rect1, rect2);
@@ -77,8 +77,8 @@ namespace System.Drawing.PrimitivesTest
Assert.Equal(height, rect.Height);
Assert.Equal(x, rect.Left);
Assert.Equal(y, rect.Top);
- Assert.Equal(x + width, rect.Right);
- Assert.Equal(y + height, rect.Bottom);
+ Assert.Equal(unchecked(x + width), rect.Right);
+ Assert.Equal(unchecked(y + height), rect.Bottom);
Point p = new Point(width, height);
Size s = new Size(x, y);
@@ -94,8 +94,8 @@ namespace System.Drawing.PrimitivesTest
Assert.Equal(y, rect.Height);
Assert.Equal(width, rect.Left);
Assert.Equal(height, rect.Top);
- Assert.Equal(x + width, rect.Right);
- Assert.Equal(y + height, rect.Bottom);
+ Assert.Equal(unchecked(x + width), rect.Right);
+ Assert.Equal(unchecked(y + height), rect.Bottom);
}
[Theory]
@@ -168,11 +168,16 @@ namespace System.Drawing.PrimitivesTest
public void RectangleFConversionTest(float x, float y, float width, float height)
{
RectangleF rect = new RectangleF(x, y, width, height);
- Rectangle rCeiling = new Rectangle((int)Math.Ceiling(x), (int)Math.Ceiling(y),
- (int)Math.Ceiling(width), (int)Math.Ceiling(height));
- Rectangle rTruncate = new Rectangle((int)x, (int)y, (int)width, (int)height);
- Rectangle rRound = new Rectangle((int)Math.Round(x), (int)Math.Round(y),
- (int)Math.Round(width), (int)Math.Round(height));
+ Rectangle rCeiling, rTruncate, rRound;
+
+ unchecked
+ {
+ rCeiling = new Rectangle((int)Math.Ceiling(x), (int)Math.Ceiling(y),
+ (int)Math.Ceiling(width), (int)Math.Ceiling(height));
+ rTruncate = new Rectangle((int)x, (int)y, (int)width, (int)height);
+ rRound = new Rectangle((int)Math.Round(x), (int)Math.Round(y),
+ (int)Math.Round(width), (int)Math.Round(height));
+ }
Assert.Equal(rCeiling, Rectangle.Ceiling(rect));
Assert.Equal(rTruncate, Rectangle.Truncate(rect));
@@ -184,7 +189,7 @@ namespace System.Drawing.PrimitivesTest
[InlineData(0, int.MinValue, int.MaxValue, 0)]
public void ContainsTest(int x, int y, int width, int height)
{
- Rectangle rect = new Rectangle(2 * x - width, 2 * y - height, width, height);
+ Rectangle rect = new Rectangle(unchecked(2 * x - width), unchecked(2 * y - height), width, height);
Point p = new Point(x, y);
Rectangle r = new Rectangle(x, y, width / 2, height / 2);
@@ -199,8 +204,11 @@ namespace System.Drawing.PrimitivesTest
[InlineData(0, int.MinValue, int.MaxValue, 0)]
public void InflateTest(int x, int y, int width, int height)
{
- Rectangle rect = new Rectangle(x, y, width, height);
- Rectangle inflatedRect = new Rectangle(x - width, y - height, width + 2 * width, height + 2 * height);
+ Rectangle inflatedRect, rect = new Rectangle(x, y, width, height);
+ unchecked
+ {
+ inflatedRect = new Rectangle(x - width, y - height, width + 2 * width, height + 2 * height);
+ }
Assert.Equal(inflatedRect, Rectangle.Inflate(rect, width, height));
@@ -208,7 +216,10 @@ namespace System.Drawing.PrimitivesTest
Assert.Equal(inflatedRect, rect);
Size s = new Size(x, y);
- inflatedRect = new Rectangle(rect.X - x, rect.Y - y, rect.Width + 2 * x, rect.Height + 2 * y);
+ unchecked
+ {
+ inflatedRect = new Rectangle(rect.X - x, rect.Y - y, rect.Width + 2 * x, rect.Height + 2 * y);
+ }
rect.Inflate(s);
Assert.Equal(inflatedRect, rect);
diff --git a/src/System.Drawing.Primitives/tests/SizeFTests.cs b/src/System.Drawing.Primitives/tests/SizeFTests.cs
index 4d5278b249..0caa768e26 100644
--- a/src/System.Drawing.Primitives/tests/SizeFTests.cs
+++ b/src/System.Drawing.Primitives/tests/SizeFTests.cs
@@ -130,7 +130,7 @@ namespace System.Drawing.PrimitivesTest
{
SizeF s1 = new SizeF(width, height);
PointF p1 = (PointF)s1;
- Size s2 = new Size((int)width, (int)height);
+ Size s2 = new Size(unchecked((int)width), unchecked((int)height));
Assert.Equal(new PointF(width, height), p1);
Assert.Equal(p1, s1.ToPointF());
diff --git a/src/System.Drawing.Primitives/tests/SizeTests.cs b/src/System.Drawing.Primitives/tests/SizeTests.cs
index 8eeefaf873..84460e1f2a 100644
--- a/src/System.Drawing.Primitives/tests/SizeTests.cs
+++ b/src/System.Drawing.Primitives/tests/SizeTests.cs
@@ -94,9 +94,13 @@ namespace System.Drawing.PrimitivesTests
{
Size sz1 = new Size(width, height);
Size sz2 = new Size(height, width);
+ Size addExpected, subExpected;
- Size addExpected = new Size(width + height, height + width);
- Size subExpected = new Size(width - height, height - width);
+ unchecked
+ {
+ addExpected = new Size(width + height, height + width);
+ subExpected = new Size(width - height, height - width);
+ }
Assert.Equal(addExpected, sz1 + sz2);
Assert.Equal(subExpected, sz1 - sz2);
@@ -112,9 +116,14 @@ namespace System.Drawing.PrimitivesTests
public void PointFMathematicalTest(float width, float height)
{
SizeF szF = new SizeF(width, height);
- Size pCeiling = new Size((int)Math.Ceiling(width), (int)Math.Ceiling(height));
- Size pTruncate = new Size((int)width, (int)height);
- Size pRound = new Size((int)Math.Round(width), (int)Math.Round(height));
+ Size pCeiling, pTruncate, pRound;
+
+ unchecked
+ {
+ pCeiling = new Size((int)Math.Ceiling(width), (int)Math.Ceiling(height));
+ pTruncate = new Size((int)width, (int)height);
+ pRound = new Size((int)Math.Round(width), (int)Math.Round(height));
+ }
Assert.Equal(pCeiling, Size.Ceiling(szF));
Assert.Equal(pRound, Size.Round(szF));
@@ -129,7 +138,7 @@ namespace System.Drawing.PrimitivesTests
public void EqualityTest(int width, int height)
{
Size p1 = new Size(width, height);
- Size p2 = new Size(width - 1, height - 1);
+ Size p2 = new Size(unchecked(width - 1), unchecked(height - 1));
Size p3 = new Size(width, height);
Assert.True(p1 == p3);