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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: visual_studio/NativeClientVSAddIn/UnitTests/TestUtilities.cs
diff --git a/visual_studio/NativeClientVSAddIn/UnitTests/TestUtilities.cs b/visual_studio/NativeClientVSAddIn/UnitTests/TestUtilities.cs
index 27941426fb325c54a8d4f43f0ca1014d6319d639..788a7a0223bedc38141d95f1ed76c550b82f3b9e 100644
--- a/visual_studio/NativeClientVSAddIn/UnitTests/TestUtilities.cs
+++ b/visual_studio/NativeClientVSAddIn/UnitTests/TestUtilities.cs
@@ -36,6 +36,12 @@ namespace UnitTests
public const string NotNaClProjectUniqueName = @"NotNaCl\NotNaCl.csproj";
/// <summary>
+ /// A generic boolean statement to be used with RetryWithTimeout.
+ /// </summary>
+ /// <returns>True if the statement is true, false if false.</returns>
+ public delegate bool RetryStatement();
+
+ /// <summary>
/// This starts an instance of Visual Studio and get its DTE object.
/// </summary>
/// <returns>DTE of the started instance.</returns>
@@ -134,27 +140,6 @@ namespace UnitTests
}
/// <summary>
- /// Ensures that the add-in is configured to load on start. If it isn't then some tests may
- /// unexpectedly fail, this check helps catch that problem early.
- /// </summary>
- /// <param name="dte">The main Visual Studio interface.</param>
- /// <param name="addInName">The name of the add-in to check if loaded.</param>
- public static void AssertAddinLoaded(DTE2 dte, string addInName)
- {
- bool found = false;
- foreach (AddIn addin in dte.AddIns)
- {
- if (addin.Connected && addInName.Equals(addin.Name))
- {
- found = true;
- break;
- }
- }
-
- Assert.IsTrue(found, "Add-in is not configured to load on start.");
- }
-
- /// <summary>
/// This returns the text contained in the given output window pane.
/// </summary>
/// <param name="pane">Pane to get text from.</param>
@@ -385,6 +370,51 @@ namespace UnitTests
}
/// <summary>
+ /// Ensures that the add-in is configured to load on start. If it isn't then some tests may
+ /// unexpectedly fail, this check helps catch that problem early.
+ /// </summary>
+ /// <param name="dte">The main Visual Studio interface.</param>
+ /// <param name="addInName">The name of the add-in to check if loaded.</param>
+ public static void AssertAddinLoaded(DTE2 dte, string addInName)
+ {
+ bool found = false;
+ foreach (AddIn addin in dte.AddIns)
+ {
+ if (addin.Connected && addInName.Equals(addin.Name))
+ {
+ found = true;
+ break;
+ }
+ }
+
+ Assert.IsTrue(found, "Add-in is not configured to load on start.");
+ }
+
+ /// <summary>
+ /// Will retry the given statement up to maxRetry times while pausing between each try for
+ /// the given interval.
+ /// </summary>
+ /// <param name="test">Generic boolean statement.</param>
+ /// <param name="interval">Amount of time to wait between each retry.</param>
+ /// <param name="maxRetry">Maximum number of retries.</param>
+ /// <param name="message">Message to print on failure.</param>
+ public static void AssertTrueWithTimeout(
+ RetryStatement test, TimeSpan interval, int maxRetry, string message)
+ {
+ for (int tryCount = 0; tryCount <= maxRetry; tryCount++)
+ {
+ if (test.Invoke())
+ {
+ return;
+ }
+
+ System.Threading.Thread.Sleep(interval);
+ }
+
+ throw new Exception(string.Format("Statement timed out. {0}", message));
+ }
+
+ /// <summary>
/// Extends the string class to allow checking if a string contains another string
/// allowing a comparison type (such as case-insensitivity).
/// </summary>

Powered by Google App Engine
This is Rietveld 408576698