Update of /cvsroot/mvp-xml/XInclude/v1/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32016/v1/test Modified Files: Elliotte_Rusty_HaroldTests.cs EntryPoint.cs NistTests.cs XIncludeReaderTests.cs XIncludeSyntaxTests.cs XIncludeTest.csproj Log Message: Optimizations/Simplifications. Index: XIncludeTest.csproj =================================================================== RCS file: /cvsroot/mvp-xml/XInclude/v1/test/XIncludeTest.csproj,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- XIncludeTest.csproj 2 Nov 2004 14:31:57 -0000 1.12 +++ XIncludeTest.csproj 3 Nov 2004 12:55:46 -0000 1.13 @@ -171,6 +171,10 @@ BuildAction = "Content" /> <File + RelPath = "results\resolver.xml" + BuildAction = "Content" + /> + <File RelPath = "results\working_example.xml" BuildAction = "Content" /> Index: EntryPoint.cs =================================================================== RCS file: /cvsroot/mvp-xml/XInclude/v1/test/EntryPoint.cs,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- EntryPoint.cs 2 Nov 2004 14:31:57 -0000 1.13 +++ EntryPoint.cs 3 Nov 2004 12:55:46 -0000 1.14 @@ -9,15 +9,15 @@ { public static void Main() { - XIncludeReaderTests rt = new XIncludeReaderTests(); + //XIncludeReaderTests rt = new XIncludeReaderTests(); //LTG_Edinburgh_UnivTests rt = new LTG_Edinburgh_UnivTests(); - //NISTTests rt = new NISTTests(); + NISTTests rt = new NISTTests(); //Elliotte_Rusty_HaroldTests rt = new Elliotte_Rusty_HaroldTests(); //FourThoughtTests rt = new FourThoughtTests(); //XIncludeSyntaxTests rt = new XIncludeSyntaxTests(); try { - rt.XmlLangTest(); + rt.Nist_include_24(); } catch (Exception e) { Index: XIncludeSyntaxTests.cs =================================================================== RCS file: /cvsroot/mvp-xml/XInclude/v1/test/XIncludeSyntaxTests.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- XIncludeSyntaxTests.cs 1 Nov 2004 05:44:44 -0000 1.4 +++ XIncludeSyntaxTests.cs 3 Nov 2004 12:55:46 -0000 1.5 @@ -22,7 +22,7 @@ /// No href and no xpointer attribute. /// </summary> [Test] - [ExpectedException(typeof(MissingHrefAndXpointerException))] + [ExpectedException(typeof(XIncludeSyntaxError))] public void NoHrefAndNoXPointerAttributes() { XIncludingReader xir = new XIncludingReader("../../tests/nohref.xml"); @@ -58,7 +58,7 @@ /// Unknown value of parse attribute. /// </summary> [Test] - [ExpectedException(typeof(UnknownParseAttributeValueException))] + [ExpectedException(typeof(XIncludeSyntaxError))] public void UnknownParseAttribute() { XIncludingReader xir = new XIncludingReader("../../tests/unknownparseattr.xml"); Index: Elliotte_Rusty_HaroldTests.cs =================================================================== RCS file: /cvsroot/mvp-xml/XInclude/v1/test/Elliotte_Rusty_HaroldTests.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- Elliotte_Rusty_HaroldTests.cs 2 Nov 2004 14:31:57 -0000 1.7 +++ Elliotte_Rusty_HaroldTests.cs 3 Nov 2004 12:55:42 -0000 1.8 @@ -306,7 +306,7 @@ /// A fallback element in an included document contains an include element with a parse attribute with an illegal value. /// </summary> [Test] - [ExpectedException(typeof(UnknownParseAttributeValueException))] + [ExpectedException(typeof(XIncludeSyntaxError))] public void harold_23() { RunAndCompare("metafallbacktest3.xml", ""); @@ -318,7 +318,7 @@ /// A fallback element in an included document contains an include element with neither an xpointer nor an href attribute. /// </summary> [Test] - [ExpectedException(typeof(MissingHrefAndXpointerException))] + [ExpectedException(typeof(XIncludeSyntaxError))] public void harold_24() { RunAndCompare("metafallbacktest4.xml", ""); @@ -331,7 +331,7 @@ /// A fallback element in an included document contains an include element whose href attribute has a fragment ID. /// </summary> [Test] - [ExpectedException(typeof(FragmentIdentifierInHrefAttribute))] + [ExpectedException(typeof(XIncludeSyntaxError))] public void harold_25() { RunAndCompare("metafallbacktestwithfragmentid.xml", ""); @@ -644,7 +644,7 @@ /// Include element is missing an href and xpointer attribute /// </summary> [Test] - [ExpectedException(typeof(MissingHrefAndXpointerException))] + [ExpectedException(typeof(XIncludeSyntaxError))] public void harold_51() { RunAndCompare("missinghref.xml", ""); @@ -656,7 +656,7 @@ /// parse attribute must have value xml or text /// </summary> [Test] - [ExpectedException(typeof(UnknownParseAttributeValueException))] + [ExpectedException(typeof(XIncludeSyntaxError))] public void harold_52() { RunAndCompare("badparseattribute.xml", ""); @@ -885,7 +885,7 @@ /// Syntax error in an XPointer is a resource error; and fatal because there's no fallback /// </summary> [Test] - [ExpectedException(typeof(FragmentIdentifierInHrefAttribute))] + [ExpectedException(typeof(XIncludeSyntaxError))] public void harold_71() { RunAndCompare("badxptr2.xml", ""); @@ -1030,7 +1030,7 @@ /// href attribute with fragment ID is a fatal error even when there's an xpointer attribute /// </summary> [Test] - [ExpectedException(typeof(FragmentIdentifierInHrefAttribute))] + [ExpectedException(typeof(XIncludeSyntaxError))] public void harold_83() { RunAndCompare("xpointeroverridesfragmentid.xml", ""); @@ -1042,7 +1042,7 @@ /// href attribute with fragment ID is a fatal error /// </summary> [Test] - [ExpectedException(typeof(FragmentIdentifierInHrefAttribute))] + [ExpectedException(typeof(XIncludeSyntaxError))] public void harold_84() { RunAndCompare("ignoresfragmentid.xml", ""); @@ -1066,7 +1066,7 @@ /// syntax of fragment IDs from RFC 2396. /// </summary> [Test] - [ExpectedException(typeof(FragmentIdentifierInHrefAttribute))] + [ExpectedException(typeof(XIncludeSyntaxError))] public void harold_86() { RunAndCompare("meaninglessfragmentid.xml", ""); @@ -1168,7 +1168,7 @@ /// Included document has an include element with neither href nor xpointer attribute /// </summary> [Test] - [ExpectedException(typeof(MissingHrefAndXpointerException))] + [ExpectedException(typeof(XIncludeSyntaxError))] public void harold_94() { RunAndCompare("toplevel.xml", ""); Index: XIncludeReaderTests.cs =================================================================== RCS file: /cvsroot/mvp-xml/XInclude/v1/test/XIncludeReaderTests.cs,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- XIncludeReaderTests.cs 2 Nov 2004 14:31:57 -0000 1.13 +++ XIncludeReaderTests.cs 3 Nov 2004 12:55:46 -0000 1.14 @@ -29,16 +29,25 @@ { RunAndCompare(source, result, false); } - + /// <summary> /// Utility method for running tests. /// </summary> public static void RunAndCompare(string source, string result, bool textAsCDATA) + { + RunAndCompare(source, result, textAsCDATA, null); + } + + /// <summary> + /// Utility method for running tests. + /// </summary> + public static void RunAndCompare(string source, string result, bool textAsCDATA, XmlResolver resolver) { XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = true; XIncludingReader xir = new XIncludingReader(source); - + if (resolver != null) + xir.XmlResolver = resolver; xir.ExposeTextInclusionsAsCDATA = textAsCDATA; // while (xir.Read()) // { @@ -70,6 +79,7 @@ while (r2.NodeType == XmlNodeType.XmlDeclaration || r2.NodeType == XmlNodeType.Whitespace) r2.Read(); + Assert.AreEqual(r1.XmlLang, r2.XmlLang); switch (r1.NodeType) { case XmlNodeType.Attribute: @@ -145,15 +155,7 @@ r1 = null; r2.Close(); r2 = null; - StreamReader sr = new StreamReader(result); - string expectedResult = sr.ReadToEnd(); - sr.Close(); - MemoryStream ms = new MemoryStream(); - doc.Save(new StreamWriter(ms, Encoding.UTF8)); - ms.Position = 0; - string actualResult = new StreamReader(ms).ReadToEnd(); - Console.WriteLine("\n-----------Expected result:-----------\n{0}", expectedResult); - Console.WriteLine("-----------Actual result:-----------\n{0}", actualResult); + ReportResults(result, doc); throw e; } finally @@ -163,7 +165,21 @@ if (r2 != null) r2.Close(); } - } + ReportResults(result, doc); + } + + private static void ReportResults(string expected, XmlDocument actual) + { + StreamReader sr = new StreamReader(expected); + string expectedResult = sr.ReadToEnd(); + sr.Close(); + MemoryStream ms = new MemoryStream(); + actual.Save(new StreamWriter(ms, Encoding.UTF8)); + ms.Position = 0; + string actualResult = new StreamReader(ms).ReadToEnd(); + Console.WriteLine("\n-----------Expected result:-----------\n{0}", expectedResult); + Console.WriteLine("-----------Actual result:-----------\n{0}", actualResult); + } /// <summary> /// General test - it should work actually. @@ -256,7 +272,7 @@ [Test] public void XmlLangTest() { - RunAndCompare("../../tests/langtest.xml", "../../results/langtest.xml"); + RunAndCompare("../../tests/langtest.xml", "../../results/langtest.xml"); } /// <summary> @@ -315,14 +331,34 @@ Assert.AreEqual(sb.ToString(), expected); } -// /// <summary> -// /// Custom resolver test. -// /// </summary> -// [Test] -// public void CustomResolver() -// { -// RunAndCompare("../../tests/resolver.xml", "../../results/resolver.xml"); -// } + /// <summary> + /// Custom resolver test. + /// </summary> + [Test] + public void CustomResolver() + { + RunAndCompare("../../tests/resolver.xml", "../../results/resolver.xml", false, new TestResolver()); + } + + } + + public class TestResolver : XmlUrlResolver + { + public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn) + { + if (absoluteUri.Scheme == "textreader") + return new StringReader(@"<text attr=""val"">From custom resolver (as TextReader)</text>"); + else if (absoluteUri.Scheme == "stream") + { + return File.OpenRead("../../results/document.xml"); + } + else if (absoluteUri.Scheme == "xmlreader") + { + return new XmlTextReader(absoluteUri.AbsoluteUri, new StringReader(@"<text attr=""val"">From custom resolver (as XmlReader)</text>")); + } + else + return base.GetEntity(absoluteUri, role, ofObjectToReturn); + } } } Index: NistTests.cs =================================================================== RCS file: /cvsroot/mvp-xml/XInclude/v1/test/NistTests.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- NistTests.cs 1 Nov 2004 08:04:00 -0000 1.6 +++ NistTests.cs 3 Nov 2004 12:55:46 -0000 1.7 @@ -58,7 +58,7 @@ /// element, result in fatal errors. /// </summary> [Test] - [ExpectedException(typeof(UnknownParseAttributeValueException))] + [ExpectedException(typeof(XIncludeSyntaxError))] public void Nist_include_03() { RunAndCompare("nist-include-03.xml", ""); |