From 67a546342ef60ff547f87ef72ad7337a761b82cb Mon Sep 17 00:00:00 2001 From: iain holmes Date: Wed, 9 Sep 2015 17:50:09 +0100 Subject: [AutoTest] Add code to set the active runtime and configuration in SelectorView --- .../NSObjectResult.cs | 52 ++++++++++++++++++++++ .../MonoDevelop.Components.AutoTest/AppResult.cs | 15 ++++++- .../AutoTestClientSession.cs | 20 +++++++++ .../AutoTestSession.cs | 30 +++++++++++++ 4 files changed, 116 insertions(+), 1 deletion(-) (limited to 'main') diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest.Results/NSObjectResult.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest.Results/NSObjectResult.cs index b9fa5d5b05..e12c8ab3ed 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest.Results/NSObjectResult.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest.Results/NSObjectResult.cs @@ -26,12 +26,15 @@ #if MAC using System; using System.Collections.Generic; +using System.Linq; using System.Reflection; using System.Xml; using AppKit; using Foundation; +using MonoDevelop.Components.MainToolbar; + namespace MonoDevelop.Components.AutoTest.Results { public class NSObjectResult : AppResult @@ -240,6 +243,55 @@ namespace MonoDevelop.Components.AutoTest.Results { } + +#region MacPlatform.MacIntegration.MainToolbar.SelectorView + public override bool SetActiveConfiguration (string configurationName) + { + Type type = ResultObject.GetType (); + PropertyInfo pinfo = type.GetProperty ("ConfigurationModel"); + if (pinfo == null) { + return false; + } + + IEnumerable model = (IEnumerable)pinfo.GetValue (ResultObject, null); + var configuration = model.FirstOrDefault (c => c.DisplayString == configurationName); + if (configuration == null) { + return false; + } + + pinfo = type.GetProperty ("ActiveConfiguration"); + if (pinfo == null) { + return false; + } + + pinfo.SetValue (ResultObject, configuration); + return true; + } + + public override bool SetActiveRuntime (string runtimeName) + { + Type type = ResultObject.GetType (); + PropertyInfo pinfo = type.GetProperty ("RuntimeModel"); + if (pinfo == null) { + return false; + } + + IEnumerable model = (IEnumerable)pinfo.GetValue (ResultObject, null); + + var runtime = model.FirstOrDefault (r => r.GetMutableModel ().FullDisplayString == runtimeName); + if (runtime == null) { + return false; + } + + pinfo = type.GetProperty ("ActiveRuntime"); + if (pinfo == null) { + return false; + } + + pinfo.SetValue (ResultObject, runtime); + return true; + } +#endregion } } 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 925b3eead2..20a71e2df5 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/AppResult.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/AppResult.cs @@ -63,9 +63,22 @@ namespace MonoDevelop.Components.AutoTest public abstract bool TypeKey (string keyString, string state = ""); public abstract bool EnterText (string text); public abstract bool Toggle (bool active); - public abstract void Flash (); + // More specific actions for complicated widgets + + #region For MacPlatform.MacIntegration.MainToolbar.SelectorView + public virtual bool SetActiveConfiguration (string configurationName) + { + return false; + } + + public virtual bool SetActiveRuntime (string runtimeName) + { + return false; + } + #endregion + // Inspection Operations public abstract ObjectProperties Properties (); public abstract string GetResultType (); 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 589565869e..085c1cba86 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/AutoTestClientSession.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/AutoTestClientSession.cs @@ -354,6 +354,26 @@ namespace MonoDevelop.Components.AutoTest } } + public bool SetActiveConfiguration (Func query, string configuration) + { + AppResult[] results = Query (query); + if (results.Length == 0) { + return false; + } + + return session.SetActiveConfiguration (results [0], configuration); + } + + public bool SetActiveRuntime (Func query, string runtime) + { + AppResult[] results = Query (query); + if (results.Length == 0) { + return false; + } + + return session.SetActiveRuntime (results [0], runtime); + } + public void RunAndWaitForTimer (Action action, string counterName, int timeout = 20000) { AutoTestSession.TimerCounterContext context = session.CreateNewTimerContext (counterName); 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 d94f39e2ba..6b7677e180 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/AutoTestSession.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/AutoTestSession.cs @@ -535,6 +535,36 @@ namespace MonoDevelop.Components.AutoTest } } + public bool SetActiveConfiguration (AppResult result, string configuration) + { + bool success = false; + + try { + ExecuteOnIdle (() => { + success = result.SetActiveConfiguration (configuration); + }); + } catch (TimeoutException e) { + ThrowOperationTimeoutException ("SetActiveConfiguration", result.SourceQuery, result, e); + } + + return success; + } + + public bool SetActiveRuntime (AppResult result, string runtime) + { + bool success = false; + + try { + ExecuteOnIdle (() => { + success = result.SetActiveRuntime (runtime); + }); + } catch (TimeoutException e) { + ThrowOperationTimeoutException ("SetActiveRuntime", result.SourceQuery, result, e); + } + + return success; + } + void ThrowOperationTimeoutException (string operation, string query, AppResult result, Exception innerException) { throw new TimeoutException (string.Format ("Timeout while executing {0}: {1}\n\ton Element: {2}", operation, query, result), innerException); -- cgit v1.2.3