svn path=/branches/mono-1-1-9/mcs/; revision=51216
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / FontNamesConverterTest.cs
1 //
2 // Tests for System.Web.UI.WebControls.Style.cs 
3 //
4 // Author:
5 //      Peter Dennis Bartok (pbartok@novell.com)
6 //
7
8 //
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 //
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:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
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.
29 //
30
31 using NUnit.Framework;
32 using System;
33 using System.Collections;
34 using System.Drawing;
35 using System.IO;
36 using System.Globalization;
37 using System.Web;
38 using System.Web.UI;
39 using System.Web.UI.WebControls;
40
41 namespace MonoTests.System.Web.UI.WebControls
42 {
43         [TestFixture]   
44         public class FontNamesConverterTest {
45                 [Test]
46                 public void Basic ()
47                 {
48                         FontNamesConverter      conv;
49                         string[]                name_array;
50                         string                  name_list;
51
52                         conv = new FontNamesConverter();
53                         name_array = new string[] { "Arial", "Courier" };
54                         name_list = "Arial,Courier";
55
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");
60
61                         Assert.AreEqual (false, conv.CanConvertFrom(null, typeof(int)), "B5");
62                         Assert.AreEqual (false, conv.CanConvertTo(null, typeof(int)), "B6");
63
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");
71
72                         // Special cases
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");
76
77                         // Roundtrip
78                         Assert.AreEqual (name_list, conv.ConvertTo(null, null, conv.ConvertFrom(null, null, name_list), typeof(string)), "B12");
79
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");
85
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");
89                 }
90         }
91 }