2008-12-23 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Tue, 23 Dec 2008 21:11:13 +0000 (21:11 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Tue, 23 Dec 2008 21:11:13 +0000 (21:11 -0000)
* GDIPlusTest.cs: Add MeasureCharacterRanges test cases around bug
#449971 and add a few delta for FP comparison.
* TestGraphics.cs: Add a few delta for FP comparison.

svn path=/trunk/mcs/; revision=122060

mcs/class/System.Drawing/Test/System.Drawing/ChangeLog
mcs/class/System.Drawing/Test/System.Drawing/GDIPlusTest.cs
mcs/class/System.Drawing/Test/System.Drawing/TestGraphics.cs

index 627b0e89c625fd23b56f18242d6ece9adf2791d9..b57f670c8ef874f44940ca6d83510a264dd9d60b 100644 (file)
@@ -1,3 +1,9 @@
+2008-12-23  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * GDIPlusTest.cs: Add MeasureCharacterRanges test cases around bug
+       #449971 and add a few delta for FP comparison.
+       * TestGraphics.cs: Add a few delta for FP comparison.
+
 2008-12-10  Atsushi Enomoto  <atsushi@ximian.com>
 
        * TestGraphics.cs, GDIPlusTest.cs : fix tests wrt rounding that
index 82fe6095d1be6b5e686031adc62733a6dfef557f..d81f63c593cedb2676fc8d93072f342eab0e1c25 100644 (file)
@@ -1583,8 +1583,8 @@ namespace MonoTests.System.Drawing {
 
                        float width, height;
                        Assert.AreEqual (Status.Ok, GDIPlus.GdipGetImageDimension (image, out width, out height), "GdipGetImageDimension");
-                       Assert.AreEqual (12976.6328f, width, "GdipGetImageDimension/Width");
-                       Assert.AreEqual (17297.9863f, height, "GdipGetImageDimension/Height");
+                       Assert.AreEqual (12976.6328f, width, 0.001f, "GdipGetImageDimension/Width");
+                       Assert.AreEqual (17297.9863f, height, 0.001f, "GdipGetImageDimension/Height");
 
                        ImageType type;
                        Assert.AreEqual (Status.Ok, GDIPlus.GdipGetImageType (image, out type), "GdipGetImageType");
index e39557822e1e6e4573f0da2a91be083794a39805..0fb3675e3dec813c78b82eccd76fcab08461a8ac 100644 (file)
@@ -5,7 +5,7 @@
 //   Jordi Mas, jordi@ximian.com
 //   Sebastien Pouliot  <sebastien@ximian.com>
 //
-// Copyright (C) 2005-2007 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2005-2008 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -2459,6 +2459,80 @@ namespace MonoTests.System.Drawing {
                        }
                }
 
+               static CharacterRange [] ranges = new CharacterRange [] {
+                    new CharacterRange (0, 1),
+                    new CharacterRange (1, 1),
+                    new CharacterRange (2, 1)
+                };
+
+               Region [] Measure (Graphics gfx, RectangleF rect)
+               {
+                       using (StringFormat format = StringFormat.GenericTypographic) {
+                               format.SetMeasurableCharacterRanges (ranges);
+
+                               using (Font font = new Font (FontFamily.GenericSerif, 11.0f)) {
+                                       return gfx.MeasureCharacterRanges ("abc", font, rect, format);
+                               }
+                       }
+               }
+
+               [Test]
+               public void Measure ()
+               {
+                       using (Graphics gfx = Graphics.FromImage (new Bitmap (1, 1))) {
+                               Region [] zero = Measure (gfx, new RectangleF (0, 0, 0, 0));
+                               Assert.AreEqual (3, zero.Length, "zero.Length");
+
+                               Region [] small = Measure (gfx, new RectangleF (0, 0, 100, 100));
+                               Assert.AreEqual (3, small.Length, "small.Length");
+                               for (int i = 0; i < 3; i++ ) {
+                                       RectangleF zb = zero [i].GetBounds (gfx);
+                                       RectangleF sb = small [i].GetBounds (gfx);
+                                       Assert.AreEqual (sb.X, zb.X, "sx" + i.ToString ());
+                                       Assert.AreEqual (sb.Y, zb.Y, "sy" + i.ToString ());
+                                       Assert.AreEqual (sb.Width, zb.Width, "sw" + i.ToString ());
+                                       Assert.AreEqual (sb.Height, zb.Height, "sh" + i.ToString ());
+                               }
+
+                               Region [] max = Measure (gfx, new RectangleF (0, 0, Single.MaxValue, Single.MaxValue));
+                               Assert.AreEqual (3, max.Length, "empty.Length");
+                               for (int i = 0; i < 3; i++) {
+                                       RectangleF zb = zero [i].GetBounds (gfx);
+                                       RectangleF mb = max [i].GetBounds (gfx);
+                                       Assert.AreEqual (mb.X, zb.X, "mx" + i.ToString ());
+                                       Assert.AreEqual (mb.Y, zb.Y, "my" + i.ToString ());
+                                       Assert.AreEqual (mb.Width, zb.Width, "mw" + i.ToString ());
+                                       Assert.AreEqual (mb.Height, zb.Height, "mh" + i.ToString ());
+                               }
+                       }
+               }
+
+               [Test]
+               public void MeasureLimits ()
+               {
+                       using (Graphics gfx = Graphics.FromImage (new Bitmap (1, 1))) {
+                               Region [] min = Measure (gfx, new RectangleF (0, 0, Single.MinValue, Single.MinValue));
+                               Assert.AreEqual (3, min.Length, "origin.Length");
+                               for (int i = 0; i < 3; i++) {
+                                       RectangleF mb = min [i].GetBounds (gfx);
+                                       Assert.AreEqual (-4194304.0f, mb.X, "minx" + i.ToString ());
+                                       Assert.AreEqual (-4194304.0f, mb.Y, "miny" + i.ToString ());
+                                       Assert.AreEqual (8388608.0f, mb.Width, "minw" + i.ToString ());
+                                       Assert.AreEqual (8388608.0f, mb.Height, "minh" + i.ToString ());
+                               }
+
+                               Region [] neg = Measure (gfx, new RectangleF (0, 0, -20, -20));
+                               Assert.AreEqual (3, neg.Length, "neg.Length");
+                               for (int i = 0; i < 3; i++) {
+                                       RectangleF mb = neg [i].GetBounds (gfx);
+                                       Assert.AreEqual (-4194304.0f, mb.X, "minx" + i.ToString ());
+                                       Assert.AreEqual (-4194304.0f, mb.Y, "miny" + i.ToString ());
+                                       Assert.AreEqual (8388608.0f, mb.Width, "minw" + i.ToString ());
+                                       Assert.AreEqual (8388608.0f, mb.Height, "minh" + i.ToString ());
+                               }
+                       }
+               }
+
                [Test]
                public void DrawString_EndlessLoop_Bug77699 ()
                {
@@ -2683,7 +2757,7 @@ namespace MonoTests.System.Drawing {
                                        RectangleF rvcb = g.VisibleClipBounds;
                                        Assert.AreEqual (0, rvcb.X, "rvcb.X");
                                        Assert.AreEqual (-100, rvcb.Y, "rvcb.Y");
-                                       Assert.AreEqual (50.0000038f, rvcb.Width, "rvcb.Width");
+                                       Assert.AreEqual (50.0f, rvcb.Width, 0.0001, "rvcb.Width");
                                        Assert.AreEqual (100, rvcb.Height, "rvcb.Height");
                                }
                        }