2 // Tests for System.Web.UI.WebControls.TextBox.cs
5 // Ben Maurer (bmaurer@novell.com)
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
31 using NUnit.Framework;
34 using System.Globalization;
37 using System.Web.UI.WebControls;
39 namespace MonoTests.System.Web.UI.WebControls {
42 public class TextBoxTest {
43 class Poker : TextBox {
44 public new void AddParsedSubObject (object o)
46 base.AddParsedSubObject (o);
49 public void TrackState ()
54 public object SaveState ()
56 foreach (string s in ViewState.Keys)
57 Console.WriteLine ("{0}: {1}", s, ViewState[s]);
59 return SaveViewState ();
62 public void LoadState (object o)
67 public string Render ()
69 StringWriter sw = new StringWriter ();
71 HtmlTextWriter writer = new HtmlTextWriter (sw);
73 return writer.InnerWriter.ToString ();
78 public void MultilineRenderEscape ()
80 Poker t = new Poker ();
81 t.TextMode = TextBoxMode.MultiLine;
82 t.Text = "</textarea>";
84 string exp = "<textarea rows=\"2\" cols=\"20\"></textarea></textarea>";
86 string exp = "<textarea name></textarea></textarea>";
89 Assert.AreEqual (exp, t.Render ());
95 public void ValidationProperties ()
97 Poker t = new Poker ();
100 Assert.AreEqual (false, t.CausesValidation, "A1");
101 Assert.AreEqual ("", t.ValidationGroup, "A2");
103 t.ValidationGroup = "VG";
104 Assert.AreEqual ("VG", t.ValidationGroup, "A3");
106 t.CausesValidation = true;
107 Assert.IsTrue (t.CausesValidation, "A4");
111 public void ViewState ()
113 Poker t = new Poker ();
117 t.ValidationGroup = "VG";
118 t.CausesValidation = true;
120 object s = t.SaveState ();
121 Console.WriteLine ("state = {0}", s == null ? "null" : "not-null");
123 Poker copy = new Poker ();
127 Assert.AreEqual ("VG", copy.ValidationGroup, "A1");
128 Assert.IsTrue (copy.CausesValidation, "A2");
132 public void ValidationRender ()
134 /* test to show that the validation settings
135 * have no effect on downlevel rendering */
136 Poker t = new Poker ();
140 t.ValidationGroup = "VG";
141 t.CausesValidation = true;
142 t.TextMode = TextBoxMode.MultiLine;
144 string exp = "<textarea rows=\"2\" cols=\"20\"></textarea>";
145 Assert.AreEqual (exp, t.Render ());