* FormTest.cs: Improved test for bug #80604.
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / FormTest.cs
1 //
2 // FormTest.cs: Test cases for Form.
3 //
4 // Author:
5 //   Ritvik Mayank (mritvik@novell.com)
6 //
7 // (C) 2005 Novell, Inc. (http://www.novell.com)
8 //
9
10 using System;
11 using System.ComponentModel;
12 using System.Drawing;
13 using System.Reflection;
14 using System.Windows.Forms;
15
16 using NUnit.Framework;
17
18 namespace MonoTests.System.Windows.Forms
19 {
20         [TestFixture]
21         public class FormTest
22         {
23                 [Test]
24                 public void FormPropertyTest ()
25                 {
26                         Form myform = new Form ();
27                         myform.Visible = true;
28                         myform.Text = "NewForm";
29                         myform.Name = "FormTest";
30                         Assert.IsNull (myform.AcceptButton, "#1");
31                         Assert.IsNull (myform.ActiveMdiChild, "#2"); 
32                         Assert.IsFalse (myform.AutoScale, "#3");
33                         Assert.IsNull (myform.CancelButton, "#6");
34                         Assert.IsTrue (myform.ControlBox, "#9");
35                         Assert.IsTrue (myform.DesktopBounds.X > 0, "#10a");
36                         Assert.IsTrue (myform.DesktopBounds.Y > 0, "#10b");
37                         Assert.AreEqual (300, myform.DesktopBounds.Height, "#10c");
38                         Assert.AreEqual (300, myform.DesktopBounds.Width, "#10d");
39                         Assert.IsTrue (myform.DesktopLocation.X > 0, "#11a");
40                         Assert.IsTrue (myform.DesktopLocation.Y > 0, "#11b");
41                         Assert.AreEqual (DialogResult.None, myform.DialogResult, "#12");
42                         Assert.AreEqual (FormBorderStyle.Sizable, myform.FormBorderStyle, "#13");
43                         Assert.IsFalse (myform.HelpButton, "#14");
44                         Assert.AreEqual ("System.Drawing.Icon", myform.Icon.GetType ().ToString (), "#15");
45                         Assert.IsFalse (myform.IsMdiChild, "#16");
46                         Assert.IsFalse (myform.IsMdiContainer, "#17");
47                         Assert.IsFalse (myform.KeyPreview, "#18");
48                         Assert.IsTrue (myform.MaximizeBox, "#19");
49                         Assert.AreEqual (0, myform.MaximumSize.Height, "#20a");
50                         Assert.AreEqual (0, myform.MaximumSize.Width, "#20b");
51                         Assert.AreEqual (0, myform.MdiChildren.Length, "#21a");
52                         Assert.AreEqual (1, myform.MdiChildren.Rank, "#21b");
53                         Assert.IsFalse (myform.MdiChildren.IsSynchronized, "#21c");
54                         Assert.IsNull (myform.MdiParent, "#22");
55                         Assert.IsNull (myform.Menu, "#23");
56                         Assert.IsNull (myform.MergedMenu, "#24");
57                         Assert.IsTrue (myform.MinimizeBox, "#25");
58                         Assert.AreEqual (0, myform.MinimumSize.Height, "#26a");
59                         Assert.AreEqual (0, myform.MinimumSize.Width, "#26b");
60                         Assert.IsTrue (myform.MinimumSize.IsEmpty, "#26c");
61                         Assert.IsFalse (myform.Modal, "#27");
62                         Assert.AreEqual (1, myform.Opacity, "#28");
63                         Assert.AreEqual (0, myform.OwnedForms.Length, "#29a");
64                         Assert.AreEqual (1, myform.OwnedForms.Rank, "#29b");
65                         Assert.IsNull (myform.Owner, "#30");
66                         Assert.IsTrue (myform.ShowInTaskbar, "#31");
67                         Assert.AreEqual (300, myform.Size.Height, "#32a");
68                         Assert.AreEqual (300, myform.Size.Width, "#32b");
69                         Assert.AreEqual (SizeGripStyle.Auto, myform.SizeGripStyle, "#33");
70                         Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, myform.StartPosition, "#34");
71                         Assert.IsTrue (myform.TopLevel, "#35");
72                         Assert.IsFalse (myform.TopMost, "#36");
73                         Assert.AreEqual (Color.Empty, myform.TransparencyKey, "#37");
74                         Assert.AreEqual (FormWindowState.Normal, myform.WindowState, "#38");
75                         Assert.AreEqual (ImeMode.NoControl, myform.ImeMode, "#39");
76                         myform.Dispose ();
77                 }
78
79                 [Test]
80                 [NUnit.Framework.Category ("NotWorking")]
81                 public void ActivateTest ()
82                 {
83                         Form myform = new Form ();
84                         myform.ShowInTaskbar = false;
85                         myform.Visible = true;
86                         myform.Text = "NewForm";
87                         myform.Name = "FormTest";
88                         myform.Activate ();
89                         Assert.AreEqual (true, myform.Focus (), "#40");
90                         myform.Dispose ();
91                 }
92
93                 [Test]
94                 public void AddOwnedFormTest ()
95                 {
96                         Form parent = new Form ();
97                         parent.ShowInTaskbar = false;
98                         parent.Text = "NewParent";
99                         Form ownedForm = new Form ();
100                         ownedForm.ShowInTaskbar = false;
101                         ownedForm.Text = "Owned Form";
102                         parent.AddOwnedForm (ownedForm);
103                         ownedForm.Show ();
104                         Assert.AreEqual ("NewParent", ownedForm.Owner.Text, "#41");
105                         ownedForm.Dispose ();
106                         parent.Dispose ();
107                 }
108
109                 [Test] // bug #80020
110                 [NUnit.Framework.Category ("NotWorking")]
111                 public void IsHandleCreated ()
112                 {
113                         Form main = new Form ();
114                         main.Name = "main";
115                         main.IsMdiContainer = true;
116                         main.ShowInTaskbar = false;
117                         Assert.IsFalse (main.IsHandleCreated, "#1");
118
119                         Form child = new Form ();
120                         child.MdiParent = main;
121                         child.WindowState = FormWindowState.Maximized;
122                         Assert.IsFalse (main.IsHandleCreated, "#2");
123
124                         child.Show ();
125                         Assert.IsFalse (child.IsHandleCreated, "#3");
126                         Assert.IsFalse (main.IsHandleCreated, "#4");
127
128                         main.Show ();
129                         Assert.IsTrue (child.IsHandleCreated, "#5");
130                         Assert.IsTrue (main.IsHandleCreated, "#6");
131
132                         child.Dispose ();
133                         main.Dispose ();
134                 }
135
136                 [Test]
137                 public void RemoveOwnedFormTest ()
138                 {
139                         Form myform = new Form ();
140                         myform.ShowInTaskbar = false;
141                         myform.Text = "NewForm";
142                         myform.Name = "FormTest";
143                         myform.RemoveOwnedForm (myform);
144                         myform.Show ();
145                         Assert.AreEqual (null, myform.Owner, "#44");
146                         myform.Dispose ();
147                 }
148
149                 [Test]
150                 public void SetDesktopBoundsTest ()
151                 {
152                         Form myform = new Form ();
153                         myform.ShowInTaskbar = false;
154                         myform.Visible = true;
155                         myform.Text = "NewForm";
156                         myform.Name = "FormTest";
157                         myform.SetDesktopBounds (10, 10, 200 , 200);
158                         Assert.AreEqual (200, myform.DesktopBounds.Height, "#45");
159                         myform.Dispose ();
160                 }
161
162                 [Test]
163                 public void SetDesktopLocationTest ()
164                 {
165                         Form myform = new Form ();
166                         myform.ShowInTaskbar = false;
167                         myform.Visible = true;
168                         myform.Text = "NewForm";
169                         myform.Name = "FormTest";
170                         myform.SetDesktopLocation (10, 10);
171                         Assert.AreEqual (10, myform.DesktopLocation.X, "#46");
172                         myform.Dispose ();
173                 }
174
175                 [Test]
176                 public void SetDialogResultOutOfRange ()
177                 {
178                         Form myform = new Form ();
179                         myform.ShowInTaskbar = false;
180                         try {
181                                 myform.DialogResult = (DialogResult) (-1);
182                                 Assert.Fail ("#48");
183                         } catch (InvalidEnumArgumentException) {
184                         }
185
186                         try {
187                                 myform.DialogResult = (DialogResult) ((int) DialogResult.No + 1);
188                                 Assert.Fail ("#49");
189                         } catch (InvalidEnumArgumentException) {
190                         }
191                         myform.Dispose ();
192                 }
193
194                 void myform_set_dialogresult (object sender, EventArgs e)
195                 {
196                         Form f = (Form)sender;
197
198                         f.DialogResult = DialogResult.OK;
199                 }
200
201                 void myform_close (object sender, EventArgs e)
202                 {
203                         Form f = (Form)sender;
204
205                         f.Close();
206                 }
207
208                 [Test]
209                 public void SetDialogResult ()
210                 {
211                         Form myform = new Form ();
212                         myform.ShowInTaskbar = false;
213                         myform.Visible = true;
214
215                         myform.DialogResult = DialogResult.Cancel;
216
217                         Assert.IsTrue (myform.Visible, "A1");
218                         Assert.IsFalse (myform.IsDisposed, "A2");
219
220                         myform.Close ();
221
222                         Assert.IsFalse (myform.Visible, "A3");
223                         Assert.IsTrue (myform.IsDisposed, "A4");
224
225                         DialogResult result;
226
227                         myform = new Form ();
228                         myform.ShowInTaskbar = false;
229                         myform.VisibleChanged += new EventHandler (myform_set_dialogresult);
230                         result = myform.ShowDialog ();
231
232                         Assert.AreEqual (result, DialogResult.OK, "A5");
233                         Assert.IsFalse (myform.Visible, "A6");
234                         Assert.IsFalse (myform.IsDisposed, "A7");
235
236                         myform = new Form ();
237                         myform.ShowInTaskbar = false;
238                         myform.VisibleChanged += new EventHandler (myform_close);
239                         result = myform.ShowDialog ();
240
241                         Assert.AreEqual (result, DialogResult.Cancel, "A8");
242                         Assert.IsFalse (myform.Visible, "A9");
243                         Assert.IsFalse (myform.IsDisposed, "A10");
244                 }
245
246                 [Test] // bug #80604
247                 [NUnit.Framework.Category ("NotWorking")]
248                 public void VisibleOnLoad ()
249                 {
250                         MockForm form = new MockForm ();
251                         form.CloseOnLoad = true;
252                         Application.Run (form);
253                         Assert.IsTrue (form.VisibleOnLoad, "#1");
254                         form.Dispose ();
255
256                         form = new MockForm ();
257                         form.ShowInTaskbar = false;
258                         form.Show ();
259                         Assert.IsTrue (form.VisibleOnLoad, "#2");
260                         form.Dispose ();
261                 }
262
263                 [Test] // bug #80052
264                 [NUnit.Framework.Category ("NotWorking")]
265                 public void Location ()
266                 {
267                         // 
268                         // CenterParent
269                         // 
270
271                         Form formA = new Form ();
272                         formA.ShowInTaskbar = false;
273                         formA.StartPosition = FormStartPosition.CenterParent;
274                         formA.Location = new Point (151, 251);
275                         formA.Show ();
276
277                         Assert.AreEqual (FormStartPosition.CenterParent, formA.StartPosition, "#A1");
278                         Assert.IsFalse (formA.Location.X == 151, "#A2");
279                         Assert.IsFalse (formA.Location.Y == 251, "#A3");
280
281                         formA.Location = new Point (311, 221);
282
283                         Assert.AreEqual (FormStartPosition.CenterParent, formA.StartPosition, "#A4");
284                         Assert.AreEqual (311, formA.Location.X, "#A5");
285                         Assert.AreEqual (221, formA.Location.Y, "#A6");
286
287                         formA.Dispose ();
288
289                         // 
290                         // CenterScreen
291                         // 
292
293                         Form formB = new Form ();
294                         formB.ShowInTaskbar = false;
295                         formB.StartPosition = FormStartPosition.CenterScreen;
296                         formB.Location = new Point (151, 251);
297                         formB.Show ();
298
299                         Assert.AreEqual (FormStartPosition.CenterScreen, formB.StartPosition, "#B1");
300                         Assert.IsFalse (formB.Location.X == 151, "#B2");
301                         Assert.IsFalse (formB.Location.Y == 251, "#B3");
302
303                         formB.Location = new Point (311, 221);
304
305                         Assert.AreEqual (FormStartPosition.CenterScreen, formB.StartPosition, "#B4");
306                         Assert.AreEqual (311, formB.Location.X, "#B5");
307                         Assert.AreEqual (221, formB.Location.Y, "#B6");
308
309                         formB.Dispose ();
310
311                         // 
312                         // Manual
313                         // 
314
315                         Form formC = new Form ();
316                         formC.ShowInTaskbar = false;
317                         formC.StartPosition = FormStartPosition.Manual;
318                         formC.Location = new Point (151, 251);
319                         formC.Show ();
320
321                         Assert.AreEqual (FormStartPosition.Manual, formC.StartPosition, "#C1");
322                         Assert.AreEqual (151, formC.Location.X, "#C2");
323                         Assert.AreEqual (251, formC.Location.Y, "#C3");
324
325                         formC.Location = new Point (311, 221);
326
327                         Assert.AreEqual (FormStartPosition.Manual, formC.StartPosition, "#C4");
328                         Assert.AreEqual (311, formC.Location.X, "#C5");
329                         Assert.AreEqual (221, formC.Location.Y, "#C6");
330
331                         formC.Dispose ();
332
333                         // 
334                         // WindowsDefaultBounds
335                         // 
336
337                         Form formD = new Form ();
338                         formD.ShowInTaskbar = false;
339                         formD.StartPosition = FormStartPosition.WindowsDefaultBounds;
340                         formD.Location = new Point (151, 251);
341                         formD.Show ();
342
343                         Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, formD.StartPosition, "#D1");
344                         Assert.IsFalse (formD.Location.X == 151, "#D2");
345                         Assert.IsFalse (formD.Location.Y == 251, "#D3");
346
347                         formD.Location = new Point (311, 221);
348
349                         Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, formD.StartPosition, "#D4");
350                         Assert.AreEqual (311, formD.Location.X, "#D5");
351                         Assert.AreEqual (221, formD.Location.Y, "#D6");
352
353                         formD.Dispose ();
354
355                         // 
356                         // WindowsDefaultLocation
357                         // 
358
359                         Form formE = new Form ();
360                         formE.ShowInTaskbar = false;
361                         formE.Location = new Point (151, 251);
362                         formE.Show ();
363
364                         Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, formE.StartPosition, "#E1");
365                         Assert.IsFalse (formE.Location.X == 151, "#E2");
366                         Assert.IsFalse (formE.Location.Y == 251, "#E3");
367
368                         formE.Location = new Point (311, 221);
369
370                         Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, formE.StartPosition, "#E4");
371                         Assert.AreEqual (311, formE.Location.X, "#E5");
372                         Assert.AreEqual (221, formE.Location.Y, "#E6");
373
374                         formE.Dispose ();
375                 }
376
377                 [Test]
378                 public void DisposeOwnerTest ()
379                 {
380                         Form f1 = new Form ();
381                         Form f2 = new Form ();
382
383                         f2.Owner = f1;
384
385                         f1.Dispose ();
386
387                         Assert.IsNull (f2.Owner, "1");
388                         Assert.AreEqual (0, f1.OwnedForms.Length, "2");
389                 }
390
391                 [Test]
392                 [ExpectedException (typeof (ObjectDisposedException))]
393                 public void AccessDisposedForm ()
394                 {
395                         Form myform = new Form ();
396                         myform.ShowInTaskbar = false;
397
398                         myform.Show ();
399                         myform.Close (); // this should result in the form being disposed
400                         myform.Show (); // and this line should result in the ODE being thrown
401                 }
402
403                 class MyForm : Form
404                 {
405                         public void DoDestroyHandle ()
406                         {
407                                 DestroyHandle();
408                         }
409                         public void DoRecreateHandle ()
410                         {
411                                 RecreateHandle();
412                         }
413                 }
414
415                 int handle_destroyed_count;
416                 void handle_destroyed (object sender, EventArgs e)
417                 {
418                         handle_destroyed_count++;
419                 }
420
421                 [Test]
422                 public void DestroyHandleTest ()
423                 {
424                         handle_destroyed_count = 0;
425
426                         MyForm f1 = new MyForm ();
427                         f1.HandleDestroyed += new EventHandler (handle_destroyed);
428                         f1.Show ();
429                         f1.DoDestroyHandle ();
430                         Assert.AreEqual (1, handle_destroyed_count, "1");
431
432                         f1 = new MyForm ();
433                         f1.HandleDestroyed += new EventHandler (handle_destroyed);
434                         f1.Show ();
435                         f1.DoRecreateHandle ();
436                         Assert.AreEqual (2, handle_destroyed_count, "2");
437                 }
438
439                 [Test]
440                 public void FormClose ()
441                 {
442                         Form myform = new Form ();
443                         myform.ShowInTaskbar = false;
444
445                         Assert.IsFalse (myform.Visible, "A1");
446                         Assert.IsFalse (myform.IsDisposed, "A2");
447
448                         myform.Close ();
449
450                         Assert.IsFalse (myform.Visible, "A3");
451                         Assert.IsFalse (myform.IsDisposed, "A4");
452
453                         myform.Show ();
454
455                         Assert.IsTrue (myform.Visible, "A5");
456                         Assert.IsFalse (myform.IsDisposed, "A6");
457
458                         myform.Close ();
459
460                         Assert.IsFalse (myform.Visible, "A7");
461                         Assert.IsTrue (myform.IsDisposed, "A8");
462                 }
463
464                 [Test]
465                 public void FormClose2 ()
466                 {
467                         WMCloseWatcher f = new WMCloseWatcher ();
468                         f.ShowInTaskbar = false;
469
470                         f.close_count = 0;
471                         Assert.IsFalse (f.Visible, "A1");
472                         f.Close ();
473                         Assert.AreEqual (0, f.close_count, "A2");
474
475
476                         f.Show ();
477                         f.Close ();
478                         Assert.AreEqual (1, f.close_count, "A3");
479                 }
480
481                 class WMCloseWatcher : Form {
482                         public int close_count;
483
484                         protected override void WndProc (ref Message msg) {
485                                 if (msg.Msg == 0x0010 /* WM_CLOSE */) {
486                                         close_count ++;
487                                 }
488
489                                 base.WndProc (ref msg);
490                         }
491                 }
492
493                 class SwallowOnActivated : Form {
494                         protected override void OnActivated (EventArgs e)
495                         {
496                                 // do nothing
497                         }
498
499                         protected override void OnCreateControl () {
500                                 base.OnCreateControl ();
501                         }
502                 }
503
504                 class EnterTest : Button {
505                         protected override void OnEnter (EventArgs e)
506                         {
507                                 on_enter = true;
508                                 base.OnEnter (e);
509                         }
510
511                         public bool on_enter;
512                 }
513
514                 [Test]
515                 public void OnActivateEventHandlingTest1 ()
516                 {
517                         if (RunningOnUnix) {
518                                 Assert.Ignore ("Relies on form.Show() synchronously generating WM_ACTIVATE");
519                         }
520
521                         SwallowOnActivated f = new SwallowOnActivated ();
522
523                         f.ShowInTaskbar = false;
524
525                         EnterTest c = new EnterTest ();
526                         f.Controls.Add (c);
527
528                         f.Show ();
529
530                         Assert.IsTrue (c.on_enter, "1");
531
532                         f.Dispose ();
533                 }
534                 
535 #if NET_2_0
536                 [Test]
537                 public void FormClosingEvents ()
538                 {
539                         // Standard Close
540                         Form f = new Form ();
541                         string events = string.Empty;
542
543                         f.Closing += new CancelEventHandler (delegate (Object obj, CancelEventArgs e) { events += ("Closing;"); });
544                         f.FormClosing += new FormClosingEventHandler (delegate (Object obj, FormClosingEventArgs e) { events += string.Format ("FormClosing [Reason:{0} - Cancel:{1}]", e.CloseReason, e.Cancel); });
545         
546                         f.Show ();
547                         f.Close ();
548                         
549                         Assert.AreEqual ("Closing;FormClosing [Reason:UserClosing - Cancel:False]", events, "A1");                      
550                 }
551
552                 [Test]
553                 public void FormClosingEventsCancel ()
554                 {
555                         // Shows that setting Cancel in Closing flows through to FormClosing
556                         Form f = new Form ();
557                         string events = string.Empty;
558
559                         f.Closing += new CancelEventHandler (delegate (Object obj, CancelEventArgs e) { events += ("Closing;"); e.Cancel = true; });
560                         f.FormClosing += new FormClosingEventHandler (delegate (Object obj, FormClosingEventArgs e) { events += string.Format("FormClosing [Reason:{0} - Cancel:{1}]", e.CloseReason, e.Cancel); e.Cancel = false; });
561
562                         f.Show ();
563                         f.Close ();
564
565                         Assert.AreEqual ("Closing;FormClosing [Reason:UserClosing - Cancel:True]", events, "A1");
566                 }
567
568                 [Test]
569                 public void FormClosedEvents ()
570                 {
571                         // Standard Closed
572                         Form f = new Form ();
573                         string events = string.Empty;
574
575                         f.Closed += new EventHandler (delegate (Object obj, EventArgs e) { events += ("Closed;"); });
576                         f.FormClosed += new FormClosedEventHandler (delegate (Object obj, FormClosedEventArgs e) { events += string.Format ("FormClosed [Reason:{0}]", e.CloseReason); });
577
578                         f.Show ();
579                         f.Close ();
580
581                         Assert.AreEqual ("Closed;FormClosed [Reason:UserClosing]", events, "A1");
582                 }
583
584                 [Test]
585                 public void ShowWithOwner ()
586                 {
587                         Form f = new Form ();
588                         Button b = new Button ();
589                         f.Controls.Add (b);
590
591                         Form f2 = new Form ();
592
593                         f2.Show (f);
594
595                         Assert.AreSame (f, f2.Owner, "A1");
596
597                         f2 = new Form ();
598
599                         f2.Show (b);
600                         Assert.AreSame (f, f2.Owner, "A2");
601
602                         Button b2 = new Button ();
603                         f2 = new Form ();
604
605                         f2.Show (b2);
606                         Assert.AreEqual (null, f2.Owner, "A3");
607
608                         f2 = new Form ();
609                         f2.Show (null);
610                         Assert.AreEqual (null, f2.Owner, "A4");
611                 }
612
613                 [Test]
614                 [ExpectedException (typeof (InvalidOperationException))]
615                 public void ShowWithOwnerIOE ()
616                 {
617                         Form f = new Form ();
618                         f.Show (f);
619                 }
620                 
621                 [Test]  // Bug #79959
622                 [NUnit.Framework.Category ("NotWorking")]
623                 public void BehaviorResizeOnBorderStyleChanged ()
624                 {
625                         // Marked NotWorking because the ClientSize is probably dependent on the WM.
626                         // The values below match .Net to make sure our behavior is the same.
627                         Form f = new Form ();
628                         f.Show ();
629
630                         Assert.AreEqual (new Size (300, 300), f.Size, "A1");
631                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A2");
632
633                         f.FormBorderStyle = FormBorderStyle.FixedSingle;
634                         Assert.AreEqual (new Size (298, 298), f.Size, "A3");
635                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A4");
636
637                         f.FormBorderStyle = FormBorderStyle.Sizable;
638                         Assert.AreEqual (new Size (300, 300), f.Size, "A5");
639                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A6");
640                         
641                         f.Close ();
642                 }
643                 
644                 [Test]  // bug #80574
645                 [NUnit.Framework.Category ("NotWorking")]
646                 public void BehaviorResizeOnBorderStyleChangedNotVisible ()
647                 {
648                         // Marked NotWorking because the ClientSize is probably dependent on the WM.
649                         // The values below match .Net to make sure our behavior is the same.
650                         Form f = new Form ();
651
652                         Assert.AreEqual (new Size (300, 300), f.Size, "A1");
653                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A2");
654
655                         f.FormBorderStyle = FormBorderStyle.Fixed3D;
656                         Assert.AreEqual (new Size (300, 300), f.Size, "A3");
657                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A4");
658
659                         f.FormBorderStyle = FormBorderStyle.FixedDialog;
660                         Assert.AreEqual (new Size (300, 300), f.Size, "A5");
661                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A6");
662
663                         f.FormBorderStyle = FormBorderStyle.FixedSingle;
664                         Assert.AreEqual (new Size (300, 300), f.Size, "A7");
665                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A8");
666
667                         f.FormBorderStyle = FormBorderStyle.FixedToolWindow;
668                         Assert.AreEqual (new Size (300, 300), f.Size, "A9");
669                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A0");
670
671                         f.FormBorderStyle = FormBorderStyle.None;
672                         Assert.AreEqual (new Size (300, 300), f.Size, "A11");
673                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A12");
674
675                         f.FormBorderStyle = FormBorderStyle.SizableToolWindow;
676                         Assert.AreEqual (new Size (300, 300), f.Size, "A13");
677                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A14");
678
679                         f.FormBorderStyle = FormBorderStyle.Sizable;
680                         Assert.AreEqual (new Size (300, 300), f.Size, "A15");
681                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A16");
682                 }
683 #endif
684
685                 private bool RunningOnUnix {
686                         get {
687                                 // check for Unix platforms - see FAQ for more details
688                                 // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
689                                 int platform = (int) Environment.OSVersion.Platform;
690                                 return ((platform == 4) || (platform == 128));
691                         }
692                 }
693
694                 private class MockForm : Form
695                 {
696                         public bool CloseOnLoad {
697                                 get { return _closeOnLoad; }
698                                 set { _closeOnLoad = value; }
699                         }
700
701                         public bool VisibleOnLoad {
702                                 get { return _visibleOnLoad; }
703                         }
704
705                         protected override void OnLoad(EventArgs e) {
706                                 base.OnLoad(e);
707                                 _visibleOnLoad = Visible;
708                                 if (CloseOnLoad)
709                                         Close ();
710                         }
711
712                         private bool _closeOnLoad;
713                         private bool _visibleOnLoad;
714                 }
715         }
716 }