Author: spouliot
Date: 2006-09-22 10:18:55 -0400 (Fri, 22 Sep 2006)
New Revision: 65819

Modified:
   trunk/mcs/class/System.Drawing/Test/System.Drawing/ChangeLog
   trunk/mcs/class/System.Drawing/Test/System.Drawing/TestGraphics.cs
Log:
2006-09-22  Sebastien Pouliot  <[EMAIL PROTECTED]>

        * TestGraphics.cs: Added more test cases for MeasureCharacterRanges,
        like handling bad ranges (start, length) and hotkey prefix handling.



Modified: trunk/mcs/class/System.Drawing/Test/System.Drawing/ChangeLog
===================================================================
--- trunk/mcs/class/System.Drawing/Test/System.Drawing/ChangeLog        
2006-09-22 14:18:34 UTC (rev 65818)
+++ trunk/mcs/class/System.Drawing/Test/System.Drawing/ChangeLog        
2006-09-22 14:18:55 UTC (rev 65819)
@@ -1,3 +1,8 @@
+2006-09-22  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * TestGraphics.cs: Added more test cases for MeasureCharacterRanges,
+       like handling bad ranges (start, length) and hotkey prefix handling.
+
 2006-09-21  Sebastien Pouliot  <[EMAIL PROTECTED]> 
 
        * GDIPlusTest.cs: Added test cases for GdipGetStringFormatTabStops and

Modified: trunk/mcs/class/System.Drawing/Test/System.Drawing/TestGraphics.cs
===================================================================
--- trunk/mcs/class/System.Drawing/Test/System.Drawing/TestGraphics.cs  
2006-09-22 14:18:34 UTC (rev 65818)
+++ trunk/mcs/class/System.Drawing/Test/System.Drawing/TestGraphics.cs  
2006-09-22 14:18:55 UTC (rev 65819)
@@ -1444,6 +1444,75 @@
                                }
                        }
                }
+
+               private void MeasureCharacterRanges (string text, int first, 
int length)
+               {
+                       CharacterRange[] ranges = new CharacterRange[1];
+                       ranges[0] = new CharacterRange (first, length);
+
+                       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);
+                                       g.MeasureCharacterRanges (text, font, 
layout_rect, string_format);
+                               }
+                       }
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void MeasureCharacterRanges_FirstTooFar ()
+               {
+                       string text = "this\nis a test";
+                       MeasureCharacterRanges (text, text.Length, 1);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void MeasureCharacterRanges_LengthTooLong ()
+               {
+                       string text = "this\nis a test";
+                       MeasureCharacterRanges (text, 0, text.Length + 1);
+               }
+
+               [Test]
+               public void MeasureCharacterRanges_Prefix ()
+               {
+                       string text = "Hello &Mono::";
+                       CharacterRange[] ranges = new CharacterRange[1];
+                       ranges[0] = new CharacterRange (5, 4);
+
+                       StringFormat string_format = new StringFormat ();
+                       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);
+
+                                       // here & is part of the measure and 
visible
+                                       string_format.HotkeyPrefix = 
HotkeyPrefix.None;
+                                       Region[] regions = 
g.MeasureCharacterRanges (text, font, layout_rect, string_format);
+                                       RectangleF bounds_none = 
regions[0].GetBounds (g);
+
+                                       // here & is part of the measure 
(range) but visible as an underline
+                                       string_format.HotkeyPrefix = 
HotkeyPrefix.Show;
+                                       regions = g.MeasureCharacterRanges 
(text, font, layout_rect, string_format);
+                                       RectangleF bounds_show = 
regions[0].GetBounds (g);
+                                       Assert ("Show<None", bounds_show.Width 
< bounds_none.Width);
+
+                                       // here & is part of the measure 
(range) but invisible
+                                       string_format.HotkeyPrefix = 
HotkeyPrefix.Hide;
+                                       regions = g.MeasureCharacterRanges 
(text, font, layout_rect, string_format);
+                                       RectangleF bounds_hide = 
regions[0].GetBounds (g);
+                                       AssertEquals ("Hide==None", 
bounds_hide.Width, bounds_show.Width);
+                               }
+                       }
+               }
 #if NET_2_0
                [Test]
                public void TestReleaseHdc ()

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to