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);
52 using (FontFamily ff = new FontFamily (GenericFontFamilies.Monospace)) {
56 catch (ArgumentException) {
57 Assert.Ignore ("No font family could be found.");
62 public void FontFamily_String_Null ()
64 Assert.Throws<ArgumentException> (() => new FontFamily (null));
68 [Category ("NotWorking")] // libgdiplus/fontconfig always return something
69 public void FontFamily_String_Empty ()
71 Assert.Throws<ArgumentException> (() => new FontFamily (String.Empty));
74 private void CheckMono (FontFamily ff)
76 Assert.IsTrue (ff.Equals (FontFamily.GenericMonospace), "GenericMonospace");
77 // note: Mono has this behaviour on both 1.1 and 2.0 profiles
78 Assert.AreEqual (ff.Name.GetHashCode (), ff.GetHashCode (), "GetHashCode");
82 public void FontFamily_String ()
84 HostIgnoreList.CheckTest ("MonoTests.System.Drawing.FontFamilyTest.FontFamily_String");
85 FontFamily ff = new FontFamily (name);
87 FontStyle style = FontStyle.Bold;
88 Assert.AreEqual (ff.Name, ff.GetName (0), "GetName");
89 Assert.IsTrue ((ff.GetCellAscent (style) > 0), "GetCellAscent");
90 Assert.IsTrue ((ff.GetCellDescent (style) > 0), "GetCellDescent");
91 Assert.IsTrue ((ff.GetEmHeight (style) > 0), "GetEmHeight");
92 Assert.IsTrue ((ff.GetLineSpacing (style) > 0), "GetLineSpacing");
93 Assert.IsTrue (ff.IsStyleAvailable (style), "IsStyleAvailable");
97 public void FontFamily_String_FontCollection_Null ()
99 FontFamily ff = new FontFamily (name, null);
104 public void FontFamily_String_InstalledFontCollection ()
106 FontFamily ff = new FontFamily (name, new InstalledFontCollection ());
111 public void FontFamily_String_PrivateFontCollection ()
113 Assert.Throws<ArgumentException> (() => new FontFamily (name, new PrivateFontCollection ()));
117 public void FontFamily_Monospace ()
119 FontFamily ff = new FontFamily (GenericFontFamilies.Monospace);
124 public void FontFamily_SansSerif ()
126 FontFamily ff = new FontFamily (GenericFontFamilies.SansSerif);
127 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");
133 public void FontFamily_Serif ()
135 FontFamily ff = new FontFamily (GenericFontFamilies.Serif);
136 Assert.IsTrue (ff.Equals (FontFamily.GenericSerif), "GenericSerif");
137 // note: Mono has this behaviour on both 1.1 and 2.0 profiles
138 Assert.AreEqual (ff.Name.GetHashCode (), ff.GetHashCode (), "GetHashCode");
142 public void FontFamily_Invalid ()
144 FontFamily ff = new FontFamily ((GenericFontFamilies)Int32.MinValue);
145 // default to Monospace
146 Assert.IsTrue (ff.Equals (FontFamily.GenericMonospace), "GenericMonospace");
151 public void GenericMonospace ()
153 FontFamily ff = FontFamily.GenericMonospace;
154 string ts = ff.ToString ();
155 Assert.AreEqual ('[', ts[0], "[");
156 Assert.IsTrue ((ts.IndexOf (name) >= 0), "ToString");
157 Assert.AreEqual (']', ts[ts.Length - 1], "]");
161 public void GenericSansSerif ()
163 FontFamily ff = FontFamily.GenericSansSerif;
164 string name = ff.Name;
166 Assert.AreEqual (name, FontFamily.GenericSansSerif.Name, "Name");
170 public void GenericSerif ()
172 FontFamily ff = FontFamily.GenericSerif;
173 string name = ff.Name;
175 Assert.AreEqual (name, FontFamily.GenericSerif.Name, "Name");
179 public void GetFamilies_Null ()
181 Assert.Throws<ArgumentNullException> (() => FontFamily.GetFamilies (null));
185 public void GetFamilies ()
187 FontFamily[] ffc = FontFamily.GetFamilies (graphic);
188 Assert.AreEqual (ffc.Length, FontFamily.Families.Length, "Length");
192 public void Dispose_Double ()
194 FontFamily ff = FontFamily.GenericSerif;
200 public void Dispose_UseAfter ()
202 FontFamily ff = FontFamily.GenericMonospace;
204 Assert.Throws<ArgumentException> (() => { var x = ff.Name; });