1*28f6c2f2SEnji Cooper // Copyright 2005, Google Inc.
2*28f6c2f2SEnji Cooper // All rights reserved.
3*28f6c2f2SEnji Cooper //
4*28f6c2f2SEnji Cooper // Redistribution and use in source and binary forms, with or without
5*28f6c2f2SEnji Cooper // modification, are permitted provided that the following conditions are
6*28f6c2f2SEnji Cooper // met:
7*28f6c2f2SEnji Cooper //
8*28f6c2f2SEnji Cooper // * Redistributions of source code must retain the above copyright
9*28f6c2f2SEnji Cooper // notice, this list of conditions and the following disclaimer.
10*28f6c2f2SEnji Cooper // * Redistributions in binary form must reproduce the above
11*28f6c2f2SEnji Cooper // copyright notice, this list of conditions and the following disclaimer
12*28f6c2f2SEnji Cooper // in the documentation and/or other materials provided with the
13*28f6c2f2SEnji Cooper // distribution.
14*28f6c2f2SEnji Cooper // * Neither the name of Google Inc. nor the names of its
15*28f6c2f2SEnji Cooper // contributors may be used to endorse or promote products derived from
16*28f6c2f2SEnji Cooper // this software without specific prior written permission.
17*28f6c2f2SEnji Cooper //
18*28f6c2f2SEnji Cooper // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19*28f6c2f2SEnji Cooper // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20*28f6c2f2SEnji Cooper // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21*28f6c2f2SEnji Cooper // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22*28f6c2f2SEnji Cooper // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23*28f6c2f2SEnji Cooper // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24*28f6c2f2SEnji Cooper // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25*28f6c2f2SEnji Cooper // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26*28f6c2f2SEnji Cooper // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27*28f6c2f2SEnji Cooper // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28*28f6c2f2SEnji Cooper // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*28f6c2f2SEnji Cooper
30*28f6c2f2SEnji Cooper // The Google C++ Testing and Mocking Framework (Google Test)
31*28f6c2f2SEnji Cooper //
32*28f6c2f2SEnji Cooper // This file defines the AssertionResult type.
33*28f6c2f2SEnji Cooper
34*28f6c2f2SEnji Cooper #include "gtest/gtest-assertion-result.h"
35*28f6c2f2SEnji Cooper
36*28f6c2f2SEnji Cooper #include <string>
37*28f6c2f2SEnji Cooper #include <utility>
38*28f6c2f2SEnji Cooper
39*28f6c2f2SEnji Cooper #include "gtest/gtest-message.h"
40*28f6c2f2SEnji Cooper
41*28f6c2f2SEnji Cooper namespace testing {
42*28f6c2f2SEnji Cooper
43*28f6c2f2SEnji Cooper // AssertionResult constructors.
44*28f6c2f2SEnji Cooper // Used in EXPECT_TRUE/FALSE(assertion_result).
AssertionResult(const AssertionResult & other)45*28f6c2f2SEnji Cooper AssertionResult::AssertionResult(const AssertionResult& other)
46*28f6c2f2SEnji Cooper : success_(other.success_),
47*28f6c2f2SEnji Cooper message_(other.message_ != nullptr
48*28f6c2f2SEnji Cooper ? new ::std::string(*other.message_)
49*28f6c2f2SEnji Cooper : static_cast< ::std::string*>(nullptr)) {}
50*28f6c2f2SEnji Cooper
51*28f6c2f2SEnji Cooper // Swaps two AssertionResults.
swap(AssertionResult & other)52*28f6c2f2SEnji Cooper void AssertionResult::swap(AssertionResult& other) {
53*28f6c2f2SEnji Cooper using std::swap;
54*28f6c2f2SEnji Cooper swap(success_, other.success_);
55*28f6c2f2SEnji Cooper swap(message_, other.message_);
56*28f6c2f2SEnji Cooper }
57*28f6c2f2SEnji Cooper
58*28f6c2f2SEnji Cooper // Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE.
operator !() const59*28f6c2f2SEnji Cooper AssertionResult AssertionResult::operator!() const {
60*28f6c2f2SEnji Cooper AssertionResult negation(!success_);
61*28f6c2f2SEnji Cooper if (message_ != nullptr) negation << *message_;
62*28f6c2f2SEnji Cooper return negation;
63*28f6c2f2SEnji Cooper }
64*28f6c2f2SEnji Cooper
65*28f6c2f2SEnji Cooper // Makes a successful assertion result.
AssertionSuccess()66*28f6c2f2SEnji Cooper AssertionResult AssertionSuccess() { return AssertionResult(true); }
67*28f6c2f2SEnji Cooper
68*28f6c2f2SEnji Cooper // Makes a failed assertion result.
AssertionFailure()69*28f6c2f2SEnji Cooper AssertionResult AssertionFailure() { return AssertionResult(false); }
70*28f6c2f2SEnji Cooper
71*28f6c2f2SEnji Cooper // Makes a failed assertion result with the given failure message.
72*28f6c2f2SEnji Cooper // Deprecated; use AssertionFailure() << message.
AssertionFailure(const Message & message)73*28f6c2f2SEnji Cooper AssertionResult AssertionFailure(const Message& message) {
74*28f6c2f2SEnji Cooper return AssertionFailure() << message;
75*28f6c2f2SEnji Cooper }
76*28f6c2f2SEnji Cooper
77*28f6c2f2SEnji Cooper } // namespace testing
78