* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.HtmlControls / HtmlTableCellTest.cs
1 //
2 // HtmlTableCellTest.cs
3 //      - Unit tests for System.Web.UI.HtmlControls.HtmlTableCell
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.UI;
33 using System.Web.UI.HtmlControls;
34
35 using NUnit.Framework;
36
37 namespace MonoTests.System.Web.UI.HtmlControls {
38
39         public class TestHtmlTableCell : HtmlTableCell {
40
41                 public string Render ()
42                 {
43                         HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
44                         base.Render (writer);
45                         return writer.InnerWriter.ToString ();
46                 }
47         }
48
49         [TestFixture]
50         public class HtmlTableCellTest {
51
52                 [Test]
53                 public void DefaultProperties ()
54                 {
55                         HtmlTableCell c = new HtmlTableCell ();
56                         Assert.AreEqual (0, c.Attributes.Count, "Attributes.Count");
57
58                         Assert.AreEqual (String.Empty, c.Align, "Align");
59                         Assert.AreEqual (String.Empty, c.BgColor, "BgColor");
60                         Assert.AreEqual (String.Empty, c.BorderColor, "BorderColor");
61                         Assert.AreEqual (-1, c.ColSpan, "ColSpan");
62                         Assert.AreEqual (String.Empty, c.Height, "Height");
63                         Assert.IsFalse (c.NoWrap, "NoWrap");
64                         Assert.AreEqual (-1, c.RowSpan, "RowSpan");
65                         Assert.AreEqual (String.Empty, c.VAlign, "VAlign");
66                         Assert.AreEqual (String.Empty, c.Width, "Width");
67
68                         Assert.AreEqual ("td", c.TagName, "TagName");
69                 }
70
71                 [Test]
72                 public void NullProperties ()
73                 {
74                         HtmlTableCell c = new HtmlTableCell ();
75                         c.Align = null;
76                         Assert.AreEqual (String.Empty, c.Align, "Align");
77                         c.BgColor = null;
78                         Assert.AreEqual (String.Empty, c.BgColor, "BgColor");
79                         c.BorderColor = null;
80                         Assert.AreEqual (String.Empty, c.BorderColor, "BorderColor");
81                         c.Height = null;
82                         Assert.AreEqual (String.Empty, c.Height, "Height");
83                         c.VAlign = null;
84                         Assert.AreEqual (String.Empty, c.VAlign, "VAlign");
85                         c.Width = null;
86                         Assert.AreEqual (String.Empty, c.Width, "Width");
87
88                         Assert.AreEqual (0, c.Attributes.Count, "Attributes.Count");
89                 }
90
91                 [Test]
92                 public void EmptyProperties ()
93                 {
94                         HtmlTableCell c = new HtmlTableCell ();
95                         c.ColSpan = -1;
96                         Assert.AreEqual (-1, c.ColSpan, "ColSpan");
97                         c.RowSpan = -1;
98                         Assert.AreEqual (-1, c.RowSpan, "RowSpan");
99                         c.NoWrap = false;
100                         Assert.IsFalse (c.NoWrap, "NoWrap");
101
102                         Assert.AreEqual (0, c.Attributes.Count, "Attributes.Count");
103                 }
104
105                 [Test]
106                 public void CleanProperties ()
107                 {
108                         HtmlTableCell c = new HtmlTableCell ();
109                         c.Align = "center";
110                         Assert.AreEqual ("center", c.Align, "Align");
111                         c.ColSpan = 1;
112                         Assert.AreEqual (1, c.ColSpan, "Align");
113                         c.NoWrap = true;
114                         Assert.IsTrue (c.NoWrap, "NoWrap");
115                         Assert.AreEqual (3, c.Attributes.Count, "3");
116
117                         c.Align = null;
118                         Assert.AreEqual (String.Empty, c.Align, "-Align");
119                         c.ColSpan = -1;
120                         Assert.AreEqual (-1, c.ColSpan, "-ColSpan");
121                         c.NoWrap = false;
122                         Assert.IsFalse (c.NoWrap, "-NoWrap");
123                         Assert.AreEqual (0, c.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                         TestHtmlTableCell c = new TestHtmlTableCell ();
135                         c.Align = "*1*";
136                         c.BgColor = "*2*";
137                         c.BorderColor = "*3*";
138                         c.ColSpan = 4;
139                         c.Width = "*5*";
140
141                         Assert.AreEqual (AdjustLineEndings ("<td align=\"*1*\" bgcolor=\"*2*\" bordercolor=\"*3*\" colspan=\"4\" width=\"*5*\"></td>\r\n"), c.Render ());
142                 }
143         }
144 }