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 [ExpectedException (typeof (ArgumentException))]
63 public void FontFamily_String_Null ()
65 new FontFamily (null);
69 [ExpectedException (typeof (ArgumentException))]
70 [Category ("NotWorking")] // libgdiplus/fontconfig always return something
71 public void FontFamily_String_Empty ()
73 new FontFamily (String.Empty);
76 private void CheckMono (FontFamily ff)
78 Assert.IsTrue (ff.Equals (FontFamily.GenericMonospace), "GenericMonospace");
80 // note: Mono has this behaviour on both 1.1 and 2.0 profiles
81 Assert.AreEqual (ff.Name.GetHashCode (), ff.GetHashCode (), "GetHashCode");
86 public void FontFamily_String ()
88 FontFamily ff = new FontFamily (name);
90 FontStyle style = FontStyle.Bold;
91 Assert.AreEqual (ff.Name, ff.GetName (0), "GetName");
92 Assert.IsTrue ((ff.GetCellAscent (style) > 0), "GetCellAscent");
93 Assert.IsTrue ((ff.GetCellDescent (style) > 0), "GetCellDescent");
94 Assert.IsTrue ((ff.GetEmHeight (style) > 0), "GetEmHeight");
95 Assert.IsTrue ((ff.GetLineSpacing (style) > 0), "GetLineSpacing");
96 Assert.IsTrue (ff.IsStyleAvailable (style), "IsStyleAvailable");
100 public void FontFamily_String_FontCollection_Null ()
102 FontFamily ff = new FontFamily (name, null);
107 public void FontFamily_String_InstalledFontCollection ()
109 FontFamily ff = new FontFamily (name, new InstalledFontCollection ());
114 [ExpectedException (typeof (ArgumentException))]
115 public void FontFamily_String_PrivateFontCollection ()
117 new FontFamily (name, new PrivateFontCollection ());
121 public void FontFamily_Monospace ()
123 FontFamily ff = new FontFamily (GenericFontFamilies.Monospace);
128 public void FontFamily_SansSerif ()
130 FontFamily ff = new FontFamily (GenericFontFamilies.SansSerif);
131 Assert.IsTrue (ff.Equals (FontFamily.GenericSansSerif), "GenericSansSerif");
133 // note: Mono has this behaviour on both 1.1 and 2.0 profiles
134 Assert.AreEqual (ff.Name.GetHashCode (), ff.GetHashCode (), "GetHashCode");
139 public void FontFamily_Serif ()
141 FontFamily ff = new FontFamily (GenericFontFamilies.Serif);
142 Assert.IsTrue (ff.Equals (FontFamily.GenericSerif), "GenericSerif");
144 // note: Mono has this behaviour on both 1.1 and 2.0 profiles
145 Assert.AreEqual (ff.Name.GetHashCode (), ff.GetHashCode (), "GetHashCode");
150 public void FontFamily_Invalid ()
152 FontFamily ff = new FontFamily ((GenericFontFamilies)Int32.MinValue);
153 // default to Monospace
154 Assert.IsTrue (ff.Equals (FontFamily.GenericMonospace), "GenericMonospace");
159 public void GenericMonospace ()
161 FontFamily ff = FontFamily.GenericMonospace;
162 string ts = ff.ToString ();
163 Assert.AreEqual ('[', ts[0], "[");
164 Assert.IsTrue ((ts.IndexOf (name) >= 0), "ToString");
165 Assert.AreEqual (']', ts[ts.Length - 1], "]");
169 public void GenericSansSerif ()
171 FontFamily ff = FontFamily.GenericSansSerif;
172 string name = ff.Name;
174 Assert.AreEqual (name, FontFamily.GenericSansSerif.Name, "Name");
178 public void GenericSerif ()
180 FontFamily ff = FontFamily.GenericSerif;
181 string name = ff.Name;
183 Assert.AreEqual (name, FontFamily.GenericSerif.Name, "Name");
187 [ExpectedException (typeof (ArgumentNullException))]
188 public void GetFamilies_Null ()
190 FontFamily.GetFamilies (null);
194 public void GetFamilies ()
196 FontFamily[] ffc = FontFamily.GetFamilies (graphic);
197 Assert.AreEqual (ffc.Length, FontFamily.Families.Length, "Length");
201 public void Dispose_Double ()
203 FontFamily ff = FontFamily.GenericSerif;
209 [ExpectedException (typeof (ArgumentException))]
210 public void Dispose_UseAfter ()
212 FontFamily ff = FontFamily.GenericMonospace;
214 Assert.AreEqual (name, ff.Name, "Name");