e1f3660f707e9689ef4ebbd09bbaaecdd32a8528
[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                 [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
124                 public void ToLogFont_DenyUnmanagedCode ()
125                 {
126                         Font f;
127                         LOGFONT lf;
128
129                         lf = new LOGFONT();
130                         f = new Font("Arial", 10);
131
132                         Assert.Throws<SecurityException> (() => f.ToLogFont(lf));
133                 }
134
135                 [Test]
136                 [SecurityPermission (SecurityAction.Assert, UnmanagedCode = true)]
137                 public void ToLogFont_AssertUnmanagedCode ()
138                 {
139                         Font f = new Font("Arial", 10);
140                         LOGFONT lf = new LOGFONT();
141
142                         f.ToLogFont (lf);
143                         Assert.AreEqual (400, lf.lfWeight, "lfWeight");
144                         Assert.AreEqual (1, lf.lfCharSet, "lfCharSet");
145                         Assert.AreEqual (f.Name, lf.lfFaceName, "lfFaceName");
146
147                         LOGFONT_STRUCT lfs = new LOGFONT_STRUCT ();
148                         f.ToLogFont (lfs);
149                         Assert.AreEqual (0, lfs.lfWeight, "struct-lfWeight");
150                         Assert.AreEqual (0, lfs.lfCharSet, "struct-lfCharSet");
151                         Assert.AreEqual (0, lfs.lfHeight, "struct-lfHeight");
152                         Assert.AreEqual (0, lfs.lfWidth, "struct-lfWidth");
153                         Assert.AreEqual (0, lfs.lfEscapement, "struct-lfEscapement");
154                         Assert.AreEqual (0, lfs.lfOrientation, "struct-lfOrientation");
155                         Assert.AreEqual (0, lfs.lfWeight, "struct-lfWeight");
156                         Assert.AreEqual (0, lfs.lfItalic, "struct-lfItalic");
157                         Assert.AreEqual (0, lfs.lfUnderline, "struct-lfUnderline");
158                         Assert.AreEqual (0, lfs.lfStrikeOut, "struct-lfStrikeOut");
159                         Assert.AreEqual (0, lfs.lfCharSet, "struct-lfCharSet");
160                         Assert.AreEqual (0, lfs.lfOutPrecision, "struct-lfOutPrecision");
161                         Assert.AreEqual (0, lfs.lfClipPrecision, "struct-lfClipPrecision");
162                         Assert.AreEqual (0, lfs.lfQuality, "struct-lfQuality");
163                         Assert.AreEqual (0, lfs.lfPitchAndFamily, "struct-lfPitchAndFamily");
164                         Assert.IsNull (lfs.lfFaceName, "struct-lfFaceName");
165                 }
166
167                 [Test]
168                 [SecurityPermission (SecurityAction.Assert, UnmanagedCode = true)]
169                 public void ToLogFont_TooSmall ()
170                 {
171                         Font f = new Font ("Arial", 10);
172                         object o = new object ();
173                         Assert.Throws<ArgumentException> (() => f.ToLogFont (o));
174                         // no PInvoke conversion exists !?!?
175                 }
176
177                 [Test]
178                 [SecurityPermission (SecurityAction.Assert, UnmanagedCode = true)]
179                 public void ToLogFont_Int ()
180                 {
181                         Font f = new Font ("Arial", 10);
182                         int i = 1;
183                         f.ToLogFont (i);
184                         Assert.AreEqual (1, i);
185                 }
186
187                 [Test]
188                 [SecurityPermission (SecurityAction.Assert, UnmanagedCode = true)]
189                 public void ToLogFont_Null ()
190                 {
191                         Font f = new Font ("Arial", 10);
192                         Assert.Throws<AccessViolationException> (() => f.ToLogFont (null));
193                 }
194                 [Test]
195                 public void Font_StringNull_Float ()
196                 {
197                         string family = null;
198                         Font f = new Font (family, 12.5f);
199                         Assert.AreEqual (FontFamily.GenericSansSerif, f.FontFamily, "FontFamily");
200                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
201                         Assert.AreEqual (12.5f, f.Size, "Size");
202                         Assert.AreEqual (12.5f, f.SizeInPoints, "SizeInPoints");
203                         Assert.AreEqual (GraphicsUnit.Point, f.Unit, "Unit");
204                 }
205
206                 [Test]
207                 public void Font_String_Float ()
208                 {
209                         Font f = new Font (name, 12.5f);
210                         Assert.AreEqual (FontFamily.GenericMonospace, f.FontFamily, "FontFamily");
211                         Assert.IsFalse (f.Bold, "Bold");
212                         Assert.AreEqual (1, f.GdiCharSet, "GdiCharSet");
213                         Assert.IsFalse (f.GdiVerticalFont, "GdiVerticalFont");
214                         Assert.IsTrue (f.Height > 0, "Height");
215                         Assert.IsFalse (f.Italic, "Italic");
216                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
217                         Assert.AreEqual (12.5f, f.Size, "Size");
218                         Assert.AreEqual (12.5f, f.SizeInPoints, "SizeInPoints");
219                         Assert.IsFalse (f.Strikeout, "Strikeout");
220                         Assert.IsFalse (f.Underline, "Underline");
221                         Assert.AreEqual (GraphicsUnit.Point, f.Unit, "Unit");
222                 }
223
224                 [Test]
225                 public void Font_String_Float_FontStyle ()
226                 {
227                         Font f = new Font (name, 12.5f, FontStyle.Bold);
228                         Assert.AreEqual (FontFamily.GenericMonospace, f.FontFamily, "FontFamily");
229                         Assert.IsTrue (f.Bold, "Bold");
230                         Assert.AreEqual (1, f.GdiCharSet, "GdiCharSet");
231                         Assert.IsFalse (f.GdiVerticalFont, "GdiVerticalFont");
232                         Assert.IsTrue (f.Height > 0, "Height");
233                         Assert.IsFalse (f.Italic, "Italic");
234                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
235                         Assert.AreEqual (12.5f, f.Size, "Size");
236                         Assert.AreEqual (12.5f, f.SizeInPoints, "SizeInPoints");
237                         Assert.IsFalse (f.Strikeout, "Strikeout");
238                         Assert.IsFalse (f.Underline, "Underline");
239                         Assert.AreEqual (GraphicsUnit.Point, f.Unit, "Unit");
240                 }
241
242                 [Test]
243                 public void Font_String_Float_FontStyle_GraphicsUnit ()
244                 {
245                         Font f = new Font (name, 12.5f, FontStyle.Italic, GraphicsUnit.Pixel);
246                         Assert.IsFalse (f.Bold, "Bold");
247                         Assert.AreEqual (1, f.GdiCharSet, "GdiCharSet");
248                         Assert.IsFalse (f.GdiVerticalFont, "GdiVerticalFont");
249                         Assert.IsTrue (f.Height > 0, "Height");
250                         Assert.IsTrue (f.Italic, "Italic");
251                         Assert.AreEqual (FontFamily.GenericMonospace, f.FontFamily, "FontFamily");
252                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
253                         Assert.AreEqual (12.5f, f.Size, "Size");
254                         Assert.IsFalse (f.Strikeout, "Strikeout");
255                         Assert.IsFalse (f.Underline, "Underline");
256                         Assert.AreEqual (GraphicsUnit.Pixel, f.Unit, "Unit");
257                 }
258
259                 [Test]
260                 public void Font_String_Float_FontStyle_GraphicsUnit_Display ()
261                 {
262                         Assert.Throws<ArgumentException> (() => new Font (name, 12.5f, FontStyle.Italic, GraphicsUnit.Display));
263                 }
264
265                 [Test]
266                 public void Font_String_Float_FontStyle_GraphicsUnit_Byte ()
267                 {
268                         Font f = new Font (name, 12.5f, FontStyle.Strikeout, GraphicsUnit.Inch, Byte.MaxValue);
269                         Assert.IsFalse (f.Bold, "Bold");
270                         Assert.AreEqual (Byte.MaxValue, f.GdiCharSet, "GdiCharSet");
271                         Assert.IsFalse (f.GdiVerticalFont, "GdiVerticalFont");
272                         Assert.IsTrue (f.Height > 0, "Height");
273                         Assert.IsFalse (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.AreEqual (900f, f.SizeInPoints, "SizeInPoints");
278                         Assert.IsTrue (f.Strikeout, "Strikeout");
279                         Assert.IsFalse (f.Underline, "Underline");
280                         Assert.AreEqual (GraphicsUnit.Inch, f.Unit, "Unit");
281                 }
282
283                 [Test]
284                 public void Font_String_Float_FontStyle_GraphicsUnit_Byte_Bool ()
285                 {
286                         Font f = new Font (name, 12.5f, FontStyle.Underline, GraphicsUnit.Document, Byte.MinValue, true);
287                         Assert.IsFalse (f.Bold, "Bold");
288                         Assert.AreEqual (Byte.MinValue, f.GdiCharSet, "GdiCharSet");
289                         Assert.IsTrue (f.GdiVerticalFont, "GdiVerticalFont");
290                         Assert.IsTrue (f.Height > 0, "Height");
291                         Assert.IsFalse (f.Italic, "Italic");
292                         Assert.AreEqual (FontFamily.GenericMonospace, f.FontFamily, "FontFamily");
293                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
294                         Assert.AreEqual (12.5f, f.Size, "Size");
295                         Assert.AreEqual (3f, f.SizeInPoints, "SizeInPoints");
296                         Assert.IsFalse (f.Strikeout, "Strikeout");
297                         Assert.IsTrue (f.Underline, "Underline");
298                         Assert.AreEqual (GraphicsUnit.Document, f.Unit, "Unit");
299                 }
300
301                 [Test]
302                 public void Font_FontFamilyNull_Float ()
303                 {
304                         FontFamily ff = null;
305                         Assert.Throws<ArgumentNullException> (() => new Font (ff, 12.5f));
306                 }
307
308                 [Test]
309                 public void Font_FontNull_FontStyle ()
310                 {
311                         Font f = null;
312                         Assert.Throws<NullReferenceException> (() => new Font (f, FontStyle.Bold));
313                 }
314
315                 [Test]
316                 public void Font_FontFamily_Float ()
317                 {
318                         Font f = new Font (FontFamily.GenericMonospace, 12.5f);
319                         Assert.AreEqual (FontFamily.GenericMonospace, f.FontFamily, "FontFamily");
320                         Assert.IsFalse (f.Bold, "Bold");
321                         Assert.AreEqual (1, f.GdiCharSet, "GdiCharSet");
322                         Assert.IsFalse (f.GdiVerticalFont, "GdiVerticalFont");
323                         Assert.IsTrue (f.Height > 0, "Height");
324                         Assert.IsFalse (f.Italic, "Italic");
325                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
326                         Assert.AreEqual (12.5f, f.Size, "Size");
327                         Assert.AreEqual (12.5f, f.SizeInPoints, "SizeInPoints");
328                         Assert.IsFalse (f.Strikeout, "Strikeout");
329                         Assert.IsFalse (f.Underline, "Underline");
330                         Assert.AreEqual (GraphicsUnit.Point, f.Unit, "Unit");
331                 }
332
333                 [Test]
334                 public void Font_FontFamily_Float_FontStyle ()
335                 {
336                         Font f = new Font (FontFamily.GenericMonospace, 12.5f, FontStyle.Bold);
337                         Assert.AreEqual (FontFamily.GenericMonospace, f.FontFamily, "FontFamily");
338                         Assert.IsTrue (f.Bold, "Bold");
339                         Assert.AreEqual (1, f.GdiCharSet, "GdiCharSet");
340                         Assert.IsFalse (f.GdiVerticalFont, "GdiVerticalFont");
341                         Assert.IsTrue (f.Height > 0, "Height");
342                         Assert.IsFalse (f.Italic, "Italic");
343                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
344                         Assert.AreEqual (12.5f, f.Size, "Size");
345                         Assert.AreEqual (12.5f, f.SizeInPoints, "SizeInPoints");
346                         Assert.IsFalse (f.Strikeout, "Strikeout");
347                         Assert.IsFalse (f.Underline, "Underline");
348                         Assert.AreEqual (GraphicsUnit.Point, f.Unit, "Unit");
349                 }
350
351                 [Test]
352                 public void Font_FontFamily_Float_FontStyle_GraphicsUnit ()
353                 {
354                         Font f = new Font (FontFamily.GenericMonospace, 12.5f, FontStyle.Italic, GraphicsUnit.Millimeter);
355                         Assert.IsFalse (f.Bold, "Bold");
356                         Assert.AreEqual (1, f.GdiCharSet, "GdiCharSet");
357                         Assert.IsFalse (f.GdiVerticalFont, "GdiVerticalFont");
358                         Assert.IsTrue (f.Height > 0, "Height");
359                         Assert.IsTrue (f.Italic, "Italic");
360                         Assert.AreEqual (FontFamily.GenericMonospace, f.FontFamily, "FontFamily");
361                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
362                         Assert.AreEqual (12.5f, f.Size, "Size");
363                         Assert.AreEqual (35.43307f, f.SizeInPoints, "SizeInPoints");
364                         Assert.IsFalse (f.Strikeout, "Strikeout");
365                         Assert.IsFalse (f.Underline, "Underline");
366                         Assert.AreEqual (GraphicsUnit.Millimeter, f.Unit, "Unit");
367                 }
368
369                 [Test]
370                 public void Font_FontFamily_Float_FontStyle_GraphicsUnit_Display ()
371                 {
372                         Assert.Throws<ArgumentException> (() => new Font (FontFamily.GenericMonospace, 12.5f, FontStyle.Italic, GraphicsUnit.Display));
373                 }
374
375                 [Test]
376                 public void Font_FontFamily_Float_FontStyle_GraphicsUnit_Byte ()
377                 {
378                         Font f = new Font (FontFamily.GenericMonospace, 12.5f, FontStyle.Strikeout, GraphicsUnit.Inch, Byte.MaxValue);
379                         Assert.IsFalse (f.Bold, "Bold");
380                         Assert.AreEqual (Byte.MaxValue, f.GdiCharSet, "GdiCharSet");
381                         Assert.IsFalse (f.GdiVerticalFont, "GdiVerticalFont");
382                         Assert.IsTrue (f.Height > 0, "Height");
383                         Assert.IsFalse (f.Italic, "Italic");
384                         Assert.AreEqual (FontFamily.GenericMonospace, f.FontFamily, "FontFamily");
385                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
386                         Assert.AreEqual (12.5f, f.Size, "Size");
387                         Assert.AreEqual (900f, f.SizeInPoints, "SizeInPoints");
388                         Assert.IsTrue (f.Strikeout, "Strikeout");
389                         Assert.IsFalse (f.Underline, "Underline");
390                         Assert.AreEqual (GraphicsUnit.Inch, f.Unit, "Unit");
391                 }
392
393                 [Test]
394                 public void Font_FontFamily_Float_FontStyle_GraphicsUnit_Byte_Bool ()
395                 {
396                         Font f = new Font (FontFamily.GenericMonospace, 12.5f, FontStyle.Underline, GraphicsUnit.Document, Byte.MinValue, true);
397                         Assert.IsFalse (f.Bold, "Bold");
398                         Assert.AreEqual (Byte.MinValue, f.GdiCharSet, "GdiCharSet");
399                         Assert.IsTrue (f.GdiVerticalFont, "GdiVerticalFont");
400                         Assert.IsTrue (f.Height > 0, "Height");
401                         Assert.IsFalse (f.Italic, "Italic");
402                         Assert.AreEqual (FontFamily.GenericMonospace, f.FontFamily, "FontFamily");
403                         Assert.AreEqual (f.Name, f.FontFamily.Name, "Name");
404                         Assert.AreEqual (12.5f, f.Size, "Size");
405                         Assert.AreEqual (3f, f.SizeInPoints, "SizeInPoints");
406                         Assert.IsFalse (f.Strikeout, "Strikeout");
407                         Assert.IsTrue (f.Underline, "Underline");
408                         Assert.AreEqual (GraphicsUnit.Document, f.Unit, "Unit");
409                 }
410
411                 [Test]
412                 public void Dispose_Double ()
413                 {
414                         Font f = new Font (name, 12.5f);
415                         f.Dispose ();
416                         f.Dispose ();
417                 }
418
419                 [Test]
420                 public void Dispose_UseAfter_Works ()
421                 {
422                         Font f = new Font (name, 12.5f);
423                         string fname = f.Name;
424                         f.Dispose ();
425                         // most properties don't throw, everything seems to be cached
426                         Assert.AreEqual (fname, f.Name, "Name");
427                         Assert.AreEqual (12.5f, f.Size, "Size");
428                 }
429
430                 [Test]
431                 public void Dispose_Height ()
432                 {
433                         Font f = new Font (name, 12.5f);
434                         f.Dispose ();
435                         Assert.Throws<ArgumentException> (() => { var x = f.Height; });
436                 }
437
438                 [Test]
439                 public void Dispose_ToLogFont ()
440                 {
441                         Font f = new Font (name, 12.5f);
442                         f.Dispose ();
443                         LOGFONT lf = new LOGFONT();
444                         Assert.Throws<ArgumentException> (() => f.ToLogFont (lf));
445                 }
446
447                 [Test]
448                 public void Dispose_ToLogFont_LoopCharSet ()
449                 {
450                         Font f = new Font (name, 12.5f);
451                         f.Dispose ();
452                         LOGFONT lf = new LOGFONT ();
453
454                         for (int i = Byte.MinValue; i < Byte.MaxValue; i++) {
455                                 byte b = (byte) i;
456                                 lf.lfHeight = b;
457                                 lf.lfWidth = b;
458                                 lf.lfEscapement = b;
459                                 lf.lfOrientation = b;
460                                 lf.lfWeight = b;
461                                 lf.lfItalic = b;
462                                 lf.lfUnderline = b;
463                                 lf.lfStrikeOut = b;
464                                 lf.lfCharSet = b;
465                                 lf.lfOutPrecision = b;
466                                 lf.lfClipPrecision = b;
467                                 lf.lfQuality = b;
468                                 lf.lfPitchAndFamily = b;
469                                 lf.lfFaceName = b.ToString ();
470                                 try {
471                                         f.ToLogFont (lf);
472                                 }
473                                 catch (ArgumentException) {
474                                         Assert.AreEqual (b, lf.lfHeight, "lfHeight");
475                                         Assert.AreEqual (b, lf.lfWidth, "lfWidth");
476                                         Assert.AreEqual (b, lf.lfEscapement, "lfEscapement");
477                                         Assert.AreEqual (b, lf.lfOrientation, "lfOrientation");
478                                         Assert.AreEqual (b, lf.lfWeight, "lfWeight");
479                                         Assert.AreEqual (b, lf.lfItalic, "lfItalic");
480                                         Assert.AreEqual (b, lf.lfUnderline, "lfUnderline");
481                                         Assert.AreEqual (b, lf.lfStrikeOut, "lfStrikeOut");
482                                         // special case for 0
483                                         Assert.AreEqual ((i == 0) ? (byte)1 : b, lf.lfCharSet, "lfCharSet");
484                                         Assert.AreEqual (b, lf.lfOutPrecision, "lfOutPrecision");
485                                         Assert.AreEqual (b, lf.lfClipPrecision, "lfClipPrecision");
486                                         Assert.AreEqual (b, lf.lfQuality, "lfQuality");
487                                         Assert.AreEqual (b, lf.lfPitchAndFamily, "lfPitchAndFamily");
488                                         Assert.AreEqual (b.ToString (), lf.lfFaceName, "lfFaceName");
489                                 }
490                                 catch (Exception e) {
491                                         Assert.Fail ("Unexcepted exception {0} at iteration {1}", e, i);
492                                 }
493                         }
494                 }
495
496                 [Test]
497                 public void Dispose_ToHFont ()
498                 {
499                         Font f = new Font (name, 12.5f);
500                         f.Dispose ();
501                         Assert.Throws<ArgumentException> (() => f.ToHfont ());
502                 }
503                 
504                 [Test]
505                 [Category ("NotWorking")]
506                 public void UnavailableStyleException ()
507                 {
508                         // Marked NotWorking because it is dependent on what fonts/styles are available
509                         // on the OS.  This test is written for Windows.
510                         Assert.Throws<ArgumentException> (() => new Font ("Monotype Corsiva", 8, FontStyle.Regular));
511                 }
512
513                 [Test]
514                 public void GetHeight_Float ()
515                 {
516                         using (Font f = new Font (name, 12.5f)) {
517                                 Assert.AreEqual (0, f.GetHeight (0), "0");
518                         }
519                 }
520
521                 [Test]
522                 public void GetHeight_Graphics ()
523                 {
524                         using (Bitmap bmp = new Bitmap (10, 10)) {
525                                 using (Graphics g = Graphics.FromImage (bmp)) {
526                                         using (Font f = new Font (name, 12.5f)) {
527                                                 float expected = f.GetHeight (g.DpiY);
528                                                 Assert.AreEqual (expected, f.GetHeight (g), 0.01f, "Default");
529                                                 g.ScaleTransform (2, 4);
530                                                 Assert.AreEqual (expected, f.GetHeight (g), 0.01f, "ScaleTransform");
531                                                 g.PageScale = 3;
532                                                 Assert.AreEqual (expected, f.GetHeight (g), 0.01f, "PageScale");
533                                         }
534                                 }
535                         }
536                 }
537
538                 [Test]
539                 public void GetHeight_Graphics_Null ()
540                 {
541                         using (Font f = new Font (name, 12.5f)) {
542                                 Assert.Throws<ArgumentNullException> (() => f.GetHeight (null));
543                         }
544                 }
545
546                 [Test]
547                 public void FontUniqueHashCode ()
548                 {
549                         Font f1 = new Font ("Arial", 14);
550                         Font f2 = new Font ("Arial", 12);
551                         Font f3 = new Font (f1, FontStyle.Bold);
552
553                         Assert.IsFalse (f1.GetHashCode () == f2.GetHashCode (), "1) Fonts with different sizes should have different HashCodes");
554                         Assert.IsFalse (f1.GetHashCode () == f3.GetHashCode (), "2) Fonts with different styles should have different HashCodes");
555                 }
556
557                 [Test]
558                 public void GetHashCode_UnitDiffers_HashesNotEqual()
559                 {
560                         Font f1 = new Font("Arial", 8.25F, GraphicsUnit.Point);
561                         Font f2 = new Font("Arial", 8.25F, GraphicsUnit.Pixel);
562
563                         Assert.IsFalse(f1.GetHashCode() == f2.GetHashCode(),
564                                 "Hashcodes should differ if _unit member differs");
565                 }
566
567                 [Test]
568                 public void GetHashCode_NameDiffers_HashesNotEqual()
569                 {
570                         Font f1 = new Font("Arial", 8.25F, GraphicsUnit.Point);
571                         Font f2 = new Font("Courier New", 8.25F, GraphicsUnit.Point);
572
573                         if (f1.Name != f2.Name) {
574                                 Assert.IsFalse(f1.GetHashCode() == f2.GetHashCode(),
575                                                            "Hashcodes should differ if _name member differs");
576                         }
577                 }
578
579                 [Test]
580                 public void GetHashCode_StyleEqualsGdiCharSet_HashesNotEqual()
581                 {
582                         Font f1 = new Font("Arial", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
583                         Font f2 = new Font("Arial", 8.25F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(1)));
584
585                         Assert.IsFalse(f1.GetHashCode() == f2.GetHashCode(),
586                                 "Hashcodes should differ if _style member differs");
587                 }
588         }
589 }