* TestGraphics.cs: Add test cases for MeasureString and
authorSebastien Pouliot <sebastien@ximian.com>
Mon, 18 Sep 2006 19:10:44 +0000 (19:10 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Mon, 18 Sep 2006 19:10:44 +0000 (19:10 -0000)
MeasureCharacterRanges methods.

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

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

index da0cf8f35af51fd55ed410ea4f62376a05bcae72..5be73583e773648fa61ac817125913f7234c47e7 100644 (file)
@@ -1,6 +1,7 @@
 2006-09-18  Sebastien Pouliot  <sebastien@ximian.com>
 
-       * TestGraphics.cs: Add test cases for MeasureString methods.
+       * TestGraphics.cs: Add test cases for MeasureString and 
+       MeasureCharacterRanges methods.
 
 2006-09-18     Boris Kirzner <borisk@mainsoft.com>
 
index 4dd0a1caaf6d5e6afd9a0241fef3cdbdb6eff90a..e0a3a5bc5575ff914c50198e6c923434146e136e 100644 (file)
@@ -1386,6 +1386,59 @@ namespace MonoTests.System.Drawing
                                }
                        }
                }
+
+               [Test]
+               public void MeasureCharacterRanges_NullOrEmptyText ()
+               {
+                       using (Bitmap bitmap = new Bitmap (20, 20)) {
+                               using (Graphics g = Graphics.FromImage (bitmap)) {
+                                       Region[] regions = g.MeasureCharacterRanges (null, font, new RectangleF (), null);
+                                       AssertEquals ("text null", 0, regions.Length);
+                                       regions = g.MeasureCharacterRanges (String.Empty, font, new RectangleF (), null);
+                                       AssertEquals ("text empty", 0, regions.Length);
+                                       // null font is ok with null or empty string
+                                       regions = g.MeasureCharacterRanges (null, null, new RectangleF (), null);
+                                       AssertEquals ("text null/null font", 0, regions.Length);
+                                       regions = g.MeasureCharacterRanges (String.Empty, null, new RectangleF (), null);
+                                       AssertEquals ("text empty/null font", 0, regions.Length);
+                               }
+                       }
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void MeasureCharacterRanges_FontNull ()
+               {
+                       using (Bitmap bitmap = new Bitmap (20, 20)) {
+                               using (Graphics g = Graphics.FromImage (bitmap)) {
+                                       g.MeasureCharacterRanges ("a", null, new RectangleF (), null);
+                               }
+                       }
+               }
+
+               [Test] // adapted from bug #78777
+               public void MeasureCharacterRanges_TwoLines ()
+               {
+                       string text = "this\nis a test";
+                       CharacterRange[] ranges = new CharacterRange [2];
+                       ranges[0] = new CharacterRange (0,5);
+                       ranges[1] = new CharacterRange (5,9);
+
+                       StringFormat string_format = new StringFormat ();
+                       string_format.FormatFlags = StringFormatFlags.NoClip;
+                       string_format.SetMeasurableCharacterRanges (ranges);
+
+                       using (Bitmap bitmap = new Bitmap (20, 20)) {
+                               using (Graphics g = Graphics.FromImage (bitmap)) {
+                                       SizeF size = g.MeasureString (text, font, new Point (0,0), string_format);
+                                       RectangleF layout_rect = new RectangleF (0.0f, 0.0f, size.Width, size.Height);                  
+                                       Region[] regions = g.MeasureCharacterRanges (text, font, layout_rect, string_format);
+
+                                       AssertEquals ("Length", 2, regions.Length);
+                                       AssertEquals ("Height", regions[0].GetBounds (g).Height, regions[1].GetBounds (g).Height);
+                               }
+                       }
+               }
 #if NET_2_0
                [Test]
                public void TestReleaseHdc ()