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 using System.IO; |
| 9 |
| 10 using EnvDTE; |
| 11 using EnvDTE80; |
| 12 using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 13 |
| 14 using NativeClientVSAddIn; |
| 15 |
| 16 /// <summary> |
| 17 /// This is a test class for PropertyManagerTest and is intended |
| 18 /// to contain all PropertyManager Unit Tests |
| 19 /// </summary> |
| 20 [TestClass] |
| 21 public class PropertyManagerTest |
| 22 { |
| 23 /// <summary> |
| 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. |
| 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 |
| 28 /// in any tests. |
| 29 /// </summary> |
| 30 private static string naclSolution; |
| 31 |
| 32 /// <summary> |
| 33 /// The main visual studio object. |
| 34 /// </summary> |
| 35 private DTE2 dte_; |
| 36 |
| 37 /// <summary> |
| 38 /// Gets or sets the test context which provides information about, |
| 39 /// and functionality for the current test run. |
| 40 /// </summary> |
| 41 public TestContext TestContext { get; set; } |
| 42 |
| 43 /// <summary> |
| 44 /// This is run one time before any test methods are called. Here we set-up
a test-copy of a |
| 45 /// new NaCl solution for use in the tests. |
| 46 /// </summary> |
| 47 /// <param name="testContext">Holds information about the current test run</
param> |
| 48 [ClassInitialize] |
| 49 public static void ClassSetup(TestContext testContext) |
| 50 { |
| 51 DTE2 dte = TestUtilities.StartVisualStudioInstance(); |
| 52 try |
| 53 { |
| 54 naclSolution = TestUtilities.CreateBlankValidNaClSolution( |
| 55 dte, |
| 56 "PropertyManagerTest", |
| 57 NativeClientVSAddIn.Strings.PepperPlatformName, |
| 58 NativeClientVSAddIn.Strings.NaClPlatformName, |
| 59 testContext); |
| 60 } |
| 61 finally |
| 62 { |
| 63 TestUtilities.CleanUpVisualStudioInstance(dte); |
| 64 } |
| 65 } |
| 66 |
| 67 /// <summary> |
| 68 /// This is run before each test to create test resources. |
| 69 /// </summary> |
| 70 [TestInitialize] |
| 71 public void TestSetup() |
| 72 { |
| 73 dte_ = TestUtilities.StartVisualStudioInstance(); |
| 74 try |
| 75 { |
| 76 TestUtilities.AssertAddinLoaded(dte_, NativeClientVSAddIn.Strings.AddInN
ame); |
| 77 } |
| 78 catch |
| 79 { |
| 80 TestUtilities.CleanUpVisualStudioInstance(dte_); |
| 81 throw; |
| 82 } |
| 83 } |
| 84 |
| 85 /// <summary> |
| 86 /// This is run after each test to clean up things created in TestSetup(). |
| 87 /// </summary> |
| 88 [TestCleanup] |
| 89 public void TestCleanup() |
| 90 { |
| 91 TestUtilities.CleanUpVisualStudioInstance(dte_); |
| 92 } |
| 93 |
| 94 /// <summary> |
| 95 /// Tests SetTarget() and SetTargetToActive(). |
| 96 /// </summary> |
| 97 [TestMethod] |
| 98 public void SetTargetTest() |
| 99 { |
| 100 string expectedSDKRootDir = |
| 101 Environment.GetEnvironmentVariable(Strings.SDKPathEnvironmentVariable)
; |
| 102 Assert.IsNotNull(expectedSDKRootDir, "SDK Path environment variable not se
t!"); |
| 103 |
| 104 PropertyManager target = new PropertyManager(); |
| 105 dte_.Solution.Open(naclSolution); |
| 106 |
| 107 Project naclProject = dte_.Solution.Projects.Item(TestUtilities.BlankNaClP
rojectUniqueName); |
| 108 Project notNacl = dte_.Solution.Projects.Item(TestUtilities.NotNaClProject
UniqueName); |
| 109 |
| 110 // Invalid project. |
| 111 target.SetTarget(notNacl, Strings.PepperPlatformName, "Debug"); |
| 112 Assert.AreEqual( |
| 113 PropertyManager.ProjectPlatformType.Other, |
| 114 target.ProjectPlatform, |
| 115 "SetTarget should not succeed with non-nacl/pepper project."); |
| 116 |
| 117 // Try valid project with different platforms. |
| 118 target.SetTarget(naclProject, Strings.NaClPlatformName, "Debug"); |
| 119 Assert.AreEqual( |
| 120 PropertyManager.ProjectPlatformType.NaCl, |
| 121 target.ProjectPlatform, |
| 122 "SetTarget did not succeed with nacl platform on valid project."); |
| 123 Assert.AreEqual(expectedSDKRootDir, target.SDKRootDirectory, "SDK Root inc
orrect."); |
| 124 |
| 125 target.SetTarget(naclProject, "Win32", "Debug"); |
| 126 Assert.AreEqual( |
| 127 PropertyManager.ProjectPlatformType.Other, |
| 128 target.ProjectPlatform, |
| 129 "SetTarget did not set 'other' platform on when Win32 platform of vali
d project."); |
| 130 |
| 131 target.SetTarget(naclProject, Strings.PepperPlatformName, "Debug"); |
| 132 Assert.AreEqual( |
| 133 PropertyManager.ProjectPlatformType.Pepper, |
| 134 target.ProjectPlatform, |
| 135 "SetTarget did not succeed with pepper platform on valid project."); |
| 136 Assert.AreEqual(expectedSDKRootDir, target.SDKRootDirectory, "SDK Root inc
orrect."); |
| 137 |
| 138 // Setting the start-up project to a non-cpp project should make loading f
ail. |
| 139 object[] badStartupProj = { TestUtilities.NotNaClProjectUniqueName }; |
| 140 dte_.Solution.SolutionBuild.StartupProjects = badStartupProj; |
| 141 target.SetTargetToActive(dte_); |
| 142 Assert.AreEqual( |
| 143 PropertyManager.ProjectPlatformType.Other, |
| 144 target.ProjectPlatform, |
| 145 "SetTargetToActive should not succeed with non-nacl/pepper project."); |
| 146 |
| 147 // Setting the start-up project to correct C++ project, but also setting t
he platform |
| 148 // to non-nacl/pepper should make loading fail. |
| 149 object[] startupProj = { TestUtilities.BlankNaClProjectUniqueName }; |
| 150 dte_.Solution.SolutionBuild.StartupProjects = startupProj; |
| 151 TestUtilities.SetSolutionConfiguration( |
| 152 dte_, TestUtilities.BlankNaClProjectUniqueName, "Debug", "Win32"); |
| 153 target.SetTargetToActive(dte_); |
| 154 Assert.AreEqual( |
| 155 PropertyManager.ProjectPlatformType.Other, |
| 156 target.ProjectPlatform, |
| 157 "SetTargetToActive should not succeed with Win32 platform."); |
| 158 |
| 159 // Now setting the platform to NaCl should make this succeed. |
| 160 TestUtilities.SetSolutionConfiguration( |
| 161 dte_, TestUtilities.BlankNaClProjectUniqueName, "Debug", Strings.NaClP
latformName); |
| 162 target.SetTargetToActive(dte_); |
| 163 Assert.AreEqual( |
| 164 PropertyManager.ProjectPlatformType.NaCl, |
| 165 target.ProjectPlatform, |
| 166 "SetTargetToActive should succeed with NaCl platform and valid project
."); |
| 167 Assert.AreEqual(expectedSDKRootDir, target.SDKRootDirectory, "SDK Root inc
orrect."); |
| 168 } |
| 169 |
| 170 /// <summary> |
| 171 /// A test for GetProperty. Checks some non-trivial C# properties and the Ge
tProperty method. |
| 172 /// </summary> |
| 173 [TestMethod] |
| 174 public void GetPropertyTest() |
| 175 { |
| 176 string expectedSDKRootDir = |
| 177 Environment.GetEnvironmentVariable(Strings.SDKPathEnvironmentVariable)
; |
| 178 Assert.IsNotNull(expectedSDKRootDir, "SDK Path environment variable not se
t!"); |
| 179 |
| 180 // Set up the property manager to read the NaCl platform settings from Bla
nkValidSolution. |
| 181 PropertyManager target = new PropertyManager(); |
| 182 dte_.Solution.Open(naclSolution); |
| 183 Project naclProject = dte_.Solution.Projects.Item(TestUtilities.BlankNaClP
rojectUniqueName); |
| 184 target.SetTarget(naclProject, Strings.NaClPlatformName, "Debug"); |
| 185 Assert.AreEqual( |
| 186 PropertyManager.ProjectPlatformType.NaCl, |
| 187 target.ProjectPlatform, |
| 188 "SetTarget did not succeed with nacl platform on valid project."); |
| 189 |
| 190 string projectDir = Path.Combine( |
| 191 Path.GetDirectoryName(naclSolution), |
| 192 Path.GetDirectoryName(TestUtilities.BlankNaClProjectUniqueName)) + @"\
"; |
| 193 string outputDir = Path.Combine(projectDir, "newlib") + @"\"; |
| 194 string assembly = Path.Combine(outputDir, TestUtilities.BlankNaClProjectNa
me + ".nexe"); |
| 195 |
| 196 Assert.AreEqual(expectedSDKRootDir, target.SDKRootDirectory, "SDK Root."); |
| 197 Assert.AreEqual(projectDir, target.ProjectDirectory, "ProjectDirectory."); |
| 198 Assert.AreEqual(outputDir, target.OutputDirectory, "OutputDirectory."); |
| 199 Assert.AreEqual(assembly, target.PluginAssembly, "PluginAssembly."); |
| 200 Assert.AreEqual( |
| 201 @"win_x86_newlib", |
| 202 target.GetProperty("ConfigurationGeneral", "PlatformToolset"), |
| 203 "GetProperty() with PlatformToolset incorrect."); |
| 204 } |
| 205 |
| 206 /// <summary> |
| 207 /// A test for SetProperty. |
| 208 /// </summary> |
| 209 [TestMethod] |
| 210 public void SetPropertyTest() |
| 211 { |
| 212 string setTargetSolution = TestUtilities.CreateBlankValidNaClSolution( |
| 213 dte_, |
| 214 "PropertyManagerTestSetTarget", |
| 215 NativeClientVSAddIn.Strings.NaClPlatformName, |
| 216 NativeClientVSAddIn.Strings.NaClPlatformName, |
| 217 TestContext); |
| 218 |
| 219 // Set up the property manager to read the NaCl platform settings from Bla
nkValidSolution. |
| 220 PropertyManager target = new PropertyManager(); |
| 221 dte_.Solution.Open(setTargetSolution); |
| 222 Project naclProject = dte_.Solution.Projects.Item(TestUtilities.BlankNaClP
rojectUniqueName); |
| 223 target.SetTarget(naclProject, Strings.NaClPlatformName, "Debug"); |
| 224 Assert.AreEqual( |
| 225 PropertyManager.ProjectPlatformType.NaCl, |
| 226 target.ProjectPlatform, |
| 227 "SetTarget did not succeed with nacl platform on valid project."); |
| 228 |
| 229 string newValue = "ThisIsNew"; |
| 230 target.SetProperty("ConfigurationGeneral", "VSNaClSDKRoot", newValue); |
| 231 Assert.AreEqual( |
| 232 newValue, |
| 233 target.GetProperty("ConfigurationGeneral", "VSNaClSDKRoot"), |
| 234 "SetProperty() did not set property VSNaClSDKRoot."); |
| 235 } |
| 236 } |
| 237 } |
OLD | NEW |