media/webrtc/trunk/testing/gtest/src/gtest-test-part.cc

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

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

mercurial