Googletest export
Merge CONTRIBUTORS, delete LICENSEs in googletest/ and googlemock/ PiperOrigin-RevId: 352558822
This commit is contained in:
@@ -1,40 +0,0 @@
|
||||
# This file contains a list of people who've made non-trivial
|
||||
# contribution to the Google C++ Mocking Framework project. People
|
||||
# who commit code to the project are encouraged to add their names
|
||||
# here. Please keep the list sorted by first names.
|
||||
|
||||
Benoit Sigoure <tsuna@google.com>
|
||||
Bogdan Piloca <boo@google.com>
|
||||
Chandler Carruth <chandlerc@google.com>
|
||||
Dave MacLachlan <dmaclach@gmail.com>
|
||||
David Anderson <danderson@google.com>
|
||||
Dean Sturtevant
|
||||
Gene Volovich <gv@cite.com>
|
||||
Hal Burch <gmock@hburch.com>
|
||||
Jeffrey Yasskin <jyasskin@google.com>
|
||||
Jim Keller <jimkeller@google.com>
|
||||
Joe Walnes <joe@truemesh.com>
|
||||
Jon Wray <jwray@google.com>
|
||||
Keir Mierle <mierle@gmail.com>
|
||||
Keith Ray <keith.ray@gmail.com>
|
||||
Kostya Serebryany <kcc@google.com>
|
||||
Lev Makhlis
|
||||
Manuel Klimek <klimek@google.com>
|
||||
Mario Tanev <radix@google.com>
|
||||
Mark Paskin
|
||||
Markus Heule <markus.heule@gmail.com>
|
||||
Matthew Simmons <simmonmt@acm.org>
|
||||
Mike Bland <mbland@google.com>
|
||||
Neal Norwitz <nnorwitz@gmail.com>
|
||||
Nermin Ozkiranartli <nermin@google.com>
|
||||
Owen Carlsen <ocarlsen@google.com>
|
||||
Paneendra Ba <paneendra@google.com>
|
||||
Paul Menage <menage@google.com>
|
||||
Piotr Kaminski <piotrk@google.com>
|
||||
Russ Rufer <russ@pentad.com>
|
||||
Sverre Sundsdal <sundsdal@gmail.com>
|
||||
Takeshi Yoshino <tyoshino@google.com>
|
||||
Vadim Berman <vadimb@google.com>
|
||||
Vlad Losev <vladl@google.com>
|
||||
Wolfgang Klier <wklier@google.com>
|
||||
Zhanyong Wan <wan@google.com>
|
||||
@@ -1,28 +0,0 @@
|
||||
Copyright 2008, Google Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
@@ -40,8 +40,8 @@ $$}} This meta comment fixes auto-indentation in editors.
|
||||
|
||||
// GOOGLETEST_CM0002 DO NOT DELETE
|
||||
|
||||
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
|
||||
#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
|
||||
#ifndef THIRD_PARTY_GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
|
||||
#define THIRD_PARTY_GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
@@ -387,4 +387,4 @@ InvokeArgument(Params&&... params) {
|
||||
|
||||
} // namespace testing
|
||||
|
||||
#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
|
||||
#endif // THIRD_PARTY_GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
|
||||
|
||||
@@ -1,10 +1,149 @@
|
||||
// This file was GENERATED by command:
|
||||
// pump.py gmock-generated-actions.h.pump
|
||||
// DO NOT EDIT BY HAND!!!
|
||||
|
||||
// GOOGLETEST_CM0002 DO NOT DELETE
|
||||
|
||||
#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
|
||||
#define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
|
||||
|
||||
#include "gmock/internal/gmock-port.h"
|
||||
#if GTEST_GOOGLE3_MODE_
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
#include "base/callback.h"
|
||||
#include "gmock/gmock-actions.h"
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
||||
// Implements the Invoke(callback) action.
|
||||
template <typename CallbackType, typename Signature>
|
||||
class InvokeCallbackAction;
|
||||
|
||||
template <typename CallbackType, typename R, typename... Args>
|
||||
class InvokeCallbackAction<CallbackType, R(Args...)> {
|
||||
public:
|
||||
// The c'tor takes ownership of the callback.
|
||||
explicit InvokeCallbackAction(CallbackType* callback) : callback_(callback) {
|
||||
callback->CheckIsRepeatable(); // Makes sure the callback is permanent.
|
||||
}
|
||||
|
||||
R operator()(Args... args) const {
|
||||
return callback_->Run(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
private:
|
||||
const std::shared_ptr<CallbackType> callback_;
|
||||
};
|
||||
|
||||
// Implements the InvokeWithoutArgs(callback) action.
|
||||
template <typename CallbackType>
|
||||
class InvokeCallbackWithoutArgsAction {
|
||||
const std::shared_ptr<CallbackType> callback_;
|
||||
|
||||
public:
|
||||
// The c'tor takes ownership of the callback.
|
||||
explicit InvokeCallbackWithoutArgsAction(CallbackType* callback)
|
||||
: callback_(callback) {
|
||||
callback->CheckIsRepeatable(); // Makes sure the callback is permanent.
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
auto operator()(const Args&...) -> decltype(this->callback_->Run()) {
|
||||
return callback_->Run();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct TypeIdentity {
|
||||
using type = T;
|
||||
};
|
||||
|
||||
inline TypeIdentity<void()> CallbackSignatureImpl(Closure*);
|
||||
template <typename R>
|
||||
TypeIdentity<R()> CallbackSignatureImpl(ResultCallback<R>*);
|
||||
|
||||
template <typename... Args>
|
||||
TypeIdentity<void(Args...)> CallbackSignatureImpl(Callback1<Args...>*);
|
||||
template <typename R, typename... Args>
|
||||
TypeIdentity<R(Args...)> CallbackSignatureImpl(ResultCallback1<R, Args...>*);
|
||||
|
||||
template <typename... Args>
|
||||
TypeIdentity<void(Args...)> CallbackSignatureImpl(Callback2<Args...>*);
|
||||
template <typename R, typename... Args>
|
||||
TypeIdentity<R(Args...)> CallbackSignatureImpl(ResultCallback2<R, Args...>*);
|
||||
|
||||
template <typename... Args>
|
||||
TypeIdentity<void(Args...)> CallbackSignatureImpl(Callback3<Args...>*);
|
||||
template <typename R, typename... Args>
|
||||
TypeIdentity<R(Args...)> CallbackSignatureImpl(ResultCallback3<R, Args...>*);
|
||||
|
||||
template <typename... Args>
|
||||
TypeIdentity<void(Args...)> CallbackSignatureImpl(Callback4<Args...>*);
|
||||
template <typename R, typename... Args>
|
||||
TypeIdentity<R(Args...)> CallbackSignatureImpl(ResultCallback4<R, Args...>*);
|
||||
|
||||
template <typename... Args>
|
||||
TypeIdentity<void(Args...)> CallbackSignatureImpl(Callback5<Args...>*);
|
||||
template <typename R, typename... Args>
|
||||
TypeIdentity<R(Args...)> CallbackSignatureImpl(ResultCallback5<R, Args...>*);
|
||||
|
||||
template <typename T>
|
||||
using CallbackSignature = typename decltype(
|
||||
internal::CallbackSignatureImpl(std::declval<T*>()))::type;
|
||||
|
||||
// Specialization for protocol buffers.
|
||||
// We support setting a proto2::Message, which doesn't have an assignment
|
||||
// operator.
|
||||
template <size_t N, typename A>
|
||||
struct SetArgumentPointeeAction<
|
||||
N, A,
|
||||
typename std::enable_if<std::is_base_of<proto2::Message, A>::value>::type> {
|
||||
A value;
|
||||
|
||||
template <typename... Args>
|
||||
void operator()(const Args&... args) const {
|
||||
::std::get<N>(std::tie(args...))->CopyFrom(value);
|
||||
}
|
||||
};
|
||||
|
||||
// Add Invoke overloads for google3 Callback types.
|
||||
|
||||
template <typename C, typename... Args,
|
||||
typename = internal::CallbackSignature<C>>
|
||||
auto InvokeArgument(C* cb, Args... args) -> decltype(cb->Run(args...)) {
|
||||
return cb->Run(args...);
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// Add Invoke overloads for google3 Callback types.
|
||||
|
||||
// Creates an action that invokes the given callback with the mock
|
||||
// function's arguments. The action takes ownership of the callback
|
||||
// and verifies that it's permanent.
|
||||
//
|
||||
// google3 doesn't support callbacks with more than 5
|
||||
// arguments yet, so we only support invoking callbacks with up to
|
||||
// 5 arguments.
|
||||
|
||||
template <typename Callback>
|
||||
internal::InvokeCallbackAction<Callback, internal::CallbackSignature<Callback>>
|
||||
Invoke(Callback* callback) {
|
||||
return internal::InvokeCallbackAction<Callback,
|
||||
internal::CallbackSignature<Callback>>(
|
||||
callback);
|
||||
}
|
||||
|
||||
// Creates an action that invokes the given callback with no argument.
|
||||
// The action takes ownership of the callback and verifies that it's
|
||||
// permanent.
|
||||
template <typename Callback, typename = internal::CallbackSignature<Callback>>
|
||||
internal::InvokeCallbackWithoutArgsAction<Callback> InvokeWithoutArgs(
|
||||
Callback* callback) {
|
||||
return internal::InvokeCallbackWithoutArgsAction<Callback>(callback);
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
|
||||
#endif // GTEST_GOOGLE3_MODE_
|
||||
|
||||
#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
$$ -*- mode: c++; -*-
|
||||
$$ This is a Pump source file. Please use Pump to convert
|
||||
$$ it to callback-actions.h.
|
||||
$$
|
||||
$var max_callback_arity = 5
|
||||
$$}} This meta comment fixes auto-indentation in editors.
|
||||
|
||||
// GOOGLETEST_CM0002 DO NOT DELETE
|
||||
#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
|
||||
#define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
|
||||
|
||||
#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
|
||||
@@ -33,4 +33,39 @@
|
||||
|
||||
#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_
|
||||
#define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "gmock/internal/gmock-port.h"
|
||||
#if GTEST_GOOGLE3_MODE_
|
||||
#include "base/callback.h"
|
||||
|
||||
// Realistically this file should be included from gmock-matchers.h
|
||||
#include "gmock/gmock-matchers.h"
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
||||
// Specialization for permanent callbacks.
|
||||
template <typename ArgType, typename ResType>
|
||||
struct CallableTraits<ResultCallback1<ResType, ArgType>*> {
|
||||
typedef ResType ResultType;
|
||||
using StorageType = std::shared_ptr<ResultCallback1<ResType, ArgType>>;
|
||||
typedef ResultCallback1<ResType, ArgType> Callback;
|
||||
|
||||
static void CheckIsValid(const StorageType& callback) {
|
||||
GTEST_CHECK_(callback != nullptr)
|
||||
<< "NULL callback is passed into ResultOf().";
|
||||
callback->CheckIsRepeatable();
|
||||
}
|
||||
template <typename T>
|
||||
static ResType Invoke(const StorageType& callback, T arg) {
|
||||
return callback->Run(arg);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
#endif // GTEST_GOOGLE3_MODE_
|
||||
|
||||
#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_
|
||||
|
||||
@@ -36,4 +36,29 @@
|
||||
#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_
|
||||
#define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_
|
||||
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
#if GTEST_GOOGLE3_MODE_
|
||||
|
||||
// Defines this iff Google Mock can use google3 callbacks. This is
|
||||
// internal as a user shouldn't rely on Google Mock to tell him
|
||||
// whether he can use google3 callbacks.
|
||||
# include "base/callback.h"
|
||||
# define GMOCK_HAS_GOOGLE3_CALLBACK_ 1
|
||||
|
||||
// Macros for declaring flags.
|
||||
# define GMOCK_DECLARE_bool_(name) DECLARE_bool(gmock_##name)
|
||||
# define GMOCK_DECLARE_int32_(name) DECLARE_int32(gmock_##name)
|
||||
# define GMOCK_DECLARE_string_(name) DECLARE_string(gmock_##name)
|
||||
|
||||
// Macros for defining flags.
|
||||
# define GMOCK_DEFINE_bool_(name, default_val, doc) \
|
||||
DEFINE_bool(gmock_##name, default_val, doc)
|
||||
# define GMOCK_DEFINE_int32_(name, default_val, doc) \
|
||||
DEFINE_int32(gmock_##name, default_val, doc)
|
||||
# define GMOCK_DEFINE_string_(name, default_val, doc) \
|
||||
DEFINE_string(gmock_##name, default_val, doc)
|
||||
|
||||
#endif // GTEST_GOOGLE3_MODE_
|
||||
|
||||
#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_
|
||||
|
||||
170
googlemock/test/gmock-generated-actions_nc.cc
Normal file
170
googlemock/test/gmock-generated-actions_nc.cc
Normal file
@@ -0,0 +1,170 @@
|
||||
// Copyright 2008, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
// Google Mock - a framework for writing C++ mock classes.
|
||||
//
|
||||
// This file contains negative compilation tests for script-generated
|
||||
// Google Mock actions.
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
using testing::Action;
|
||||
using testing::Invoke;
|
||||
using testing::WithArgs;
|
||||
|
||||
int Nullary() { return 0; }
|
||||
int Binary(int a, int b) { return a + b; }
|
||||
|
||||
#if defined(TEST_NULLARY_WITH_ARGS)
|
||||
|
||||
// Tests that WithArgs(action) doesn't compile.
|
||||
void Test() {
|
||||
Action<int(int)> a = WithArgs(Invoke(Nullary));
|
||||
}
|
||||
|
||||
#elif defined(TEST_TOO_FEW_ARGS_FOR_WITH_ARGS)
|
||||
|
||||
// Tests that you cannot pass too few arguments to the inner action in
|
||||
// WithArgs().
|
||||
void Test() {
|
||||
Action<int(int, int, int)> a = WithArgs<1>(Invoke(Binary));
|
||||
}
|
||||
|
||||
#elif defined(TEST_TOO_MANY_ARGS_FOR_WITH_ARGS)
|
||||
|
||||
// Tests that you cannot pass too many arguments to the inner action in
|
||||
// WithArgs().
|
||||
void Test() {
|
||||
Action<int(int, int, int)> a = WithArgs<1, 2, 0>(Invoke(Binary));
|
||||
}
|
||||
|
||||
#elif defined(TEST_INCOMPATIBLE_ARG_TYPES_FOR_WITH_ARGS)
|
||||
|
||||
// Tests that you cannot pass arguments of incompatible types to the
|
||||
// inner action in WithArgs().
|
||||
void Test() {
|
||||
Action<int(int, const char*, int)> a = WithArgs<1, 2>(Invoke(Binary));
|
||||
}
|
||||
|
||||
#elif defined(TEST_WRONG_ARG_TYPE_IN_ACTION_MACRO)
|
||||
|
||||
// Tests using an ACTION definition in a mock function whose argument
|
||||
// types are incompatible.
|
||||
ACTION(WrongArgType) { return 10/arg0; }
|
||||
|
||||
void Test() {
|
||||
Action<int(const char*)> a = WrongArgType();
|
||||
}
|
||||
|
||||
#elif defined(TEST_WRONG_RETURN_TYPE_IN_ACTION_MACRO)
|
||||
|
||||
// Tests using an ACTION definition in a mock function whose return
|
||||
// types is incompatible.
|
||||
ACTION(WrongReturnType) { return 10; }
|
||||
|
||||
void Test() {
|
||||
Action<const char*()> a = WrongReturnType();
|
||||
}
|
||||
|
||||
#elif defined(TEST_EXCESSIVE_ARG_IN_ACTION_MACRO)
|
||||
|
||||
// Tests using an ACTION definition in a mock function that doesn't
|
||||
// provide enough arguments.
|
||||
ACTION(UseExcessiveArg) { return arg0 + arg1; }
|
||||
|
||||
void Test() {
|
||||
Action<int(int)> a = UseExcessiveArg();
|
||||
}
|
||||
|
||||
#elif defined(TEST_ACTION_MACRO_IN_CLASS)
|
||||
|
||||
// Tests using ACTION in a class scope.
|
||||
class Foo {
|
||||
public:
|
||||
// This won't compile as C++ doesn't allow defining a method of a
|
||||
// nested class out-of-line in the enclosing class.
|
||||
ACTION(Bar) { return arg0; }
|
||||
};
|
||||
|
||||
#elif defined(TEST_ACTION_MACRO_IN_FUNCTION)
|
||||
|
||||
// Tests using ACTION in a function body.
|
||||
void Test() {
|
||||
// This won't compile as C++ doesn't allow member templates in local
|
||||
// classes. We may want to revisit this when C++0x is widely
|
||||
// implemented.
|
||||
ACTION(Bar) { return arg0; }
|
||||
}
|
||||
|
||||
#elif defined(TEST_SET_ARG_REFEREE_MUST_BE_USED_WITH_REFERENCE)
|
||||
|
||||
// Verifies that using SetArgReferee<k>(...) where the k-th argument
|
||||
// of the mock function is not a reference generates a compiler error.
|
||||
void Test() {
|
||||
Action<void(bool, int)> a = testing::SetArgReferee<1>(5);
|
||||
}
|
||||
|
||||
#elif defined(TEST_DELETE_ARG_MUST_BE_USED_WITH_POINTER)
|
||||
|
||||
// Verifies that using DeleteArg<k>(...) where the k-th argument of the mock
|
||||
// function is not a pointer generates a compiler error.
|
||||
void Test() {
|
||||
Action<void(int)> a = testing::DeleteArg<0>(); // NOLINT
|
||||
}
|
||||
|
||||
#elif defined(TEST_CANNOT_OVERLOAD_ACTION_TEMPLATE_ON_TEMPLATE_PARAM_NUMBER)
|
||||
|
||||
// Tests that ACTION_TEMPLATE cannot be overloaded on the number of
|
||||
// template parameters alone.
|
||||
|
||||
ACTION_TEMPLATE(OverloadedAction,
|
||||
HAS_1_TEMPLATE_PARAMS(typename, T),
|
||||
AND_1_VALUE_PARAMS(p)) {}
|
||||
|
||||
ACTION_TEMPLATE(OverloadedAction,
|
||||
HAS_2_TEMPLATE_PARAMS(typename, T1, typename, T2),
|
||||
AND_1_VALUE_PARAMS(p)) {}
|
||||
|
||||
#elif defined(TEST_CANNOT_OVERLOAD_ACTION_AND_ACTION_TEMPLATE_W_SAME_VALUE_PS)
|
||||
|
||||
// Tests that ACTION_TEMPLATE and ACTION_P cannot be overloaded when
|
||||
// they have the same number of value parameters.
|
||||
|
||||
ACTION_P(OverloadedAction, p) {}
|
||||
|
||||
ACTION_TEMPLATE(OverloadedAction,
|
||||
HAS_1_TEMPLATE_PARAMS(typename, T),
|
||||
AND_1_VALUE_PARAMS(p)) {}
|
||||
|
||||
#else
|
||||
|
||||
// Sanity check - this should compile.
|
||||
|
||||
#endif
|
||||
137
googlemock/test/gmock_generated_actions_nc_test.py
Executable file
137
googlemock/test/gmock_generated_actions_nc_test.py
Executable file
@@ -0,0 +1,137 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2008, Google Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Google Inc. nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
# Google Mock - a framework for writing C++ mock classes.
|
||||
#
|
||||
# This file drives the negative compilation tests for script-generated
|
||||
# Google Mock actions.
|
||||
|
||||
"""Driver for the NC tests for script-generated Google Mock actions."""
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
IS_LINUX = os.name == "posix" and os.uname()[0] == "Linux"
|
||||
if not IS_LINUX:
|
||||
sys.stderr.write(
|
||||
"WARNING: Negative compilation tests are not supported on this platform")
|
||||
sys.exit(0)
|
||||
|
||||
# Suppresses the 'Import not at the top of the file' lint complaint.
|
||||
# pylint: disable-msg=C6204
|
||||
from google3.testing.pybase import fake_target_util
|
||||
from google3.testing.pybase import googletest
|
||||
# pylint: enable-msg=C6204
|
||||
|
||||
|
||||
class GMockGeneratedActionTest(googletest.TestCase):
|
||||
"""Negative compilation tests for generated Google Mock actions."""
|
||||
|
||||
# The class body is intentionally empty. The actual test*() methods
|
||||
# will be defined at run time by a call to
|
||||
# DefineNegativeCompilationTests() later.
|
||||
pass
|
||||
|
||||
# Defines a list of test specs, where each element is a tuple
|
||||
# (test name, list of regexes for matching the compiler errors).
|
||||
TEST_SPECS = [
|
||||
("NULLARY_WITH_ARGS", [
|
||||
r"no matching function for call to 'WithArgs",
|
||||
]),
|
||||
("TOO_FEW_ARGS_FOR_WITH_ARGS", [
|
||||
r"no known conversion",
|
||||
]),
|
||||
("TOO_MANY_ARGS_FOR_WITH_ARGS", [
|
||||
r"no known conversion",
|
||||
]),
|
||||
("INCOMPATIBLE_ARG_TYPES_FOR_WITH_ARGS", [
|
||||
r"no known conversion",
|
||||
]),
|
||||
("WRONG_ARG_TYPE_IN_ACTION_MACRO", [
|
||||
r"invalid operands",
|
||||
]),
|
||||
(
|
||||
"WRONG_RETURN_TYPE_IN_ACTION_MACRO",
|
||||
[
|
||||
r"invalid conversion", # GCC
|
||||
r"cannot initialize return object", # Clang
|
||||
]),
|
||||
(
|
||||
"EXCESSIVE_ARG_IN_ACTION_MACRO",
|
||||
[
|
||||
r"no match for 'operator\+'", # GCC
|
||||
r"invalid operands to binary expression", # Clang
|
||||
]),
|
||||
(
|
||||
"ACTION_MACRO_IN_CLASS",
|
||||
[
|
||||
r"cannot define member function.*Bar.*within.*Foo", # GCC
|
||||
r"ACTION\(Bar\)", # Clang
|
||||
]),
|
||||
(
|
||||
"ACTION_MACRO_IN_FUNCTION",
|
||||
[
|
||||
r"invalid declaration of member template in local class", # GCC
|
||||
r"templates cannot be declared inside of a local class", # Clang
|
||||
]),
|
||||
("SET_ARG_REFEREE_MUST_BE_USED_WITH_REFERENCE",
|
||||
[r"Argument must be a reference type"]),
|
||||
(
|
||||
"DELETE_ARG_MUST_BE_USED_WITH_POINTER",
|
||||
[
|
||||
r"argument given to 'delete', expected pointer", # GCC
|
||||
r"cannot delete expression of type", # Clang
|
||||
]),
|
||||
(
|
||||
"CANNOT_OVERLOAD_ACTION_TEMPLATE_ON_TEMPLATE_PARAM_NUMBER",
|
||||
[
|
||||
r"wrong number of template arguments", # GCC
|
||||
r"too many template parameters", # Clang
|
||||
]),
|
||||
(
|
||||
"CANNOT_OVERLOAD_ACTION_AND_ACTION_TEMPLATE_W_SAME_VALUE_PS",
|
||||
[
|
||||
r"wrong number of template arguments", # GCC
|
||||
r"too many template parameters", # Clang
|
||||
]),
|
||||
("SANITY", None),
|
||||
]
|
||||
|
||||
# Define a test method in GMockGeneratedActionTest for each element in
|
||||
# TEST_SPECS.
|
||||
fake_target_util.DefineNegativeCompilationTests(
|
||||
GMockGeneratedActionTest,
|
||||
"google3/third_party/googletest/googlemock/test/gmock-generated-actions_nc", # fake target
|
||||
"gmock-generated-actions_nc.o", # object file
|
||||
TEST_SPECS)
|
||||
|
||||
if __name__ == "__main__":
|
||||
googletest.main()
|
||||
Reference in New Issue
Block a user