Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@ -0,0 +1,89 @@
//
// AttributeCollectionCas.cs
// - CAS unit tests for System.Web.UI.AttributeCollection
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.IO;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
namespace MonoCasTests.System.Web.UI {
[TestFixture]
[Category ("CAS")]
public class AttributeCollectionCas : AspNetHostingMinimal {
private StateBag bag;
private HtmlTextWriter writer;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
bag = new StateBag ();
writer = new HtmlTextWriter (new StringWriter ());
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
// nothing else is required
AttributeCollection ac = new AttributeCollection (bag);
Assert.AreEqual (0, ac.Count, "Count");
Assert.IsNotNull (ac.CssStyle, "CssStyle");
ac["mono"] = "monkey";
Assert.AreEqual ("monkey", ac["mono"], "this");
Assert.IsNotNull (ac.Keys, "Keys");
ac.Add ("monkey", "mono");
ac.AddAttributes (writer);
ac.Clear ();
ac.Remove ("mono");
ac.Render (writer);
}
// LinkDemand
public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
{
ConstructorInfo ci = this.Type.GetConstructor (new Type[1] { typeof (StateBag) });
Assert.IsNotNull (ci, ".ctor(StateBag)");
return ci.Invoke (new object[1] { bag });
}
public override Type Type {
get { return typeof (AttributeCollection); }
}
}
}

View File

@ -0,0 +1,272 @@
//
// Tests for System.Web.UI.AttributeCollection.cs and CssStyleCollection
//
// Author:
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
//
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.IO;
using System.Globalization;
using System.Web;
using System.Web.UI;
using System.Collections;
using AC = System.Web.UI.AttributeCollection;
namespace MonoTests.System.Web.UI {
[TestFixture]
public class AttributeCollectionTest {
[Test]
public void InitialNoBag1 ()
{
AC ac = new AC (null);
Assert.IsNotNull (ac.CssStyle, "style");
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void InitialNoBag2 ()
{
AC ac = new AC (null);
int i = ac.Count;
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void InitialNoBag3 ()
{
AC ac = new AC (null);
ICollection coll = ac.Keys;
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void InitialNoBag4 ()
{
AC ac = new AC (null);
string k = ac ["hola"];
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void InitialNoBag5 ()
{
AC ac = new AC (null);
ac.Add ("att", "value");
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void InitialNoBag6 ()
{
AC ac = new AC (null);
ac.Clear ();
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void InitialNoBag7 ()
{
AC ac = new AC (null);
HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
ac.AddAttributes (writer);
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void InitialNoBag8 ()
{
AC ac = new AC (null);
HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
ac.Render (writer);
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void InitialNoBag9 ()
{
AC ac = new AC (null);
ac.Remove ("hola");
}
[Test]
public void InitialNoBag10()
{
AC ac = new AC(null);
CssStyleCollection css = ac.CssStyle;
int i = css.Count;
Assert.AreEqual(0, i, "InitialNoBag10");
}
[Test]
public void InitialNoBag11()
{
AC ac = new AC(null);
CssStyleCollection css = ac.CssStyle;
ICollection coll = css.Keys;
Assert.AreEqual(0, coll.Count, "InitialNoBag11");
}
[Test]
public void InitialNoBag12()
{
AC ac = new AC(null);
CssStyleCollection css = ac.CssStyle;
string v = css["hola"];
Assert.AreEqual(null, v, "InitialNoBag12");
}
[Test]
public void InitialBag1 ()
{
StateBag bag = new StateBag (true);
AC ac = new AC (bag);
Assert.AreEqual (0, ac.Count, "count");
Assert.AreEqual (null, ac ["hola"], "item");
Assert.AreEqual (0, ac.Keys.Count, "keys");
ac.Add ("notexists", "invalid");
ac.Remove ("notexists");
ac.Remove ("notexists");
HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
ac.AddAttributes (writer);
ac.Render (writer);
Assert.AreEqual (0, writer.InnerWriter.ToString().Length, "length");
CssStyleCollection css = ac.CssStyle;
Assert.AreEqual (0, css.Count, "csscount");
Assert.AreEqual (null, css ["hola"], "cssitem");
Assert.AreEqual (0, css.Keys.Count, "csskeys");
css.Add ("notexists", "invalid");
css.Remove ("notexists");
css.Remove ("notexists");
css.Add ("notexists", "invalid");
css.Clear ();
Assert.AreEqual (0, css.Keys.Count, "csskeys2");
}
[Test]
public void NonStyleAttributes1 ()
{
StateBag bag = new StateBag (true);
AC ac = new AC (bag);
StringWriter sr = new StringWriter ();
HtmlTextWriter writer = new HtmlTextWriter (sr);
ac.Add ("notexists", "somevalue");
ac.AddAttributes (writer);
string str = sr.ToString ();
Assert.AreEqual ("", str, "value1");
Assert.AreEqual (1, bag.Count, "count1");
writer = new HtmlTextWriter (sr);
writer.RenderBeginTag (HtmlTextWriterTag.A);
ac.AddAttributes (writer);
writer.RenderEndTag ();
Assert.AreEqual ("", str, "value2");
Assert.AreEqual (1, bag.Count, "count2");
}
[Test]
public void NonStyleAttributes2 ()
{
StateBag bag = new StateBag (true);
AC ac = new AC (bag);
StringWriter sr = new StringWriter ();
HtmlTextWriter writer = new HtmlTextWriter (sr);
ac.Add ("class", "classname");
ac.AddAttributes (writer);
string str = sr.ToString ();
Assert.AreEqual ("", str, "value1");
Assert.AreEqual (1, bag.Count, "count1");
writer = new HtmlTextWriter (sr);
writer.RenderBeginTag (HtmlTextWriterTag.A);
ac.AddAttributes (writer);
writer.RenderEndTag ();
Assert.AreEqual ("", str, "value2");
Assert.AreEqual (1, bag.Count, "count2");
}
[Test]
public void Count1 ()
{
StateBag bag = new StateBag (true);
AC ac = new AC (bag);
ac.Add ("style", "padding: 0px; margin: 0px");
Assert.AreEqual (1, ac.Count, "AttributeCollection.Count");
Assert.AreEqual (2, ac.CssStyle.Count, "AttributeCollection.Count");
ac.Remove ("style");
Assert.AreEqual (0, ac.Count, "AttributeCollection.Count");
Assert.AreEqual (0, ac.CssStyle.Count, "AttributeCollection.Count");
}
[Test]
public void Count2 ()
{
StateBag bag = new StateBag (true);
AC ac = new AC (bag);
ac ["style"] = "padding: 0px; margin: 0px";
Assert.AreEqual (1, ac.Count, "AttributeCollection.Count");
Assert.AreEqual (2, ac.CssStyle.Count, "AttributeCollection.Count");
ac ["style"] = null;
Assert.AreEqual (0, ac.Count, "AttributeCollection.Count");
Assert.AreEqual (0, ac.CssStyle.Count, "AttributeCollection.Count");
}
[Test]
public void Count3 ()
{
StateBag bag = new StateBag (true);
AC ac = new AC (bag);
ac.CssStyle.Add("padding", "0px");
ac.CssStyle.Add("margin", "0px");
Assert.AreEqual (1, ac.Count, "AttributeCollection.Count");
Assert.AreEqual (2, ac.CssStyle.Count, "AttributeCollection.Count");
ac.CssStyle.Remove ("padding");
ac.CssStyle.Remove ("margin");
Assert.AreEqual (0, ac.Count, "AttributeCollection.Count");
Assert.AreEqual (0, ac.CssStyle.Count, "AttributeCollection.Count");
}
#if NET_2_0
[Test]
public void Count4 ()
{
StateBag bag = new StateBag (true);
AC ac = new AC (bag);
ac.CssStyle ["padding"] = "0px";
ac.CssStyle ["margin"] = "0px";
Assert.AreEqual (1, ac.Count, "AttributeCollection.Count");
Assert.AreEqual (2, ac.CssStyle.Count, "AttributeCollection.Count");
ac.CssStyle.Value = null;
Assert.AreEqual (0, ac.Count, "AttributeCollection.Count");
Assert.AreEqual (0, ac.CssStyle.Count, "AttributeCollection.Count");
}
#endif
}
}

View File

@ -0,0 +1,55 @@
//
// BaseParserCas.cs - CAS unit tests for System.Web.UI.BaseParser
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
namespace MonoCasTests.System.Web.UI {
[TestFixture]
[Category ("CAS")]
public class BaseParserCas : AspNetHostingMinimal {
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
new BaseParser ();
}
// LinkDemand
public override Type Type {
get { return typeof (BaseParser); }
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,193 @@
//
// ChtmlTextWriterTest.cs: Unit tests for System.Web.UI.ChtmlTextWriter
//
// Author:
// Cesar Lopez Nataren <cnataren@novell.com>
//
// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.IO;
using System.Web.UI;
using NUnit.Framework;
using System.Collections;
namespace MonoTests.System.Web.UI {
public class ChtmlTextWriterTester : ChtmlTextWriter {
public ChtmlTextWriterTester (TextWriter writer)
: this (writer, DefaultTabString)
{
}
public ChtmlTextWriterTester (TextWriter writer, string tabString)
: base (writer, tabString)
{
}
public bool IsRecognizedAttribute (string elementName, string attributeName)
{
Hashtable elem_attrs = (Hashtable) RecognizedAttributes [elementName];
if (elem_attrs == null)
return false;
return elem_attrs [attributeName] != null;
}
public string PublicGetAttributeName (HtmlTextWriterAttribute attrKey)
{
return GetAttributeName (attrKey);
}
public bool PublicOnAttributeRender (string name, string value, HtmlTextWriterAttribute attr)
{
return OnAttributeRender (name, value, attr);
}
public bool PublicOnStyleAttributeRender (string name, string value, HtmlTextWriterStyle key)
{
return OnStyleAttributeRender (name, value, key);
}
public bool PublicOnTagRender (string name, HtmlTextWriterTag tag)
{
return OnTagRender (name, tag);
}
public Hashtable PublicGlobalSuppressedAttributes {
get { return GlobalSuppressedAttributes; }
}
public Hashtable PublicSuppressedAttributes {
get { return SuppressedAttributes; }
}
}
[TestFixture]
public class ChtmlTextWriterTest {
ChtmlTextWriterTester chtml;
StringWriter writer;
string absent_element = "absent-elem";
string absent_attr = "absent-attr";
[SetUp]
public void SetupTests ()
{
writer = new StringWriter ();
chtml = new ChtmlTextWriterTester (writer);
}
[Test]
public void AddRecognizedAttributeTest ()
{
chtml.AddRecognizedAttribute (absent_element, absent_attr);
Assert.AreEqual (true, chtml.IsRecognizedAttribute (absent_element, absent_attr), "#A01");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void AddRecognizedAttribute2 ()
{
AddRecognizedAttributeTest ();
AddRecognizedAttributeTest ();
}
[Test]
public void RemoveRecognizedAttributeTest ()
{
AddRecognizedAttributeTest ();
chtml.RemoveRecognizedAttribute (absent_element, absent_attr);
Assert.AreEqual (false, chtml.IsRecognizedAttribute (absent_element, absent_attr), "#B01");
string version_two = "v2";
chtml.RemoveRecognizedAttribute (absent_element + version_two, absent_attr + version_two);
}
[Test]
public void WriteBreakTest ()
{
string br = "<br>";
chtml.WriteBreak ();
Assert.AreEqual (true, br == writer.ToString (), "#C01");
}
[Test]
public void WriteEncodedTest ()
{
string encoded_text = "<custID> & <invoice#>";
string unencoded_text = "&lt;custID&gt; &amp; &lt;invoice#&gt;";
chtml.WriteEncodedText (encoded_text);
Assert.AreEqual (true, unencoded_text == writer.ToString (), "#D01");
}
[Test]
public void OnAttributeRenderTest ()
{
HtmlTextWriterAttribute [] enum_values = (HtmlTextWriterAttribute []) Enum.GetValues (typeof (HtmlTextWriterAttribute));
int i = 0;
foreach (HtmlTextWriterAttribute attr in enum_values) {
try {
chtml.PublicOnAttributeRender (chtml.PublicGetAttributeName (attr), "accesskey", attr);
} catch (ArgumentNullException e) {
i++;
}
}
Assert.AreEqual (enum_values.Length, i, "#E01");
}
[Test]
public void OnStyleAttributeRenderTest ()
{
bool expected;
int i = 0;
foreach (HtmlTextWriterStyle tag in Enum.GetValues (typeof (HtmlTextWriterStyle))) {
expected = (tag == HtmlTextWriterStyle.Display);
Assert.AreEqual (expected, chtml.PublicOnStyleAttributeRender ("foo", "foo", tag), "#F0" + i++);
}
}
[Test]
public void OnTagRenderTest ()
{
int i = 0;
bool expected;
foreach (HtmlTextWriterTag tag in Enum.GetValues (typeof (HtmlTextWriterTag))) {
expected = (tag != HtmlTextWriterTag.Span);
Assert.AreEqual (expected, chtml.PublicOnTagRender ("foo", tag), "#G0" + i++);
}
}
}
}
#endif

View File

@ -0,0 +1,188 @@
//
// CleanHtmlTextWriter.cs
//
// An HtmlTextWriter that cleans stuff up for you a bit. Helps writing tests
// because you do not have to reproduce the attribute order, etc.
//
// Author:
// Ben Maurer <bmaurer@novell.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//#define TEST_THIS
using System.Web.UI;
using System;
using System.IO;
using System.Collections;
class CleanHtmlTextWriter : HtmlTextWriter {
public CleanHtmlTextWriter (TextWriter tw) : base (tw)
{
tw.NewLine = "\n";
}
ArrayList pending_attrs = new ArrayList ();
ArrayList pending_styles = new ArrayList ();
class PendingStyle : IComparable {
public string name, value;
public HtmlTextWriterStyle s;
public PendingStyle (string name, string value, HtmlTextWriterStyle s)
{
this.name = name;
this.value = value;
this.s = s;
}
public int CompareTo (object o)
{
return string.CompareOrdinal (name, ((PendingStyle) o).name);
}
}
class PendingAttribute : IComparable {
public string name, value;
public HtmlTextWriterAttribute a;
public bool encode;
public bool know_encode;
public PendingAttribute (string name, string value, HtmlTextWriterAttribute a, bool encode, bool know_encode)
{
this.name = name;
this.value = value;
this.a = a;
this.encode = encode;
this.know_encode = know_encode;
}
public int CompareTo (object o)
{
return string.CompareOrdinal (name, ((PendingAttribute) o).name);
}
}
bool filtering = false;
//
// Some idiot at microsoft did not do a sanity check on this api,
// thus forcing me to deal with some serious pain.
//
public override void AddAttribute (HtmlTextWriterAttribute key, string value)
{
if (filtering) {
base.AddAttribute (key, value);
return;
}
pending_attrs.Add (new PendingAttribute (GetAttributeName (key), value, key, false, false));
}
public override void AddAttribute (HtmlTextWriterAttribute key, string value, bool fEncode)
{
if (filtering) {
base.AddAttribute (key, value, fEncode);
return;
}
pending_attrs.Add (new PendingAttribute (GetAttributeName (key), value, key, fEncode, true));
}
public override void AddAttribute (string name, string value)
{
if (filtering) {
base.AddAttribute (name, value);
return;
}
pending_attrs.Add (new PendingAttribute (name, value, 0, false, false));
}
public override void AddAttribute (string name, string value, bool fEncode)
{
if (filtering) {
base.AddAttribute (name, value, fEncode);
return;
}
pending_attrs.Add (new PendingAttribute (name, value, 0, fEncode, true));
}
protected override void AddAttribute (string name, string value, HtmlTextWriterAttribute key)
{
if (filtering) {
base.AddAttribute (name, value, key);
return;
}
pending_attrs.Add (new PendingAttribute (name, value, key, false, false));
}
// TODO: use the above retardation in this stuff
protected override void AddStyleAttribute (string name, string value, HtmlTextWriterStyle s)
{
pending_styles.Add (new PendingStyle (name, value, s));
}
protected override void FilterAttributes ()
{
pending_attrs.Sort ();
pending_styles.Sort ();
filtering = true;
foreach (PendingAttribute a in pending_attrs) {
if (a.a == 0) {
if (a.know_encode)
base.AddAttribute (a.name, a.value, a.encode);
else
base.AddAttribute (a.name, a.value, a.encode);
} else {
if (a.know_encode)
base.AddAttribute (a.a, a.value, a.encode);
else
base.AddAttribute (a.a, a.value, a.encode);
}
}
foreach (PendingStyle s in pending_styles)
base.AddStyleAttribute (s.name, s.value, s.s);
filtering = false;
pending_attrs.Clear ();
pending_styles.Clear ();
base.FilterAttributes ();
}
#if TEST_THIS
static void Main ()
{
HtmlTextWriter w = new CleanHtmlTextWriter (Console.Out);
w.AddAttribute (HtmlTextWriterAttribute.Name, "abcd");
w.AddAttribute (HtmlTextWriterAttribute.Id, "efg");
w.RenderBeginTag (HtmlTextWriterTag.Input);
w.RenderEndTag ();
Console.WriteLine ();
}
#endif
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,79 @@
//
// CompiledTemplateBuilderCas.cs
// - CAS unit tests for System.Web.UI.CompiledTemplateBuilder
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.IO;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
namespace MonoCasTests.System.Web.UI {
[TestFixture]
[Category ("CAS")]
public class CompiledTemplateBuilderCas : AspNetHostingMinimal {
private Control control;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
control = new Control ();
}
private void BuildTemplate (Control control)
{
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
CompiledTemplateBuilder ctb = new CompiledTemplateBuilder (new BuildTemplateMethod (BuildTemplate));
ctb.InstantiateIn (control);
}
// LinkDemand
public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
{
ConstructorInfo ci = this.Type.GetConstructor (new Type[1] { typeof (BuildTemplateMethod) });
Assert.IsNotNull (ci, ".ctor(BuildTemplateMethod)");
return ci.Invoke (new object[1] { new BuildTemplateMethod (BuildTemplate) });
}
public override Type Type {
get { return typeof (CompiledTemplateBuilder); }
}
}
}

View File

@ -0,0 +1,59 @@
//
// ConstructorNeedsTagAttributeCas.cs
// - CAS unit tests for System.Web.UI.ConstructorNeedsTagAttributeCas
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
namespace MonoCasTests.System.Web.UI {
[TestFixture]
[Category ("CAS")]
public class ConstructorNeedsTagAttributeCas : AspNetHostingMinimal {
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
ConstructorNeedsTagAttribute a1 = new ConstructorNeedsTagAttribute ();
Assert.IsFalse (a1.NeedsTag, "NeedsTag-1");
ConstructorNeedsTagAttribute a2 = new ConstructorNeedsTagAttribute (true);
Assert.IsTrue (a2.NeedsTag, "NeedsTag-2");
}
// LinkDemand
public override Type Type {
get { return typeof (ConstructorNeedsTagAttribute); }
}
}
}

View File

@ -0,0 +1,68 @@
//
// ControlBuilderAttributeCas.cs
// - CAS unit tests for System.Web.UI.ControlBuilderAttribute
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Reflection;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
namespace MonoCasTests.System.Web.UI {
[TestFixture]
[Category ("CAS")]
public class ControlBuilderAttributeCas : AspNetHostingMinimal {
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
ControlBuilderAttribute attr = new ControlBuilderAttribute (null);
Assert.IsNull (attr.BuilderType, "BuilderType");
Assert.IsTrue (attr.Equals (ControlBuilderAttribute.Default), "Equals");
attr.GetHashCode ();
Assert.IsTrue (attr.IsDefaultAttribute (), "IsDefaultAttribute");
}
// LinkDemand
public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
{
ConstructorInfo ci = this.Type.GetConstructor (new Type[1] { typeof (Type) });
Assert.IsNotNull (ci, ".ctor(Type)");
return ci.Invoke (new object[1] { null });
}
public override Type Type {
get { return typeof (ControlBuilderAttribute); }
}
}
}

View File

@ -0,0 +1,76 @@
//
// ControlBuilderCas.cs - CAS unit tests for System.Web.UI.ControlBuilder
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Reflection;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
namespace MonoCasTests.System.Web.UI {
[TestFixture]
[Category ("CAS")]
public class ControlBuilderCas : AspNetHostingMinimal {
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
ControlBuilder cb = new ControlBuilder ();
Assert.IsNull (cb.ControlType, "ControlType");
Assert.IsFalse (cb.HasAspCode, "HasAspCode");
cb.ID = "mono";
Assert.AreEqual ("mono", cb.ID, "ID");
Assert.AreEqual (typeof (Control), cb.NamingContainerType, "NamingContainerType");
Assert.IsNull (cb.TagName, "TagName");
Assert.IsTrue (cb.AllowWhitespaceLiterals (), "AllowWhitespaceLiterals");
cb.AppendLiteralString ("mono");
cb.AppendSubBuilder (cb);
cb.CloseControl ();
Assert.IsNull (cb.GetChildControlType (null, null), "GetChildControlType");
Assert.IsTrue (cb.HasBody (), "HasBody");
Assert.IsFalse (cb.HtmlDecodeLiterals (), "HtmlDecodeLiterals");
cb.Init (null, cb, typeof (TemplateBuilder), "span", "mono", null);
Assert.IsFalse (cb.NeedsTagInnerText (), "NeedsTagInnerText");
//cb.OnAppendToParentBuilder (null);
cb.SetTagInnerText ("mono");
cb = ControlBuilder.CreateBuilderFromType (null, cb, typeof (TemplateBuilder), "span", "mono", null, 0, String.Empty);
Assert.IsNotNull (cb, "CreateBuilderFromType");
}
// LinkDemand
public override Type Type {
get { return typeof (ControlBuilder); }
}
}
}

View File

@ -0,0 +1,155 @@
//
// ControlCas.cs - CAS unit tests for System.Web.UI.Control
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.IO;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MonoCasTests.System.Web.UI {
[TestFixture]
[Category ("CAS")]
public class ControlCas : AspNetHostingMinimal {
private Control control;
private HtmlTextWriter writer;
private Page page;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
control = new Control ();
writer = new HtmlTextWriter (new StringWriter ());
page = new Page ();
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Properties_Deny_Unrestricted ()
{
Control c = new Control ();
Assert.IsNull (c.ClientID, "ClientID");
Assert.IsNotNull (c.Controls, "Controls");
c.EnableViewState = true;
Assert.IsTrue (c.EnableViewState, "EnableViewState");
c.ID = "mono";
Assert.AreEqual ("mono", c.ID, "ID");
Assert.IsNull (c.NamingContainer, "NamingContainer");
Assert.IsNull (c.Page, "Page");
Assert.IsNull (c.Parent, "Parent");
Assert.IsNull (c.Site, "Site");
Assert.AreEqual ("mono", c.UniqueID, "UniqueID");
Assert.IsTrue (c.Visible, "Visible");
#if NET_2_0
c.AppRelativeTemplateSourceDirectory = String.Empty;
Assert.AreEqual (String.Empty, c.AppRelativeTemplateSourceDirectory, "AppRelativeTemplateSourceDirectory");
c.EnableTheming = true;
Assert.IsTrue (c.EnableTheming, "EnableTheming");
c.SkinID = String.Empty;
Assert.AreEqual (String.Empty, c.SkinID, "SkinID");
c.TemplateControl = null;
Assert.IsNull (c.TemplateControl, "TemplateControl");
Assert.AreEqual (String.Empty, c.TemplateSourceDirectory, "TemplateSourceDirectory");
#endif
}
private void SetRenderMethodDelegate (HtmlTextWriter writer, Control control)
{
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Methods_Deny_Unrestricted ()
{
Control c = new Control ();
c.DataBind ();
Assert.IsNull (c.FindControl ("mono"), "FindControl");
Assert.IsFalse (c.HasControls (), "HasControls");
c.RenderControl (writer);
Assert.IsNotNull (c.ResolveUrl (String.Empty), "ResolveUrl");
c.SetRenderMethodDelegate (new RenderMethod (SetRenderMethodDelegate));
#if NET_2_0
c.ApplyStyleSheetSkin (page);
Assert.IsNotNull (c.ResolveClientUrl (String.Empty), "ResolveClientUrl");
#endif
c.Dispose ();
}
#if NET_2_0
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (InvalidOperationException))]
public void Focus_Deny_Unrestricted ()
{
Control c = new Control ();
page.Controls.Add (c);
c.Focus ();
// normal, no forms on page
}
#endif
private void Handler (object sender, EventArgs e)
{
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Events_Deny_Unrestricted ()
{
Control c = new Control ();
c.DataBinding += new EventHandler (Handler);
c.Disposed += new EventHandler (Handler);
c.Init += new EventHandler (Handler);
c.Load += new EventHandler (Handler);
c.PreRender += new EventHandler (Handler);
c.Unload += new EventHandler (Handler);
c.DataBinding -= new EventHandler (Handler);
c.Disposed -= new EventHandler (Handler);
c.Init -= new EventHandler (Handler);
c.Load -= new EventHandler (Handler);
c.PreRender -= new EventHandler (Handler);
c.Unload -= new EventHandler (Handler);
}
// LinkDemand
public override Type Type {
get { return typeof (Control); }
}
}
}

View File

@ -0,0 +1,92 @@
//
// ControlCollectionCas.cs
// - CAS unit tests for System.Web.UI.ControlCollection
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.IO;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
namespace MonoCasTests.System.Web.UI {
[TestFixture]
[Category ("CAS")]
public class ControlCollectionCas : AspNetHostingMinimal {
private Control control;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
control = new Control ();
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
// note: using the same control (as owner) to add results
// in killing the ms runtime with a stackoverflow - FDBK36722
ControlCollection cc = new ControlCollection (new Control ());
Assert.AreEqual (0, cc.Count, "Count");
Assert.IsFalse (cc.IsReadOnly, "IsReadOnly");
Assert.IsFalse (cc.IsSynchronized, "IsSynchronized");
Assert.IsNotNull (cc.SyncRoot, "SyncRoot");
cc.Add (control);
Assert.IsNotNull (cc[0], "this[int]");
cc.Clear ();
cc.AddAt (0, control);
Assert.IsTrue (cc.Contains (control), "Contains");
cc.CopyTo (new Control[1], 0);
Assert.IsNotNull (cc.GetEnumerator (), "GetEnumerator");
Assert.AreEqual (0, cc.IndexOf (control), "IndexOf");
cc.RemoveAt (0);
cc.Remove (control);
}
// LinkDemand
public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
{
ConstructorInfo ci = this.Type.GetConstructor (new Type[1] { typeof (Control) });
Assert.IsNotNull (ci, ".ctor(Control)");
return ci.Invoke (new object[1] { control });
}
public override Type Type {
get { return typeof (ControlCollection); }
}
}
}

View File

@ -0,0 +1,55 @@
//
// Tests for System.Web.UI.ControlCollection
//
// Authors:
// Gonzalo Paniagua Javier <gonzalo@novell.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.IO;
using System.Security.Principal;
using System.Web;
using System.Web.UI;
namespace MonoTests.System.Web.UI {
[TestFixture]
public class ControlCollectionTest {
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void AddNull ()
{
Page p = new Page ();
p.Controls.Add (null);
}
[Test]
public void RemoveNull ()
{
Page p = new Page ();
p.Controls.Remove (null);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,90 @@
//
// CssStyleCollectionCas.cs
// - CAS unit tests for System.Web.UI.CssStyleCollectionCas
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.IO;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MonoCasTests.System.Web.UI {
[TestFixture]
[Category ("CAS")]
public class CssStyleCollectionCas : AspNetHostingMinimal {
private CssStyleCollection css;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
css = new Table ().Style;
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
Assert.AreEqual (0, css.Count, "Count");
css ["mono"] = "monkey";
Assert.AreEqual ("monkey", css["mono"], "this[string]");
Assert.IsNotNull (css.Keys, "Keys");
css.Add ("monkey", "mono");
css.Remove ("monkey");
css.Clear ();
#if NET_2_0
css[HtmlTextWriterStyle.Top] = "1";
Assert.AreEqual ("1", css[HtmlTextWriterStyle.Top], "this[HtmlTextWriterStyle]");
Assert.IsNotNull (css.Value, "Value");
css.Value = String.Empty;
css.Add (HtmlTextWriterStyle.Left, "1");
css.Remove (HtmlTextWriterStyle.Left);
#endif
}
// LinkDemand
public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
{
// no public ctor is available but we know the Count property isn't protected
MethodInfo mi = this.Type.GetProperty ("Count").GetGetMethod ();
Assert.IsNotNull (mi, "Count");
return mi.Invoke (css, null);
}
public override Type Type {
get { return typeof (CssStyleCollection); }
}
}
}

View File

@ -0,0 +1,196 @@
//
// Tests for System.Web.UI.CssStyleCollection.cs
//
// Author:
// Igor Zelmanovich (igorz@mainsoft.com)
//
//
// Copyright (C) 2006 Mainsoft, Inc (http://www.mainsoft.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Collections;
using System.Drawing;
using System.IO;
using System.Globalization;
using refl = System.Reflection;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Specialized;
using System.Text;
namespace MonoTests.System.Web.UI
{
[TestFixture]
public class CssStyleCollectionTest
{
#if NET_2_0
[Test]
public void CssStyleCollection_BackgroundImage () {
WebControl c = new WebControl (HtmlTextWriterTag.A);
CssStyleCollection css = c.Style;
string url = "http://www.go-mono.com/space here?key1=val1&key2=val2";
string url_encoded = "http://www.go-mono.com/space%20here?key1=val1&key2=val2";
css.Add (HtmlTextWriterStyle.BackgroundImage, url);
Assert.AreEqual (url, css ["background-image"], "CssStyleCollection_BackgroundImage#1");
Assert.AreEqual ("background-image:url(" + url_encoded + ");", css.Value, "CssStyleCollection_BackgroundImage#3");
Assert.AreEqual ("background-image:url(" + url_encoded + ");", c.Attributes["style"], "CssStyleCollection_BackgroundImage#4");
}
#endif
[Test]
public void CssStyleCollection_BackgroundImage2 () {
WebControl c = new WebControl (HtmlTextWriterTag.A);
CssStyleCollection css = c.Style;
string url = "http://www.go-mono.com/space here?key1=val1&key2=val2";
string url_encoded = "http://www.go-mono.com/space%20here?key1=val1&key2=val2";
css.Add ("background-image", url);
Assert.AreEqual (url, css ["background-image"], "CssStyleCollection_BackgroundImage#1");
#if NET_2_0
Assert.AreEqual ("background-image:url(" + url_encoded + ");", css.Value, "CssStyleCollection_BackgroundImage#3");
#endif
Assert.AreEqual ("background-image:url(" + url_encoded + ");", c.Attributes ["style"], "CssStyleCollection_BackgroundImage#4");
}
[Test]
public void CssStyleCollection_BackgroundImage3 () {
WebControl c = new WebControl (HtmlTextWriterTag.A);
CssStyleCollection css = c.Style;
string url = "http://www.go-mono.com/space here?key1=val1&key2=val2";
string url_encoded = "http://www.go-mono.com/space%20here?key1=val1&key2=val2";
css.Add ("background-image", "url(" + url_encoded + ")");
Assert.AreEqual ("url(" + url_encoded + ")", css ["background-image"], "CssStyleCollection_BackgroundImage#1");
#if NET_2_0
Assert.AreEqual ("background-image:url(" + url_encoded + ");", css.Value, "CssStyleCollection_BackgroundImage#3");
#endif
Assert.AreEqual ("background-image:url(" + url_encoded + ");", c.Attributes ["style"], "CssStyleCollection_BackgroundImage#4");
}
[Test]
public void CssStyleCollection_BackgroundImage4 () {
WebControl c = new WebControl (HtmlTextWriterTag.A);
CssStyleCollection css = c.Style;
string url = "http://www.go-mono.com/space here?key1=val1&key2=val2";
string url_encoded = "http://www.go-mono.com/space%20here?key1=val1&key2=val2";
c.Attributes ["style"] = "background-image:url(" + url_encoded + ");";
Assert.AreEqual ("url(" + url_encoded + ")", css ["background-image"], "CssStyleCollection_BackgroundImage#1");
#if NET_2_0
Assert.AreEqual ("background-image:url(" + url_encoded + ");", css.Value, "CssStyleCollection_BackgroundImage#3");
#endif
Assert.AreEqual ("background-image:url(" + url_encoded + ");", c.Attributes ["style"], "CssStyleCollection_BackgroundImage#4");
}
[Test]
public void CssStyleCollection_Enumerator () {
WebControl c = new WebControl (HtmlTextWriterTag.A);
c.BackColor = Color.Beige;
c.ForeColor = Color.Brown;
c.Font.Bold = true;
c.Attributes ["style"] = "padding: 0px; margin: 0px";
Assert.AreEqual (2, c.Style.Count, "Style Count");
#if NET_2_0
Assert.AreEqual (3, c.ControlStyle.GetStyleAttributes (c).Count, "ControlStyle Count");
#endif
CssStyleCollection col = c.Style;
NameValueCollection styles = new NameValueCollection ();
foreach (string key in col.Keys) {
styles [key] = col [key];
}
Assert.AreEqual ("0px", styles ["padding"], "Style padding");
Assert.AreEqual ("0px",styles ["margin"], "Style margin");
}
[Test]
public void CssStyleCollection_Style_Attribute () {
WebControl c = new WebControl (HtmlTextWriterTag.A);
Assert.IsTrue (Object.ReferenceEquals (c.Style, c.Attributes.CssStyle));
// style attribute is parsed to CssStyleCollection
c.Attributes.Add ("style", "padding: 1px; margin: 2px");
Assert.AreEqual (2, c.Style.Count, "Style Count");
Assert.AreEqual ("1px", c.Style ["padding"], "");
Assert.AreEqual ("2px", c.Style ["margin"], "");
// CssStyleCollection is merged to style attribute
c.Style.Add ("color", "red");
Assert.AreEqual (3, c.Style.Count, "Style Count");
Assert.AreEqual ("red", c.Style ["color"], "");
Assert.IsTrue (c.Attributes ["style"].IndexOf("color:")>=0);
// replacing style attribute replaces CssStyleCollection's items
c.Attributes ["style"] = "align: center";
Assert.AreEqual (1, c.Style.Count, "Style Count");
Assert.AreEqual ("center", c.Style ["align"], "");
// removing style attribute clears CssStyleCollection
c.Attributes.Remove("style");
Assert.AreEqual (0, c.Style.Count, "Style Count");
// adding to CssStyleCollection create style attribute
c.Style.Add ("color", "red");
Assert.AreEqual (1, c.Attributes.Count, "Attributes Count");
c.Attributes ["style"] = "align: center; color: red;";
Assert.AreEqual (2, c.Style.Count, "Style Count");
Assert.AreEqual ("center", c.Style ["align"], "");
Assert.AreEqual ("red", c.Style ["color"], "");
// clearing CssStyleCollection removes style attribute
c.Style.Clear ();
Assert.AreEqual (0, c.Attributes.Count, "Attributes Count");
}
[Test]
public void CssStyleCollection_case_sensitive () {
WebControl c = new WebControl (HtmlTextWriterTag.A);
c.Style.Add ("color", "red");
#if NET_2_0
Assert.AreEqual ("red", c.Style ["Color"], "");
#else
Assert.AreEqual (null, c.Style ["Color"], "");
Assert.AreEqual ("red", c.Style ["color"], "");
#endif
c.Style.Add ("Color", "Blue");
#if NET_2_0
Assert.AreEqual ("Blue", c.Style ["color"], "");
Assert.AreEqual (1, c.Style.Count, "Style Count");
#else
Assert.AreEqual ("red", c.Style ["color"], "");
Assert.AreEqual ("Blue", c.Style ["Color"], "");
Assert.AreEqual (2, c.Style.Count, "Style Count");
#endif
}
}
}

View File

@ -0,0 +1,102 @@
//
// DataBinderCas.cs - CAS unit tests for System.Web.UI.DataBinder
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Collections;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
namespace MonoCasTests.System.Web.UI {
[TestFixture]
[Category ("CAS")]
public class DataBinderCas : AspNetHostingMinimal {
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Eval_Deny_Unrestricted ()
{
Assert.IsNull (DataBinder.Eval (null, "Data"), "Eval(object,string)");
Assert.AreEqual (String.Empty, DataBinder.Eval (null, "Data", null), "Eval(object,string,string)");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (ArgumentNullException))]
public void GetIndexedPropertyValue2_Deny_Unrestricted ()
{
DataBinder.GetIndexedPropertyValue (null, "Data");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (ArgumentNullException))]
public void GetIndexedPropertyValue3_Deny_Unrestricted ()
{
DataBinder.GetIndexedPropertyValue (null, "Data", "{0}");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (ArgumentNullException))]
public void GetPropertyValue2_Deny_Unrestricted ()
{
DataBinder.GetPropertyValue (null, "Data");
Assert.IsNull (DataBinder.GetPropertyValue (null, "Data", "{0}"), "GetPropertyValue(object,string,string)");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (ArgumentNullException))]
public void GetPropertyValue3_Deny_Unrestricted ()
{
DataBinder.GetPropertyValue (null, "Data", "{0}");
}
#if NET_2_0
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void GetDataItem_Deny_Unrestricted ()
{
Assert.IsNull (DataBinder.GetDataItem (null), "GetDataItem(object)");
bool found = true;
Assert.IsNull (DataBinder.GetDataItem (null, out found), "GetDataItem(object,out bool)");
Assert.IsFalse (found, "found");
}
#endif
// LinkDemand
public override Type Type {
get { return typeof (DataBinder); }
}
}
}

View File

@ -0,0 +1,176 @@
//
// DataBinderTest.cs
//
// Author:
// Marek Habersack (mhabersack@novell.com)
//
// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Collections;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
namespace MonoTests.System.Web.UI
{
class InnerObject
{
public string Property {
get { return "InnerObject.Property"; }
}
public string InnerProperty {
get { return "InnerObject.InnerProperty"; }
}
}
class OuterObject
{
InnerObject inner;
ArrayList items;
public InnerObject InnerObject {
get { return inner; }
}
public string Property {
get { return "OuterObject.Property"; }
}
public IList Items {
get { return items; }
}
public OuterObject ()
{
inner = new InnerObject ();
items = new ArrayList ();
items.Add ("Item One");
items.Add ("Item Two");
}
}
class IndexedOuterObject : OuterObject
{
public string this [int index] {
get { return Items [index] as string; }
}
}
[TestFixture]
public class DataBinderTest
{
[Test]
public void DataBinder_Eval ()
{
IndexedOuterObject oo = new IndexedOuterObject ();
object val;
val = DataBinder.Eval (oo, "Property");
Assert.IsTrue (val is string, "#A1");
Assert.AreEqual ("OuterObject.Property", val, "#A2");
val = DataBinder.Eval (oo, "InnerObject.Property");
Assert.IsTrue (val is string, "#B1");
Assert.AreEqual ("InnerObject.Property", val, "#B2");
val = DataBinder.Eval (oo, "InnerObject.InnerProperty");
Assert.IsTrue (val is string, "#C1");
Assert.AreEqual ("InnerObject.InnerProperty", val, "#C2");
val = DataBinder.Eval (oo, "Items[0]");
Assert.IsTrue (val is string, "#D1");
Assert.AreEqual ("Item One", val, "#D2");
val = DataBinder.Eval (oo, "[1]");
Assert.IsTrue (val is string, "#E1");
Assert.AreEqual ("Item Two", val, "#E2");
Hashtable hash = new Hashtable ();
hash.Add ("item1", "Item One");
val = DataBinder.Eval (hash, "[item1]");
Assert.IsTrue (val is string, "#F1");
Assert.AreEqual ("Item One", val, "#F2");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void DataBinder_Eval_NoIndexer ()
{
OuterObject oo = new OuterObject ();
object val = DataBinder.Eval (oo, "[1]");
}
[Test]
[ExpectedException (typeof (HttpException))]
public void DataBinder_Eval_MissingProperty ()
{
OuterObject oo = new OuterObject ();
object val = DataBinder.Eval (oo, "InternalObject.Property");
}
[Test]
[ExpectedException (typeof (HttpException))]
public void DataBinder_Eval_InvalidIndexedPropertyName ()
{
OuterObject oo = new OuterObject ();
object val = DataBinder.Eval (oo, "Items [0]");
}
[Test]
[ExpectedException (typeof (HttpException))]
public void DataBinder_Eval_MissingIndexedPropertyName ()
{
OuterObject oo = new OuterObject ();
object val = DataBinder.Eval (oo, "MyItems[0]");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void DataBinder_Eval_InvalidIndexedPropertyIndexerType ()
{
OuterObject oo = new OuterObject ();
object val = DataBinder.Eval (oo, "Items['item']");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void DataBinder_Eval_InvalidIndexerType ()
{
OuterObject oo = new OuterObject ();
object val = DataBinder.Eval (oo, "[\"item\"]");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void DataBinder_Eval_InvalidIndexerType2 ()
{
OuterObject oo = new OuterObject ();
object val = DataBinder.Eval (oo, "[item]");
}
}
}

View File

@ -0,0 +1,72 @@
//
// DataBindingCas.cs - CAS unit tests for System.Web.UI.DataBinding
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Collections;
using System.Reflection;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
namespace MonoCasTests.System.Web.UI {
[TestFixture]
[Category ("CAS")]
public class DataBindingCas : AspNetHostingMinimal {
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
DataBinding db = new DataBinding ("property", typeof (string), String.Empty);
db.Expression = "expression";
Assert.AreEqual ("expression", db.Expression, "Expression");
Assert.AreEqual ("property", db.PropertyName, "PropertyName");
Assert.AreEqual (typeof (string), db.PropertyType, "PropertyType");
Assert.IsTrue (db.Equals (db), "Equals");
Assert.IsTrue (db.GetHashCode () != 0, "GetHashCode"); // likely
}
// LinkDemand
public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
{
ConstructorInfo ci = this.Type.GetConstructor (new Type[3] { typeof (string), typeof (Type), typeof (string) });
Assert.IsNotNull (ci, ".ctor(String,Type,String)");
return ci.Invoke (new object[3] { String.Empty, typeof (string), String.Empty });
}
public override Type Type {
get { return typeof (DataBinding); }
}
}
}

Some files were not shown because too many files have changed in this diff Show More