2007-03-16 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing / SystemFontsTest.cs
1 //
2 // Tests for System.Drawing.SystemFontsTest
3 //
4 // Authors:
5 //      Gert Driesen  <drieseng@users.sourceforge.net>
6 //      Sebastien Pouliot  <sebastien@ximian.com>
7 //
8 // Copyright (C) 2006-2007 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 #if NET_2_0
31
32 using System;
33 using System.Drawing;
34
35 using NUnit.Framework;
36
37 namespace MonoTests.System.Drawing {
38
39         [TestFixture]
40         public class SystemFontsTest {
41
42                 // avoid lots of failures if no fonts are available (e.g. headless systems)
43                 static bool font_available;
44
45                 [TestFixtureSetUp]
46                 public void FixtureSetUp ()
47                 {
48                         try {
49                                 Font f = SystemFonts.DefaultFont;
50                                 font_available = true;
51                         }
52                         catch (ArgumentException) {
53                                 font_available = false;
54                         }
55                 }
56
57                 [SetUp]
58                 public void SetUp ()
59                 {
60                         if (!font_available)
61                                 Assert.Ignore ("No font family could be found.");
62                 }
63
64                 [Test]
65                 public void DefaultFont ()
66                 {
67                         Font f = SystemFonts.DefaultFont;
68                         Assert.IsFalse (f.Bold, "#1");
69
70                         Assert.AreEqual (true, f.IsSystemFont, "#3");
71                         Assert.IsFalse (f.Italic, "#4");
72                         Assert.AreEqual (8.25, f.Size, "#6");
73                         Assert.AreEqual (8.25, f.SizeInPoints, "#7");
74                         Assert.IsFalse (f.Strikeout, "#8");
75                         Assert.IsFalse (f.Underline, "#9");
76                         Assert.AreEqual (GraphicsUnit.Point, f.Unit, "#10");
77                 }
78
79                 [Test]
80                 [Category ("NotWorking")] // on Unix mapping is done to Bitstream Vera Sans
81                 public void DefaultFont_Names ()
82                 {
83                         Font f = SystemFonts.DefaultFont;
84                         Assert.AreEqual ("Microsoft Sans Serif", f.FontFamily.Name, "#1");
85                         Assert.AreEqual ("Microsoft Sans Serif", f.Name, "#2");
86                 }
87
88                 [Test]
89                 public void SystemFontName ()
90                 {
91                         Assert.AreEqual ("CaptionFont", SystemFonts.CaptionFont.SystemFontName, "CaptionFont");
92                         Assert.AreEqual ("DefaultFont", SystemFonts.DefaultFont.SystemFontName, "DefaultFont");
93                         Assert.AreEqual ("DialogFont", SystemFonts.DialogFont.SystemFontName, "DialogFont");
94                         Assert.AreEqual ("IconTitleFont", SystemFonts.IconTitleFont.SystemFontName, "IconTitleFont");
95                         Assert.AreEqual ("MenuFont", SystemFonts.MenuFont.SystemFontName, "MenuFont");
96                         Assert.AreEqual ("MessageBoxFont", SystemFonts.MessageBoxFont.SystemFontName, "MessageBoxFont");
97                         Assert.AreEqual ("SmallCaptionFont", SystemFonts.SmallCaptionFont.SystemFontName, "SmallCaptionFont");
98                         Assert.AreEqual ("StatusFont", SystemFonts.StatusFont.SystemFontName, "StatusFont");
99                 }
100
101                 [Test]
102                 public void GetFontByName ()
103                 {
104                         Assert.AreEqual ("CaptionFont", SystemFonts.GetFontByName ("CaptionFont").SystemFontName, "CaptionFont");
105                         Assert.AreEqual ("DefaultFont", SystemFonts.GetFontByName ("DefaultFont").SystemFontName, "DefaultFont");
106                         Assert.AreEqual ("DialogFont", SystemFonts.GetFontByName ("DialogFont").SystemFontName, "DialogFont");
107                         Assert.AreEqual ("IconTitleFont", SystemFonts.GetFontByName ("IconTitleFont").SystemFontName, "IconTitleFont");
108                         Assert.AreEqual ("MenuFont", SystemFonts.GetFontByName ("MenuFont").SystemFontName, "MenuFont");
109                         Assert.AreEqual ("MessageBoxFont", SystemFonts.GetFontByName ("MessageBoxFont").SystemFontName, "MessageBoxFont");
110                         Assert.AreEqual ("SmallCaptionFont", SystemFonts.GetFontByName ("SmallCaptionFont").SystemFontName, "SmallCaptionFont");
111                         Assert.AreEqual ("StatusFont", SystemFonts.GetFontByName ("StatusFont").SystemFontName, "StatusFont");
112                 }
113
114                 [Test]
115                 public void GetFontByName_Invalid ()
116                 {
117                         Assert.IsNull (SystemFonts.GetFontByName (null), "null");
118                         Assert.IsNull (SystemFonts.GetFontByName (String.Empty), "Empty");
119                         Assert.IsNull (SystemFonts.GetFontByName ("defaultfont"), "lowercase");
120                         Assert.IsNull (SystemFonts.GetFontByName ("DEFAULTFONT"), "UPPERCASE");
121                 }
122
123                 [Test]
124                 public void Same ()
125                 {
126                         Font f1 = SystemFonts.CaptionFont;
127                         Font f2 = SystemFonts.CaptionFont;
128                         Assert.IsFalse (Object.ReferenceEquals (f1, f2), "property-property");
129                         f2 = SystemFonts.GetFontByName ("CaptionFont");
130                         Assert.IsFalse (Object.ReferenceEquals (f1, f2), "property-GetFontByName");
131                 }
132
133                 [Test]
134                 [ExpectedException (typeof (ArgumentException))]
135                 public void Dispose_Instance ()
136                 {
137                         Font f1 = SystemFonts.CaptionFont;
138                         float height = f1.GetHeight (72f);
139                         f1.Dispose ();
140                         f1.GetHeight (72f);
141                 }
142
143                 [Test]
144                 public void Dispose_Property ()
145                 {
146                         float height = SystemFonts.CaptionFont.GetHeight (72f);
147                         SystemFonts.CaptionFont.Dispose ();
148                         Assert.AreEqual (height, SystemFonts.CaptionFont.GetHeight (72f), "height");
149                 }
150         }
151 }
152
153 #endif