| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444 |
- //
- // PictureBoxTest.cs: Test cases for PictureBox.
- //
- // Author:
- // Ritvik Mayank ([email protected])
- //
- // (C) 2005 Novell, Inc. (http://www.novell.com)
- //
- using System;
- using System.Drawing;
- using System.IO;
- using System.Reflection;
- using System.Threading;
- using System.Windows.Forms;
- using NUnit.Framework;
- namespace MonoTests.System.Windows.Forms
- {
- [TestFixture]
- public class PictureBoxTest : TestHelper
- {
- [Test]
- public void PictureBoxPropertyTest ()
- {
- Form myForm = new Form ();
- myForm.ShowInTaskbar = false;
- PictureBox myPicBox = new PictureBox ();
- myForm.Controls.Add (myPicBox);
-
- // B
- Assert.AreEqual (BorderStyle.None, myPicBox.BorderStyle, "#B1");
- myPicBox.BorderStyle = BorderStyle.Fixed3D;
- Assert.AreEqual (BorderStyle.Fixed3D, myPicBox.BorderStyle, "#B2");
-
- // P
- Assert.AreEqual (PictureBoxSizeMode.Normal, myPicBox.SizeMode, "#P1");
- myPicBox.SizeMode = PictureBoxSizeMode.AutoSize;
- Assert.AreEqual (PictureBoxSizeMode.AutoSize, myPicBox.SizeMode, "#P2");
- myForm.Dispose ();
- }
- #if NET_2_0
- [Test]
- [Category ("NotWorking")]
- public void ImageLocation_Async ()
- {
- Form f = new Form ();
- PictureBox pb = new PictureBox ();
- f.Controls.Add (pb);
- f.Show ();
- Assert.IsNull (pb.ImageLocation, "#A");
- pb.ImageLocation = "M.gif";
- Application.DoEvents ();
- Assert.AreEqual ("M.gif", pb.ImageLocation, "#B1");
- Assert.AreSame (pb.InitialImage, pb.Image, "#B2");
- using (Stream s = this.GetType ().Assembly.GetManifestResourceStream ("32x32.ico")) {
- pb.Image = Image.FromStream (s);
- }
- Application.DoEvents ();
- Assert.AreEqual ("M.gif", pb.ImageLocation, "#C1");
- Assert.IsNotNull (pb.Image, "#C2");
- Assert.AreEqual (60, pb.Image.Height, "#C3");
- Assert.AreEqual (150, pb.Image.Width, "#C4");
- pb.ImageLocation = null;
- Application.DoEvents ();
- Assert.IsNull (pb.ImageLocation, "#D1");
- Assert.IsNull (pb.Image, "#D2");
- pb.ImageLocation = "M.gif";
- Application.DoEvents ();
- Assert.AreEqual ("M.gif", pb.ImageLocation, "#E1");
- Assert.IsNull (pb.Image, "#E2");
- pb.Load ();
- Application.DoEvents ();
- Assert.AreEqual ("M.gif", pb.ImageLocation, "#F1");
- Assert.IsNotNull (pb.Image, "#F2");
- Assert.AreEqual (60, pb.Image.Height, "#F3");
- Assert.AreEqual (150, pb.Image.Width, "#F4");
- pb.ImageLocation = null;
- Application.DoEvents ();
- Assert.IsNull (pb.ImageLocation, "#G1");
- Assert.IsNull (pb.Image, "#G2");
- pb.ImageLocation = "M.gif";
- pb.Load ();
- pb.ImageLocation = "XYZ.gif";
- Application.DoEvents ();
- Assert.AreEqual ("XYZ.gif", pb.ImageLocation, "#H1");
- Assert.IsNotNull (pb.Image, "#H2");
- Assert.AreEqual (60, pb.Image.Height, "#H3");
- Assert.AreEqual (150, pb.Image.Width, "#H4");
- pb.ImageLocation = string.Empty;
- Application.DoEvents ();
- Assert.AreEqual (string.Empty, pb.ImageLocation, "#I1");
- Assert.IsNull (pb.Image, "#I2");
- using (Stream s = this.GetType ().Assembly.GetManifestResourceStream ("32x32.ico")) {
- pb.Image = Image.FromStream (s);
- }
- Application.DoEvents ();
- Assert.AreEqual (string.Empty, pb.ImageLocation, "#J1");
- Assert.IsNotNull (pb.Image, "#J2");
- Assert.AreEqual (96, pb.Image.Height, "#J3");
- Assert.AreEqual (96, pb.Image.Width, "#J4");
- pb.Load ("M.gif");
- Application.DoEvents ();
- Assert.AreEqual ("M.gif", pb.ImageLocation, "#K1");
- Assert.IsNotNull (pb.Image, "#K2");
- Assert.AreEqual (60, pb.Image.Height, "#K3");
- Assert.AreEqual (150, pb.Image.Width, "#K4");
- pb.ImageLocation = null;
- Application.DoEvents ();
- Assert.IsNull (pb.ImageLocation, "#L1");
- Assert.IsNull (pb.Image, "#L2");
- f.Dispose ();
- }
- [Test]
- public void ImageLocation_Sync ()
- {
- Form f = new Form ();
- PictureBox pb = new PictureBox ();
- pb.WaitOnLoad = true;
- f.Controls.Add (pb);
- f.Show ();
- Assert.IsNull (pb.ImageLocation, "#A");
- pb.ImageLocation = "M.gif";
- Assert.AreEqual ("M.gif", pb.ImageLocation, "#B1");
- Assert.IsNotNull (pb.Image, "#B2");
- Assert.AreEqual (60, pb.Image.Height, "#B3");
- Assert.AreEqual (150, pb.Image.Width, "#B4");
- using (Stream s = this.GetType ().Assembly.GetManifestResourceStream ("32x32.ico")) {
- pb.Image = Image.FromStream (s);
- }
- Assert.AreEqual ("M.gif", pb.ImageLocation, "#C1");
- Assert.IsNotNull (pb.Image, "#C2");
- Assert.AreEqual (96, pb.Image.Height, "#C3");
- Assert.AreEqual (96, pb.Image.Width, "#C4");
- pb.ImageLocation = null;
- Assert.IsNull (pb.ImageLocation, "#D1");
- Assert.IsNotNull (pb.Image, "#D2");
- Assert.AreEqual (96, pb.Image.Height, "#D3");
- Assert.AreEqual (96, pb.Image.Width, "#D4");
- pb.ImageLocation = "M.gif";
- Assert.AreEqual ("M.gif", pb.ImageLocation, "#E1");
- Assert.IsNotNull (pb.Image, "#E2");
- Assert.AreEqual (60, pb.Image.Height, "#E3");
- Assert.AreEqual (150, pb.Image.Width, "#E4");
- pb.Load ();
- Assert.AreEqual ("M.gif", pb.ImageLocation, "#F1");
- Assert.IsNotNull (pb.Image, "#F2");
- Assert.AreEqual (60, pb.Image.Height, "#F3");
- Assert.AreEqual (150, pb.Image.Width, "#F4");
- pb.ImageLocation = null;
- Assert.IsNull (pb.ImageLocation, "#G1");
- Assert.IsNull (pb.Image, "#G2");
- using (Stream s = this.GetType ().Assembly.GetManifestResourceStream ("32x32.ico")) {
- pb.Image = Image.FromStream (s);
- }
- Assert.IsNull (pb.ImageLocation, "#H1");
- Assert.IsNotNull (pb.Image, "#H2");
- Assert.AreEqual (96, pb.Image.Height, "#H3");
- Assert.AreEqual (96, pb.Image.Width, "#H4");
- pb.Load ("M.gif");
- Assert.AreEqual ("M.gif", pb.ImageLocation, "#I1");
- Assert.IsNotNull (pb.Image, "#I2");
- Assert.AreEqual (60, pb.Image.Height, "#I3");
- Assert.AreEqual (150, pb.Image.Width, "#I4");
- pb.ImageLocation = string.Empty;
- Assert.AreEqual (string.Empty, pb.ImageLocation, "#J1");
- Assert.IsNull (pb.Image, "#J2");
- pb.ImageLocation = "M.gif";
- Assert.AreEqual ("M.gif", pb.ImageLocation, "#K1");
- Assert.IsNotNull (pb.Image, "#K2");
- Assert.AreEqual (60, pb.Image.Height, "#K3");
- Assert.AreEqual (150, pb.Image.Width, "#K4");
- try {
- pb.ImageLocation = "XYZ.gif";
- Assert.Fail ("#L1");
- } catch (FileNotFoundException ex) {
- Assert.AreEqual (typeof (FileNotFoundException), ex.GetType (), "#L2");
- Assert.IsNull (ex.InnerException, "#L3");
- Assert.IsNotNull (ex.Message, "#L4");
- }
- Assert.AreEqual ("XYZ.gif", pb.ImageLocation, "#M1");
- Assert.IsNotNull (pb.Image, "#M2");
- Assert.AreEqual (60, pb.Image.Height, "#M3");
- Assert.AreEqual (150, pb.Image.Width, "#M4");
- f.Dispose ();
- }
- #endif
- [Test]
- public void ImagePropertyTest ()
- {
- PictureBox myPicBox = new PictureBox ();
- // I
- Assert.IsNull (myPicBox.Image, "#1");
- Image myImage = Image.FromFile ("M.gif");
- myPicBox.Image = myImage;
- Assert.AreSame (myImage, myPicBox.Image, "#2");
- Assert.AreEqual (60, myPicBox.Image.Height, "#3");
- Assert.AreEqual (150, myPicBox.Image.Width, "#4");
- myPicBox.Image = null;
- Assert.IsNull (myPicBox.Image, "#5");
- myPicBox.Image = null;
- Assert.IsNull (myPicBox.Image, "#6");
- }
- #if NET_2_0
- [Test] // Load ()
- public void Load_ImageLocation_Empty ()
- {
- PictureBox pb = new PictureBox ();
- pb.ImageLocation = string.Empty;
- try {
- pb.Load ();
- Assert.Fail ("#1");
- } catch (InvalidOperationException ex) {
- // ImageLocation must be set
- Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- }
- }
- [Test] // Load ()
- public void Load_ImageLocation_Null ()
- {
- PictureBox pb = new PictureBox ();
- pb.ImageLocation = null;
- try {
- pb.Load ();
- Assert.Fail ("#1");
- } catch (InvalidOperationException ex) {
- // ImageLocation must be set
- Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- }
- }
- [Test] // Load (String)
- public void Load2_Url_Empty ()
- {
- PictureBox pb = new PictureBox ();
- try {
- pb.Load (string.Empty);
- Assert.Fail ("#1");
- } catch (InvalidOperationException ex) {
- // ImageLocation must be set
- Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- }
- }
- [Test] // Load (String)
- public void Load2_Url_Null ()
- {
- PictureBox pb = new PictureBox ();
- try {
- pb.Load ((string) null);
- Assert.Fail ("#1");
- } catch (InvalidOperationException ex) {
- // ImageLocation must be set
- Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- }
- }
- [Test] // LoadAsync ()
- public void LoadAsync1_ImageLocation_Empty ()
- {
- PictureBox pb = new PictureBox ();
- pb.ImageLocation = string.Empty;
- try {
- pb.LoadAsync ();
- Assert.Fail ("#1");
- } catch (InvalidOperationException ex) {
- // ImageLocation must be set
- Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- }
- }
- [Test] // LoadAsync ()
- public void LoadAsync1_ImageLocation_Null ()
- {
- PictureBox pb = new PictureBox ();
- pb.ImageLocation = null;
- try {
- pb.LoadAsync ();
- Assert.Fail ("#1");
- } catch (InvalidOperationException ex) {
- // ImageLocation must be set
- Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- }
- }
- [Test] // LoadAsync (String)
- public void LoadASync2_Url_Empty ()
- {
- PictureBox pb = new PictureBox ();
- try {
- pb.LoadAsync (string.Empty);
- Assert.Fail ("#1");
- } catch (InvalidOperationException ex) {
- // ImageLocation must be set
- Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- }
- }
- [Test] // LoadAsync (String)
- public void LoadAsync2_Url_Null ()
- {
- PictureBox pb = new PictureBox ();
- try {
- pb.LoadAsync ((string) null);
- Assert.Fail ("#1");
- } catch (InvalidOperationException ex) {
- // ImageLocation must be set
- Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- }
- }
- #endif
- [Test]
- public void ToStringMethodTest ()
- {
- PictureBox myPicBox = new PictureBox ();
- Assert.AreEqual ("System.Windows.Forms.PictureBox, SizeMode: Normal", myPicBox.ToString (), "#T1");
- }
- #if NET_2_0
- [Test]
- public void Defaults ()
- {
- PictureBox pb = new PictureBox ();
-
- Assert.IsNotNull (pb.ErrorImage, "A1");
- Assert.AreEqual (false, pb.WaitOnLoad, "A2");
-
- Assert.AreEqual (false, pb.AutoSize, "A3");
- pb.SizeMode = PictureBoxSizeMode.AutoSize;
- Assert.AreEqual (true, pb.AutoSize, "A4");
-
- }
- #endif
- [TestFixture]
- public class PictureBoxSizeModeEventClass : TestHelper
- {
- static bool eventhandled = false;
- public static void SizeMode_EventHandler (object sender, EventArgs e)
- {
- eventhandled = true;
- }
- [Test]
- public void PictureBoxEventTest ()
- {
- Form myForm = new Form ();
- myForm.ShowInTaskbar = false;
- PictureBox myPicBox = new PictureBox ();
- myForm.Controls.Add (myPicBox);
- myPicBox.SizeModeChanged += new EventHandler (SizeMode_EventHandler);
- myPicBox.SizeMode = PictureBoxSizeMode.AutoSize;
- Assert.AreEqual (true, eventhandled, "#SM1");
- eventhandled = false;
- myPicBox.SizeMode = PictureBoxSizeMode.CenterImage;
- Assert.AreEqual (true, eventhandled, "#SM2");
- eventhandled = false;
- myPicBox.SizeMode = PictureBoxSizeMode.StretchImage;
- Assert.AreEqual (true, eventhandled, "#SM3");
- myForm.Dispose ();
- }
- }
- }
- }
|