3 // - Unit tests for System.Web.UI.HtmlControls.HtmlTable
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
33 using System.Web.UI.HtmlControls;
35 using NUnit.Framework;
37 namespace MonoTests.System.Web.UI.HtmlControls {
39 public class TestHtmlTable : HtmlTable {
41 public string Render ()
43 HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
45 return writer.InnerWriter.ToString ();
48 public ControlCollection GetCollection ()
50 return base.CreateControlCollection ();
54 public class InheritedHtmlTableRow : HtmlTableRow {
58 public class HtmlTableTest {
61 public void DefaultProperties ()
63 HtmlTable t = new HtmlTable ();
64 Assert.AreEqual (0, t.Attributes.Count, "Attributes.Count");
66 Assert.AreEqual (String.Empty, t.Align, "Align");
67 Assert.AreEqual (String.Empty, t.BgColor, "BgColor");
68 Assert.AreEqual (-1, t.Border, "Border");
69 Assert.AreEqual (String.Empty, t.BorderColor, "BorderColor");
70 Assert.AreEqual (-1, t.CellPadding, "CellPadding");
71 Assert.AreEqual (-1, t.CellSpacing, "CellSpacing");
72 Assert.AreEqual (String.Empty, t.Height, "Height");
73 Assert.AreEqual (0, t.Rows.Count, "Rows");
74 Assert.AreEqual (String.Empty, t.Width, "Width");
76 Assert.AreEqual ("table", t.TagName, "TagName");
80 public void NullProperties ()
82 HtmlTable t = new HtmlTable ();
84 Assert.AreEqual (String.Empty, t.Align, "Align");
86 Assert.AreEqual (String.Empty, t.BgColor, "BgColor");
88 Assert.AreEqual (String.Empty, t.BorderColor, "BorderColor");
90 Assert.AreEqual (String.Empty, t.Height, "Height");
92 Assert.AreEqual (String.Empty, t.Width, "Width");
94 Assert.AreEqual (0, t.Attributes.Count, "Attributes.Count");
98 public void EmptyProperties ()
100 HtmlTable t = new HtmlTable ();
102 Assert.AreEqual (-1, t.Border, "Border");
104 Assert.AreEqual (-1, t.CellPadding, "CellPadding");
106 Assert.AreEqual (-1, t.CellSpacing, "CellSpacing");
108 Assert.AreEqual (0, t.Attributes.Count, "Attributes.Count");
112 public void CleanProperties ()
114 HtmlTable t = new HtmlTable ();
116 Assert.AreEqual ("center", t.Align, "Align");
118 Assert.AreEqual (1, t.Border, "Border");
119 Assert.AreEqual (2, t.Attributes.Count, "2");
122 Assert.AreEqual (-1, t.Border, "-Border");
124 Assert.AreEqual (String.Empty, t.Align, "-Align");
125 Assert.AreEqual (0, t.Attributes.Count, "0");
129 public void MaxInt32 ()
131 HtmlTable t = new HtmlTable ();
132 t.Border = Int32.MaxValue;
133 Assert.AreEqual (Int32.MaxValue, t.Border, "Border");
134 t.CellPadding = Int32.MaxValue;
135 Assert.AreEqual (Int32.MaxValue, t.CellPadding, "CellPadding");
136 t.CellSpacing = Int32.MaxValue;
137 Assert.AreEqual (Int32.MaxValue, t.CellSpacing, "CellSpacing");
139 Assert.AreEqual (3, t.Attributes.Count, "Attributes.Count");
143 public void MinInt32 ()
145 HtmlTable t = new HtmlTable ();
146 t.Border = Int32.MinValue;
147 Assert.AreEqual (Int32.MinValue, t.Border, "Border");
148 t.CellPadding = Int32.MinValue;
149 Assert.AreEqual (Int32.MinValue, t.CellPadding, "CellPadding");
150 t.CellSpacing = Int32.MinValue;
151 Assert.AreEqual (Int32.MinValue, t.CellSpacing, "CellSpacing");
153 Assert.AreEqual (3, t.Attributes.Count, "Attributes.Count");
157 [ExpectedException (typeof (FormatException))]
158 public void WrongTypeString ()
160 HtmlTable t = new HtmlTable ();
161 t.Attributes.Add ("Border", "yes");
162 Assert.AreEqual (-1, t.Border, "Border");
166 public void WrongTypeInt ()
168 HtmlTable t = new HtmlTable ();
170 Assert.AreEqual ("42", t.Attributes ["border"], "Border");
174 [ExpectedException (typeof (NotSupportedException))]
175 public void InnerHtml_Get ()
177 HtmlTable t = new HtmlTable ();
178 Assert.IsNotNull (t.InnerHtml);
182 [ExpectedException (typeof (NotSupportedException))]
183 public void InnerHtml_Set ()
185 HtmlTable t = new HtmlTable ();
186 t.InnerHtml = String.Empty;
190 [ExpectedException (typeof (NotSupportedException))]
191 public void InnerText_Get ()
193 HtmlTable t = new HtmlTable ();
194 Assert.IsNotNull (t.InnerText);
198 [ExpectedException (typeof (NotSupportedException))]
199 public void InnerText_Set ()
201 HtmlTable t = new HtmlTable ();
202 t.InnerText = String.Empty;
205 private string RemoveWS (string s)
207 s = s.Replace ("\t", "");
208 s = s.Replace ("\r", "");
209 return s.Replace ("\n", "");
213 public void Render_Table_Simple ()
215 TestHtmlTable t = new TestHtmlTable ();
216 Assert.AreEqual (RemoveWS ("<table>\r\n</table>\r\n"), RemoveWS (t.Render ()));
220 public void Render_Table ()
222 TestHtmlTable t = new TestHtmlTable ();
226 t.BorderColor = "*4*";
231 Assert.AreEqual (RemoveWS ("<table align=\"*1*\" bgcolor=\"*2*\" border=\"3\" bordercolor=\"*4*\" cellpadding=\"5\" cellspacing=\"6\" height=\"*7*\" width=\"*8*\">\r\n</table>\r\n"), RemoveWS (t.Render ()));
235 public void Render_TableRow_Simple ()
237 TestHtmlTable t = new TestHtmlTable ();
238 t.Rows.Add (new HtmlTableRow ());
239 Assert.AreEqual (RemoveWS ("<table>\r\n\t<tr>\r\n\t</tr>\r\n</table>\r\n"), RemoveWS (t.Render ()));
243 public void Render_TableRow ()
245 TestHtmlTable t = new TestHtmlTable ();
247 HtmlTableRow r1 = new HtmlTableRow ();
250 HtmlTableRow r2 = new HtmlTableRow ();
253 Assert.AreEqual (RemoveWS ("<table border=\"0\">\r\n\t<tr align=\"right\">\r\n\t</tr>\r\n\t<tr align=\"left\">\r\n\t</tr>\r\n</table>\r\n"), RemoveWS (t.Render ()));
257 public void Render_TableRowCell_Simple ()
259 TestHtmlTable t = new TestHtmlTable ();
260 HtmlTableRow r = new HtmlTableRow ();
261 r.Cells.Add (new HtmlTableCell ());
263 Assert.AreEqual (RemoveWS ("<table>\r\n\t<tr>\r\n\t\t<td></td>\r\n\t</tr>\r\n</table>\r\n"),
264 RemoveWS (t.Render ()));
268 public void Render_TableRowCell ()
270 TestHtmlTable t = new TestHtmlTable ();
272 HtmlTableRow r = new HtmlTableRow ();
275 HtmlTableCell c1 = new HtmlTableCell ();
279 HtmlTableCell c2 = new HtmlTableCell ();
281 c2.InnerHtml = "<a href=\"http://www.go-mono.com\">Mono</a>";
283 Assert.AreEqual (RemoveWS ("<table align=\"center\">\r\n\t<tr valign=\"top\">\r\n\t\t<td align=\"right\">Go</td>\r\n\t\t<td align=\"left\"><a href=\"http://www.go-mono.com\">Mono</a></td>\r\n\t</tr>\r\n</table>\r\n"), RemoveWS (t.Render ()));
287 [ExpectedException (typeof (NullReferenceException))]
288 public void HtmlTableRowControlCollectionAdd_Null ()
290 TestHtmlTable t = new TestHtmlTable ();
291 ControlCollection c = t.GetCollection ();
296 [ExpectedException (typeof (ArgumentException))]
297 public void HtmlTableRowControlCollectionAdd_WrongType ()
299 TestHtmlTable t = new TestHtmlTable ();
300 ControlCollection c = t.GetCollection ();
301 c.Add (new HtmlTable ());
305 public void HtmlTableRowControlCollectionAdd ()
307 TestHtmlTable t = new TestHtmlTable ();
308 ControlCollection c = t.GetCollection ();
309 c.Add (new HtmlTableRow ());
310 c.Add (new InheritedHtmlTableRow ());
311 Assert.AreEqual (2, c.Count, "Rows");
315 [ExpectedException (typeof (NullReferenceException))]
316 public void HtmlTableRowControlCollectionAddAt_Null ()
318 TestHtmlTable t = new TestHtmlTable ();
319 ControlCollection c = t.GetCollection ();
324 [ExpectedException (typeof (ArgumentException))]
325 public void HtmlTableRowControlCollectionAddAt_WrongType ()
327 TestHtmlTable t = new TestHtmlTable ();
328 ControlCollection c = t.GetCollection ();
329 c.AddAt (0, new HtmlTable ());
333 public void HtmlTableRowControlCollectionAddAt ()
335 TestHtmlTable t = new TestHtmlTable ();
336 ControlCollection c = t.GetCollection ();
337 c.AddAt (0, new HtmlTableRow ());
338 c.AddAt (0, new InheritedHtmlTableRow ());
339 Assert.AreEqual (2, c.Count, "Rows");