2 // Tests for System.Web.UI.WebControls.Label.cs
5 // Miguel de Icaza (miguel@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 LabelTest {
45 public new void AddParsedSubObject (object o)
47 base.AddParsedSubObject (o);
50 public void TrackState ()
55 public object SaveState ()
57 return SaveViewState ();
60 public void LoadState (object o)
65 public string Render ()
67 StringWriter sw = new StringWriter ();
69 HtmlTextWriter writer = new HtmlTextWriter (sw);
71 return writer.InnerWriter.ToString ();
76 public void Label_ViewState ()
78 Poker p = new Poker ();
81 Assert.AreEqual (p.Text, "", "A1");
83 Assert.AreEqual (p.Text, "Hello", "A2");
85 object state = p.SaveState ();
87 Poker copy = new Poker ();
89 copy.LoadState (state);
90 Assert.AreEqual (copy.Text, "Hello", "A3");
94 public void Label_Render ()
96 Poker l = new Poker ();
98 Assert.AreEqual ("<span>Hello</span>", l.Render (), "R1");
103 Poker p = new Poker ();
104 Label ll = new Label ();
106 p.AddParsedSubObject (new LiteralControl ("Hello"));
107 p.AddParsedSubObject (ll);
113 public void ChildControl ()
115 Poker l = MakeNested ();
116 Assert.AreEqual ("<span>Hello<span>, World</span></span>", l.Render ());
117 Assert.AreEqual ("", l.Text);
119 Assert.AreEqual ("<span>Hello</span>", l.Render ());
120 Assert.AreEqual ("Hello", l.Text);
121 Assert.IsFalse (l.HasControls ());
125 public void ChildControlViewstate ()
127 Poker l = MakeNested ();
131 object o = l.SaveState ();
136 Assert.AreEqual ("<span>Hello</span>", l.Render ());
137 Assert.AreEqual ("Hello", l.Text);
138 Assert.IsFalse (l.HasControls ());
142 public void AssocControlId ()
144 Page p = new Page ();
145 Poker l = new Poker ();
146 TextBox t = new TextBox ();
153 l.AssociatedControlID = "mytxtbox";
154 Assert.AreEqual (@"<label for=""mytxtbox"">Hello</label>", l.Render ());