2 // ChtmlTextWriterTest.cs: Unit tests for System.Web.UI.ChtmlTextWriter
5 // Cesar Lopez Nataren <cnataren@novell.com>
7 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
34 using NUnit.Framework;
35 using System.Collections;
37 namespace MonoTests.System.Web.UI {
39 public class ChtmlTextWriterTester : ChtmlTextWriter {
41 public ChtmlTextWriterTester (TextWriter writer)
42 : this (writer, DefaultTabString)
46 public ChtmlTextWriterTester (TextWriter writer, string tabString)
47 : base (writer, tabString)
51 public bool IsRecognizedAttribute (string elementName, string attributeName)
53 Hashtable elem_attrs = (Hashtable) RecognizedAttributes [elementName];
55 if (elem_attrs == null)
57 return elem_attrs [attributeName] != null;
60 public string PublicGetAttributeName (HtmlTextWriterAttribute attrKey)
62 return GetAttributeName (attrKey);
65 public bool PublicOnAttributeRender (string name, string value, HtmlTextWriterAttribute attr)
67 return OnAttributeRender (name, value, attr);
70 public bool PublicOnStyleAttributeRender (string name, string value, HtmlTextWriterStyle key)
72 return OnStyleAttributeRender (name, value, key);
75 public bool PublicOnTagRender (string name, HtmlTextWriterTag tag)
77 return OnTagRender (name, tag);
80 public Hashtable PublicGlobalSuppressedAttributes {
81 get { return GlobalSuppressedAttributes; }
84 public Hashtable PublicSuppressedAttributes {
85 get { return SuppressedAttributes; }
90 public class ChtmlTextWriterTest {
92 ChtmlTextWriterTester chtml;
95 string absent_element = "absent-elem";
96 string absent_attr = "absent-attr";
99 public void SetupTests ()
101 writer = new StringWriter ();
102 chtml = new ChtmlTextWriterTester (writer);
106 public void AddRecognizedAttributeTest ()
108 chtml.AddRecognizedAttribute (absent_element, absent_attr);
109 Assertion.AssertEquals ("#A01", true, chtml.IsRecognizedAttribute (absent_element, absent_attr));
113 [ExpectedException (typeof (ArgumentException))]
114 public void AddRecognizedAttribute2 ()
116 AddRecognizedAttributeTest ();
117 AddRecognizedAttributeTest ();
121 public void RemoveRecognizedAttributeTest ()
123 AddRecognizedAttributeTest ();
125 chtml.RemoveRecognizedAttribute (absent_element, absent_attr);
126 Assertion.AssertEquals ("#B01", false, chtml.IsRecognizedAttribute (absent_element, absent_attr));
128 string version_two = "v2";
129 chtml.RemoveRecognizedAttribute (absent_element + version_two, absent_attr + version_two);
133 public void WriteBreakTest ()
137 Assertion.AssertEquals ("#C01", true, br == writer.ToString ());
141 public void WriteEncodedTest ()
143 string encoded_text = "<custID> & <invoice#>";
144 string unencoded_text = "<custID> & <invoice#>";
145 chtml.WriteEncodedText (encoded_text);
147 Assertion.AssertEquals ("#D01", true, unencoded_text == writer.ToString ());
151 public void OnAttributeRenderTest ()
153 HtmlTextWriterAttribute [] enum_values = (HtmlTextWriterAttribute []) Enum.GetValues (typeof (HtmlTextWriterAttribute));
156 foreach (HtmlTextWriterAttribute attr in enum_values) {
158 chtml.PublicOnAttributeRender (chtml.PublicGetAttributeName (attr), "accesskey", attr);
159 } catch (ArgumentNullException e) {
163 Assertion.AssertEquals ("#E01", enum_values.Length, i);
167 public void OnStyleAttributeRenderTest ()
172 foreach (HtmlTextWriterStyle tag in Enum.GetValues (typeof (HtmlTextWriterStyle))) {
173 expected = (tag == HtmlTextWriterStyle.Display);
174 Assertion.AssertEquals ("#F0" + i++, expected, chtml.PublicOnStyleAttributeRender ("foo", "foo", tag));
180 public void OnTagRenderTest ()
185 foreach (HtmlTextWriterTag tag in Enum.GetValues (typeof (HtmlTextWriterTag))) {
186 expected = (tag != HtmlTextWriterTag.Span);
187 Assertion.AssertEquals ("#G0" + i++, expected, chtml.PublicOnTagRender ("foo", tag));