michael@0: // Copyright 2008, Google Inc. michael@0: // All rights reserved. michael@0: // michael@0: // Redistribution and use in source and binary forms, with or without michael@0: // modification, are permitted provided that the following conditions are michael@0: // met: michael@0: // michael@0: // * Redistributions of source code must retain the above copyright michael@0: // notice, this list of conditions and the following disclaimer. michael@0: // * Redistributions in binary form must reproduce the above michael@0: // copyright notice, this list of conditions and the following disclaimer michael@0: // in the documentation and/or other materials provided with the michael@0: // distribution. michael@0: // * Neither the name of Google Inc. nor the names of its michael@0: // contributors may be used to endorse or promote products derived from michael@0: // this software without specific prior written permission. michael@0: // michael@0: // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS michael@0: // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT michael@0: // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR michael@0: // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT michael@0: // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, michael@0: // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT michael@0: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, michael@0: // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY michael@0: // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT michael@0: // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE michael@0: // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. michael@0: // michael@0: // Author: mheule@google.com (Markus Heule) michael@0: // michael@0: // The Google C++ Testing Framework (Google Test) michael@0: michael@0: #include "gtest/gtest-test-part.h" michael@0: michael@0: // Indicates that this translation unit is part of Google Test's michael@0: // implementation. It must come before gtest-internal-inl.h is michael@0: // included, or there will be a compiler error. This trick is to michael@0: // prevent a user from accidentally including gtest-internal-inl.h in michael@0: // his code. michael@0: #define GTEST_IMPLEMENTATION_ 1 michael@0: #include "src/gtest-internal-inl.h" michael@0: #undef GTEST_IMPLEMENTATION_ michael@0: michael@0: namespace testing { michael@0: michael@0: using internal::GetUnitTestImpl; michael@0: michael@0: // Gets the summary of the failure message by omitting the stack trace michael@0: // in it. michael@0: internal::String TestPartResult::ExtractSummary(const char* message) { michael@0: const char* const stack_trace = strstr(message, internal::kStackTraceMarker); michael@0: return stack_trace == NULL ? internal::String(message) : michael@0: internal::String(message, stack_trace - message); michael@0: } michael@0: michael@0: // Prints a TestPartResult object. michael@0: std::ostream& operator<<(std::ostream& os, const TestPartResult& result) { michael@0: return os michael@0: << result.file_name() << ":" << result.line_number() << ": " michael@0: << (result.type() == TestPartResult::kSuccess ? "Success" : michael@0: result.type() == TestPartResult::kFatalFailure ? "Fatal failure" : michael@0: "Non-fatal failure") << ":\n" michael@0: << result.message() << std::endl; michael@0: } michael@0: michael@0: // Appends a TestPartResult to the array. michael@0: void TestPartResultArray::Append(const TestPartResult& result) { michael@0: array_.push_back(result); michael@0: } michael@0: michael@0: // Returns the TestPartResult at the given index (0-based). michael@0: const TestPartResult& TestPartResultArray::GetTestPartResult(int index) const { michael@0: if (index < 0 || index >= size()) { michael@0: printf("\nInvalid index (%d) into TestPartResultArray.\n", index); michael@0: internal::posix::Abort(); michael@0: } michael@0: michael@0: return array_[index]; michael@0: } michael@0: michael@0: // Returns the number of TestPartResult objects in the array. michael@0: int TestPartResultArray::size() const { michael@0: return static_cast(array_.size()); michael@0: } michael@0: michael@0: namespace internal { michael@0: michael@0: HasNewFatalFailureHelper::HasNewFatalFailureHelper() michael@0: : has_new_fatal_failure_(false), michael@0: original_reporter_(GetUnitTestImpl()-> michael@0: GetTestPartResultReporterForCurrentThread()) { michael@0: GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread(this); michael@0: } michael@0: michael@0: HasNewFatalFailureHelper::~HasNewFatalFailureHelper() { michael@0: GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread( michael@0: original_reporter_); michael@0: } michael@0: michael@0: void HasNewFatalFailureHelper::ReportTestPartResult( michael@0: const TestPartResult& result) { michael@0: if (result.fatally_failed()) michael@0: has_new_fatal_failure_ = true; michael@0: original_reporter_->ReportTestPartResult(result); michael@0: } michael@0: michael@0: } // namespace internal michael@0: michael@0: } // namespace testing