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:
authorLluis Sanchez <lluis@xamarin.com>2014-02-20 16:30:37 +0400
committerLluis Sanchez <lluis@xamarin.com>2014-02-20 16:30:37 +0400
commitf761f9d6633df78218916cd7483fecdb73b772c4 (patch)
treed83c3dd24792b34816b03ce24317a8040eb9de45 /main/tests
parent5aa0f1762bd55bc9a2acfc1f3e0dd298c48388d6 (diff)
parentc23cf96380ca4a9b74f38a627c53f629c6070257 (diff)
Merge remote-tracking branch 'origin/master' into retina
Diffstat (limited to 'main/tests')
-rw-r--r--main/tests/UserInterfaceTests/IdeApi.cs (renamed from main/tests/UserInterfaceTests/MonoDevelop.UserInterfaceTests/IdeApi.cs)63
-rw-r--r--main/tests/UserInterfaceTests/Main.cs129
-rw-r--r--main/tests/UserInterfaceTests/MonoDevelop.Components.AutoTest/StressTest.cs160
-rw-r--r--main/tests/UserInterfaceTests/MonoDevelop.Components.AutoTest/TestStep.cs51
-rw-r--r--main/tests/UserInterfaceTests/MonoDevelop.Components.AutoTest/UndoTestStepAttribute.cs41
-rw-r--r--main/tests/UserInterfaceTests/MonoDevelop.UserInterfaceTests/Ide.cs41
-rw-r--r--main/tests/UserInterfaceTests/ProcessUtils.cs127
-rw-r--r--main/tests/UserInterfaceTests/SimpleTest.cs (renamed from main/tests/UserInterfaceTests/MonoDevelop.UserInterfaceTests/SimpleTest.cs)98
-rw-r--r--main/tests/UserInterfaceTests/TestService.cs (renamed from main/tests/UserInterfaceTests/MonoDevelop.Components.AutoTest/TestService.cs)44
-rw-r--r--main/tests/UserInterfaceTests/UITestBase.cs (renamed from main/tests/UserInterfaceTests/MonoDevelop.UserInterfaceTests/BaseStressTest.cs)50
-rw-r--r--main/tests/UserInterfaceTests/UserInterfaceTests.csproj33
-rw-r--r--main/tests/UserInterfaceTests/Util.cs (renamed from main/tests/UserInterfaceTests/MonoDevelop.UserInterfaceTests/Util.cs)68
12 files changed, 308 insertions, 597 deletions
diff --git a/main/tests/UserInterfaceTests/MonoDevelop.UserInterfaceTests/IdeApi.cs b/main/tests/UserInterfaceTests/IdeApi.cs
index 13d4605b64..c62053f7b3 100644
--- a/main/tests/UserInterfaceTests/MonoDevelop.UserInterfaceTests/IdeApi.cs
+++ b/main/tests/UserInterfaceTests/IdeApi.cs
@@ -1,21 +1,21 @@
-//
+//
// IdeApi.cs
-//
+//
// Author:
// Lluis Sanchez Gual <lluis@novell.com>
-//
+//
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
-//
+//
// 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
@@ -24,42 +24,55 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-using System;
using MonoDevelop.Components.AutoTest;
using MonoDevelop.Core;
+using MonoDevelop.Ide.Commands;
+using NUnit.Framework;
-namespace MonoDevelop.UserInterfaceTests
+namespace UserInterfaceTests
{
public static class IdeApi
{
public static void OpenFile (FilePath file)
{
TestService.Session.GlobalInvoke ("MonoDevelop.Ide.IdeApp.Workbench.OpenDocument", (FilePath) file, true);
+ Assert.AreEqual (file, IdeApi.GetActiveDocumentFilename ());
}
-
- public static void OpenFile (string relFile, FilePath projectFilePath)
+
+ public static FilePath OpenTestSolution (string solution)
{
- FilePath file = projectFilePath.ParentDirectory.Combine (Util.ToValidPath (relFile));
- OpenFile (file);
+ FilePath path = Util.GetSampleProject (solution);
+
+ var op = TestService.Session.GlobalInvoke<AutoTestOperation> (
+ "MonoDevelop.Ide.IdeApp.Workspace.OpenWorkspaceItem", (string) path
+ );
+
+ op.WaitForCompleted ();
+ Assert.IsTrue (op.Success);
+
+ return path;
}
-
- public static FilePath OpenTestSolution (string file)
+
+ public static void CloseAll ()
{
- FilePath path = Util.GetSampleProject (file);
- TestService.Session.GlobalInvoke ("MonoDevelop.Ide.IdeApp.Workspace.OpenWorkspaceItem", (string) path);
- return path;
+ TestService.Session.ExecuteCommand (FileCommands.CloseWorkspace);
+ TestService.Session.ExecuteCommand (FileCommands.CloseAllFiles);
}
-
- public static void CloseWorkspace ()
+
+ public static FilePath GetActiveDocumentFilename ()
{
- TestService.Session.GlobalInvoke ("MonoDevelop.Ide.IdeApp.Workspace.Close");
+ return TestService.Session.GetGlobalValue<FilePath> ("MonoDevelop.Ide.IdeApp.Workbench.ActiveDocument.FileName");
}
-
- public static void CloseActiveFile ()
+
+ public static void BuildSolution (bool expectedResult = true)
{
- TestService.Session.SetGlobalValue ("MonoDevelop.Ide.IdeApp.Workbench.ActiveDocument.IsDirty", false);
- TestService.Session.GlobalInvoke ("MonoDevelop.Ide.IdeApp.Workbench.ActiveDocument.Close");
+ TestService.Session.ExecuteCommand (ProjectCommands.BuildSolution);
+
+ var buildOp = TestService.Session.GetGlobalValue<AutoTestOperation> (
+ "MonoDevelop.Ide.IdeApp.ProjectOperations.CurrentBuildOperation"
+ );
+ buildOp.WaitForCompleted ();
+ Assert.AreEqual (buildOp.Success, expectedResult);
}
}
}
-
diff --git a/main/tests/UserInterfaceTests/Main.cs b/main/tests/UserInterfaceTests/Main.cs
deleted file mode 100644
index ef3f2ed2c2..0000000000
--- a/main/tests/UserInterfaceTests/Main.cs
+++ /dev/null
@@ -1,129 +0,0 @@
-//
-// Main.cs
-//
-// Author:
-// Lluis Sanchez Gual <lluis@novell.com>
-//
-// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
-//
-// 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.IO;
-using MonoDevelop.Components.AutoTest;
-using MonoDevelop.Core;
-using MonoDevelop.Ide.Commands;
-using System.Threading;
-using System.Linq;
-
-namespace UserInterfaceTests
-{
- class MainClass
- {
- public static int Main (string[] args)
- {
- int pa = 0;
- bool attach = false;
- if (args [pa] == "-a") {
- attach = true;
- pa++;
- }
- if (pa >= args.Length) {
- Console.WriteLine ("Test name not provided");
- return 1;
- }
-
- string testName = args[pa];
-
- Type testType = typeof(MainClass).Assembly.GetTypes ().FirstOrDefault (t => t.FullName == testName);
-
- if (testType == null)
- testType = typeof(MainClass).Assembly.GetTypes ().FirstOrDefault (t => t.Name == testName);
-
- if (testType == null) {
- Console.WriteLine ("Test not found: " + args[0]);
- return 1;
- }
-
- StressTest test = (StressTest) Activator.CreateInstance (testType);
- TestPlan plan = new TestPlan ();
- plan.Repeat = 1;
- pa++;
-
- if (pa < args.Length) {
- int rep;
- if (int.TryParse (args[pa], out rep)) {
- plan.Repeat = rep;
- pa++;
- }
- }
-
- while (pa < args.Length) {
- string arg = args [pa];
- int i = arg.IndexOf ('*');
- string tname = arg.Substring (0, i);
- string it = arg.Substring (i+1);
- int nit;
- if (!int.TryParse (it, out nit)) {
- Console.WriteLine ("Invalid number of iterations: " + it);
- return 1;
- }
- if (tname.Length == 0)
- plan.Iterations = nit;
- else {
- if (!test.HasTest (tname)) {
- Console.Write ("Unknown test: " + tname);
- return 1;
- }
- plan.SetIterationsForTest (tname, nit);
- }
- pa++;
- }
-
- AutoTestClientSession session = new AutoTestClientSession ();
- Console.CancelKeyPress += delegate {
- Console.WriteLine ("Test session cancelled");
- session.Stop ();
- };
- try {
- if (attach) {
- session.AttachApplication ();
- }
- else {
- string app = typeof(AutoTestClientSession).Assembly.Location;
- app = Path.Combine (Path.GetDirectoryName (app), "MonoDevelop.exe");
- session.StartApplication (app, "");
- Console.WriteLine ("Connected");
- session.WaitForEvent ("MonoDevelop.Ide.IdeInitialized");
- }
- Console.WriteLine ("Initialized");
- TestService.Session = session;
-
- test.Run (plan);
- } finally {
- if (!attach) {
- Console.WriteLine ("Press Enter to stop the test process");
- Console.ReadLine ();
- }
- session.Stop ();
- }
- return 0;
- }
- }
-}
-
diff --git a/main/tests/UserInterfaceTests/MonoDevelop.Components.AutoTest/StressTest.cs b/main/tests/UserInterfaceTests/MonoDevelop.Components.AutoTest/StressTest.cs
deleted file mode 100644
index 11203a031b..0000000000
--- a/main/tests/UserInterfaceTests/MonoDevelop.Components.AutoTest/StressTest.cs
+++ /dev/null
@@ -1,160 +0,0 @@
-//
-// StressTestAttribute.cs
-//
-// Author:
-// Lluis Sanchez Gual <lluis@novell.com>
-//
-// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
-//
-// 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;
-using System.Collections.Generic;
-using System.Linq;
-
-namespace MonoDevelop.Components.AutoTest
-{
- public class StressTest
- {
- List<TestCase> cachedTests;
-
- public StressTest ()
- {
- }
-
- public AutoTestClientSession Session {
- get { return TestService.Session; }
- }
-
- protected virtual void Setup ()
- {
- }
-
- protected virtual void TearDown ()
- {
- }
-
- public void Run (TestPlan testPlan)
- {
- List<TestCase> tests = GetTests ();
-
- Setup ();
- for (int n=0; n<testPlan.Repeat; n++) {
- Console.WriteLine ("Test suite iteration: " + n);
- foreach (TestCase t in tests) {
- int ti = testPlan.GetIterationsForTest (t.Method.Name);
- for (int i=0; i<ti; i++) {
- Console.WriteLine ("Running test {0}: {1}", t.Method.Name, i);
- t.Method.Invoke (this, null);
- if (i < ti-1 && t.UndoMethod != null) {
- t.UndoMethod.Invoke (this, null);
- }
- }
- }
- }
- TearDown ();
- }
-
- public bool HasTest (string name)
- {
- return GetTests ().Any (t => t.Method.Name == name);
- }
-
- List<TestCase> GetTests ()
- {
- if (cachedTests != null)
- return cachedTests;
-
- List<TestCase> tests = new List<TestCase> ();
-
- foreach (MethodInfo met in GetType().GetMethods ())
- {
- foreach (TestStepAttribute sat in met.GetCustomAttributes (typeof(TestStepAttribute), true)) {
- TestCase tc = new TestCase () {
- Method = met,
- RunAfter = sat.RunAfter,
- Stage = sat.Stage
- };
- AddSorted (tests, tc);
- }
- foreach (UndoTestStepAttribute sat in met.GetCustomAttributes (typeof(UndoTestStepAttribute), true)) {
- AddUndo (tests, sat.Undoes, met);
- }
- }
- cachedTests = tests;
- return tests;
- }
-
- void AddSorted (List<TestCase> list, TestCase t)
- {
- for (int n=0; n<list.Count; n++) {
- if (list[n].Method.Name == t.RunAfter) {
- list.Insert (n+1, t);
- return;
- }
- if (list[n].RunAfter == t.Method.Name) {
- list.Insert (n, t);
- return;
- }
- }
- list.Add (t);
- }
-
- void AddUndo (List<TestCase> list, string methodName, MethodInfo undoer)
- {
- foreach (TestCase t in list) {
- if (t.Method.Name == methodName)
- t.UndoMethod = undoer;
- }
- }
- }
-
- class TestCase
- {
- public MethodInfo Method { get; set; }
- public MethodInfo UndoMethod { get; set; }
- public string RunAfter { get; set; }
- public string Stage { get; set; }
- }
-
- public class TestPlan
- {
- Dictionary<string,int> itersByTest = new Dictionary<string, int> ();
-
- public int Repeat { get; set; }
-
- public int Iterations { get; set; }
-
- public int GetIterationsForTest (string name)
- {
- int res;
- if (itersByTest.TryGetValue (name, out res))
- return res;
- else
- return Iterations > 0 ? Iterations : 1;
- }
-
- public void SetIterationsForTest (string name, int iterations)
- {
- itersByTest [name] = iterations;
- }
- }
-}
-
diff --git a/main/tests/UserInterfaceTests/MonoDevelop.Components.AutoTest/TestStep.cs b/main/tests/UserInterfaceTests/MonoDevelop.Components.AutoTest/TestStep.cs
deleted file mode 100644
index b1a51b4cd9..0000000000
--- a/main/tests/UserInterfaceTests/MonoDevelop.Components.AutoTest/TestStep.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-//
-// TestCase.cs
-//
-// Author:
-// Lluis Sanchez Gual <lluis@novell.com>
-//
-// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
-//
-// 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;
-
-namespace MonoDevelop.Components.AutoTest
-{
- public class TestStepAttribute: Attribute
- {
- string stage;
-
- public TestStepAttribute ()
- {
- }
-
- public string RunAfter { get; set; }
-
- public string Stage {
- get {
- return stage ?? "Main";
- }
- set {
- stage = value;
- }
- }
- }
-}
-
diff --git a/main/tests/UserInterfaceTests/MonoDevelop.Components.AutoTest/UndoTestStepAttribute.cs b/main/tests/UserInterfaceTests/MonoDevelop.Components.AutoTest/UndoTestStepAttribute.cs
deleted file mode 100644
index d6a4d66e58..0000000000
--- a/main/tests/UserInterfaceTests/MonoDevelop.Components.AutoTest/UndoTestStepAttribute.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-//
-// UndoTestStepAttribute.cs
-//
-// Author:
-// Lluis Sanchez Gual <lluis@novell.com>
-//
-// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
-//
-// 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;
-
-
-namespace MonoDevelop.Components.AutoTest
-{
- public class UndoTestStepAttribute: Attribute
- {
- public UndoTestStepAttribute (string undoes)
- {
- Undoes = undoes;
- }
-
- public string Undoes { get; set; }
- }
-}
-
diff --git a/main/tests/UserInterfaceTests/MonoDevelop.UserInterfaceTests/Ide.cs b/main/tests/UserInterfaceTests/MonoDevelop.UserInterfaceTests/Ide.cs
deleted file mode 100644
index 7f382ad8ec..0000000000
--- a/main/tests/UserInterfaceTests/MonoDevelop.UserInterfaceTests/Ide.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-//
-// Ide.cs
-//
-// Author:
-// Lluis Sanchez Gual <lluis@novell.com>
-//
-// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
-//
-// 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 MonoDevelop.Components.AutoTest;
-using MonoDevelop.Ide.Commands;
-
-namespace MonoDevelop.UserInterfaceTests
-{
- public static class Ide
- {
- public static void OpenFile (string file)
- {
- TestService.Session.ExecuteCommand (FileCommands.OpenFile);
- }
- }
-}
-
diff --git a/main/tests/UserInterfaceTests/ProcessUtils.cs b/main/tests/UserInterfaceTests/ProcessUtils.cs
new file mode 100644
index 0000000000..0922f5b056
--- /dev/null
+++ b/main/tests/UserInterfaceTests/ProcessUtils.cs
@@ -0,0 +1,127 @@
+//
+// ProcessUtils.cs
+//
+// Author:
+// Michael Hutchinson <mhutch@xamarin.com>
+// Jérémie Laval <jeremie.laval@xamarin.com>
+//
+// Copyright (c) 2012 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.IO;
+using System.Diagnostics;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace UserInterfaceTests
+{
+ public static class ProcessUtils
+ {
+ public static Task<int> StartProcess (ProcessStartInfo psi, TextWriter stdout, TextWriter stderr, CancellationToken cancellationToken)
+ {
+ var tcs = new TaskCompletionSource<int> ();
+ if (cancellationToken.CanBeCanceled && cancellationToken.IsCancellationRequested) {
+ tcs.TrySetCanceled ();
+ return tcs.Task;
+ }
+
+ psi.UseShellExecute = false;
+ psi.RedirectStandardOutput |= stdout != null;
+ psi.RedirectStandardError |= stderr != null;
+
+ var p = Process.Start (psi);
+
+ if (cancellationToken.CanBeCanceled) {
+ cancellationToken.Register (() => {
+ try {
+ if (!p.HasExited) {
+ p.Kill ();
+ }
+ } catch (InvalidOperationException ex) {
+ if (ex.Message.IndexOf ("already exited", StringComparison.Ordinal) < 0)
+ throw;
+ }
+ });
+ }
+
+ bool outputDone = false;
+ bool errorDone = false;
+ bool exitDone = false;
+
+ p.EnableRaisingEvents = true;
+ if (psi.RedirectStandardOutput) {
+ bool stdOutInitialized = false;
+ p.OutputDataReceived += (sender, e) => {
+ try {
+ if (e.Data == null) {
+ outputDone = true;
+ if (exitDone && errorDone)
+ tcs.TrySetResult (p.ExitCode);
+ return;
+ }
+
+ if (stdOutInitialized)
+ stdout.WriteLine ();
+ stdout.Write (e.Data);
+ stdOutInitialized = true;
+ } catch (Exception ex) {
+ tcs.TrySetException (ex);
+ }
+ };
+ p.BeginOutputReadLine ();
+ } else {
+ outputDone = true;
+ }
+
+ if (psi.RedirectStandardError) {
+ bool stdErrInitialized = false;
+ p.ErrorDataReceived += (sender, e) => {
+ try {
+ if (e.Data == null) {
+ errorDone = true;
+ if (exitDone && outputDone)
+ tcs.TrySetResult (p.ExitCode);
+ return;
+ }
+
+ if (stdErrInitialized)
+ stderr.WriteLine ();
+ stderr.Write (e.Data);
+ stdErrInitialized = true;
+ } catch (Exception ex) {
+ tcs.TrySetException (ex);
+ }
+ };
+ p.BeginErrorReadLine ();
+ } else {
+ errorDone = true;
+ }
+
+ p.Exited += (sender, e) => {
+ exitDone = true;
+ if (errorDone && outputDone)
+ tcs.TrySetResult (p.ExitCode);
+ };
+
+ return tcs.Task;
+ }
+ }
+}
diff --git a/main/tests/UserInterfaceTests/MonoDevelop.UserInterfaceTests/SimpleTest.cs b/main/tests/UserInterfaceTests/SimpleTest.cs
index f45b01c466..161ed3da21 100644
--- a/main/tests/UserInterfaceTests/MonoDevelop.UserInterfaceTests/SimpleTest.cs
+++ b/main/tests/UserInterfaceTests/SimpleTest.cs
@@ -1,21 +1,21 @@
-//
+//
// SimpleTest.cs
-//
+//
// Author:
// Lluis Sanchez Gual <lluis@novell.com>
-//
+//
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
-//
+//
// 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
@@ -24,66 +24,52 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-using System;
-using MonoDevelop.Components.AutoTest;
+using System.Diagnostics;
+using System.IO;
+using System.Threading;
+using MonoDevelop.Core;
using MonoDevelop.Ide.Commands;
+using NUnit.Framework;
-namespace MonoDevelop.UserInterfaceTests
+namespace UserInterfaceTests
{
- public class SimpleTest: BaseStressTest
+ public class SimpleTest: UITestBase
{
- string project;
-
- protected override void Setup ()
- {
- base.Setup ();
- project = IdeApi.OpenTestSolution ("ContactBook/ContactBook.mds");
- }
-
- protected override void TearDown ()
- {
- base.TearDown ();
- IdeApi.CloseWorkspace ();
- }
-
- [TestStep]
- public void LoadFile ()
- {
- IdeApi.OpenFile ("ContactBook/Main.cs", project);
- System.Threading.Thread.Sleep (50);
- }
-
- [UndoTestStep ("LoadFile")]
- public void UndoLoadFile ()
- {
- IdeApi.CloseActiveFile ();
- System.Threading.Thread.Sleep (50);
- }
-
- [TestStep (RunAfter="LoadFile")]
- public void TypeSomeText ()
+ [Test]
+ public void OpenEditCompile ()
{
+ var slnFile = IdeApi.OpenTestSolution ("ConsoleApp-VS2010/ConsoleApplication.sln");
+ var slnDir = slnFile.ParentDirectory;
+
+ var exe = slnDir.Combine ("bin", "Debug", "ConsoleApplication.exe");
+ Assert.IsFalse (File.Exists (exe));
+
+ IdeApi.OpenFile (slnFile.ParentDirectory.Combine ("Program.cs"));
+
+ IdeApi.BuildSolution ();
+ AssertExeHasOutput (exe, "");
+
+ //select text editor, move down 10 lines, and insert a statement
Session.SelectActiveWidget ();
- for (int n=0; n<12; n++)
+ for (int n = 0; n < 10; n++)
Session.ExecuteCommand (TextEditorCommands.LineDown);
Session.ExecuteCommand (TextEditorCommands.LineEnd);
- Session.TypeText ("Gtk.Widget w; w.ca");
- }
-
- [UndoTestStep ("TypeSomeText")]
- public void UndoTypeSomeText ()
- {
- Session.SelectActiveWidget ();
- for (int n=0; n<18;n++)
- Session.ExecuteCommand (EditCommands.Undo);
- Session.ExecuteCommand (TextEditorCommands.DocumentStart);
+ Session.TypeText ("\nConsole.WriteLine (\"Hello World!\");");
+
+ IdeApi.BuildSolution ();
+ AssertExeHasOutput (exe, "Hello World!");
+
+ IdeApi.CloseAll ();
}
-
- [TestStep (RunAfter="TypeSomeText")]
- public void CloseFile ()
+
+ void AssertExeHasOutput (string exe, string expectedOutput)
{
- IdeApi.CloseActiveFile ();
+ var sw = new StringWriter ();
+ var p = ProcessUtils.StartProcess (new ProcessStartInfo (exe), sw, sw, CancellationToken.None);
+ Assert.AreEqual (0, p.Result);
+ string output = sw.ToString ();
+
+ Assert.AreEqual (expectedOutput, output.Trim ());
}
}
}
-
diff --git a/main/tests/UserInterfaceTests/MonoDevelop.Components.AutoTest/TestService.cs b/main/tests/UserInterfaceTests/TestService.cs
index d721033b6a..8043a080a2 100644
--- a/main/tests/UserInterfaceTests/MonoDevelop.Components.AutoTest/TestService.cs
+++ b/main/tests/UserInterfaceTests/TestService.cs
@@ -1,21 +1,21 @@
-//
+//
// TestService.cs
-//
+//
// Author:
-// Lluis Sanchez Gual <lluis@novell.com>
-//
-// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
-//
+// Michael Hutchinson <m.j.hutchinson@gmail.com>
+//
+// Copyright (c) 2014 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
@@ -25,12 +25,34 @@
// THE SOFTWARE.
using System;
+using MonoDevelop.Components.AutoTest;
+using System.Collections.Generic;
-namespace MonoDevelop.Components.AutoTest
+namespace UserInterfaceTests
{
public static class TestService
{
- public static AutoTestClientSession Session { get; set; }
+ public static AutoTestClientSession Session { get; private set; }
+
+ public static void StartSession ()
+ {
+ Console.WriteLine ("Starting application");
+
+ Session = new AutoTestClientSession ();
+
+ //TODO: support for testing the installed app
+
+ Session.StartApplication (environment: new Dictionary<string,string> {
+ { "MONODEVELOP_TEST_PROFILE", Util.CreateTmpDir ("profile") }
+ });
+
+ Session.GlobalInvoke ("MonoDevelop.Ide.IdeApp.Workbench.GrabDesktopFocus");
+ }
+
+ public static void EndSession ()
+ {
+ Console.WriteLine ("Stopping application");
+ Session.Stop ();
+ }
}
}
-
diff --git a/main/tests/UserInterfaceTests/MonoDevelop.UserInterfaceTests/BaseStressTest.cs b/main/tests/UserInterfaceTests/UITestBase.cs
index 74c54f05a2..5aefb49e6a 100644
--- a/main/tests/UserInterfaceTests/MonoDevelop.UserInterfaceTests/BaseStressTest.cs
+++ b/main/tests/UserInterfaceTests/UITestBase.cs
@@ -1,21 +1,21 @@
-//
-// BaseStressTest.cs
-//
+//
+// UserInterfaceTest.cs
+//
// Author:
-// Lluis Sanchez Gual <lluis@novell.com>
-//
-// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
-//
+// Michael Hutchinson <m.j.hutchinson@gmail.com>
+//
+// Copyright (c) 2014 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
@@ -24,30 +24,30 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-using System;
+using NUnit.Framework;
using MonoDevelop.Components.AutoTest;
-using System.IO;
-namespace MonoDevelop.UserInterfaceTests
+namespace UserInterfaceTests
{
- public class BaseStressTest: StressTest
+ [TestFixture]
+ public abstract class UITestBase
{
- static bool firstRun = true;
-
- protected override void Setup ()
+ public AutoTestClientSession Session {
+ get { return TestService.Session; }
+ }
+
+ [SetUp]
+ public virtual void SetUp ()
{
- if (firstRun) {
- firstRun = false;
- Util.ClearTmpDir ();
- }
- base.Setup ();
+ Util.ClearTmpDir ();
+
+ TestService.StartSession ();
}
- protected override void TearDown ()
+ [TearDown]
+ public virtual void Teardown ()
{
- base.TearDown ();
+ TestService.EndSession ();
}
-
}
}
-
diff --git a/main/tests/UserInterfaceTests/UserInterfaceTests.csproj b/main/tests/UserInterfaceTests/UserInterfaceTests.csproj
index 6094b09314..43597ce02d 100644
--- a/main/tests/UserInterfaceTests/UserInterfaceTests.csproj
+++ b/main/tests/UserInterfaceTests/UserInterfaceTests.csproj
@@ -6,9 +6,11 @@
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{07F55155-51A8-4072-9F80-FA473666F086}</ProjectGuid>
- <OutputType>Exe</OutputType>
+ <OutputType>Library</OutputType>
<RootNamespace>UserInterfaceTests</RootNamespace>
<AssemblyName>UserInterfaceTests</AssemblyName>
+ <TestRunnerCommand>..\..\build\bin\mdtool.exe</TestRunnerCommand>
+ <TestRunnerArgs>run-md-tests</TestRunnerArgs>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>True</DebugSymbols>
@@ -29,26 +31,17 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
- <Reference Include="gdk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">
- </Reference>
<Reference Include="System.Core" />
- <Reference Include="gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">
- </Reference>
- <Reference Include="atk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
- <Reference Include="glib-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
- <Reference Include="pango-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
+ <Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" />
+ <Reference Include="nunit.core, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" />
</ItemGroup>
<ItemGroup>
- <Compile Include="Main.cs" />
- <Compile Include="MonoDevelop.Components.AutoTest\TestStep.cs" />
- <Compile Include="MonoDevelop.UserInterfaceTests\SimpleTest.cs" />
- <Compile Include="MonoDevelop.Components.AutoTest\StressTest.cs" />
- <Compile Include="MonoDevelop.Components.AutoTest\UndoTestStepAttribute.cs" />
- <Compile Include="MonoDevelop.UserInterfaceTests\Ide.cs" />
- <Compile Include="MonoDevelop.UserInterfaceTests\IdeApi.cs" />
- <Compile Include="MonoDevelop.Components.AutoTest\TestService.cs" />
- <Compile Include="MonoDevelop.UserInterfaceTests\BaseStressTest.cs" />
- <Compile Include="MonoDevelop.UserInterfaceTests\Util.cs" />
+ <Compile Include="IdeApi.cs" />
+ <Compile Include="UITestBase.cs" />
+ <Compile Include="TestService.cs" />
+ <Compile Include="Util.cs" />
+ <Compile Include="SimpleTest.cs" />
+ <Compile Include="ProcessUtils.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\core\MonoDevelop.Ide\MonoDevelop.Ide.csproj">
@@ -62,9 +55,5 @@
<Private>False</Private>
</ProjectReference>
</ItemGroup>
- <ItemGroup>
- <Folder Include="MonoDevelop.Components.AutoTest\" />
- <Folder Include="MonoDevelop.UserInterfaceTests\" />
- </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project> \ No newline at end of file
diff --git a/main/tests/UserInterfaceTests/MonoDevelop.UserInterfaceTests/Util.cs b/main/tests/UserInterfaceTests/Util.cs
index 5079bb1e1a..0fd9c76b87 100644
--- a/main/tests/UserInterfaceTests/MonoDevelop.UserInterfaceTests/Util.cs
+++ b/main/tests/UserInterfaceTests/Util.cs
@@ -1,21 +1,21 @@
-//
+//
// Util.cs
-//
+//
// Author:
// Lluis Sanchez Gual <lluis@novell.com>
-//
+//
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
-//
+//
// 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
@@ -24,88 +24,84 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-using System;
using System.IO;
using MonoDevelop.Core;
-namespace MonoDevelop.UserInterfaceTests
+namespace UserInterfaceTests
{
public static class Util
{
static FilePath rootDir;
static int projectId = 1;
-
+
public static FilePath TestsRootDir {
get {
if (rootDir.IsNull) {
rootDir = Path.GetDirectoryName (typeof(Util).Assembly.Location);
- rootDir = Path.Combine (Path.Combine (rootDir, ".."), "..");
- rootDir = Path.Combine (rootDir, "tests");
+ rootDir = rootDir.ParentDirectory.ParentDirectory.Combine ("tests");
}
return rootDir;
}
}
-
+
public static FilePath TmpDir {
get { return TestsRootDir.Combine ("tmp"); }
}
-
+
public static void ClearTmpDir ()
{
if (Directory.Exists (TmpDir))
Directory.Delete (TmpDir, true);
projectId = 1;
}
-
+
public static string ToValidPath (string path)
{
if (Path.DirectorySeparatorChar == '/')
return path;
- else
- return path.Replace ('/', Path.DirectorySeparatorChar);
+ return path.Replace ('/', Path.DirectorySeparatorChar);
}
-
- public static FilePath GetSampleProject (string projectName)
+
+ public static FilePath GetSampleProject (FilePath solution)
{
- projectName = ToValidPath (projectName);
- FilePath srcDir = TestsRootDir.Combine ("test-projects").Combine (projectName);
- FilePath projDir = srcDir;
- srcDir = srcDir.ParentDirectory;
- FilePath tmpDir = CreateTmpDir (projDir.FileName);
+ solution = GetSampleProjectPath (solution);
+
+ FilePath srcDir = solution.ParentDirectory;
+
+ FilePath tmpDir = CreateTmpDir (srcDir.FileName);
CopyDir (srcDir, tmpDir);
- return tmpDir.Combine (projDir.FileName);
+ return tmpDir.Combine (solution.FileName);
}
-
- public static FilePath GetSampleProjectPath (string projectName)
+
+ public static FilePath GetSampleProjectPath (string solution)
{
- projectName = ToValidPath (projectName);
- return TestsRootDir.Combine ("test-projects").Combine (projectName);
+ solution = ToValidPath (solution);
+ return TestsRootDir.Combine ("test-projects").Combine (solution);
}
-
+
public static FilePath CreateTmpDir (string hint)
{
- FilePath tmpDir = TmpDir.Combine (hint + "-" + projectId.ToString ());
+ FilePath tmpDir = TmpDir.Combine (hint + "-" + projectId);
projectId++;
-
+
if (!Directory.Exists (tmpDir))
Directory.CreateDirectory (tmpDir);
return tmpDir;
}
-
+
static void CopyDir (string src, string dst)
{
if (Path.GetFileName (src) == ".svn")
return;
-
+
if (!Directory.Exists (dst))
Directory.CreateDirectory (dst);
-
+
foreach (string file in Directory.GetFiles (src))
File.Copy (file, Path.Combine (dst, Path.GetFileName (file)));
-
+
foreach (string dir in Directory.GetDirectories (src))
CopyDir (dir, Path.Combine (dst, Path.GetFileName (dir)));
}
}
}
-