2 // Tests for System.Web.UI.WebControls.Style.cs
5 // Peter Dennis Bartok (pbartok@novell.com)
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using NUnit.Framework;
33 using System.Collections;
36 using System.Globalization;
39 using System.Web.UI.WebControls;
41 namespace MonoTests.System.Web.UI.WebControls
44 public class FontNamesConverterTest {
48 FontNamesConverter conv;
52 conv = new FontNamesConverter();
53 name_array = new string[] { "Arial", "Courier" };
54 name_list = "Arial,Courier";
56 Assert.AreEqual (true, conv.CanConvertFrom(null, typeof(string)), "B1");
57 Assert.AreEqual (true, conv.CanConvertTo(null, typeof(string)), "B2");
58 Assert.AreEqual (false, conv.CanConvertFrom(null, typeof(string[])), "B3");
59 Assert.AreEqual (false, conv.CanConvertTo(null, typeof(string[])), "B4");
61 Assert.AreEqual (false, conv.CanConvertFrom(null, typeof(int)), "B5");
62 Assert.AreEqual (false, conv.CanConvertTo(null, typeof(int)), "B6");
64 // ASP.NET in a Nutshell 2nd Edition (O'Reilly), pg855:
65 // FontNamesConverter converts between a font name array and a string that contains a
66 // list of font names separated by comma.
67 // Why does the CanConvertFrom() and CanConvertTo() then indicate that it cannot handle string[]???
68 // It obviously works:
69 Assert.AreEqual (name_array, conv.ConvertFrom(null, null, name_list), "B7");
70 Assert.AreEqual (name_list, conv.ConvertTo(null, null, name_array, typeof(string)), "B8");
73 Assert.AreEqual ("", conv.ConvertTo(null, null, new string[0], typeof(string)), "B9");
74 Assert.AreEqual ("", conv.ConvertTo(null, null, null, typeof(string)), "B10");
75 Assert.AreEqual (new string[0], conv.ConvertFrom(null, null, ""), "B11");
78 Assert.AreEqual (name_list, conv.ConvertTo(null, null, conv.ConvertFrom(null, null, name_list), typeof(string)), "B12");
80 // Whitespace (leading and trailing)
81 Assert.AreEqual (name_array, conv.ConvertFrom(null, null, "Arial, Courier"), "B13");
82 Assert.AreEqual (new string[] { "Arial\nCourier" }, conv.ConvertFrom(null, null, "Arial\nCourier\n"), "B14");
83 Assert.AreEqual (name_array, conv.ConvertFrom(null, null, "Arial,\nCourier\r\n"), "B15");
84 Assert.AreEqual (new string[] { "Arial", "Courier" }, conv.ConvertFrom(null, null, "Arial\n,\nCourier\n"), "B16");
86 // This is stupid behaviour and prevents roundtripping; why trim in ConvertFrom and not in ConvertTo?
87 Assert.AreEqual ("Arial\n,Courier\n", conv.ConvertTo(null, null, new string[] { "Arial\n", "Courier\n" }, typeof(string)), "B17");
88 Assert.AreEqual ("Arial,\n,Courier\n", conv.ConvertTo(null, null, new string[] { "Arial,\n", "Courier\n" }, typeof(string)), "B18");