Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(375)

Side by Side Diff: visual_studio/NativeClientVSAddIn/UnitTests/TestUtilities.cs

Issue 10836143: Refactored the VS add-in (Closed) Base URL: https://nativeclient-sdk.googlecode.com/svn/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 namespace UnitTests 5 namespace UnitTests
6 { 6 {
7 using System; 7 using System;
8 using System.Collections.Generic; 8 using System.Collections.Generic;
9 using System.IO; 9 using System.IO;
10 using System.Linq; 10 using System.Linq;
(...skipping 18 matching lines...) Expand all
29 /// Uniquename of the NaCl project in BlankValidSolution. 29 /// Uniquename of the NaCl project in BlankValidSolution.
30 /// </summary> 30 /// </summary>
31 public const string BlankNaClProjectUniqueName = @"NaClProject\NaClProject.v cxproj"; 31 public const string BlankNaClProjectUniqueName = @"NaClProject\NaClProject.v cxproj";
32 32
33 /// <summary> 33 /// <summary>
34 /// Uniquename of the non-NaCl project in BlankValidSolution. 34 /// Uniquename of the non-NaCl project in BlankValidSolution.
35 /// </summary> 35 /// </summary>
36 public const string NotNaClProjectUniqueName = @"NotNaCl\NotNaCl.csproj"; 36 public const string NotNaClProjectUniqueName = @"NotNaCl\NotNaCl.csproj";
37 37
38 /// <summary> 38 /// <summary>
39 /// A generic boolean statement to be used with RetryWithTimeout.
40 /// </summary>
41 /// <returns>True if the statement is true, false if false.</returns>
42 public delegate bool RetryStatement();
43
44 /// <summary>
39 /// This starts an instance of Visual Studio and get its DTE object. 45 /// This starts an instance of Visual Studio and get its DTE object.
40 /// </summary> 46 /// </summary>
41 /// <returns>DTE of the started instance.</returns> 47 /// <returns>DTE of the started instance.</returns>
42 public static DTE2 StartVisualStudioInstance() 48 public static DTE2 StartVisualStudioInstance()
43 { 49 {
44 // Set up filter to handle threading events and automatically retry calls 50 // Set up filter to handle threading events and automatically retry calls
45 // to dte which fail because dte is busy. 51 // to dte which fail because dte is busy.
46 ComMessageFilter.Register(); 52 ComMessageFilter.Register();
47 53
48 Type visualStudioType = Type.GetTypeFromProgID("VisualStudio.DTE.10.0"); 54 Type visualStudioType = Type.GetTypeFromProgID("VisualStudio.DTE.10.0");
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 if (dte.Solution != null) 133 if (dte.Solution != null)
128 { 134 {
129 dte.Solution.Close(); 135 dte.Solution.Close();
130 } 136 }
131 } 137 }
132 138
133 return newSolution; 139 return newSolution;
134 } 140 }
135 141
136 /// <summary> 142 /// <summary>
137 /// Ensures that the add-in is configured to load on start. If it isn't then some tests may
138 /// unexpectedly fail, this check helps catch that problem early.
139 /// </summary>
140 /// <param name="dte">The main Visual Studio interface.</param>
141 /// <param name="addInName">The name of the add-in to check if loaded.</para m>
142 public static void AssertAddinLoaded(DTE2 dte, string addInName)
143 {
144 bool found = false;
145 foreach (AddIn addin in dte.AddIns)
146 {
147 if (addin.Connected && addInName.Equals(addin.Name))
148 {
149 found = true;
150 break;
151 }
152 }
153
154 Assert.IsTrue(found, "Add-in is not configured to load on start.");
155 }
156
157 /// <summary>
158 /// This returns the text contained in the given output window pane. 143 /// This returns the text contained in the given output window pane.
159 /// </summary> 144 /// </summary>
160 /// <param name="pane">Pane to get text from.</param> 145 /// <param name="pane">Pane to get text from.</param>
161 /// <returns>Text in the window.</returns> 146 /// <returns>Text in the window.</returns>
162 public static string GetPaneText(OutputWindowPane pane) 147 public static string GetPaneText(OutputWindowPane pane)
163 { 148 {
164 TextSelection selection = pane.TextDocument.Selection; 149 TextSelection selection = pane.TextDocument.Selection;
165 selection.StartOfDocument(false); 150 selection.StartOfDocument(false);
166 selection.EndOfDocument(true); 151 selection.EndOfDocument(true);
167 return selection.Text; 152 return selection.Text;
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 string message = string.Format( 363 string message = string.Format(
379 "{0} was null or empty. Page: {1}, Configuration: {2}", 364 "{0} was null or empty. Page: {1}, Configuration: {2}",
380 propertyName, 365 propertyName,
381 pageName, 366 pageName,
382 configuration.ConfigurationName); 367 configuration.ConfigurationName);
383 368
384 Assert.IsFalse(string.IsNullOrEmpty(propertyValue), message); 369 Assert.IsFalse(string.IsNullOrEmpty(propertyValue), message);
385 } 370 }
386 371
387 /// <summary> 372 /// <summary>
373 /// Ensures that the add-in is configured to load on start. If it isn't then some tests may
374 /// unexpectedly fail, this check helps catch that problem early.
375 /// </summary>
376 /// <param name="dte">The main Visual Studio interface.</param>
377 /// <param name="addInName">The name of the add-in to check if loaded.</para m>
378 public static void AssertAddinLoaded(DTE2 dte, string addInName)
379 {
380 bool found = false;
381 foreach (AddIn addin in dte.AddIns)
382 {
383 if (addin.Connected && addInName.Equals(addin.Name))
384 {
385 found = true;
386 break;
387 }
388 }
389
390 Assert.IsTrue(found, "Add-in is not configured to load on start.");
391 }
392
393 /// <summary>
394 /// Will retry the given statement up to maxRetry times while pausing betwee n each try for
395 /// the given interval.
396 /// </summary>
397 /// <param name="test">Generic boolean statement.</param>
398 /// <param name="interval">Amount of time to wait between each retry.</param >
399 /// <param name="maxRetry">Maximum number of retries.</param>
400 /// <param name="message">Message to print on failure.</param>
401 public static void AssertTrueWithTimeout(
402 RetryStatement test, TimeSpan interval, int maxRetry, string message)
403 {
404 for (int tryCount = 0; tryCount <= maxRetry; tryCount++)
405 {
406 if (test.Invoke())
407 {
408 return;
409 }
410
411 System.Threading.Thread.Sleep(interval);
412 }
413
414 throw new Exception(string.Format("Statement timed out. {0}", message));
415 }
416
417 /// <summary>
388 /// Extends the string class to allow checking if a string contains another string 418 /// Extends the string class to allow checking if a string contains another string
389 /// allowing a comparison type (such as case-insensitivity). 419 /// allowing a comparison type (such as case-insensitivity).
390 /// </summary> 420 /// </summary>
391 /// <param name="source">Base string to search.</param> 421 /// <param name="source">Base string to search.</param>
392 /// <param name="toCheck">String to check if contained within base string.</ param> 422 /// <param name="toCheck">String to check if contained within base string.</ param>
393 /// <param name="comparison">Comparison type.</param> 423 /// <param name="comparison">Comparison type.</param>
394 /// <returns>True if toCheck is contained in source.</returns> 424 /// <returns>True if toCheck is contained in source.</returns>
395 public static bool Contains(this string source, string toCheck, StringCompar ison comparison) 425 public static bool Contains(this string source, string toCheck, StringCompar ison comparison)
396 { 426 {
397 return source.IndexOf(toCheck, comparison) != -1; 427 return source.IndexOf(toCheck, comparison) != -1;
(...skipping 26 matching lines...) Expand all
424 } 454 }
425 455
426 foreach (DirectoryInfo subdir in dir.GetDirectories()) 456 foreach (DirectoryInfo subdir in dir.GetDirectories())
427 { 457 {
428 string path = Path.Combine(dest, subdir.Name); 458 string path = Path.Combine(dest, subdir.Name);
429 CopyDirectory(subdir.FullName, path); 459 CopyDirectory(subdir.FullName, path);
430 } 460 }
431 } 461 }
432 } 462 }
433 } 463 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698