diff options
author | Atsushi Eno <atsushieno@gmail.com> | 2004-09-07 10:34:56 +0400 |
---|---|---|
committer | Atsushi Eno <atsushieno@gmail.com> | 2004-09-07 10:34:56 +0400 |
commit | 4513f3ed86e53fe1ffcaa9b22481f44bda4a6111 (patch) | |
tree | 613265e61379d93483f1acd46f3dbde3bfe582bf | |
parent | e38f6d2220c9dc93ac2c3887bce3581c6a0d9d8c (diff) |
2004-09-07 Atsushi Enomoto <atsushi@ximian.com>
* XmlReaderSettingsTests.cs : added, including XmlReader.Create() tests
* XmlTextReaderTests.cs : added normalization and Setting sests.
svn path=/trunk/mcs/; revision=33473
3 files changed, 152 insertions, 0 deletions
diff --git a/mcs/class/System.XML/Test/System.Xml/ChangeLog b/mcs/class/System.XML/Test/System.Xml/ChangeLog index c57dde010ec..c284b4ba958 100644 --- a/mcs/class/System.XML/Test/System.Xml/ChangeLog +++ b/mcs/class/System.XML/Test/System.Xml/ChangeLog @@ -1,3 +1,8 @@ +2004-09-07 Atsushi Enomoto <atsushi@ximian.com> + + * XmlReaderSettingsTests.cs : added, including XmlReader.Create() tests + * XmlTextReaderTests.cs : added normalization and Setting sests. + 2004-09-06 Atsushi Enomoto <atsushi@ximian.com> * XmlElementTests.cs : added another set_InnerXml test. diff --git a/mcs/class/System.XML/Test/System.Xml/XmlReaderSettingsTests.cs b/mcs/class/System.XML/Test/System.Xml/XmlReaderSettingsTests.cs new file mode 100755 index 00000000000..f367ae51efd --- /dev/null +++ b/mcs/class/System.XML/Test/System.Xml/XmlReaderSettingsTests.cs @@ -0,0 +1,127 @@ +// +// System.Xml.XmlReaderSettingsTests.cs +// +// Authors: +// Atsushi Enomoto <atsushi@ximian.com> +// +// (C)2004 Novell Inc. +// + +#if NET_2_0 +using System; +using System.IO; +using System.Xml; +using System.Xml.Schema; +using NUnit.Framework; + +namespace MonoTests.System.Xml +{ + [TestFixture] + public class XmlReaderSettingsTests : Assertion + { + [Test] + public void DefaultValue () + { + XmlReaderSettings s = new XmlReaderSettings (); + AssertEquals (true, s.CheckCharacters); + AssertEquals (ConformanceLevel.Document, s.ConformanceLevel); + AssertEquals (false, s.DtdValidate); + AssertEquals (false, s.IgnoreComments); + AssertEquals (true, s.IgnoreInlineSchema); + AssertEquals (false, s.IgnoreProcessingInstructions); + AssertEquals (true, s.IgnoreSchemaLocation); + AssertEquals (true, s.IgnoreValidationWarnings); + AssertEquals (false, s.IgnoreWhitespace); + AssertEquals (0, s.LineNumberOffset); + AssertEquals (0, s.LinePositionOffset); + AssertNull (s.NameTable); + AssertEquals (0, s.Schemas.Count); + AssertEquals (false, s.XsdValidate); + } + + [Test] + [ExpectedException (typeof (XmlException))] + public void SetSchemas () + { + XmlReaderSettings s = new XmlReaderSettings (); + s.Schemas = new XmlSchemaSet (); + } + + [Test] + public void CloseInput () + { + StringReader sr = new StringReader ("<root/><root/>"); + XmlReader xtr = XmlReader.Create (sr); // default false + xtr.Read (); + xtr.Close (); + // It should without error, unlike usual XmlTextReader. + sr.ReadLine (); + } + + [Test] + public void CreateAndNormalization () + { + StringReader sr = new StringReader ( + "<root attr=' value '>test\rstring</root>"); + XmlReaderSettings settings = new XmlReaderSettings (); + settings.CheckCharacters = false; + XmlReader xtr = XmlReader.Create ( + sr, null, null, settings); + xtr.Read (); + xtr.MoveToFirstAttribute (); + AssertEquals (" value ", xtr.Value); + xtr.Read (); + // Text string is normalized + AssertEquals ("test\nstring", xtr.Value); + } + + [Test] + public void CheckCharactersAndNormalization () + { + // It should *not* raise an error (even Normalization + // is set by default). + StringReader sr = new StringReader ( + "<root attr='�'>�</root>"); + XmlReaderSettings settings = new XmlReaderSettings (); + settings.CheckCharacters = false; + XmlReader xtr = XmlReader.Create ( + sr, null, null, settings); + // After creation, changes on source XmlReaderSettings + // does not matter. + settings.CheckCharacters = false; + xtr.Read (); + xtr.MoveToFirstAttribute (); + AssertEquals ("\0", xtr.Value); + xtr.Read (); + AssertEquals ("\0", xtr.Value); + } + + // Hmm, does it really make sense? :-/ + [Test] + public void CheckCharactersForNonTextReader () + { + // It should *not* raise an error (even Normalization + // is set by default). + StringReader sr = new StringReader ( + "<root attr='�'>�</root>"); + XmlReaderSettings settings = new XmlReaderSettings (); + settings.CheckCharacters = false; + XmlReader xr = XmlReader.Create ( + sr, null, null, settings); + + // Enable character checking for XmlNodeReader. + settings.CheckCharacters = true; + XmlDocument doc = new XmlDocument (); + doc.Load (xr); + xr = XmlReader.Create (new XmlNodeReader (doc), settings); + + // But it won't work against XmlNodeReader. + xr.Read (); + xr.MoveToFirstAttribute (); + AssertEquals ("\0", xr.Value); + xr.Read (); + AssertEquals ("\0", xr.Value); + } + } +} +#endif diff --git a/mcs/class/System.XML/Test/System.Xml/XmlTextReaderTests.cs b/mcs/class/System.XML/Test/System.Xml/XmlTextReaderTests.cs index a37e60f4c67..cfe1bcef0c2 100644 --- a/mcs/class/System.XML/Test/System.Xml/XmlTextReaderTests.cs +++ b/mcs/class/System.XML/Test/System.Xml/XmlTextReaderTests.cs @@ -843,6 +843,19 @@ namespace MonoTests.System.Xml } [Test] + public void NormalizationAttributes () + { + // does not normalize attribute values. + StringReader sr = new StringReader ("<!DOCTYPE root [<!ELEMENT root EMPTY><!ATTLIST root attr ID #IMPLIED>]><root attr=' value '/>"); + XmlTextReader xtr = new XmlTextReader (sr); + xtr.Normalization = true; + xtr.Read (); + xtr.Read (); + xtr.MoveToFirstAttribute (); + AssertEquals (" value ", xtr.Value); + } + + [Test] public void CloseIsNotAlwaysEOF () { // See bug #63505 @@ -897,6 +910,13 @@ namespace MonoTests.System.Xml while (!xtr.EOF) xtr.Read (); } + + [Test] + public void Settings () + { + XmlTextReader xtr = new XmlTextReader ("<root/>", XmlNodeType.Document, null); + AssertNull (xtr.Settings); + } #endif } } |