/home/arjun/llvm-project/llvm/utils/unittest/googletest/src/gtest-test-part.cc
| Line | Count | Source (jump to first uncovered line) | 
| 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 |  | // Author: mheule@google.com (Markus Heule) | 
| 31 |  | // | 
| 32 |  | // The Google C++ Testing Framework (Google Test) | 
| 33 |  |  | 
| 34 |  | #include "gtest/gtest-test-part.h" | 
| 35 |  |  | 
| 36 |  | // Indicates that this translation unit is part of Google Test's | 
| 37 |  | // implementation.  It must come before gtest-internal-inl.h is | 
| 38 |  | // included, or there will be a compiler error.  This trick exists to | 
| 39 |  | // prevent the accidental inclusion of gtest-internal-inl.h in the | 
| 40 |  | // user's code. | 
| 41 |  | #define GTEST_IMPLEMENTATION_ 1 | 
| 42 |  | #include "src/gtest-internal-inl.h" | 
| 43 |  | #undef GTEST_IMPLEMENTATION_ | 
| 44 |  |  | 
| 45 |  | namespace testing { | 
| 46 |  |  | 
| 47 |  | using internal::GetUnitTestImpl; | 
| 48 |  |  | 
| 49 |  | // Gets the summary of the failure message by omitting the stack trace | 
| 50 |  | // in it. | 
| 51 | 0 | std::string TestPartResult::ExtractSummary(const char* message) { | 
| 52 | 0 |   const char* const stack_trace = strstr(message, internal::kStackTraceMarker); | 
| 53 | 0 |   return stack_trace == NULL ? message : | 
| 54 | 0 |       std::string(message, stack_trace); | 
| 55 | 0 | } | 
| 56 |  |  | 
| 57 |  | // Prints a TestPartResult object. | 
| 58 | 0 | std::ostream& operator<<(std::ostream& os, const TestPartResult& result) { | 
| 59 | 0 |   return os | 
| 60 | 0 |       << result.file_name() << ":" << result.line_number() << ": " | 
| 61 | 0 |       << (result.type() == TestPartResult::kSuccess ? "Success" : | 
| 62 | 0 |           result.type() == TestPartResult::kFatalFailure ? "Fatal failure" : | 
| 63 | 0 |           "Non-fatal failure") << ":\n" | 
| 64 | 0 |       << result.message() << std::endl; | 
| 65 | 0 | } | 
| 66 |  |  | 
| 67 |  | // Appends a TestPartResult to the array. | 
| 68 | 0 | void TestPartResultArray::Append(const TestPartResult& result) { | 
| 69 | 0 |   array_.push_back(result); | 
| 70 | 0 | } | 
| 71 |  |  | 
| 72 |  | // Returns the TestPartResult at the given index (0-based). | 
| 73 | 0 | const TestPartResult& TestPartResultArray::GetTestPartResult(int index) const { | 
| 74 | 0 |   if (index < 0 || index >= size()) { | 
| 75 | 0 |     printf("\nInvalid index (%d) into TestPartResultArray.\n", index); | 
| 76 | 0 |     internal::posix::Abort(); | 
| 77 | 0 |   } | 
| 78 | 0 | 
 | 
| 79 | 0 |   return array_[index]; | 
| 80 | 0 | } | 
| 81 |  |  | 
| 82 |  | // Returns the number of TestPartResult objects in the array. | 
| 83 | 0 | int TestPartResultArray::size() const { | 
| 84 | 0 |   return static_cast<int>(array_.size()); | 
| 85 | 0 | } | 
| 86 |  |  | 
| 87 |  | namespace internal { | 
| 88 |  |  | 
| 89 |  | HasNewFatalFailureHelper::HasNewFatalFailureHelper() | 
| 90 |  |     : has_new_fatal_failure_(false), | 
| 91 |  |       original_reporter_(GetUnitTestImpl()-> | 
| 92 | 0 |                          GetTestPartResultReporterForCurrentThread()) { | 
| 93 | 0 |   GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread(this); | 
| 94 | 0 | } | 
| 95 |  |  | 
| 96 | 0 | HasNewFatalFailureHelper::~HasNewFatalFailureHelper() { | 
| 97 | 0 |   GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread( | 
| 98 | 0 |       original_reporter_); | 
| 99 | 0 | } | 
| 100 |  |  | 
| 101 |  | void HasNewFatalFailureHelper::ReportTestPartResult( | 
| 102 | 0 |     const TestPartResult& result) { | 
| 103 | 0 |   if (result.fatally_failed()) | 
| 104 | 0 |     has_new_fatal_failure_ = true; | 
| 105 | 0 |   original_reporter_->ReportTestPartResult(result); | 
| 106 | 0 | } | 
| 107 |  |  | 
| 108 |  | }  // namespace internal | 
| 109 |  |  | 
| 110 |  | }  // namespace testing |