New test.
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing / TestFont.cs
1 //
2 // Test Font class testing unit
3 //
4 // Author:
5 //
6 //       Jordi Mas i Hernandez, jordi@ximian.com
7 //       Peter Dennis Bartok, pbartok@novell.com
8 //
9 // (C) 2003 Ximian, Inc.  http://www.ximian.com
10 // Copyright (C) 2004-2006 Novell, Inc (http://www.novell.com)
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31 using NUnit.Framework;
32 using System;
33 using System.Drawing;
34 using System.Drawing.Text;
35 using System.Security;
36 using System.Security.Permissions;
37 using System.Runtime.InteropServices;
38
39 namespace MonoTests.System.Drawing{
40
41         [TestFixture]
42         public class FontTest {
43
44                 private string name;
45
46                 [TestFixtureSetUp]
47                 public void FixtureSetUp ()
48                 {
49                         try {
50                                 using (FontFamily ff = new FontFamily (GenericFontFamilies.Monospace)) {
51                                         name = ff.Name;
52                                 }
53                         }
54                         catch (ArgumentException) {
55                                 Assert.Ignore ("No font family could be found.");
56                         }
57                 }
58
59                 // Test basic Font clone, properties and contructor
60                 [Test]
61                 [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
62                 public void TestClone()
63                 {               
64                         Font f = new Font("Arial",12);  
65                         Font f2 = (Font) f.Clone();
66                         
67                         Assert.AreEqual (f.Bold, f2.Bold, "Bold");
68                         Assert.AreEqual (f.FontFamily, f2.FontFamily, "FontFamily");
69                         Assert.AreEqual (f.GdiCharSet, f2.GdiCharSet, "GdiCharSet");
70                         Assert.AreEqual (f.GdiVerticalFont, f2.GdiVerticalFont, "GdiVerticalFont");
71                         Assert.AreEqual (f.Height, f2.Height, "Height");
72                         Assert.AreEqual (f.Italic, f2.Italic, "Italic");
73                         Assert.AreEqual (f.Name, f2.Name, "Name");
74                         Assert.AreEqual (f.Size, f2.Size, "Size");
75                         Assert.AreEqual (f.SizeInPoints, f2.SizeInPoints, "SizeInPoints");
76                         Assert.AreEqual (f.Strikeout, f2.Strikeout, "Strikeout");
77                         Assert.AreEqual (f.Style, f2.Style, "Style");
78                         Assert.AreEqual (f.Underline, f2.Underline, "Underline");
79                         Assert.AreEqual (f.Unit, f2.Unit, "Unit");
80                 }
81
82                 [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
83                 class LOGFONT {
84                         public int lfHeight;
85                         public int lfWidth;
86                         public int lfEscapement;
87                         public int lfOrientation;
88                         public int lfWeight;
89                         public byte lfItalic;
90                         public byte lfUnderline;
91                         public byte lfStrikeOut;
92                         public byte lfCharSet;
93                         public byte lfOutPrecision;
94                         public byte lfClipPrecision;
95                         public byte lfQuality;
96                         public byte lfPitchAndFamily;
97                         [ MarshalAs(UnmanagedType.ByValTStr, SizeConst=32) ]
98                         public string lfFaceName;
99                 }
100
101                 [StructLayout (LayoutKind.Sequential, CharSet = CharSet.Auto)]
102                 struct LOGFONT_STRUCT {
103                         public int lfHeight;
104                         public int lfWidth;
105                         public int lfEscapement;
106                         public int lfOrientation;
107                         public int lfWeight;
108                         public byte lfItalic;
109                         public byte lfUnderline;
110                         public byte lfStrikeOut;
111                         public byte lfCharSet;
112                         public byte lfOutPrecision;
113                         public byte lfClipPrecision;
114                         public byte lfQuality;
115                         public byte lfPitchAndFamily;
116                         [MarshalAs (UnmanagedType.ByValTStr, SizeConst = 32)]
117                         public string lfFaceName;
118                 }
119
120 #if !TARGET_JVM
121                 [Test]
122                 [Category ("CAS")]
123                 [ExpectedException (typeof (SecurityException))]
124                 [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
125                 public void ToLogFont_DenyUnmanagedCode ()
126                 {
127                         Font f;
128                         LOGFONT lf;
129
130                         lf = new LOGFONT();
131                         f = new Font("Arial", 10);
132
133                         f.ToLogFont(lf);
134                 }
135
136                 [Test]
137                 [SecurityPermission (SecurityAction.Assert, UnmanagedCode = true)]
138                 public void ToLogFont_AssertUnmanagedCode ()
139                 {
140                         Font f = new Font("Arial", 10);
141                         LOGFONT lf = new LOGFONT();
142
143                         f.ToLogFont (lf);
144                         Assert.AreEqual (400, lf.lfWeight, "lfWeight");
145                         Assert.AreEqual (1, lf.lfCharSet, "lfCharSet");
146                         Assert.AreEqual (f.Name, lf.lfFaceName, "lfFaceName");
147
148                         LOGFONT_STRUCT lfs = new LOGFONT_STRUCT ();
149                         f.ToLogFont (lfs);
150                         Assert.AreEqual (0, lfs.lfWeight, "struct-lfWeight");
151                         Assert.AreEqual (0, lfs.lfCharSet, "struct-lfCharSet");
152                         Assert.AreEqual (0, lfs.lfHeight, "struct-lfHeight");
153                         Assert.AreEqual (0, lfs.lfWidth, "struct-lfWidth");
154                         Assert.AreEqual (0, lfs.lfEscapement, "struct-lfEscapement");
155                         Assert.AreEqual (0, lfs.lfOrientation, "struct-lfOrientation");
156                         Assert.AreEqual (0, lfs.lfWeight, "struct-lfWeight");
157                         Assert.AreEqual (0, lfs.lfItalic, "struct-lfItalic");
158                         Assert.AreEqual (0, lfs.lfUnderline, "struct-lfUnderline");
159                         Assert.AreEqual (0, lfs.lfStrikeOut, "struct-lfStrikeOut");
160                         Assert.AreEqual (0, lfs.lfCharSet, "struct-lfCharSet");
161                         Assert.AreEqual (0, lfs.lfOutPrecision, "struct-lfOutPrecision");
162                         Assert.AreEqual (0, lfs.lfClipPrecision, "struct-lfClipPrecision");
163                         Assert.AreEqual (0, lfs.lfQuality, "struct-lfQuality");
164                         Assert.AreEqual (0, lfs.lfPitchAndFamily, "struct-lfPitchAndFamily");
165                         Assert.IsNull (lfs.lfFaceName, "struct-lfFaceName");
166                 }
167
168                 [Test]
169                 [SecurityPermission (SecurityAction.Assert, UnmanagedCode = true)]
170                 [ExpectedException (typeof (ArgumentException))]
171                 public void ToLogFont_TooSmall ()
172                 {
173                         Font f = new Font ("Arial", 10);
174                         object o = new object ();
175                         f.ToLogFont (o);
176                         // no PInvoke conversion exists !?!?
177                 }
178
179                 [Test]
180                 [SecurityPermission (SecurityAction.Assert, UnmanagedCode = true)]
181                 public void ToLogFont_Int ()
182                 {
183                         Font f = new Font ("Arial", 10);
184                         int i = 1;
185                         f.ToLogFont (i);
186                         Assert.AreEqual (1, i);
187                 }
188
189                 [Test]
190                 [SecurityPermission (SecurityAction.Assert, UnmanagedCode = true)]
191         #if NET_2_0
192                 [ExpectedException (typeof (AccessViolationException))]
193         #else
194                 [ExpectedException (typeof (NullReferenceException))]
195         #endif
196                 public void ToLogFont_Null ()
197                 {
198                         Font f = new Font ("Arial", 10);
199                         f.ToLogFont (null);
200                 }
201 #endif
202                 [Test]
203 #if ONLY_1_1
204                 [ExpectedException (typeof (ArgumentNullException))]
205 #endif
206 #if TARGET_JVM
207                 [Category ("NotWorking")]
208 #endif
209                 public void Font_StringNull_Float ()
210                 {
211                         string family = null;
212                         Font f = new Font (family, 12.5f);
213                         Assert.AreEqual (FontFamily.GenericSansSerif, f.FontFamily, "FontFamily");
214                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
215                         Assert.AreEqual (12.5f, f.Size, "Size");
216                         Assert.AreEqual (12.5f, f.SizeInPoints, "SizeInPoints");
217                         Assert.AreEqual (GraphicsUnit.Point, f.Unit, "Unit");
218                 }
219
220                 [Test]
221 #if TARGET_JVM
222                 [Category ("NotWorking")]
223 #endif
224                 public void Font_String_Float ()
225                 {
226                         Font f = new Font (name, 12.5f);
227                         Assert.AreEqual (FontFamily.GenericMonospace, f.FontFamily, "FontFamily");
228                         Assert.IsFalse (f.Bold, "Bold");
229                         Assert.AreEqual (1, f.GdiCharSet, "GdiCharSet");
230                         Assert.IsFalse (f.GdiVerticalFont, "GdiVerticalFont");
231                         Assert.IsTrue (f.Height > 0, "Height");
232                         Assert.IsFalse (f.Italic, "Italic");
233                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
234                         Assert.AreEqual (12.5f, f.Size, "Size");
235                         Assert.AreEqual (12.5f, f.SizeInPoints, "SizeInPoints");
236                         Assert.IsFalse (f.Strikeout, "Strikeout");
237                         Assert.IsFalse (f.Underline, "Underline");
238                         Assert.AreEqual (GraphicsUnit.Point, f.Unit, "Unit");
239                 }
240
241                 [Test]
242 #if TARGET_JVM
243                 [Category ("NotWorking")]
244 #endif
245                 public void Font_String_Float_FontStyle ()
246                 {
247                         Font f = new Font (name, 12.5f, FontStyle.Bold);
248                         Assert.AreEqual (FontFamily.GenericMonospace, f.FontFamily, "FontFamily");
249                         Assert.IsTrue (f.Bold, "Bold");
250                         Assert.AreEqual (1, f.GdiCharSet, "GdiCharSet");
251                         Assert.IsFalse (f.GdiVerticalFont, "GdiVerticalFont");
252                         Assert.IsTrue (f.Height > 0, "Height");
253                         Assert.IsFalse (f.Italic, "Italic");
254                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
255                         Assert.AreEqual (12.5f, f.Size, "Size");
256                         Assert.AreEqual (12.5f, f.SizeInPoints, "SizeInPoints");
257                         Assert.IsFalse (f.Strikeout, "Strikeout");
258                         Assert.IsFalse (f.Underline, "Underline");
259                         Assert.AreEqual (GraphicsUnit.Point, f.Unit, "Unit");
260                 }
261
262                 [Test]
263 #if TARGET_JVM
264                 [Category ("NotWorking")]
265 #endif
266                 public void Font_String_Float_FontStyle_GraphicsUnit ()
267                 {
268                         Font f = new Font (name, 12.5f, FontStyle.Italic, GraphicsUnit.Pixel);
269                         Assert.IsFalse (f.Bold, "Bold");
270                         Assert.AreEqual (1, f.GdiCharSet, "GdiCharSet");
271                         Assert.IsFalse (f.GdiVerticalFont, "GdiVerticalFont");
272                         Assert.IsTrue (f.Height > 0, "Height");
273                         Assert.IsTrue (f.Italic, "Italic");
274                         Assert.AreEqual (FontFamily.GenericMonospace, f.FontFamily, "FontFamily");
275                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
276                         Assert.AreEqual (12.5f, f.Size, "Size");
277                         Assert.IsFalse (f.Strikeout, "Strikeout");
278                         Assert.IsFalse (f.Underline, "Underline");
279                         Assert.AreEqual (GraphicsUnit.Pixel, f.Unit, "Unit");
280                 }
281
282                 [Test]
283                 [ExpectedException (typeof (ArgumentException))]
284 #if TARGET_JVM
285                 [Category ("NotWorking")]
286 #endif
287                 public void Font_String_Float_FontStyle_GraphicsUnit_Display ()
288                 {
289                         new Font (name, 12.5f, FontStyle.Italic, GraphicsUnit.Display);
290                 }
291
292                 [Test]
293 #if TARGET_JVM
294                 [Category ("NotWorking")]
295 #endif
296                 public void Font_String_Float_FontStyle_GraphicsUnit_Byte ()
297                 {
298                         Font f = new Font (name, 12.5f, FontStyle.Strikeout, GraphicsUnit.Inch, Byte.MaxValue);
299                         Assert.IsFalse (f.Bold, "Bold");
300                         Assert.AreEqual (Byte.MaxValue, f.GdiCharSet, "GdiCharSet");
301                         Assert.IsFalse (f.GdiVerticalFont, "GdiVerticalFont");
302                         Assert.IsTrue (f.Height > 0, "Height");
303                         Assert.IsFalse (f.Italic, "Italic");
304                         Assert.AreEqual (FontFamily.GenericMonospace, f.FontFamily, "FontFamily");
305                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
306                         Assert.AreEqual (12.5f, f.Size, "Size");
307                         Assert.AreEqual (900f, f.SizeInPoints, "SizeInPoints");
308                         Assert.IsTrue (f.Strikeout, "Strikeout");
309                         Assert.IsFalse (f.Underline, "Underline");
310                         Assert.AreEqual (GraphicsUnit.Inch, f.Unit, "Unit");
311                 }
312
313                 [Test]
314 #if TARGET_JVM
315                 [Category ("NotWorking")]
316 #endif
317                 public void Font_String_Float_FontStyle_GraphicsUnit_Byte_Bool ()
318                 {
319                         Font f = new Font (name, 12.5f, FontStyle.Underline, GraphicsUnit.Document, Byte.MinValue, true);
320                         Assert.IsFalse (f.Bold, "Bold");
321                         Assert.AreEqual (Byte.MinValue, f.GdiCharSet, "GdiCharSet");
322                         Assert.IsTrue (f.GdiVerticalFont, "GdiVerticalFont");
323                         Assert.IsTrue (f.Height > 0, "Height");
324                         Assert.IsFalse (f.Italic, "Italic");
325                         Assert.AreEqual (FontFamily.GenericMonospace, f.FontFamily, "FontFamily");
326                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
327                         Assert.AreEqual (12.5f, f.Size, "Size");
328                         Assert.AreEqual (3f, f.SizeInPoints, "SizeInPoints");
329                         Assert.IsFalse (f.Strikeout, "Strikeout");
330                         Assert.IsTrue (f.Underline, "Underline");
331                         Assert.AreEqual (GraphicsUnit.Document, f.Unit, "Unit");
332                 }
333
334                 [Test]
335                 [ExpectedException (typeof (ArgumentNullException))]
336                 public void Font_FontFamilyNull_Float ()
337                 {
338                         FontFamily ff = null;
339                         new Font (ff, 12.5f);
340                 }
341
342                 [Test]
343 #if TARGET_JVM
344                 [Category ("NotWorking")]
345 #endif
346                 public void Font_FontFamily_Float ()
347                 {
348                         Font f = new Font (FontFamily.GenericMonospace, 12.5f);
349                         Assert.AreEqual (FontFamily.GenericMonospace, f.FontFamily, "FontFamily");
350                         Assert.IsFalse (f.Bold, "Bold");
351                         Assert.AreEqual (1, f.GdiCharSet, "GdiCharSet");
352                         Assert.IsFalse (f.GdiVerticalFont, "GdiVerticalFont");
353                         Assert.IsTrue (f.Height > 0, "Height");
354                         Assert.IsFalse (f.Italic, "Italic");
355                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
356                         Assert.AreEqual (12.5f, f.Size, "Size");
357                         Assert.AreEqual (12.5f, f.SizeInPoints, "SizeInPoints");
358                         Assert.IsFalse (f.Strikeout, "Strikeout");
359                         Assert.IsFalse (f.Underline, "Underline");
360                         Assert.AreEqual (GraphicsUnit.Point, f.Unit, "Unit");
361                 }
362
363                 [Test]
364 #if TARGET_JVM
365                 [Category ("NotWorking")]
366 #endif
367                 public void Font_FontFamily_Float_FontStyle ()
368                 {
369                         Font f = new Font (FontFamily.GenericMonospace, 12.5f, FontStyle.Bold);
370                         Assert.AreEqual (FontFamily.GenericMonospace, f.FontFamily, "FontFamily");
371                         Assert.IsTrue (f.Bold, "Bold");
372                         Assert.AreEqual (1, f.GdiCharSet, "GdiCharSet");
373                         Assert.IsFalse (f.GdiVerticalFont, "GdiVerticalFont");
374                         Assert.IsTrue (f.Height > 0, "Height");
375                         Assert.IsFalse (f.Italic, "Italic");
376                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
377                         Assert.AreEqual (12.5f, f.Size, "Size");
378                         Assert.AreEqual (12.5f, f.SizeInPoints, "SizeInPoints");
379                         Assert.IsFalse (f.Strikeout, "Strikeout");
380                         Assert.IsFalse (f.Underline, "Underline");
381                         Assert.AreEqual (GraphicsUnit.Point, f.Unit, "Unit");
382                 }
383
384                 [Test]
385 #if TARGET_JVM
386                 [Category ("NotWorking")]
387 #endif
388                 public void Font_FontFamily_Float_FontStyle_GraphicsUnit ()
389                 {
390                         Font f = new Font (FontFamily.GenericMonospace, 12.5f, FontStyle.Italic, GraphicsUnit.Millimeter);
391                         Assert.IsFalse (f.Bold, "Bold");
392                         Assert.AreEqual (1, f.GdiCharSet, "GdiCharSet");
393                         Assert.IsFalse (f.GdiVerticalFont, "GdiVerticalFont");
394                         Assert.IsTrue (f.Height > 0, "Height");
395                         Assert.IsTrue (f.Italic, "Italic");
396                         Assert.AreEqual (FontFamily.GenericMonospace, f.FontFamily, "FontFamily");
397                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
398                         Assert.AreEqual (12.5f, f.Size, "Size");
399                         Assert.AreEqual (35.43307f, f.SizeInPoints, "SizeInPoints");
400                         Assert.IsFalse (f.Strikeout, "Strikeout");
401                         Assert.IsFalse (f.Underline, "Underline");
402                         Assert.AreEqual (GraphicsUnit.Millimeter, f.Unit, "Unit");
403                 }
404
405                 [Test]
406                 [ExpectedException (typeof (ArgumentException))]
407 #if TARGET_JVM
408                 [Category ("NotWorking")]
409 #endif
410                 public void Font_FontFamily_Float_FontStyle_GraphicsUnit_Display ()
411                 {
412                         new Font (FontFamily.GenericMonospace, 12.5f, FontStyle.Italic, GraphicsUnit.Display);
413                 }
414
415                 [Test]
416 #if TARGET_JVM
417                 [Category ("NotWorking")]
418 #endif
419                 public void Font_FontFamily_Float_FontStyle_GraphicsUnit_Byte ()
420                 {
421                         Font f = new Font (FontFamily.GenericMonospace, 12.5f, FontStyle.Strikeout, GraphicsUnit.Inch, Byte.MaxValue);
422                         Assert.IsFalse (f.Bold, "Bold");
423                         Assert.AreEqual (Byte.MaxValue, f.GdiCharSet, "GdiCharSet");
424                         Assert.IsFalse (f.GdiVerticalFont, "GdiVerticalFont");
425                         Assert.IsTrue (f.Height > 0, "Height");
426                         Assert.IsFalse (f.Italic, "Italic");
427                         Assert.AreEqual (FontFamily.GenericMonospace, f.FontFamily, "FontFamily");
428                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
429                         Assert.AreEqual (12.5f, f.Size, "Size");
430                         Assert.AreEqual (900f, f.SizeInPoints, "SizeInPoints");
431                         Assert.IsTrue (f.Strikeout, "Strikeout");
432                         Assert.IsFalse (f.Underline, "Underline");
433                         Assert.AreEqual (GraphicsUnit.Inch, f.Unit, "Unit");
434                 }
435
436                 [Test]
437 #if TARGET_JVM
438                 [Category ("NotWorking")]
439 #endif
440                 public void Font_FontFamily_Float_FontStyle_GraphicsUnit_Byte_Bool ()
441                 {
442                         Font f = new Font (FontFamily.GenericMonospace, 12.5f, FontStyle.Underline, GraphicsUnit.Document, Byte.MinValue, true);
443                         Assert.IsFalse (f.Bold, "Bold");
444                         Assert.AreEqual (Byte.MinValue, f.GdiCharSet, "GdiCharSet");
445                         Assert.IsTrue (f.GdiVerticalFont, "GdiVerticalFont");
446                         Assert.IsTrue (f.Height > 0, "Height");
447                         Assert.IsFalse (f.Italic, "Italic");
448                         Assert.AreEqual (FontFamily.GenericMonospace, f.FontFamily, "FontFamily");
449                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
450                         Assert.AreEqual (12.5f, f.Size, "Size");
451                         Assert.AreEqual (3f, f.SizeInPoints, "SizeInPoints");
452                         Assert.IsFalse (f.Strikeout, "Strikeout");
453                         Assert.IsTrue (f.Underline, "Underline");
454                         Assert.AreEqual (GraphicsUnit.Document, f.Unit, "Unit");
455                 }
456
457                 [Test]
458                 public void Dispose_Double ()
459                 {
460                         Font f = new Font (name, 12.5f);
461                         f.Dispose ();
462                         f.Dispose ();
463                 }
464
465                 [Test]
466                 public void Dispose_UseAfter_Works ()
467                 {
468                         Font f = new Font (name, 12.5f);
469                         string fname = f.Name;
470                         f.Dispose ();
471                         // most properties don't throw, everything seems to be cached
472                         Assert.AreEqual (fname, f.Name, "Name");
473                         Assert.AreEqual (12.5f, f.Size, "Size");
474                 }
475
476                 [Test]
477                 [ExpectedException (typeof (ArgumentException))]
478 #if TARGET_JVM
479                 [Category ("NotWorking")]
480 #endif
481                 public void Dispose_Height ()
482                 {
483                         Font f = new Font (name, 12.5f);
484                         f.Dispose ();
485                         Assert.AreEqual (0, f.Height, "Name");
486                 }
487
488                 [Test]
489                 [ExpectedException (typeof (ArgumentException))]
490 #if TARGET_JVM
491                 [Category ("NotWorking")]
492 #endif
493                 public void Dispose_ToLogFont ()
494                 {
495                         Font f = new Font (name, 12.5f);
496                         f.Dispose ();
497                         LOGFONT lf = new LOGFONT();
498                         f.ToLogFont (lf);
499                 }
500
501                 [Test]
502 #if TARGET_JVM
503                 [Category ("NotWorking")]
504 #endif
505                 public void Dispose_ToLogFont_LoopCharSet ()
506                 {
507                         Font f = new Font (name, 12.5f);
508                         f.Dispose ();
509                         LOGFONT lf = new LOGFONT ();
510
511                         for (int i = Byte.MinValue; i < Byte.MaxValue; i++) {
512                                 byte b = (byte) i;
513                                 lf.lfHeight = b;
514                                 lf.lfWidth = b;
515                                 lf.lfEscapement = b;
516                                 lf.lfOrientation = b;
517                                 lf.lfWeight = b;
518                                 lf.lfItalic = b;
519                                 lf.lfUnderline = b;
520                                 lf.lfStrikeOut = b;
521                                 lf.lfCharSet = b;
522                                 lf.lfOutPrecision = b;
523                                 lf.lfClipPrecision = b;
524                                 lf.lfQuality = b;
525                                 lf.lfPitchAndFamily = b;
526                                 lf.lfFaceName = b.ToString ();
527                                 try {
528                                         f.ToLogFont (lf);
529                                 }
530                                 catch (ArgumentException) {
531                                         Assert.AreEqual (b, lf.lfHeight, "lfHeight");
532                                         Assert.AreEqual (b, lf.lfWidth, "lfWidth");
533                                         Assert.AreEqual (b, lf.lfEscapement, "lfEscapement");
534                                         Assert.AreEqual (b, lf.lfOrientation, "lfOrientation");
535                                         Assert.AreEqual (b, lf.lfWeight, "lfWeight");
536                                         Assert.AreEqual (b, lf.lfItalic, "lfItalic");
537                                         Assert.AreEqual (b, lf.lfUnderline, "lfUnderline");
538                                         Assert.AreEqual (b, lf.lfStrikeOut, "lfStrikeOut");
539                                         // special case for 0
540                                         Assert.AreEqual ((i == 0) ? (byte)1 : b, lf.lfCharSet, "lfCharSet");
541                                         Assert.AreEqual (b, lf.lfOutPrecision, "lfOutPrecision");
542                                         Assert.AreEqual (b, lf.lfClipPrecision, "lfClipPrecision");
543                                         Assert.AreEqual (b, lf.lfQuality, "lfQuality");
544                                         Assert.AreEqual (b, lf.lfPitchAndFamily, "lfPitchAndFamily");
545                                         Assert.AreEqual (b.ToString (), lf.lfFaceName, "lfFaceName");
546                                 }
547                                 catch (Exception e) {
548                                         Assert.Fail ("Unexcepted exception {0} at iteration {1}", e, i);
549                                 }
550                         }
551                 }
552
553                 [Test]
554                 [ExpectedException (typeof (ArgumentException))]
555 #if TARGET_JVM
556                 [Category ("NotWorking")]
557 #endif
558                 public void Dispose_ToHFont ()
559                 {
560                         Font f = new Font (name, 12.5f);
561                         f.Dispose ();
562                         f.ToHfont ();
563                 }
564         }
565 }