LabelTest.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // Copyright (c) 2005 Novell, Inc.
  3. //
  4. // Authors:
  5. // Hisham Mardam Bey ([email protected])
  6. //
  7. //
  8. using System;
  9. using NUnit.Framework;
  10. using System.Windows.Forms;
  11. using System.Drawing;
  12. using System.Runtime.Remoting;
  13. namespace MonoTests.System.Windows.Forms
  14. {
  15. [TestFixture]
  16. public class LabelTest2
  17. {
  18. [Test]
  19. public void PubPropTest ()
  20. {
  21. Label l = new Label ();
  22. // A
  23. Assert.AreEqual (false, l.AutoSize, "A1");
  24. l.AutoSize = true;
  25. Assert.AreEqual (true, l.AutoSize, "A2");
  26. l.AutoSize = false;
  27. Assert.AreEqual (false, l.AutoSize, "A3");
  28. // B
  29. Assert.AreEqual (null, l.BackgroundImage, "B1");
  30. l.BackgroundImage = Image.FromFile ("a.png");;
  31. Assert.IsNotNull (l.BackgroundImage, "B2");
  32. Bitmap bmp = (Bitmap)l.BackgroundImage;
  33. Assert.IsNotNull (bmp.GetPixel (0, 0), "B3");
  34. Assert.AreEqual (BorderStyle.None, l.BorderStyle, "B4");
  35. l.BorderStyle = BorderStyle.FixedSingle;
  36. Assert.AreEqual (BorderStyle.FixedSingle, l.BorderStyle, "B5");
  37. l.BorderStyle = BorderStyle.Fixed3D;
  38. Assert.AreEqual (BorderStyle.Fixed3D, l.BorderStyle, "B6");
  39. l.BorderStyle = BorderStyle.None;
  40. Assert.AreEqual (BorderStyle.None, l.BorderStyle, "B7");
  41. // C
  42. string name = l.CompanyName;
  43. if (!name.Equals("Mono Project, Novell, Inc.") && !name.Equals("Microsoft Corporation")) {
  44. Assert.Fail("CompanyName property does not match any accepted value - C1");
  45. }
  46. // F
  47. Assert.AreEqual (FlatStyle.Standard, l.FlatStyle, "F1");
  48. l.FlatStyle = FlatStyle.Flat;
  49. Assert.AreEqual (FlatStyle.Flat, l.FlatStyle, "F1");
  50. l.FlatStyle = FlatStyle.Popup;
  51. Assert.AreEqual (FlatStyle.Popup, l.FlatStyle, "F2");
  52. l.FlatStyle = FlatStyle.Standard;
  53. Assert.AreEqual (FlatStyle.Standard, l.FlatStyle, "F3");
  54. l.FlatStyle = FlatStyle.System;
  55. Assert.AreEqual (FlatStyle.System, l.FlatStyle, "F4");
  56. // I
  57. Assert.AreEqual (ContentAlignment.MiddleCenter, l.ImageAlign, "I1");
  58. l.ImageAlign = ContentAlignment.TopLeft;
  59. Assert.AreEqual (ContentAlignment.TopLeft, l.ImageAlign, "I2");
  60. l.ImageAlign = ContentAlignment.TopCenter;
  61. Assert.AreEqual (ContentAlignment.TopCenter, l.ImageAlign, "I3");
  62. l.ImageAlign = ContentAlignment.TopRight;
  63. Assert.AreEqual (ContentAlignment.TopRight, l.ImageAlign, "I4");
  64. l.ImageAlign = ContentAlignment.MiddleLeft;
  65. Assert.AreEqual (ContentAlignment.MiddleLeft, l.ImageAlign, "I5");
  66. l.ImageAlign = ContentAlignment.MiddleCenter;
  67. Assert.AreEqual (ContentAlignment.MiddleCenter, l.ImageAlign, "I6");
  68. l.ImageAlign = ContentAlignment.MiddleRight;
  69. Assert.AreEqual (ContentAlignment.MiddleRight, l.ImageAlign, "I7");
  70. l.ImageAlign = ContentAlignment.BottomLeft;
  71. Assert.AreEqual (ContentAlignment.BottomLeft, l.ImageAlign, "I8");
  72. l.ImageAlign = ContentAlignment.BottomCenter;
  73. Assert.AreEqual (ContentAlignment.BottomCenter, l.ImageAlign, "I9");
  74. l.ImageAlign = ContentAlignment.BottomRight;
  75. Assert.AreEqual (ContentAlignment.BottomRight, l.ImageAlign, "I10");
  76. Assert.AreEqual (-1, l.ImageIndex, "I11");
  77. Assert.AreEqual (null, l.ImageList, "I12");
  78. Assert.AreEqual (null, l.Image, "I13");
  79. l.Image = Image.FromFile ("a.png");
  80. Assert.IsNotNull (l.Image, "I14");
  81. bmp = (Bitmap)l.Image;
  82. Assert.IsNotNull (bmp.GetPixel (0, 0), "I15");
  83. ImageList il = new ImageList ();
  84. il.ColorDepth = ColorDepth.Depth32Bit;
  85. il.ImageSize = new Size (15, 15);
  86. il.Images.Add (Image.FromFile ("a.png"));
  87. l.ImageList = il;
  88. l.ImageIndex = 0;
  89. Assert.AreEqual (0, l.ImageIndex, "I16");
  90. Assert.IsNotNull (l.ImageList, "I17");
  91. // PreferredHeight
  92. // PregerredWidth
  93. // RenderTransparent
  94. // T
  95. // Assert.AreEqual (false, l.TabStop, "T1");
  96. Assert.AreEqual (ContentAlignment.TopLeft, l.TextAlign, "T2");
  97. // U
  98. Assert.AreEqual (true, l.UseMnemonic, "U1");
  99. l.UseMnemonic = false;
  100. Assert.AreEqual (false, l.UseMnemonic, "U2");
  101. }
  102. [Test]
  103. public void PubMethodTest ()
  104. {
  105. Label l = new Label ();
  106. l.Text = "My Label";
  107. Assert.AreEqual ("System.Windows.Forms.LabelText: My Label", l.ToString (), "T1");
  108. }
  109. }
  110. }