| OLD | NEW |
| 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 using System; | 4 using System; |
| 5 using System.Text; | 5 using System.Text; |
| 6 using System.Collections.Generic; | 6 using System.Collections.Generic; |
| 7 using EnvDTE; | 7 using EnvDTE; |
| 8 using EnvDTE80; | 8 using EnvDTE80; |
| 9 using Microsoft.VisualStudio.TestTools.UnitTesting; | 9 using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 10 using Microsoft.VisualStudio.VCProjectEngine; | 10 using Microsoft.VisualStudio.VCProjectEngine; |
| 11 using NaCl.Build.CPPTasks; | 11 using NaCl.Build.CPPTasks; |
| 12 using NativeClientVSAddIn; | 12 using NativeClientVSAddIn; |
| 13 | 13 |
| 14 namespace UnitTests | 14 namespace UnitTests |
| 15 { | 15 { |
| 16 [TestClass] | 16 [TestClass] |
| 17 public class CompileTest | 17 public class ComileTest : BaseCompileTest |
| 18 { | 18 { |
| 19 /// <summary> | 19 private static string SolutionBaseName_ = "CompileTest"; |
| 20 /// The main visual studio object. | |
| 21 /// </summary> | |
| 22 private DTE2 dte_; | |
| 23 | 20 |
| 24 /// <summary> | |
| 25 /// The path to a NaCl solution used in compile tests. | |
| 26 /// </summary> | |
| 27 private static string SolutionName_; | |
| 28 | |
| 29 /// <summary> | |
| 30 /// This is run one time before any test methods are called. Here we set
-up test-copies of | |
| 31 /// new NaCl solutions for use in the tests. | |
| 32 /// </summary> | |
| 33 /// <param name="testContext">Holds information about the current test r
un</param> | |
| 34 [ClassInitialize] | 21 [ClassInitialize] |
| 35 public static void ClassSetUp(TestContext testContext) | 22 public new static void ClassSetUp(TestContext testContext) |
| 36 { | 23 { |
| 37 DTE2 dte = TestUtilities.StartVisualStudioInstance(); | 24 BaseCompileTest.ClassSetUp(testContext, SolutionBaseName_); |
| 38 try | |
| 39 { | |
| 40 SolutionName_ = TestUtilities.CreateBlankValidNaClSolution( | |
| 41 dte, | |
| 42 "CompileTest", | |
| 43 Strings.PepperPlatformName, | |
| 44 Strings.NaCl64PlatformName, | |
| 45 testContext); | |
| 46 } | |
| 47 finally | |
| 48 { | |
| 49 TestUtilities.CleanUpVisualStudioInstance(dte); | |
| 50 } | |
| 51 } | 25 } |
| 52 | 26 |
| 53 /// <summary> | 27 /// <summary> |
| 54 /// This is run after each test to clean up things created in TestSetup(
). | 28 /// This is run after each test to clean up things created in TestSetup(
). |
| 55 /// </summary> | 29 /// </summary> |
| 56 [TestCleanup] | 30 [TestCleanup] |
| 57 public void ClassTearDown() | 31 public void ClassTearDown() |
| 58 { | 32 { |
| 59 TestUtilities.CleanUpVisualStudioInstance(dte_); | 33 TestUtilities.CleanUpVisualStudioInstance(dte_); |
| 60 } | 34 } |
| 61 | 35 |
| 62 /// <summary> | 36 /// <summary> |
| 63 /// This is run before each test to create test resources. | |
| 64 /// </summary> | |
| 65 [TestInitialize] | |
| 66 public void TestSetup() | |
| 67 { | |
| 68 dte_ = TestUtilities.StartVisualStudioInstance(); | |
| 69 try | |
| 70 { | |
| 71 TestUtilities.AssertAddinLoaded(dte_, Strings.AddInName); | |
| 72 } | |
| 73 catch | |
| 74 { | |
| 75 TestUtilities.CleanUpVisualStudioInstance(dte_); | |
| 76 throw; | |
| 77 } | |
| 78 } | |
| 79 | |
| 80 /// <summary> | |
| 81 /// Helper function which opens the given solution, sets the configurati
on and platform and | |
| 82 /// tries to compile, failing the test if the build does not succeed. | |
| 83 /// </summary> | |
| 84 /// <param name="solutionPath">Path to the solution to open.</param> | |
| 85 /// <param name="configName">Solution Configuration name (Debug or Relea
se).</param> | |
| 86 /// <param name="platformName">Platform name.</param> | |
| 87 private void TryCompile(string configName, string platformName) | |
| 88 { | |
| 89 string failFormat = "Project compile failed for {0} platform {1} con
fig." | |
| 90 + "Build output: {2}"; | |
| 91 string cygwinWarningFormat = "Did not pass cygwin nodosfilewarning e
nvironment var to" | |
| 92 + " tools Platform: {0}, configuration: {
1}"; | |
| 93 StringComparison ignoreCase = StringComparison.InvariantCultureIgnor
eCase; | |
| 94 | |
| 95 // Open Debug configuration and build. | |
| 96 dte_.Solution.Open(SolutionName_); | |
| 97 TestUtilities.SetSolutionConfiguration( | |
| 98 dte_, TestUtilities.NaClProjectUniqueName, configName, platformN
ame); | |
| 99 dte_.Solution.SolutionBuild.Build(true); | |
| 100 | |
| 101 string compileOutput = TestUtilities.GetPaneText( | |
| 102 dte_.ToolWindows.OutputWindow.OutputWindowPanes.Item("Build")); | |
| 103 Assert.IsTrue( | |
| 104 compileOutput.Contains("Build succeeded.", ignoreCase), | |
| 105 string.Format(failFormat, platformName, configName, compileOutpu
t)); | |
| 106 Assert.IsFalse( | |
| 107 compileOutput.Contains("MS-DOS style path detected", ignoreCase)
, | |
| 108 string.Format(cygwinWarningFormat, platformName, configName)); | |
| 109 | |
| 110 dte_.Solution.Close(true); | |
| 111 } | |
| 112 | |
| 113 /// <summary> | |
| 114 /// Set the type of the project: Executable, DynamicLibrary, StaticLibra
ry | |
| 115 /// </summary> | |
| 116 private void SetProjectType(string projectType, string platformName) | |
| 117 { | |
| 118 dte_.Solution.Open(SolutionName_); | |
| 119 Project project = dte_.Solution.Projects.Item(TestUtilities.NaClProj
ectUniqueName); | |
| 120 VCConfiguration config; | |
| 121 IVCRulePropertyStorage rule; | |
| 122 | |
| 123 config = TestUtilities.GetVCConfiguration(project, "Debug", platform
Name); | |
| 124 rule = config.Rules.Item("ConfigurationGeneral"); | |
| 125 rule.SetPropertyValue("ConfigurationType", projectType); | |
| 126 | |
| 127 config = TestUtilities.GetVCConfiguration(project, "Release", platfo
rmName); | |
| 128 rule = config.Rules.Item("ConfigurationGeneral"); | |
| 129 rule.SetPropertyValue("ConfigurationType", projectType); | |
| 130 dte_.Solution.Close(true); | |
| 131 } | |
| 132 | |
| 133 /// <summary> | |
| 134 /// Test method to check that the NaCl platform compiles a test project. | 37 /// Test method to check that the NaCl platform compiles a test project. |
| 135 /// </summary> | 38 /// </summary> |
| 136 [TestMethod] | 39 [TestMethod] |
| 137 public void CheckNaCl64Compile() | 40 public void CheckNaCl64Compile() |
| 138 { | 41 { |
| 139 CheckCompile(Strings.NaCl64PlatformName, false); | 42 CheckCompile(Strings.NaCl64PlatformName, false); |
| 140 } | 43 } |
| 141 | 44 |
| 142 /// <summary> | 45 /// <summary> |
| 143 /// Test method to check that the NaCl platform compiles a test project. | 46 /// Test method to check that the NaCl platform compiles a test project. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 169 public void CheckPNaClCompile() | 72 public void CheckPNaClCompile() |
| 170 { | 73 { |
| 171 string root = System.Environment.GetEnvironmentVariable("NACL_SDK_RO
OT"); | 74 string root = System.Environment.GetEnvironmentVariable("NACL_SDK_RO
OT"); |
| 172 if (!SDKUtilities.SupportsPNaCl(root)) | 75 if (!SDKUtilities.SupportsPNaCl(root)) |
| 173 { | 76 { |
| 174 Assert.Inconclusive(); | 77 Assert.Inconclusive(); |
| 175 } | 78 } |
| 176 CheckCompile(Strings.PNaClPlatformName, false); | 79 CheckCompile(Strings.PNaClPlatformName, false); |
| 177 } | 80 } |
| 178 | 81 |
| 179 private void CheckCompile(string platform, bool dll) | |
| 180 { | |
| 181 SetProjectType("Executable", platform); | |
| 182 TryCompile("Debug", platform); | |
| 183 TryCompile("Release", platform); | |
| 184 SetProjectType("StaticLibrary", platform); | |
| 185 TryCompile("Debug", platform); | |
| 186 TryCompile("Release", platform); | |
| 187 if (dll) | |
| 188 { | |
| 189 SetProjectType("DynamicLibrary", platform); | |
| 190 TryCompile("Debug", platform); | |
| 191 TryCompile("Release", platform); | |
| 192 } | |
| 193 } | |
| 194 } | 82 } |
| 195 } | 83 } |
| OLD | NEW |