PictureBoxTest.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // PictureBoxTest.cs: Test cases for PictureBox.
  3. //
  4. // Author:
  5. // Ritvik Mayank ([email protected])
  6. //
  7. // (C) 2005 Novell, Inc. (http://www.novell.com)
  8. //
  9. using System;
  10. using System.Windows.Forms;
  11. using System.Drawing;
  12. using System.Reflection;
  13. using NUnit.Framework;
  14. using System.Threading;
  15. namespace MonoTests.System.Windows.Forms
  16. {
  17. [TestFixture]
  18. public class PictureBoxTest
  19. {
  20. [Test]
  21. public void PictureBoxPropertyTest ()
  22. {
  23. Form myForm = new Form ();
  24. myForm.ShowInTaskbar = false;
  25. PictureBox myPicBox = new PictureBox ();
  26. myForm.Controls.Add (myPicBox);
  27. // B
  28. Assert.AreEqual (BorderStyle.None, myPicBox.BorderStyle, "#B1");
  29. myPicBox.BorderStyle = BorderStyle.Fixed3D;
  30. Assert.AreEqual (BorderStyle.Fixed3D, myPicBox.BorderStyle, "#B2");
  31. // P
  32. Assert.AreEqual (PictureBoxSizeMode.Normal, myPicBox.SizeMode, "#P1");
  33. myPicBox.SizeMode = PictureBoxSizeMode.AutoSize;
  34. Assert.AreEqual (PictureBoxSizeMode.AutoSize, myPicBox.SizeMode, "#P2");
  35. myForm.Dispose ();
  36. }
  37. [Test]
  38. public void ImagePropertyTest ()
  39. {
  40. PictureBox myPicBox = new PictureBox ();
  41. // I
  42. Assert.AreEqual (null, myPicBox.Image, "#I1");
  43. Image myImage = Image.FromFile("M.gif");
  44. myPicBox.Image = myImage;
  45. Assert.AreEqual (60, myPicBox.Image.Height, "#I2");
  46. Assert.AreEqual (150, myPicBox.Image.Width, "#I3");
  47. }
  48. [Test]
  49. public void ToStringMethodTest ()
  50. {
  51. PictureBox myPicBox = new PictureBox ();
  52. Assert.AreEqual ("System.Windows.Forms.PictureBox, SizeMode: Normal", myPicBox.ToString (), "#T1");
  53. }
  54. [TestFixture]
  55. public class PictureBoxSizeModeEventClass
  56. {
  57. static bool eventhandled = false;
  58. public static void SizeMode_EventHandler (object sender, EventArgs e)
  59. {
  60. eventhandled = true;
  61. }
  62. [Test]
  63. public void PictureBoxEvenTest ()
  64. {
  65. Form myForm = new Form ();
  66. myForm.ShowInTaskbar = false;
  67. PictureBox myPicBox = new PictureBox ();
  68. myForm.Controls.Add (myPicBox);
  69. myPicBox.SizeModeChanged += new EventHandler (SizeMode_EventHandler);
  70. myPicBox.SizeMode = PictureBoxSizeMode.AutoSize;
  71. Assert.AreEqual (true, eventhandled, "#SM1");
  72. eventhandled = false;
  73. myPicBox.SizeMode = PictureBoxSizeMode.CenterImage;
  74. Assert.AreEqual (true, eventhandled, "#SM2");
  75. eventhandled = false;
  76. myPicBox.SizeMode = PictureBoxSizeMode.StretchImage;
  77. Assert.AreEqual (true, eventhandled, "#SM3");
  78. myForm.Dispose ();
  79. }
  80. }
  81. }
  82. }