Things happen a little differently when control is created.
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / PictureBoxTest.cs
1 //
2 // PictureBoxTest.cs: Test cases for PictureBox.
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.Windows.Forms;
12 using System.Drawing;
13 using System.Reflection;
14 using NUnit.Framework;
15 using System.Threading;
16
17 namespace MonoTests.System.Windows.Forms
18 {
19         [TestFixture]
20         public class PictureBoxTest
21         {
22                 [Test]
23                 public void PictureBoxPropertyTest ()
24                 {
25                         Form myForm = new Form ();
26                         PictureBox myPicBox = new PictureBox ();
27                         myForm.Controls.Add (myPicBox);
28                         
29                         // B 
30                         Assert.AreEqual (BorderStyle.None, myPicBox.BorderStyle, "#B1");
31                         myPicBox.BorderStyle = BorderStyle.Fixed3D;
32                         Assert.AreEqual (BorderStyle.Fixed3D, myPicBox.BorderStyle, "#B2");
33
34                         // I 
35                         Assert.AreEqual (null, myPicBox.Image, "#I1");
36                         Image myImage = Image.FromFile("M.gif");
37                         myPicBox.Image = myImage;
38                         Assert.AreEqual (60, myPicBox.Image.Height, "#I2");
39                         Assert.AreEqual (150, myPicBox.Image.Width, "#I3");
40                         
41                         // P 
42                         Assert.AreEqual (PictureBoxSizeMode.Normal, myPicBox.SizeMode, "#P1");
43                         myPicBox.SizeMode = PictureBoxSizeMode.AutoSize;
44                         Assert.AreEqual (PictureBoxSizeMode.AutoSize, myPicBox.SizeMode, "#P2");
45                 }
46                         
47                 
48                 [Test, Ignore ("This seems to fail.")]
49                 public void ToStringMethodTest () 
50                 {
51                         PictureBox myPicBox = new PictureBox ();
52                         Assert.AreEqual ("System.Windows.Forms.PictureBox, SizeMode: Normal", myPicBox.ToString (), "#T1");
53                 }
54                 
55                 [TestFixture]
56                 public class PictureBoxSizeModeEventClass
57                 {
58                         static bool eventhandled = false;
59                         public static void SizeMode_EventHandler (object sender, EventArgs e)
60                         {
61                                 eventhandled = true;
62                         }
63
64                         [Test]
65                         public void PictureBoxEvenTest ()
66                         {
67                                 Form myForm = new Form ();
68                                 PictureBox myPicBox = new PictureBox ();
69                                 myForm.Controls.Add (myPicBox);
70                                 myPicBox.SizeModeChanged += new EventHandler (SizeMode_EventHandler);
71                                 myPicBox.SizeMode = PictureBoxSizeMode.AutoSize;                                
72                                 Assert.AreEqual (true, eventhandled, "#SM1");
73                                 eventhandled = false;
74                                 myPicBox.SizeMode = PictureBoxSizeMode.CenterImage;
75                                 Assert.AreEqual (true, eventhandled, "#SM2");
76                                 eventhandled = false;
77                                 myPicBox.SizeMode = PictureBoxSizeMode.StretchImage;
78                                 Assert.AreEqual (true, eventhandled, "#SM3");   
79                         }
80                 }
81         }
82 }