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