Path: blob/master/dep/googletest/src/gtest-assertion-result.cc
4804 views
// Copyright 2005, 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// The Google C++ Testing and Mocking Framework (Google Test)30//31// This file defines the AssertionResult type.3233#include "gtest/gtest-assertion-result.h"3435#include <string>36#include <utility>3738#include "gtest/gtest-message.h"3940namespace testing {4142// AssertionResult constructors.43// Used in EXPECT_TRUE/FALSE(assertion_result).44AssertionResult::AssertionResult(const AssertionResult& other)45: success_(other.success_),46message_(other.message_ != nullptr47? new ::std::string(*other.message_)48: static_cast< ::std::string*>(nullptr)) {}4950// Swaps two AssertionResults.51void AssertionResult::swap(AssertionResult& other) {52using std::swap;53swap(success_, other.success_);54swap(message_, other.message_);55}5657// Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE.58AssertionResult AssertionResult::operator!() const {59AssertionResult negation(!success_);60if (message_ != nullptr) negation << *message_;61return negation;62}6364// Makes a successful assertion result.65AssertionResult AssertionSuccess() { return AssertionResult(true); }6667// Makes a failed assertion result.68AssertionResult AssertionFailure() { return AssertionResult(false); }6970// Makes a failed assertion result with the given failure message.71// Deprecated; use AssertionFailure() << message.72AssertionResult AssertionFailure(const Message& message) {73return AssertionFailure() << message;74}7576} // namespace testing777879