New test.
[mono.git] / mcs / class / System.Web / Test / System.Web.UI / ControlTest.cs
1 //
2 // Tests for System.Web.UI.Control
3 //
4 // Author:
5 //      Peter Dennis Bartok (pbartok@novell.com)
6 //      Gonzalo Paniagua Javier (gonzalo@novell.com)
7 //
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9
10
11 //
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:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
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.
30 //
31
32 using NUnit.Framework;
33 using System;
34 using System.Collections;
35 using System.Drawing;
36 using System.IO;
37 using System.Globalization;
38 using System.Web;
39 using System.Web.UI;
40 using System.Web.UI.WebControls;
41
42 namespace MonoTests.System.Web.UI
43 {
44         [TestFixture]   
45         public class ControlTest {
46                 [Test]
47                 public void DataBindingInterfaceTest ()
48                 {
49                         Control c;
50                         DataBindingCollection db;
51
52                         c = new Control ();
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);
59
60                 }
61
62                 class MyNC : Control, INamingContainer {
63                 }
64
65                 [Test]
66                 public void UniqueID1 ()
67                 {
68                         // Standalone NC
69                         Control nc = new MyNC ();
70                         Assert.IsNull (nc.UniqueID, "nulltest");
71                 }
72
73                 [Test]
74                 public void UniqueID2 ()
75                 {
76                         // NC in NC
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");
82                 }
83
84                 [Test]
85                 public void UniqueID3 ()
86                 {
87                         // NC in control
88                         Control control = new Control ();
89                         Control nc = new MyNC ();
90
91                         control.Controls.Add (nc);
92                         Assert.IsNull (nc.UniqueID, "null");
93                 }
94
95                 [Test]
96                 public void UniqueID4 ()
97                 {
98                         // NC in control
99                         Control control = new Control ();
100                         Control nc = new MyNC ();
101
102                         nc.Controls.Add (control);
103                         Assert.IsNotNull (control.UniqueID, "notnull");
104                 }
105
106                 [Test]
107                 public void UniqueID5 ()
108                 {
109                         // NC in control
110                         Control control = new Control ();
111                         Control nc = new MyNC ();
112                         Control nc2 = new MyNC ();
113
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");
120                 }
121
122                 class DerivedControl : Control {
123                         ControlCollection coll;
124
125                         public DerivedControl ()
126                         {
127                                 coll = new ControlCollection (this);
128                         }
129
130                         public override ControlCollection Controls {
131                                 get { return coll; }
132                         }
133                         
134 #if NET_2_0
135                         public bool DoIsViewStateEnabled {
136                                 get { return IsViewStateEnabled; }
137                         }
138 #endif
139                 }
140
141                 // From bug #76919: Control uses _controls instead of
142                 // Controls when RenderChildren is called.
143                 [Test]
144                 public void Controls1 ()
145                 {
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 ();
152
153                         Assert.AreEqual ("", result, "#01");
154                 }
155
156 #if NET_2_0
157                 [Test]
158                 public void ApplyStyleSheetSkin ()
159                 {
160                         Page p = new Page ();
161                         p.StyleSheetTheme = "";
162                         Control c = new Control ();
163                         c.ApplyStyleSheetSkin (p);
164                 }
165                 
166                 [Test]
167                 public void IsViewStateEnabled ()
168                 {
169                         DerivedControl c = new DerivedControl ();
170                         Assert.IsFalse (c.DoIsViewStateEnabled);
171                         Page p = new Page ();
172                         c.Page = p;
173                         p.Controls.Add (c);
174                         Assert.IsTrue (c.DoIsViewStateEnabled);
175                         p.EnableViewState = false;
176                         Assert.IsFalse (c.DoIsViewStateEnabled);
177                 }
178 #endif
179         }
180 }
181