2 // ContainerControl class testing unit
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using C
=System
.ComponentModel
;
31 using System
.Security
.Permissions
;
32 using System
.Windows
.Forms
;
33 using System
.Collections
;
34 using NUnit
.Framework
;
36 namespace MonoTests
.System
.Windows
.Forms
{
38 public class IContainerControlTest
: Control
, IContainerControl
{
40 public bool ActivateControl (Control active
)
45 public Control ActiveControl
{
51 public class FormCustom
: Form
{
55 public FormCustom(string name
, bool record
, Queue events
) {
61 protected override void OnValidating(C
.CancelEventArgs e
) {
63 events
.Enqueue(String
.Format("{0}:{1}:OnValidating", this, this.Name
));
64 base.OnValidating (e
);
67 protected override void OnValidated(EventArgs e
) {
69 events
.Enqueue(String
.Format("{0}:{1}:OnValidated", this, this.Name
));
73 protected override void OnGotFocus(EventArgs e
) {
75 events
.Enqueue(String
.Format("{0}:{1}:OnGotFocus", this, this.Name
));
81 public class ContainerControlCustom
: ContainerControl
{
85 public ContainerControlCustom(string name
, bool record
, Queue events
) {
91 protected override void OnValidating(C
.CancelEventArgs e
) {
93 events
.Enqueue(String
.Format("{0}:{1}:OnValidating", this, this.Name
));
94 base.OnValidating (e
);
97 protected override void OnValidated(EventArgs e
) {
99 events
.Enqueue(String
.Format("{0}:{1}:OnValidated", this, this.Name
));
100 base.OnValidated (e
);
103 protected override void OnGotFocus(EventArgs e
) {
105 events
.Enqueue(String
.Format("{0}:{1}:OnGotFocus", this, this.Name
));
109 protected override void Select(bool directed
, bool forward
) {
111 events
.Enqueue(String
.Format("{0}:{1}:Select", this, this.Name
));
112 base.Select (directed
, forward
);
116 public class UserControlCustom
: UserControl
{
120 public UserControlCustom(string name
, bool record
, Queue events
) {
122 this.record
= record
;
123 this.events
= events
;
125 protected override void OnValidating(C
.CancelEventArgs e
) {
127 events
.Enqueue(String
.Format("{0}:{1}:OnValidating", this, this.Name
));
128 base.OnValidating (e
);
131 protected override void OnValidated(EventArgs e
) {
133 events
.Enqueue(String
.Format("{0}:{1}:OnValidated", this, this.Name
));
134 base.OnValidated (e
);
137 protected override void OnGotFocus(EventArgs e
) {
139 events
.Enqueue(String
.Format("{0}:{1}:OnGotFocus", this, this.Name
));
143 protected override void Select(bool directed
, bool forward
) {
145 events
.Enqueue(String
.Format("{0}:{1}:Select", this, this.Name
));
146 base.Select (directed
, forward
);
151 [SecurityPermission (SecurityAction
.Deny
, UnmanagedCode
= true)]
152 public class ContainerControlTest
{
155 public void GetContainerControl ()
157 ContainerControl cc
= new ContainerControl ();
158 Assert
.IsTrue (Object
.ReferenceEquals (cc
, cc
.GetContainerControl ()), "ContainerControl.GetContainerControl");
160 Button b
= new Button ();
161 Assert
.IsNull (b
.GetContainerControl (), "Button.GetContainerControl/without parent");
163 Assert
.IsTrue (Object
.ReferenceEquals (cc
, b
.GetContainerControl ()), "Button.GetContainerControl");
167 public void GetContainerControl_WithoutStyle ()
169 IContainerControlTest cct
= new IContainerControlTest ();
170 Assert
.IsNull (cct
.GetContainerControl (), "IContainerControlTest.GetContainerControl");
172 Button b
= new Button ();
174 Assert
.IsNull (b
.GetContainerControl (), "Button.GetContainerControl/without parent");
178 [ExpectedException (typeof (ArgumentException
))]
179 public void ActiveControlNotChildTest ()
181 ContainerControl c
= new ContainerControl ();
182 c
.ActiveControl
= new Control ();
186 public void Validation() {
187 Queue events
= new Queue();
189 FormCustom form
= new FormCustom("form1", true, events
);
190 ContainerControlCustom container1
= new ContainerControlCustom("container1", true, events
);
191 ContainerControlCustom container2
= new ContainerControlCustom("container2", true, events
);
192 ContainerControlCustom container3
= new ContainerControlCustom("container3", true, events
);
193 UserControlCustom userctl1
= new UserControlCustom("userctl1", true, events
);
194 UserControlCustom userctl2
= new UserControlCustom("userctl2", true, events
);
195 UserControlCustom userctl3
= new UserControlCustom("userctl3", true, events
);
197 container2
.Controls
.Add(userctl2
);
198 container2
.Controls
.Add(userctl3
);
199 container1
.Controls
.Add(userctl1
);
200 form
.Controls
.Add(container1
);
201 form
.Controls
.Add(container2
);
202 form
.Controls
.Add(container3
);
208 events
.Enqueue("START");
210 events
.Enqueue("END");
211 events
.Enqueue("START");
213 events
.Enqueue("END");
214 events
.Enqueue("START");
216 events
.Enqueue("END");
217 events
.Enqueue("START");
219 events
.Enqueue("END");
220 events
.Enqueue("START");
222 events
.Enqueue("END");
223 events
.Enqueue("START");
225 events
.Enqueue("END");
228 while (events
.Count
> 0) {
229 s
= events
.Dequeue();
230 Console
.WriteLine(s
.ToString());
239 container1
.Dispose();
240 container1
.Dispose();