New test.
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / TextBoxTest.cs
1 //
2 // Tests for System.Web.UI.WebControls.TextBox.cs 
3 //
4 // Author:
5 //     Ben Maurer (bmaurer@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.IO;
34 using System.Globalization;
35 using System.Web;
36 using System.Web.UI;
37 using System.Web.UI.WebControls;
38
39 namespace MonoTests.System.Web.UI.WebControls {
40         
41         [TestFixture]   
42         public class TextBoxTest {
43                 class Poker : TextBox {
44                         public new void AddParsedSubObject (object o)
45                         {
46                                 base.AddParsedSubObject (o);
47                         }
48
49                         public void TrackState () 
50                         {
51                                 TrackViewState ();
52                         }
53                         
54                         public object SaveState ()
55                         {
56                                 foreach (string s in ViewState.Keys)
57                                         Console.WriteLine ("{0}: {1}", s, ViewState[s]);
58
59                                 return SaveViewState ();
60                         }
61                         
62                         public void LoadState (object o)
63                         {
64                                 LoadViewState (o);
65                         }
66                         
67                         public string Render ()
68                         {
69                                 StringWriter sw = new StringWriter ();
70                                 sw.NewLine = "\n";
71                                 HtmlTextWriter writer = new HtmlTextWriter (sw);
72                                 base.Render (writer);
73                                 return writer.InnerWriter.ToString ();
74                         }                       
75                 }
76
77                 [Test]
78         [Category ("NotWorking")]
79                 public void MultilineRenderEscape ()
80                 {
81                         Poker t = new Poker ();
82                         t.TextMode = TextBoxMode.MultiLine;
83                         t.Text = "</textarea>";
84 #if NET_2_0
85                         string exp = "<textarea rows=\"2\" cols=\"20\">&lt;/textarea&gt;</textarea>";
86 #else
87                         string exp = "<textarea name>&lt;/textarea&gt;</textarea>";
88 #endif
89
90                         Assert.AreEqual (exp, t.Render ());
91                 }
92
93
94 #if NET_2_0
95                 [Test]
96                 public void ValidationProperties ()
97                 {
98                         Poker t = new Poker ();
99
100                         // initial values
101                         Assert.AreEqual (false, t.CausesValidation, "A1");
102                         Assert.AreEqual ("", t.ValidationGroup, "A2");
103
104                         t.ValidationGroup = "VG";
105                         Assert.AreEqual ("VG", t.ValidationGroup, "A3");
106
107                         t.CausesValidation = true;
108                         Assert.IsTrue (t.CausesValidation, "A4");
109                 }
110
111                 [Test]
112                 public void ViewState ()
113                 {
114                         Poker t = new Poker ();
115
116                         t.TrackState();
117
118                         t.ValidationGroup = "VG";
119                         t.CausesValidation = true;
120
121                         object s = t.SaveState ();
122                         Console.WriteLine ("state = {0}", s == null ? "null" : "not-null");
123
124                         Poker copy = new Poker ();
125
126                         copy.LoadState (s);
127
128                         Assert.AreEqual ("VG", copy.ValidationGroup, "A1");
129                         Assert.IsTrue (copy.CausesValidation, "A2");
130                 }
131
132                 [Test]
133         [Category ("NotWorking")]
134                 public void ValidationRender ()
135                 {
136                         /* test to show that the validation settings
137                          * have no effect on downlevel rendering */
138                         Poker t = new Poker ();
139
140                         t.TrackState();
141
142                         t.ValidationGroup = "VG";
143                         t.CausesValidation = true;
144                         t.TextMode = TextBoxMode.MultiLine;
145
146                         string exp = "<textarea rows=\"2\" cols=\"20\"></textarea>";
147                         Assert.AreEqual (exp, t.Render ());
148                 }
149 #endif
150         }
151 }
152