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

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

Issue 11266051: Add PNaCl support for VS addin. (Closed) Base URL: http://nativeclient-sdk.googlecode.com/svn/trunk/src
Patch Set: fix nits and tests Created 8 years, 1 month 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.IO; 8 using System.IO;
9 9
10 using EnvDTE; 10 using EnvDTE;
11 using EnvDTE80; 11 using EnvDTE80;
12 using Microsoft.VisualStudio.TestTools.UnitTesting; 12 using Microsoft.VisualStudio.TestTools.UnitTesting;
13 13
14 using NativeClientVSAddIn; 14 using NativeClientVSAddIn;
15 15
16 /// <summary> 16 /// <summary>
17 /// This is a test class for PropertyManagerTest and is intended 17 /// This is a test class for PropertyManagerTest and is intended
18 /// to contain all PropertyManager Unit Tests 18 /// to contain all PropertyManager Unit Tests
19 /// </summary> 19 /// </summary>
20 [TestClass] 20 [TestClass]
21 public class PropertyManagerTest 21 public class PropertyManagerTest
22 { 22 {
23 /// <summary> 23 /// <summary>
24 /// This holds the path to the NaCl solution used in these tests. 24 /// This holds the path to the NaCl solution used in these tests.
25 /// The NaCl solution is a valid nacl/pepper plug-in VS solution. 25 /// The NaCl solution is a valid NaCl/pepper plug-in VS solution.
26 /// It is copied into the testing deployment directory and opened in some te sts. 26 /// It is copied into the testing deployment directory and opened in some te sts.
27 /// Because unit-tests run in any order, the solution should not be written to 27 /// Because unit-tests run in any order, the solution should not be written to
28 /// in any tests. 28 /// in any tests.
29 /// </summary> 29 /// </summary>
30 private static string naclSolution; 30 private static string naclSolution;
31 31
32 /// <summary> 32 /// <summary>
33 /// The main visual studio object. 33 /// The main visual studio object.
34 /// </summary> 34 /// </summary>
35 private DTE2 dte_; 35 private DTE2 dte_;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 PropertyManager target = new PropertyManager(); 105 PropertyManager target = new PropertyManager();
106 dte_.Solution.Open(naclSolution); 106 dte_.Solution.Open(naclSolution);
107 107
108 Project naclProject = dte_.Solution.Projects.Item(TestUtilities.BlankNaClP rojectUniqueName); 108 Project naclProject = dte_.Solution.Projects.Item(TestUtilities.BlankNaClP rojectUniqueName);
109 Project notNacl = dte_.Solution.Projects.Item(TestUtilities.NotNaClProject UniqueName); 109 Project notNacl = dte_.Solution.Projects.Item(TestUtilities.NotNaClProject UniqueName);
110 110
111 // Invalid project. 111 // Invalid project.
112 target.SetTarget(notNacl, Strings.PepperPlatformName, "Debug"); 112 target.SetTarget(notNacl, Strings.PepperPlatformName, "Debug");
113 Assert.AreEqual( 113 Assert.AreEqual(
114 PropertyManager.ProjectPlatformType.Other, 114 PropertyManager.ProjectPlatformType.Other,
115 target.ProjectPlatform, 115 target.PlatformType,
116 "SetTarget should not succeed with non-nacl/pepper project."); 116 "SetTarget should not succeed with non-nacl/pepper project.");
117 117
118 // Try valid project with different platforms. 118 // Try valid project with different platforms.
119 target.SetTarget(naclProject, Strings.NaCl64PlatformName, "Debug"); 119 target.SetTarget(naclProject, Strings.NaCl64PlatformName, "Debug");
120 Assert.AreEqual( 120 Assert.AreEqual(
121 PropertyManager.ProjectPlatformType.NaCl, 121 PropertyManager.ProjectPlatformType.NaCl,
122 target.ProjectPlatform, 122 target.PlatformType,
123 "SetTarget did not succeed with nacl platform on valid project."); 123 "SetTarget did not succeed with nacl platform on valid project.");
124 Assert.AreEqual(expectedSDKRootDir, target.SDKRootDirectory, "SDK Root inc orrect."); 124 Assert.AreEqual(expectedSDKRootDir, target.SDKRootDirectory, "SDK Root inc orrect.");
125 125
126 target.SetTarget(naclProject, "Win32", "Debug"); 126 target.SetTarget(naclProject, "Win32", "Debug");
127 Assert.AreEqual( 127 Assert.AreEqual(
128 PropertyManager.ProjectPlatformType.Other, 128 PropertyManager.ProjectPlatformType.Other,
129 target.ProjectPlatform, 129 target.PlatformType,
130 "SetTarget did not set 'other' platform on when Win32 platform of vali d project."); 130 "SetTarget did not set 'other' platform on when Win32 platform of vali d project.");
131 131
132 target.SetTarget(naclProject, Strings.PNaClPlatformName, "Debug");
133 Assert.AreEqual(
134 PropertyManager.ProjectPlatformType.NaCl,
135 target.PlatformType,
136 "SetTarget did not succeed with nacl platform on valid project.");
137 Assert.AreEqual(expectedSDKRootDir, target.SDKRootDirectory, "SDK Root inc orrect.");
138
132 target.SetTarget(naclProject, Strings.PepperPlatformName, "Debug"); 139 target.SetTarget(naclProject, Strings.PepperPlatformName, "Debug");
133 Assert.AreEqual( 140 Assert.AreEqual(
134 PropertyManager.ProjectPlatformType.Pepper, 141 PropertyManager.ProjectPlatformType.Pepper,
135 target.ProjectPlatform, 142 target.PlatformType,
136 "SetTarget did not succeed with pepper platform on valid project."); 143 "SetTarget did not succeed with pepper platform on valid project.");
137 Assert.AreEqual(expectedSDKRootDir, target.SDKRootDirectory, "SDK Root inc orrect."); 144 Assert.AreEqual(expectedSDKRootDir, target.SDKRootDirectory, "SDK Root inc orrect.");
138 145
139 // Setting the start-up project to a non-cpp project should make loading f ail. 146 // Setting the start-up project to a non-cpp project should make loading f ail.
140 object[] badStartupProj = { TestUtilities.NotNaClProjectUniqueName }; 147 object[] badStartupProj = { TestUtilities.NotNaClProjectUniqueName };
141 dte_.Solution.SolutionBuild.StartupProjects = badStartupProj; 148 dte_.Solution.SolutionBuild.StartupProjects = badStartupProj;
142 target.SetTargetToActive(dte_); 149 target.SetTargetToActive(dte_);
143 Assert.AreEqual( 150 Assert.AreEqual(
144 PropertyManager.ProjectPlatformType.Other, 151 PropertyManager.ProjectPlatformType.Other,
145 target.ProjectPlatform, 152 target.PlatformType,
146 "SetTargetToActive should not succeed with non-nacl/pepper project."); 153 "SetTargetToActive should not succeed with non-nacl/pepper project.");
147 154
148 // Setting the start-up project to correct C++ project, but also setting t he platform 155 // Setting the start-up project to correct C++ project, but also setting t he platform
149 // to non-nacl/pepper should make loading fail. 156 // to non-nacl/pepper should make loading fail.
150 object[] startupProj = { TestUtilities.BlankNaClProjectUniqueName }; 157 object[] startupProj = { TestUtilities.BlankNaClProjectUniqueName };
151 dte_.Solution.SolutionBuild.StartupProjects = startupProj; 158 dte_.Solution.SolutionBuild.StartupProjects = startupProj;
152 TestUtilities.SetSolutionConfiguration( 159 TestUtilities.SetSolutionConfiguration(
153 dte_, TestUtilities.BlankNaClProjectUniqueName, "Debug", "Win32"); 160 dte_, TestUtilities.BlankNaClProjectUniqueName, "Debug", "Win32");
154 target.SetTargetToActive(dte_); 161 target.SetTargetToActive(dte_);
155 Assert.AreEqual( 162 Assert.AreEqual(
156 PropertyManager.ProjectPlatformType.Other, 163 PropertyManager.ProjectPlatformType.Other,
157 target.ProjectPlatform, 164 target.PlatformType,
158 "SetTargetToActive should not succeed with Win32 platform."); 165 "SetTargetToActive should not succeed with Win32 platform.");
159 166
160 // Now setting the platform to NaCl should make this succeed. 167 // Now setting the platform to NaCl should make this succeed.
161 TestUtilities.SetSolutionConfiguration( 168 TestUtilities.SetSolutionConfiguration(
162 dte_, TestUtilities.BlankNaClProjectUniqueName, "Debug", Strings.NaCl6 4PlatformName); 169 dte_, TestUtilities.BlankNaClProjectUniqueName, "Debug", Strings.NaCl6 4PlatformName);
163 target.SetTargetToActive(dte_); 170 target.SetTargetToActive(dte_);
164 Assert.AreEqual( 171 Assert.AreEqual(
165 PropertyManager.ProjectPlatformType.NaCl, 172 PropertyManager.ProjectPlatformType.NaCl,
166 target.ProjectPlatform, 173 target.PlatformType,
167 "SetTargetToActive should succeed with NaCl platform and valid project ."); 174 "SetTargetToActive should succeed with NaCl platform and valid project .");
168 Assert.AreEqual(expectedSDKRootDir, target.SDKRootDirectory, "SDK Root inc orrect."); 175 Assert.AreEqual(expectedSDKRootDir, target.SDKRootDirectory, "SDK Root inc orrect.");
169 } 176 }
170 177
171 /// <summary> 178 /// <summary>
172 /// A test for GetProperty. Checks some non-trivial C# properties and the Ge tProperty method. 179 /// A test for GetProperty. Checks some non-trivial C# properties and the Ge tProperty method.
173 /// </summary> 180 /// </summary>
174 [TestMethod] 181 [TestMethod]
175 public void GetPropertyTest() 182 public void GetPropertyTest()
176 { 183 {
177 string expectedSDKRootDir = 184 string expectedSDKRootDir =
178 Environment.GetEnvironmentVariable(Strings.SDKPathEnvironmentVariable) ; 185 Environment.GetEnvironmentVariable(Strings.SDKPathEnvironmentVariable) ;
179 Assert.IsNotNull(expectedSDKRootDir, "SDK Path environment variable not se t!"); 186 Assert.IsNotNull(expectedSDKRootDir, "SDK Path environment variable not se t!");
180 expectedSDKRootDir = expectedSDKRootDir.TrimEnd(new char[] { '/', '\\' }); 187 expectedSDKRootDir = expectedSDKRootDir.TrimEnd(new char[] { '/', '\\' });
181 188
182 // Set up the property manager to read the NaCl platform settings from Bla nkValidSolution. 189 // Set up the property manager to read the NaCl platform settings from Bla nkValidSolution.
183 PropertyManager target = new PropertyManager(); 190 PropertyManager target = new PropertyManager();
184 dte_.Solution.Open(naclSolution); 191 dte_.Solution.Open(naclSolution);
185 Project naclProject = dte_.Solution.Projects.Item(TestUtilities.BlankNaClP rojectUniqueName); 192 Project naclProject = dte_.Solution.Projects.Item(TestUtilities.BlankNaClP rojectUniqueName);
186 target.SetTarget(naclProject, Strings.NaCl64PlatformName, "Debug"); 193 target.SetTarget(naclProject, Strings.NaCl64PlatformName, "Debug");
187 Assert.AreEqual( 194 Assert.AreEqual(
188 PropertyManager.ProjectPlatformType.NaCl, 195 PropertyManager.ProjectPlatformType.NaCl,
189 target.ProjectPlatform, 196 target.PlatformType,
190 "SetTarget did not succeed with nacl platform on valid project."); 197 "SetTarget did not succeed with nacl platform on valid project.");
191 198
192 string slnDir = Path.GetDirectoryName(naclSolution); 199 string slnDir = Path.GetDirectoryName(naclSolution);
193 string projectDir = Path.Combine( 200 string projectDir = Path.Combine(
194 slnDir, Path.GetDirectoryName(TestUtilities.BlankNaClProjectUniqueName )) + @"\"; 201 slnDir, Path.GetDirectoryName(TestUtilities.BlankNaClProjectUniqueName )) + @"\";
195 string outputDir = Path.Combine(projectDir, "NaCl64", "newlib", "Debug") + @"\"; 202 string outputDir = Path.Combine(projectDir, "NaCl64", "newlib", "Debug") + @"\";
196 string assembly = Path.Combine(outputDir, TestUtilities.BlankNaClProjectNa me + "_64.nexe"); 203 string assembly = Path.Combine(outputDir, TestUtilities.BlankNaClProjectNa me + "_64.nexe");
197 204
198 Assert.AreEqual(expectedSDKRootDir, target.SDKRootDirectory, "SDK Root."); 205 Assert.AreEqual(expectedSDKRootDir, target.SDKRootDirectory, "SDK Root.");
199 Assert.AreEqual(projectDir, target.ProjectDirectory, "ProjectDirectory."); 206 Assert.AreEqual(projectDir, target.ProjectDirectory, "ProjectDirectory.");
200 Assert.AreEqual(outputDir, target.OutputDirectory, "OutputDirectory."); 207 Assert.AreEqual(outputDir, target.OutputDirectory, "OutputDirectory.");
201 Assert.AreEqual(assembly, target.PluginAssembly, "PluginAssembly."); 208 Assert.AreEqual(assembly, target.PluginAssembly, "PluginAssembly.");
202 Assert.AreEqual( 209 Assert.AreEqual(
203 @"newlib", 210 @"newlib",
204 target.GetProperty("ConfigurationGeneral", "ToolchainName"), 211 target.GetProperty("ConfigurationGeneral", "ToolchainName"),
205 "GetProperty() with ToolchainName incorrect."); 212 "GetProperty() with ToolchainName incorrect.");
206 } 213 }
207 214
208 /// <summary> 215 /// <summary>
216 /// A test for GetProperty. Checks some non-trivial C# properties and the Ge tProperty method.
217 /// </summary>
218 [TestMethod]
219 public void GetPropertyPNaClTest()
220 {
221 string expectedSDKRootDir =
222 Environment.GetEnvironmentVariable(Strings.SDKPathEnvironmentVariabl e);
223 Assert.IsNotNull(expectedSDKRootDir, "SDK Path environment variable not set!");
224 expectedSDKRootDir = expectedSDKRootDir.TrimEnd(new char[] { '/', '\\' } );
225
226 // Set up the property manager to read the NaCl platform settings from B lankValidSolution.
227 PropertyManager target = new PropertyManager();
228 dte_.Solution.Open(naclSolution);
229 Project naclProject = dte_.Solution.Projects.Item(TestUtilities.BlankNaC lProjectUniqueName);
230 target.SetTarget(naclProject, Strings.PNaClPlatformName, "Debug");
231 Assert.AreEqual(
232 PropertyManager.ProjectPlatformType.NaCl,
233 target.PlatformType,
234 "SetTarget did not succeed with nacl platform on valid project.");
235
236 string slnDir = Path.GetDirectoryName(naclSolution);
237 string projectDir = Path.Combine(
238 slnDir, Path.GetDirectoryName(TestUtilities.BlankNaClProjectUniqueNa me)) + @"\";
239 string outputDir = Path.Combine(projectDir, "PNaCl", "newlib", "Debug") + @"\";
240 string assembly = Path.Combine(outputDir, TestUtilities.BlankNaClProject Name + ".pexe");
241
242 Assert.AreEqual(expectedSDKRootDir, target.SDKRootDirectory, "SDK Root." );
243 Assert.AreEqual(projectDir, target.ProjectDirectory, "ProjectDirectory." );
244 Assert.AreEqual(outputDir, target.OutputDirectory, "OutputDirectory.");
245 Assert.AreEqual(assembly, target.PluginAssembly, "PluginAssembly.");
246 Assert.AreEqual(
247 @"newlib",
248 target.GetProperty("ConfigurationGeneral", "ToolchainName"),
249 "GetProperty() with ToolchainName incorrect.");
250 }
251
252 /// <summary>
209 /// A test for SetProperty. 253 /// A test for SetProperty.
210 /// </summary> 254 /// </summary>
211 [TestMethod] 255 [TestMethod]
212 public void SetPropertyTest() 256 public void SetPropertyTest()
213 { 257 {
214 string setTargetSolution = TestUtilities.CreateBlankValidNaClSolution( 258 string setTargetSolution = TestUtilities.CreateBlankValidNaClSolution(
215 dte_, 259 dte_,
216 "PropertyManagerTestSetTarget", 260 "PropertyManagerTestSetTarget",
217 NativeClientVSAddIn.Strings.NaCl64PlatformName, 261 NativeClientVSAddIn.Strings.NaCl64PlatformName,
218 NativeClientVSAddIn.Strings.NaCl64PlatformName, 262 NativeClientVSAddIn.Strings.NaCl64PlatformName,
219 TestContext); 263 TestContext);
220 264
221 // Set up the property manager to read the NaCl platform settings from Bla nkValidSolution. 265 // Set up the property manager to read the NaCl platform settings from Bla nkValidSolution.
222 PropertyManager target = new PropertyManager(); 266 PropertyManager target = new PropertyManager();
223 dte_.Solution.Open(setTargetSolution); 267 dte_.Solution.Open(setTargetSolution);
224 Project naclProject = dte_.Solution.Projects.Item(TestUtilities.BlankNaClP rojectUniqueName); 268 Project naclProject = dte_.Solution.Projects.Item(TestUtilities.BlankNaClP rojectUniqueName);
225 target.SetTarget(naclProject, Strings.NaCl64PlatformName, "Debug"); 269 target.SetTarget(naclProject, Strings.NaCl64PlatformName, "Debug");
226 Assert.AreEqual( 270 Assert.AreEqual(
227 PropertyManager.ProjectPlatformType.NaCl, 271 PropertyManager.ProjectPlatformType.NaCl,
228 target.ProjectPlatform, 272 target.PlatformType,
229 "SetTarget did not succeed with nacl platform on valid project."); 273 "SetTarget did not succeed with nacl platform on valid project.");
230 274
231 string newValue = "ThisIsNew"; 275 string newValue = "ThisIsNew";
232 target.SetProperty("ConfigurationGeneral", "VSNaClSDKRoot", newValue); 276 target.SetProperty("ConfigurationGeneral", "VSNaClSDKRoot", newValue);
233 Assert.AreEqual( 277 Assert.AreEqual(
234 newValue, 278 newValue,
235 target.GetProperty("ConfigurationGeneral", "VSNaClSDKRoot"), 279 target.GetProperty("ConfigurationGeneral", "VSNaClSDKRoot"),
236 "SetProperty() did not set property VSNaClSDKRoot."); 280 "SetProperty() did not set property VSNaClSDKRoot.");
237 } 281 }
238 } 282 }
239 } 283 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698