1e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// Copyright 2008, Google Inc.
2e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// All rights reserved.
3e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian//
4e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// Redistribution and use in source and binary forms, with or without
5e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// modification, are permitted provided that the following conditions are
6e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// met:
7e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian//
8e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian//     * Redistributions of source code must retain the above copyright
9e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// notice, this list of conditions and the following disclaimer.
10e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian//     * Redistributions in binary form must reproduce the above
11e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// copyright notice, this list of conditions and the following disclaimer
12e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// in the documentation and/or other materials provided with the
13e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// distribution.
14e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian//     * Neither the name of Google Inc. nor the names of its
15e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// contributors may be used to endorse or promote products derived from
16e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// this software without specific prior written permission.
17e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian//
18e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian//
30e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// Author: mheule@google.com (Markus Heule)
31e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian//
32e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// The Google C++ Testing Framework (Google Test)
33e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian
34dac3e879c56a50696a36f53e1e5e353e48fa665fzhanyong.wan#include "gtest/gtest-test-part.h"
35e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian
36e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// Indicates that this translation unit is part of Google Test's
37e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// implementation.  It must come before gtest-internal-inl.h is
3896ddffe8fdabccb10fb693a54dcb88bd5b71bc09kosak// included, or there will be a compiler error.  This trick exists to
3996ddffe8fdabccb10fb693a54dcb88bd5b71bc09kosak// prevent the accidental inclusion of gtest-internal-inl.h in the
4096ddffe8fdabccb10fb693a54dcb88bd5b71bc09kosak// user's code.
410af0709b02899f9177db55eba7929e65e5834b29zhanyong.wan#define GTEST_IMPLEMENTATION_ 1
42e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian#include "src/gtest-internal-inl.h"
430af0709b02899f9177db55eba7929e65e5834b29zhanyong.wan#undef GTEST_IMPLEMENTATION_
44e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian
45e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqiannamespace testing {
46e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian
47aaebfcdc4005afb22b68df61b58edd1ccc002913zhanyong.wanusing internal::GetUnitTestImpl;
48aaebfcdc4005afb22b68df61b58edd1ccc002913zhanyong.wan
49e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// Gets the summary of the failure message by omitting the stack trace
50e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// in it.
5187fdda2cf24d953f3cbec1e0c266b2db9928f406jgmstd::string TestPartResult::ExtractSummary(const char* message) {
52e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian  const char* const stack_trace = strstr(message, internal::kStackTraceMarker);
5387fdda2cf24d953f3cbec1e0c266b2db9928f406jgm  return stack_trace == NULL ? message :
5487fdda2cf24d953f3cbec1e0c266b2db9928f406jgm      std::string(message, stack_trace);
55e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian}
56e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian
57e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// Prints a TestPartResult object.
58e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqianstd::ostream& operator<<(std::ostream& os, const TestPartResult& result) {
59e5373af0cb9cae249e7bc618cae3483397332895zhanyong.wan  return os
60e5373af0cb9cae249e7bc618cae3483397332895zhanyong.wan      << result.file_name() << ":" << result.line_number() << ": "
61e5373af0cb9cae249e7bc618cae3483397332895zhanyong.wan      << (result.type() == TestPartResult::kSuccess ? "Success" :
62e5373af0cb9cae249e7bc618cae3483397332895zhanyong.wan          result.type() == TestPartResult::kFatalFailure ? "Fatal failure" :
63e5373af0cb9cae249e7bc618cae3483397332895zhanyong.wan          "Non-fatal failure") << ":\n"
64e5373af0cb9cae249e7bc618cae3483397332895zhanyong.wan      << result.message() << std::endl;
65e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian}
66e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian
67e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// Appends a TestPartResult to the array.
68e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqianvoid TestPartResultArray::Append(const TestPartResult& result) {
690d27868d0faef474594682f25336229daa89d6d7zhanyong.wan  array_.push_back(result);
70e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian}
71e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian
72e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// Returns the TestPartResult at the given index (0-based).
73e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqianconst TestPartResult& TestPartResultArray::GetTestPartResult(int index) const {
74e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian  if (index < 0 || index >= size()) {
75e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian    printf("\nInvalid index (%d) into TestPartResultArray.\n", index);
76f2d0d0e3d56794855d1e9a1f157457b7225e8c88zhanyong.wan    internal::posix::Abort();
77e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian  }
78e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian
790d27868d0faef474594682f25336229daa89d6d7zhanyong.wan  return array_[index];
80e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian}
81e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian
82e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian// Returns the number of TestPartResult objects in the array.
83e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqianint TestPartResultArray::size() const {
846baed3c1173c19f5d43af75798d3685853fbe8bdzhanyong.wan  return static_cast<int>(array_.size());
85e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian}
86e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian
87e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqiannamespace internal {
88e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian
89e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqianHasNewFatalFailureHelper::HasNewFatalFailureHelper()
90e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian    : has_new_fatal_failure_(false),
91aaebfcdc4005afb22b68df61b58edd1ccc002913zhanyong.wan      original_reporter_(GetUnitTestImpl()->
92e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian                         GetTestPartResultReporterForCurrentThread()) {
93aaebfcdc4005afb22b68df61b58edd1ccc002913zhanyong.wan  GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread(this);
94e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian}
95e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian
96e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqianHasNewFatalFailureHelper::~HasNewFatalFailureHelper() {
97aaebfcdc4005afb22b68df61b58edd1ccc002913zhanyong.wan  GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread(
98e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian      original_reporter_);
99e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian}
100e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian
101e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqianvoid HasNewFatalFailureHelper::ReportTestPartResult(
102e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian    const TestPartResult& result) {
103e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian  if (result.fatally_failed())
104e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian    has_new_fatal_failure_ = true;
105e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian  original_reporter_->ReportTestPartResult(result);
106e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian}
107e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian
108e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian}  // namespace internal
109e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian
110e0865dd9199e8fffd5c2f95a68de6c1851f77c15shiqian}  // namespace testing
111