| 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 | 4 |
| 5 namespace UnitTests | 5 namespace UnitTests |
| 6 { | 6 { |
| 7 using System; | 7 using System; |
| 8 using System.Diagnostics; | 8 using System.Diagnostics; |
| 9 using System.IO; | 9 using System.IO; |
| 10 using System.Reflection; | 10 using System.Reflection; |
| 11 using System.Threading; | 11 using System.Threading; |
| 12 | 12 |
| 13 using EnvDTE; |
| 13 using EnvDTE80; | 14 using EnvDTE80; |
| 14 using Microsoft.VisualStudio.TestTools.UnitTesting; | 15 using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 15 | 16 |
| 16 using NativeClientVSAddIn; | 17 using NativeClientVSAddIn; |
| 17 | 18 |
| 18 /// <summary> | 19 /// <summary> |
| 19 /// This is a test class for PluginDebuggerHelperTest and is intended | 20 /// This is a test class for PluginDebuggerHelperTest and is intended |
| 20 /// to contain all PluginDebuggerHelperTest Unit Tests. | 21 /// to contain all PluginDebuggerHelperTest Unit Tests. |
| 21 /// </summary> | 22 /// </summary> |
| 22 [TestClass] | 23 [TestClass] |
| 23 public class PluginDebuggerHelperTest | 24 public class PluginDebuggerHelperTest |
| 24 { | 25 { |
| 25 /// <summary> | 26 /// <summary> |
| 26 /// The dummy loop solution is a valid nacl/pepper plug-in VS solution. | 27 /// This holds the path to the NaCl solution used in these tests. |
| 28 /// The NaCl solution is a valid nacl/pepper plug-in VS solution. |
| 27 /// It is copied into the testing deployment directory and opened in some te
sts. | 29 /// It is copied into the testing deployment directory and opened in some te
sts. |
| 28 /// Because unit-tests run in any order, the solution should not be written
to | 30 /// Because unit-tests run in any order, the solution should not be written
to |
| 29 /// in any tests. | 31 /// in any tests. |
| 30 /// </summary> | 32 /// </summary> |
| 31 private const string DummyLoopSolution = @"\DummyLoop\DummyLoop.sln"; | 33 private static string naclSolution; |
| 32 | 34 |
| 33 /// <summary> | 35 /// <summary> |
| 34 /// The main visual studio object. | 36 /// The main visual studio object. |
| 35 /// </summary> | 37 /// </summary> |
| 36 private DTE2 dte_ = null; | 38 private DTE2 dte_ = null; |
| 37 | 39 |
| 38 /// <summary> | 40 /// <summary> |
| 39 /// Gets or sets the test context which provides information about, | 41 /// Gets or sets the test context which provides information about, |
| 40 /// and functionality for the current test run. | 42 /// and functionality for the current test run. |
| 41 /// </summary> | 43 /// </summary> |
| 42 public TestContext TestContext { get; set; } | 44 public TestContext TestContext { get; set; } |
| 43 | 45 |
| 44 /// <summary> | 46 /// <summary> |
| 47 /// This is run one time before any test methods are called. Here we set-up
a test-copy of a |
| 48 /// new NaCl solution for use in the tests. |
| 49 /// </summary> |
| 50 /// <param name="testContext">Holds information about the current test run</
param> |
| 51 [ClassInitialize] |
| 52 public static void ClassSetup(TestContext testContext) |
| 53 { |
| 54 naclSolution = TestUtilities.CreateBlankValidNaClSolution( |
| 55 "PluginDebuggerHelperTest", |
| 56 testContext); |
| 57 } |
| 58 |
| 59 /// <summary> |
| 45 /// This is run before each test to create test resources. | 60 /// This is run before each test to create test resources. |
| 46 /// </summary> | 61 /// </summary> |
| 47 [TestInitialize] | 62 [TestInitialize] |
| 48 public void TestSetup() | 63 public void TestSetup() |
| 49 { | 64 { |
| 50 dte_ = TestUtilities.StartVisualStudioInstance(); | 65 dte_ = TestUtilities.StartVisualStudioInstance(); |
| 51 } | 66 } |
| 52 | 67 |
| 53 /// <summary> | 68 /// <summary> |
| 54 /// This is run after each test to clean up things created in TestSetup(). | 69 /// This is run after each test to clean up things created in TestSetup(). |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 target.pluginAssembly_ = "fakeAssemblyString"; | 119 target.pluginAssembly_ = "fakeAssemblyString"; |
| 105 target.irtPath_ = "fakeIrtPath"; | 120 target.irtPath_ = "fakeIrtPath"; |
| 106 target.gdbPath_ = "python.exe"; | 121 target.gdbPath_ = "python.exe"; |
| 107 target.gdbProcess_ = TestUtilities.StartProcessForKilling(existingGDB, 2
0); | 122 target.gdbProcess_ = TestUtilities.StartProcessForKilling(existingGDB, 2
0); |
| 108 string existingInitFileName = Path.GetTempFileName(); | 123 string existingInitFileName = Path.GetTempFileName(); |
| 109 target.gdbInitFileName_ = existingInitFileName; | 124 target.gdbInitFileName_ = existingInitFileName; |
| 110 target.isProperlyInitialized_ = true; | 125 target.isProperlyInitialized_ = true; |
| 111 | 126 |
| 112 // Visual studio won't allow adding a breakpoint unless it is associated
with | 127 // Visual studio won't allow adding a breakpoint unless it is associated
with |
| 113 // an existing file and valid line number, so use DummyLoopSolution. | 128 // an existing file and valid line number, so use DummyLoopSolution. |
| 114 dte_.Solution.Open(TestContext.DeploymentDirectory + DummyLoopSolution); | 129 dte_.Solution.Open(naclSolution); |
| 115 string fileName = "main.cpp"; | 130 string fileName = "main.cpp"; |
| 116 string functionName = "DummyInstance::HandleMessage"; | 131 string functionName = "DummyInstance::HandleMessage"; |
| 117 int lineNumber = 35; | 132 int lineNumber = 35; |
| 118 dte_.Debugger.Breakpoints.Add(Function: functionName); | 133 dte_.Debugger.Breakpoints.Add(Function: functionName); |
| 119 dte_.Debugger.Breakpoints.Add(Line: lineNumber, File: fileName); | 134 dte_.Debugger.Breakpoints.Add(Line: lineNumber, File: fileName); |
| 120 | 135 |
| 121 target.AttachNaClGDB(null, new PluginDebuggerHelper.PluginFoundEventArgs
(0)); | 136 target.AttachNaClGDB(null, new PluginDebuggerHelper.PluginFoundEventArgs
(0)); |
| 122 | 137 |
| 123 Assert.IsTrue(File.Exists(target.gdbInitFileName_), "Init file not writt
en"); | 138 Assert.IsTrue(File.Exists(target.gdbInitFileName_), "Init file not writt
en"); |
| 124 | 139 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 try | 317 try |
| 303 { | 318 { |
| 304 target.LoadProjectSettings(); | 319 target.LoadProjectSettings(); |
| 305 Assert.Fail("Initializing with no loaded solution shouldn't succeed"); | 320 Assert.Fail("Initializing with no loaded solution shouldn't succeed"); |
| 306 } | 321 } |
| 307 catch (ArgumentOutOfRangeException) | 322 catch (ArgumentOutOfRangeException) |
| 308 { | 323 { |
| 309 // This is expected for a correct implementation. | 324 // This is expected for a correct implementation. |
| 310 } | 325 } |
| 311 | 326 |
| 312 dte_.Solution.Open(TestContext.DeploymentDirectory + DummyLoopSolution); | 327 dte_.Solution.Open(naclSolution); |
| 313 | 328 |
| 314 // Setting the start-up project to a non-cpp project should make loading f
ail. | 329 // Setting the start-up project to a non-cpp project should make loading f
ail. |
| 315 string badProjectUniqueName = @"NotNaCl\NotNaCl.csproj"; | 330 object[] badStartupProj = { TestUtilities.NotNaClProjectUniqueName }; |
| 316 object[] badStartupProj = { badProjectUniqueName }; | |
| 317 dte_.Solution.SolutionBuild.StartupProjects = badStartupProj; | 331 dte_.Solution.SolutionBuild.StartupProjects = badStartupProj; |
| 318 Assert.IsFalse(target.LoadProjectSettings()); | 332 Assert.IsFalse(target.LoadProjectSettings()); |
| 319 Assert.IsFalse(target.isProperlyInitialized_); | 333 Assert.IsFalse(target.isProperlyInitialized_); |
| 320 | 334 |
| 321 // Setting the start-up project to correct C++ project, but also setting t
he platform | 335 // Setting the start-up project to correct C++ project, but also setting t
he platform |
| 322 // to non-nacl/pepper should make loading fail. | 336 // to non-nacl/pepper should make loading fail. |
| 323 string projectUniqueName = @"DummyLoop\DummyLoop.vcxproj"; | 337 object[] startupProj = { TestUtilities.BlankNaClProjectUniqueName }; |
| 324 object[] startupProj = { projectUniqueName }; | |
| 325 dte_.Solution.SolutionBuild.StartupProjects = startupProj; | 338 dte_.Solution.SolutionBuild.StartupProjects = startupProj; |
| 326 TestUtilities.SetSolutionConfiguration(dte_, projectUniqueName, "Debug", "
Win32"); | 339 TestUtilities.SetSolutionConfiguration( |
| 340 dte_, TestUtilities.BlankNaClProjectUniqueName, "Debug", "Win32"); |
| 327 Assert.IsFalse(target.LoadProjectSettings()); | 341 Assert.IsFalse(target.LoadProjectSettings()); |
| 328 Assert.IsFalse(target.isProperlyInitialized_); | 342 Assert.IsFalse(target.isProperlyInitialized_); |
| 329 | 343 |
| 330 // Setting the platform to NaCl should make loading succeed. | 344 // Setting the platform to NaCl should make loading succeed. |
| 331 TestUtilities.SetSolutionConfiguration( | 345 TestUtilities.SetSolutionConfiguration( |
| 332 dte_, projectUniqueName, "Debug", Strings.NaClPlatformName); | 346 dte_, TestUtilities.BlankNaClProjectUniqueName, "Debug", Strings.NaClP
latformName); |
| 333 Assert.IsTrue(target.LoadProjectSettings()); | 347 Assert.IsTrue(target.LoadProjectSettings()); |
| 334 Assert.IsTrue(target.isProperlyInitialized_); | 348 Assert.IsTrue(target.isProperlyInitialized_); |
| 335 Assert.AreEqual( | 349 Assert.AreEqual( |
| 336 target.projectPlatformType_, | 350 PluginDebuggerHelper_Accessor.ProjectPlatformType.NaCl, |
| 337 PluginDebuggerHelper_Accessor.ProjectPlatformType.NaCl); | 351 target.projectPlatformType_); |
| 338 Assert.AreEqual( | 352 |
| 339 target.pluginProjectDirectory_, | 353 string projectDir = Path.Combine( |
| 340 TestContext.DeploymentDirectory + @"\DummyLoop\DummyLoop\"); | 354 Path.GetDirectoryName(naclSolution), |
| 341 Assert.AreEqual( | 355 Path.GetDirectoryName(TestUtilities.BlankNaClProjectUniqueName)) + @"\
"; |
| 342 target.pluginAssembly_, | 356 string outputDir = Path.Combine(projectDir, "newlib") + @"\"; |
| 343 TestContext.DeploymentDirectory + @"\DummyLoop\DummyLoop\NaCl\Debug\Du
mmyLoop.nexe"); | 357 string assembly = Path.Combine(outputDir, TestUtilities.BlankNaClProjectNa
me + ".nexe"); |
| 344 Assert.AreEqual( | 358 |
| 345 target.pluginOutputDirectory_, | 359 Assert.AreEqual(projectDir, target.pluginProjectDirectory_); |
| 346 TestContext.DeploymentDirectory + @"\DummyLoop\DummyLoop\NaCl\Debug\")
; | 360 Assert.AreEqual(outputDir, target.pluginOutputDirectory_); |
| 347 Assert.AreEqual(target.sdkRootDirectory_, expectedSDKRootDir); | 361 Assert.AreEqual(assembly, target.pluginAssembly_); |
| 348 Assert.AreEqual(target.webServerExecutable_, "python.exe"); | 362 |
| 349 ////Assert.AreEqual(target._webServerArguments, ""); | 363 Assert.AreEqual(expectedSDKRootDir, target.sdkRootDirectory_); |
| 350 ////Assert.AreEqual(target._gdbPath, ""); | 364 Assert.AreEqual("python.exe", target.webServerExecutable_); |
| 351 | 365 |
| 352 // Setting platform to Pepper should make succeed. | 366 // Setting platform to Pepper should make succeed. |
| 353 TestUtilities.SetSolutionConfiguration( | 367 TestUtilities.SetSolutionConfiguration( |
| 354 dte_, projectUniqueName, "Debug", Strings.PepperPlatformName); | 368 dte_, TestUtilities.BlankNaClProjectUniqueName, "Debug", Strings.Peppe
rPlatformName); |
| 355 Assert.IsTrue(target.LoadProjectSettings()); | 369 Assert.IsTrue(target.LoadProjectSettings()); |
| 356 Assert.IsTrue(target.isProperlyInitialized_); | 370 Assert.IsTrue(target.isProperlyInitialized_); |
| 357 Assert.AreEqual( | 371 Assert.AreEqual( |
| 358 target.projectPlatformType_, | 372 PluginDebuggerHelper_Accessor.ProjectPlatformType.Pepper, |
| 359 PluginDebuggerHelper_Accessor.ProjectPlatformType.Pepper); | 373 target.projectPlatformType_); |
| 360 Assert.AreEqual( | 374 |
| 361 target.pluginProjectDirectory_, | 375 outputDir = Path.Combine(projectDir, "win") + @"\"; |
| 362 TestContext.DeploymentDirectory + @"\DummyLoop\DummyLoop\"); | 376 assembly = Path.Combine(outputDir, TestUtilities.BlankNaClProjectName + ".
dll"); |
| 363 Assert.AreEqual( | 377 Assert.AreEqual(projectDir, target.pluginProjectDirectory_); |
| 364 target.pluginAssembly_, | 378 Assert.AreEqual(outputDir, target.pluginOutputDirectory_); |
| 365 TestContext.DeploymentDirectory + @"\DummyLoop\Debug\PPAPI\DummyLoop.d
ll"); | 379 Assert.AreEqual(assembly, target.pluginAssembly_); |
| 366 Assert.AreEqual( | 380 |
| 367 target.pluginOutputDirectory_, | 381 Assert.AreEqual(expectedSDKRootDir, target.sdkRootDirectory_); |
| 368 TestContext.DeploymentDirectory + @"\DummyLoop\Debug\PPAPI\"); | 382 Assert.AreEqual("python.exe", target.webServerExecutable_); |
| 369 Assert.AreEqual(target.sdkRootDirectory_, expectedSDKRootDir); | |
| 370 Assert.AreEqual(target.webServerExecutable_, "python.exe"); | |
| 371 ////Assert.AreEqual(target._webServerArguments, ""); | |
| 372 ////Assert.AreEqual(target._gdbPath, ""); | |
| 373 } | 383 } |
| 374 | 384 |
| 375 /// <summary> | 385 /// <summary> |
| 376 /// Checks that VS properly attaches debugger. | 386 /// Checks that VS properly attaches debugger. |
| 377 /// </summary> | 387 /// </summary> |
| 378 [TestMethod] | 388 [TestMethod] |
| 379 [DeploymentItem("NativeClientVSAddIn.dll")] | 389 [DeploymentItem("NativeClientVSAddIn.dll")] |
| 380 public void AttachVSDebuggerTest() | 390 public void AttachVSDebuggerTest() |
| 381 { | 391 { |
| 382 using (Process dummyProc = TestUtilities.StartProcessForKilling("DummyProc
", 20)) | 392 using (System.Diagnostics.Process dummyProc = TestUtilities.StartProcessFo
rKilling( |
| 393 "DummyProc", 20)) |
| 383 { | 394 { |
| 384 try | 395 try |
| 385 { | 396 { |
| 386 PluginDebuggerHelper_Accessor target = new PluginDebuggerHelper_Access
or(dte_); | 397 PluginDebuggerHelper_Accessor target = new PluginDebuggerHelper_Access
or(dte_); |
| 387 target.projectPlatformType_ = PluginDebuggerHelper_Accessor.ProjectPla
tformType.Pepper; | 398 target.projectPlatformType_ = PluginDebuggerHelper_Accessor.ProjectPla
tformType.Pepper; |
| 388 target.isProperlyInitialized_ = true; | 399 target.isProperlyInitialized_ = true; |
| 389 | 400 |
| 390 target.AttachVSDebugger( | 401 var pluginFoundArgs = new NativeClientVSAddIn.PluginDebuggerHelper.Plu
ginFoundEventArgs( |
| 391 null, | 402 (uint)dummyProc.Id); |
| 392 new NativeClientVSAddIn.PluginDebuggerHelper.PluginFoundEventArgs(
(uint)dummyProc.Id)); | 403 target.AttachVSDebugger(null, pluginFoundArgs); |
| 393 | 404 |
| 394 bool isBeingDebugged = false; | 405 bool isBeingDebugged = false; |
| 395 foreach (EnvDTE.Process proc in dte_.Debugger.DebuggedProcesses) | 406 foreach (EnvDTE.Process proc in dte_.Debugger.DebuggedProcesses) |
| 396 { | 407 { |
| 397 if (proc.ProcessID == dummyProc.Id) | 408 if (proc.ProcessID == dummyProc.Id) |
| 398 { | 409 { |
| 399 isBeingDebugged = true; | 410 isBeingDebugged = true; |
| 400 } | 411 } |
| 401 } | 412 } |
| 402 | 413 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 for (int repeat = 0; repeat < 20; repeat++) | 515 for (int repeat = 0; repeat < 20; repeat++) |
| 505 { | 516 { |
| 506 if (result != null && | 517 if (result != null && |
| 507 result.Contains(successMessage) && | 518 result.Contains(successMessage) && |
| 508 result.Contains(stderrMessage) && | 519 result.Contains(stderrMessage) && |
| 509 result.Contains(TestContext.DeploymentDirectory)) | 520 result.Contains(TestContext.DeploymentDirectory)) |
| 510 { | 521 { |
| 511 break; | 522 break; |
| 512 } | 523 } |
| 513 | 524 |
| 514 Thread.Sleep(500); | 525 System.Threading.Thread.Sleep(500); |
| 515 result = TestUtilities.GetPaneText(target.webServerOutputPane_); | 526 result = TestUtilities.GetPaneText(target.webServerOutputPane_); |
| 516 } | 527 } |
| 517 | 528 |
| 518 Assert.IsFalse(string.IsNullOrEmpty(result), "Nothing printed to output
pane"); | 529 Assert.IsFalse(string.IsNullOrEmpty(result), "Nothing printed to output
pane"); |
| 519 StringAssert.Contains( | 530 StringAssert.Contains( |
| 520 result, | 531 result, |
| 521 successMessage, | 532 successMessage, |
| 522 "Executable did not successfully run given arguments"); | 533 "Executable did not successfully run given arguments"); |
| 523 StringAssert.Contains( | 534 StringAssert.Contains( |
| 524 result, | 535 result, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 | 601 |
| 591 // Wait for results to arrive for up to 10 seconds, checking every 0.5 sec
onds. | 602 // Wait for results to arrive for up to 10 seconds, checking every 0.5 sec
onds. |
| 592 for (int repeat = 0; repeat < 20; repeat++) | 603 for (int repeat = 0; repeat < 20; repeat++) |
| 593 { | 604 { |
| 594 if (result != null && | 605 if (result != null && |
| 595 result.Contains(successMessage)) | 606 result.Contains(successMessage)) |
| 596 { | 607 { |
| 597 break; | 608 break; |
| 598 } | 609 } |
| 599 | 610 |
| 600 Thread.Sleep(500); | 611 System.Threading.Thread.Sleep(500); |
| 601 result = TestUtilities.GetPaneText(target.webServerOutputPane_); | 612 result = TestUtilities.GetPaneText(target.webServerOutputPane_); |
| 602 } | 613 } |
| 603 | 614 |
| 604 StringAssert.Contains(result, successMessage, "Message failed to print"); | 615 StringAssert.Contains(result, successMessage, "Message failed to print"); |
| 605 } | 616 } |
| 606 } | 617 } |
| 607 } | 618 } |
| OLD | NEW |