HtmlTextWriterCas.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. //
  2. // HtmlTextWriterCas.cs - CAS unit tests for System.Web.UI.HtmlTextWriter
  3. //
  4. // Author:
  5. // Sebastien Pouliot <[email protected]>
  6. //
  7. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using NUnit.Framework;
  29. using System;
  30. using System.IO;
  31. using System.Reflection;
  32. using System.Security.Permissions;
  33. using System.Web;
  34. using System.Web.UI;
  35. namespace MonoCasTests.System.Web.UI {
  36. [TestFixture]
  37. [Category ("CAS")]
  38. public class HtmlTextWriterCas : AspNetHostingMinimal {
  39. private StringWriter sw;
  40. [SetUp]
  41. public override void SetUp ()
  42. {
  43. base.SetUp ();
  44. sw = new StringWriter ();
  45. }
  46. private void Deny_Unrestricted (HtmlTextWriter htw)
  47. {
  48. Assert.IsTrue (htw.Indent >= 0, "Indent");
  49. Assert.AreSame (sw, htw.InnerWriter, "InnerWriter");
  50. htw.NewLine = Environment.NewLine;
  51. Assert.IsNotNull (htw.NewLine, "NewLine");
  52. htw.AddAttribute (HtmlTextWriterAttribute.Bgcolor, "blue");
  53. htw.AddAttribute (HtmlTextWriterAttribute.Bgcolor, "blue", false);
  54. htw.AddAttribute ("align", "left");
  55. htw.AddAttribute ("align", "left", false);
  56. htw.AddStyleAttribute (HtmlTextWriterStyle.BackgroundColor, "blue");
  57. htw.AddStyleAttribute ("left", "1");
  58. htw.RenderBeginTag (HtmlTextWriterTag.Table);
  59. htw.RenderBeginTag ("<tr>");
  60. htw.RenderEndTag ();
  61. htw.WriteAttribute ("align", "left");
  62. htw.WriteAttribute ("align", "left", false);
  63. htw.WriteBeginTag ("table");
  64. htw.WriteEndTag ("table");
  65. htw.WriteFullBeginTag ("div");
  66. htw.WriteStyleAttribute ("left", "2");
  67. htw.WriteStyleAttribute ("left", "3", false);
  68. htw.Write (new char[1], 0, 1);
  69. htw.Write ((double)1.0);
  70. htw.Write (Char.MinValue);
  71. htw.Write (new char[1]);
  72. htw.Write ((int)1);
  73. htw.Write ("{0}", 1);
  74. htw.Write ("{0}{1}", 1, 2);
  75. htw.Write ("{0}{1}{2}", 1, 2, 3);
  76. htw.Write (String.Empty);
  77. htw.Write ((long)1);
  78. htw.Write (this);
  79. htw.Write ((float)1.0);
  80. htw.Write (false);
  81. htw.WriteLine (new char[1], 0, 1);
  82. htw.WriteLine ((double)1.0);
  83. htw.WriteLine (Char.MinValue);
  84. htw.WriteLine (new char[1]);
  85. htw.WriteLine ((int)1);
  86. htw.WriteLine ("{0}", 1);
  87. htw.WriteLine ("{0}{1}", 1, 2);
  88. htw.WriteLine ("{0}{1}{2}", 1, 2, 3);
  89. htw.WriteLine (String.Empty);
  90. htw.WriteLine ((long)1);
  91. htw.WriteLine (this);
  92. htw.WriteLine ((float)1.0);
  93. htw.WriteLine (false);
  94. htw.WriteLine ((uint)0);
  95. htw.WriteLine ();
  96. htw.WriteLineNoTabs (String.Empty);
  97. htw.Flush ();
  98. htw.Close ();
  99. }
  100. [Test]
  101. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  102. public void Ctor1_Deny_Unrestricted ()
  103. {
  104. HtmlTextWriter htw = new HtmlTextWriter (sw);
  105. Deny_Unrestricted (htw);
  106. }
  107. [Test]
  108. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  109. public void Ctor2_Deny_Unrestricted ()
  110. {
  111. HtmlTextWriter htw = new HtmlTextWriter (sw, String.Empty);
  112. Deny_Unrestricted (htw);
  113. }
  114. // LinkDemand
  115. public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
  116. {
  117. ConstructorInfo ci = this.Type.GetConstructor (new Type[1] { typeof (TextWriter) });
  118. Assert.IsNotNull (ci, ".ctor(TextWriter)");
  119. return ci.Invoke (new object[1] { sw });
  120. }
  121. public override Type Type {
  122. get { return typeof (HtmlTextWriter); }
  123. }
  124. }
  125. }