00001 // Copyright 2008, Google Inc. 00002 // All rights reserved. 00003 // 00004 // Redistribution and use in source and binary forms, with or without 00005 // modification, are permitted provided that the following conditions are 00006 // met: 00007 // 00008 // * Redistributions of source code must retain the above copyright 00009 // notice, this list of conditions and the following disclaimer. 00010 // * Redistributions in binary form must reproduce the above 00011 // copyright notice, this list of conditions and the following disclaimer 00012 // in the documentation and/or other materials provided with the 00013 // distribution. 00014 // * Neither the name of Google Inc. nor the names of its 00015 // contributors may be used to endorse or promote products derived from 00016 // this software without specific prior written permission. 00017 // 00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00019 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00020 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00021 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00022 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00023 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00024 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00025 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00026 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00028 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 // 00030 // Author: mheule@google.com (Markus Heule) 00031 // 00032 // The Google C++ Testing Framework (Google Test) 00033 00034 #include "gtest/gtest-test-part.h" 00035 00036 // Indicates that this translation unit is part of Google Test's 00037 // implementation. It must come before gtest-internal-inl.h is 00038 // included, or there will be a compiler error. This trick exists to 00039 // prevent the accidental inclusion of gtest-internal-inl.h in the 00040 // user's code. 00041 #define GTEST_IMPLEMENTATION_ 1 00042 #include "src/gtest-internal-inl.h" 00043 #undef GTEST_IMPLEMENTATION_ 00044 00045 namespace testing { 00046 00047 using internal::GetUnitTestImpl; 00048 00049 // Gets the summary of the failure message by omitting the stack trace 00050 // in it. 00051 std::string TestPartResult::ExtractSummary(const char* message) { 00052 const char* const stack_trace = strstr(message, internal::kStackTraceMarker); 00053 return stack_trace == NULL ? message : 00054 std::string(message, stack_trace); 00055 } 00056 00057 // Prints a TestPartResult object. 00058 std::ostream& operator<<(std::ostream& os, const TestPartResult& result) { 00059 return os 00060 << result.file_name() << ":" << result.line_number() << ": " 00061 << (result.type() == TestPartResult::kSuccess ? "Success" : 00062 result.type() == TestPartResult::kFatalFailure ? "Fatal failure" : 00063 "Non-fatal failure") << ":\n" 00064 << result.message() << std::endl; 00065 } 00066 00067 // Appends a TestPartResult to the array. 00068 void TestPartResultArray::Append(const TestPartResult& result) { 00069 array_.push_back(result); 00070 } 00071 00072 // Returns the TestPartResult at the given index (0-based). 00073 const TestPartResult& TestPartResultArray::GetTestPartResult(int index) const { 00074 if (index < 0 || index >= size()) { 00075 printf("\nInvalid index (%d) into TestPartResultArray.\n", index); 00076 internal::posix::Abort(); 00077 } 00078 00079 return array_[index]; 00080 } 00081 00082 // Returns the number of TestPartResult objects in the array. 00083 int TestPartResultArray::size() const { 00084 return static_cast<int>(array_.size()); 00085 } 00086 00087 namespace internal { 00088 00089 HasNewFatalFailureHelper::HasNewFatalFailureHelper() 00090 : has_new_fatal_failure_(false), 00091 original_reporter_(GetUnitTestImpl()-> 00092 GetTestPartResultReporterForCurrentThread()) { 00093 GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread(this); 00094 } 00095 00096 HasNewFatalFailureHelper::~HasNewFatalFailureHelper() { 00097 GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread( 00098 original_reporter_); 00099 } 00100 00101 void HasNewFatalFailureHelper::ReportTestPartResult( 00102 const TestPartResult& result) { 00103 if (result.fatally_failed()) 00104 has_new_fatal_failure_ = true; 00105 original_reporter_->ReportTestPartResult(result); 00106 } 00107 00108 } // namespace internal 00109 00110 } // namespace testing