Path: blob/master/dep/googletest/src/gtest-test-part.cc
4804 views
// Copyright 2008, Google Inc.1// All rights reserved.2//3// Redistribution and use in source and binary forms, with or without4// modification, are permitted provided that the following conditions are5// met:6//7// * Redistributions of source code must retain the above copyright8// notice, this list of conditions and the following disclaimer.9// * Redistributions in binary form must reproduce the above10// copyright notice, this list of conditions and the following disclaimer11// in the documentation and/or other materials provided with the12// distribution.13// * Neither the name of Google Inc. nor the names of its14// contributors may be used to endorse or promote products derived from15// this software without specific prior written permission.16//17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT19// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR20// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT21// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,22// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT23// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,24// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY25// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT26// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE27// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.2829//30// The Google C++ Testing and Mocking Framework (Google Test)3132#include "gtest/gtest-test-part.h"3334#include <ostream>35#include <string>3637#include "gtest/internal/gtest-port.h"38#include "src/gtest-internal-inl.h"3940namespace testing {4142// Gets the summary of the failure message by omitting the stack trace43// in it.44std::string TestPartResult::ExtractSummary(const char* message) {45const char* const stack_trace = strstr(message, internal::kStackTraceMarker);46return stack_trace == nullptr ? message : std::string(message, stack_trace);47}4849// Prints a TestPartResult object.50std::ostream& operator<<(std::ostream& os, const TestPartResult& result) {51return os << internal::FormatFileLocation(result.file_name(),52result.line_number())53<< " "54<< (result.type() == TestPartResult::kSuccess ? "Success"55: result.type() == TestPartResult::kSkip ? "Skipped"56: result.type() == TestPartResult::kFatalFailure57? "Fatal failure"58: "Non-fatal failure")59<< ":\n"60<< result.message() << std::endl;61}6263// Appends a TestPartResult to the array.64void TestPartResultArray::Append(const TestPartResult& result) {65array_.push_back(result);66}6768// Returns the TestPartResult at the given index (0-based).69const TestPartResult& TestPartResultArray::GetTestPartResult(int index) const {70if (index < 0 || index >= size()) {71printf("\nInvalid index (%d) into TestPartResultArray.\n", index);72internal::posix::Abort();73}7475return array_[static_cast<size_t>(index)];76}7778// Returns the number of TestPartResult objects in the array.79int TestPartResultArray::size() const {80return static_cast<int>(array_.size());81}8283namespace internal {8485HasNewFatalFailureHelper::HasNewFatalFailureHelper()86: has_new_fatal_failure_(false),87original_reporter_(88GetUnitTestImpl()->GetTestPartResultReporterForCurrentThread()) {89GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread(this);90}9192HasNewFatalFailureHelper::~HasNewFatalFailureHelper() {93GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread(94original_reporter_);95}9697void HasNewFatalFailureHelper::ReportTestPartResult(98const TestPartResult& result) {99if (result.fatally_failed()) has_new_fatal_failure_ = true;100original_reporter_->ReportTestPartResult(result);101}102103} // namespace internal104105} // namespace testing106107108