TextBoxTest.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //
  2. // Tests for System.Web.UI.WebControls.TextBox.cs
  3. //
  4. // Author:
  5. // Ben Maurer ([email protected])
  6. //
  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.IO;
  32. using System.Globalization;
  33. using System.Web;
  34. using System.Web.UI;
  35. using System.Web.UI.WebControls;
  36. namespace MonoTests.System.Web.UI.WebControls {
  37. [TestFixture]
  38. public class TextBoxTest {
  39. class Poker : TextBox {
  40. public new void AddParsedSubObject (object o)
  41. {
  42. base.AddParsedSubObject (o);
  43. }
  44. public void TrackState ()
  45. {
  46. TrackViewState ();
  47. }
  48. public object SaveState ()
  49. {
  50. foreach (string s in ViewState.Keys)
  51. Console.WriteLine ("{0}: {1}", s, ViewState[s]);
  52. return SaveViewState ();
  53. }
  54. public void LoadState (object o)
  55. {
  56. LoadViewState (o);
  57. }
  58. public string Render ()
  59. {
  60. StringWriter sw = new StringWriter ();
  61. sw.NewLine = "\n";
  62. HtmlTextWriter writer = new HtmlTextWriter (sw);
  63. base.Render (writer);
  64. return writer.InnerWriter.ToString ();
  65. }
  66. }
  67. [Test]
  68. public void MultilineRenderEscape ()
  69. {
  70. Poker t = new Poker ();
  71. t.TextMode = TextBoxMode.MultiLine;
  72. t.Text = "</textarea>";
  73. #if NET_2_0
  74. string exp = "<textarea rows=\"0\" cols=\"0\">&lt;/textarea&gt;</textarea>";
  75. #else
  76. string exp = "<textarea name>&lt;/textarea&gt;</textarea>";
  77. #endif
  78. Assert.AreEqual (exp, t.Render ());
  79. }
  80. #if NET_2_0
  81. [Test]
  82. public void ValidationProperties ()
  83. {
  84. Poker t = new Poker ();
  85. // initial values
  86. Assert.AreEqual (false, t.CausesValidation, "A1");
  87. Assert.AreEqual ("", t.ValidationGroup, "A2");
  88. t.ValidationGroup = "VG";
  89. Assert.AreEqual ("VG", t.ValidationGroup, "A3");
  90. t.CausesValidation = true;
  91. Assert.IsTrue (t.CausesValidation, "A4");
  92. }
  93. [Test]
  94. public void ViewState ()
  95. {
  96. Poker t = new Poker ();
  97. t.TrackState();
  98. t.ValidationGroup = "VG";
  99. t.CausesValidation = true;
  100. object s = t.SaveState ();
  101. Console.WriteLine ("state = {0}", s == null ? "null" : "not-null");
  102. Poker copy = new Poker ();
  103. copy.LoadState (s);
  104. Assert.AreEqual ("VG", copy.ValidationGroup, "A1");
  105. Assert.IsTrue (copy.CausesValidation, "A2");
  106. }
  107. [Test]
  108. public void ValidationRender ()
  109. {
  110. /* test to show that the validation settings
  111. * have no effect on downlevel rendering */
  112. Poker t = new Poker ();
  113. t.TrackState();
  114. t.ValidationGroup = "VG";
  115. t.CausesValidation = true;
  116. t.TextMode = TextBoxMode.MultiLine;
  117. string exp = "<textarea rows=\"0\" cols=\"0\"></textarea>";
  118. Assert.AreEqual (exp, t.Render ());
  119. }
  120. #endif
  121. }
  122. }