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