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

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

Issue 10831030: NaCl settings and completed install scripts. (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.Linq; 10 using System.Linq;
10 using System.Management; 11 using System.Management;
11 12
12 using EnvDTE; 13 using EnvDTE;
13 using EnvDTE80; 14 using EnvDTE80;
14 using Microsoft.VisualStudio.TestTools.UnitTesting; 15 using Microsoft.VisualStudio.TestTools.UnitTesting;
15 using Microsoft.VisualStudio.VCProjectEngine; 16 using Microsoft.VisualStudio.VCProjectEngine;
16 17
17 /// <summary> 18 /// <summary>
18 /// This class contains utilities for running tests. 19 /// This class contains utilities for running tests.
19 /// </summary> 20 /// </summary>
20 public static class TestUtilities 21 public static class TestUtilities
21 { 22 {
22 /// <summary> 23 /// <summary>
24 /// Name of the NaCl project in BlankValidSolution.
25 /// </summary>
26 public const string BlankNaClProjectName = @"NaClProject";
27
28 /// <summary>
29 /// Uniquename of the NaCl project in BlankValidSolution.
30 /// </summary>
31 public const string BlankNaClProjectUniqueName = @"NaClProject\NaClProject.v cxproj";
32
33 /// <summary>
34 /// Uniquename of the non-NaCl project in BlankValidSolution.
35 /// </summary>
36 public const string NotNaClProjectUniqueName = @"NotNaCl\NotNaCl.csproj";
37
38 /// <summary>
23 /// This starts an instance of Visual Studio and get it's DTE object. 39 /// This starts an instance of Visual Studio and get it's DTE object.
24 /// </summary> 40 /// </summary>
25 /// <returns>DTE of the started instance.</returns> 41 /// <returns>DTE of the started instance.</returns>
26 public static DTE2 StartVisualStudioInstance() 42 public static DTE2 StartVisualStudioInstance()
27 { 43 {
28 // Set up filter to handle threading events and automatically retry calls 44 // Set up filter to handle threading events and automatically retry calls
29 // to dte which fail because dte is busy. 45 // to dte which fail because dte is busy.
30 ComMessageFilter.Register(); 46 ComMessageFilter.Register();
31 47
32 Type visualStudioType = Type.GetTypeFromProgID("VisualStudio.DTE.10.0"); 48 Type visualStudioType = Type.GetTypeFromProgID("VisualStudio.DTE.10.0");
(...skipping 21 matching lines...) Expand all
54 } 70 }
55 71
56 dte.Quit(); 72 dte.Quit();
57 } 73 }
58 74
59 // Stop the message filter. 75 // Stop the message filter.
60 ComMessageFilter.Revoke(); 76 ComMessageFilter.Revoke();
61 } 77 }
62 78
63 /// <summary> 79 /// <summary>
80 /// Creates a blank valid NaCl project with up-to-date settings. The path t o the new solution
81 /// is returned.
82 /// </summary>
83 /// <param name="name">Name to give newly created solution.</param>
84 /// <param name="testContext">Test context used for finding deployment direc tory.</param>
85 /// <returns>Path to the newly created solution.</returns>
86 public static string CreateBlankValidNaClSolution(string name, TestContext t estContext)
87 {
88 const string BlankSolution = "BlankValidSolution";
89 string newSolutionDir = Path.Combine(testContext.DeploymentDirectory, name );
90 string newSolution = Path.Combine(newSolutionDir, BlankSolution + ".sln");
91 CopyDirectory(Path.Combine(testContext.DeploymentDirectory, BlankSolution) , newSolutionDir);
92
93 DTE2 dte = null;
94 try
95 {
96 dte = TestUtilities.StartVisualStudioInstance();
97 dte.Solution.Open(newSolution);
98 Project proj = dte.Solution.Projects.Item(BlankNaClProjectUniqueName);
99
100 proj.ConfigurationManager.AddPlatform(
101 NativeClientVSAddIn.Strings.PepperPlatformName,
102 NativeClientVSAddIn.Strings.PepperPlatformName,
103 true);
104
105 proj.ConfigurationManager.AddPlatform(
106 NativeClientVSAddIn.Strings.NaClPlatformName,
107 NativeClientVSAddIn.Strings.NaClPlatformName,
108 true);
109
110 proj.Save();
111 dte.Solution.SaveAs(newSolution);
112 }
113 finally
114 {
115 TestUtilities.CleanUpVisualStudioInstance(dte);
116 }
117
118 return newSolution;
119 }
120
121 /// <summary>
64 /// This returns the text contained in the given output window pane. 122 /// This returns the text contained in the given output window pane.
65 /// </summary> 123 /// </summary>
66 /// <param name="pane">Pane to get text from.</param> 124 /// <param name="pane">Pane to get text from.</param>
67 /// <returns>Text in the window.</returns> 125 /// <returns>Text in the window.</returns>
68 public static string GetPaneText(OutputWindowPane pane) 126 public static string GetPaneText(OutputWindowPane pane)
69 { 127 {
70 TextSelection selection = pane.TextDocument.Selection; 128 TextSelection selection = pane.TextDocument.Selection;
71 selection.StartOfDocument(false); 129 selection.StartOfDocument(false);
72 selection.EndOfDocument(true); 130 selection.EndOfDocument(true);
73 return selection.Text; 131 return selection.Text;
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 /// allowing a comparison type (such as case-insensitivity). 330 /// allowing a comparison type (such as case-insensitivity).
273 /// </summary> 331 /// </summary>
274 /// <param name="source">Base string to search.</param> 332 /// <param name="source">Base string to search.</param>
275 /// <param name="toCheck">String to check if contained within base string.</ param> 333 /// <param name="toCheck">String to check if contained within base string.</ param>
276 /// <param name="comparison">Comparison type.</param> 334 /// <param name="comparison">Comparison type.</param>
277 /// <returns>True if toCheck is contained in source.</returns> 335 /// <returns>True if toCheck is contained in source.</returns>
278 public static bool Contains(this string source, string toCheck, StringCompar ison comparison) 336 public static bool Contains(this string source, string toCheck, StringCompar ison comparison)
279 { 337 {
280 return source.IndexOf(toCheck, comparison) != -1; 338 return source.IndexOf(toCheck, comparison) != -1;
281 } 339 }
340
341 /// <summary>
342 /// Copies the entire contents of a directory and sub directories.
343 /// </summary>
344 /// <param name="source">Directory to copy from.</param>
345 /// <param name="dest">Directory to copy to.</param>
346 public static void CopyDirectory(string source, string dest)
347 {
348 DirectoryInfo dir = new DirectoryInfo(source);
349
350 if (!dir.Exists)
351 {
352 throw new DirectoryNotFoundException(source);
353 }
354
355 if (!Directory.Exists(dest))
356 {
357 Directory.CreateDirectory(dest);
358 }
359
360 FileInfo[] files = dir.GetFiles();
361 foreach (FileInfo file in files)
362 {
363 string path = Path.Combine(dest, file.Name);
364 file.CopyTo(path, false);
365 }
366
367 foreach (DirectoryInfo subdir in dir.GetDirectories())
368 {
369 string path = Path.Combine(dest, subdir.Name);
370 CopyDirectory(subdir.FullName, path);
371 }
372 }
282 } 373 }
283 } 374 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698