Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 namespace UnitTests | |
| 6 { | |
| 7 using System; | |
| 8 | |
| 9 using EnvDTE; | |
| 10 using EnvDTE80; | |
| 11 using Microsoft.VisualStudio.TestTools.UnitTesting; | |
| 12 using Microsoft.VisualStudio.VCProjectEngine; | |
| 13 | |
| 14 /// <summary> | |
| 15 /// This test class contains tests related to the custom project settings | |
| 16 /// and property pages for PPAPI and NaCl configurations. | |
| 17 /// </summary> | |
| 18 [TestClass] | |
| 19 public class ProjectSettingsTest | |
| 20 { | |
| 21 /// <summary> | |
| 22 /// The ProjectSettingsTest solution is a valid nacl/pepper plug-in VS solut ion | |
| 23 /// that has not had the custom platforms added (PPAPI and NaCl). Immediatel y | |
| 24 /// before these unit tests are run the project is copied into the testing | |
| 25 /// deployment directory, and the custom platforms are added to this copy so that | |
| 26 /// the project settings are based on the most recent template. Because unit -tests | |
| 27 /// run in any order, the solution should not be written to in any test. | |
| 28 /// </summary> | |
| 29 private const string ProjectSettingsTestSolution = | |
| 30 @"\ProjectSettingsTest\ProjectSettingsTest.sln"; | |
| 31 | |
| 32 /// <summary> | |
| 33 /// This is the project corresponding to ProjectSettingsTestSolution. | |
| 34 /// </summary> | |
| 35 private const string ProjectSettingsTestProject = | |
| 36 @"ProjectSettingsTest\ProjectSettingsTest.vcxproj"; | |
| 37 | |
| 38 /// <summary> | |
| 39 /// The main visual studio object. | |
| 40 /// </summary> | |
| 41 private DTE2 dte_ = null; | |
|
noelallen1
2012/07/20 21:46:01
Why set this one to null but not the others?
tysand
2012/07/24 21:24:15
You're right, in C# this would default to null any
| |
| 42 | |
| 43 /// <summary> | |
| 44 /// The project configuration for debug settings of a test's platform. | |
| 45 /// </summary> | |
| 46 private VCConfiguration debug_; | |
| 47 | |
| 48 /// <summary> | |
| 49 /// The project configuration for release settings of a test's platform | |
| 50 /// </summary> | |
| 51 private VCConfiguration release_; | |
| 52 | |
| 53 /// <summary> | |
| 54 /// Gets or sets the test context which provides information about, | |
| 55 /// and functionality for the current test run. | |
| 56 /// </summary> | |
| 57 public TestContext TestContext { get; set; } | |
| 58 | |
| 59 /// <summary> | |
| 60 /// This is run one time before any test methods are called. Here we set-up the testing copy | |
| 61 /// of ProjectSettingsTest to use the most up-to-date custom project setting s. | |
| 62 /// </summary> | |
| 63 /// <param name="testContext">Holds information about the current test run</ param> | |
| 64 [ClassInitialize] | |
| 65 public static void ClassSetup(TestContext testContext) | |
| 66 { | |
| 67 DTE2 dte = null; | |
| 68 try | |
| 69 { | |
| 70 dte = TestUtilities.StartVisualStudioInstance(); | |
| 71 dte.Solution.Open(testContext.DeploymentDirectory + ProjectSettingsTestS olution); | |
| 72 Project proj = dte.Solution.Projects.Item(ProjectSettingsTestProject); | |
| 73 | |
| 74 proj.ConfigurationManager.AddPlatform( | |
| 75 NativeClientVSAddIn.Strings.PepperPlatformName, | |
| 76 NativeClientVSAddIn.Strings.PepperPlatformName, | |
| 77 true); | |
| 78 | |
| 79 proj.ConfigurationManager.AddPlatform( | |
| 80 NativeClientVSAddIn.Strings.NaClPlatformName, | |
| 81 NativeClientVSAddIn.Strings.NaClPlatformName, | |
| 82 true); | |
| 83 | |
| 84 proj.Save(); | |
| 85 dte.Solution.SaveAs(testContext.DeploymentDirectory + ProjectSettingsTes tSolution); | |
| 86 } | |
| 87 finally | |
| 88 { | |
| 89 TestUtilities.CleanUpVisualStudioInstance(dte); | |
| 90 } | |
| 91 } | |
| 92 | |
| 93 /// <summary> | |
| 94 /// This is run before each test to create test resources. | |
| 95 /// </summary> | |
| 96 [TestInitialize] | |
| 97 public void TestSetup() | |
| 98 { | |
| 99 dte_ = TestUtilities.StartVisualStudioInstance(); | |
| 100 } | |
| 101 | |
| 102 /// <summary> | |
| 103 /// This is run after each test to clean up things created in TestSetup(). | |
| 104 /// </summary> | |
| 105 [TestCleanup] | |
| 106 public void TestCleanup() | |
| 107 { | |
| 108 TestUtilities.CleanUpVisualStudioInstance(dte_); | |
| 109 } | |
| 110 | |
| 111 /// <summary> | |
| 112 /// Test method to check that the PPAPI platform template correctly sets def ault values. | |
| 113 /// </summary> | |
| 114 [TestMethod] | |
| 115 public void VerifyDefaultPepperSettings() | |
| 116 { | |
| 117 string page; | |
| 118 | |
| 119 // Extract the debug and release configurations for Pepper from the projec t. | |
| 120 dte_.Solution.Open(TestContext.DeploymentDirectory + ProjectSettingsTestSo lution); | |
| 121 Project project = dte_.Solution.Projects.Item(ProjectSettingsTestProject); | |
|
noelallen1
2012/07/20 21:46:01
Should you test/assert project != null?
tysand
2012/07/24 21:24:15
The Projects collection throws an ArgumentExceptio
| |
| 122 string pepperPlatform = NativeClientVSAddIn.Strings.PepperPlatformName; | |
| 123 debug_ = TestUtilities.GetVCConfiguration(project, "Debug", pepperPlatform ); | |
|
noelallen1
2012/07/20 21:46:01
Should you test/assert debug_/release_ != null?
tysand
2012/07/24 21:24:15
I have code in GetVCConfiguration which throws an
| |
| 124 release_ = TestUtilities.GetVCConfiguration(project, "Release", pepperPlat form); | |
| 125 | |
| 126 // General | |
| 127 page = "ConfigurationGeneral"; | |
| 128 AllConfigsAssertPropertyEquals(page, "OutDir", @"$(SolutionDir)$(Configura tion)\$(Platform)\", true); | |
|
binji
2012/07/20 22:54:49
wrap at 100 char, here and elsewhere
tysand
2012/07/24 21:24:15
Done.
| |
| 129 AllConfigsAssertPropertyEquals(page, "IntDir", @"$(Configuration)\$(Platfo rm)\", true); | |
| 130 AllConfigsAssertPropertyEquals(page, "TargetExt", ".dll", true); | |
| 131 AllConfigsAssertPropertyEquals(page, "ConfigurationType", "DynamicLibrary" , true); | |
| 132 | |
| 133 // Debugging | |
| 134 page = "WindowsLocalDebugger"; | |
| 135 AllConfigsAssertPropertyEquals(page, "LocalDebuggerCommand", @"$(CHROME_PA TH)\chrome.exe", true); | |
| 136 AllConfigsAssertPropertyEquals(page, "LocalDebuggerCommandArguments", "--r egister-pepper-plugins=\"$(OutDir)$(TargetName)$(TargetExt);application/x-nacl\" --single-process --incognito --no-sandbox http://localhost:5103", true); | |
| 137 | |
| 138 // VC++ Directories | |
| 139 page = "ConfigurationDirectories"; | |
| 140 AllConfigsAssertPropertyContains(page, "IncludePath", @"$(NACL_SDK_ROOT)\s rc;", true); | |
| 141 | |
| 142 // C/C++ Code Generation | |
| 143 page = "CL"; | |
| 144 //// TODO(tysand): TestUtilities.AssertPropertyEquals(debug_, page, "Runti meLibrary", "MultiThreadedDebug", false); | |
|
noelallen1
2012/07/20 21:46:01
If you are not planning to finish this, add a bug
tysand
2012/07/24 21:24:15
Will review these settings in our meeting today an
| |
| 145 //// TODO(tysand): TestUtilities.AssertPropertyEquals(debug_, page, "Runti meLibrary", "MultiThreaded", false); | |
|
noelallen1
2012/07/20 21:46:01
release_?
tysand
2012/07/24 21:24:15
Done.
| |
| 146 | |
| 147 // Linker Input | |
| 148 page = "Link"; | |
| 149 //// TODO(tysand): AllConfigsAssertPropertyContains(page, "AdditionalDepen dencies", "ppapi_cpp.lib", false); | |
| 150 } | |
| 151 | |
| 152 /// <summary> | |
| 153 /// Test method to check that the NaCl platform template correctly sets defa ult values. | |
| 154 /// </summary> | |
| 155 [TestMethod] | |
| 156 public void VerifyDefaultNaClSettings() | |
| 157 { | |
| 158 string page; | |
| 159 | |
| 160 // Extract the debug and release configurations for NaCl from the project. | |
| 161 dte_.Solution.Open(TestContext.DeploymentDirectory + ProjectSettingsTestSo lution); | |
| 162 Project project = dte_.Solution.Projects.Item(ProjectSettingsTestProject); | |
| 163 string naclPlatform = NativeClientVSAddIn.Strings.NaClPlatformName; | |
| 164 debug_ = TestUtilities.GetVCConfiguration(project, "Debug", naclPlatform); | |
| 165 release_ = TestUtilities.GetVCConfiguration(project, "Release", naclPlatfo rm); | |
| 166 | |
| 167 // General | |
| 168 page = "ConfigurationGeneral"; | |
| 169 AllConfigsAssertPropertyEquals(page, "OutDir", @"$(SolutionDir)$(Configura tion)\$(Platform)\", true); | |
| 170 AllConfigsAssertPropertyEquals(page, "IntDir", @"$(Configuration)\$(Platfo rm)\", true); | |
| 171 AllConfigsAssertPropertyEquals(page, "TargetExt", ".nexe", true); | |
| 172 AllConfigsAssertPropertyEquals(page, "PlatformToolset", "win_x86_newlib", true); | |
| 173 AllConfigsAssertPropertyEquals(page, "ConfigurationType", "Application", t rue); | |
| 174 AllConfigsAssertPropertyEquals(page, "TargetArchitecture", "i686", true); | |
| 175 | |
| 176 // Debugging | |
| 177 page = "WindowsLocalDebugger"; | |
| 178 AllConfigsAssertPropertyEquals(page, "LocalDebuggerCommand", @"$(CHROME_PA TH)\chrome.exe", true); | |
| 179 AllConfigsAssertPropertyEquals(page, "LocalDebuggerCommandArguments", @"-- enable-nacl http://localhost:5103", true); | |
| 180 | |
| 181 // VC++ Directories | |
| 182 page = "ConfigurationDirectories"; | |
| 183 AllConfigsAssertPropertyContains(page, "IncludePath", @"$(ToolchainPath)\x 86_64-nacl\include; $(ToolchainPath)\x86_64-nacl\include\c++\4.4.3", true); | |
| 184 AllConfigsAssertPropertyContains(page, "LibraryPath", @"$(ToolchainPath)\x 86_64-nacl\lib32;", true); | |
| 185 | |
| 186 // C/C++ General | |
| 187 page = "CL"; | |
| 188 TestUtilities.AssertPropertyEquals( | |
| 189 debug_, | |
| 190 page, | |
| 191 "GenerateDebuggingInformation", | |
| 192 "true", | |
| 193 false); | |
| 194 TestUtilities.AssertPropertyEquals( | |
| 195 release_, | |
| 196 page, | |
| 197 "GenerateDebuggingInformation", | |
| 198 "false", | |
| 199 false); | |
| 200 | |
| 201 AllConfigsAssertPropertyEquals(page, "Warnings", "NormalWarnings", true); | |
| 202 AllConfigsAssertPropertyEquals(page, "WarningsAsErrors", "false", true); | |
| 203 AllConfigsAssertPropertyEquals(page, "OutputCommandLine", "false", true); | |
| 204 AllConfigsAssertPropertyEquals(page, "ConfigurationType", "$(Configuration Type)", true); | |
| 205 AllConfigsAssertPropertyEquals(page, "UserHeaderDependenciesOnly", "true", true); | |
| 206 | |
| 207 // C/C++ Optimization | |
| 208 TestUtilities.AssertPropertyEquals(debug_, page, "OptimizationLevel", "O0" , false); | |
| 209 TestUtilities.AssertPropertyEquals(release_, page, "OptimizationLevel", "O 3", false); | |
| 210 | |
| 211 // C/C++ Preprocessor | |
| 212 AllConfigsAssertPropertyContains(page, "PreprocessorDefinitions", "NaCl", false); | |
| 213 | |
| 214 // C/C++ Code Generation | |
| 215 //// TODO(tysand): AllConfigsAssertPropertyEquals(page, "PositionIndepende ntCode", "false", false); | |
| 216 //// TODO(tysand): AllConfigsAssertPropertyEquals(page, "ExceptionHandling ", "true", false); | |
| 217 | |
| 218 // C/C++ Output Files | |
| 219 AllConfigsAssertPropertyEquals(page, "ObjectFileName", @"$(IntDir)%(FileNa me).o", false); | |
| 220 | |
| 221 // C/C++ Advanced | |
| 222 AllConfigsAssertPropertyEquals(page, "CompileAs", "Default", true); | |
| 223 | |
| 224 // Linker Input | |
| 225 page = "Link"; | |
| 226 //// TODO(tysand): AllConfigsAssertPropertyContains(page, "AdditionalDepen dencies", "ppapi_cpp", false); | |
| 227 } | |
| 228 | |
| 229 /// <summary> | |
| 230 /// Tests that a given property has a specific value for both Debug and Rele ase | |
| 231 /// configurations under the current test's platform. | |
| 232 /// </summary> | |
| 233 /// <param name="pageName">Property page name where property resides.</param > | |
| 234 /// <param name="propertyName">Name of the property to check.</param> | |
| 235 /// <param name="expectedValue">Expected value of the property.</param> | |
| 236 /// <param name="ignoreCase">Ignore case when comparing the expected and act ual values.</param> | |
| 237 private void AllConfigsAssertPropertyEquals( | |
| 238 string pageName, | |
| 239 string propertyName, | |
| 240 string expectedValue, | |
| 241 bool ignoreCase) | |
| 242 { | |
| 243 TestUtilities.AssertPropertyEquals( | |
| 244 debug_, | |
| 245 pageName, | |
| 246 propertyName, | |
| 247 expectedValue, | |
| 248 ignoreCase); | |
| 249 TestUtilities.AssertPropertyEquals( | |
| 250 release_, | |
| 251 pageName, | |
| 252 propertyName, | |
| 253 expectedValue, | |
| 254 ignoreCase); | |
| 255 } | |
| 256 | |
| 257 /// <summary> | |
| 258 /// Tests that a given property contains a specific string for both Debug an d Release | |
| 259 /// configurations under the NaCl platform. | |
| 260 /// </summary> | |
| 261 /// <param name="pageName">Property page name where property resides.</param > | |
| 262 /// <param name="propertyName">Name of the property to check.</param> | |
| 263 /// <param name="expectedValue">Expected value of the property.</param> | |
| 264 /// <param name="ignoreCase">Ignore case when comparing the expected and act ual values.</param> | |
| 265 private void AllConfigsAssertPropertyContains( | |
| 266 string pageName, | |
| 267 string propertyName, | |
| 268 string expectedValue, | |
| 269 bool ignoreCase) | |
| 270 { | |
| 271 TestUtilities.AssertPropertyContains( | |
| 272 debug_, | |
| 273 pageName, | |
| 274 propertyName, | |
| 275 expectedValue, | |
| 276 ignoreCase); | |
| 277 TestUtilities.AssertPropertyContains( | |
| 278 release_, | |
| 279 pageName, | |
| 280 propertyName, | |
| 281 expectedValue, | |
| 282 ignoreCase); | |
| 283 } | |
| 284 } | |
| 285 } | |
| OLD | NEW |