GroupBoxTest.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. //
  2. // GroupBoxTest.cs: Test cases for GroupBox.
  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. namespace MonoTests.System.Windows.Forms
  15. {
  16. [TestFixture]
  17. public class GroupBoxTest : TestHelper
  18. {
  19. [Test]
  20. public void Constructor ()
  21. {
  22. GroupBox gb = new GroupBox ();
  23. Assert.AreEqual (false, gb.AllowDrop, "A1");
  24. // Top/Height are dependent on font height
  25. // Assert.AreEqual (new Rectangle (3, 16, 194, 81), gb.DisplayRectangle, "A2");
  26. Assert.AreEqual (FlatStyle.Standard, gb.FlatStyle, "A3");
  27. Assert.AreEqual (false, gb.TabStop, "A4");
  28. Assert.AreEqual (string.Empty, gb.Text, "A5");
  29. #if NET_2_0
  30. Assert.AreEqual (false, gb.AutoSize, "A6");
  31. Assert.AreEqual (AutoSizeMode.GrowOnly, gb.AutoSizeMode, "A7");
  32. Assert.AreEqual (true, gb.UseCompatibleTextRendering, "A8");
  33. Assert.AreEqual ("System.Windows.Forms.GroupBox+GroupBoxAccessibleObject", gb.AccessibilityObject.GetType ().ToString (), "A9");
  34. #endif
  35. }
  36. [Test]
  37. public void GroupBoxPropertyTest ()
  38. {
  39. Form myform = new Form ();
  40. myform.ShowInTaskbar = false;
  41. GroupBox mygrpbox = new GroupBox ();
  42. RadioButton myradiobutton1 = new RadioButton ();
  43. RadioButton myradiobutton2 = new RadioButton ();
  44. mygrpbox.Controls.Add (myradiobutton1);
  45. mygrpbox.Controls.Add (myradiobutton2);
  46. myform.Show ();
  47. Assert.AreEqual (FlatStyle.Standard, mygrpbox.FlatStyle, "#1");
  48. mygrpbox.FlatStyle = FlatStyle.Popup;
  49. Assert.AreEqual (FlatStyle.Popup, mygrpbox.FlatStyle, "#2");
  50. mygrpbox.FlatStyle = FlatStyle.Flat;
  51. Assert.AreEqual (FlatStyle.Flat, mygrpbox.FlatStyle, "#3");
  52. mygrpbox.FlatStyle = FlatStyle.System;
  53. Assert.AreEqual (FlatStyle.System, mygrpbox.FlatStyle, "#4");
  54. myform.Dispose ();
  55. }
  56. #if NET_2_0
  57. [Test]
  58. public void AutoSize ()
  59. {
  60. if (TestHelper.RunningOnUnix)
  61. Assert.Ignore ("Dependent on font height and theme, values are for windows.");
  62. Form f = new Form ();
  63. f.ShowInTaskbar = false;
  64. GroupBox p = new GroupBox ();
  65. p.AutoSize = true;
  66. f.Controls.Add (p);
  67. Button b = new Button ();
  68. b.Size = new Size (200, 200);
  69. b.Location = new Point (200, 200);
  70. p.Controls.Add (b);
  71. f.Show ();
  72. Assert.AreEqual (new Size (406, 419), p.ClientSize, "A1");
  73. p.Controls.Remove (b);
  74. Assert.AreEqual (new Size (200, 100), p.ClientSize, "A2");
  75. p.AutoSizeMode = AutoSizeMode.GrowAndShrink;
  76. Assert.AreEqual (new Size (6, 19), p.ClientSize, "A3");
  77. f.Dispose ();
  78. }
  79. [Test]
  80. public void PropertyDisplayRectangle ()
  81. {
  82. GroupBox gb = new GroupBox ();
  83. gb.Size = new Size (200, 200);
  84. Assert.AreEqual (new Padding (3), gb.Padding, "A0");
  85. gb.Padding = new Padding (25, 25, 25, 25);
  86. Assert.AreEqual (new Rectangle (0, 0, 200, 200), gb.ClientRectangle, "A1");
  87. // Basically, we are testing that the DisplayRectangle includes
  88. // Padding. Top/Height are affected by font height, so we aren't
  89. // using exact numbers.
  90. Assert.AreEqual (25, gb.DisplayRectangle.Left, "A2");
  91. Assert.AreEqual (150, gb.DisplayRectangle.Width, "A3");
  92. Assert.IsTrue (gb.DisplayRectangle.Top > gb.Padding.Top, "A4");
  93. Assert.IsTrue (gb.DisplayRectangle.Height < (gb.Height - gb.Padding.Vertical), "A5");
  94. }
  95. [Test]
  96. public void MethodScaleControl ()
  97. {
  98. Form f = new Form ();
  99. f.ShowInTaskbar = false;
  100. f.Show ();
  101. PublicGroupBox gb = new PublicGroupBox ();
  102. gb.Location = new Point (5, 10);
  103. f.Controls.Add (gb);
  104. Assert.AreEqual (new Rectangle (5, 10, 200, 100), gb.Bounds, "A1");
  105. gb.PublicScaleControl (new SizeF (2.0f, 2.0f), BoundsSpecified.All);
  106. Assert.AreEqual (new Rectangle (10, 20, 400, 200), gb.Bounds, "A2");
  107. gb.PublicScaleControl (new SizeF (.5f, .5f), BoundsSpecified.Location);
  108. Assert.AreEqual (new Rectangle (5, 10, 400, 200), gb.Bounds, "A3");
  109. gb.PublicScaleControl (new SizeF (.5f, .5f), BoundsSpecified.Size);
  110. Assert.AreEqual (new Rectangle (5, 10, 200, 100), gb.Bounds, "A4");
  111. f.Dispose ();
  112. }
  113. private class PublicGroupBox : GroupBox
  114. {
  115. public void PublicScaleControl (SizeF factor, BoundsSpecified specified)
  116. {
  117. base.ScaleControl (factor, specified);
  118. }
  119. }
  120. #endif
  121. }
  122. }