xref: /aosp_15_r20/external/cronet/third_party/googletest/custom/gtest/internal/custom/stack_trace_getter.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2018 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 #ifndef THIRD_PARTY_GOOGLETEST_CUSTOM_GTEST_INTERNAL_CUSTOM_STACK_TRACE_GETTER_H_
6 #define THIRD_PARTY_GOOGLETEST_CUSTOM_GTEST_INTERNAL_CUSTOM_STACK_TRACE_GETTER_H_
7 
8 #include "base/debug/stack_trace.h"
9 #include "third_party/abseil-cpp/absl/types/optional.h"
10 #include "third_party/googletest/src/googletest/src/gtest-internal-inl.h"
11 
12 // An implementation of Google Test's OsStackTraceGetterInterface that uses
13 // Chromium's base::debug::StackTrace to obtain stringified stack traces.
14 class StackTraceGetter
15     : public ::testing::internal::OsStackTraceGetterInterface {
16  public:
17   StackTraceGetter() = default;
18   ~StackTraceGetter() override = default;
19   StackTraceGetter(const StackTraceGetter&) = delete;
20   StackTraceGetter& operator=(const StackTraceGetter&) = delete;
21 
22   // ::testing::internal::OsStackTraceGetterInterface:
23   std::string CurrentStackTrace(int max_depth, int skip_count) override;
24   void UponLeavingGTest() override;
25 
26  private:
27   absl::optional<base::debug::StackTrace> stack_trace_upon_leaving_gtest_;
28 };
29 
30 #endif  // THIRD_PARTY_GOOGLETEST_CUSTOM_GTEST_INTERNAL_CUSTOM_STACK_TRACE_GETTER_H_
31