Ejemplo n.º 1
0
        void RunTest1()
        {
            AXmlParser parser = new AXmlParser();

            try {
                parser.Lock.EnterWriteLock();

                parser.Parse(initialDocumentText, null);                 // full reparse

                IList <DocumentChangeEventArgs> changes = new List <DocumentChangeEventArgs>();

                changes.Add(new DocumentChangeEventArgs(offset, original, replacement));

                parser.Parse(finalDocumentText, changes);
            } finally {
                parser.Lock.ExitWriteLock();
            }
        }
Ejemplo n.º 2
0
        /// <remarks>
        /// If using DTD, canonical representation is not checked
        /// If using DTD, uknown entiry references are not error
        /// </remarks>
        bool TestFile(TestFile testFile, bool isWellFormed)
        {
            bool passed = true;

            string content = testFile.Content;

            Debug.WriteLine("Testing " + testFile.Name + "...");
            AXmlParser parser = new AXmlParser();

            bool usingDTD = content.Contains("<!DOCTYPE") && (content.Contains("<!ENTITY") || content.Contains(" SYSTEM "));

            if (usingDTD)
            {
                parser.UnknownEntityReferenceIsError = false;
            }

            AXmlDocument document;

            parser.Lock.EnterWriteLock();
            try {
                document = parser.Parse(content, null);
            } finally {
                parser.Lock.ExitWriteLock();
            }

            string printed = PrettyPrintAXmlVisitor.PrettyPrint(document);

            if (content != printed)
            {
                errorOutput.AppendFormat("Output of pretty printed XML for \"{0}\" does not match the original.\n", testFile.Name);
                errorOutput.AppendFormat("Pretty printed:\n{0}\n", Indent(printed));
                passed = false;
            }

            if (isWellFormed && !usingDTD)
            {
                string canonicalPrint = CanonicalPrintAXmlVisitor.Print(document);
                if (testFile.Canonical != null)
                {
                    if (testFile.Canonical != canonicalPrint)
                    {
                        errorOutput.AppendFormat("Canonical XML for \"{0}\" does not match the excpected.\n", testFile.Name);
                        errorOutput.AppendFormat("Expected:\n{0}\n", Indent(testFile.Canonical));
                        errorOutput.AppendFormat("Seen:\n{0}\n", Indent(canonicalPrint));
                        passed = false;
                    }
                }
                else
                {
                    errorOutput.AppendFormat("Can not find canonical output for \"{0}\"", testFile.Name);
                    errorOutput.AppendFormat("Suggested canonical output:\n{0}\n", Indent(canonicalPrint));
                    passed = false;
                }
            }

            bool hasErrors = document.SyntaxErrors.FirstOrDefault() != null;

            if (isWellFormed && hasErrors)
            {
                errorOutput.AppendFormat("Syntax error(s) in well formed file \"{0}\":\n", testFile.Name);
                foreach (var error in document.SyntaxErrors)
                {
                    string followingText = content.Substring(error.StartOffset, Math.Min(10, content.Length - error.StartOffset));
                    errorOutput.AppendFormat("Error ({0}-{1}): {2} (followed by \"{3}\")\n", error.StartOffset, error.EndOffset, error.Message, followingText);
                }
                passed = false;
            }

            if (!isWellFormed && !hasErrors)
            {
                errorOutput.AppendFormat("No syntax errors reported for mallformed file \"{0}\"\n", testFile.Name);
                passed = false;
            }

            // Epilog
            if (!passed)
            {
                if (testFile.Description != null)
                {
                    errorOutput.AppendFormat("Test description:\n{0}\n", Indent(testFile.Description));
                }
                errorOutput.AppendFormat("File content:\n{0}\n", Indent(content));
                errorOutput.AppendLine();
            }

            return(passed);
        }
Ejemplo n.º 3
0
		/// <remarks>
		/// If using DTD, canonical representation is not checked
		/// If using DTD, uknown entiry references are not error
		/// </remarks>
		bool TestFile(TestFile testFile, bool isWellFormed)
		{
			bool passed = true;
			
			string content = testFile.Content;
			Debug.WriteLine("Testing " + testFile.Name + "...");
			AXmlParser parser = new AXmlParser();
			
			bool usingDTD = content.Contains("<!DOCTYPE") && (content.Contains("<!ENTITY") || content.Contains(" SYSTEM "));
			if (usingDTD)
				parser.UnknownEntityReferenceIsError = false;
			
			AXmlDocument document;
			
			parser.Lock.EnterWriteLock();
			try {
				document = parser.Parse(content, null);
			} finally {
				parser.Lock.ExitWriteLock();
			}
			
			string printed = PrettyPrintAXmlVisitor.PrettyPrint(document);
			if (content != printed) {
				errorOutput.AppendFormat("Output of pretty printed XML for \"{0}\" does not match the original.\n", testFile.Name);
				errorOutput.AppendFormat("Pretty printed:\n{0}\n", Indent(printed));
				passed = false;
			}
			
			if (isWellFormed && !usingDTD) {
				string canonicalPrint = CanonicalPrintAXmlVisitor.Print(document);
				if (testFile.Canonical != null) {
					if (testFile.Canonical != canonicalPrint) {
						errorOutput.AppendFormat("Canonical XML for \"{0}\" does not match the excpected.\n", testFile.Name);
						errorOutput.AppendFormat("Expected:\n{0}\n", Indent(testFile.Canonical));
						errorOutput.AppendFormat("Seen:\n{0}\n", Indent(canonicalPrint));
						passed = false;
					}
				} else {
					errorOutput.AppendFormat("Can not find canonical output for \"{0}\"", testFile.Name);
					errorOutput.AppendFormat("Suggested canonical output:\n{0}\n", Indent(canonicalPrint));
					passed = false;
				}
			}
			
			bool hasErrors = document.SyntaxErrors.FirstOrDefault() != null;
			if (isWellFormed && hasErrors) {
				errorOutput.AppendFormat("Syntax error(s) in well formed file \"{0}\":\n", testFile.Name);
				foreach (var error in document.SyntaxErrors) {
					string followingText = content.Substring(error.StartOffset, Math.Min(10, content.Length - error.StartOffset));
					errorOutput.AppendFormat("Error ({0}-{1}): {2} (followed by \"{3}\")\n", error.StartOffset, error.EndOffset, error.Message, followingText);
				}
				passed = false;
			}
			
			if (!isWellFormed && !hasErrors) {
				errorOutput.AppendFormat("No syntax errors reported for mallformed file \"{0}\"\n", testFile.Name);
				passed = false;
			}
			
			// Epilog
			if (!passed) {
				if (testFile.Description != null) {
					errorOutput.AppendFormat("Test description:\n{0}\n", Indent(testFile.Description));
				}
				errorOutput.AppendFormat("File content:\n{0}\n", Indent(content));
				errorOutput.AppendLine();
			}
			
			return passed;
		}
Ejemplo n.º 4
0
		void RunTest1()
		{
			AXmlParser parser = new AXmlParser();
			
			try {
				parser.Lock.EnterWriteLock();
				
				parser.Parse(initialDocumentText, null); // full reparse
				
				IList<DocumentChangeEventArgs> changes = new List<DocumentChangeEventArgs>();
				
				changes.Add(new DocumentChangeEventArgs(offset, original, replacement));
				
				parser.Parse(finalDocumentText, changes);
			} finally {
				parser.Lock.ExitWriteLock();
			}
		}