diff options
author | Manish Sinha <manish.sinha@xamarin.com> | 2015-06-25 19:03:47 +0300 |
---|---|---|
committer | Manish Sinha <manish.sinha@xamarin.com> | 2015-06-25 19:10:31 +0300 |
commit | 0d045a5fa16fea8f33bcaf008a029670e62b7ec9 (patch) | |
tree | 9ba31e11d35851f144f77dd1c8547a583487cd04 /main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest | |
parent | 7913f8032331ba40891db3a9ab1acf95241fbc30 (diff) |
[Autotest] Added ability to fetch properties
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest')
3 files changed, 178 insertions, 2 deletions
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 4d6a9a4f2d..e7ef6df28b 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/AppResult.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/AppResult.cs @@ -23,12 +23,14 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. + using System; using System.Collections.Generic; -using System.Runtime.InteropServices; using System.Xml; using System.Reflection; using System.Linq; +using System.Collections.ObjectModel; +using MonoDevelop.Components.AutoTest.Results; namespace MonoDevelop.Components.AutoTest { @@ -63,6 +65,10 @@ namespace MonoDevelop.Components.AutoTest public abstract void Flash (Action completionHandler); + // Inspection Operations + public abstract ObjectProperties Properties (); + public abstract Type GetResultType (); + public string SourceQuery { get; set; } void AddChildrenToList (List<AppResult> children, AppResult child) @@ -114,6 +120,40 @@ namespace MonoDevelop.Components.AutoTest }); } + protected ObjectProperties GetProperties (object resultObject) + { + var propertiesObject = new ObjectProperties (); + if (resultObject != null) { + var properties = resultObject.GetType ().GetProperties ( + BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static); + foreach (var property in properties) { + var value = GetPropertyValue (property.Name, resultObject); + AppResult result = null; + + var gtkNotebookValue = value as Gtk.Notebook; + if (gtkNotebookValue != null) + result = new GtkNotebookResult (gtkNotebookValue); + var gtkTreeviewValue = value as Gtk.TreeView; + if (gtkTreeviewValue != null && result == null) + result = new GtkTreeModelResult (gtkTreeviewValue, gtkTreeviewValue.Model, 0); + var gtkWidgetValue = value as Gtk.Widget; + if (gtkWidgetValue != null && result == null) + result = new GtkWidgetResult (gtkWidgetValue); + #if MAC + var nsObjectValue = value as Foundation.NSObject; + if (nsObjectValue != null && result == null) + result = new NSObjectResult (nsObjectValue); + #endif + if (result == null) + result = new ObjectResult (value); + + propertiesObject.Add (property.Name, result, property); + } + } + + return propertiesObject; + } + protected AppResult MatchProperty (string propertyName, object objectToCompare, object value) { foreach (var singleProperty in propertyName.Split (new [] { '.' })) { @@ -135,4 +175,4 @@ namespace MonoDevelop.Components.AutoTest } } } -}
\ No newline at end of file +} diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/ObjectProperties.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/ObjectProperties.cs new file mode 100644 index 0000000000..9fa28fc9c5 --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/ObjectProperties.cs @@ -0,0 +1,67 @@ +// +// ObjectProperties.cs +// +// Author: +// Manish Sinha <manish.sinha@xamarin.com> +// +// Copyright (c) 2015 Xamarin Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Reflection; +using System.Linq; + +namespace MonoDevelop.Components.AutoTest +{ + public class ObjectProperties : MarshalByRefObject + { + readonly Dictionary<string,AppResult> propertyMap = new Dictionary<string,AppResult> (); + + readonly Dictionary<string,PropertyMetadata> propertyMetaData = new Dictionary<string,PropertyMetadata> (); + + internal ObjectProperties () { } + + internal void Add (string propertyName, AppResult propertyValue, PropertyInfo propertyInfo) + { + propertyMap.Add (propertyName, propertyValue); + propertyMetaData.Add (propertyName, new PropertyMetadata (propertyInfo)); + } + + public ReadOnlyCollection<string> GetPropertyNames () + { + return propertyMap.Keys.ToList ().AsReadOnly (); + } + + public AppResult this [string propertyName] + { + get { + return propertyMap [propertyName]; + } + } + + public PropertyMetadata GetMetaData (string propertyName) + { + return propertyMetaData [propertyName]; + } + } +} + diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/PropertyMetadata.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/PropertyMetadata.cs new file mode 100644 index 0000000000..7d0c7e0151 --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AutoTest/PropertyMetadata.cs @@ -0,0 +1,69 @@ +// +// PropertyMetadata.cs +// +// Author: +// Manish Sinha <manish.sinha@xamarin.com> +// +// Copyright (c) 2015 Xamarin Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +using System; +using System.Reflection; + +namespace MonoDevelop.Components.AutoTest +{ + public class PropertyMetadata : MarshalByRefObject + { + readonly PropertyInfo propertyInfo; + + internal PropertyMetadata (PropertyInfo propertyInfo) + { + this.propertyInfo = propertyInfo; + } + + public string Name + { + get { + return propertyInfo.Name; + } + } + + public bool CanRead + { + get { + return propertyInfo.CanRead; + } + } + + public bool CanWrite + { + get { + return propertyInfo.CanWrite; + } + } + + public string PropertyType + { + get { + return propertyInfo.PropertyType.FullName; + } + } + } +} + |