Chromium Code Reviews| Index: visual_studio/NativeClientVSAddIn/UnitTests/ProjectSettingsTest.cs |
| diff --git a/visual_studio/NativeClientVSAddIn/UnitTests/ProjectSettingsTest.cs b/visual_studio/NativeClientVSAddIn/UnitTests/ProjectSettingsTest.cs |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7b73f182b18223a3fc5ea5eea44e20e991bffbb8 |
| --- /dev/null |
| +++ b/visual_studio/NativeClientVSAddIn/UnitTests/ProjectSettingsTest.cs |
| @@ -0,0 +1,285 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +namespace UnitTests |
| +{ |
| + using System; |
| + |
| + using EnvDTE; |
| + using EnvDTE80; |
| + using Microsoft.VisualStudio.TestTools.UnitTesting; |
| + using Microsoft.VisualStudio.VCProjectEngine; |
| + |
| + /// <summary> |
| + /// This test class contains tests related to the custom project settings |
| + /// and property pages for PPAPI and NaCl configurations. |
| + /// </summary> |
| + [TestClass] |
| + public class ProjectSettingsTest |
| + { |
| + /// <summary> |
| + /// The ProjectSettingsTest solution is a valid nacl/pepper plug-in VS solution |
| + /// that has not had the custom platforms added (PPAPI and NaCl). Immediately |
| + /// before these unit tests are run the project is copied into the testing |
| + /// deployment directory, and the custom platforms are added to this copy so that |
| + /// the project settings are based on the most recent template. Because unit-tests |
| + /// run in any order, the solution should not be written to in any test. |
| + /// </summary> |
| + private const string ProjectSettingsTestSolution = |
| + @"\ProjectSettingsTest\ProjectSettingsTest.sln"; |
| + |
| + /// <summary> |
| + /// This is the project corresponding to ProjectSettingsTestSolution. |
| + /// </summary> |
| + private const string ProjectSettingsTestProject = |
| + @"ProjectSettingsTest\ProjectSettingsTest.vcxproj"; |
| + |
| + /// <summary> |
| + /// The main visual studio object. |
| + /// </summary> |
| + 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
|
| + |
| + /// <summary> |
| + /// The project configuration for debug settings of a test's platform. |
| + /// </summary> |
| + private VCConfiguration debug_; |
| + |
| + /// <summary> |
| + /// The project configuration for release settings of a test's platform |
| + /// </summary> |
| + private VCConfiguration release_; |
| + |
| + /// <summary> |
| + /// Gets or sets the test context which provides information about, |
| + /// and functionality for the current test run. |
| + /// </summary> |
| + public TestContext TestContext { get; set; } |
| + |
| + /// <summary> |
| + /// This is run one time before any test methods are called. Here we set-up the testing copy |
| + /// of ProjectSettingsTest to use the most up-to-date custom project settings. |
| + /// </summary> |
| + /// <param name="testContext">Holds information about the current test run</param> |
| + [ClassInitialize] |
| + public static void ClassSetup(TestContext testContext) |
| + { |
| + DTE2 dte = null; |
| + try |
| + { |
| + dte = TestUtilities.StartVisualStudioInstance(); |
| + dte.Solution.Open(testContext.DeploymentDirectory + ProjectSettingsTestSolution); |
| + Project proj = dte.Solution.Projects.Item(ProjectSettingsTestProject); |
| + |
| + proj.ConfigurationManager.AddPlatform( |
| + NativeClientVSAddIn.Strings.PepperPlatformName, |
| + NativeClientVSAddIn.Strings.PepperPlatformName, |
| + true); |
| + |
| + proj.ConfigurationManager.AddPlatform( |
| + NativeClientVSAddIn.Strings.NaClPlatformName, |
| + NativeClientVSAddIn.Strings.NaClPlatformName, |
| + true); |
| + |
| + proj.Save(); |
| + dte.Solution.SaveAs(testContext.DeploymentDirectory + ProjectSettingsTestSolution); |
| + } |
| + finally |
| + { |
| + TestUtilities.CleanUpVisualStudioInstance(dte); |
| + } |
| + } |
| + |
| + /// <summary> |
| + /// This is run before each test to create test resources. |
| + /// </summary> |
| + [TestInitialize] |
| + public void TestSetup() |
| + { |
| + dte_ = TestUtilities.StartVisualStudioInstance(); |
| + } |
| + |
| + /// <summary> |
| + /// This is run after each test to clean up things created in TestSetup(). |
| + /// </summary> |
| + [TestCleanup] |
| + public void TestCleanup() |
| + { |
| + TestUtilities.CleanUpVisualStudioInstance(dte_); |
| + } |
| + |
| + /// <summary> |
| + /// Test method to check that the PPAPI platform template correctly sets default values. |
| + /// </summary> |
| + [TestMethod] |
| + public void VerifyDefaultPepperSettings() |
| + { |
| + string page; |
| + |
| + // Extract the debug and release configurations for Pepper from the project. |
| + dte_.Solution.Open(TestContext.DeploymentDirectory + ProjectSettingsTestSolution); |
| + 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
|
| + string pepperPlatform = NativeClientVSAddIn.Strings.PepperPlatformName; |
| + 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
|
| + release_ = TestUtilities.GetVCConfiguration(project, "Release", pepperPlatform); |
| + |
| + // General |
| + page = "ConfigurationGeneral"; |
| + AllConfigsAssertPropertyEquals(page, "OutDir", @"$(SolutionDir)$(Configuration)\$(Platform)\", true); |
|
binji
2012/07/20 22:54:49
wrap at 100 char, here and elsewhere
tysand
2012/07/24 21:24:15
Done.
|
| + AllConfigsAssertPropertyEquals(page, "IntDir", @"$(Configuration)\$(Platform)\", true); |
| + AllConfigsAssertPropertyEquals(page, "TargetExt", ".dll", true); |
| + AllConfigsAssertPropertyEquals(page, "ConfigurationType", "DynamicLibrary", true); |
| + |
| + // Debugging |
| + page = "WindowsLocalDebugger"; |
| + AllConfigsAssertPropertyEquals(page, "LocalDebuggerCommand", @"$(CHROME_PATH)\chrome.exe", true); |
| + AllConfigsAssertPropertyEquals(page, "LocalDebuggerCommandArguments", "--register-pepper-plugins=\"$(OutDir)$(TargetName)$(TargetExt);application/x-nacl\" --single-process --incognito --no-sandbox http://localhost:5103", true); |
| + |
| + // VC++ Directories |
| + page = "ConfigurationDirectories"; |
| + AllConfigsAssertPropertyContains(page, "IncludePath", @"$(NACL_SDK_ROOT)\src;", true); |
| + |
| + // C/C++ Code Generation |
| + page = "CL"; |
| + //// TODO(tysand): TestUtilities.AssertPropertyEquals(debug_, page, "RuntimeLibrary", "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
|
| + //// TODO(tysand): TestUtilities.AssertPropertyEquals(debug_, page, "RuntimeLibrary", "MultiThreaded", false); |
|
noelallen1
2012/07/20 21:46:01
release_?
tysand
2012/07/24 21:24:15
Done.
|
| + |
| + // Linker Input |
| + page = "Link"; |
| + //// TODO(tysand): AllConfigsAssertPropertyContains(page, "AdditionalDependencies", "ppapi_cpp.lib", false); |
| + } |
| + |
| + /// <summary> |
| + /// Test method to check that the NaCl platform template correctly sets default values. |
| + /// </summary> |
| + [TestMethod] |
| + public void VerifyDefaultNaClSettings() |
| + { |
| + string page; |
| + |
| + // Extract the debug and release configurations for NaCl from the project. |
| + dte_.Solution.Open(TestContext.DeploymentDirectory + ProjectSettingsTestSolution); |
| + Project project = dte_.Solution.Projects.Item(ProjectSettingsTestProject); |
| + string naclPlatform = NativeClientVSAddIn.Strings.NaClPlatformName; |
| + debug_ = TestUtilities.GetVCConfiguration(project, "Debug", naclPlatform); |
| + release_ = TestUtilities.GetVCConfiguration(project, "Release", naclPlatform); |
| + |
| + // General |
| + page = "ConfigurationGeneral"; |
| + AllConfigsAssertPropertyEquals(page, "OutDir", @"$(SolutionDir)$(Configuration)\$(Platform)\", true); |
| + AllConfigsAssertPropertyEquals(page, "IntDir", @"$(Configuration)\$(Platform)\", true); |
| + AllConfigsAssertPropertyEquals(page, "TargetExt", ".nexe", true); |
| + AllConfigsAssertPropertyEquals(page, "PlatformToolset", "win_x86_newlib", true); |
| + AllConfigsAssertPropertyEquals(page, "ConfigurationType", "Application", true); |
| + AllConfigsAssertPropertyEquals(page, "TargetArchitecture", "i686", true); |
| + |
| + // Debugging |
| + page = "WindowsLocalDebugger"; |
| + AllConfigsAssertPropertyEquals(page, "LocalDebuggerCommand", @"$(CHROME_PATH)\chrome.exe", true); |
| + AllConfigsAssertPropertyEquals(page, "LocalDebuggerCommandArguments", @"--enable-nacl http://localhost:5103", true); |
| + |
| + // VC++ Directories |
| + page = "ConfigurationDirectories"; |
| + AllConfigsAssertPropertyContains(page, "IncludePath", @"$(ToolchainPath)\x86_64-nacl\include; $(ToolchainPath)\x86_64-nacl\include\c++\4.4.3", true); |
| + AllConfigsAssertPropertyContains(page, "LibraryPath", @"$(ToolchainPath)\x86_64-nacl\lib32;", true); |
| + |
| + // C/C++ General |
| + page = "CL"; |
| + TestUtilities.AssertPropertyEquals( |
| + debug_, |
| + page, |
| + "GenerateDebuggingInformation", |
| + "true", |
| + false); |
| + TestUtilities.AssertPropertyEquals( |
| + release_, |
| + page, |
| + "GenerateDebuggingInformation", |
| + "false", |
| + false); |
| + |
| + AllConfigsAssertPropertyEquals(page, "Warnings", "NormalWarnings", true); |
| + AllConfigsAssertPropertyEquals(page, "WarningsAsErrors", "false", true); |
| + AllConfigsAssertPropertyEquals(page, "OutputCommandLine", "false", true); |
| + AllConfigsAssertPropertyEquals(page, "ConfigurationType", "$(ConfigurationType)", true); |
| + AllConfigsAssertPropertyEquals(page, "UserHeaderDependenciesOnly", "true", true); |
| + |
| + // C/C++ Optimization |
| + TestUtilities.AssertPropertyEquals(debug_, page, "OptimizationLevel", "O0", false); |
| + TestUtilities.AssertPropertyEquals(release_, page, "OptimizationLevel", "O3", false); |
| + |
| + // C/C++ Preprocessor |
| + AllConfigsAssertPropertyContains(page, "PreprocessorDefinitions", "NaCl", false); |
| + |
| + // C/C++ Code Generation |
| + //// TODO(tysand): AllConfigsAssertPropertyEquals(page, "PositionIndependentCode", "false", false); |
| + //// TODO(tysand): AllConfigsAssertPropertyEquals(page, "ExceptionHandling", "true", false); |
| + |
| + // C/C++ Output Files |
| + AllConfigsAssertPropertyEquals(page, "ObjectFileName", @"$(IntDir)%(FileName).o", false); |
| + |
| + // C/C++ Advanced |
| + AllConfigsAssertPropertyEquals(page, "CompileAs", "Default", true); |
| + |
| + // Linker Input |
| + page = "Link"; |
| + //// TODO(tysand): AllConfigsAssertPropertyContains(page, "AdditionalDependencies", "ppapi_cpp", false); |
| + } |
| + |
| + /// <summary> |
| + /// Tests that a given property has a specific value for both Debug and Release |
| + /// configurations under the current test's platform. |
| + /// </summary> |
| + /// <param name="pageName">Property page name where property resides.</param> |
| + /// <param name="propertyName">Name of the property to check.</param> |
| + /// <param name="expectedValue">Expected value of the property.</param> |
| + /// <param name="ignoreCase">Ignore case when comparing the expected and actual values.</param> |
| + private void AllConfigsAssertPropertyEquals( |
| + string pageName, |
| + string propertyName, |
| + string expectedValue, |
| + bool ignoreCase) |
| + { |
| + TestUtilities.AssertPropertyEquals( |
| + debug_, |
| + pageName, |
| + propertyName, |
| + expectedValue, |
| + ignoreCase); |
| + TestUtilities.AssertPropertyEquals( |
| + release_, |
| + pageName, |
| + propertyName, |
| + expectedValue, |
| + ignoreCase); |
| + } |
| + |
| + /// <summary> |
| + /// Tests that a given property contains a specific string for both Debug and Release |
| + /// configurations under the NaCl platform. |
| + /// </summary> |
| + /// <param name="pageName">Property page name where property resides.</param> |
| + /// <param name="propertyName">Name of the property to check.</param> |
| + /// <param name="expectedValue">Expected value of the property.</param> |
| + /// <param name="ignoreCase">Ignore case when comparing the expected and actual values.</param> |
| + private void AllConfigsAssertPropertyContains( |
| + string pageName, |
| + string propertyName, |
| + string expectedValue, |
| + bool ignoreCase) |
| + { |
| + TestUtilities.AssertPropertyContains( |
| + debug_, |
| + pageName, |
| + propertyName, |
| + expectedValue, |
| + ignoreCase); |
| + TestUtilities.AssertPropertyContains( |
| + release_, |
| + pageName, |
| + propertyName, |
| + expectedValue, |
| + ignoreCase); |
| + } |
| + } |
| +} |