2 // Tests for System.Web.UI.Control
5 // Peter Dennis Bartok (pbartok@novell.com)
6 // Gonzalo Paniagua Javier (gonzalo@novell.com)
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using NUnit.Framework;
34 using System.Collections;
37 using System.Globalization;
40 using System.Web.UI.WebControls;
42 namespace MonoTests.System.Web.UI
45 public class ControlTest {
47 public void DataBindingInterfaceTest ()
50 DataBindingCollection db;
53 Assert.AreEqual (false, ((IDataBindingsAccessor)c).HasDataBindings, "DB1");
54 db = ((IDataBindingsAccessor)c).DataBindings;
55 Assert.IsNotNull (db, "DB2");
56 Assert.AreEqual (false, ((IDataBindingsAccessor)c).HasDataBindings, "DB3");
57 db.Add(new DataBinding ("property", typeof(bool), "expression"));
58 Assert.AreEqual (true, ((IDataBindingsAccessor)c).HasDataBindings);
62 class MyNC : Control, INamingContainer {
66 public void UniqueID1 ()
69 Control nc = new MyNC ();
70 Assert.IsNull (nc.UniqueID, "nulltest");
74 public void UniqueID2 ()
77 Control nc = new MyNC ();
78 Control nc2 = new MyNC ();
79 nc2.Controls.Add (nc);
80 Assert.IsNotNull (nc.UniqueID, "notnull");
81 Assert.IsTrue (nc.UniqueID.IndexOfAny (new char [] {':', '$' }) == -1, "separator");
85 public void UniqueID3 ()
88 Control control = new Control ();
89 Control nc = new MyNC ();
91 control.Controls.Add (nc);
92 Assert.IsNull (nc.UniqueID, "null");
96 public void UniqueID4 ()
99 Control control = new Control ();
100 Control nc = new MyNC ();
102 nc.Controls.Add (control);
103 Assert.IsNotNull (control.UniqueID, "notnull");
107 public void UniqueID5 ()
110 Control control = new Control ();
111 Control nc = new MyNC ();
112 Control nc2 = new MyNC ();
114 nc2.Controls.Add (nc);
115 nc.Controls.Add (control);
116 Assert.IsNotNull (control.UniqueID, "notnull");
117 Assert.IsNull (nc2.ID, "null-1");
118 Assert.IsNull (nc.ID, "null-2");
119 Assert.IsTrue (-1 != control.UniqueID.IndexOfAny (new char [] {':', '$' }), "separator");
122 class DerivedControl : Control {
123 ControlCollection coll;
125 public DerivedControl ()
127 coll = new ControlCollection (this);
130 public override ControlCollection Controls {
135 public bool DoIsViewStateEnabled {
136 get { return IsViewStateEnabled; }
141 // From bug #76919: Control uses _controls instead of
142 // Controls when RenderChildren is called.
144 public void Controls1 ()
146 DerivedControl derived = new DerivedControl ();
147 derived.Controls.Add (new LiteralControl ("hola"));
148 StringWriter sw = new StringWriter ();
149 HtmlTextWriter htw = new HtmlTextWriter (sw);
150 derived.RenderControl (htw);
151 string result = sw.ToString ();
153 Assert.AreEqual ("", result, "#01");
158 public void ApplyStyleSheetSkin ()
160 Page p = new Page ();
161 p.StyleSheetTheme = "";
162 Control c = new Control ();
163 c.ApplyStyleSheetSkin (p);
167 public void IsViewStateEnabled ()
169 DerivedControl c = new DerivedControl ();
170 Assert.IsFalse (c.DoIsViewStateEnabled);
171 Page p = new Page ();
174 Assert.IsTrue (c.DoIsViewStateEnabled);
175 p.EnableViewState = false;
176 Assert.IsFalse (c.DoIsViewStateEnabled);