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_; |
| 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); |
| 122 Assert.IsNotNull(project, "Testing project was not found"); |
| 123 string pepperPlatform = NativeClientVSAddIn.Strings.PepperPlatformName; |
| 124 debug_ = TestUtilities.GetVCConfiguration(project, "Debug", pepperPlatform
); |
| 125 release_ = TestUtilities.GetVCConfiguration(project, "Release", pepperPlat
form); |
| 126 |
| 127 // General |
| 128 page = "ConfigurationGeneral"; |
| 129 AllConfigsAssertPropertyEquals(page, "OutDir", @"$(ProjectDir)Win\", true)
; |
| 130 AllConfigsAssertPropertyEquals(page, "IntDir", @"$(ProjectDir)Intermediate
\Win\", true); |
| 131 AllConfigsAssertPropertyEquals(page, "TargetExt", ".dll", true); |
| 132 AllConfigsAssertPropertyEquals(page, "ConfigurationType", "DynamicLibrary"
, true); |
| 133 AllConfigsAssertPropertyEquals(page, "VSNaClSDKRoot", @"$(NACL_SDK_ROOT)\"
, false); |
| 134 |
| 135 // Debugging |
| 136 page = "WindowsLocalDebugger"; |
| 137 AllConfigsAssertPropertyEquals( |
| 138 page, |
| 139 "LocalDebuggerCommand", |
| 140 @"$(CHROME_PATH)\chrome.exe", |
| 141 true); |
| 142 AllConfigsAssertPropertyEquals( |
| 143 page, |
| 144 "LocalDebuggerCommandArguments", |
| 145 "--register-pepper-plugins=\"$(TargetPath)\";application/x-nacl localh
ost:5103", |
| 146 true); |
| 147 |
| 148 // VC++ Directories |
| 149 page = "ConfigurationDirectories"; |
| 150 AllConfigsAssertPropertyContains(page, "IncludePath", @"$(VSNaClSDKRoot)in
clude;", true); |
| 151 AllConfigsAssertPropertyContains(page, "IncludePath", @"$(VCInstallDir)inc
lude", true); |
| 152 AllConfigsAssertPropertyContains(page, "LibraryPath", @"$(VSNaClSDKRoot)li
b;", true); |
| 153 AllConfigsAssertPropertyContains(page, "LibraryPath", @"$(VCInstallDir)lib
", true); |
| 154 |
| 155 // C/C++ Code Generation |
| 156 page = "CL"; |
| 157 TestUtilities.AssertPropertyEquals( |
| 158 debug_, |
| 159 page, |
| 160 "RuntimeLibrary", |
| 161 "MultiThreadedDebug", |
| 162 false); |
| 163 TestUtilities.AssertPropertyEquals(release_, page, "RuntimeLibrary", "Mult
iThreaded", false); |
| 164 |
| 165 // Linker Input |
| 166 page = "Link"; |
| 167 AllConfigsAssertPropertyContains(page, "AdditionalDependencies", "ppapi_cp
p.lib", false); |
| 168 AllConfigsAssertPropertyContains(page, "AdditionalDependencies", "ppapi.li
b", false); |
| 169 } |
| 170 |
| 171 /// <summary> |
| 172 /// Tests that a given property has a specific value for both Debug and Rele
ase |
| 173 /// configurations under the current test's platform. |
| 174 /// </summary> |
| 175 /// <param name="pageName">Property page name where property resides.</param
> |
| 176 /// <param name="propertyName">Name of the property to check.</param> |
| 177 /// <param name="expectedValue">Expected value of the property.</param> |
| 178 /// <param name="ignoreCase">Ignore case when comparing the expected and act
ual values.</param> |
| 179 private void AllConfigsAssertPropertyEquals( |
| 180 string pageName, |
| 181 string propertyName, |
| 182 string expectedValue, |
| 183 bool ignoreCase) |
| 184 { |
| 185 TestUtilities.AssertPropertyEquals( |
| 186 debug_, |
| 187 pageName, |
| 188 propertyName, |
| 189 expectedValue, |
| 190 ignoreCase); |
| 191 TestUtilities.AssertPropertyEquals( |
| 192 release_, |
| 193 pageName, |
| 194 propertyName, |
| 195 expectedValue, |
| 196 ignoreCase); |
| 197 } |
| 198 |
| 199 /// <summary> |
| 200 /// Tests that a given property contains a specific string for both Debug an
d Release |
| 201 /// configurations under the NaCl platform. |
| 202 /// </summary> |
| 203 /// <param name="pageName">Property page name where property resides.</param
> |
| 204 /// <param name="propertyName">Name of the property to check.</param> |
| 205 /// <param name="expectedValue">Expected value of the property.</param> |
| 206 /// <param name="ignoreCase">Ignore case when comparing the expected and act
ual values.</param> |
| 207 private void AllConfigsAssertPropertyContains( |
| 208 string pageName, |
| 209 string propertyName, |
| 210 string expectedValue, |
| 211 bool ignoreCase) |
| 212 { |
| 213 TestUtilities.AssertPropertyContains( |
| 214 debug_, |
| 215 pageName, |
| 216 propertyName, |
| 217 expectedValue, |
| 218 ignoreCase); |
| 219 TestUtilities.AssertPropertyContains( |
| 220 release_, |
| 221 pageName, |
| 222 propertyName, |
| 223 expectedValue, |
| 224 ignoreCase); |
| 225 } |
| 226 } |
| 227 } |
OLD | NEW |