[eglib] Prefer <langinfo.h> to <localcharset.h>
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / CheckBoxListTest.cs
1 //
2 // Tests for System.Web.UI.WebControls.CheckBoxList.cs 
3 //
4 // Author:
5 //      Jackson Harper (jackson@ximian.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.IO;
34 using System.Globalization;
35 using System.Web;
36 using System.Web.UI;
37 using System.Web.UI.WebControls;
38 using System.Drawing;
39 using System.Collections;
40 using MonoTests.SystemWeb.Framework;
41 using MonoTests.stand_alone.WebHarness;
42 using System.Collections.Specialized;
43
44 namespace MonoTests.System.Web.UI.WebControls {
45
46         public class CheckBoxListPoker : CheckBoxList {
47
48                 public Style CreateStyle ()
49                 {
50                         return CreateControlStyle ();
51                 }
52
53                 public Control FindControlPoke (string name, int offset)
54                 {
55                         return FindControl (name, offset);
56                 }
57
58                 public string Render ()
59                 {
60                         HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
61                         base.Render (writer);
62                         return writer.InnerWriter.ToString ();
63                 }
64
65                 
66                 public new bool HasFooter
67                 {
68                         get
69                         {
70                                 return base.HasFooter;
71                         }
72                 }
73
74                 public new bool HasHeader
75                 {
76                         get
77                         {
78                                 return base.HasHeader;
79                         }
80                 }
81
82                 public new bool HasSeparators
83                 {
84                         get
85                         {
86                                 return base.HasSeparators;
87                         }
88                 }
89
90                 public new int RepeatedItemCount
91                 {
92                         get
93                         {
94                                 return base.RepeatedItemCount;
95                         }
96                 }
97
98                 public new void RaisePostDataChangedEvent ()
99                 {
100                         base.RaisePostDataChangedEvent ();
101                 }
102
103                 protected override Style GetItemStyle (ListItemType itemType, int repeatIndex)
104                 {
105                         Style s = new Style();
106                         s.BackColor = Color.Red;
107                         s.BorderStyle = BorderStyle.Solid;
108                         WebTest.CurrentTest.UserData = "GetItemStyle";
109                         return s;
110                 }
111
112                 public Style DoGetItemStyle (ListItemType itemType, int repeatIndex)
113                 {
114                         return base.GetItemStyle (itemType, repeatIndex);
115                 }
116
117                 public new string RenderItem (ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo)
118                 {
119                         HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
120                         base.RenderItem(itemType,repeatIndex,repeatInfo,writer);
121                         return writer.InnerWriter.ToString ();
122                 }
123         }
124
125         [TestFixture]
126         public class CheckBoxListTest
127         {
128                 [TestFixtureSetUp]
129                 public void SetUp ()
130                 {
131                         Type t = GetType ();
132                         WebTest.CopyResource (t, "CheckBoxList_Bug377703_1.aspx", "CheckBoxList_Bug377703_1.aspx");
133                         WebTest.CopyResource (t, "CheckBoxList_Bug377703_2.aspx", "CheckBoxList_Bug377703_2.aspx");
134                         WebTest.CopyResource (t, "CheckBoxList_Bug578770.aspx", "CheckBoxList_Bug578770.aspx");
135                         WebTest.CopyResource (t, "CheckBoxList_Bug600415.aspx", "CheckBoxList_Bug600415.aspx");
136                 }
137                 
138                 [Test]
139                 public void Defaults ()
140                 {
141                         CheckBoxListPoker c = new CheckBoxListPoker ();
142
143                         Assert.AreEqual (c.CellPadding, -1, "A1");
144                         Assert.AreEqual (c.CellSpacing, -1, "A2");
145                         Assert.AreEqual (c.RepeatColumns, 0, "A3");
146                         Assert.AreEqual (c.RepeatDirection,
147                                         RepeatDirection.Vertical, "A4");
148                         Assert.AreEqual (c.RepeatLayout,
149                                         RepeatLayout.Table, "A5");
150                         Assert.AreEqual (c.TextAlign, TextAlign.Right, "A6");
151                         Assert.AreEqual (false, c.HasFooter, "HasFooter");
152                         Assert.AreEqual (false, c.HasHeader, "HasHeader");
153                         Assert.AreEqual (false, c.HasSeparators, "HasSeparators");
154                         Assert.AreEqual (0, c.RepeatedItemCount, "RepeatedItemCount");
155                         Assert.AreEqual (null, c.DoGetItemStyle (ListItemType.Item, 0), "GetItemStyle");
156                 }
157
158                 [Test]
159                 public void CheckBoxList_Bug377703_1 ()
160                 {
161                         WebTest t = new WebTest ("CheckBoxList_Bug377703_1.aspx");
162                         t.Invoker = PageInvoker.CreateOnInit (CheckBoxList_Bug377703_1_OnInit);
163 #if NET_4_0
164                         string origHtmlFirst = "<table id=\"cbxl1\">\r\n\t<tr>\r\n\t\t<td><input id=\"cbxl1_0\" type=\"checkbox\" name=\"cbxl1$0\" value=\"x\" /><label for=\"cbxl1_0\">x</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"cbxl1_1\" type=\"checkbox\" name=\"cbxl1$1\" value=\"y\" /><label for=\"cbxl1_1\">y</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"cbxl1_2\" type=\"checkbox\" name=\"cbxl1$2\" value=\"z\" /><label for=\"cbxl1_2\">z</label></td>\r\n\t</tr>\r\n</table>";
165                         string origHtmlSecond = "<table id=\"cbxl1\">\r\n\t<tr>\r\n\t\t<td><input id=\"cbxl1_0\" type=\"checkbox\" name=\"cbxl1$0\" checked=\"checked\" value=\"x\" /><label for=\"cbxl1_0\">x</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"cbxl1_1\" type=\"checkbox\" name=\"cbxl1$1\" value=\"y\" /><label for=\"cbxl1_1\">y</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"cbxl1_2\" type=\"checkbox\" name=\"cbxl1$2\" value=\"z\" /><label for=\"cbxl1_2\">z</label></td>\r\n\t</tr>\r\n</table>";
166 #else
167                         string origHtmlFirst = "<table id=\"cbxl1\" border=\"0\">\r\n\t<tr>\r\n\t\t<td><input id=\"cbxl1_0\" type=\"checkbox\" name=\"cbxl1$0\" /><label for=\"cbxl1_0\">x</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"cbxl1_1\" type=\"checkbox\" name=\"cbxl1$1\" /><label for=\"cbxl1_1\">y</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"cbxl1_2\" type=\"checkbox\" name=\"cbxl1$2\" /><label for=\"cbxl1_2\">z</label></td>\r\n\t</tr>\r\n</table>";
168                         string origHtmlSecond = "<table id=\"cbxl1\" border=\"0\">\r\n\t<tr>\r\n\t\t<td><input id=\"cbxl1_0\" type=\"checkbox\" name=\"cbxl1$0\" checked=\"checked\" /><label for=\"cbxl1_0\">x</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"cbxl1_1\" type=\"checkbox\" name=\"cbxl1$1\" /><label for=\"cbxl1_1\">y</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"cbxl1_2\" type=\"checkbox\" name=\"cbxl1$2\" /><label for=\"cbxl1_2\">z</label></td>\r\n\t</tr>\r\n</table>";
169 #endif
170                         string html = t.Run ();
171                         string listHtml = HtmlDiff.GetControlFromPageHtml (html);
172
173                         HtmlDiff.AssertAreEqual (origHtmlFirst, listHtml, "#A1");
174
175                         FormRequest fr = new FormRequest (t.Response, "form1");
176                         fr.Controls.Add ("cbxl1$0");
177                         fr.Controls ["cbxl1$0"].Value = "on";
178
179                         fr.Controls.Add ("ctl01");
180                         fr.Controls ["ctl01"].Value = "Click me twice to have the first Item become empty";
181
182                         t.Request = fr;
183                         html = t.Run ();
184
185                         fr = new FormRequest (t.Response, "form1");
186                         fr.Controls.Add ("cbxl1$0");
187                         fr.Controls ["cbxl1$0"].Value = "on";
188
189                         fr.Controls.Add ("ctl01");
190                         fr.Controls ["ctl01"].Value = "Click me twice to have the first Item become empty";
191
192                         t.Request = fr;
193                         html = t.Run ();
194
195                         listHtml = HtmlDiff.GetControlFromPageHtml (html);
196                         HtmlDiff.AssertAreEqual (origHtmlSecond, listHtml, "#A2");
197                 }
198
199                 public static void CheckBoxList_Bug377703_1_OnInit (Page p)
200                 {
201                         CheckBoxList cbxl1 = p.FindControl ("cbxl1") as CheckBoxList;
202                         
203                         cbxl1.DataSource = new[] {
204                                 new { ID = "x", Text = "X" },
205                                 new { ID = "y", Text = "Y" },
206                                 new { ID = "z", Text = "Z" },
207                         };
208                         cbxl1.DataValueField = "ID";
209                         cbxl1.DataTextField = "ID";
210                         cbxl1.DataBind();
211                 }
212
213                 [Test]
214                 public void CheckBoxList_Bug377703_2 ()
215                 {
216                         WebTest t = new WebTest ("CheckBoxList_Bug377703_2.aspx");
217                         t.Invoker = PageInvoker.CreateOnInit (CheckBoxList_Bug377703_2_OnInit);
218 #if NET_4_0
219                         string origHtmlFirst = "<table id=\"cbxl2\">\r\n\t<tr>\r\n\t\t<td><input id=\"cbxl2_0\" type=\"checkbox\" name=\"cbxl2$0\" value=\"x\" /><label for=\"cbxl2_0\">x</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"cbxl2_1\" type=\"checkbox\" name=\"cbxl2$1\" value=\"y\" /><label for=\"cbxl2_1\">y</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"cbxl2_2\" type=\"checkbox\" name=\"cbxl2$2\" value=\"z\" /><label for=\"cbxl2_2\">z</label></td>\r\n\t</tr>\r\n</table>";
220                         string origHtmlSecond = "<table id=\"cbxl2\" class=\"aspNetDisabled\">\r\n\t<tr>\r\n\t\t<td><span class=\"aspNetDisabled\"><input id=\"cbxl2_0\" type=\"checkbox\" name=\"cbxl2$0\" checked=\"checked\" disabled=\"disabled\" value=\"x\" /><label for=\"cbxl2_0\">x</label></span></td>\r\n\t</tr><tr>\r\n\t\t<td><span class=\"aspNetDisabled\"><input id=\"cbxl2_1\" type=\"checkbox\" name=\"cbxl2$1\" disabled=\"disabled\" value=\"y\" /><label for=\"cbxl2_1\">y</label></span></td>\r\n\t</tr><tr>\r\n\t\t<td><span class=\"aspNetDisabled\"><input id=\"cbxl2_2\" type=\"checkbox\" name=\"cbxl2$2\" checked=\"checked\" disabled=\"disabled\" value=\"z\" /><label for=\"cbxl2_2\">z</label></span></td>\r\n\t</tr>\r\n</table>";
221                         string origHtmlThird = "<table id=\"cbxl2\" class=\"aspNetDisabled\">\r\n\t<tr>\r\n\t\t<td><span class=\"aspNetDisabled\"><input id=\"cbxl2_0\" type=\"checkbox\" name=\"cbxl2$0\" checked=\"checked\" disabled=\"disabled\" value=\"x\" /><label for=\"cbxl2_0\">x</label></span></td>\r\n\t</tr><tr>\r\n\t\t<td><span class=\"aspNetDisabled\"><input id=\"cbxl2_1\" type=\"checkbox\" name=\"cbxl2$1\" disabled=\"disabled\" value=\"y\" /><label for=\"cbxl2_1\">y</label></span></td>\r\n\t</tr><tr>\r\n\t\t<td><span class=\"aspNetDisabled\"><input id=\"cbxl2_2\" type=\"checkbox\" name=\"cbxl2$2\" checked=\"checked\" disabled=\"disabled\" value=\"z\" /><label for=\"cbxl2_2\">z</label></span></td>\r\n\t</tr>\r\n</table>";
222 #else
223                         string origHtmlFirst = "<table id=\"cbxl2\" border=\"0\">\r\n\t<tr>\r\n\t\t<td><input id=\"cbxl2_0\" type=\"checkbox\" name=\"cbxl2$0\" /><label for=\"cbxl2_0\">x</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"cbxl2_1\" type=\"checkbox\" name=\"cbxl2$1\" /><label for=\"cbxl2_1\">y</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"cbxl2_2\" type=\"checkbox\" name=\"cbxl2$2\" /><label for=\"cbxl2_2\">z</label></td>\r\n\t</tr>\r\n</table>";
224                         string origHtmlSecond = "<table id=\"cbxl2\" disabled=\"disabled\" border=\"0\">\r\n\t<tr>\r\n\t\t<td><span disabled=\"disabled\"><input id=\"cbxl2_0\" type=\"checkbox\" name=\"cbxl2$0\" checked=\"checked\" disabled=\"disabled\" /><label for=\"cbxl2_0\">x</label></span></td>\r\n\t</tr><tr>\r\n\t\t<td><span disabled=\"disabled\"><input id=\"cbxl2_1\" type=\"checkbox\" name=\"cbxl2$1\" disabled=\"disabled\" /><label for=\"cbxl2_1\">y</label></span></td>\r\n\t</tr><tr>\r\n\t\t<td><span disabled=\"disabled\"><input id=\"cbxl2_2\" type=\"checkbox\" name=\"cbxl2$2\" checked=\"checked\" disabled=\"disabled\" /><label for=\"cbxl2_2\">z</label></span></td>\r\n\t</tr>\r\n</table>";
225                         string origHtmlThird = "<table id=\"cbxl2\" disabled=\"disabled\" border=\"0\">\r\n\t<tr>\r\n\t\t<td><span disabled=\"disabled\"><input id=\"cbxl2_0\" type=\"checkbox\" name=\"cbxl2$0\" checked=\"checked\" disabled=\"disabled\" /><label for=\"cbxl2_0\">x</label></span></td>\r\n\t</tr><tr>\r\n\t\t<td><span disabled=\"disabled\"><input id=\"cbxl2_1\" type=\"checkbox\" name=\"cbxl2$1\" disabled=\"disabled\" /><label for=\"cbxl2_1\">y</label></span></td>\r\n\t</tr><tr>\r\n\t\t<td><span disabled=\"disabled\"><input id=\"cbxl2_2\" type=\"checkbox\" name=\"cbxl2$2\" checked=\"checked\" disabled=\"disabled\" /><label for=\"cbxl2_2\">z</label></span></td>\r\n\t</tr>\r\n</table>";
226 #endif
227                         string html = t.Run ();
228                         string listHtml = HtmlDiff.GetControlFromPageHtml (html);
229
230                         HtmlDiff.AssertAreEqual (origHtmlFirst, listHtml, "#A1");
231
232                         FormRequest fr = new FormRequest (t.Response, "form1");
233                         fr.Controls.Add ("cbxl2$0");
234                         fr.Controls ["cbxl2$0"].Value = "on";
235
236                         fr.Controls.Add ("cbxl2$2");
237                         fr.Controls ["cbxl2$2"].Value = "on";
238                         
239                         fr.Controls.Add ("ctl01");
240                         fr.Controls ["ctl01"].Value = "Click to toggle enable status above";
241
242                         t.Request = fr;
243                         html = t.Run ();
244
245                         listHtml = HtmlDiff.GetControlFromPageHtml (html);
246
247                         HtmlDiff.AssertAreEqual (origHtmlSecond, listHtml, "#A2");
248                         
249                         fr = new FormRequest (t.Response, "form1");
250                         fr.Controls.Add ("ctl02");
251                         fr.Controls ["ctl02"].Value = "Click to refresh page";
252
253                         t.Request = fr;
254                         html = t.Run ();
255
256                         listHtml = HtmlDiff.GetControlFromPageHtml (html);
257                         HtmlDiff.AssertAreEqual (origHtmlThird, listHtml, "#A3");
258                 }
259
260                 public static void CheckBoxList_Bug377703_2_OnInit (Page p)
261                 {
262                         CheckBoxList cbxl2 = p.FindControl ("cbxl2") as CheckBoxList;
263                         
264                         cbxl2.DataSource = new[] {
265                                 new { ID = "x", Text = "X" },
266                                 new { ID = "y", Text = "Y" },
267                                 new { ID = "z", Text = "Z" },
268                         };
269                         cbxl2.DataValueField = "ID";
270                         cbxl2.DataTextField = "ID";
271                         cbxl2.DataBind();
272                 }
273
274                 [Test]
275                 public void CheckBoxList_Bug578770 ()
276                 {
277                         WebTest t = new WebTest ("CheckBoxList_Bug578770.aspx");
278                         t.Invoker = PageInvoker.CreateOnInit (CheckBoxList_Bug578770_OnInit);
279 #if NET_4_0
280                         string origHtml = "<table id=\"test\">\r\n\t<tr>\r\n\t\t<td><span class=\"aspNetDisabled\"><input id=\"test_0\" type=\"checkbox\" name=\"test$0\" disabled=\"disabled\" value=\"Sun\" /><label for=\"test_0\">Sun</label></span></td>\r\n\t</tr><tr>\r\n\t\t<td><span><input id=\"test_1\" type=\"checkbox\" name=\"test$1\" value=\"Mon\" /><label for=\"test_1\">Mon</label></span></td>\r\n\t</tr><tr>\r\n\t\t<td><span><input id=\"test_2\" type=\"checkbox\" name=\"test$2\" value=\"Tue\" /><label for=\"test_2\">Tue</label></span></td>\r\n\t</tr><tr>\r\n\t\t<td><span><input id=\"test_3\" type=\"checkbox\" name=\"test$3\" value=\"Wed\" /><label for=\"test_3\">Wed</label></span></td>\r\n\t</tr><tr>\r\n\t\t<td><span><input id=\"test_4\" type=\"checkbox\" name=\"test$4\" value=\"Thu\" /><label for=\"test_4\">Thu</label></span></td>\r\n\t</tr><tr>\r\n\t\t<td><span><input id=\"test_5\" type=\"checkbox\" name=\"test$5\" value=\"Fri\" /><label for=\"test_5\">Fri</label></span></td>\r\n\t</tr><tr>\r\n\t\t<td><span><input id=\"test_6\" type=\"checkbox\" name=\"test$6\" value=\"Sat\" /><label for=\"test_6\">Sat</label></span></td>\r\n\t</tr>\r\n</table>";
281 #else
282                         string origHtml = "<table id=\"test\" border=\"0\">\r\n\t<tr>\r\n\t\t<td><span disabled=\"disabled\"><input id=\"test_0\" type=\"checkbox\" name=\"test$0\" disabled=\"disabled\" /><label for=\"test_0\">Sun</label></span></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"test_1\" type=\"checkbox\" name=\"test$1\" /><label for=\"test_1\">Mon</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"test_2\" type=\"checkbox\" name=\"test$2\" /><label for=\"test_2\">Tue</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"test_3\" type=\"checkbox\" name=\"test$3\" /><label for=\"test_3\">Wed</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"test_4\" type=\"checkbox\" name=\"test$4\" /><label for=\"test_4\">Thu</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"test_5\" type=\"checkbox\" name=\"test$5\" /><label for=\"test_5\">Fri</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"test_6\" type=\"checkbox\" name=\"test$6\" /><label for=\"test_6\">Sat</label></td>\r\n\t</tr>\r\n</table>";
283 #endif
284                         string html = t.Run ();
285                         string listHtml = HtmlDiff.GetControlFromPageHtml (html);
286
287                         HtmlDiff.AssertAreEqual (origHtml, listHtml, "#A1");
288                 }
289
290                 public static void CheckBoxList_Bug578770_OnInit (Page p)
291                 {
292                         CheckBoxList test = p.FindControl ("test") as CheckBoxList;
293                         string[] weekDays = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
294                         test.DataSource = weekDays;
295                         test.DataBind();
296                         test.Items[0].Enabled = false;
297                 }
298
299                 [Test]
300                 public void CheckBoxList_Bug600415 ()
301                 {
302                         WebTest t = new WebTest ("CheckBoxList_Bug600415.aspx");
303 #if NET_4_0
304                         string origHtmlFirst = "<table id=\"checkBoxList\">\r\n\t<tr>\r\n\t\t<td><input id=\"checkBoxList_0\" type=\"checkbox\" name=\"checkBoxList$0\" checked=\"checked\" value=\"Item 1\" /><label for=\"checkBoxList_0\">Item 1</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"checkBoxList_1\" type=\"checkbox\" name=\"checkBoxList$1\" value=\"Item 2\" /><label for=\"checkBoxList_1\">Item 2</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"checkBoxList_2\" type=\"checkbox\" name=\"checkBoxList$2\" checked=\"checked\" value=\"Item 3\" /><label for=\"checkBoxList_2\">Item 3</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"checkBoxList_3\" type=\"checkbox\" name=\"checkBoxList$3\" value=\"Item 4\" /><label for=\"checkBoxList_3\">Item 4</label></td>\r\n\t</tr>\r\n</table>";
305                         string origHtmlSecond = "<table id=\"checkBoxList\">\r\n\t<tr>\r\n\t\t<td><input id=\"checkBoxList_0\" type=\"checkbox\" name=\"checkBoxList$0\" value=\"Item 1\" /><label for=\"checkBoxList_0\">Item 1</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"checkBoxList_1\" type=\"checkbox\" name=\"checkBoxList$1\" value=\"Item 2\" /><label for=\"checkBoxList_1\">Item 2</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"checkBoxList_2\" type=\"checkbox\" name=\"checkBoxList$2\" value=\"Item 3\" /><label for=\"checkBoxList_2\">Item 3</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"checkBoxList_3\" type=\"checkbox\" name=\"checkBoxList$3\" value=\"Item 4\" /><label for=\"checkBoxList_3\">Item 4</label></td>\r\n\t</tr>\r\n</table>";
306                         string origHtmlThird = "<table id=\"checkBoxList\">\r\n\t<tr>\r\n\t\t<td><input id=\"checkBoxList_0\" type=\"checkbox\" name=\"checkBoxList$0\" checked=\"checked\" value=\"Item 1\" /><label for=\"checkBoxList_0\">Item 1</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"checkBoxList_1\" type=\"checkbox\" name=\"checkBoxList$1\" checked=\"checked\" value=\"Item 2\" /><label for=\"checkBoxList_1\">Item 2</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"checkBoxList_2\" type=\"checkbox\" name=\"checkBoxList$2\" checked=\"checked\" value=\"Item 3\" /><label for=\"checkBoxList_2\">Item 3</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"checkBoxList_3\" type=\"checkbox\" name=\"checkBoxList$3\" checked=\"checked\" value=\"Item 4\" /><label for=\"checkBoxList_3\">Item 4</label></td>\r\n\t</tr>\r\n</table>";
307 #else
308                         string origHtmlFirst = "<table id=\"checkBoxList\" border=\"0\">\r\n\t<tr>\r\n\t\t<td><input id=\"checkBoxList_0\" type=\"checkbox\" name=\"checkBoxList$0\" checked=\"checked\" /><label for=\"checkBoxList_0\">Item 1</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"checkBoxList_1\" type=\"checkbox\" name=\"checkBoxList$1\" /><label for=\"checkBoxList_1\">Item 2</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"checkBoxList_2\" type=\"checkbox\" name=\"checkBoxList$2\" checked=\"checked\" /><label for=\"checkBoxList_2\">Item 3</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"checkBoxList_3\" type=\"checkbox\" name=\"checkBoxList$3\" /><label for=\"checkBoxList_3\">Item 4</label></td>\r\n\t</tr>\r\n</table>";
309                         string origHtmlSecond = "<table id=\"checkBoxList\" border=\"0\">\r\n\t<tr>\r\n\t\t<td><input id=\"checkBoxList_0\" type=\"checkbox\" name=\"checkBoxList$0\" /><label for=\"checkBoxList_0\">Item 1</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"checkBoxList_1\" type=\"checkbox\" name=\"checkBoxList$1\" /><label for=\"checkBoxList_1\">Item 2</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"checkBoxList_2\" type=\"checkbox\" name=\"checkBoxList$2\" /><label for=\"checkBoxList_2\">Item 3</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"checkBoxList_3\" type=\"checkbox\" name=\"checkBoxList$3\" /><label for=\"checkBoxList_3\">Item 4</label></td>\r\n\t</tr>\r\n</table>";
310                         string origHtmlThird = "<table id=\"checkBoxList\" border=\"0\">\r\n\t<tr>\r\n\t\t<td><input id=\"checkBoxList_0\" type=\"checkbox\" name=\"checkBoxList$0\" checked=\"checked\" /><label for=\"checkBoxList_0\">Item 1</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"checkBoxList_1\" type=\"checkbox\" name=\"checkBoxList$1\" checked=\"checked\" /><label for=\"checkBoxList_1\">Item 2</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"checkBoxList_2\" type=\"checkbox\" name=\"checkBoxList$2\" checked=\"checked\" /><label for=\"checkBoxList_2\">Item 3</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"checkBoxList_3\" type=\"checkbox\" name=\"checkBoxList$3\" checked=\"checked\" /><label for=\"checkBoxList_3\">Item 4</label></td>\r\n\t</tr>\r\n</table>";
311 #endif
312                         string html = t.Run ();
313                         string listHtml = HtmlDiff.GetControlFromPageHtml (html);
314
315                         HtmlDiff.AssertAreEqual (origHtmlFirst, listHtml, "#A1");
316
317                         FormRequest fr = new FormRequest (t.Response, "form1");
318                         fr.Controls.Add ("cmdClick");
319                         fr.Controls ["cmdClick"].Value = "Ok";
320
321                         t.Request = fr;
322                         html = t.Run ();
323                         
324                         listHtml = HtmlDiff.GetControlFromPageHtml (html);
325                         HtmlDiff.AssertAreEqual (origHtmlSecond, listHtml, "#A2");
326
327                         fr = new FormRequest (t.Response, "form1");
328                         fr.Controls.Add ("checkBoxList$0");
329                         fr.Controls ["checkBoxList$0"].Value = "on";
330                         fr.Controls.Add ("checkBoxList$1");
331                         fr.Controls ["checkBoxList$1"].Value = "on";
332                         fr.Controls.Add ("checkBoxList$2");
333                         fr.Controls ["checkBoxList$2"].Value = "on";
334                         fr.Controls.Add ("checkBoxList$3");
335                         fr.Controls ["checkBoxList$3"].Value = "on";
336
337                         t.Request = fr;
338                         html = t.Run ();
339                         listHtml = HtmlDiff.GetControlFromPageHtml (html);
340                         HtmlDiff.AssertAreEqual (origHtmlThird, listHtml, "#A3");
341                 }
342                 
343                 [Test]
344                 public void RaisePostDataChangedEvent ()
345                 {
346                         CheckBoxListPoker c = new CheckBoxListPoker ();
347                         c.SelectedIndexChanged += new EventHandler (c_SelectedIndexChanged);
348                         Assert.AreEqual (false, eventSelectedIndexChanged, "RaisePostDataChangedEvent#1");
349                         c.RaisePostDataChangedEvent ();
350                         Assert.AreEqual (true, eventSelectedIndexChanged, "RaisePostDataChangedEvent#2");
351                 }
352
353                 bool eventSelectedIndexChanged;
354                 void c_SelectedIndexChanged (object sender, EventArgs e)
355                 {
356                         eventSelectedIndexChanged = true;
357                 }
358
359                 [Test]
360                 [Category("NunitWeb")]
361                 public void GetItemStyle ()
362                 {
363                         WebTest t = new WebTest (PageInvoker.CreateOnLoad (GetItemStyle_Load));
364                         string html = t.Run ();
365                         string ctrl = HtmlDiff.GetControlFromPageHtml (html);
366                         if (ctrl == string.Empty)
367                                 Assert.Fail ("CheckBoxList not created fail");
368                         Assert.AreEqual ("GetItemStyle", (string) t.UserData, "GetItemStyle not done");
369                         if ( ctrl.IndexOf("<td style=\"background-color:Red;border-style:Solid;\">") == -1)
370                                 Assert.Fail ("CheckBoxList style not rendered");
371                 }
372
373                 public static void GetItemStyle_Load (Page p)
374                 {
375                         CheckBoxListPoker c = new CheckBoxListPoker ();
376                         ListItem l1 = new ListItem ("item1", "value1");
377                         ListItem l2 = new ListItem ("item2", "value2");
378
379                         c.Items.Add (l1);
380                         c.Items.Add (l2);
381                         p.Form.Controls.Add(new LiteralControl(HtmlDiff.BEGIN_TAG));
382                         p.Form.Controls.Add (c);
383                         p.Form.Controls.Add(new LiteralControl(HtmlDiff.END_TAG));
384                 }
385
386                 [Test]
387                 public void RenderItem ()
388                 {
389 #if NET_4_0
390                         string origHtml1 = "<input id=\"0\" type=\"checkbox\" name=\"0\" value=\"value1\" /><label for=\"0\">item1</label>";
391                         string origHtml2 = "<input id=\"1\" type=\"checkbox\" name=\"1\" value=\"value2\" /><label for=\"1\">item2</label>";
392 #else
393                         string origHtml1 = "<input id=\"0\" type=\"checkbox\" name=\"0\" /><label for=\"0\">item1</label>";
394                         string origHtml2 = "<input id=\"1\" type=\"checkbox\" name=\"1\" /><label for=\"1\">item2</label>";
395 #endif
396                         CheckBoxListPoker c = new CheckBoxListPoker ();
397                         ListItem l1 = new ListItem ("item1", "value1");
398                         ListItem l2 = new ListItem ("item2", "value2");
399
400                         c.Items.Add (l1);
401                         c.Items.Add (l2);
402                         string html = c.RenderItem (ListItemType.Item, 0, null);
403                         HtmlDiff.AssertAreEqual (origHtml1, html, "RenderItem#1");
404                         html = c.RenderItem (ListItemType.Item, 1, null);
405                         HtmlDiff.AssertAreEqual (origHtml2, html, "RenderItem#2");
406                 }
407
408                 [Test]
409                 public void RepeatedItemCount ()
410                 {
411                         CheckBoxListPoker c = new CheckBoxListPoker ();
412                         ListItem l1 = new ListItem ("item1", "value1");
413                         ListItem l2 = new ListItem ("item2", "value2");
414                         Assert.AreEqual (0, c.RepeatedItemCount, "RepeatedItemCount#1");
415                         c.Items.Add (l1);
416                         c.Items.Add (l2);
417                         Assert.AreEqual (2, c.RepeatedItemCount, "RepeatedItemCount#2");
418                 }
419
420
421
422                 [Test]
423                 public void CleanProperties ()
424                 {
425                         CheckBoxList c = new CheckBoxList ();
426
427                         c.CellPadding = Int32.MaxValue;
428                         Assert.AreEqual (c.CellPadding, Int32.MaxValue, "A1");
429
430                         c.CellSpacing = Int32.MaxValue;
431                         Assert.AreEqual (c.CellSpacing, Int32.MaxValue, "A2");
432
433                         c.RepeatColumns = Int32.MaxValue;
434                         Assert.AreEqual (c.RepeatColumns, Int32.MaxValue, "A3");
435
436                         foreach (RepeatDirection d in
437                                         Enum.GetValues (typeof (RepeatDirection))) {
438                                 c.RepeatDirection = d;
439                                 Assert.AreEqual (c.RepeatDirection, d, "A4-" + d);
440                         }
441
442                         foreach (RepeatLayout l in
443                                         Enum.GetValues (typeof (RepeatLayout))) {
444                                 c.RepeatLayout = l;
445                                 Assert.AreEqual (c.RepeatLayout, l, "A5-" + l);
446                         }
447                 }
448
449                 [Test]
450                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
451                 public void CellPaddingTooLow ()
452                 {
453                         CheckBoxList c = new CheckBoxList ();
454                         c.CellPadding = -2;
455                 }
456
457                 [Test]
458                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
459                 public void CellSpacingTooLow ()
460                 {
461                         CheckBoxList c = new CheckBoxList ();
462                         c.CellSpacing = -2;
463                 }
464
465                 [Test]
466                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
467                 public void RepeatColumsTooLow ()
468                 {
469                         CheckBoxList c = new CheckBoxList ();
470                         c.RepeatColumns = -1;
471                 }
472
473                 [Test]
474                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
475                 public void RepeatDirection_Invalid ()
476                 {
477                         CheckBoxList c = new CheckBoxList ();
478                         c.RepeatDirection = (RepeatDirection) Int32.MaxValue;
479                 }
480
481                 [Test]
482                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
483                 public void RepeatLayout_Invalid ()
484                 {
485                         CheckBoxList c = new CheckBoxList ();
486                         c.RepeatLayout = (RepeatLayout) Int32.MaxValue;
487                 }
488
489                 [Test]
490                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
491                 public void TextAlign_Invalid ()
492                 {
493                         CheckBoxList c = new CheckBoxList ();
494                         c.TextAlign = (TextAlign) Int32.MaxValue;
495                 }
496
497                 [Test]
498                 public void ChildCheckBoxControl ()
499                 {
500                         CheckBoxList c = new CheckBoxList ();
501                         Assert.AreEqual (c.Controls.Count, 1, "A1");
502                         Assert.AreEqual (c.Controls [0].GetType (), typeof (CheckBox), "A2");
503                 }
504
505                 [Test]
506                 public void CreateStyle ()
507                 {
508                         CheckBoxListPoker c = new CheckBoxListPoker ();
509                         Assert.AreEqual (c.CreateStyle ().GetType (), typeof (TableStyle), "A1");
510                 }
511
512                 [Test]
513                 public void RepeatInfoProperties ()
514                 {
515                         IRepeatInfoUser ri = new CheckBoxList ();
516
517                         Assert.IsFalse (ri.HasFooter, "A1");
518                         Assert.IsFalse (ri.HasHeader, "A2");
519                         Assert.IsFalse (ri.HasSeparators, "A3");
520                         Assert.AreEqual (ri.RepeatedItemCount, 0, "A4");
521                 }
522
523                 [Test]
524                 public void RepeatInfoCount ()
525                 {
526                         CheckBoxList c = new CheckBoxList ();
527                         IRepeatInfoUser ri = (IRepeatInfoUser) c;
528
529                         Assert.AreEqual (ri.RepeatedItemCount, 0, "A1");
530
531                         c.Items.Add ("one");
532                         c.Items.Add ("two");
533                         c.Items.Add ("three");
534                         Assert.AreEqual (ri.RepeatedItemCount, 3, "A2");
535                 }
536
537                 [Test]
538                 public void RepeatInfoStyle ()
539                 {
540                         IRepeatInfoUser ri = new CheckBoxList ();
541
542                         foreach (ListItemType t in Enum.GetValues (typeof (ListItemType))) {
543                                 Assert.AreEqual (ri.GetItemStyle (t, 0), null, "A1-" + t);
544                                 Assert.AreEqual (ri.GetItemStyle (t, 1), null, "A2-" + t);
545                                 Assert.AreEqual (ri.GetItemStyle (t, 2), null, "A3-" + t);
546                                 Assert.AreEqual (ri.GetItemStyle (t, 3), null, "A4-" + t);
547                         }
548                 }
549
550                 [Test]
551                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
552                 public void RepeatInfoRenderOutOfRange ()
553                 {
554                         StringWriter sw = new StringWriter ();
555                         HtmlTextWriter tw = new HtmlTextWriter (sw);
556                         IRepeatInfoUser ri = new CheckBoxList ();
557
558                         ri.RenderItem (ListItemType.Item, -1, new RepeatInfo (), tw); 
559                 }
560
561                 [Test]
562                 public void RepeatInfoRenderItem ()
563                 {
564 #if NET_4_0
565                         string origHtml = "<input id=\"0\" type=\"checkbox\" name=\"0\" value=\"one\" /><label for=\"0\">one</label>";
566 #else
567                         string origHtml = "<input id=\"0\" type=\"checkbox\" name=\"0\" /><label for=\"0\">one</label>";
568 #endif
569                         StringWriter sw = new StringWriter ();
570                         HtmlTextWriter tw = new HtmlTextWriter (sw);
571                         CheckBoxList c = new CheckBoxList ();
572                         IRepeatInfoUser ri = (IRepeatInfoUser) c;
573                         RepeatInfo r = new RepeatInfo ();
574
575                         c.Items.Add ("one");
576                         c.Items.Add ("two");
577
578                         ri.RenderItem (ListItemType.Item, 0, r, tw);
579                         string html = sw.ToString ();
580                         Assert.AreEqual (origHtml, html, "A1");
581                 }
582
583                 [Test]
584                 public void FindControl ()
585                 {
586                         CheckBoxListPoker p = new CheckBoxListPoker ();
587
588                         p.ID = "id";
589                         p.Items.Add ("one");
590                         p.Items.Add ("two");
591                         p.Items.Add ("three");
592
593                         // Everything seems to return this.
594                         Assert.AreEqual (p.FindControlPoke (String.Empty, 0), p, "A1");
595                         Assert.AreEqual (p.FindControlPoke ("id", 0), p, "A2");
596                         Assert.AreEqual (p.FindControlPoke ("id_0", 0), p, "A3");
597                         Assert.AreEqual (p.FindControlPoke ("id_1", 0), p, "A4");
598                         Assert.AreEqual (p.FindControlPoke ("id_2", 0), p, "A5");
599                         Assert.AreEqual (p.FindControlPoke ("id_3", 0), p, "A6");
600                         Assert.AreEqual (p.FindControlPoke ("0", 0), p, "A7");
601
602                         Assert.AreEqual (p.FindControlPoke (String.Empty, 10), p, "A1");
603                         Assert.AreEqual (p.FindControlPoke ("id", 10), p, "A2");
604                         Assert.AreEqual (p.FindControlPoke ("id_0", 10), p, "A3");
605                         Assert.AreEqual (p.FindControlPoke ("id_1", 10), p, "A4");
606                         Assert.AreEqual (p.FindControlPoke ("id_2", 10), p, "A5");
607                         Assert.AreEqual (p.FindControlPoke ("id_3", 10), p, "A6");
608                         Assert.AreEqual (p.FindControlPoke ("0", 10), p, "A7");
609                 }
610
611                 private void Render (CheckBoxList list, string expected, string test)
612                 {
613                         StringWriter sw = new StringWriter ();
614                         HtmlTextWriter tw = new CleanHtmlTextWriter (sw);
615                         sw.NewLine = "\n";
616
617                         list.RenderControl (tw);
618                         HtmlDiff.AssertAreEqual (expected, sw.ToString (), test);
619                 }
620
621                 [Test]
622                 public void RenderEmpty ()
623                 {
624                         CheckBoxList c = new CheckBoxList ();
625
626                         Render (c, "", "A1");
627                         c.CellPadding = 1;
628                         Render (c, "", "A2");
629
630                         c = new CheckBoxList ();
631                         c.CellPadding = 1;
632                         Render (c, "", "A3");
633
634                         c = new CheckBoxList ();
635                         c.TextAlign = TextAlign.Left;
636                         Render (c, "", "A4");
637                 }
638
639                 [Test]
640                 [Category("NotDotNet")] // MS's implementation throws NRE's from these
641                 public void Render ()
642                 {
643 #if NET_4_0
644                         string origHtml1 = "<table>\n\t<tr>\n\t\t<td><input id=\"0\" name=\"0\" type=\"checkbox\" value=\"foo\"/><label for=\"0\">foo</label></td>\n\t</tr>\n</table>";
645                         string origHtml2 = "<table>\n\t<tr>\n\t\t<td><input id=\"0\" name=\"0\" type=\"checkbox\" value=\"foo\"/><label for=\"0\">foo</label></td>\n\t</tr>\n</table>";
646 #else
647                         string origHtml1 = "<table border=\"0\">\n\t<tr>\n\t\t<td><input id=\"0\" name=\"0\" type=\"checkbox\" /><label for=\"0\">foo</label></td>\n\t</tr>\n</table>";
648                         string origHtml2 = "<table border=\"0\">\n\t<tr>\n\t\t<td><input id=\"0\" name=\"0\" type=\"checkbox\" /><label for=\"0\">foo</label></td>\n\t</tr>\n</table>";
649 #endif
650                         CheckBoxList c;
651                         c = new CheckBoxList ();
652                         c.Items.Add ("foo");
653
654                         Render (c, origHtml1, "A5");
655
656                         c = new CheckBoxList ();
657                         c.Items.Add ("foo");
658                         Render (c, origHtml2, "A6");
659                 }
660
661                 // bug 51648
662                 [Test]
663                 [Category("NotDotNet")] // MS's implementation throws NRE's from these
664                 public void TestTabIndex ()
665                 {
666                         CheckBoxList c = new CheckBoxList ();
667                         c.TabIndex = 5;
668                         c.Items.Add ("Item1");
669 #if NET_4_0
670                         string exp = @"<table>
671         <tr>
672                 <td><input id=""0"" name=""0"" tabindex=""5"" type=""checkbox"" value=""Item1""/><label for=""0"">Item1</label></td>
673         </tr>
674 </table>";
675 #else
676                         string exp = @"<table border=""0"">
677         <tr>
678                 <td><input id=""0"" name=""0"" tabindex=""5"" type=""checkbox"" /><label for=""0"">Item1</label></td>
679         </tr>
680 </table>";
681 #endif
682                         Render (c, exp, "B1");
683                 }
684
685                 // bug 48802
686                 [Test]
687                 [Category("NotDotNet")] // MS's implementation throws NRE's from these
688                 public void TestDisabled ()
689                 {
690                         CheckBoxList c = new CheckBoxList ();
691                         c.Enabled = false;
692                         c.Items.Add ("Item1");
693 #if NET_4_0
694                         string exp = @"<table class=""aspNetDisabled"">
695         <tr>
696                 <td><span class=""aspNetDisabled""><input disabled=""disabled"" id=""0"" name=""0"" type=""checkbox"" value=""Item1""/><label for=""0"">Item1</label></span></td>
697         </tr>
698 </table>";
699 #else
700                         string exp = @"<table border=""0"" disabled=""disabled"">
701         <tr>
702                 <td><span disabled=""disabled""><input disabled=""disabled"" id=""0"" name=""0"" type=""checkbox"" /><label for=""0"">Item1</label></span></td>
703         </tr>
704 </table>";
705 #endif
706                         Render (c, exp, "C1");
707                 }       
708         class TestCheckBoxList : CheckBoxList
709         {
710             public void CallVerifyMultiSelect()
711             {
712                 base.VerifyMultiSelect();
713             }
714         }
715         [Test]
716         public void VerifyMultiSelectTest()
717         {
718             TestCheckBoxList list = new TestCheckBoxList();
719             list.CallVerifyMultiSelect();
720         }
721         [TestFixtureTearDown]
722                 public void teardown ()
723                 {
724                         WebTest.Unload ();
725                 }
726         }
727 }
728
729