2 // System.Drawing.FontFamily unit tests
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Drawing.Drawing2D;
32 using System.Drawing.Text;
33 using System.Security.Permissions;
34 using NUnit.Framework;
36 namespace MonoTests.System.Drawing {
39 [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
40 public class FontFamilyTest {
42 private Bitmap bitmap;
43 private Graphics graphic;
47 public void FixtureSetUp ()
49 bitmap = new Bitmap (10, 10);
50 graphic = Graphics.FromImage (bitmap);
51 using (FontFamily ff = new FontFamily (GenericFontFamilies.Monospace)) {
57 [ExpectedException (typeof (ArgumentException))]
58 public void FontFamily_String_Null ()
60 new FontFamily (null);
64 [ExpectedException (typeof (ArgumentException))]
65 [Category ("NotWorking")] // libgdiplus/fontconfig always return something
66 public void FontFamily_String_Empty ()
68 new FontFamily (String.Empty);
71 private void CheckMono (FontFamily ff)
73 Assert.IsTrue (ff.Equals (FontFamily.GenericMonospace), "GenericMonospace");
75 // note: Mono has this behaviour on both 1.1 and 2.0 profiles
76 Assert.AreEqual (ff.Name.GetHashCode (), ff.GetHashCode (), "GetHashCode");
81 public void FontFamily_String ()
83 FontFamily ff = new FontFamily (name);
85 FontStyle style = FontStyle.Bold;
86 Assert.AreEqual (ff.Name, ff.GetName (0), "GetName");
87 Assert.IsTrue ((ff.GetCellAscent (style) > 0), "GetCellAscent");
88 Assert.IsTrue ((ff.GetCellDescent (style) > 0), "GetCellDescent");
89 Assert.IsTrue ((ff.GetEmHeight (style) > 0), "GetEmHeight");
90 Assert.IsTrue ((ff.GetLineSpacing (style) > 0), "GetLineSpacing");
91 Assert.IsTrue (ff.IsStyleAvailable (style), "IsStyleAvailable");
95 public void FontFamily_String_FontCollection_Null ()
97 FontFamily ff = new FontFamily (name, null);
102 public void FontFamily_String_InstalledFontCollection ()
104 FontFamily ff = new FontFamily (name, new InstalledFontCollection ());
109 [ExpectedException (typeof (ArgumentException))]
110 public void FontFamily_String_PrivateFontCollection ()
112 new FontFamily (name, new PrivateFontCollection ());
116 public void FontFamily_Monospace ()
118 FontFamily ff = new FontFamily (GenericFontFamilies.Monospace);
123 public void FontFamily_SansSerif ()
125 FontFamily ff = new FontFamily (GenericFontFamilies.SansSerif);
126 Assert.IsTrue (ff.Equals (FontFamily.GenericSansSerif), "GenericSansSerif");
128 // note: Mono has this behaviour on both 1.1 and 2.0 profiles
129 Assert.AreEqual (ff.Name.GetHashCode (), ff.GetHashCode (), "GetHashCode");
134 public void FontFamily_Serif ()
136 FontFamily ff = new FontFamily (GenericFontFamilies.Serif);
137 Assert.IsTrue (ff.Equals (FontFamily.GenericSerif), "GenericSerif");
139 // note: Mono has this behaviour on both 1.1 and 2.0 profiles
140 Assert.AreEqual (ff.Name.GetHashCode (), ff.GetHashCode (), "GetHashCode");
145 public void FontFamily_Invalid ()
147 FontFamily ff = new FontFamily ((GenericFontFamilies)Int32.MinValue);
148 // default to Monospace
149 Assert.IsTrue (ff.Equals (FontFamily.GenericMonospace), "GenericMonospace");
154 public void GenericMonospace ()
156 FontFamily ff = FontFamily.GenericMonospace;
157 string ts = ff.ToString ();
158 Assert.AreEqual ('[', ts[0], "[");
159 Assert.IsTrue ((ts.IndexOf (name) >= 0), "ToString");
160 Assert.AreEqual (']', ts[ts.Length - 1], "]");
164 public void GenericSansSerif ()
166 FontFamily ff = FontFamily.GenericSansSerif;
167 string name = ff.Name;
169 Assert.AreEqual (name, FontFamily.GenericSansSerif.Name, "Name");
173 public void GenericSerif ()
175 FontFamily ff = FontFamily.GenericSerif;
176 string name = ff.Name;
178 Assert.AreEqual (name, FontFamily.GenericSerif.Name, "Name");
182 [ExpectedException (typeof (ArgumentNullException))]
183 public void GetFamilies_Null ()
185 FontFamily.GetFamilies (null);
189 public void GetFamilies ()
191 FontFamily[] ffc = FontFamily.GetFamilies (graphic);
192 Assert.AreEqual (ffc.Length, FontFamily.Families.Length, "Length");
196 public void Dispose_Double ()
198 FontFamily ff = FontFamily.GenericSerif;
204 [ExpectedException (typeof (ArgumentException))]
205 public void Dispose_UseAfter ()
207 FontFamily ff = FontFamily.GenericMonospace;
209 Assert.AreEqual (name, ff.Name, "Name");