xref: /aosp_15_r20/external/cronet/base/debug/debugger_unittest.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2014 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "base/debug/debugger.h"
6 #include "build/build_config.h"
7 
8 #if BUILDFLAG(IS_WIN)
9 #include <windows.h>
10 #endif
11 
12 #include "testing/gtest/include/gtest/gtest.h"
13 
14 namespace {
15 
16 #if defined(GTEST_HAS_DEATH_TEST) && !BUILDFLAG(IS_ANDROID)
CrashWithBreakDebugger()17 void CrashWithBreakDebugger() {
18   base::debug::SetSuppressDebugUI(false);
19   base::debug::BreakDebugger();
20 
21 #if BUILDFLAG(IS_WIN)
22   // This should not be executed.
23   _exit(125);
24 #endif
25 }
26 #endif  // defined(GTEST_HAS_DEATH_TEST)
27 
28 }  // namespace
29 
30 // Death tests misbehave on Android.
31 #if defined(GTEST_HAS_DEATH_TEST) && !BUILDFLAG(IS_ANDROID)
32 
TEST(Debugger,CrashAtBreakpoint)33 TEST(Debugger, CrashAtBreakpoint) {
34   EXPECT_DEATH(CrashWithBreakDebugger(), "");
35 }
36 
37 #if BUILDFLAG(IS_WIN)
TEST(Debugger,DoesntExecuteBeyondBreakpoint)38 TEST(Debugger, DoesntExecuteBeyondBreakpoint) {
39   EXPECT_EXIT(CrashWithBreakDebugger(),
40               ::testing::ExitedWithCode(STATUS_BREAKPOINT), "");
41 }
42 #endif  // BUILDFLAG(IS_WIN)
43 
44 #else   // defined(GTEST_HAS_DEATH_TEST) && !BUILDFLAG(IS_ANDROID)
TEST(Debugger,NoTest)45 TEST(Debugger, NoTest) {
46 }
47 #endif  // defined(GTEST_HAS_DEATH_TEST) && !BUILDFLAG(IS_ANDROID)
48