ControlTest.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. //
  2. // Tests for System.Web.UI.Control
  3. //
  4. // Author:
  5. // Peter Dennis Bartok ([email protected])
  6. // Gonzalo Paniagua Javier ([email protected])
  7. //
  8. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using NUnit.Framework;
  30. using System;
  31. using System.Collections;
  32. using System.Drawing;
  33. using System.IO;
  34. using System.Globalization;
  35. using System.Web;
  36. using System.Web.UI;
  37. using System.Web.UI.WebControls;
  38. namespace MonoTests.System.Web.UI
  39. {
  40. [TestFixture]
  41. public class ControlTest {
  42. [Test]
  43. public void DataBindingInterfaceTest ()
  44. {
  45. Control c;
  46. DataBindingCollection db;
  47. c = new Control ();
  48. Assert.AreEqual (false, ((IDataBindingsAccessor)c).HasDataBindings, "DB1");
  49. db = ((IDataBindingsAccessor)c).DataBindings;
  50. Assert.IsNotNull (db, "DB2");
  51. Assert.AreEqual (false, ((IDataBindingsAccessor)c).HasDataBindings, "DB3");
  52. db.Add(new DataBinding ("property", typeof(bool), "expression"));
  53. Assert.AreEqual (true, ((IDataBindingsAccessor)c).HasDataBindings);
  54. }
  55. class MyNC : Control, INamingContainer {
  56. }
  57. [Test]
  58. public void UniqueID1 ()
  59. {
  60. // Standalone NC
  61. Control nc = new MyNC ();
  62. Assert.IsNull (nc.UniqueID, "nulltest");
  63. }
  64. [Test]
  65. public void UniqueID2 ()
  66. {
  67. // NC in NC
  68. Control nc = new MyNC ();
  69. Control nc2 = new MyNC ();
  70. nc2.Controls.Add (nc);
  71. Assert.IsNotNull (nc.UniqueID, "notnull");
  72. Assert.IsTrue (nc.UniqueID.IndexOfAny (new char [] {':', '$' }) == -1, "separator");
  73. }
  74. [Test]
  75. public void UniqueID3 ()
  76. {
  77. // NC in control
  78. Control control = new Control ();
  79. Control nc = new MyNC ();
  80. control.Controls.Add (nc);
  81. Assert.IsNull (nc.UniqueID, "null");
  82. }
  83. [Test]
  84. public void UniqueID4 ()
  85. {
  86. // NC in control
  87. Control control = new Control ();
  88. Control nc = new MyNC ();
  89. nc.Controls.Add (control);
  90. Assert.IsNotNull (control.UniqueID, "notnull");
  91. }
  92. [Test]
  93. public void UniqueID5 ()
  94. {
  95. // NC in control
  96. Control control = new Control ();
  97. Control nc = new MyNC ();
  98. Control nc2 = new MyNC ();
  99. nc2.Controls.Add (nc);
  100. nc.Controls.Add (control);
  101. Assert.IsNotNull (control.UniqueID, "notnull");
  102. Assert.IsNull (nc2.ID, "null-1");
  103. Assert.IsNull (nc.ID, "null-2");
  104. Assert.IsTrue (-1 != control.UniqueID.IndexOfAny (new char [] {':', '$' }), "separator");
  105. }
  106. class DerivedControl : Control {
  107. ControlCollection coll;
  108. public DerivedControl ()
  109. {
  110. coll = new ControlCollection (this);
  111. }
  112. public override ControlCollection Controls {
  113. get { return coll; }
  114. }
  115. }
  116. // From bug #76919: Control uses _controls instead of
  117. // Controls when RenderChildren is called.
  118. [Test]
  119. public void Controls1 ()
  120. {
  121. DerivedControl derived = new DerivedControl ();
  122. derived.Controls.Add (new LiteralControl ("hola"));
  123. StringWriter sw = new StringWriter ();
  124. HtmlTextWriter htw = new HtmlTextWriter (sw);
  125. derived.RenderControl (htw);
  126. string result = sw.ToString ();
  127. Assert.AreEqual ("", result, "#01");
  128. }
  129. }
  130. }