debugger_unittest.cc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2014 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. #include "base/debug/debugger.h"
  5. #include "build/build_config.h"
  6. #if BUILDFLAG(IS_WIN)
  7. #include <windows.h>
  8. #endif
  9. #include "testing/gtest/include/gtest/gtest.h"
  10. namespace {
  11. #if defined(GTEST_HAS_DEATH_TEST) && !BUILDFLAG(IS_ANDROID)
  12. void CrashWithBreakDebugger() {
  13. base::debug::SetSuppressDebugUI(false);
  14. base::debug::BreakDebugger();
  15. #if BUILDFLAG(IS_WIN)
  16. // This should not be executed.
  17. _exit(125);
  18. #endif
  19. }
  20. #endif // defined(GTEST_HAS_DEATH_TEST)
  21. } // namespace
  22. // Death tests misbehave on Android.
  23. #if defined(GTEST_HAS_DEATH_TEST) && !BUILDFLAG(IS_ANDROID)
  24. TEST(Debugger, CrashAtBreakpoint) {
  25. EXPECT_DEATH(CrashWithBreakDebugger(), "");
  26. }
  27. #if BUILDFLAG(IS_WIN)
  28. TEST(Debugger, DoesntExecuteBeyondBreakpoint) {
  29. EXPECT_EXIT(CrashWithBreakDebugger(),
  30. ::testing::ExitedWithCode(STATUS_BREAKPOINT), "");
  31. }
  32. #endif // BUILDFLAG(IS_WIN)
  33. #else // defined(GTEST_HAS_DEATH_TEST) && !BUILDFLAG(IS_ANDROID)
  34. TEST(Debugger, NoTest) {
  35. }
  36. #endif // defined(GTEST_HAS_DEATH_TEST) && !BUILDFLAG(IS_ANDROID)