| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include <sstream> | 5 #include <sstream> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/debug/stack_trace.h" | 8 #include "base/debug/stack_trace.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #define MAYBE_OutputToStream OutputToStream | 21 #define MAYBE_OutputToStream OutputToStream |
| 22 #endif | 22 #endif |
| 23 TEST(StackTrace, MAYBE_OutputToStream) { | 23 TEST(StackTrace, MAYBE_OutputToStream) { |
| 24 StackTrace trace; | 24 StackTrace trace; |
| 25 | 25 |
| 26 // Dump the trace into a string. | 26 // Dump the trace into a string. |
| 27 std::ostringstream os; | 27 std::ostringstream os; |
| 28 trace.OutputToStream(&os); | 28 trace.OutputToStream(&os); |
| 29 std::string backtrace_message = os.str(); | 29 std::string backtrace_message = os.str(); |
| 30 | 30 |
| 31 // ToString() should produce the same output. |
| 32 EXPECT_EQ(backtrace_message, trace.ToString()); |
| 33 |
| 31 #if defined(OS_POSIX) && !defined(OS_MACOSX) && NDEBUG | 34 #if defined(OS_POSIX) && !defined(OS_MACOSX) && NDEBUG |
| 32 // Stack traces require an extra data table that bloats our binaries, | 35 // Stack traces require an extra data table that bloats our binaries, |
| 33 // so they're turned off for release builds. We stop the test here, | 36 // so they're turned off for release builds. We stop the test here, |
| 34 // at least letting us verify that the calls don't crash. | 37 // at least letting us verify that the calls don't crash. |
| 35 return; | 38 return; |
| 36 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) && NDEBUG | 39 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) && NDEBUG |
| 37 | 40 |
| 38 size_t frames_found = 0; | 41 size_t frames_found = 0; |
| 39 trace.Addresses(&frames_found); | 42 trace.Addresses(&frames_found); |
| 40 ASSERT_GE(frames_found, 5u) << | 43 ASSERT_GE(frames_found, 5u) << |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 VLOG(1) << os.str(); | 111 VLOG(1) << os.str(); |
| 109 } | 112 } |
| 110 | 113 |
| 111 // The test is used for manual testing, e.g., to see the raw output. | 114 // The test is used for manual testing, e.g., to see the raw output. |
| 112 TEST(StackTrace, DebugPrintBacktrace) { | 115 TEST(StackTrace, DebugPrintBacktrace) { |
| 113 StackTrace().PrintBacktrace(); | 116 StackTrace().PrintBacktrace(); |
| 114 } | 117 } |
| 115 | 118 |
| 116 } // namespace debug | 119 } // namespace debug |
| 117 } // namespace base | 120 } // namespace base |
| OLD | NEW |