New test.
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / TableHeaderCellTest.cs
1 //
2 // TableHeaderCellTest.cs
3 //      - Unit tests for System.Web.UI.WebControls.TableHeaderCell
4 //
5 // Author:
6 //      Sebastien Pouliot  <sebastien@ximian.com>
7 //
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using System;
31 using System.IO;
32 using System.Web;
33 using System.Web.UI;
34 using System.Web.UI.WebControls;
35
36 using NUnit.Framework;
37
38 namespace MonoTests.System.Web.UI.WebControls {
39
40         public class TestTableHeaderCell : TableHeaderCell {
41
42                 public string Tag {
43                         get { return base.TagName; }
44                 }
45
46                 public StateBag StateBag {
47                         get { return base.ViewState; }
48                 }
49
50                 public string Render ()
51                 {
52                         HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
53                         base.Render (writer);
54                         return writer.InnerWriter.ToString ();
55                 }
56         }
57
58         [TestFixture]
59         public class TableHeaderCellTest {
60
61                 [Test]
62                 public void DefaultProperties ()
63                 {
64                         TestTableHeaderCell th = new TestTableHeaderCell ();
65                         Assert.AreEqual (0, th.Attributes.Count, "Attributes.Count");
66                         Assert.AreEqual (0, th.StateBag.Count, "ViewState.Count");
67 #if NET_2_0
68                         Assert.AreEqual (String.Empty, th.AbbreviatedText, "AbbreviatedText");
69                         Assert.AreEqual (0, th.CategoryText.Length, "CategoryText");
70                         Assert.AreEqual (TableHeaderScope.NotSet, th.Scope, "Scope");
71 #endif
72                         Assert.AreEqual ("th", th.Tag, "TagName");
73                         Assert.AreEqual (0, th.Attributes.Count, "Attributes.Count-2");
74                         Assert.AreEqual (0, th.StateBag.Count, "ViewState.Count-2");
75                 }
76
77                 [Test]
78                 public void NullProperties ()
79                 {
80                         TestTableHeaderCell th = new TestTableHeaderCell ();
81 #if NET_2_0
82                         th.AbbreviatedText = null;
83                         Assert.AreEqual (String.Empty, th.AbbreviatedText, "AbbreviatedText");
84
85                         th.CategoryText = new string[0];
86                         Assert.AreEqual (0, th.CategoryText.Length, "CategoryText");
87                         Assert.AreEqual (1, th.StateBag.Count, "ViewState.Count-1");
88
89                         th.Scope = TableHeaderScope.NotSet;
90                         Assert.AreEqual (TableHeaderScope.NotSet, th.Scope, "Scope");
91                         Assert.AreEqual (2, th.StateBag.Count, "ViewState.Count-2");
92 #else
93                         Assert.AreEqual (0, th.StateBag.Count, "ViewState.Count-1");
94 #endif
95                         Assert.AreEqual (0, th.Attributes.Count, "Attributes.Count");
96                 }
97
98                 [Test]
99                 public void CleanProperties ()
100                 {
101                         TestTableHeaderCell th = new TestTableHeaderCell ();
102 #if NET_2_0
103                         th.AbbreviatedText = "header";
104                         Assert.AreEqual ("header", th.AbbreviatedText, "AbbreviatedText");
105                         th.AbbreviatedText = null;
106                         Assert.AreEqual (String.Empty, th.AbbreviatedText, "-AbbreviatedText");
107                         Assert.AreEqual (0, th.StateBag.Count, "ViewState.Count-1");
108
109                         th.CategoryText = new string[1] { "mono" };
110                         Assert.AreEqual (1, th.CategoryText.Length, "CategoryText");
111                         th.CategoryText = new string[0];
112                         Assert.AreEqual (0, th.CategoryText.Length, "-CategoryText");
113                         Assert.AreEqual (1, th.StateBag.Count, "ViewState.Count-1");
114
115                         th.Scope = TableHeaderScope.Row;
116                         Assert.AreEqual (TableHeaderScope.Row, th.Scope, "Scope");
117                         th.Scope = TableHeaderScope.NotSet;
118                         Assert.AreEqual (TableHeaderScope.NotSet, th.Scope, "-Scope");
119                         Assert.AreEqual (2, th.StateBag.Count, "ViewState.Count-2");
120 #else
121                         Assert.AreEqual (0, th.StateBag.Count, "ViewState.Count-1");
122 #endif
123                         Assert.AreEqual (0, th.Attributes.Count, "Attributes.Count");
124                 }
125
126                 private string AdjustLineEndings (string s)
127                 {
128                         return s.Replace ("\r\n", Environment.NewLine);
129                 }
130
131                 [Test]
132                 public void Render ()
133                 {
134                         TestTableHeaderCell th = new TestTableHeaderCell ();
135                         string s = th.Render ();
136                         Assert.AreEqual (AdjustLineEndings ("<th></th>"), s, "empty/default");
137 #if NET_2_0
138                         th.AbbreviatedText = "header";
139                         s = th.Render ();
140                         Assert.AreEqual (AdjustLineEndings ("<th abbr=\"header\"></th>"), s, "AbbreviatedText");
141                         th.AbbreviatedText = null;
142
143                         th.CategoryText = new string[1] { "mono" };
144                         s = th.Render ();
145                         Assert.AreEqual (AdjustLineEndings ("<th axis=\"mono\"></th>"), s, "CategoryText-1");
146                         th.CategoryText = new string[2] { "mono", "http://www.mono-project.com" };
147                         s = th.Render ();
148                         Assert.AreEqual (AdjustLineEndings ("<th axis=\"mono,http://www.mono-project.com\"></th>"), s, "CategoryText-2");
149                         th.CategoryText = new string[3] { "mono", "http://www.mono-project.com", "," };
150                         s = th.Render ();
151                         Assert.AreEqual (AdjustLineEndings ("<th axis=\"mono,http://www.mono-project.com,,\"></th>"), s, "CategoryText-2");
152                         th.CategoryText = new string[0];
153                         s = th.Render ();
154                         Assert.AreEqual (AdjustLineEndings ("<th></th>"), s, "CategoryText-2");
155
156                         th.Scope = TableHeaderScope.Row;
157                         s = th.Render ();
158                         Assert.AreEqual (AdjustLineEndings ("<th scope=\"row\"></th>"), s, "Row");
159                         th.Scope = TableHeaderScope.Column;
160                         s = th.Render ();
161                         Assert.AreEqual (AdjustLineEndings ("<th scope=\"column\"></th>"), s, "Column");
162                         th.Scope = TableHeaderScope.NotSet;
163                         s = th.Render ();
164                         Assert.AreEqual (AdjustLineEndings ("<th></th>"), s, "NotSet");
165 #endif
166                         th.Text = "test";
167                         s = th.Render ();
168                         Assert.AreEqual (AdjustLineEndings ("<th>test</th>"), s, "Text");
169                 }
170         }
171 }