Example #1
0
        private static string RunTest(CaseFolding caseFolding, string doctype, bool format, string source, XmlReaderTestCallback callback)
        {
            // initialize sgml reader
            XmlReader reader = new SgmlReader {
                CaseFolding = caseFolding,
                DocType = doctype,
                InputStream = new StringReader(source),
                WhitespaceHandling = format ? WhitespaceHandling.None : WhitespaceHandling.All
            };

            // check if we need to use the LoggingXmlReader
            if(_debug) {
                reader = new LoggingXmlReader(reader, Console.Out);
            }

            // initialize xml writer
            var stringWriter = new StringWriter();
            var xmlTextWriter = new XmlTextWriter(stringWriter);
            if(format) {
                xmlTextWriter.Formatting = Formatting.Indented;
            }
            callback(reader, xmlTextWriter);
            xmlTextWriter.Close();

            // reproduce the parsed document
            var actual = stringWriter.ToString();

            // ensure that output can be parsed again
            try {
                using(var stringReader = new StringReader(actual)) {
                    var doc = new XmlDocument();
                    doc.Load(stringReader);
                }
            } catch(Exception) {
                Assert.Fail("unable to parse sgml reader output:\n{0}", actual);
            }
            return actual.Trim().Replace("\r", "");
        }
Example #2
0
        private static string RunTest(CaseFolding caseFolding, string doctype, bool format, string source, XmlReaderTestCallback callback)
        {
            // initialize sgml reader
            XmlReader reader = new SgmlReader {
                CaseFolding        = caseFolding,
                DocType            = doctype,
                InputStream        = new StringReader(source),
                WhitespaceHandling = format ? WhitespaceHandling.None : WhitespaceHandling.All
            };

            // check if we need to use the LoggingXmlReader
            if (_debug)
            {
                reader = new LoggingXmlReader(reader, Console.Out);
            }

            // initialize xml writer
            StringWriter  stringWriter  = new StringWriter();
            XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);

            if (format)
            {
                xmlTextWriter.Formatting = Formatting.Indented;
            }
            callback(reader, xmlTextWriter);
            xmlTextWriter.Close();

            // reproduce the parsed document
            string actual = stringWriter.ToString();

            // ensure that output can be parsed again
            try {
                using (StringReader stringReader = new StringReader(actual)) {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(stringReader);
                }
            } catch (Exception) {
                Assert.Fail("unable to parse sgml reader output:\n{0}", actual);
            }
            return(actual.Trim().Replace("\r", ""));
        }
		private static string RunTest(CaseFolding caseFolding, string doctype, bool format, string source, XmlReaderTestCallback callback)
		{

			var pseudoBaseUri = new Uri(string.Format(
				"rsrc://{0}/{1}/",
				typeof(Tests).Assembly.FullName.Split(',')[0],
				typeof(Tests).Namespace));

			// initialize sgml reader
			XmlReader reader = new SgmlReader(
				new StringReader(source),
				pseudoBaseUri,
				pseudoUri =>	// Stream opener (Uri --> Stream callback)
				{
					var resourcePath = string.Join(
						".",
						pseudoUri.PathAndQuery.Split(
							new[] { '/' },
							StringSplitOptions.RemoveEmptyEntries));
					return new StreamInformation
						{
							Stream = typeof(Tests).Assembly.GetManifestResourceStream(resourcePath),
							DefaultEncoding = Encoding.UTF8
						};
				})
				{
					CaseFolding = caseFolding,
					DocType = doctype,
					WhitespaceHandling = format == false
				};

			// check if we need to use the LoggingXmlReader
			if (_debug)
			{
				reader = new LoggingXmlReader(reader, Console.Out);
			}

			// initialize xml writer
			var stringWriter = new StringWriter();
			var xmlTextWriter = new XmlTextWriter(stringWriter);
			if (format)
			{
				xmlTextWriter.Formatting = Formatting.Indented;
			}
			callback(reader, xmlTextWriter);
			xmlTextWriter.Close();

			// reproduce the parsed document
			var actual = stringWriter.ToString();

			// ensure that output can be parsed again
			try
			{
				using (var stringReader = new StringReader(actual))
				{
					var doc = new XmlDocument();
					doc.Load(stringReader);
				}
			}
			catch (Exception)
			{
				Assert.Fail("unable to parse sgml reader output:\n{0}", actual);
			}
			return actual.Trim().Replace("\r", "");
		}
Example #4
0
        private static string RunTest(CaseFolding caseFolding, string doctype, bool format, string source, XmlReaderTestCallback callback)
        {
            var pseudoBaseUri = new Uri(string.Format(
                                            "rsrc://{0}/{1}/",
                                            typeof(Tests).Assembly.FullName.Split(',')[0],
                                            typeof(Tests).Namespace));

            // initialize sgml reader
            XmlReader reader = new SgmlReader(
                new StringReader(source),
                pseudoBaseUri,
                pseudoUri =>                    // Stream opener (Uri --> Stream callback)
            {
                var resourcePath = string.Join(
                    ".",
                    pseudoUri.PathAndQuery.Split(
                        new[] { '/' },
                        StringSplitOptions.RemoveEmptyEntries));
                return(new StreamInformation
                {
                    Stream = typeof(Tests).Assembly.GetManifestResourceStream(resourcePath),
                    DefaultEncoding = Encoding.UTF8
                });
            })
            {
                CaseFolding        = caseFolding,
                DocType            = doctype,
                WhitespaceHandling = format == false
            };

            // check if we need to use the LoggingXmlReader
            if (_debug)
            {
                reader = new LoggingXmlReader(reader, Console.Out);
            }

            // initialize xml writer
            var stringWriter  = new StringWriter();
            var xmlTextWriter = new XmlTextWriter(stringWriter);

            if (format)
            {
                xmlTextWriter.Formatting = Formatting.Indented;
            }
            callback(reader, xmlTextWriter);
            xmlTextWriter.Close();

            // reproduce the parsed document
            var actual = stringWriter.ToString();

            // ensure that output can be parsed again
            try
            {
                using (var stringReader = new StringReader(actual))
                {
                    var doc = new XmlDocument();
                    doc.Load(stringReader);
                }
            }
            catch (Exception)
            {
                Assert.Fail("unable to parse sgml reader output:\n{0}", actual);
            }
            return(actual.Trim().Replace("\r", ""));
        }
        private static string RunTest(CaseFolding caseFolding, string doctype, bool format, string source, XmlReaderTestCallback callback)
        {
            // initialize sgml reader
            SgmlReader sgmlReader = new SgmlReader
            {
                CaseFolding        = caseFolding,
                DocType            = doctype,
                InputStream        = new StringReader(source),
                WhitespaceHandling = format ? WhitespaceHandling.None : WhitespaceHandling.All,
                Resolver           = new TestEntityResolver()
            };

            if (doctype == "OFX")
            {
                sgmlReader.SystemLiteral = "ofx160.dtd";
            }

            // check if we need to use the LoggingXmlReader
            XmlReader reader = sgmlReader;

#if DEBUG
            {
                reader = new LoggingXmlReader(sgmlReader, Console.Out);
            }
#endif

            // initialize xml writer
            StringWriter  stringWriter  = new StringWriter();
            XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
            if (format)
            {
                xmlTextWriter.Formatting = Formatting.Indented;
            }
            callback(reader, xmlTextWriter);
            xmlTextWriter.Close();

            // reproduce the parsed document
            var actual = stringWriter.ToString();

            // ensure that output can be parsed again
            try
            {
                using (StringReader stringReader = new StringReader(actual))
                {
                    var doc = new XmlDocument();
                    doc.Load(stringReader);
                }
            }
            catch (Exception)
            {
                Assert.Fail("unable to parse " + nameof(SgmlReader) + " output:\n{0}", actual);
            }

            return(actual.Trim().Replace("\r", ""));
        }