Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriain holmes <iain@xamarin.com>2015-06-24 18:48:47 +0300
committeriain holmes <iain@xamarin.com>2015-06-24 18:48:47 +0300
commit6bc2f7287e184f2df8e6cec0d98d8d3e7484ade3 (patch)
treec5e67b7f1aa521d49323b213aff5425aafaff8c7 /main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest
parent4b821c70d4175962cc3809ea5332cf6bf282aba9 (diff)
[Test Framework] Export results as XML
Generate an XML representation of the widget hierarchy using the members of an AppResult array as the root nodes
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest')
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/AppQuery.cs1
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/AppResult.cs22
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/AutoTestClientSession.cs10
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/AutoTestSession.cs78
4 files changed, 109 insertions, 2 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/AppQuery.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/AppQuery.cs
index 87b6ad4c7e..6e9e31a26e 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/AppQuery.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/AppQuery.cs
@@ -30,6 +30,7 @@ using Gtk;
using MonoDevelop.Components.AutoTest.Operations;
using MonoDevelop.Components.AutoTest.Results;
using System.Linq;
+using System.Xml;
#if MAC
using AppKit;
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/AppResult.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/AppResult.cs
index a5b44d3cd1..2896c5200d 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/AppResult.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/AppResult.cs
@@ -26,6 +26,7 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
+using System.Xml;
namespace MonoDevelop.Components.AutoTest
{
@@ -38,6 +39,10 @@ namespace MonoDevelop.Components.AutoTest
public AppResult PreviousSibling { get; set; }
public AppResult NextSibling { get; set; }
+ public virtual void ToXml (XmlElement element)
+ {
+ }
+
// Operations
public abstract AppResult Marked (string mark);
public abstract AppResult CheckType (Type desiredType);
@@ -74,6 +79,19 @@ namespace MonoDevelop.Components.AutoTest
return children;
}
- }
-}
+ /// <summary>
+ /// Convenience function to add an attribute to an element
+ /// </summary>
+ /// <param name="element">The element to add the attribute</param>
+ /// <param name="name">The name of the attribute</param>
+ /// <param name="value">The value of the attribute</param>
+ protected void AddAttribute (XmlElement element, string name, string value)
+ {
+ XmlDocument doc = element.OwnerDocument;
+ XmlAttribute attr = doc.CreateAttribute (name);
+ attr.Value = value;
+ element.Attributes.Append (attr);
+ }
+ }
+} \ No newline at end of file
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/AutoTestClientSession.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/AutoTestClientSession.cs
index 9e909f2f1f..8f4207f8b4 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/AutoTestClientSession.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/AutoTestClientSession.cs
@@ -31,6 +31,7 @@ using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System.Threading;
using System.Collections.Generic;
+using System.Xml;
using MonoDevelop.Core.Instrumentation;
using MonoDevelop.Components.Commands;
@@ -352,6 +353,15 @@ namespace MonoDevelop.Components.AutoTest
action ();
session.WaitForTimerContext (context);
}
+
+ public XmlDocument ResultsAsXml (AppResult[] results)
+ {
+ string xmlResults = session.ResultsAsXml (results);
+ XmlDocument document = new XmlDocument ();
+ document.LoadXml (xmlResults);
+
+ return document;
+ }
}
public interface IAutoTestClient
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/AutoTestSession.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/AutoTestSession.cs
index ded11ff43d..ab7a734a1a 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/AutoTestSession.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/AutoTestSession.cs
@@ -26,10 +26,12 @@
using System;
using System.Diagnostics;
+using System.IO;
using System.Runtime.InteropServices;
using System.Linq;
using System.Reflection;
using System.Threading;
+using System.Text;
using System.Collections.Generic;
using MonoDevelop.Core.Instrumentation;
using MonoDevelop.Ide;
@@ -37,6 +39,8 @@ using MonoDevelop.Ide.Tasks;
using MonoDevelop.Components.Commands;
using MonoDevelop.Core;
+using System.Xml;
+
namespace MonoDevelop.Components.AutoTest
{
public class AutoTestSession: MarshalByRefObject
@@ -521,6 +525,80 @@ namespace MonoDevelop.Components.AutoTest
{
throw new TimeoutException (string.Format ("Timeout while executing {0}: {1}\n\ton Element: {2}", operation, query, result), innerException);
}
+
+ void AddChildrenToDocument (XmlDocument document, XmlElement parentElement, AppResult children, bool withSiblings = true)
+ {
+ while (children != null) {
+ XmlElement childElement = document.CreateElement ("result");
+ children.ToXml (childElement);
+ parentElement.AppendChild (childElement);
+
+ if (children.FirstChild != null) {
+ AddChildrenToDocument (document, childElement, children.FirstChild);
+ }
+
+ children = withSiblings ? children.NextSibling : null;
+ }
+ }
+
+ class UTF8StringWriter : StringWriter
+ {
+ public override Encoding Encoding {
+ get {
+ return Encoding.UTF8;
+ }
+ }
+ }
+
+ //
+ // The XML result structure
+ // <AutoTest>
+ // <query>c =&gt; c.Window()</query>
+ // <results>
+ // <result type="Gtk.Window" fulltype="Gtk.Window" name="Main Window" visible="true" sensitive="true" allocation="1,1 1024x1024">
+ // ... contains result elements for all children widgets ...
+ // </result>
+ // ... and more result element trees for each of the AppResult in results ...
+ // </results>
+ // </AutoTest>
+ //
+ public string ResultsAsXml (AppResult[] results)
+ {
+ XmlDocument document = new XmlDocument ();
+ XmlElement rootElement = document.CreateElement ("AutoTest");
+ document.AppendChild (rootElement);
+
+ if (results [0].SourceQuery != null) {
+ XmlElement queryElement = document.CreateElement ("query");
+ queryElement.AppendChild (document.CreateTextNode (results [0].SourceQuery));
+ rootElement.AppendChild (queryElement);
+ }
+
+ XmlElement resultsElement = document.CreateElement ("results");
+ rootElement.AppendChild (resultsElement);
+
+ try {
+ ExecuteOnIdle (() => {
+ foreach (var result in results) {
+ AddChildrenToDocument (document, resultsElement, result, false);
+ }
+ });
+ } catch (TimeoutException e) {
+ ThrowOperationTimeoutException ("ResultsAsXml", null, null, e);
+ }
+
+ string output;
+
+ using (var sw = new UTF8StringWriter ()) {
+ using (var xw = XmlWriter.Create (sw, new XmlWriterSettings { Indent = true })) {
+ document.WriteTo (xw);
+ }
+
+ output = sw.ToString ();
+ }
+
+ return output;
+ }
}
[StructLayout (LayoutKind.Sequential)]