[bcl] Remove more NET_2_0 checks from class libs
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing / TestFont.cs
1 //
2 // Test Font class testing unit
3 //
4 // Authors:
5 //      Jordi Mas i Hernandez, jordi@ximian.com
6 //      Peter Dennis Bartok, pbartok@novell.com
7 //      Sebastien Pouliot  <sebastien@ximian.com>
8 //
9 // (C) 2003 Ximian, Inc.  http://www.ximian.com
10 // Copyright (C) 2004-2007 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
32 using NUnit.Framework;
33 using System;
34 using System.Drawing;
35 using System.Drawing.Text;
36 using System.Security;
37 using System.Security.Permissions;
38 using System.Runtime.InteropServices;
39
40 namespace MonoTests.System.Drawing{
41
42         [TestFixture]
43         public class FontTest {
44
45                 private string name;
46
47                 [TestFixtureSetUp]
48                 public void FixtureSetUp ()
49                 {
50                         try {
51                                 using (FontFamily ff = new FontFamily (GenericFontFamilies.Monospace)) {
52                                         name = ff.Name;
53                                 }
54                         }
55                         catch (ArgumentException) {
56                                 Assert.Ignore ("No font family could be found.");
57                         }
58                 }
59
60                 // Test basic Font clone, properties and contructor
61                 [Test]
62                 [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
63                 public void TestClone()
64                 {               
65                         Font f = new Font("Arial",12);  
66                         Font f2 = (Font) f.Clone();
67                         
68                         Assert.AreEqual (f.Bold, f2.Bold, "Bold");
69                         Assert.AreEqual (f.FontFamily, f2.FontFamily, "FontFamily");
70                         Assert.AreEqual (f.GdiCharSet, f2.GdiCharSet, "GdiCharSet");
71                         Assert.AreEqual (f.GdiVerticalFont, f2.GdiVerticalFont, "GdiVerticalFont");
72                         Assert.AreEqual (f.Height, f2.Height, "Height");
73                         Assert.AreEqual (f.Italic, f2.Italic, "Italic");
74                         Assert.AreEqual (f.Name, f2.Name, "Name");
75                         Assert.AreEqual (f.Size, f2.Size, "Size");
76                         Assert.AreEqual (f.SizeInPoints, f2.SizeInPoints, "SizeInPoints");
77                         Assert.AreEqual (f.Strikeout, f2.Strikeout, "Strikeout");
78                         Assert.AreEqual (f.Style, f2.Style, "Style");
79                         Assert.AreEqual (f.Underline, f2.Underline, "Underline");
80                         Assert.AreEqual (f.Unit, f2.Unit, "Unit");
81                 }
82
83                 [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
84                 class LOGFONT {
85                         public int lfHeight;
86                         public int lfWidth;
87                         public int lfEscapement;
88                         public int lfOrientation;
89                         public int lfWeight;
90                         public byte lfItalic;
91                         public byte lfUnderline;
92                         public byte lfStrikeOut;
93                         public byte lfCharSet;
94                         public byte lfOutPrecision;
95                         public byte lfClipPrecision;
96                         public byte lfQuality;
97                         public byte lfPitchAndFamily;
98                         [ MarshalAs(UnmanagedType.ByValTStr, SizeConst=32) ]
99                         public string lfFaceName;
100                 }
101
102                 [StructLayout (LayoutKind.Sequential, CharSet = CharSet.Auto)]
103                 struct LOGFONT_STRUCT {
104                         public int lfHeight;
105                         public int lfWidth;
106                         public int lfEscapement;
107                         public int lfOrientation;
108                         public int lfWeight;
109                         public byte lfItalic;
110                         public byte lfUnderline;
111                         public byte lfStrikeOut;
112                         public byte lfCharSet;
113                         public byte lfOutPrecision;
114                         public byte lfClipPrecision;
115                         public byte lfQuality;
116                         public byte lfPitchAndFamily;
117                         [MarshalAs (UnmanagedType.ByValTStr, SizeConst = 32)]
118                         public string lfFaceName;
119                 }
120
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                 [ExpectedException (typeof (AccessViolationException))]
192                 public void ToLogFont_Null ()
193                 {
194                         Font f = new Font ("Arial", 10);
195                         f.ToLogFont (null);
196                 }
197                 [Test]
198 #if ONLY_1_1
199                 [ExpectedException (typeof (ArgumentNullException))]
200 #endif
201                 public void Font_StringNull_Float ()
202                 {
203                         string family = null;
204                         Font f = new Font (family, 12.5f);
205                         Assert.AreEqual (FontFamily.GenericSansSerif, f.FontFamily, "FontFamily");
206                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
207                         Assert.AreEqual (12.5f, f.Size, "Size");
208                         Assert.AreEqual (12.5f, f.SizeInPoints, "SizeInPoints");
209                         Assert.AreEqual (GraphicsUnit.Point, f.Unit, "Unit");
210                 }
211
212                 [Test]
213                 public void Font_String_Float ()
214                 {
215                         Font f = new Font (name, 12.5f);
216                         Assert.AreEqual (FontFamily.GenericMonospace, f.FontFamily, "FontFamily");
217                         Assert.IsFalse (f.Bold, "Bold");
218                         Assert.AreEqual (1, f.GdiCharSet, "GdiCharSet");
219                         Assert.IsFalse (f.GdiVerticalFont, "GdiVerticalFont");
220                         Assert.IsTrue (f.Height > 0, "Height");
221                         Assert.IsFalse (f.Italic, "Italic");
222                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
223                         Assert.AreEqual (12.5f, f.Size, "Size");
224                         Assert.AreEqual (12.5f, f.SizeInPoints, "SizeInPoints");
225                         Assert.IsFalse (f.Strikeout, "Strikeout");
226                         Assert.IsFalse (f.Underline, "Underline");
227                         Assert.AreEqual (GraphicsUnit.Point, f.Unit, "Unit");
228                 }
229
230                 [Test]
231                 public void Font_String_Float_FontStyle ()
232                 {
233                         Font f = new Font (name, 12.5f, FontStyle.Bold);
234                         Assert.AreEqual (FontFamily.GenericMonospace, f.FontFamily, "FontFamily");
235                         Assert.IsTrue (f.Bold, "Bold");
236                         Assert.AreEqual (1, f.GdiCharSet, "GdiCharSet");
237                         Assert.IsFalse (f.GdiVerticalFont, "GdiVerticalFont");
238                         Assert.IsTrue (f.Height > 0, "Height");
239                         Assert.IsFalse (f.Italic, "Italic");
240                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
241                         Assert.AreEqual (12.5f, f.Size, "Size");
242                         Assert.AreEqual (12.5f, f.SizeInPoints, "SizeInPoints");
243                         Assert.IsFalse (f.Strikeout, "Strikeout");
244                         Assert.IsFalse (f.Underline, "Underline");
245                         Assert.AreEqual (GraphicsUnit.Point, f.Unit, "Unit");
246                 }
247
248                 [Test]
249                 public void Font_String_Float_FontStyle_GraphicsUnit ()
250                 {
251                         Font f = new Font (name, 12.5f, FontStyle.Italic, GraphicsUnit.Pixel);
252                         Assert.IsFalse (f.Bold, "Bold");
253                         Assert.AreEqual (1, f.GdiCharSet, "GdiCharSet");
254                         Assert.IsFalse (f.GdiVerticalFont, "GdiVerticalFont");
255                         Assert.IsTrue (f.Height > 0, "Height");
256                         Assert.IsTrue (f.Italic, "Italic");
257                         Assert.AreEqual (FontFamily.GenericMonospace, f.FontFamily, "FontFamily");
258                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
259                         Assert.AreEqual (12.5f, f.Size, "Size");
260                         Assert.IsFalse (f.Strikeout, "Strikeout");
261                         Assert.IsFalse (f.Underline, "Underline");
262                         Assert.AreEqual (GraphicsUnit.Pixel, f.Unit, "Unit");
263                 }
264
265                 [Test]
266                 [ExpectedException (typeof (ArgumentException))]
267                 public void Font_String_Float_FontStyle_GraphicsUnit_Display ()
268                 {
269                         new Font (name, 12.5f, FontStyle.Italic, GraphicsUnit.Display);
270                 }
271
272                 [Test]
273                 public void Font_String_Float_FontStyle_GraphicsUnit_Byte ()
274                 {
275                         Font f = new Font (name, 12.5f, FontStyle.Strikeout, GraphicsUnit.Inch, Byte.MaxValue);
276                         Assert.IsFalse (f.Bold, "Bold");
277                         Assert.AreEqual (Byte.MaxValue, f.GdiCharSet, "GdiCharSet");
278                         Assert.IsFalse (f.GdiVerticalFont, "GdiVerticalFont");
279                         Assert.IsTrue (f.Height > 0, "Height");
280                         Assert.IsFalse (f.Italic, "Italic");
281                         Assert.AreEqual (FontFamily.GenericMonospace, f.FontFamily, "FontFamily");
282                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
283                         Assert.AreEqual (12.5f, f.Size, "Size");
284                         Assert.AreEqual (900f, f.SizeInPoints, "SizeInPoints");
285                         Assert.IsTrue (f.Strikeout, "Strikeout");
286                         Assert.IsFalse (f.Underline, "Underline");
287                         Assert.AreEqual (GraphicsUnit.Inch, f.Unit, "Unit");
288                 }
289
290                 [Test]
291                 public void Font_String_Float_FontStyle_GraphicsUnit_Byte_Bool ()
292                 {
293                         Font f = new Font (name, 12.5f, FontStyle.Underline, GraphicsUnit.Document, Byte.MinValue, true);
294                         Assert.IsFalse (f.Bold, "Bold");
295                         Assert.AreEqual (Byte.MinValue, f.GdiCharSet, "GdiCharSet");
296                         Assert.IsTrue (f.GdiVerticalFont, "GdiVerticalFont");
297                         Assert.IsTrue (f.Height > 0, "Height");
298                         Assert.IsFalse (f.Italic, "Italic");
299                         Assert.AreEqual (FontFamily.GenericMonospace, f.FontFamily, "FontFamily");
300                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
301                         Assert.AreEqual (12.5f, f.Size, "Size");
302                         Assert.AreEqual (3f, f.SizeInPoints, "SizeInPoints");
303                         Assert.IsFalse (f.Strikeout, "Strikeout");
304                         Assert.IsTrue (f.Underline, "Underline");
305                         Assert.AreEqual (GraphicsUnit.Document, f.Unit, "Unit");
306                 }
307
308                 [Test]
309                 [ExpectedException (typeof (ArgumentNullException))]
310                 public void Font_FontFamilyNull_Float ()
311                 {
312                         FontFamily ff = null;
313                         new Font (ff, 12.5f);
314                 }
315
316                 [Test]
317                 [ExpectedException (typeof (NullReferenceException))]
318                 public void Font_FontNull_FontStyle ()
319                 {
320                         Font f = null;
321                         new Font (f, FontStyle.Bold);
322                 }
323
324                 [Test]
325                 public void Font_FontFamily_Float ()
326                 {
327                         Font f = new Font (FontFamily.GenericMonospace, 12.5f);
328                         Assert.AreEqual (FontFamily.GenericMonospace, f.FontFamily, "FontFamily");
329                         Assert.IsFalse (f.Bold, "Bold");
330                         Assert.AreEqual (1, f.GdiCharSet, "GdiCharSet");
331                         Assert.IsFalse (f.GdiVerticalFont, "GdiVerticalFont");
332                         Assert.IsTrue (f.Height > 0, "Height");
333                         Assert.IsFalse (f.Italic, "Italic");
334                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
335                         Assert.AreEqual (12.5f, f.Size, "Size");
336                         Assert.AreEqual (12.5f, f.SizeInPoints, "SizeInPoints");
337                         Assert.IsFalse (f.Strikeout, "Strikeout");
338                         Assert.IsFalse (f.Underline, "Underline");
339                         Assert.AreEqual (GraphicsUnit.Point, f.Unit, "Unit");
340                 }
341
342                 [Test]
343                 public void Font_FontFamily_Float_FontStyle ()
344                 {
345                         Font f = new Font (FontFamily.GenericMonospace, 12.5f, FontStyle.Bold);
346                         Assert.AreEqual (FontFamily.GenericMonospace, f.FontFamily, "FontFamily");
347                         Assert.IsTrue (f.Bold, "Bold");
348                         Assert.AreEqual (1, f.GdiCharSet, "GdiCharSet");
349                         Assert.IsFalse (f.GdiVerticalFont, "GdiVerticalFont");
350                         Assert.IsTrue (f.Height > 0, "Height");
351                         Assert.IsFalse (f.Italic, "Italic");
352                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
353                         Assert.AreEqual (12.5f, f.Size, "Size");
354                         Assert.AreEqual (12.5f, f.SizeInPoints, "SizeInPoints");
355                         Assert.IsFalse (f.Strikeout, "Strikeout");
356                         Assert.IsFalse (f.Underline, "Underline");
357                         Assert.AreEqual (GraphicsUnit.Point, f.Unit, "Unit");
358                 }
359
360                 [Test]
361                 public void Font_FontFamily_Float_FontStyle_GraphicsUnit ()
362                 {
363                         Font f = new Font (FontFamily.GenericMonospace, 12.5f, FontStyle.Italic, GraphicsUnit.Millimeter);
364                         Assert.IsFalse (f.Bold, "Bold");
365                         Assert.AreEqual (1, f.GdiCharSet, "GdiCharSet");
366                         Assert.IsFalse (f.GdiVerticalFont, "GdiVerticalFont");
367                         Assert.IsTrue (f.Height > 0, "Height");
368                         Assert.IsTrue (f.Italic, "Italic");
369                         Assert.AreEqual (FontFamily.GenericMonospace, f.FontFamily, "FontFamily");
370                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
371                         Assert.AreEqual (12.5f, f.Size, "Size");
372                         Assert.AreEqual (35.43307f, f.SizeInPoints, "SizeInPoints");
373                         Assert.IsFalse (f.Strikeout, "Strikeout");
374                         Assert.IsFalse (f.Underline, "Underline");
375                         Assert.AreEqual (GraphicsUnit.Millimeter, f.Unit, "Unit");
376                 }
377
378                 [Test]
379                 [ExpectedException (typeof (ArgumentException))]
380                 public void Font_FontFamily_Float_FontStyle_GraphicsUnit_Display ()
381                 {
382                         new Font (FontFamily.GenericMonospace, 12.5f, FontStyle.Italic, GraphicsUnit.Display);
383                 }
384
385                 [Test]
386                 public void Font_FontFamily_Float_FontStyle_GraphicsUnit_Byte ()
387                 {
388                         Font f = new Font (FontFamily.GenericMonospace, 12.5f, FontStyle.Strikeout, GraphicsUnit.Inch, Byte.MaxValue);
389                         Assert.IsFalse (f.Bold, "Bold");
390                         Assert.AreEqual (Byte.MaxValue, f.GdiCharSet, "GdiCharSet");
391                         Assert.IsFalse (f.GdiVerticalFont, "GdiVerticalFont");
392                         Assert.IsTrue (f.Height > 0, "Height");
393                         Assert.IsFalse (f.Italic, "Italic");
394                         Assert.AreEqual (FontFamily.GenericMonospace, f.FontFamily, "FontFamily");
395                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
396                         Assert.AreEqual (12.5f, f.Size, "Size");
397                         Assert.AreEqual (900f, f.SizeInPoints, "SizeInPoints");
398                         Assert.IsTrue (f.Strikeout, "Strikeout");
399                         Assert.IsFalse (f.Underline, "Underline");
400                         Assert.AreEqual (GraphicsUnit.Inch, f.Unit, "Unit");
401                 }
402
403                 [Test]
404                 public void Font_FontFamily_Float_FontStyle_GraphicsUnit_Byte_Bool ()
405                 {
406                         Font f = new Font (FontFamily.GenericMonospace, 12.5f, FontStyle.Underline, GraphicsUnit.Document, Byte.MinValue, true);
407                         Assert.IsFalse (f.Bold, "Bold");
408                         Assert.AreEqual (Byte.MinValue, f.GdiCharSet, "GdiCharSet");
409                         Assert.IsTrue (f.GdiVerticalFont, "GdiVerticalFont");
410                         Assert.IsTrue (f.Height > 0, "Height");
411                         Assert.IsFalse (f.Italic, "Italic");
412                         Assert.AreEqual (FontFamily.GenericMonospace, f.FontFamily, "FontFamily");
413                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
414                         Assert.AreEqual (12.5f, f.Size, "Size");
415                         Assert.AreEqual (3f, f.SizeInPoints, "SizeInPoints");
416                         Assert.IsFalse (f.Strikeout, "Strikeout");
417                         Assert.IsTrue (f.Underline, "Underline");
418                         Assert.AreEqual (GraphicsUnit.Document, f.Unit, "Unit");
419                 }
420
421                 [Test]
422                 public void Dispose_Double ()
423                 {
424                         Font f = new Font (name, 12.5f);
425                         f.Dispose ();
426                         f.Dispose ();
427                 }
428
429                 [Test]
430                 public void Dispose_UseAfter_Works ()
431                 {
432                         Font f = new Font (name, 12.5f);
433                         string fname = f.Name;
434                         f.Dispose ();
435                         // most properties don't throw, everything seems to be cached
436                         Assert.AreEqual (fname, f.Name, "Name");
437                         Assert.AreEqual (12.5f, f.Size, "Size");
438                 }
439
440                 [Test]
441                 [ExpectedException (typeof (ArgumentException))]
442                 public void Dispose_Height ()
443                 {
444                         Font f = new Font (name, 12.5f);
445                         f.Dispose ();
446                         Assert.AreEqual (0, f.Height, "Name");
447                 }
448
449                 [Test]
450                 [ExpectedException (typeof (ArgumentException))]
451                 public void Dispose_ToLogFont ()
452                 {
453                         Font f = new Font (name, 12.5f);
454                         f.Dispose ();
455                         LOGFONT lf = new LOGFONT();
456                         f.ToLogFont (lf);
457                 }
458
459                 [Test]
460                 public void Dispose_ToLogFont_LoopCharSet ()
461                 {
462                         Font f = new Font (name, 12.5f);
463                         f.Dispose ();
464                         LOGFONT lf = new LOGFONT ();
465
466                         for (int i = Byte.MinValue; i < Byte.MaxValue; i++) {
467                                 byte b = (byte) i;
468                                 lf.lfHeight = b;
469                                 lf.lfWidth = b;
470                                 lf.lfEscapement = b;
471                                 lf.lfOrientation = b;
472                                 lf.lfWeight = b;
473                                 lf.lfItalic = b;
474                                 lf.lfUnderline = b;
475                                 lf.lfStrikeOut = b;
476                                 lf.lfCharSet = b;
477                                 lf.lfOutPrecision = b;
478                                 lf.lfClipPrecision = b;
479                                 lf.lfQuality = b;
480                                 lf.lfPitchAndFamily = b;
481                                 lf.lfFaceName = b.ToString ();
482                                 try {
483                                         f.ToLogFont (lf);
484                                 }
485                                 catch (ArgumentException) {
486                                         Assert.AreEqual (b, lf.lfHeight, "lfHeight");
487                                         Assert.AreEqual (b, lf.lfWidth, "lfWidth");
488                                         Assert.AreEqual (b, lf.lfEscapement, "lfEscapement");
489                                         Assert.AreEqual (b, lf.lfOrientation, "lfOrientation");
490                                         Assert.AreEqual (b, lf.lfWeight, "lfWeight");
491                                         Assert.AreEqual (b, lf.lfItalic, "lfItalic");
492                                         Assert.AreEqual (b, lf.lfUnderline, "lfUnderline");
493                                         Assert.AreEqual (b, lf.lfStrikeOut, "lfStrikeOut");
494                                         // special case for 0
495                                         Assert.AreEqual ((i == 0) ? (byte)1 : b, lf.lfCharSet, "lfCharSet");
496                                         Assert.AreEqual (b, lf.lfOutPrecision, "lfOutPrecision");
497                                         Assert.AreEqual (b, lf.lfClipPrecision, "lfClipPrecision");
498                                         Assert.AreEqual (b, lf.lfQuality, "lfQuality");
499                                         Assert.AreEqual (b, lf.lfPitchAndFamily, "lfPitchAndFamily");
500                                         Assert.AreEqual (b.ToString (), lf.lfFaceName, "lfFaceName");
501                                 }
502                                 catch (Exception e) {
503                                         Assert.Fail ("Unexcepted exception {0} at iteration {1}", e, i);
504                                 }
505                         }
506                 }
507
508                 [Test]
509                 [ExpectedException (typeof (ArgumentException))]
510                 public void Dispose_ToHFont ()
511                 {
512                         Font f = new Font (name, 12.5f);
513                         f.Dispose ();
514                         f.ToHfont ();
515                 }
516                 
517                 [Test]
518                 [ExpectedException (typeof (ArgumentException))]
519                 [Category ("NotWorking")]
520                 public void UnavailableStyleException ()
521                 {
522                         // Marked NotWorking because it is dependent on what fonts/styles are available
523                         // on the OS.  This test is written for Windows.
524                         Font f = new Font ("Monotype Corsiva", 8, FontStyle.Regular);
525                 }
526
527                 [Test]
528                 public void GetHeight_Float ()
529                 {
530                         using (Font f = new Font (name, 12.5f)) {
531                                 Assert.AreEqual (0, f.GetHeight (0), "0");
532                         }
533                 }
534
535                 [Test]
536                 public void GetHeight_Graphics ()
537                 {
538                         using (Bitmap bmp = new Bitmap (10, 10)) {
539                                 using (Graphics g = Graphics.FromImage (bmp)) {
540                                         using (Font f = new Font (name, 12.5f)) {
541                                                 float expected = f.GetHeight (g.DpiY);
542                                                 Assert.AreEqual (expected, f.GetHeight (g), 0.01f, "Default");
543                                                 g.ScaleTransform (2, 4);
544                                                 Assert.AreEqual (expected, f.GetHeight (g), 0.01f, "ScaleTransform");
545                                                 g.PageScale = 3;
546                                                 Assert.AreEqual (expected, f.GetHeight (g), 0.01f, "PageScale");
547                                         }
548                                 }
549                         }
550                 }
551
552                 [Test]
553                 [ExpectedException (typeof (ArgumentNullException))]
554                 public void GetHeight_Graphics_Null ()
555                 {
556                         using (Font f = new Font (name, 12.5f)) {
557                                 Assert.AreEqual (0, f.GetHeight (null), "0");
558                         }
559                 }
560
561                 [Test]
562                 public void FontUniqueHashCode ()
563                 {
564                         Font f1 = new Font ("Arial", 14);
565                         Font f2 = new Font ("Arial", 12);
566                         Font f3 = new Font (f1, FontStyle.Bold);
567
568                         Assert.IsFalse (f1.GetHashCode () == f2.GetHashCode (), "1) Fonts with different sizes should have different HashCodes");
569                         Assert.IsFalse (f1.GetHashCode () == f3.GetHashCode (), "2) Fonts with different styles should have different HashCodes");
570                 }
571
572         [Test]
573         public void GetHashCode_UnitDiffers_HashesNotEqual()
574         {
575             Font f1 = new Font("Arial", 8.25F, GraphicsUnit.Point);
576             Font f2 = new Font("Arial", 8.25F, GraphicsUnit.Pixel);
577
578             Assert.IsFalse(f1.GetHashCode() == f2.GetHashCode(),
579                 "Hashcodes should differ if _unit member differs");
580         }
581
582         [Test]
583         public void GetHashCode_NameDiffers_HashesNotEqual()
584         {
585             Font f1 = new Font("Arial", 8.25F, GraphicsUnit.Point);
586             Font f2 = new Font("Courier New", 8.25F, GraphicsUnit.Point);
587
588             Assert.IsFalse(f1.GetHashCode() == f2.GetHashCode(),
589                 "Hashcodes should differ if _name member differs");
590         }
591
592         [Test]
593         public void GetHashCode_StyleEqualsGdiCharSet_HashesNotEqual()
594         {
595             Font f1 = new Font("Arial", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
596             Font f2 = new Font("Arial", 8.25F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(1)));
597
598             Assert.IsFalse(f1.GetHashCode() == f2.GetHashCode(),
599                 "Hashcodes should differ if _style member differs");
600         }
601         }
602 }