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

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>
23 /// This starts an instance of Visual Studio and get it's DTE object. 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>
39 /// This starts an instance of Visual Studio and get its 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");
33 DTE2 visualStudio = Activator.CreateInstance(visualStudioType) as DTE2; 49 DTE2 visualStudio = Activator.CreateInstance(visualStudioType) as DTE2;
(...skipping 20 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="dte">Interface to an open Visual Studio instance to use.</p aram>
84 /// <param name="name">Name to give newly created solution.</param>
85 /// <param name="pepperCopyFrom">Platform name to copy existing settings fro m to pepper.</param>
86 /// <param name="naclCopyFrom">Platform name to copy existing settings from to NaCl.</param>
87 /// <param name="testContext">Test context used for finding deployment direc tory.</param>
88 /// <returns>Path to the newly created solution.</returns>
89 public static string CreateBlankValidNaClSolution(
90 DTE2 dte, string name, string pepperCopyFrom, string naclCopyFrom, TestC ontext testContext)
91 {
92 const string BlankSolution = "BlankValidSolution";
93 string newSolutionDir = Path.Combine(testContext.DeploymentDirectory, name );
94 string newSolution = Path.Combine(newSolutionDir, BlankSolution + ".sln");
95 CopyDirectory(Path.Combine(testContext.DeploymentDirectory, BlankSolution) , newSolutionDir);
96
97 try
98 {
99 dte.Solution.Open(newSolution);
100 Project proj = dte.Solution.Projects.Item(BlankNaClProjectUniqueName);
101
102 // Order matters if copying from the other Native Client type.
103 if (pepperCopyFrom.Equals(NativeClientVSAddIn.Strings.NaClPlatformName))
104 {
105 proj.ConfigurationManager.AddPlatform(
106 NativeClientVSAddIn.Strings.NaClPlatformName, naclCopyFrom, true);
107 proj.ConfigurationManager.AddPlatform(
108 NativeClientVSAddIn.Strings.PepperPlatformName, pepperCopyFrom, true );
109 }
110 else
111 {
112 proj.ConfigurationManager.AddPlatform(
113 NativeClientVSAddIn.Strings.PepperPlatformName, pepperCopyFrom, true );
114 proj.ConfigurationManager.AddPlatform(
115 NativeClientVSAddIn.Strings.NaClPlatformName, naclCopyFrom, true);
116 }
117
118 proj.Save();
119 dte.Solution.SaveAs(newSolution);
120 }
121 finally
122 {
123 if (dte.Solution != null)
124 {
125 dte.Solution.Close();
126 }
127 }
128
129 return newSolution;
130 }
131
132 /// <summary>
64 /// This returns the text contained in the given output window pane. 133 /// This returns the text contained in the given output window pane.
65 /// </summary> 134 /// </summary>
66 /// <param name="pane">Pane to get text from.</param> 135 /// <param name="pane">Pane to get text from.</param>
67 /// <returns>Text in the window.</returns> 136 /// <returns>Text in the window.</returns>
68 public static string GetPaneText(OutputWindowPane pane) 137 public static string GetPaneText(OutputWindowPane pane)
69 { 138 {
70 TextSelection selection = pane.TextDocument.Selection; 139 TextSelection selection = pane.TextDocument.Selection;
71 selection.StartOfDocument(false); 140 selection.StartOfDocument(false);
72 selection.EndOfDocument(true); 141 selection.EndOfDocument(true);
73 return selection.Text; 142 return selection.Text;
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 /// allowing a comparison type (such as case-insensitivity). 341 /// allowing a comparison type (such as case-insensitivity).
273 /// </summary> 342 /// </summary>
274 /// <param name="source">Base string to search.</param> 343 /// <param name="source">Base string to search.</param>
275 /// <param name="toCheck">String to check if contained within base string.</ param> 344 /// <param name="toCheck">String to check if contained within base string.</ param>
276 /// <param name="comparison">Comparison type.</param> 345 /// <param name="comparison">Comparison type.</param>
277 /// <returns>True if toCheck is contained in source.</returns> 346 /// <returns>True if toCheck is contained in source.</returns>
278 public static bool Contains(this string source, string toCheck, StringCompar ison comparison) 347 public static bool Contains(this string source, string toCheck, StringCompar ison comparison)
279 { 348 {
280 return source.IndexOf(toCheck, comparison) != -1; 349 return source.IndexOf(toCheck, comparison) != -1;
281 } 350 }
351
352 /// <summary>
353 /// Copies the entire contents of a directory and sub directories.
354 /// </summary>
355 /// <param name="source">Directory to copy from.</param>
356 /// <param name="dest">Directory to copy to.</param>
357 public static void CopyDirectory(string source, string dest)
358 {
359 DirectoryInfo dir = new DirectoryInfo(source);
360
361 if (!dir.Exists)
362 {
363 throw new DirectoryNotFoundException(source);
364 }
365
366 if (!Directory.Exists(dest))
367 {
368 Directory.CreateDirectory(dest);
369 }
370
371 FileInfo[] files = dir.GetFiles();
372 foreach (FileInfo file in files)
373 {
374 string path = Path.Combine(dest, file.Name);
375 file.CopyTo(path, false);
376 }
377
378 foreach (DirectoryInfo subdir in dir.GetDirectories())
379 {
380 string path = Path.Combine(dest, subdir.Name);
381 CopyDirectory(subdir.FullName, path);
382 }
383 }
282 } 384 }
283 } 385 }
OLDNEW
« no previous file with comments | « visual_studio/NativeClientVSAddIn/UnitTests/ProjectSettingsTest.cs ('k') | visual_studio/NativeClientVSAddIn/build.bat » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698