* support-test-*.cs: Rename from test-*-p2.cs.
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / DataGridPagerStyleTest.cs
1 //
2 // Tests for System.Web.UI.WebControls.DataGridPagerStyle 
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         public class DGTestClass : DataGrid {
43
44                 public DGTestClass ()
45                         : base () {
46                 }
47
48                 public StateBag StateBag {
49                         get { return base.ViewState; }
50                 }
51
52                 public string[] KeyValuePairs() {
53                         IEnumerator     e;
54                         string[]        result;
55                         int             item;
56
57                         e = ViewState.GetEnumerator();
58                         result = new string[ViewState.Keys.Count];
59                         item = 0;
60
61                         while (e.MoveNext()) {
62                                 DictionaryEntry d;
63                                 StateItem       si;
64
65                                 d = (DictionaryEntry)e.Current;
66                                 si = (StateItem)d.Value;
67
68                                 if (si.Value is String[]) {
69                                         string[] values;
70
71                                         values = (string[]) si.Value;
72                                         result[item] = d.Key.ToString() + "=";
73                                         if (values.Length > 0) {
74                                                 result[item] += values[0];
75
76                                                 for (int i = 1; i < values.Length; i++) {
77                                                         result[item] += ", " + values[i];
78                                                 }
79                                         }
80                                 } else {
81                                         result[item] =  d.Key.ToString() + "=" + si.Value;
82                                 }
83                                 item++;
84                         }
85
86                         return result;
87                 }
88         }
89
90         [TestFixture]   
91         public class DataGridPagerStyleTest {
92                 private static HtmlTextWriter GetWriter () {
93                         StringWriter sw = new StringWriter ();
94                         sw.NewLine = "\n";
95                         return new HtmlTextWriter (sw);
96                 }
97
98                 private bool IsEqual(object[] a1, object[] a2, string assertion) {
99                         int     matches;
100                         bool[]  notfound;       
101
102                         if (a1.Length != a2.Length) {
103                                 if (assertion != null) {
104                                         Assert.Fail(assertion + "( different length )");
105                                 }
106                                 return false;
107                         }
108
109                         matches = 0;
110                         notfound = new bool[a1.Length];
111
112                         for (int i = 0; i < a1.Length; i++) {
113                                 for (int j = 0; j < a2.Length; j++) {
114                                         if (a1[i].Equals(a2[j])) {
115                                                 matches++;
116                                                 break;
117                                         }
118                                 }
119                                 if ((assertion != null) && (matches != i+1)) {
120                                         Assert.Fail(assertion + "( missing " + a1[i].ToString() + " )");
121                                 }
122                         }
123
124                         return matches == a1.Length;
125                 }
126
127                 [Test]
128                 public void DataGridPagerStyle_Defaults () {
129                         DataGrid                g;
130                         DataGridPagerStyle      s;
131
132                         g = new DataGrid();
133                         s = g.PagerStyle;
134
135                         Assert.AreEqual (Color.Empty, s.BackColor, "D1");
136                         Assert.AreEqual (Color.Empty, s.BorderColor, "D2");
137                         Assert.AreEqual (BorderStyle.NotSet, s.BorderStyle, "D3");
138                         Assert.AreEqual (Unit.Empty, s.BorderWidth, "D4");
139                         Assert.AreEqual (string.Empty, s.CssClass, "D5");
140                         Assert.AreEqual (Color.Empty, s.ForeColor, "D6");
141                         Assert.AreEqual (Unit.Empty, s.Height, "D7");
142                         Assert.AreEqual (Unit.Empty, s.Width, "D8");
143
144                         Assert.AreEqual (PagerMode.NextPrev, s.Mode, "D9");
145                         Assert.AreEqual ("&gt;", s.NextPageText, "D10");
146                         Assert.AreEqual (10, s.PageButtonCount, "D11");
147                         Assert.AreEqual (PagerPosition.Bottom, s.Position, "D12");
148                         Assert.AreEqual ("&lt;", s.PrevPageText, "D13");
149                         Assert.AreEqual (true, s.Visible, "D14");
150                 }
151
152                 [Test]
153                 public void DataGridPagerStyle_Assignment () {
154                         DataGrid                g;
155                         DataGridPagerStyle      s;
156
157                         g = new DataGrid();
158                         s = g.PagerStyle;
159
160
161                         s.Mode = PagerMode.NumericPages;
162                         Assert.AreEqual (PagerMode.NumericPages, s.Mode, "A1");
163
164                         s.NextPageText = "Next";
165                         Assert.AreEqual ("Next", s.NextPageText, "A2");
166
167                         s.PageButtonCount = 20;
168                         Assert.AreEqual (20, s.PageButtonCount, "A3");
169
170                         s.Position = PagerPosition.TopAndBottom;
171                         Assert.AreEqual (PagerPosition.TopAndBottom, s.Position, "A4");
172
173                         s.PrevPageText = "Prev";
174                         Assert.AreEqual ("Prev", s.PrevPageText, "A5");
175
176                         s.Visible = false;
177                         Assert.AreEqual (false, s.Visible, "A6");
178                 }
179
180                 [Test]
181                 public void DataGridPagerStyle_Copy () {
182                         string[]                keyvalues;
183                         DataGrid                g;
184                         DataGrid                g2;
185                         DataGridPagerStyle      s;
186                         DataGridPagerStyle      copy;
187
188                         g = new DataGrid();
189                         g2 = new DataGrid();
190
191                         s = g.PagerStyle;
192                         copy = g2.PagerStyle;
193
194                         s.Mode = PagerMode.NumericPages;
195                         Assert.AreEqual (PagerMode.NumericPages, s.Mode, "C1");
196
197                         s.NextPageText = "Next";
198                         Assert.AreEqual ("Next", s.NextPageText, "C2");
199
200                         s.PageButtonCount = 20;
201                         Assert.AreEqual (20, s.PageButtonCount, "C3");
202
203                         s.Position = PagerPosition.TopAndBottom;
204                         Assert.AreEqual (PagerPosition.TopAndBottom, s.Position, "C4");
205
206                         s.PrevPageText = "Prev";
207                         Assert.AreEqual ("Prev", s.PrevPageText, "C5");
208
209                         s.Visible = false;
210                         Assert.AreEqual (false, s.Visible, "C6");
211
212                         // Now copy them over;
213                         copy.CopyFrom(s);
214                         Assert.AreEqual (PagerMode.NumericPages, copy.Mode, "C7");
215                         Assert.AreEqual ("Next", copy.NextPageText, "C8");
216                         Assert.AreEqual (20, copy.PageButtonCount, "C9");
217                         Assert.AreEqual (PagerPosition.TopAndBottom, copy.Position, "C10");
218                         Assert.AreEqual ("Prev", copy.PrevPageText, "C11");
219                         Assert.AreEqual (false, copy.Visible, "C12");
220                 }
221
222                 [Test]
223                 public void DataGridPagerStyle_Merge () {
224                         string[]                keyvalues;
225                         DataGrid                g;
226                         DataGrid                g2;
227                         DataGridPagerStyle      s;
228                         DataGridPagerStyle      copy;
229
230                         g = new DataGrid();
231                         g2 = new DataGrid();
232
233                         s = g.PagerStyle;
234                         copy = g2.PagerStyle;
235
236                         s.Mode = PagerMode.NumericPages;
237                         Assert.AreEqual (PagerMode.NumericPages, s.Mode, "M1");
238
239                         s.NextPageText = "Next";
240                         Assert.AreEqual ("Next", s.NextPageText, "M2");
241
242                         s.PageButtonCount = 20;
243                         Assert.AreEqual (20, s.PageButtonCount, "M3");
244
245                         copy.Position = PagerPosition.Top;
246                         s.Position = PagerPosition.TopAndBottom;
247                         Assert.AreEqual (PagerPosition.TopAndBottom, s.Position, "M4");
248
249                         copy.PrevPageText = "Blah";
250                         s.PrevPageText = "Prev";
251                         Assert.AreEqual ("Prev", s.PrevPageText, "M5");
252
253                         copy.Visible = true;
254                         s.Visible = false;
255                         Assert.AreEqual (false, s.Visible, "M6");
256
257                         // Now merge
258                         copy.MergeWith(s);
259
260                         Assert.AreEqual (PagerMode.NumericPages, copy.Mode, "M7");
261                         Assert.AreEqual ("Next", copy.NextPageText, "M8");
262                         Assert.AreEqual (20, copy.PageButtonCount, "M9");
263                         Assert.AreEqual (PagerPosition.Top, copy.Position, "M10");
264                         Assert.AreEqual ("Blah", copy.PrevPageText, "M11");
265                         Assert.AreEqual (true, copy.Visible, "M12");
266                 }
267
268                 [Test]
269                 public void DataGridPagerStyle_Reset () {
270                         string[]                keyvalues;
271                         DataGrid                g;
272                         DataGridPagerStyle      s;
273
274                         g = new DataGrid();
275
276                         s = g.PagerStyle;
277
278                         s.Mode = PagerMode.NumericPages;
279                         Assert.AreEqual (PagerMode.NumericPages, s.Mode, "R1");
280
281                         s.NextPageText = "Next";
282                         Assert.AreEqual ("Next", s.NextPageText, "R2");
283
284                         s.PageButtonCount = 20;
285                         Assert.AreEqual (20, s.PageButtonCount, "R3");
286
287                         s.Position = PagerPosition.TopAndBottom;
288                         Assert.AreEqual (PagerPosition.TopAndBottom, s.Position, "R4");
289
290                         s.PrevPageText = "Prev";
291                         Assert.AreEqual ("Prev", s.PrevPageText, "R5");
292
293                         s.Visible = false;
294                         Assert.AreEqual (false, s.Visible, "R6");
295
296                         s.Reset();
297
298                         Assert.AreEqual (PagerMode.NextPrev, s.Mode, "D9");
299                         Assert.AreEqual ("&gt;", s.NextPageText, "D10");
300                         Assert.AreEqual (10, s.PageButtonCount, "D11");
301                         Assert.AreEqual (PagerPosition.Bottom, s.Position, "D12");
302                         Assert.AreEqual ("&lt;", s.PrevPageText, "D13");
303                         Assert.AreEqual (true, s.Visible, "D14");
304                 }
305
306                 [Test]
307                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
308                 public void PageButtonCount_Neg ()
309                 {
310                         DataGrid        d;
311
312                         d = new DataGrid();
313                         // bug 50236
314                         d.PagerStyle.PageButtonCount = -2;
315                 }
316
317                 [Test]
318                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
319                 public void PageButtonCount_Zero ()
320                 {
321                         DataGrid d;
322
323                         d = new DataGrid ();
324                         d.PagerStyle.PageButtonCount = 0;
325                 }
326         }
327 }