| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- //
- // System.Xml.XmlReaderSettingsTests.cs
- //
- // Authors:
- // Atsushi Enomoto <[email protected]>
- //
- // (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
|