gtest-test-part.cc
Go to the documentation of this file.
1 // Copyright 2008, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30 //
31 // The Google C++ Testing and Mocking Framework (Google Test)
32 
33 #include "gtest/gtest-test-part.h"
34 #include "src/gtest-internal-inl.h"
35 
36 namespace testing {
37 
38 using internal::GetUnitTestImpl;
39 
40 // Gets the summary of the failure message by omitting the stack trace
41 // in it.
42 std::string TestPartResult::ExtractSummary(const char* message) {
43  const char* const stack_trace = strstr(message, internal::kStackTraceMarker);
44  return stack_trace == nullptr ? message : std::string(message, stack_trace);
45 }
46 
47 // Prints a TestPartResult object.
48 std::ostream& operator<<(std::ostream& os, const TestPartResult& result) {
49  return os << result.file_name() << ":" << result.line_number() << ": "
50  << (result.type() == TestPartResult::kSuccess
51  ? "Success"
52  : result.type() == TestPartResult::kSkip
53  ? "Skipped"
54  : result.type() == TestPartResult::kFatalFailure
55  ? "Fatal failure"
56  : "Non-fatal failure")
57  << ":\n"
58  << result.message() << std::endl;
59 }
60 
61 // Appends a TestPartResult to the array.
62 void TestPartResultArray::Append(const TestPartResult& result) {
63  array_.push_back(result);
64 }
65 
66 // Returns the TestPartResult at the given index (0-based).
67 const TestPartResult& TestPartResultArray::GetTestPartResult(int index) const {
68  if (index < 0 || index >= size()) {
69  printf("\nInvalid index (%d) into TestPartResultArray.\n", index);
71  }
72 
73  return array_[index];
74 }
75 
76 // Returns the number of TestPartResult objects in the array.
77 int TestPartResultArray::size() const {
78  return static_cast<int>(array_.size());
79 }
80 
81 namespace internal {
82 
83 HasNewFatalFailureHelper::HasNewFatalFailureHelper()
84  : has_new_fatal_failure_(false),
85  original_reporter_(GetUnitTestImpl()->
86  GetTestPartResultReporterForCurrentThread()) {
87  GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread(this);
88 }
89 
90 HasNewFatalFailureHelper::~HasNewFatalFailureHelper() {
91  GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread(
92  original_reporter_);
93 }
94 
95 void HasNewFatalFailureHelper::ReportTestPartResult(
96  const TestPartResult& result) {
97  if (result.fatally_failed())
98  has_new_fatal_failure_ = true;
99  original_reporter_->ReportTestPartResult(result);
100 }
101 
102 } // namespace internal
103 
104 } // namespace testing
testing
Definition: gmock-actions.h:59
gtest-internal-inl.h
testing::operator<<
std::ostream & operator<<(std::ostream &os, const Message &sb)
Definition: gtest-message.h:204
Append
static void Append(State *state, const char *const str, const int length)
Definition: demangle.cc:272
string
GLsizei const GLchar *const * string
Definition: glcorearb.h:3083
testing::internal::posix::Abort
void Abort()
Definition: gtest-port.h:2158
size
#define size
Definition: glcorearb.h:2944
testing::internal::kStackTraceMarker
const GTEST_API_ char kStackTraceMarker[]
Definition: gtest.cc:178
internal
Definition: any.pb.h:40
false
#define false
Definition: cJSON.c:70
gtest-test-part.h
index
GLuint index
Definition: glcorearb.h:3055
message
GLenum GLuint GLenum GLsizei const GLchar * message
Definition: glcorearb.h:2695


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:53