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