Files
mono/mcs/class/System.XML/Test/System.Xml/XsdParticleValidationTests.cs
T
Atsushi Eno 229aad73ed 2004-01-28 Atsushi Enomoto <[email protected]>
* XmlDocumentTypeTests.cs : Added IncorrectInternalSubset().
	* XmlNodeTests.cs : Since .NET 1.1 also prohibits multiple document
	  element, removed extraneous test switch for InsertBefore().
	* XsdParticleValidationTests.cs,
	  XsdValidatingReaderTests.cs : These test class names are too
	  ambiguous so just renamed them. (No bug reports are found on them,
	  but should be warned in the meantime.)

svn path=/trunk/mcs/; revision=22568
2004-01-28 07:26:43 +00:00

223 lines
5.7 KiB
C#

//
// MonoTests.System.Xml.XsdParticleValidationTests.cs
//
// Author:
// Atsushi Enomoto <[email protected]>
//
// (C)2003 Atsushi Enomoto
//
using System;
using System.Xml;
using System.Xml.Schema;
using NUnit.Framework;
namespace MonoTests.System.Xml
{
// using XmlValidatingReader = XmlTextReader;
[TestFixture]
public class XsdParticleValidationTests : Assertion
{
XmlSchema schema;
XmlReader xr;
XmlValidatingReader xvr;
private void PrepareReader1 (string xsdUrl, string xml)
{
schema = XmlSchema.Read (new XmlTextReader ("Test/XmlFiles/XsdValidation/" + xsdUrl), null);
xr = new XmlTextReader (xml, XmlNodeType.Document, null);
xvr = new XmlValidatingReader (xr);
xvr.Schemas.Add (schema);
// xvr = xr as XmlValidatingReader;
}
[Test]
public void ValidateRootElementOnlyValid ()
{
PrepareReader1 ("1.xsd", "<root xmlns='urn:foo' />");
xvr.Read ();
PrepareReader1 ("1.xsd", "<root xmlns='urn:foo'></root>");
xvr.Read ();
xvr.Read ();
}
[Test]
[ExpectedException (typeof (XmlSchemaException))]
public void ValidateRootElementOnlyInvalid ()
{
PrepareReader1 ("1.xsd", "<invalid xmlns='urn:foo' />");
xvr.Read ();
}
[Test]
[ExpectedException (typeof (XmlSchemaException))]
public void ValidateRootElementOnlyInvalid2 ()
{
PrepareReader1 ("1.xsd", "<root xmlns='urn:foo'><invalid_child/></root>");
xvr.Read ();
xvr.Read ();
}
[Test]
public void ValidateElementContainsElementValid1 ()
{
PrepareReader1 ("2.xsd", "<root xmlns='urn:foo'><child/></root>");
while (!xvr.EOF)
xvr.Read ();
}
[Test]
public void ValidateElementContainsElementValid2 ()
{
PrepareReader1 ("2.xsd", "<root xmlns='urn:foo'><child/><child/></root>");
while (!xvr.EOF)
xvr.Read ();
}
[Test]
[ExpectedException (typeof (XmlSchemaException))]
public void ValidateElementContainsElementInvalid1 ()
{
PrepareReader1 ("2.xsd", "<root xmlns='urn:foo'></root>");
while (!xvr.EOF)
xvr.Read ();
}
[Test]
[ExpectedException (typeof (XmlSchemaException))]
public void ValidateElementContainsElementInvalid2 ()
{
PrepareReader1 ("2.xsd", "<root xmlns='urn:foo'><child/><child/><child/></root>");
while (!xvr.EOF)
xvr.Read ();
}
[Test]
public void ValidateSequenceValid ()
{
PrepareReader1 ("3.xsd", "<root xmlns='urn:foo'><child1/><child2/></root>");
while (!xvr.EOF)
xvr.Read ();
PrepareReader1 ("3.xsd", "<root xmlns='urn:foo'><child1/><child2/><child1/><child2/></root>");
while (!xvr.EOF)
xvr.Read ();
}
[Test]
[ExpectedException (typeof (XmlSchemaException))]
public void ValidateSequenceInvalid1 ()
{
PrepareReader1 ("3.xsd", "<root xmlns='urn:foo'></root>");
while (!xvr.EOF)
xvr.Read ();
}
[Test]
[ExpectedException (typeof (XmlSchemaException))]
public void ValidateSequenceInvalid2 ()
{
PrepareReader1 ("3.xsd", "<root xmlns='urn:foo'><child1/></root>");
while (!xvr.EOF)
xvr.Read ();
}
[Test]
[ExpectedException (typeof (XmlSchemaException))]
public void ValidateSequenceInvalid3 ()
{
PrepareReader1 ("3.xsd", "<root xmlns='urn:foo'><child1/><child2/><child1/></root>");
while (!xvr.EOF)
xvr.Read ();
}
[Test]
[ExpectedException (typeof (XmlSchemaException))]
public void ValidateSequenceInvalid4 ()
{
PrepareReader1 ("3.xsd", "<root xmlns='urn:foo'><child1/><child2/><child1/><child2/><child1/></root>");
while (!xvr.EOF)
xvr.Read ();
}
[Test]
[ExpectedException (typeof (XmlSchemaException))]
public void ValidateSequenceInvalid5 ()
{
PrepareReader1 ("3.xsd", "<root xmlns='urn:foo'><child1/><child2/><child1/><child2/><child1/><child2/></root>");
while (!xvr.EOF)
xvr.Read ();
}
[Test]
public void ValidateChoiceValid ()
{
PrepareReader1 ("4.xsd", "<root xmlns='urn:foo'><child1/></root>");
while (!xvr.EOF)
xvr.Read ();
PrepareReader1 ("4.xsd", "<root xmlns='urn:foo'><child2/></root>");
while (!xvr.EOF)
xvr.Read ();
PrepareReader1 ("4.xsd", "<root xmlns='urn:foo'><child1/><child2/></root>");
while (!xvr.EOF)
xvr.Read ();
PrepareReader1 ("4.xsd", "<root xmlns='urn:foo'><child2/><child2/></root>");
while (!xvr.EOF)
xvr.Read ();
PrepareReader1 ("4.xsd", "<root xmlns='urn:foo'><child2/><child2/><child2/><child2/></root>");
while (!xvr.EOF)
xvr.Read ();
PrepareReader1 ("4.xsd", "<root xmlns='urn:foo'><child2/><child2/><child1/></root>");
while (!xvr.EOF)
xvr.Read ();
PrepareReader1 ("4.xsd", "<root xmlns='urn:foo'></root>");
while (!xvr.EOF)
xvr.Read ();
}
[Test]
[ExpectedException (typeof (XmlSchemaException))]
public void ValidateChoiceInvalid1 ()
{
PrepareReader1 ("4.xsd", "<root xmlns='urn:foo'><child1/><child1/><child1/></root>");
while (!xvr.EOF)
xvr.Read ();
}
[Test]
[ExpectedException (typeof (XmlSchemaException))]
public void ValidateChoiceInvalid2 ()
{
PrepareReader1 ("3.xsd", "<root xmlns='urn:foo'><child2/><child2/><child2/><child2/><child2/></root>");
while (!xvr.EOF)
xvr.Read ();
}
[Test]
[ExpectedException (typeof (XmlSchemaException))]
public void ValidateChoiceInvalid3 ()
{
PrepareReader1 ("3.xsd", "<root xmlns='urn:foo'><child2/><child2/><child2/><child1/></root>");
while (!xvr.EOF)
xvr.Read ();
}
[Test]
[ExpectedException (typeof (XmlSchemaException))]
public void ValidateChoiceInvalid4 ()
{
PrepareReader1 ("3.xsd", "<root xmlns='urn:foo'><child1/><child2/><child2/><child2/></root>");
while (!xvr.EOF)
xvr.Read ();
}
}
}