Merge branch 'chore/fix_library_json' of https://github.com/ciband/googletest into chore/fix_library_json
This commit is contained in:
commit
fd1c7976ae
@ -1,9 +1,13 @@
|
||||
|
||||
# Google Test #
|
||||
|
||||
[![Build Status](https://api.travis-ci.org/abseil/googletest.svg?branch=master)](https://travis-ci.org/abseil/googletest)
|
||||
[![Build Status](https://api.travis-ci.org/google/googletest.svg?branch=master)](https://travis-ci.org/google/googletest)
|
||||
[![Build status](https://ci.appveyor.com/api/projects/status/4o38plt0xbo1ubc8/branch/master?svg=true)](https://ci.appveyor.com/project/GoogleTestAppVeyor/googletest/branch/master)
|
||||
|
||||
**PR FREEZE COMING SOON**
|
||||
|
||||
We are working on a large refactoring that would make it hard to accept external PRs. *Really Soon Now* we will not be accepting new PRs until the refactoring has been completed.
|
||||
|
||||
**Future Plans**:
|
||||
* 1.8.x Release - [the 1.8.x](https://github.com/google/googletest/releases/tag/release-1.8.1) is the last release that works with pre-C++11 compilers. The 1.8.x will not accept any requests for any new features and any bugfix requests will only be accepted if proven "critical"
|
||||
* Post 1.8.x - work to improve/cleanup/pay technical debt. When this work is completed there will be a 1.9.x tagged release
|
||||
|
@ -32,10 +32,10 @@ pkginclude_HEADERS = \
|
||||
include/gmock/gmock-generated-actions.h \
|
||||
include/gmock/gmock-generated-function-mockers.h \
|
||||
include/gmock/gmock-generated-matchers.h \
|
||||
include/gmock/gmock-generated-nice-strict.h \
|
||||
include/gmock/gmock-matchers.h \
|
||||
include/gmock/gmock-more-actions.h \
|
||||
include/gmock/gmock-more-matchers.h \
|
||||
include/gmock/gmock-nice-strict.h \
|
||||
include/gmock/gmock-spec-builders.h \
|
||||
include/gmock/gmock.h
|
||||
|
||||
@ -141,7 +141,6 @@ EXTRA_DIST += \
|
||||
include/gmock/gmock-generated-actions.h.pump \
|
||||
include/gmock/gmock-generated-function-mockers.h.pump \
|
||||
include/gmock/gmock-generated-matchers.h.pump \
|
||||
include/gmock/gmock-generated-nice-strict.h.pump \
|
||||
include/gmock/internal/gmock-generated-internal-utils.h.pump \
|
||||
include/gmock/internal/custom/gmock-generated-actions.h.pump
|
||||
|
||||
|
@ -42,18 +42,15 @@
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#include "gmock/internal/gmock-internal-utils.h"
|
||||
#include "gmock/internal/gmock-port.h"
|
||||
|
||||
#if GTEST_LANG_CXX11 // Defined by gtest-port.h via gmock-port.h.
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:4100)
|
||||
@ -72,9 +69,6 @@ namespace testing {
|
||||
|
||||
namespace internal {
|
||||
|
||||
template <typename F1, typename F2>
|
||||
class ActionAdaptor;
|
||||
|
||||
// BuiltInDefaultValueGetter<T, true>::Get() returns a
|
||||
// default-constructed T value. BuiltInDefaultValueGetter<T,
|
||||
// false>::Get() crashes with an error.
|
||||
@ -105,7 +99,6 @@ struct BuiltInDefaultValueGetter<T, false> {
|
||||
template <typename T>
|
||||
class BuiltInDefaultValue {
|
||||
public:
|
||||
#if GTEST_LANG_CXX11
|
||||
// This function returns true iff type T has a built-in default value.
|
||||
static bool Exists() {
|
||||
return ::std::is_default_constructible<T>::value;
|
||||
@ -115,18 +108,6 @@ class BuiltInDefaultValue {
|
||||
return BuiltInDefaultValueGetter<
|
||||
T, ::std::is_default_constructible<T>::value>::Get();
|
||||
}
|
||||
|
||||
#else // GTEST_LANG_CXX11
|
||||
// This function returns true iff type T has a built-in default value.
|
||||
static bool Exists() {
|
||||
return false;
|
||||
}
|
||||
|
||||
static T Get() {
|
||||
return BuiltInDefaultValueGetter<T, false>::Get();
|
||||
}
|
||||
|
||||
#endif // GTEST_LANG_CXX11
|
||||
};
|
||||
|
||||
// This partial specialization says that we use the same built-in
|
||||
@ -358,6 +339,19 @@ class ActionInterface {
|
||||
// object as a handle to it.
|
||||
template <typename F>
|
||||
class Action {
|
||||
// Adapter class to allow constructing Action from a legacy ActionInterface.
|
||||
// New code should create Actions from functors instead.
|
||||
struct ActionAdapter {
|
||||
// Adapter must be copyable to satisfy std::function requirements.
|
||||
::std::shared_ptr<ActionInterface<F>> impl_;
|
||||
|
||||
template <typename... Args>
|
||||
typename internal::Function<F>::Result operator()(Args&&... args) {
|
||||
return impl_->Perform(
|
||||
::std::forward_as_tuple(::std::forward<Args>(args)...));
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
typedef typename internal::Function<F>::Result Result;
|
||||
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
|
||||
@ -366,7 +360,6 @@ class Action {
|
||||
// STL containers.
|
||||
Action() {}
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
// Construct an Action from a specified callable.
|
||||
// This cannot take std::function directly, because then Action would not be
|
||||
// directly constructible from lambda (it would require two conversions).
|
||||
@ -374,26 +367,19 @@ class Action {
|
||||
typename = typename ::std::enable_if<
|
||||
::std::is_constructible<::std::function<F>, G>::value>::type>
|
||||
Action(G&& fun) : fun_(::std::forward<G>(fun)) {} // NOLINT
|
||||
#endif
|
||||
|
||||
// Constructs an Action from its implementation.
|
||||
explicit Action(ActionInterface<F>* impl) : impl_(impl) {}
|
||||
explicit Action(ActionInterface<F>* impl)
|
||||
: fun_(ActionAdapter{::std::shared_ptr<ActionInterface<F>>(impl)}) {}
|
||||
|
||||
// This constructor allows us to turn an Action<Func> object into an
|
||||
// Action<F>, as long as F's arguments can be implicitly converted
|
||||
// to Func's and Func's return type can be implicitly converted to
|
||||
// F's.
|
||||
// to Func's and Func's return type can be implicitly converted to F's.
|
||||
template <typename Func>
|
||||
explicit Action(const Action<Func>& action);
|
||||
explicit Action(const Action<Func>& action) : fun_(action.fun_) {}
|
||||
|
||||
// Returns true iff this is the DoDefault() action.
|
||||
bool IsDoDefault() const {
|
||||
#if GTEST_LANG_CXX11
|
||||
return impl_ == nullptr && fun_ == nullptr;
|
||||
#else
|
||||
return impl_ == NULL;
|
||||
#endif
|
||||
}
|
||||
bool IsDoDefault() const { return fun_ == nullptr; }
|
||||
|
||||
// Performs the action. Note that this method is const even though
|
||||
// the corresponding method in ActionInterface is not. The reason
|
||||
@ -405,31 +391,15 @@ class Action {
|
||||
if (IsDoDefault()) {
|
||||
internal::IllegalDoDefault(__FILE__, __LINE__);
|
||||
}
|
||||
#if GTEST_LANG_CXX11
|
||||
if (fun_ != nullptr) {
|
||||
return internal::Apply(fun_, ::std::move(args));
|
||||
}
|
||||
#endif
|
||||
return impl_->Perform(args);
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename F1, typename F2>
|
||||
friend class internal::ActionAdaptor;
|
||||
|
||||
template <typename G>
|
||||
friend class Action;
|
||||
|
||||
// In C++11, Action can be implemented either as a generic functor (through
|
||||
// std::function), or legacy ActionInterface. In C++98, only ActionInterface
|
||||
// is available. The invariants are as follows:
|
||||
// * in C++98, impl_ is null iff this is the default action
|
||||
// * in C++11, at most one of fun_ & impl_ may be nonnull; both are null iff
|
||||
// this is the default action
|
||||
#if GTEST_LANG_CXX11
|
||||
// fun_ is an empty function iff this is the DoDefault() action.
|
||||
::std::function<F> fun_;
|
||||
#endif
|
||||
std::shared_ptr<ActionInterface<F>> impl_;
|
||||
};
|
||||
|
||||
// The PolymorphicAction class template makes it easy to implement a
|
||||
@ -508,26 +478,6 @@ inline PolymorphicAction<Impl> MakePolymorphicAction(const Impl& impl) {
|
||||
|
||||
namespace internal {
|
||||
|
||||
// Allows an Action<F2> object to pose as an Action<F1>, as long as F2
|
||||
// and F1 are compatible.
|
||||
template <typename F1, typename F2>
|
||||
class ActionAdaptor : public ActionInterface<F1> {
|
||||
public:
|
||||
typedef typename internal::Function<F1>::Result Result;
|
||||
typedef typename internal::Function<F1>::ArgumentTuple ArgumentTuple;
|
||||
|
||||
explicit ActionAdaptor(const Action<F2>& from) : impl_(from.impl_) {}
|
||||
|
||||
Result Perform(const ArgumentTuple& args) override {
|
||||
return impl_->Perform(args);
|
||||
}
|
||||
|
||||
private:
|
||||
const std::shared_ptr<ActionInterface<F2>> impl_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(ActionAdaptor);
|
||||
};
|
||||
|
||||
// Helper struct to specialize ReturnAction to execute a move instead of a copy
|
||||
// on return. Useful for move-only types, but could be used on any type.
|
||||
template <typename T>
|
||||
@ -574,7 +524,7 @@ class ReturnAction {
|
||||
// This template type conversion operator allows Return(x) to be
|
||||
// used in ANY function that returns x's type.
|
||||
template <typename F>
|
||||
operator Action<F>() const {
|
||||
operator Action<F>() const { // NOLINT
|
||||
// Assert statement belongs here because this is the best place to verify
|
||||
// conditions on F. It produces the clearest error messages
|
||||
// in most compilers.
|
||||
@ -587,6 +537,8 @@ class ReturnAction {
|
||||
GTEST_COMPILE_ASSERT_(
|
||||
!is_reference<Result>::value,
|
||||
use_ReturnRef_instead_of_Return_to_return_a_reference);
|
||||
static_assert(!std::is_void<Result>::value,
|
||||
"Can't use Return() on an action expected to return `void`.");
|
||||
return Action<F>(new Impl<R, F>(value_));
|
||||
}
|
||||
|
||||
@ -660,13 +612,7 @@ class ReturnNullAction {
|
||||
// pointer type on compile time.
|
||||
template <typename Result, typename ArgumentTuple>
|
||||
static Result Perform(const ArgumentTuple&) {
|
||||
#if GTEST_LANG_CXX11
|
||||
return nullptr;
|
||||
#else
|
||||
GTEST_COMPILE_ASSERT_(internal::is_pointer<Result>::value,
|
||||
ReturnNull_can_be_used_to_return_a_pointer_only);
|
||||
return NULL;
|
||||
#endif // GTEST_LANG_CXX11
|
||||
}
|
||||
};
|
||||
|
||||
@ -1017,51 +963,6 @@ void PrintTo(const ReferenceWrapper<T>& ref, ::std::ostream* os) {
|
||||
UniversalPrinter<T&>::Print(value, os);
|
||||
}
|
||||
|
||||
// Does two actions sequentially. Used for implementing the DoAll(a1,
|
||||
// a2, ...) action.
|
||||
template <typename Action1, typename Action2>
|
||||
class DoBothAction {
|
||||
public:
|
||||
DoBothAction(Action1 action1, Action2 action2)
|
||||
: action1_(action1), action2_(action2) {}
|
||||
|
||||
// This template type conversion operator allows DoAll(a1, ..., a_n)
|
||||
// to be used in ANY function of compatible type.
|
||||
template <typename F>
|
||||
operator Action<F>() const {
|
||||
return Action<F>(new Impl<F>(action1_, action2_));
|
||||
}
|
||||
|
||||
private:
|
||||
// Implements the DoAll(...) action for a particular function type F.
|
||||
template <typename F>
|
||||
class Impl : public ActionInterface<F> {
|
||||
public:
|
||||
typedef typename Function<F>::Result Result;
|
||||
typedef typename Function<F>::ArgumentTuple ArgumentTuple;
|
||||
typedef typename Function<F>::MakeResultVoid VoidResult;
|
||||
|
||||
Impl(const Action<VoidResult>& action1, const Action<F>& action2)
|
||||
: action1_(action1), action2_(action2) {}
|
||||
|
||||
Result Perform(const ArgumentTuple& args) override {
|
||||
action1_.Perform(args);
|
||||
return action2_.Perform(args);
|
||||
}
|
||||
|
||||
private:
|
||||
const Action<VoidResult> action1_;
|
||||
const Action<F> action2_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(Impl);
|
||||
};
|
||||
|
||||
Action1 action1_;
|
||||
Action2 action2_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(DoBothAction);
|
||||
};
|
||||
|
||||
template <typename InnerAction, size_t... I>
|
||||
struct WithArgsAction {
|
||||
InnerAction action;
|
||||
@ -1080,6 +981,35 @@ struct WithArgsAction {
|
||||
}
|
||||
};
|
||||
|
||||
template <typename... Actions>
|
||||
struct DoAllAction {
|
||||
private:
|
||||
template <typename... Args, size_t... I>
|
||||
std::vector<Action<void(Args...)>> Convert(IndexSequence<I...>) const {
|
||||
return {std::get<I>(actions)...};
|
||||
}
|
||||
|
||||
public:
|
||||
std::tuple<Actions...> actions;
|
||||
|
||||
template <typename R, typename... Args>
|
||||
operator Action<R(Args...)>() const { // NOLINT
|
||||
struct Op {
|
||||
std::vector<Action<void(Args...)>> converted;
|
||||
Action<R(Args...)> last;
|
||||
R operator()(Args... args) const {
|
||||
auto tuple_args = std::forward_as_tuple(std::forward<Args>(args)...);
|
||||
for (auto& a : converted) {
|
||||
a.Perform(tuple_args);
|
||||
}
|
||||
return last.Perform(tuple_args);
|
||||
}
|
||||
};
|
||||
return Op{Convert<Args...>(MakeIndexSequence<sizeof...(Actions) - 1>()),
|
||||
std::get<sizeof...(Actions) - 1>(actions)};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// An Unused object can be implicitly constructed from ANY value.
|
||||
@ -1114,20 +1044,12 @@ struct WithArgsAction {
|
||||
// EXPECT_CALL(mock, Bar(5, _, _)).WillOnce(Invoke(DistanceToOrigin));
|
||||
typedef internal::IgnoredValue Unused;
|
||||
|
||||
// This constructor allows us to turn an Action<From> object into an
|
||||
// Action<To>, as long as To's arguments can be implicitly converted
|
||||
// to From's and From's return type cann be implicitly converted to
|
||||
// To's.
|
||||
template <typename To>
|
||||
template <typename From>
|
||||
Action<To>::Action(const Action<From>& from)
|
||||
:
|
||||
#if GTEST_LANG_CXX11
|
||||
fun_(from.fun_),
|
||||
#endif
|
||||
impl_(from.impl_ == nullptr
|
||||
? nullptr
|
||||
: new internal::ActionAdaptor<To, From>(from)) {
|
||||
// Creates an action that does actions a1, a2, ..., sequentially in
|
||||
// each invocation.
|
||||
template <typename... Action>
|
||||
internal::DoAllAction<typename std::decay<Action>::type...> DoAll(
|
||||
Action&&... action) {
|
||||
return {std::forward_as_tuple(std::forward<Action>(action)...)};
|
||||
}
|
||||
|
||||
// WithArg<k>(an_action) creates an action that passes the k-th
|
||||
@ -1218,10 +1140,6 @@ SetArgPointee(const T& x) {
|
||||
N, T, internal::IsAProtocolMessage<T>::value>(x));
|
||||
}
|
||||
|
||||
#if !((GTEST_GCC_VER_ && GTEST_GCC_VER_ < 40000) || GTEST_OS_SYMBIAN)
|
||||
// This overload allows SetArgPointee() to accept a string literal.
|
||||
// GCC prior to the version 4.0 and Symbian C++ compiler cannot distinguish
|
||||
// this overload from the templated version and emit a compile error.
|
||||
template <size_t N>
|
||||
PolymorphicAction<
|
||||
internal::SetArgumentPointeeAction<N, const char*, false> >
|
||||
@ -1237,7 +1155,6 @@ SetArgPointee(const wchar_t* p) {
|
||||
return MakePolymorphicAction(internal::SetArgumentPointeeAction<
|
||||
N, const wchar_t*, false>(p));
|
||||
}
|
||||
#endif
|
||||
|
||||
// The following version is DEPRECATED.
|
||||
template <size_t N, typename T>
|
||||
|
@ -474,97 +474,6 @@ class ActionHelper {
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// Creates an action that does actions a1, a2, ..., sequentially in
|
||||
// each invocation.
|
||||
template <typename Action1, typename Action2>
|
||||
inline internal::DoBothAction<Action1, Action2>
|
||||
DoAll(Action1 a1, Action2 a2) {
|
||||
return internal::DoBothAction<Action1, Action2>(a1, a2);
|
||||
}
|
||||
|
||||
template <typename Action1, typename Action2, typename Action3>
|
||||
inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
|
||||
Action3> >
|
||||
DoAll(Action1 a1, Action2 a2, Action3 a3) {
|
||||
return DoAll(a1, DoAll(a2, a3));
|
||||
}
|
||||
|
||||
template <typename Action1, typename Action2, typename Action3,
|
||||
typename Action4>
|
||||
inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
|
||||
internal::DoBothAction<Action3, Action4> > >
|
||||
DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4) {
|
||||
return DoAll(a1, DoAll(a2, a3, a4));
|
||||
}
|
||||
|
||||
template <typename Action1, typename Action2, typename Action3,
|
||||
typename Action4, typename Action5>
|
||||
inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
|
||||
internal::DoBothAction<Action3, internal::DoBothAction<Action4,
|
||||
Action5> > > >
|
||||
DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5) {
|
||||
return DoAll(a1, DoAll(a2, a3, a4, a5));
|
||||
}
|
||||
|
||||
template <typename Action1, typename Action2, typename Action3,
|
||||
typename Action4, typename Action5, typename Action6>
|
||||
inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
|
||||
internal::DoBothAction<Action3, internal::DoBothAction<Action4,
|
||||
internal::DoBothAction<Action5, Action6> > > > >
|
||||
DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6) {
|
||||
return DoAll(a1, DoAll(a2, a3, a4, a5, a6));
|
||||
}
|
||||
|
||||
template <typename Action1, typename Action2, typename Action3,
|
||||
typename Action4, typename Action5, typename Action6, typename Action7>
|
||||
inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
|
||||
internal::DoBothAction<Action3, internal::DoBothAction<Action4,
|
||||
internal::DoBothAction<Action5, internal::DoBothAction<Action6,
|
||||
Action7> > > > > >
|
||||
DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
|
||||
Action7 a7) {
|
||||
return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7));
|
||||
}
|
||||
|
||||
template <typename Action1, typename Action2, typename Action3,
|
||||
typename Action4, typename Action5, typename Action6, typename Action7,
|
||||
typename Action8>
|
||||
inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
|
||||
internal::DoBothAction<Action3, internal::DoBothAction<Action4,
|
||||
internal::DoBothAction<Action5, internal::DoBothAction<Action6,
|
||||
internal::DoBothAction<Action7, Action8> > > > > > >
|
||||
DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
|
||||
Action7 a7, Action8 a8) {
|
||||
return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8));
|
||||
}
|
||||
|
||||
template <typename Action1, typename Action2, typename Action3,
|
||||
typename Action4, typename Action5, typename Action6, typename Action7,
|
||||
typename Action8, typename Action9>
|
||||
inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
|
||||
internal::DoBothAction<Action3, internal::DoBothAction<Action4,
|
||||
internal::DoBothAction<Action5, internal::DoBothAction<Action6,
|
||||
internal::DoBothAction<Action7, internal::DoBothAction<Action8,
|
||||
Action9> > > > > > > >
|
||||
DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
|
||||
Action7 a7, Action8 a8, Action9 a9) {
|
||||
return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8, a9));
|
||||
}
|
||||
|
||||
template <typename Action1, typename Action2, typename Action3,
|
||||
typename Action4, typename Action5, typename Action6, typename Action7,
|
||||
typename Action8, typename Action9, typename Action10>
|
||||
inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
|
||||
internal::DoBothAction<Action3, internal::DoBothAction<Action4,
|
||||
internal::DoBothAction<Action5, internal::DoBothAction<Action6,
|
||||
internal::DoBothAction<Action7, internal::DoBothAction<Action8,
|
||||
internal::DoBothAction<Action9, Action10> > > > > > > > >
|
||||
DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
|
||||
Action7 a7, Action8 a8, Action9 a9, Action10 a10) {
|
||||
return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8, a9, a10));
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
|
||||
// The ACTION* family of macros can be used in a namespace scope to
|
||||
|
@ -165,34 +165,6 @@ $template
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// Creates an action that does actions a1, a2, ..., sequentially in
|
||||
// each invocation.
|
||||
$range i 2..n
|
||||
$for i [[
|
||||
$range j 2..i
|
||||
$var types = [[$for j, [[typename Action$j]]]]
|
||||
$var Aas = [[$for j [[, Action$j a$j]]]]
|
||||
|
||||
template <typename Action1, $types>
|
||||
$range k 1..i-1
|
||||
|
||||
inline $for k [[internal::DoBothAction<Action$k, ]]Action$i$for k [[>]]
|
||||
|
||||
DoAll(Action1 a1$Aas) {
|
||||
$if i==2 [[
|
||||
|
||||
return internal::DoBothAction<Action1, Action2>(a1, a2);
|
||||
]] $else [[
|
||||
$range j2 2..i
|
||||
|
||||
return DoAll(a1, DoAll($for j2, [[a$j2]]));
|
||||
]]
|
||||
|
||||
}
|
||||
|
||||
]]
|
||||
|
||||
} // namespace testing
|
||||
|
||||
// The ACTION* family of macros can be used in a namespace scope to
|
||||
|
@ -41,15 +41,12 @@
|
||||
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
|
||||
#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
|
||||
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
|
||||
#include "gmock/gmock-spec-builders.h"
|
||||
#include "gmock/internal/gmock-internal-utils.h"
|
||||
|
||||
#if GTEST_HAS_STD_FUNCTION_
|
||||
# include <functional>
|
||||
#endif
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
// Removes the given pointer; this is a helper for the expectation setter method
|
||||
|
@ -42,15 +42,12 @@ $var n = 10 $$ The maximum arity we support.
|
||||
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
|
||||
#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
|
||||
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
|
||||
#include "gmock/gmock-spec-builders.h"
|
||||
#include "gmock/internal/gmock-internal-utils.h"
|
||||
|
||||
#if GTEST_HAS_STD_FUNCTION_
|
||||
# include <functional>
|
||||
#endif
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
||||
|
@ -1,459 +0,0 @@
|
||||
// This file was GENERATED by command:
|
||||
// pump.py gmock-generated-nice-strict.h.pump
|
||||
// DO NOT EDIT BY HAND!!!
|
||||
|
||||
// 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.
|
||||
|
||||
|
||||
// Implements class templates NiceMock, NaggyMock, and StrictMock.
|
||||
//
|
||||
// Given a mock class MockFoo that is created using Google Mock,
|
||||
// NiceMock<MockFoo> is a subclass of MockFoo that allows
|
||||
// uninteresting calls (i.e. calls to mock methods that have no
|
||||
// EXPECT_CALL specs), NaggyMock<MockFoo> is a subclass of MockFoo
|
||||
// that prints a warning when an uninteresting call occurs, and
|
||||
// StrictMock<MockFoo> is a subclass of MockFoo that treats all
|
||||
// uninteresting calls as errors.
|
||||
//
|
||||
// Currently a mock is naggy by default, so MockFoo and
|
||||
// NaggyMock<MockFoo> behave like the same. However, we will soon
|
||||
// switch the default behavior of mocks to be nice, as that in general
|
||||
// leads to more maintainable tests. When that happens, MockFoo will
|
||||
// stop behaving like NaggyMock<MockFoo> and start behaving like
|
||||
// NiceMock<MockFoo>.
|
||||
//
|
||||
// NiceMock, NaggyMock, and StrictMock "inherit" the constructors of
|
||||
// their respective base class. Therefore you can write
|
||||
// NiceMock<MockFoo>(5, "a") to construct a nice mock where MockFoo
|
||||
// has a constructor that accepts (int, const char*), for example.
|
||||
//
|
||||
// A known limitation is that NiceMock<MockFoo>, NaggyMock<MockFoo>,
|
||||
// and StrictMock<MockFoo> only works for mock methods defined using
|
||||
// the MOCK_METHOD* family of macros DIRECTLY in the MockFoo class.
|
||||
// If a mock method is defined in a base class of MockFoo, the "nice"
|
||||
// or "strict" modifier may not affect it, depending on the compiler.
|
||||
// In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT
|
||||
// supported.
|
||||
|
||||
// GOOGLETEST_CM0002 DO NOT DELETE
|
||||
|
||||
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
|
||||
#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
|
||||
|
||||
#include "gmock/gmock-spec-builders.h"
|
||||
#include "gmock/internal/gmock-port.h"
|
||||
|
||||
namespace testing {
|
||||
|
||||
template <class MockClass>
|
||||
class NiceMock : public MockClass {
|
||||
public:
|
||||
NiceMock() : MockClass() {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
// Ideally, we would inherit base class's constructors through a using
|
||||
// declaration, which would preserve their visibility. However, many existing
|
||||
// tests rely on the fact that current implementation reexports protected
|
||||
// constructors as public. These tests would need to be cleaned up first.
|
||||
|
||||
// Single argument constructor is special-cased so that it can be
|
||||
// made explicit.
|
||||
template <typename A>
|
||||
explicit NiceMock(A&& arg) : MockClass(std::forward<A>(arg)) {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename... An>
|
||||
NiceMock(A1&& arg1, A2&& arg2, An&&... args)
|
||||
: MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
|
||||
std::forward<An>(args)...) {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
#else
|
||||
// C++98 doesn't have variadic templates, so we have to define one
|
||||
// for each arity.
|
||||
template <typename A1>
|
||||
explicit NiceMock(const A1& a1) : MockClass(a1) {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
template <typename A1, typename A2>
|
||||
NiceMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3>
|
||||
NiceMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4>
|
||||
NiceMock(const A1& a1, const A2& a2, const A3& a3,
|
||||
const A4& a4) : MockClass(a1, a2, a3, a4) {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5>
|
||||
NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6>
|
||||
NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7>
|
||||
NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
|
||||
a6, a7) {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7, typename A8>
|
||||
NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
|
||||
a2, a3, a4, a5, a6, a7, a8) {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7, typename A8, typename A9>
|
||||
NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5, const A6& a6, const A7& a7, const A8& a8,
|
||||
const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7, typename A8, typename A9, typename A10>
|
||||
NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
|
||||
const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
~NiceMock() { // NOLINT
|
||||
::testing::Mock::UnregisterCallReaction(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock);
|
||||
};
|
||||
|
||||
template <class MockClass>
|
||||
class NaggyMock : public MockClass {
|
||||
public:
|
||||
NaggyMock() : MockClass() {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
// Ideally, we would inherit base class's constructors through a using
|
||||
// declaration, which would preserve their visibility. However, many existing
|
||||
// tests rely on the fact that current implementation reexports protected
|
||||
// constructors as public. These tests would need to be cleaned up first.
|
||||
|
||||
// Single argument constructor is special-cased so that it can be
|
||||
// made explicit.
|
||||
template <typename A>
|
||||
explicit NaggyMock(A&& arg) : MockClass(std::forward<A>(arg)) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename... An>
|
||||
NaggyMock(A1&& arg1, A2&& arg2, An&&... args)
|
||||
: MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
|
||||
std::forward<An>(args)...) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
#else
|
||||
// C++98 doesn't have variadic templates, so we have to define one
|
||||
// for each arity.
|
||||
template <typename A1>
|
||||
explicit NaggyMock(const A1& a1) : MockClass(a1) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
template <typename A1, typename A2>
|
||||
NaggyMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3>
|
||||
NaggyMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4>
|
||||
NaggyMock(const A1& a1, const A2& a2, const A3& a3,
|
||||
const A4& a4) : MockClass(a1, a2, a3, a4) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5>
|
||||
NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6>
|
||||
NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7>
|
||||
NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
|
||||
a6, a7) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7, typename A8>
|
||||
NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
|
||||
a2, a3, a4, a5, a6, a7, a8) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7, typename A8, typename A9>
|
||||
NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5, const A6& a6, const A7& a7, const A8& a8,
|
||||
const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7, typename A8, typename A9, typename A10>
|
||||
NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
|
||||
const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
~NaggyMock() { // NOLINT
|
||||
::testing::Mock::UnregisterCallReaction(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(NaggyMock);
|
||||
};
|
||||
|
||||
template <class MockClass>
|
||||
class StrictMock : public MockClass {
|
||||
public:
|
||||
StrictMock() : MockClass() {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
// Ideally, we would inherit base class's constructors through a using
|
||||
// declaration, which would preserve their visibility. However, many existing
|
||||
// tests rely on the fact that current implementation reexports protected
|
||||
// constructors as public. These tests would need to be cleaned up first.
|
||||
|
||||
// Single argument constructor is special-cased so that it can be
|
||||
// made explicit.
|
||||
template <typename A>
|
||||
explicit StrictMock(A&& arg) : MockClass(std::forward<A>(arg)) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename... An>
|
||||
StrictMock(A1&& arg1, A2&& arg2, An&&... args)
|
||||
: MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
|
||||
std::forward<An>(args)...) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
#else
|
||||
// C++98 doesn't have variadic templates, so we have to define one
|
||||
// for each arity.
|
||||
template <typename A1>
|
||||
explicit StrictMock(const A1& a1) : MockClass(a1) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
template <typename A1, typename A2>
|
||||
StrictMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3>
|
||||
StrictMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4>
|
||||
StrictMock(const A1& a1, const A2& a2, const A3& a3,
|
||||
const A4& a4) : MockClass(a1, a2, a3, a4) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5>
|
||||
StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6>
|
||||
StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7>
|
||||
StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
|
||||
a6, a7) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7, typename A8>
|
||||
StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
|
||||
a2, a3, a4, a5, a6, a7, a8) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7, typename A8, typename A9>
|
||||
StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5, const A6& a6, const A7& a7, const A8& a8,
|
||||
const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7, typename A8, typename A9, typename A10>
|
||||
StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
|
||||
const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
~StrictMock() { // NOLINT
|
||||
::testing::Mock::UnregisterCallReaction(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock);
|
||||
};
|
||||
|
||||
// The following specializations catch some (relatively more common)
|
||||
// user errors of nesting nice and strict mocks. They do NOT catch
|
||||
// all possible errors.
|
||||
|
||||
// These specializations are declared but not defined, as NiceMock,
|
||||
// NaggyMock, and StrictMock cannot be nested.
|
||||
|
||||
template <typename MockClass>
|
||||
class NiceMock<NiceMock<MockClass> >;
|
||||
template <typename MockClass>
|
||||
class NiceMock<NaggyMock<MockClass> >;
|
||||
template <typename MockClass>
|
||||
class NiceMock<StrictMock<MockClass> >;
|
||||
|
||||
template <typename MockClass>
|
||||
class NaggyMock<NiceMock<MockClass> >;
|
||||
template <typename MockClass>
|
||||
class NaggyMock<NaggyMock<MockClass> >;
|
||||
template <typename MockClass>
|
||||
class NaggyMock<StrictMock<MockClass> >;
|
||||
|
||||
template <typename MockClass>
|
||||
class StrictMock<NiceMock<MockClass> >;
|
||||
template <typename MockClass>
|
||||
class StrictMock<NaggyMock<MockClass> >;
|
||||
template <typename MockClass>
|
||||
class StrictMock<StrictMock<MockClass> >;
|
||||
|
||||
} // namespace testing
|
||||
|
||||
#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
|
@ -44,6 +44,7 @@
|
||||
|
||||
#include <math.h>
|
||||
#include <algorithm>
|
||||
#include <initializer_list>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
@ -57,10 +58,6 @@
|
||||
#include "gmock/internal/gmock-port.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#if GTEST_HAS_STD_INITIALIZER_LIST_
|
||||
# include <initializer_list> // NOLINT -- must be after gtest.h
|
||||
#endif
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(
|
||||
4251 5046 /* class A needs to have dll-interface to be used by clients of
|
||||
class B */
|
||||
@ -194,7 +191,6 @@ class MatcherCastImpl<T, Matcher<U> > {
|
||||
|
||||
// We delegate the matching logic to the source matcher.
|
||||
bool MatchAndExplain(T x, MatchResultListener* listener) const override {
|
||||
#if GTEST_LANG_CXX11
|
||||
using FromType = typename std::remove_cv<typename std::remove_pointer<
|
||||
typename std::remove_reference<T>::type>::type>::type;
|
||||
using ToType = typename std::remove_cv<typename std::remove_pointer<
|
||||
@ -208,7 +204,6 @@ class MatcherCastImpl<T, Matcher<U> > {
|
||||
std::is_same<FromType, ToType>::value ||
|
||||
!std::is_base_of<FromType, ToType>::value,
|
||||
"Can't implicitly convert from <base> to <derived>");
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
return source_matcher_.MatchAndExplain(static_cast<U>(x), listener);
|
||||
}
|
||||
@ -249,11 +244,8 @@ inline Matcher<T> MatcherCast(const M& matcher) {
|
||||
|
||||
// Implements SafeMatcherCast().
|
||||
//
|
||||
// We use an intermediate class to do the actual safe casting as Nokia's
|
||||
// Symbian compiler cannot decide between
|
||||
// template <T, M> ... (M) and
|
||||
// template <T, U> ... (const Matcher<U>&)
|
||||
// for function templates but can for member function templates.
|
||||
// FIXME: The intermediate SafeMatcherCastImpl class was introduced as a
|
||||
// workaround for a compiler bug, and can now be removed.
|
||||
template <typename T>
|
||||
class SafeMatcherCastImpl {
|
||||
public:
|
||||
@ -387,11 +379,9 @@ class TuplePrefix {
|
||||
typename std::tuple_element<N - 1, MatcherTuple>::type matcher =
|
||||
std::get<N - 1>(matchers);
|
||||
typedef typename std::tuple_element<N - 1, ValueTuple>::type Value;
|
||||
GTEST_REFERENCE_TO_CONST_(Value) value = std::get<N - 1>(values);
|
||||
const Value& value = std::get<N - 1>(values);
|
||||
StringMatchResultListener listener;
|
||||
if (!matcher.MatchAndExplain(value, &listener)) {
|
||||
// FIXME: include in the message the name of the parameter
|
||||
// as used in MOCK_METHOD*() when possible.
|
||||
*os << " Expected arg #" << N - 1 << ": ";
|
||||
std::get<N - 1>(matchers).DescribeTo(os);
|
||||
*os << "\n Actual: ";
|
||||
@ -492,9 +482,9 @@ OutIter TransformTupleValues(Func f, const Tuple& t, OutIter out) {
|
||||
|
||||
// Implements A<T>().
|
||||
template <typename T>
|
||||
class AnyMatcherImpl : public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> {
|
||||
class AnyMatcherImpl : public MatcherInterface<const T&> {
|
||||
public:
|
||||
bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) /* x */,
|
||||
bool MatchAndExplain(const T& /* x */,
|
||||
MatchResultListener* /* listener */) const override {
|
||||
return true;
|
||||
}
|
||||
@ -524,11 +514,7 @@ class IsNullMatcher {
|
||||
template <typename Pointer>
|
||||
bool MatchAndExplain(const Pointer& p,
|
||||
MatchResultListener* /* listener */) const {
|
||||
#if GTEST_LANG_CXX11
|
||||
return p == nullptr;
|
||||
#else // GTEST_LANG_CXX11
|
||||
return GetRawPointer(p) == NULL;
|
||||
#endif // GTEST_LANG_CXX11
|
||||
}
|
||||
|
||||
void DescribeTo(::std::ostream* os) const { *os << "is NULL"; }
|
||||
@ -544,11 +530,7 @@ class NotNullMatcher {
|
||||
template <typename Pointer>
|
||||
bool MatchAndExplain(const Pointer& p,
|
||||
MatchResultListener* /* listener */) const {
|
||||
#if GTEST_LANG_CXX11
|
||||
return p != nullptr;
|
||||
#else // GTEST_LANG_CXX11
|
||||
return GetRawPointer(p) != NULL;
|
||||
#endif // GTEST_LANG_CXX11
|
||||
}
|
||||
|
||||
void DescribeTo(::std::ostream* os) const { *os << "isn't NULL"; }
|
||||
@ -976,12 +958,12 @@ class Ge2Matcher : public PairMatchBase<Ge2Matcher, AnyGe> {
|
||||
// will prevent different instantiations of NotMatcher from sharing
|
||||
// the same NotMatcherImpl<T> class.
|
||||
template <typename T>
|
||||
class NotMatcherImpl : public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> {
|
||||
class NotMatcherImpl : public MatcherInterface<const T&> {
|
||||
public:
|
||||
explicit NotMatcherImpl(const Matcher<T>& matcher)
|
||||
: matcher_(matcher) {}
|
||||
|
||||
bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x,
|
||||
bool MatchAndExplain(const T& x,
|
||||
MatchResultListener* listener) const override {
|
||||
return !matcher_.MatchAndExplain(x, listener);
|
||||
}
|
||||
@ -1025,8 +1007,7 @@ class NotMatcher {
|
||||
// that will prevent different instantiations of BothOfMatcher from
|
||||
// sharing the same BothOfMatcherImpl<T> class.
|
||||
template <typename T>
|
||||
class AllOfMatcherImpl
|
||||
: public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> {
|
||||
class AllOfMatcherImpl : public MatcherInterface<const T&> {
|
||||
public:
|
||||
explicit AllOfMatcherImpl(std::vector<Matcher<T> > matchers)
|
||||
: matchers_(std::move(matchers)) {}
|
||||
@ -1049,7 +1030,7 @@ class AllOfMatcherImpl
|
||||
*os << ")";
|
||||
}
|
||||
|
||||
bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x,
|
||||
bool MatchAndExplain(const T& x,
|
||||
MatchResultListener* listener) const override {
|
||||
// If either matcher1_ or matcher2_ doesn't match x, we only need
|
||||
// to explain why one of them fails.
|
||||
@ -1132,8 +1113,7 @@ using AllOfMatcher = VariadicMatcher<AllOfMatcherImpl, Args...>;
|
||||
// that will prevent different instantiations of AnyOfMatcher from
|
||||
// sharing the same EitherOfMatcherImpl<T> class.
|
||||
template <typename T>
|
||||
class AnyOfMatcherImpl
|
||||
: public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> {
|
||||
class AnyOfMatcherImpl : public MatcherInterface<const T&> {
|
||||
public:
|
||||
explicit AnyOfMatcherImpl(std::vector<Matcher<T> > matchers)
|
||||
: matchers_(std::move(matchers)) {}
|
||||
@ -1156,7 +1136,7 @@ class AnyOfMatcherImpl
|
||||
*os << ")";
|
||||
}
|
||||
|
||||
bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x,
|
||||
bool MatchAndExplain(const T& x,
|
||||
MatchResultListener* listener) const override {
|
||||
std::string no_match_result;
|
||||
|
||||
@ -1584,8 +1564,7 @@ class PointeeMatcher {
|
||||
// enough for implementing the DescribeTo() method of Pointee().
|
||||
template <typename Pointer>
|
||||
operator Matcher<Pointer>() const {
|
||||
return Matcher<Pointer>(
|
||||
new Impl<GTEST_REFERENCE_TO_CONST_(Pointer)>(matcher_));
|
||||
return Matcher<Pointer>(new Impl<const Pointer&>(matcher_));
|
||||
}
|
||||
|
||||
private:
|
||||
@ -1676,7 +1655,6 @@ class WhenDynamicCastToMatcher : public WhenDynamicCastToMatcherBase<To> {
|
||||
|
||||
template <typename From>
|
||||
bool MatchAndExplain(From from, MatchResultListener* listener) const {
|
||||
// FIXME: Add more detail on failures. ie did the dyn_cast fail?
|
||||
To to = dynamic_cast<To>(from);
|
||||
return MatchPrintAndExplain(to, this->matcher_, listener);
|
||||
}
|
||||
@ -1730,23 +1708,22 @@ class FieldMatcher {
|
||||
|
||||
template <typename T>
|
||||
bool MatchAndExplain(const T& value, MatchResultListener* listener) const {
|
||||
// FIXME: The dispatch on std::is_pointer was introduced as a workaround for
|
||||
// a compiler bug, and can now be removed.
|
||||
return MatchAndExplainImpl(
|
||||
typename ::testing::internal::
|
||||
is_pointer<GTEST_REMOVE_CONST_(T)>::type(),
|
||||
value, listener);
|
||||
typename std::is_pointer<GTEST_REMOVE_CONST_(T)>::type(), value,
|
||||
listener);
|
||||
}
|
||||
|
||||
private:
|
||||
// The first argument of MatchAndExplainImpl() is needed to help
|
||||
// Symbian's C++ compiler choose which overload to use. Its type is
|
||||
// true_type iff the Field() matcher is used to match a pointer.
|
||||
bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& obj,
|
||||
bool MatchAndExplainImpl(std::false_type /* is_not_pointer */,
|
||||
const Class& obj,
|
||||
MatchResultListener* listener) const {
|
||||
*listener << whose_field_ << "is ";
|
||||
return MatchPrintAndExplain(obj.*field_, matcher_, listener);
|
||||
}
|
||||
|
||||
bool MatchAndExplainImpl(true_type /* is_pointer */, const Class* p,
|
||||
bool MatchAndExplainImpl(std::true_type /* is_pointer */, const Class* p,
|
||||
MatchResultListener* listener) const {
|
||||
if (p == nullptr) return false;
|
||||
|
||||
@ -1754,7 +1731,7 @@ class FieldMatcher {
|
||||
// Since *p has a field, it must be a class/struct/union type and
|
||||
// thus cannot be a pointer. Therefore we pass false_type() as
|
||||
// the first argument.
|
||||
return MatchAndExplainImpl(false_type(), *p, listener);
|
||||
return MatchAndExplainImpl(std::false_type(), *p, listener);
|
||||
}
|
||||
|
||||
const FieldType Class::*field_;
|
||||
@ -1775,11 +1752,7 @@ class FieldMatcher {
|
||||
template <typename Class, typename PropertyType, typename Property>
|
||||
class PropertyMatcher {
|
||||
public:
|
||||
// The property may have a reference type, so 'const PropertyType&'
|
||||
// may cause double references and fail to compile. That's why we
|
||||
// need GTEST_REFERENCE_TO_CONST, which works regardless of
|
||||
// PropertyType being a reference or not.
|
||||
typedef GTEST_REFERENCE_TO_CONST_(PropertyType) RefToConstProperty;
|
||||
typedef const PropertyType& RefToConstProperty;
|
||||
|
||||
PropertyMatcher(Property property, const Matcher<RefToConstProperty>& matcher)
|
||||
: property_(property),
|
||||
@ -1805,16 +1778,13 @@ class PropertyMatcher {
|
||||
template <typename T>
|
||||
bool MatchAndExplain(const T&value, MatchResultListener* listener) const {
|
||||
return MatchAndExplainImpl(
|
||||
typename ::testing::internal::
|
||||
is_pointer<GTEST_REMOVE_CONST_(T)>::type(),
|
||||
value, listener);
|
||||
typename std::is_pointer<GTEST_REMOVE_CONST_(T)>::type(), value,
|
||||
listener);
|
||||
}
|
||||
|
||||
private:
|
||||
// The first argument of MatchAndExplainImpl() is needed to help
|
||||
// Symbian's C++ compiler choose which overload to use. Its type is
|
||||
// true_type iff the Property() matcher is used to match a pointer.
|
||||
bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& obj,
|
||||
bool MatchAndExplainImpl(std::false_type /* is_not_pointer */,
|
||||
const Class& obj,
|
||||
MatchResultListener* listener) const {
|
||||
*listener << whose_property_ << "is ";
|
||||
// Cannot pass the return value (for example, int) to MatchPrintAndExplain,
|
||||
@ -1823,7 +1793,7 @@ class PropertyMatcher {
|
||||
return MatchPrintAndExplain(result, matcher_, listener);
|
||||
}
|
||||
|
||||
bool MatchAndExplainImpl(true_type /* is_pointer */, const Class* p,
|
||||
bool MatchAndExplainImpl(std::true_type /* is_pointer */, const Class* p,
|
||||
MatchResultListener* listener) const {
|
||||
if (p == nullptr) return false;
|
||||
|
||||
@ -1831,7 +1801,7 @@ class PropertyMatcher {
|
||||
// Since *p has a property method, it must be a class/struct/union
|
||||
// type and thus cannot be a pointer. Therefore we pass
|
||||
// false_type() as the first argument.
|
||||
return MatchAndExplainImpl(false_type(), *p, listener);
|
||||
return MatchAndExplainImpl(std::false_type(), *p, listener);
|
||||
}
|
||||
|
||||
Property property_;
|
||||
@ -1852,14 +1822,8 @@ struct CallableTraits {
|
||||
|
||||
static void CheckIsValid(Functor /* functor */) {}
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
template <typename T>
|
||||
static auto Invoke(Functor f, T arg) -> decltype(f(arg)) { return f(arg); }
|
||||
#else
|
||||
typedef typename Functor::result_type ResultType;
|
||||
template <typename T>
|
||||
static ResultType Invoke(Functor f, T arg) { return f(arg); }
|
||||
#endif
|
||||
};
|
||||
|
||||
// Specialization for function pointers.
|
||||
@ -1898,12 +1862,8 @@ class ResultOfMatcher {
|
||||
|
||||
template <typename T>
|
||||
class Impl : public MatcherInterface<T> {
|
||||
#if GTEST_LANG_CXX11
|
||||
using ResultType = decltype(CallableTraits<Callable>::template Invoke<T>(
|
||||
std::declval<CallableStorageType>(), std::declval<T>()));
|
||||
#else
|
||||
typedef typename CallableTraits<Callable>::ResultType ResultType;
|
||||
#endif
|
||||
|
||||
public:
|
||||
template <typename M>
|
||||
@ -1959,7 +1919,7 @@ class SizeIsMatcher {
|
||||
|
||||
template <typename Container>
|
||||
operator Matcher<Container>() const {
|
||||
return MakeMatcher(new Impl<Container>(size_matcher_));
|
||||
return Matcher<Container>(new Impl<const Container&>(size_matcher_));
|
||||
}
|
||||
|
||||
template <typename Container>
|
||||
@ -2009,7 +1969,7 @@ class BeginEndDistanceIsMatcher {
|
||||
|
||||
template <typename Container>
|
||||
operator Matcher<Container>() const {
|
||||
return MakeMatcher(new Impl<Container>(distance_matcher_));
|
||||
return Matcher<Container>(new Impl<const Container&>(distance_matcher_));
|
||||
}
|
||||
|
||||
template <typename Container>
|
||||
@ -2034,13 +1994,9 @@ class BeginEndDistanceIsMatcher {
|
||||
|
||||
bool MatchAndExplain(Container container,
|
||||
MatchResultListener* listener) const override {
|
||||
#if GTEST_HAS_STD_BEGIN_AND_END_
|
||||
using std::begin;
|
||||
using std::end;
|
||||
DistanceType distance = std::distance(begin(container), end(container));
|
||||
#else
|
||||
DistanceType distance = std::distance(container.begin(), container.end());
|
||||
#endif
|
||||
StringMatchResultListener distance_listener;
|
||||
const bool result =
|
||||
distance_matcher_.MatchAndExplain(distance, &distance_listener);
|
||||
@ -2269,7 +2225,8 @@ class PointwiseMatcher {
|
||||
!IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)>::value,
|
||||
use_UnorderedPointwise_with_hash_tables);
|
||||
|
||||
return MakeMatcher(new Impl<LhsContainer>(tuple_matcher_, rhs_));
|
||||
return Matcher<LhsContainer>(
|
||||
new Impl<const LhsContainer&>(tuple_matcher_, rhs_));
|
||||
}
|
||||
|
||||
template <typename LhsContainer>
|
||||
@ -2471,7 +2428,8 @@ class ContainsMatcher {
|
||||
|
||||
template <typename Container>
|
||||
operator Matcher<Container>() const {
|
||||
return MakeMatcher(new ContainsMatcherImpl<Container>(inner_matcher_));
|
||||
return Matcher<Container>(
|
||||
new ContainsMatcherImpl<const Container&>(inner_matcher_));
|
||||
}
|
||||
|
||||
private:
|
||||
@ -2488,7 +2446,8 @@ class EachMatcher {
|
||||
|
||||
template <typename Container>
|
||||
operator Matcher<Container>() const {
|
||||
return MakeMatcher(new EachMatcherImpl<Container>(inner_matcher_));
|
||||
return Matcher<Container>(
|
||||
new EachMatcherImpl<const Container&>(inner_matcher_));
|
||||
}
|
||||
|
||||
private:
|
||||
@ -2501,7 +2460,6 @@ struct Rank1 {};
|
||||
struct Rank0 : Rank1 {};
|
||||
|
||||
namespace pair_getters {
|
||||
#if GTEST_LANG_CXX11
|
||||
using std::get;
|
||||
template <typename T>
|
||||
auto First(T& x, Rank1) -> decltype(get<0>(x)) { // NOLINT
|
||||
@ -2520,25 +2478,6 @@ template <typename T>
|
||||
auto Second(T& x, Rank0) -> decltype((x.second)) { // NOLINT
|
||||
return x.second;
|
||||
}
|
||||
#else
|
||||
template <typename T>
|
||||
typename T::first_type& First(T& x, Rank0) { // NOLINT
|
||||
return x.first;
|
||||
}
|
||||
template <typename T>
|
||||
const typename T::first_type& First(const T& x, Rank0) {
|
||||
return x.first;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename T::second_type& Second(T& x, Rank0) { // NOLINT
|
||||
return x.second;
|
||||
}
|
||||
template <typename T>
|
||||
const typename T::second_type& Second(const T& x, Rank0) {
|
||||
return x.second;
|
||||
}
|
||||
#endif // GTEST_LANG_CXX11
|
||||
} // namespace pair_getters
|
||||
|
||||
// Implements Key(inner_matcher) for the given argument pair type.
|
||||
@ -3086,8 +3025,10 @@ class UnorderedElementsAreMatcher {
|
||||
matchers.reserve(::std::tuple_size<MatcherTuple>::value);
|
||||
TransformTupleValues(CastAndAppendTransform<const Element&>(), matchers_,
|
||||
::std::back_inserter(matchers));
|
||||
return MakeMatcher(new UnorderedElementsAreMatcherImpl<Container>(
|
||||
UnorderedMatcherRequire::ExactMatch, matchers.begin(), matchers.end()));
|
||||
return Matcher<Container>(
|
||||
new UnorderedElementsAreMatcherImpl<const Container&>(
|
||||
UnorderedMatcherRequire::ExactMatch, matchers.begin(),
|
||||
matchers.end()));
|
||||
}
|
||||
|
||||
private:
|
||||
@ -3116,7 +3057,7 @@ class ElementsAreMatcher {
|
||||
matchers.reserve(::std::tuple_size<MatcherTuple>::value);
|
||||
TransformTupleValues(CastAndAppendTransform<const Element&>(), matchers_,
|
||||
::std::back_inserter(matchers));
|
||||
return MakeMatcher(new ElementsAreMatcherImpl<Container>(
|
||||
return Matcher<Container>(new ElementsAreMatcherImpl<const Container&>(
|
||||
matchers.begin(), matchers.end()));
|
||||
}
|
||||
|
||||
@ -3136,7 +3077,8 @@ class UnorderedElementsAreArrayMatcher {
|
||||
|
||||
template <typename Container>
|
||||
operator Matcher<Container>() const {
|
||||
return MakeMatcher(new UnorderedElementsAreMatcherImpl<Container>(
|
||||
return Matcher<Container>(
|
||||
new UnorderedElementsAreMatcherImpl<const Container&>(
|
||||
match_flags_, matchers_.begin(), matchers_.end()));
|
||||
}
|
||||
|
||||
@ -3160,7 +3102,7 @@ class ElementsAreArrayMatcher {
|
||||
!IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>::value,
|
||||
use_UnorderedElementsAreArray_with_hash_tables);
|
||||
|
||||
return MakeMatcher(new ElementsAreMatcherImpl<Container>(
|
||||
return Matcher<Container>(new ElementsAreMatcherImpl<const Container&>(
|
||||
matchers_.begin(), matchers_.end()));
|
||||
}
|
||||
|
||||
@ -3548,13 +3490,11 @@ ElementsAreArray(const Container& container) {
|
||||
return ElementsAreArray(container.begin(), container.end());
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_INITIALIZER_LIST_
|
||||
template <typename T>
|
||||
inline internal::ElementsAreArrayMatcher<T>
|
||||
ElementsAreArray(::std::initializer_list<T> xs) {
|
||||
return ElementsAreArray(xs.begin(), xs.end());
|
||||
}
|
||||
#endif
|
||||
|
||||
// UnorderedElementsAreArray(iterator_first, iterator_last)
|
||||
// UnorderedElementsAreArray(pointer, count)
|
||||
@ -3597,13 +3537,11 @@ UnorderedElementsAreArray(const Container& container) {
|
||||
return UnorderedElementsAreArray(container.begin(), container.end());
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_INITIALIZER_LIST_
|
||||
template <typename T>
|
||||
inline internal::UnorderedElementsAreArrayMatcher<T>
|
||||
UnorderedElementsAreArray(::std::initializer_list<T> xs) {
|
||||
return UnorderedElementsAreArray(xs.begin(), xs.end());
|
||||
}
|
||||
#endif
|
||||
|
||||
// _ is a matcher that matches anything of any type.
|
||||
//
|
||||
@ -3770,8 +3708,7 @@ Property(PropertyType (Class::*property)() const,
|
||||
return MakePolymorphicMatcher(
|
||||
internal::PropertyMatcher<Class, PropertyType,
|
||||
PropertyType (Class::*)() const>(
|
||||
property,
|
||||
MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher)));
|
||||
property, MatcherCast<const PropertyType&>(matcher)));
|
||||
// The call to MatcherCast() is required for supporting inner
|
||||
// matchers of compatible types. For example, it allows
|
||||
// Property(&Foo::bar, m)
|
||||
@ -3789,11 +3726,9 @@ Property(const std::string& property_name,
|
||||
return MakePolymorphicMatcher(
|
||||
internal::PropertyMatcher<Class, PropertyType,
|
||||
PropertyType (Class::*)() const>(
|
||||
property_name, property,
|
||||
MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher)));
|
||||
property_name, property, MatcherCast<const PropertyType&>(matcher)));
|
||||
}
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
// The same as above but for reference-qualified member functions.
|
||||
template <typename Class, typename PropertyType, typename PropertyMatcher>
|
||||
inline PolymorphicMatcher<internal::PropertyMatcher<
|
||||
@ -3802,9 +3737,8 @@ Property(PropertyType (Class::*property)() const &,
|
||||
const PropertyMatcher& matcher) {
|
||||
return MakePolymorphicMatcher(
|
||||
internal::PropertyMatcher<Class, PropertyType,
|
||||
PropertyType (Class::*)() const &>(
|
||||
property,
|
||||
MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher)));
|
||||
PropertyType (Class::*)() const&>(
|
||||
property, MatcherCast<const PropertyType&>(matcher)));
|
||||
}
|
||||
|
||||
// Three-argument form for reference-qualified member functions.
|
||||
@ -3816,11 +3750,9 @@ Property(const std::string& property_name,
|
||||
const PropertyMatcher& matcher) {
|
||||
return MakePolymorphicMatcher(
|
||||
internal::PropertyMatcher<Class, PropertyType,
|
||||
PropertyType (Class::*)() const &>(
|
||||
property_name, property,
|
||||
MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher)));
|
||||
PropertyType (Class::*)() const&>(
|
||||
property_name, property, MatcherCast<const PropertyType&>(matcher)));
|
||||
}
|
||||
#endif
|
||||
|
||||
// Creates a matcher that matches an object iff the result of applying
|
||||
// a callable to x matches 'matcher'.
|
||||
@ -4112,7 +4044,6 @@ Pointwise(const TupleMatcher& tuple_matcher, const Container& rhs) {
|
||||
tuple_matcher, rhs);
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_INITIALIZER_LIST_
|
||||
|
||||
// Supports the Pointwise(m, {a, b, c}) syntax.
|
||||
template <typename TupleMatcher, typename T>
|
||||
@ -4121,7 +4052,6 @@ inline internal::PointwiseMatcher<TupleMatcher, std::vector<T> > Pointwise(
|
||||
return Pointwise(tuple_matcher, std::vector<T>(rhs));
|
||||
}
|
||||
|
||||
#endif // GTEST_HAS_STD_INITIALIZER_LIST_
|
||||
|
||||
// UnorderedPointwise(pair_matcher, rhs) matches an STL-style
|
||||
// container or a native array that contains the same number of
|
||||
@ -4166,7 +4096,6 @@ UnorderedPointwise(const Tuple2Matcher& tuple2_matcher,
|
||||
return UnorderedElementsAreArray(matchers);
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_INITIALIZER_LIST_
|
||||
|
||||
// Supports the UnorderedPointwise(m, {a, b, c}) syntax.
|
||||
template <typename Tuple2Matcher, typename T>
|
||||
@ -4177,7 +4106,6 @@ UnorderedPointwise(const Tuple2Matcher& tuple2_matcher,
|
||||
return UnorderedPointwise(tuple2_matcher, std::vector<T>(rhs));
|
||||
}
|
||||
|
||||
#endif // GTEST_HAS_STD_INITIALIZER_LIST_
|
||||
|
||||
// Matches an STL-style container or a native array that contains at
|
||||
// least one element matching the given value or matcher.
|
||||
@ -4257,13 +4185,11 @@ IsSupersetOf(const Container& container) {
|
||||
return IsSupersetOf(container.begin(), container.end());
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_INITIALIZER_LIST_
|
||||
template <typename T>
|
||||
inline internal::UnorderedElementsAreArrayMatcher<T> IsSupersetOf(
|
||||
::std::initializer_list<T> xs) {
|
||||
return IsSupersetOf(xs.begin(), xs.end());
|
||||
}
|
||||
#endif
|
||||
|
||||
// IsSubsetOf(iterator_first, iterator_last)
|
||||
// IsSubsetOf(pointer, count)
|
||||
@ -4316,13 +4242,11 @@ IsSubsetOf(const Container& container) {
|
||||
return IsSubsetOf(container.begin(), container.end());
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_INITIALIZER_LIST_
|
||||
template <typename T>
|
||||
inline internal::UnorderedElementsAreArrayMatcher<T> IsSubsetOf(
|
||||
::std::initializer_list<T> xs) {
|
||||
return IsSubsetOf(xs.begin(), xs.end());
|
||||
}
|
||||
#endif
|
||||
|
||||
// Matches an STL-style container or a native array that contains only
|
||||
// elements matching the given value or matcher.
|
||||
|
@ -1,8 +1,3 @@
|
||||
$$ -*- mode: c++; -*-
|
||||
$$ This is a Pump source file. Please use Pump to convert
|
||||
$$ it to gmock-generated-nice-strict.h.
|
||||
$$
|
||||
$var n = 10 $$ The maximum arity we support.
|
||||
// Copyright 2008, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
@ -65,34 +60,22 @@ $var n = 10 $$ The maximum arity we support.
|
||||
|
||||
// GOOGLETEST_CM0002 DO NOT DELETE
|
||||
|
||||
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
|
||||
#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
|
||||
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_
|
||||
#define GMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_
|
||||
|
||||
#include "gmock/gmock-spec-builders.h"
|
||||
#include "gmock/internal/gmock-port.h"
|
||||
|
||||
namespace testing {
|
||||
|
||||
$range kind 0..2
|
||||
$for kind [[
|
||||
|
||||
$var clazz=[[$if kind==0 [[NiceMock]]
|
||||
$elif kind==1 [[NaggyMock]]
|
||||
$else [[StrictMock]]]]
|
||||
|
||||
$var method=[[$if kind==0 [[AllowUninterestingCalls]]
|
||||
$elif kind==1 [[WarnUninterestingCalls]]
|
||||
$else [[FailUninterestingCalls]]]]
|
||||
|
||||
template <class MockClass>
|
||||
class $clazz : public MockClass {
|
||||
class NiceMock : public MockClass {
|
||||
public:
|
||||
$clazz() : MockClass() {
|
||||
::testing::Mock::$method(
|
||||
NiceMock() : MockClass() {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
// Ideally, we would inherit base class's constructors through a using
|
||||
// declaration, which would preserve their visibility. However, many existing
|
||||
// tests rely on the fact that current implementation reexports protected
|
||||
@ -101,50 +84,103 @@ class $clazz : public MockClass {
|
||||
// Single argument constructor is special-cased so that it can be
|
||||
// made explicit.
|
||||
template <typename A>
|
||||
explicit $clazz(A&& arg) : MockClass(std::forward<A>(arg)) {
|
||||
::testing::Mock::$method(
|
||||
explicit NiceMock(A&& arg) : MockClass(std::forward<A>(arg)) {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename... An>
|
||||
$clazz(A1&& arg1, A2&& arg2, An&&... args)
|
||||
NiceMock(A1&& arg1, A2&& arg2, An&&... args)
|
||||
: MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
|
||||
std::forward<An>(args)...) {
|
||||
::testing::Mock::$method(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
#else
|
||||
// C++98 doesn't have variadic templates, so we have to define one
|
||||
// for each arity.
|
||||
template <typename A1>
|
||||
explicit $clazz(const A1& a1) : MockClass(a1) {
|
||||
::testing::Mock::$method(
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
$range i 2..n
|
||||
$for i [[
|
||||
$range j 1..i
|
||||
template <$for j, [[typename A$j]]>
|
||||
$clazz($for j, [[const A$j& a$j]]) : MockClass($for j, [[a$j]]) {
|
||||
::testing::Mock::$method(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
|
||||
]]
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
~$clazz() { // NOLINT
|
||||
~NiceMock() { // NOLINT
|
||||
::testing::Mock::UnregisterCallReaction(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_($clazz);
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock);
|
||||
};
|
||||
|
||||
]]
|
||||
template <class MockClass>
|
||||
class NaggyMock : public MockClass {
|
||||
public:
|
||||
NaggyMock() : MockClass() {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
// Ideally, we would inherit base class's constructors through a using
|
||||
// declaration, which would preserve their visibility. However, many existing
|
||||
// tests rely on the fact that current implementation reexports protected
|
||||
// constructors as public. These tests would need to be cleaned up first.
|
||||
|
||||
// Single argument constructor is special-cased so that it can be
|
||||
// made explicit.
|
||||
template <typename A>
|
||||
explicit NaggyMock(A&& arg) : MockClass(std::forward<A>(arg)) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename... An>
|
||||
NaggyMock(A1&& arg1, A2&& arg2, An&&... args)
|
||||
: MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
|
||||
std::forward<An>(args)...) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
~NaggyMock() { // NOLINT
|
||||
::testing::Mock::UnregisterCallReaction(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(NaggyMock);
|
||||
};
|
||||
|
||||
template <class MockClass>
|
||||
class StrictMock : public MockClass {
|
||||
public:
|
||||
StrictMock() : MockClass() {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
// Ideally, we would inherit base class's constructors through a using
|
||||
// declaration, which would preserve their visibility. However, many existing
|
||||
// tests rely on the fact that current implementation reexports protected
|
||||
// constructors as public. These tests would need to be cleaned up first.
|
||||
|
||||
// Single argument constructor is special-cased so that it can be
|
||||
// made explicit.
|
||||
template <typename A>
|
||||
explicit StrictMock(A&& arg) : MockClass(std::forward<A>(arg)) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename... An>
|
||||
StrictMock(A1&& arg1, A2&& arg2, An&&... args)
|
||||
: MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
|
||||
std::forward<An>(args)...) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
~StrictMock() { // NOLINT
|
||||
::testing::Mock::UnregisterCallReaction(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock);
|
||||
};
|
||||
|
||||
// The following specializations catch some (relatively more common)
|
||||
// user errors of nesting nice and strict mocks. They do NOT catch
|
||||
@ -176,4 +212,4 @@ class StrictMock<StrictMock<MockClass> >;
|
||||
|
||||
} // namespace testing
|
||||
|
||||
#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
|
||||
#endif // GMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_
|
@ -186,7 +186,6 @@ class GTEST_API_ UntypedFunctionMockerBase {
|
||||
// this information in the global mock registry. Will be called
|
||||
// whenever an EXPECT_CALL() or ON_CALL() is executed on this mock
|
||||
// method.
|
||||
// FIXME: rename to SetAndRegisterOwner().
|
||||
void RegisterOwner(const void* mock_obj)
|
||||
GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
|
||||
|
||||
@ -301,12 +300,7 @@ class OnCallSpec : public UntypedOnCallSpecBase {
|
||||
const ArgumentMatcherTuple& matchers)
|
||||
: UntypedOnCallSpecBase(a_file, a_line),
|
||||
matchers_(matchers),
|
||||
// By default, extra_matcher_ should match anything. However,
|
||||
// we cannot initialize it with _ as that triggers a compiler
|
||||
// bug in Symbian's C++ compiler (cannot decide between two
|
||||
// overloaded constructors of Matcher<const ArgumentTuple&>).
|
||||
extra_matcher_(A<const ArgumentTuple&>()) {
|
||||
}
|
||||
extra_matcher_(_) {}
|
||||
|
||||
// Implements the .With() clause.
|
||||
OnCallSpec& With(const Matcher<const ArgumentTuple&>& m) {
|
||||
@ -896,11 +890,7 @@ class TypedExpectation : public ExpectationBase {
|
||||
: ExpectationBase(a_file, a_line, a_source_text),
|
||||
owner_(owner),
|
||||
matchers_(m),
|
||||
// By default, extra_matcher_ should match anything. However,
|
||||
// we cannot initialize it with _ as that triggers a compiler
|
||||
// bug in Symbian's C++ compiler (cannot decide between two
|
||||
// overloaded constructors of Matcher<const ArgumentTuple&>).
|
||||
extra_matcher_(A<const ArgumentTuple&>()),
|
||||
extra_matcher_(_),
|
||||
repeated_action_(DoDefault()) {}
|
||||
|
||||
~TypedExpectation() override {
|
||||
@ -1206,9 +1196,6 @@ class TypedExpectation : public ExpectationBase {
|
||||
mocker->DescribeDefaultActionTo(args, what);
|
||||
DescribeCallCountTo(why);
|
||||
|
||||
// FIXME: allow the user to control whether
|
||||
// unexpected calls should fail immediately or continue using a
|
||||
// flag --gmock_unexpected_calls_are_fatal.
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -62,10 +62,10 @@
|
||||
#include "gmock/gmock-generated-actions.h"
|
||||
#include "gmock/gmock-generated-function-mockers.h"
|
||||
#include "gmock/gmock-generated-matchers.h"
|
||||
#include "gmock/gmock-generated-nice-strict.h"
|
||||
#include "gmock/gmock-matchers.h"
|
||||
#include "gmock/gmock-more-actions.h"
|
||||
#include "gmock/gmock-more-matchers.h"
|
||||
#include "gmock/gmock-nice-strict.h"
|
||||
#include "gmock/internal/gmock-internal-utils.h"
|
||||
|
||||
namespace testing {
|
||||
|
@ -43,6 +43,7 @@
|
||||
#define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_
|
||||
|
||||
#include "gmock/internal/gmock-port.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace testing {
|
||||
|
||||
@ -51,19 +52,6 @@ class Matcher;
|
||||
|
||||
namespace internal {
|
||||
|
||||
// An IgnoredValue object can be implicitly constructed from ANY value.
|
||||
// This is used in implementing the IgnoreResult(a) action.
|
||||
class IgnoredValue {
|
||||
public:
|
||||
// This constructor template allows any value to be implicitly
|
||||
// converted to IgnoredValue. The object has no data member and
|
||||
// doesn't try to remember anything about the argument. We
|
||||
// deliberately omit the 'explicit' keyword in order to allow the
|
||||
// conversion to be implicit.
|
||||
template <typename T>
|
||||
IgnoredValue(const T& /* ignored */) {} // NOLINT(runtime/explicit)
|
||||
};
|
||||
|
||||
// MatcherTuple<T>::type is a tuple type where each field is a Matcher
|
||||
// for the corresponding field in tuple type T.
|
||||
template <typename Tuple>
|
||||
|
@ -44,6 +44,7 @@ $var n = 10 $$ The maximum arity we support.
|
||||
#define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_
|
||||
|
||||
#include "gmock/internal/gmock-port.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace testing {
|
||||
|
||||
@ -52,19 +53,6 @@ class Matcher;
|
||||
|
||||
namespace internal {
|
||||
|
||||
// An IgnoredValue object can be implicitly constructed from ANY value.
|
||||
// This is used in implementing the IgnoreResult(a) action.
|
||||
class IgnoredValue {
|
||||
public:
|
||||
// This constructor template allows any value to be implicitly
|
||||
// converted to IgnoredValue. The object has no data member and
|
||||
// doesn't try to remember anything about the argument. We
|
||||
// deliberately omit the 'explicit' keyword in order to allow the
|
||||
// conversion to be implicit.
|
||||
template <typename T>
|
||||
IgnoredValue(const T& /* ignored */) {} // NOLINT(runtime/explicit)
|
||||
};
|
||||
|
||||
// MatcherTuple<T>::type is a tuple type where each field is a Matcher
|
||||
// for the corresponding field in tuple type T.
|
||||
template <typename Tuple>
|
||||
|
@ -92,16 +92,11 @@ inline const typename Pointer::element_type* GetRawPointer(const Pointer& p) {
|
||||
template <typename Element>
|
||||
inline Element* GetRawPointer(Element* p) { return p; }
|
||||
|
||||
// Symbian compilation can be done with wchar_t being either a native
|
||||
// type or a typedef. Using Google Mock with OpenC without wchar_t
|
||||
// should require the definition of _STLP_NO_WCHAR_T.
|
||||
//
|
||||
// MSVC treats wchar_t as a native type usually, but treats it as the
|
||||
// same as unsigned short when the compiler option /Zc:wchar_t- is
|
||||
// specified. It defines _NATIVE_WCHAR_T_DEFINED symbol when wchar_t
|
||||
// is a native type.
|
||||
#if (GTEST_OS_SYMBIAN && defined(_STLP_NO_WCHAR_T)) || \
|
||||
(defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED))
|
||||
#if defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED)
|
||||
// wchar_t is a typedef.
|
||||
#else
|
||||
# define GMOCK_WCHAR_T_IS_NATIVE_ 1
|
||||
@ -351,8 +346,6 @@ class WithoutMatchers {
|
||||
// Internal use only: access the singleton instance of WithoutMatchers.
|
||||
GTEST_API_ WithoutMatchers GetWithoutMatchers();
|
||||
|
||||
// FIXME: group all type utilities together.
|
||||
|
||||
// Type traits.
|
||||
|
||||
// is_reference<T>::value is non-zero iff T is a reference type.
|
||||
@ -452,32 +445,10 @@ class StlContainerView<Element[N]> {
|
||||
static const_reference ConstReference(const Element (&array)[N]) {
|
||||
// Ensures that Element is not a const type.
|
||||
testing::StaticAssertTypeEq<Element, RawElement>();
|
||||
#if GTEST_OS_SYMBIAN
|
||||
// The Nokia Symbian compiler confuses itself in template instantiation
|
||||
// for this call without the cast to Element*:
|
||||
// function call '[testing::internal::NativeArray<char *>].NativeArray(
|
||||
// {lval} const char *[4], long, testing::internal::RelationToSource)'
|
||||
// does not match
|
||||
// 'testing::internal::NativeArray<char *>::NativeArray(
|
||||
// char *const *, unsigned int, testing::internal::RelationToSource)'
|
||||
// (instantiating: 'testing::internal::ContainsMatcherImpl
|
||||
// <const char * (&)[4]>::Matches(const char * (&)[4]) const')
|
||||
// (instantiating: 'testing::internal::StlContainerView<char *[4]>::
|
||||
// ConstReference(const char * (&)[4])')
|
||||
// (and though the N parameter type is mismatched in the above explicit
|
||||
// conversion of it doesn't help - only the conversion of the array).
|
||||
return type(const_cast<Element*>(&array[0]), N,
|
||||
RelationToSourceReference());
|
||||
#else
|
||||
return type(array, N, RelationToSourceReference());
|
||||
#endif // GTEST_OS_SYMBIAN
|
||||
}
|
||||
static type Copy(const Element (&array)[N]) {
|
||||
#if GTEST_OS_SYMBIAN
|
||||
return type(const_cast<Element*>(&array[0]), N, RelationToSourceCopy());
|
||||
#else
|
||||
return type(array, N, RelationToSourceCopy());
|
||||
#endif // GTEST_OS_SYMBIAN
|
||||
}
|
||||
};
|
||||
|
||||
@ -528,7 +499,6 @@ struct BooleanConstant {};
|
||||
// reduce code size.
|
||||
GTEST_API_ void IllegalDoDefault(const char* file, int line);
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
// Helper types for Apply() below.
|
||||
template <size_t... Is> struct int_pack { typedef int_pack type; };
|
||||
|
||||
@ -554,7 +524,6 @@ auto Apply(F&& f, Tuple&& args)
|
||||
return ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args),
|
||||
make_int_pack<std::tuple_size<Tuple>::value>());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
@ -19,6 +19,9 @@
|
||||
# a copy of Google Test at a different location.
|
||||
GTEST_DIR = ../../googletest
|
||||
|
||||
# Points to the location of the Google Test libraries
|
||||
GTEST_LIB_DIR = .
|
||||
|
||||
# Points to the root of Google Mock, relative to where this file is.
|
||||
# Remember to tweak this if you move this file.
|
||||
GMOCK_DIR = ..
|
||||
@ -33,7 +36,10 @@ USER_DIR = ../test
|
||||
CPPFLAGS += -isystem $(GTEST_DIR)/include -isystem $(GMOCK_DIR)/include
|
||||
|
||||
# Flags passed to the C++ compiler.
|
||||
CXXFLAGS += -g -Wall -Wextra -pthread
|
||||
CXXFLAGS += -g -Wall -Wextra -pthread -std=c++11
|
||||
|
||||
# Google Test libraries
|
||||
GTEST_LIBS = libgtest.a libgtest_main.a libgmock.a libgmock_main.a
|
||||
|
||||
# All tests produced by this Makefile. Remember to add new tests you
|
||||
# created to the list.
|
||||
@ -53,10 +59,10 @@ GMOCK_HEADERS = $(GMOCK_DIR)/include/gmock/*.h \
|
||||
|
||||
# House-keeping build targets.
|
||||
|
||||
all : $(TESTS)
|
||||
all : $(GTEST_LIBS) $(TESTS)
|
||||
|
||||
clean :
|
||||
rm -f $(TESTS) gmock.a gmock_main.a *.o
|
||||
rm -f $(GTEST_LIBS) $(TESTS) *.o
|
||||
|
||||
# Builds gmock.a and gmock_main.a. These libraries contain both
|
||||
# Google Mock and Google Test. A test should link with either gmock.a
|
||||
@ -78,6 +84,10 @@ gtest-all.o : $(GTEST_SRCS_)
|
||||
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) -I$(GMOCK_DIR) $(CXXFLAGS) \
|
||||
-c $(GTEST_DIR)/src/gtest-all.cc
|
||||
|
||||
gtest_main.o : $(GTEST_SRCS_)
|
||||
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) -I$(GMOCK_DIR) $(CXXFLAGS) \
|
||||
-c $(GTEST_DIR)/src/gtest_main.cc
|
||||
|
||||
gmock-all.o : $(GMOCK_SRCS_)
|
||||
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) -I$(GMOCK_DIR) $(CXXFLAGS) \
|
||||
-c $(GMOCK_DIR)/src/gmock-all.cc
|
||||
@ -86,10 +96,16 @@ gmock_main.o : $(GMOCK_SRCS_)
|
||||
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) -I$(GMOCK_DIR) $(CXXFLAGS) \
|
||||
-c $(GMOCK_DIR)/src/gmock_main.cc
|
||||
|
||||
gmock.a : gmock-all.o gtest-all.o
|
||||
libgtest.a : gtest-all.o
|
||||
$(AR) $(ARFLAGS) $@ $^
|
||||
|
||||
gmock_main.a : gmock-all.o gtest-all.o gmock_main.o
|
||||
libgtest_main.a : gtest_main.o
|
||||
$(AR) $(ARFLAGS) $@ $^
|
||||
|
||||
libgmock.a : gmock-all.o
|
||||
$(AR) $(ARFLAGS) $@ $^
|
||||
|
||||
libgmock_main.a : gmock_main.o
|
||||
$(AR) $(ARFLAGS) $@ $^
|
||||
|
||||
# Builds a sample test.
|
||||
@ -97,5 +113,5 @@ gmock_main.a : gmock-all.o gtest-all.o gmock_main.o
|
||||
gmock_test.o : $(USER_DIR)/gmock_test.cc $(GMOCK_HEADERS)
|
||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/gmock_test.cc
|
||||
|
||||
gmock_test : gmock_test.o gmock_main.a
|
||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
|
||||
gmock_test : gmock_test.o $(GTEST_LIBS)
|
||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -L$(GTEST_LIB_DIR) -lgmock -lpthread $^ -o $@
|
||||
|
@ -154,9 +154,6 @@ GTEST_API_ void Log(LogSeverity severity, const std::string& message,
|
||||
// Ensures that logs from different threads don't interleave.
|
||||
MutexLock l(&g_log_mutex);
|
||||
|
||||
// "using ::std::cout;" doesn't work with Symbian's STLport, where cout is a
|
||||
// macro.
|
||||
|
||||
if (severity == kWarning) {
|
||||
// Prints a GMOCK WARNING marker to make the warnings easily searchable.
|
||||
std::cout << "\nGMOCK WARNING:";
|
||||
|
@ -572,7 +572,7 @@ struct MockObjectState {
|
||||
// invoked on this mock object.
|
||||
const char* first_used_file;
|
||||
int first_used_line;
|
||||
::std::string first_used_test_case;
|
||||
::std::string first_used_test_suite;
|
||||
::std::string first_used_test;
|
||||
bool leakable; // true iff it's OK to leak the object.
|
||||
FunctionMockers function_mockers; // All registered methods of the object.
|
||||
@ -592,9 +592,6 @@ class MockObjectRegistry {
|
||||
// object alive. Therefore we report any living object as test
|
||||
// failure, unless the user explicitly asked us to ignore it.
|
||||
~MockObjectRegistry() {
|
||||
// "using ::std::cout;" doesn't work with Symbian's STLport, where cout is
|
||||
// a macro.
|
||||
|
||||
if (!GMOCK_FLAG(catch_leaked_mocks))
|
||||
return;
|
||||
|
||||
@ -612,7 +609,7 @@ class MockObjectRegistry {
|
||||
state.first_used_line);
|
||||
std::cout << " ERROR: this mock object";
|
||||
if (state.first_used_test != "") {
|
||||
std::cout << " (used in test " << state.first_used_test_case << "."
|
||||
std::cout << " (used in test " << state.first_used_test_suite << "."
|
||||
<< state.first_used_test << ")";
|
||||
}
|
||||
std::cout << " should be deleted but never is. Its address is @"
|
||||
@ -793,10 +790,7 @@ void Mock::RegisterUseByOnCallOrExpectCall(const void* mock_obj,
|
||||
const TestInfo* const test_info =
|
||||
UnitTest::GetInstance()->current_test_info();
|
||||
if (test_info != nullptr) {
|
||||
// FIXME: record the test case name when the
|
||||
// ON_CALL or EXPECT_CALL is invoked from SetUpTestCase() or
|
||||
// TearDownTestCase().
|
||||
state.first_used_test_case = test_info->test_case_name();
|
||||
state.first_used_test_suite = test_info->test_suite_name();
|
||||
state.first_used_test = test_info->name();
|
||||
}
|
||||
}
|
||||
|
@ -33,9 +33,6 @@
|
||||
|
||||
namespace testing {
|
||||
|
||||
// FIXME: support using environment variables to
|
||||
// control the flag values, like what Google Test does.
|
||||
|
||||
GMOCK_DEFINE_bool_(catch_leaked_mocks, true,
|
||||
"true iff Google Mock should report leaked mock objects "
|
||||
"as failures.");
|
||||
|
@ -220,7 +220,6 @@ class MyNonDefaultConstructible {
|
||||
int value_;
|
||||
};
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
|
||||
TEST(BuiltInDefaultValueTest, ExistsForDefaultConstructibleType) {
|
||||
EXPECT_TRUE(BuiltInDefaultValue<MyDefaultConstructible>::Exists());
|
||||
@ -230,7 +229,6 @@ TEST(BuiltInDefaultValueTest, IsDefaultConstructedForDefaultConstructibleType) {
|
||||
EXPECT_EQ(42, BuiltInDefaultValue<MyDefaultConstructible>::Get().value());
|
||||
}
|
||||
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
TEST(BuiltInDefaultValueTest, DoesNotExistForNonDefaultConstructibleType) {
|
||||
EXPECT_FALSE(BuiltInDefaultValue<MyNonDefaultConstructible>::Exists());
|
||||
@ -300,7 +298,6 @@ TEST(DefaultValueDeathTest, GetReturnsBuiltInDefaultValueWhenUnset) {
|
||||
}, "");
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_UNIQUE_PTR_
|
||||
TEST(DefaultValueTest, GetWorksForMoveOnlyIfSet) {
|
||||
EXPECT_TRUE(DefaultValue<std::unique_ptr<int>>::Exists());
|
||||
EXPECT_TRUE(DefaultValue<std::unique_ptr<int>>::Get() == nullptr);
|
||||
@ -311,7 +308,6 @@ TEST(DefaultValueTest, GetWorksForMoveOnlyIfSet) {
|
||||
std::unique_ptr<int> i = DefaultValue<std::unique_ptr<int>>::Get();
|
||||
EXPECT_EQ(42, *i);
|
||||
}
|
||||
#endif // GTEST_HAS_STD_UNIQUE_PTR_
|
||||
|
||||
// Tests that DefaultValue<void>::Get() returns void.
|
||||
TEST(DefaultValueTest, GetWorksForVoid) {
|
||||
@ -448,19 +444,12 @@ class IsNotZero : public ActionInterface<bool(int)> { // NOLINT
|
||||
}
|
||||
};
|
||||
|
||||
#if !GTEST_OS_SYMBIAN
|
||||
// Compiling this test on Nokia's Symbian compiler fails with:
|
||||
// 'Result' is not a member of class 'testing::internal::Function<int>'
|
||||
// (point of instantiation: '@unnamed@gmock_actions_test_cc@::
|
||||
// ActionTest_CanBeConvertedToOtherActionType_Test::TestBody()')
|
||||
// with no obvious fix.
|
||||
TEST(ActionTest, CanBeConvertedToOtherActionType) {
|
||||
const Action<bool(int)> a1(new IsNotZero); // NOLINT
|
||||
const Action<int(char)> a2 = Action<int(char)>(a1); // NOLINT
|
||||
EXPECT_EQ(1, a2.Perform(std::make_tuple('a')));
|
||||
EXPECT_EQ(0, a2.Perform(std::make_tuple('\0')));
|
||||
}
|
||||
#endif // !GTEST_OS_SYMBIAN
|
||||
|
||||
// The following two classes are for testing MakePolymorphicAction().
|
||||
|
||||
@ -643,7 +632,6 @@ TEST(ReturnNullTest, WorksInPointerReturningFunction) {
|
||||
EXPECT_TRUE(a2.Perform(std::make_tuple(true)) == nullptr);
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_UNIQUE_PTR_
|
||||
// Tests that ReturnNull() returns NULL for shared_ptr and unique_ptr returning
|
||||
// functions.
|
||||
TEST(ReturnNullTest, WorksInSmartPointerReturningFunction) {
|
||||
@ -653,7 +641,6 @@ TEST(ReturnNullTest, WorksInSmartPointerReturningFunction) {
|
||||
const Action<std::shared_ptr<int>(std::string)> a2 = ReturnNull();
|
||||
EXPECT_TRUE(a2.Perform(std::make_tuple("foo")) == nullptr);
|
||||
}
|
||||
#endif // GTEST_HAS_STD_UNIQUE_PTR_
|
||||
|
||||
// Tests that ReturnRef(v) works for reference types.
|
||||
TEST(ReturnRefTest, WorksForReference) {
|
||||
@ -706,14 +693,12 @@ class MockClass {
|
||||
|
||||
MOCK_METHOD1(IntFunc, int(bool flag)); // NOLINT
|
||||
MOCK_METHOD0(Foo, MyNonDefaultConstructible());
|
||||
#if GTEST_HAS_STD_UNIQUE_PTR_
|
||||
MOCK_METHOD0(MakeUnique, std::unique_ptr<int>());
|
||||
MOCK_METHOD0(MakeUniqueBase, std::unique_ptr<Base>());
|
||||
MOCK_METHOD0(MakeVectorUnique, std::vector<std::unique_ptr<int>>());
|
||||
MOCK_METHOD1(TakeUnique, int(std::unique_ptr<int>));
|
||||
MOCK_METHOD2(TakeUnique,
|
||||
int(const std::unique_ptr<int>&, std::unique_ptr<int>));
|
||||
#endif
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockClass);
|
||||
@ -813,9 +798,7 @@ TEST(SetArgPointeeTest, SetsTheNthPointee) {
|
||||
EXPECT_EQ('a', ch);
|
||||
}
|
||||
|
||||
#if !((GTEST_GCC_VER_ && GTEST_GCC_VER_ < 40000) || GTEST_OS_SYMBIAN)
|
||||
// Tests that SetArgPointee<N>() accepts a string literal.
|
||||
// GCC prior to v4.0 and the Symbian compiler do not support this.
|
||||
TEST(SetArgPointeeTest, AcceptsStringLiteral) {
|
||||
typedef void MyFunction(std::string*, const char**);
|
||||
Action<MyFunction> a = SetArgPointee<0>("hi");
|
||||
@ -849,7 +832,6 @@ TEST(SetArgPointeeTest, AcceptsWideStringLiteral) {
|
||||
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
|
||||
// Tests that SetArgPointee<N>() accepts a char pointer.
|
||||
TEST(SetArgPointeeTest, AcceptsCharPointer) {
|
||||
@ -1265,7 +1247,6 @@ TEST(ByRefTest, PrintsCorrectly) {
|
||||
EXPECT_EQ(expected.str(), actual.str());
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_UNIQUE_PTR_
|
||||
|
||||
std::unique_ptr<int> UniquePtrSource() {
|
||||
return std::unique_ptr<int>(new int(19));
|
||||
@ -1378,9 +1359,7 @@ TEST(MockMethodTest, CanTakeMoveOnlyValue) {
|
||||
EXPECT_EQ(42, *saved);
|
||||
}
|
||||
|
||||
#endif // GTEST_HAS_STD_UNIQUE_PTR_
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
// Tests for std::function based action.
|
||||
|
||||
int Add(int val, int& ref, int* ptr) { // NOLINT
|
||||
@ -1459,10 +1438,6 @@ TEST(FunctorActionTest, UnusedArguments) {
|
||||
}
|
||||
|
||||
// Test that basic built-in actions work with move-only arguments.
|
||||
// FIXME: Currently, almost all ActionInterface-based actions will not
|
||||
// work, even if they only try to use other, copyable arguments. Implement them
|
||||
// if necessary (but note that DoAll cannot work on non-copyable types anyway -
|
||||
// so maybe it's better to make users use lambdas instead.
|
||||
TEST(MoveOnlyArgumentsTest, ReturningActions) {
|
||||
Action<int(std::unique_ptr<int>)> a = Return(1);
|
||||
EXPECT_EQ(1, a.Perform(std::make_tuple(nullptr)));
|
||||
@ -1476,7 +1451,6 @@ TEST(MoveOnlyArgumentsTest, ReturningActions) {
|
||||
EXPECT_EQ(x, 3);
|
||||
}
|
||||
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
} // Unnamed namespace
|
||||
|
||||
|
@ -45,13 +45,6 @@
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
// There is a bug in MSVC (fixed in VS 2008) that prevents creating a
|
||||
// mock for a function with const arguments, so we don't test such
|
||||
// cases for MSVC versions older than 2008.
|
||||
#if !GTEST_OS_WINDOWS || (_MSC_VER >= 1500)
|
||||
# define GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
|
||||
#endif // !GTEST_OS_WINDOWS || (_MSC_VER >= 1500)
|
||||
|
||||
namespace testing {
|
||||
namespace gmock_function_mocker_test {
|
||||
|
||||
@ -84,9 +77,7 @@ class FooInterface {
|
||||
|
||||
virtual bool TakesNonConstReference(int& n) = 0; // NOLINT
|
||||
virtual std::string TakesConstReference(const int& n) = 0;
|
||||
#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
|
||||
virtual bool TakesConst(const int x) = 0;
|
||||
#endif // GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
|
||||
|
||||
virtual int OverloadedOnArgumentNumber() = 0;
|
||||
virtual int OverloadedOnArgumentNumber(int n) = 0;
|
||||
@ -137,10 +128,7 @@ class MockFoo : public FooInterface {
|
||||
|
||||
MOCK_METHOD(bool, TakesNonConstReference, (int&)); // NOLINT
|
||||
MOCK_METHOD(std::string, TakesConstReference, (const int&));
|
||||
|
||||
#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
|
||||
MOCK_METHOD(bool, TakesConst, (const int)); // NOLINT
|
||||
#endif
|
||||
|
||||
// Tests that the function return type can contain unprotected comma.
|
||||
MOCK_METHOD((std::map<int, std::string>), ReturnTypeWithComma, (), ());
|
||||
@ -248,7 +236,6 @@ TEST_F(MockMethodFunctionMockerTest, MocksFunctionWithConstReferenceArgument) {
|
||||
EXPECT_EQ("Hello", foo_->TakesConstReference(a));
|
||||
}
|
||||
|
||||
#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
|
||||
// Tests mocking a function that takes a const variable.
|
||||
TEST_F(MockMethodFunctionMockerTest, MocksFunctionWithConstArgument) {
|
||||
EXPECT_CALL(mock_foo_, TakesConst(Lt(10)))
|
||||
@ -256,7 +243,6 @@ TEST_F(MockMethodFunctionMockerTest, MocksFunctionWithConstArgument) {
|
||||
|
||||
EXPECT_FALSE(foo_->TakesConst(5));
|
||||
}
|
||||
#endif // GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
|
||||
|
||||
// Tests mocking functions overloaded on the number of arguments.
|
||||
TEST_F(MockMethodFunctionMockerTest, MocksFunctionsOverloadedOnArgumentNumber) {
|
||||
@ -598,7 +584,6 @@ TEST(MockMethodMockFunctionTest, WorksFor10Arguments) {
|
||||
EXPECT_EQ(2, foo.Call(true, 'a', 0, 0, 0, 0, 0, 'b', 1, false));
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_FUNCTION_
|
||||
TEST(MockMethodMockFunctionTest, AsStdFunction) {
|
||||
MockFunction<int(int)> foo;
|
||||
auto call = [](const std::function<int(int)> &f, int i) {
|
||||
@ -630,7 +615,6 @@ TEST(MockMethodMockFunctionTest, AsStdFunctionWithReferenceParameter) {
|
||||
EXPECT_EQ(-1, call(foo.AsStdFunction(), i));
|
||||
}
|
||||
|
||||
#endif // GTEST_HAS_STD_FUNCTION_
|
||||
|
||||
struct MockMethodSizes0 {
|
||||
MOCK_METHOD(void, func, ());
|
||||
|
@ -428,11 +428,12 @@ TEST(DoAllTest, TenActions) {
|
||||
// the macro definition, as the warnings are generated when the macro
|
||||
// is expanded and macro expansion cannot contain #pragma. Therefore
|
||||
// we suppress them here.
|
||||
// Also suppress C4503 decorated name length exceeded, name was truncated
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:4100)
|
||||
# pragma warning(disable:4503)
|
||||
#endif
|
||||
|
||||
// Tests the ACTION*() macro family.
|
||||
|
||||
// Tests that ACTION() can define an action that doesn't reference the
|
||||
@ -1058,9 +1059,6 @@ TEST(ActionTemplateTest, CanBeOverloadedOnNumberOfValueParameters) {
|
||||
EXPECT_EQ(12345, a4.Perform(std::make_tuple()));
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
} // namespace gmock_generated_actions_test
|
||||
} // namespace testing
|
||||
|
@ -582,7 +582,6 @@ TEST(MockFunctionTest, WorksFor10Arguments) {
|
||||
EXPECT_EQ(2, foo.Call(true, 'a', 0, 0, 0, 0, 0, 'b', 1, false));
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_FUNCTION_
|
||||
TEST(MockFunctionTest, AsStdFunction) {
|
||||
MockFunction<int(int)> foo;
|
||||
auto call = [](const std::function<int(int)> &f, int i) {
|
||||
@ -614,7 +613,6 @@ TEST(MockFunctionTest, AsStdFunctionWithReferenceParameter) {
|
||||
EXPECT_EQ(-1, call(foo.AsStdFunction(), i));
|
||||
}
|
||||
|
||||
#endif // GTEST_HAS_STD_FUNCTION_
|
||||
|
||||
struct MockMethodSizes0 {
|
||||
MOCK_METHOD0(func, void());
|
||||
|
@ -489,7 +489,6 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithVector) {
|
||||
EXPECT_THAT(test_vector, Not(ElementsAreArray(expected)));
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_INITIALIZER_LIST_
|
||||
|
||||
TEST(ElementsAreArrayTest, TakesInitializerList) {
|
||||
const int a[5] = { 1, 2, 3, 4, 5 };
|
||||
@ -525,7 +524,6 @@ TEST(ElementsAreArrayTest,
|
||||
{ Eq(1), Ne(-2), Ge(3), Le(4), Eq(6) })));
|
||||
}
|
||||
|
||||
#endif // GTEST_HAS_STD_INITIALIZER_LIST_
|
||||
|
||||
TEST(ElementsAreArrayTest, CanBeCreatedWithMatcherVector) {
|
||||
const int a[] = { 1, 2, 3 };
|
||||
@ -1139,7 +1137,6 @@ TEST(AnyOfTest, DoesNotCallAnyOfUnqualified) {
|
||||
|
||||
} // namespace adl_test
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
|
||||
TEST(AllOfTest, WorksOnMoveOnlyType) {
|
||||
std::unique_ptr<int> p(new int(3));
|
||||
@ -1177,7 +1174,6 @@ TEST(MatcherPMacroTest, WorksOnMoveOnlyType) {
|
||||
EXPECT_THAT(p, Not(UniquePointee(2)));
|
||||
}
|
||||
|
||||
#endif // GTEST_LASNG_CXX11
|
||||
|
||||
} // namespace
|
||||
|
||||
|
@ -123,13 +123,9 @@ TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameIsMixture) {
|
||||
}
|
||||
|
||||
TEST(PointeeOfTest, WorksForSmartPointers) {
|
||||
#if GTEST_HAS_STD_UNIQUE_PTR_
|
||||
CompileAssertTypesEqual<int, PointeeOf<std::unique_ptr<int> >::type>();
|
||||
#endif // GTEST_HAS_STD_UNIQUE_PTR_
|
||||
#if GTEST_HAS_STD_SHARED_PTR_
|
||||
CompileAssertTypesEqual<std::string,
|
||||
PointeeOf<std::shared_ptr<std::string> >::type>();
|
||||
#endif // GTEST_HAS_STD_SHARED_PTR_
|
||||
}
|
||||
|
||||
TEST(PointeeOfTest, WorksForRawPointers) {
|
||||
@ -139,21 +135,16 @@ TEST(PointeeOfTest, WorksForRawPointers) {
|
||||
}
|
||||
|
||||
TEST(GetRawPointerTest, WorksForSmartPointers) {
|
||||
#if GTEST_HAS_STD_UNIQUE_PTR_
|
||||
const char* const raw_p1 = new const char('a'); // NOLINT
|
||||
const std::unique_ptr<const char> p1(raw_p1);
|
||||
EXPECT_EQ(raw_p1, GetRawPointer(p1));
|
||||
#endif // GTEST_HAS_STD_UNIQUE_PTR_
|
||||
#if GTEST_HAS_STD_SHARED_PTR_
|
||||
double* const raw_p2 = new double(2.5); // NOLINT
|
||||
const std::shared_ptr<double> p2(raw_p2);
|
||||
EXPECT_EQ(raw_p2, GetRawPointer(p2));
|
||||
#endif // GTEST_HAS_STD_SHARED_PTR_
|
||||
}
|
||||
|
||||
TEST(GetRawPointerTest, WorksForRawPointers) {
|
||||
int* p = nullptr;
|
||||
// Don't use EXPECT_EQ as no NULL-testing magic on Symbian.
|
||||
EXPECT_TRUE(nullptr == GetRawPointer(p));
|
||||
int n = 1;
|
||||
EXPECT_EQ(&n, GetRawPointer(&n));
|
||||
@ -529,12 +520,6 @@ TEST(TypeTraitsTest, is_reference) {
|
||||
EXPECT_TRUE(is_reference<const int&>::value);
|
||||
}
|
||||
|
||||
TEST(TypeTraitsTest, is_pointer) {
|
||||
EXPECT_FALSE(is_pointer<int>::value);
|
||||
EXPECT_FALSE(is_pointer<char&>::value);
|
||||
EXPECT_TRUE(is_pointer<const int*>::value);
|
||||
}
|
||||
|
||||
TEST(TypeTraitsTest, type_equals) {
|
||||
EXPECT_FALSE((type_equals<int, const int>::value));
|
||||
EXPECT_FALSE((type_equals<int, int&>::value));
|
||||
|
@ -46,6 +46,7 @@
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <deque>
|
||||
#include <forward_list>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
@ -56,22 +57,16 @@
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "gtest/gtest-spi.h"
|
||||
|
||||
#if GTEST_HAS_STD_FORWARD_LIST_
|
||||
# include <forward_list> // NOLINT
|
||||
#endif
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
# include <type_traits>
|
||||
#endif
|
||||
|
||||
namespace testing {
|
||||
namespace gmock_matchers_test {
|
||||
namespace {
|
||||
|
||||
using std::greater;
|
||||
using std::less;
|
||||
@ -158,6 +153,19 @@ using testing::internal::StreamMatchResultListener;
|
||||
using testing::internal::string;
|
||||
using testing::internal::Strings;
|
||||
|
||||
// Helper for testing container-valued matchers in mock method context. It is
|
||||
// important to test matchers in this context, since it requires additional type
|
||||
// deduction beyond what EXPECT_THAT does, thus making it more restrictive.
|
||||
struct ContainerHelper {
|
||||
MOCK_METHOD1(Call, void(std::vector<std::unique_ptr<int>>));
|
||||
};
|
||||
|
||||
std::vector<std::unique_ptr<int>> MakeUniquePtrs(const std::vector<int>& ints) {
|
||||
std::vector<std::unique_ptr<int>> pointers;
|
||||
for (int i : ints) pointers.emplace_back(new int(i));
|
||||
return pointers;
|
||||
}
|
||||
|
||||
// For testing ExplainMatchResultTo().
|
||||
class GreaterThanMatcher : public MatcherInterface<int> {
|
||||
public:
|
||||
@ -1159,30 +1167,18 @@ TEST(IsNullTest, MatchesNullPointer) {
|
||||
EXPECT_TRUE(m2.Matches(p2));
|
||||
EXPECT_FALSE(m2.Matches("hi"));
|
||||
|
||||
#if !GTEST_OS_SYMBIAN
|
||||
// Nokia's Symbian compiler generates:
|
||||
// gmock-matchers.h: ambiguous access to overloaded function
|
||||
// gmock-matchers.h: 'testing::Matcher<void *>::Matcher(void *)'
|
||||
// gmock-matchers.h: 'testing::Matcher<void *>::Matcher(const testing::
|
||||
// MatcherInterface<void *> *)'
|
||||
// gmock-matchers.h: (point of instantiation: 'testing::
|
||||
// gmock_matchers_test::IsNullTest_MatchesNullPointer_Test::TestBody()')
|
||||
// gmock-matchers.h: (instantiating: 'testing::PolymorphicMatc
|
||||
Matcher<void*> m3 = IsNull();
|
||||
void* p3 = nullptr;
|
||||
EXPECT_TRUE(m3.Matches(p3));
|
||||
EXPECT_FALSE(m3.Matches(reinterpret_cast<void*>(0xbeef)));
|
||||
#endif
|
||||
}
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
TEST(IsNullTest, StdFunction) {
|
||||
const Matcher<std::function<void()>> m = IsNull();
|
||||
|
||||
EXPECT_TRUE(m.Matches(std::function<void()>()));
|
||||
EXPECT_FALSE(m.Matches([]{}));
|
||||
}
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
// Tests that IsNull() describes itself properly.
|
||||
TEST(IsNullTest, CanDescribeSelf) {
|
||||
@ -1223,14 +1219,12 @@ TEST(NotNullTest, ReferenceToConstLinkedPtr) {
|
||||
EXPECT_TRUE(m.Matches(non_null_p));
|
||||
}
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
TEST(NotNullTest, StdFunction) {
|
||||
const Matcher<std::function<void()>> m = NotNull();
|
||||
|
||||
EXPECT_TRUE(m.Matches([]{}));
|
||||
EXPECT_FALSE(m.Matches(std::function<void()>()));
|
||||
}
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
// Tests that NotNull() describes itself properly.
|
||||
TEST(NotNullTest, CanDescribeSelf) {
|
||||
@ -1513,7 +1507,6 @@ TEST(KeyTest, MatchesCorrectly) {
|
||||
EXPECT_THAT(p, Not(Key(Lt(25))));
|
||||
}
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
template <size_t I>
|
||||
struct Tag {};
|
||||
|
||||
@ -1540,7 +1533,6 @@ TEST(PairTest, MatchesPairWithGetCorrectly) {
|
||||
std::vector<PairWithGet> v = {{11, "Foo"}, {29, "gMockIsBestMock"}};
|
||||
EXPECT_THAT(v, Contains(Key(29)));
|
||||
}
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
TEST(KeyTest, SafelyCastsInnerMatcher) {
|
||||
Matcher<int> is_positive = Gt(0);
|
||||
@ -1679,7 +1671,12 @@ TEST(PairTest, InsideContainsUsingMap) {
|
||||
EXPECT_THAT(container, Not(Contains(Pair(3, _))));
|
||||
}
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
TEST(ContainsTest, WorksWithMoveOnly) {
|
||||
ContainerHelper helper;
|
||||
EXPECT_CALL(helper, Call(Contains(Pointee(2))));
|
||||
helper.Call(MakeUniquePtrs({1, 2}));
|
||||
}
|
||||
|
||||
TEST(PairTest, UseGetInsteadOfMembers) {
|
||||
PairWithGet pair{7, "ABC"};
|
||||
EXPECT_THAT(pair, Pair(7, "ABC"));
|
||||
@ -1689,7 +1686,6 @@ TEST(PairTest, UseGetInsteadOfMembers) {
|
||||
std::vector<PairWithGet> v = {{11, "Foo"}, {29, "gMockIsBestMock"}};
|
||||
EXPECT_THAT(v, ElementsAre(Pair(11, string("Foo")), Pair(Ge(10), Not(""))));
|
||||
}
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
// Tests StartsWith(s).
|
||||
|
||||
@ -2660,7 +2656,6 @@ static void AnyOfMatches(int num, const Matcher<int>& m) {
|
||||
EXPECT_FALSE(m.Matches(num + 1));
|
||||
}
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
static void AnyOfStringMatches(int num, const Matcher<std::string>& m) {
|
||||
SCOPED_TRACE(Describe(m));
|
||||
EXPECT_FALSE(m.Matches(std::to_string(0)));
|
||||
@ -2670,7 +2665,6 @@ static void AnyOfStringMatches(int num, const Matcher<std::string>& m) {
|
||||
}
|
||||
EXPECT_FALSE(m.Matches(std::to_string(num + 1)));
|
||||
}
|
||||
#endif
|
||||
|
||||
// Tests that AnyOf(m1, ..., mn) matches any value that matches at
|
||||
// least one of the given matchers.
|
||||
@ -2715,7 +2709,6 @@ TEST(AnyOfTest, MatchesWhenAnyMatches) {
|
||||
AnyOfMatches(10, AnyOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
|
||||
}
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
// Tests the variadic version of the AnyOfMatcher.
|
||||
TEST(AnyOfTest, VariadicMatchesWhenAnyMatches) {
|
||||
// Also make sure AnyOf is defined in the right namespace and does not depend
|
||||
@ -2764,7 +2757,6 @@ TEST(ElementsAreTest, HugeMatcherUnordered) {
|
||||
Eq(3), Eq(9), Eq(12), Eq(11), Ne(122)));
|
||||
}
|
||||
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
// Tests that AnyOf(m1, ..., mn) describes itself properly.
|
||||
TEST(AnyOfTest, CanDescribeSelf) {
|
||||
@ -3166,20 +3158,8 @@ TEST(MatcherAssertionTest, WorksForByRefArguments) {
|
||||
"Actual: 0" + OfType("int") + ", which is located @");
|
||||
}
|
||||
|
||||
#if !GTEST_OS_SYMBIAN
|
||||
// Tests that ASSERT_THAT() and EXPECT_THAT() work when the matcher is
|
||||
// monomorphic.
|
||||
|
||||
// ASSERT_THAT("hello", starts_with_he) fails to compile with Nokia's
|
||||
// Symbian compiler: it tries to compile
|
||||
// template<T, U> class MatcherCastImpl { ...
|
||||
// virtual bool MatchAndExplain(T x, ...) const {
|
||||
// return source_matcher_.MatchAndExplain(static_cast<U>(x), ...);
|
||||
// with U == string and T == const char*
|
||||
// With ASSERT_THAT("hello"...) changed to ASSERT_THAT(string("hello") ... )
|
||||
// the compiler silently crashes with no output.
|
||||
// If MatcherCastImpl is changed to use U(x) instead of static_cast<U>(x)
|
||||
// the code compiles but the converted string is bogus.
|
||||
TEST(MatcherAssertionTest, WorksForMonomorphicMatcher) {
|
||||
Matcher<const char*> starts_with_he = StartsWith("he");
|
||||
ASSERT_THAT("hello", starts_with_he);
|
||||
@ -3197,7 +3177,6 @@ TEST(MatcherAssertionTest, WorksForMonomorphicMatcher) {
|
||||
"Expected: is > 5\n"
|
||||
" Actual: 5" + OfType("int"));
|
||||
}
|
||||
#endif // !GTEST_OS_SYMBIAN
|
||||
|
||||
// Tests floating-point matchers.
|
||||
template <typename RawType>
|
||||
@ -4135,9 +4114,7 @@ class AClass {
|
||||
// A getter that returns a reference to const.
|
||||
const std::string& s() const { return s_; }
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
const std::string& s_ref() const & { return s_; }
|
||||
#endif
|
||||
|
||||
void set_s(const std::string& new_s) { s_ = new_s; }
|
||||
|
||||
@ -4194,7 +4171,6 @@ TEST(PropertyTest, WorksForReferenceToConstProperty) {
|
||||
EXPECT_FALSE(m_with_name.Matches(a));
|
||||
}
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
// Tests that Property(&Foo::property, ...) works when property() is
|
||||
// ref-qualified.
|
||||
TEST(PropertyTest, WorksForRefQualifiedProperty) {
|
||||
@ -4211,7 +4187,6 @@ TEST(PropertyTest, WorksForRefQualifiedProperty) {
|
||||
EXPECT_FALSE(m.Matches(a));
|
||||
EXPECT_FALSE(m_with_name.Matches(a));
|
||||
}
|
||||
#endif
|
||||
|
||||
// Tests that Property(&Foo::property, ...) works when property()
|
||||
// returns a reference to non-const.
|
||||
@ -4574,7 +4549,6 @@ TEST(ResultOfTest, WorksForPolymorphicFunctors) {
|
||||
EXPECT_FALSE(matcher_string.Matches("shrt"));
|
||||
}
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
TEST(ResultOfTest, WorksForPolymorphicFunctorsIgnoringResultType) {
|
||||
Matcher<int*> matcher = ResultOf(PolymorphicFunctor(), "good ptr");
|
||||
|
||||
@ -4589,7 +4563,6 @@ TEST(ResultOfTest, WorksForLambdas) {
|
||||
EXPECT_TRUE(matcher.Matches(3));
|
||||
EXPECT_FALSE(matcher.Matches(1));
|
||||
}
|
||||
#endif
|
||||
|
||||
const int* ReferencingFunction(const int& n) { return &n; }
|
||||
|
||||
@ -4752,6 +4725,12 @@ TEST(IsEmptyTest, ExplainsResult) {
|
||||
EXPECT_EQ("whose size is 1", Explain(m, container));
|
||||
}
|
||||
|
||||
TEST(IsEmptyTest, WorksWithMoveOnly) {
|
||||
ContainerHelper helper;
|
||||
EXPECT_CALL(helper, Call(IsEmpty()));
|
||||
helper.Call({});
|
||||
}
|
||||
|
||||
TEST(IsTrueTest, IsTrueIsFalse) {
|
||||
EXPECT_THAT(true, IsTrue());
|
||||
EXPECT_THAT(false, IsFalse());
|
||||
@ -4774,7 +4753,6 @@ TEST(IsTrueTest, IsTrueIsFalse) {
|
||||
EXPECT_THAT(&a, Not(IsFalse()));
|
||||
EXPECT_THAT(false, Not(IsTrue()));
|
||||
EXPECT_THAT(true, Not(IsFalse()));
|
||||
#if GTEST_LANG_CXX11
|
||||
EXPECT_THAT(std::true_type(), IsTrue());
|
||||
EXPECT_THAT(std::true_type(), Not(IsFalse()));
|
||||
EXPECT_THAT(std::false_type(), IsFalse());
|
||||
@ -4787,7 +4765,6 @@ TEST(IsTrueTest, IsTrueIsFalse) {
|
||||
EXPECT_THAT(null_unique, IsFalse());
|
||||
EXPECT_THAT(nonnull_unique, IsTrue());
|
||||
EXPECT_THAT(nonnull_unique, Not(IsFalse()));
|
||||
#endif // GTEST_LANG_CXX11
|
||||
}
|
||||
|
||||
TEST(SizeIsTest, ImplementsSizeIs) {
|
||||
@ -4822,6 +4799,12 @@ TEST(SizeIsTest, WorksWithReferences) {
|
||||
EXPECT_THAT(container, m);
|
||||
}
|
||||
|
||||
TEST(SizeIsTest, WorksWithMoveOnly) {
|
||||
ContainerHelper helper;
|
||||
EXPECT_CALL(helper, Call(SizeIs(3)));
|
||||
helper.Call(MakeUniquePtrs({1, 2, 3}));
|
||||
}
|
||||
|
||||
// SizeIs should work for any type that provides a size() member function.
|
||||
// For example, a size_type member type should not need to be provided.
|
||||
struct MinimalistCustomType {
|
||||
@ -5281,7 +5264,6 @@ TEST(StreamlikeTest, Iteration) {
|
||||
}
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_FORWARD_LIST_
|
||||
TEST(BeginEndDistanceIsTest, WorksWithForwardList) {
|
||||
std::forward_list<int> container;
|
||||
EXPECT_THAT(container, BeginEndDistanceIs(0));
|
||||
@ -5293,7 +5275,6 @@ TEST(BeginEndDistanceIsTest, WorksWithForwardList) {
|
||||
EXPECT_THAT(container, Not(BeginEndDistanceIs(0)));
|
||||
EXPECT_THAT(container, BeginEndDistanceIs(2));
|
||||
}
|
||||
#endif // GTEST_HAS_STD_FORWARD_LIST_
|
||||
|
||||
TEST(BeginEndDistanceIsTest, WorksWithNonStdList) {
|
||||
const int a[5] = {1, 2, 3, 4, 5};
|
||||
@ -5308,6 +5289,12 @@ TEST(BeginEndDistanceIsTest, CanDescribeSelf) {
|
||||
DescribeNegation(m));
|
||||
}
|
||||
|
||||
TEST(BeginEndDistanceIsTest, WorksWithMoveOnly) {
|
||||
ContainerHelper helper;
|
||||
EXPECT_CALL(helper, Call(BeginEndDistanceIs(2)));
|
||||
helper.Call(MakeUniquePtrs({1, 2}));
|
||||
}
|
||||
|
||||
TEST(BeginEndDistanceIsTest, ExplainsResult) {
|
||||
Matcher<vector<int> > m1 = BeginEndDistanceIs(2);
|
||||
Matcher<vector<int> > m2 = BeginEndDistanceIs(Lt(2));
|
||||
@ -5469,13 +5456,19 @@ TEST(IsSupersetOfTest, MatchAndExplain) {
|
||||
" - element #2 is matched by matcher #0"));
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_INITIALIZER_LIST_
|
||||
TEST(IsSupersetOfTest, WorksForRhsInitializerList) {
|
||||
const int numbers[] = {1, 3, 6, 2, 4, 5};
|
||||
EXPECT_THAT(numbers, IsSupersetOf({1, 2}));
|
||||
EXPECT_THAT(numbers, Not(IsSupersetOf({3, 0})));
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST(IsSupersetOfTest, WorksWithMoveOnly) {
|
||||
ContainerHelper helper;
|
||||
EXPECT_CALL(helper, Call(IsSupersetOf({Pointee(1)})));
|
||||
helper.Call(MakeUniquePtrs({1, 2}));
|
||||
EXPECT_CALL(helper, Call(Not(IsSupersetOf({Pointee(1), Pointee(2)}))));
|
||||
helper.Call(MakeUniquePtrs({2}));
|
||||
}
|
||||
|
||||
TEST(IsSubsetOfTest, WorksForNativeArray) {
|
||||
const int subset[] = {1, 4};
|
||||
@ -5591,13 +5584,19 @@ TEST(IsSubsetOfTest, MatchAndExplain) {
|
||||
" - element #1 is matched by matcher #2"));
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_INITIALIZER_LIST_
|
||||
TEST(IsSubsetOfTest, WorksForRhsInitializerList) {
|
||||
const int numbers[] = {1, 2, 3};
|
||||
EXPECT_THAT(numbers, IsSubsetOf({1, 2, 3, 4}));
|
||||
EXPECT_THAT(numbers, Not(IsSubsetOf({1, 2})));
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST(IsSubsetOfTest, WorksWithMoveOnly) {
|
||||
ContainerHelper helper;
|
||||
EXPECT_CALL(helper, Call(IsSubsetOf({Pointee(1), Pointee(2)})));
|
||||
helper.Call(MakeUniquePtrs({1}));
|
||||
EXPECT_CALL(helper, Call(Not(IsSubsetOf({Pointee(1)}))));
|
||||
helper.Call(MakeUniquePtrs({2}));
|
||||
}
|
||||
|
||||
// Tests using ElementsAre() and ElementsAreArray() with stream-like
|
||||
// "containers".
|
||||
@ -5632,6 +5631,15 @@ TEST(ElementsAreTest, WorksWithUncopyable) {
|
||||
EXPECT_THAT(objs, ElementsAre(UncopyableIs(-3), Truly(ValueIsPositive)));
|
||||
}
|
||||
|
||||
TEST(ElementsAreTest, WorksWithMoveOnly) {
|
||||
ContainerHelper helper;
|
||||
EXPECT_CALL(helper, Call(ElementsAre(Pointee(1), Pointee(2))));
|
||||
helper.Call(MakeUniquePtrs({1, 2}));
|
||||
|
||||
EXPECT_CALL(helper, Call(ElementsAreArray({Pointee(3), Pointee(4)})));
|
||||
helper.Call(MakeUniquePtrs({3, 4}));
|
||||
}
|
||||
|
||||
TEST(ElementsAreTest, TakesStlContainer) {
|
||||
const int actual[] = {3, 1, 2};
|
||||
|
||||
@ -5699,7 +5707,6 @@ TEST(UnorderedElementsAreArrayTest, TakesStlContainer) {
|
||||
EXPECT_THAT(actual, Not(UnorderedElementsAreArray(expected)));
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_INITIALIZER_LIST_
|
||||
|
||||
TEST(UnorderedElementsAreArrayTest, TakesInitializerList) {
|
||||
const int a[5] = {2, 1, 4, 5, 3};
|
||||
@ -5733,7 +5740,13 @@ TEST(UnorderedElementsAreArrayTest,
|
||||
{Eq(1), Ne(-2), Ge(3), Le(4), Eq(6)})));
|
||||
}
|
||||
|
||||
#endif // GTEST_HAS_STD_INITIALIZER_LIST_
|
||||
|
||||
TEST(UnorderedElementsAreArrayTest, WorksWithMoveOnly) {
|
||||
ContainerHelper helper;
|
||||
EXPECT_CALL(helper,
|
||||
Call(UnorderedElementsAreArray({Pointee(1), Pointee(2)})));
|
||||
helper.Call(MakeUniquePtrs({2, 1}));
|
||||
}
|
||||
|
||||
class UnorderedElementsAreTest : public testing::Test {
|
||||
protected:
|
||||
@ -5782,6 +5795,12 @@ TEST_F(UnorderedElementsAreTest, WorksForStreamlike) {
|
||||
EXPECT_THAT(s, Not(UnorderedElementsAre(2, 2, 3, 4, 5)));
|
||||
}
|
||||
|
||||
TEST_F(UnorderedElementsAreTest, WorksWithMoveOnly) {
|
||||
ContainerHelper helper;
|
||||
EXPECT_CALL(helper, Call(UnorderedElementsAre(Pointee(1), Pointee(2))));
|
||||
helper.Call(MakeUniquePtrs({2, 1}));
|
||||
}
|
||||
|
||||
// One naive implementation of the matcher runs in O(N!) time, which is too
|
||||
// slow for many real-world inputs. This test shows that our matcher can match
|
||||
// 100 inputs very quickly (a few milliseconds). An O(100!) is 10^158
|
||||
@ -6332,6 +6351,12 @@ TEST(EachTest, WorksForNativeArrayAsTuple) {
|
||||
EXPECT_THAT(std::make_tuple(pointer, 2), Not(Each(Gt(1))));
|
||||
}
|
||||
|
||||
TEST(EachTest, WorksWithMoveOnly) {
|
||||
ContainerHelper helper;
|
||||
EXPECT_CALL(helper, Call(Each(Pointee(Gt(0)))));
|
||||
helper.Call(MakeUniquePtrs({1, 2}));
|
||||
}
|
||||
|
||||
// For testing Pointwise().
|
||||
class IsHalfOfMatcher {
|
||||
public:
|
||||
@ -6419,7 +6444,6 @@ TEST(PointwiseTest, WorksForVectorOfBool) {
|
||||
EXPECT_THAT(lhs, Not(Pointwise(Eq(), rhs)));
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_INITIALIZER_LIST_
|
||||
|
||||
TEST(PointwiseTest, WorksForRhsInitializerList) {
|
||||
const vector<int> lhs{2, 4, 6};
|
||||
@ -6427,7 +6451,6 @@ TEST(PointwiseTest, WorksForRhsInitializerList) {
|
||||
EXPECT_THAT(lhs, Not(Pointwise(Lt(), {3, 3, 7})));
|
||||
}
|
||||
|
||||
#endif // GTEST_HAS_STD_INITIALIZER_LIST_
|
||||
|
||||
TEST(PointwiseTest, RejectsWrongSize) {
|
||||
const double lhs[2] = {1, 2};
|
||||
@ -6470,6 +6493,17 @@ TEST(PointwiseTest, AllowsMonomorphicInnerMatcher) {
|
||||
EXPECT_EQ("", Explain(Pointwise(m2, rhs), lhs));
|
||||
}
|
||||
|
||||
MATCHER(PointeeEquals, "Points to an equal value") {
|
||||
return ExplainMatchResult(::testing::Pointee(::testing::get<1>(arg)),
|
||||
::testing::get<0>(arg), result_listener);
|
||||
}
|
||||
|
||||
TEST(PointwiseTest, WorksWithMoveOnly) {
|
||||
ContainerHelper helper;
|
||||
EXPECT_CALL(helper, Call(Pointwise(PointeeEquals(), std::vector<int>{1, 2})));
|
||||
helper.Call(MakeUniquePtrs({1, 2}));
|
||||
}
|
||||
|
||||
TEST(UnorderedPointwiseTest, DescribesSelf) {
|
||||
vector<int> rhs;
|
||||
rhs.push_back(1);
|
||||
@ -6530,7 +6564,6 @@ TEST(UnorderedPointwiseTest, WorksForRhsNativeArray) {
|
||||
EXPECT_THAT(lhs, Not(UnorderedPointwise(Lt(), rhs)));
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_INITIALIZER_LIST_
|
||||
|
||||
TEST(UnorderedPointwiseTest, WorksForRhsInitializerList) {
|
||||
const vector<int> lhs{2, 4, 6};
|
||||
@ -6538,7 +6571,6 @@ TEST(UnorderedPointwiseTest, WorksForRhsInitializerList) {
|
||||
EXPECT_THAT(lhs, Not(UnorderedPointwise(Lt(), {1, 1, 7})));
|
||||
}
|
||||
|
||||
#endif // GTEST_HAS_STD_INITIALIZER_LIST_
|
||||
|
||||
TEST(UnorderedPointwiseTest, RejectsWrongSize) {
|
||||
const double lhs[2] = {1, 2};
|
||||
@ -6584,6 +6616,13 @@ TEST(UnorderedPointwiseTest, AllowsMonomorphicInnerMatcher) {
|
||||
EXPECT_THAT(lhs, UnorderedPointwise(m2, rhs));
|
||||
}
|
||||
|
||||
TEST(UnorderedPointwiseTest, WorksWithMoveOnly) {
|
||||
ContainerHelper helper;
|
||||
EXPECT_CALL(helper, Call(UnorderedPointwise(PointeeEquals(),
|
||||
std::vector<int>{1, 2})));
|
||||
helper.Call(MakeUniquePtrs({2, 1}));
|
||||
}
|
||||
|
||||
// Sample optional type implementation with minimal requirements for use with
|
||||
// Optional matcher.
|
||||
class SampleOptionalInt {
|
||||
@ -6724,7 +6763,6 @@ TEST(AnyWithTest, TestBadCastType) {
|
||||
EXPECT_FALSE(m.Matches(SampleAnyType(1)));
|
||||
}
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
TEST(AnyWithTest, TestUseInContainers) {
|
||||
std::vector<SampleAnyType> a;
|
||||
a.emplace_back(1);
|
||||
@ -6741,7 +6779,6 @@ TEST(AnyWithTest, TestUseInContainers) {
|
||||
AnyWith<std::string>("merhaba"),
|
||||
AnyWith<std::string>("salut")}));
|
||||
}
|
||||
#endif // GTEST_LANG_CXX11
|
||||
TEST(AnyWithTest, TestCompare) {
|
||||
EXPECT_THAT(SampleAnyType(1), AnyWith<int>(Gt(0)));
|
||||
}
|
||||
@ -6976,8 +7013,7 @@ TEST_F(PredicateFormatterFromMatcherTest, NoShortCircuitOnFailure) {
|
||||
EXPECT_FALSE(result); // Implicit cast to bool.
|
||||
std::string expect =
|
||||
"Value of: dummy-name\nExpected: [DescribeTo]\n"
|
||||
" Actual: 1" +
|
||||
OfType(kMatcherType) + ", [MatchAndExplain]";
|
||||
" Actual: 1, [MatchAndExplain]";
|
||||
EXPECT_EQ(expect, result.message());
|
||||
}
|
||||
|
||||
@ -6988,11 +7024,11 @@ TEST_F(PredicateFormatterFromMatcherTest, DetectsFlakyShortCircuit) {
|
||||
"Value of: dummy-name\nExpected: [DescribeTo]\n"
|
||||
" The matcher failed on the initial attempt; but passed when rerun to "
|
||||
"generate the explanation.\n"
|
||||
" Actual: 2" +
|
||||
OfType(kMatcherType) + ", [MatchAndExplain]";
|
||||
" Actual: 2, [MatchAndExplain]";
|
||||
EXPECT_EQ(expect, result.message());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace gmock_matchers_test
|
||||
} // namespace testing
|
||||
|
||||
|
@ -27,8 +27,7 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
#include "gmock/gmock-generated-nice-strict.h"
|
||||
#include "gmock/gmock-nice-strict.h"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
@ -114,23 +113,22 @@ class MockBar {
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockBar);
|
||||
};
|
||||
|
||||
#if GTEST_GTEST_LANG_CXX11
|
||||
|
||||
class MockBaz {
|
||||
public:
|
||||
class MoveOnly {
|
||||
public:
|
||||
MoveOnly() = default;
|
||||
|
||||
MoveOnly(const MoveOnly&) = delete;
|
||||
operator=(const MoveOnly&) = delete;
|
||||
MoveOnly& operator=(const MoveOnly&) = delete;
|
||||
|
||||
MoveOnly(MoveOnly&&) = default;
|
||||
operator=(MoveOnly&&) = default;
|
||||
MoveOnly& operator=(MoveOnly&&) = default;
|
||||
};
|
||||
|
||||
MockBaz(MoveOnly) {}
|
||||
}
|
||||
#endif // GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
|
||||
};
|
||||
|
||||
#if GTEST_HAS_STREAM_REDIRECTION
|
||||
|
||||
@ -292,29 +290,17 @@ TEST(NiceMockTest, AllowLeak) {
|
||||
leaked->DoThis();
|
||||
}
|
||||
|
||||
#if GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
|
||||
|
||||
TEST(NiceMockTest, MoveOnlyConstructor) {
|
||||
NiceMock<MockBaz> nice_baz(MockBaz::MoveOnly());
|
||||
NiceMock<MockBaz> nice_baz(MockBaz::MoveOnly{});
|
||||
}
|
||||
|
||||
#endif // GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
|
||||
|
||||
#if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
|
||||
// Tests that NiceMock<Mock> compiles where Mock is a user-defined
|
||||
// class (as opposed to ::testing::Mock). We had to work around an
|
||||
// MSVC 8.0 bug that caused the symbol Mock used in the definition of
|
||||
// NiceMock to be looked up in the wrong context, and this test
|
||||
// ensures that our fix works.
|
||||
//
|
||||
// We have to skip this test on Symbian and Windows Mobile, as it
|
||||
// causes the program to crash there, for reasons unclear to us yet.
|
||||
// class (as opposed to ::testing::Mock).
|
||||
TEST(NiceMockTest, AcceptsClassNamedMock) {
|
||||
NiceMock< ::Mock> nice;
|
||||
EXPECT_CALL(nice, DoThis());
|
||||
nice.DoThis();
|
||||
}
|
||||
#endif // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
|
||||
|
||||
TEST(NiceMockTest, IsNaggy_IsNice_IsStrict) {
|
||||
NiceMock<MockFoo> nice_foo;
|
||||
@ -407,29 +393,17 @@ TEST(NaggyMockTest, AllowLeak) {
|
||||
leaked->DoThis();
|
||||
}
|
||||
|
||||
#if GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
|
||||
|
||||
TEST(NaggyMockTest, MoveOnlyConstructor) {
|
||||
NaggyMock<MockBaz> naggy_baz(MockBaz::MoveOnly());
|
||||
NaggyMock<MockBaz> naggy_baz(MockBaz::MoveOnly{});
|
||||
}
|
||||
|
||||
#endif // GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
|
||||
|
||||
#if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
|
||||
// Tests that NaggyMock<Mock> compiles where Mock is a user-defined
|
||||
// class (as opposed to ::testing::Mock). We had to work around an
|
||||
// MSVC 8.0 bug that caused the symbol Mock used in the definition of
|
||||
// NaggyMock to be looked up in the wrong context, and this test
|
||||
// ensures that our fix works.
|
||||
//
|
||||
// We have to skip this test on Symbian and Windows Mobile, as it
|
||||
// causes the program to crash there, for reasons unclear to us yet.
|
||||
// class (as opposed to ::testing::Mock).
|
||||
TEST(NaggyMockTest, AcceptsClassNamedMock) {
|
||||
NaggyMock< ::Mock> naggy;
|
||||
EXPECT_CALL(naggy, DoThis());
|
||||
naggy.DoThis();
|
||||
}
|
||||
#endif // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
|
||||
|
||||
TEST(NaggyMockTest, IsNaggy_IsNice_IsStrict) {
|
||||
NaggyMock<MockFoo> naggy_foo;
|
||||
@ -503,29 +477,17 @@ TEST(StrictMockTest, AllowLeak) {
|
||||
leaked->DoThis();
|
||||
}
|
||||
|
||||
#if GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
|
||||
|
||||
TEST(StrictMockTest, MoveOnlyConstructor) {
|
||||
StrictMock<MockBaz> strict_baz(MockBaz::MoveOnly());
|
||||
StrictMock<MockBaz> strict_baz(MockBaz::MoveOnly{});
|
||||
}
|
||||
|
||||
#endif // GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
|
||||
|
||||
#if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
|
||||
// Tests that StrictMock<Mock> compiles where Mock is a user-defined
|
||||
// class (as opposed to ::testing::Mock). We had to work around an
|
||||
// MSVC 8.0 bug that caused the symbol Mock used in the definition of
|
||||
// StrictMock to be looked up in the wrong context, and this test
|
||||
// ensures that our fix works.
|
||||
//
|
||||
// We have to skip this test on Symbian and Windows Mobile, as it
|
||||
// causes the program to crash there, for reasons unclear to us yet.
|
||||
// class (as opposed to ::testing::Mock).
|
||||
TEST(StrictMockTest, AcceptsClassNamedMock) {
|
||||
StrictMock< ::Mock> strict;
|
||||
EXPECT_CALL(strict, DoThis());
|
||||
strict.DoThis();
|
||||
}
|
||||
#endif // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
|
||||
|
||||
TEST(StrictMockTest, IsNaggy_IsNice_IsStrict) {
|
||||
StrictMock<MockFoo> strict_foo;
|
||||
|
@ -751,7 +751,7 @@ necessary.
|
||||
### Death Test Naming
|
||||
|
||||
IMPORTANT: We strongly recommend you to follow the convention of naming your
|
||||
**test case** (not test) `*DeathTest` when it contains a death test, as
|
||||
**test suite** (not test) `*DeathTest` when it contains a death test, as
|
||||
demonstrated in the above example. The [Death Tests And
|
||||
Threads](#death-tests-and-threads) section below explains why.
|
||||
|
||||
@ -865,7 +865,7 @@ googletest has three features intended to raise awareness of threading issues.
|
||||
|
||||
1. A warning is emitted if multiple threads are running when a death test is
|
||||
encountered.
|
||||
2. Test cases with a name ending in "DeathTest" are run before all other tests.
|
||||
2. Test suites with a name ending in "DeathTest" are run before all other tests.
|
||||
3. It uses `clone()` instead of `fork()` to spawn the child process on Linux
|
||||
(`clone()` is not available on Cygwin and Mac), as `fork()` is more likely
|
||||
to cause the child to hang when the parent process has multiple threads.
|
||||
@ -1174,15 +1174,15 @@ will output XML like this:
|
||||
> ones already used by googletest (`name`, `status`, `time`, `classname`,
|
||||
> `type_param`, and `value_param`).
|
||||
> * Calling `RecordProperty()` outside of the lifespan of a test is allowed.
|
||||
> If it's called outside of a test but between a test case's
|
||||
> `SetUpTestCase()` and `TearDownTestCase()` methods, it will be attributed
|
||||
> to the XML element for the test case. If it's called outside of all test
|
||||
> cases (e.g. in a test environment), it will be attributed to the top-level
|
||||
> If it's called outside of a test but between a test suite's
|
||||
> `SetUpTestSuite()` and `TearDownTestSuite()` methods, it will be attributed
|
||||
> to the XML element for the test suite. If it's called outside of all test
|
||||
> suites (e.g. in a test environment), it will be attributed to the top-level
|
||||
> XML element.
|
||||
|
||||
**Availability**: Linux, Windows, Mac.
|
||||
|
||||
## Sharing Resources Between Tests in the Same Test Case
|
||||
## Sharing Resources Between Tests in the Same Test Suite
|
||||
|
||||
googletest creates a new test fixture object for each test in order to make
|
||||
tests independent and easier to debug. However, sometimes tests use resources
|
||||
@ -1191,20 +1191,20 @@ expensive.
|
||||
|
||||
If the tests don't change the resource, there's no harm in their sharing a
|
||||
single resource copy. So, in addition to per-test set-up/tear-down, googletest
|
||||
also supports per-test-case set-up/tear-down. To use it:
|
||||
also supports per-test-suite set-up/tear-down. To use it:
|
||||
|
||||
1. In your test fixture class (say `FooTest` ), declare as `static` some member
|
||||
variables to hold the shared resources.
|
||||
1. Outside your test fixture class (typically just below it), define those
|
||||
member variables, optionally giving them initial values.
|
||||
1. In the same test fixture class, define a `static void SetUpTestCase()`
|
||||
function (remember not to spell it as **`SetupTestCase`** with a small `u`!)
|
||||
to set up the shared resources and a `static void TearDownTestCase()`
|
||||
1. In the same test fixture class, define a `static void SetUpTestSuite()`
|
||||
function (remember not to spell it as **`SetUpTestSuite`** with a small `u`!)
|
||||
to set up the shared resources and a `static void TearDownTestSuite()`
|
||||
function to tear them down.
|
||||
|
||||
That's it! googletest automatically calls `SetUpTestCase()` before running the
|
||||
*first test* in the `FooTest` test case (i.e. before creating the first
|
||||
`FooTest` object), and calls `TearDownTestCase()` after running the *last test*
|
||||
That's it! googletest automatically calls `SetUpTestSuite()` before running the
|
||||
*first test* in the `FooTest` test suite (i.e. before creating the first
|
||||
`FooTest` object), and calls `TearDownTestSuite()` after running the *last test*
|
||||
in it (i.e. after deleting the last `FooTest` object). In between, the tests can
|
||||
use the shared resources.
|
||||
|
||||
@ -1213,22 +1213,22 @@ preceding or following another. Also, the tests must either not modify the state
|
||||
of any shared resource, or, if they do modify the state, they must restore the
|
||||
state to its original value before passing control to the next test.
|
||||
|
||||
Here's an example of per-test-case set-up and tear-down:
|
||||
Here's an example of per-test-suite set-up and tear-down:
|
||||
|
||||
```c++
|
||||
class FooTest : public ::testing::Test {
|
||||
protected:
|
||||
// Per-test-case set-up.
|
||||
// Called before the first test in this test case.
|
||||
// Per-test-suite set-up.
|
||||
// Called before the first test in this test suite.
|
||||
// Can be omitted if not needed.
|
||||
static void SetUpTestCase() {
|
||||
static void SetUpTestSuite() {
|
||||
shared_resource_ = new ...;
|
||||
}
|
||||
|
||||
// Per-test-case tear-down.
|
||||
// Called after the last test in this test case.
|
||||
// Per-test-suite tear-down.
|
||||
// Called after the last test in this test suite.
|
||||
// Can be omitted if not needed.
|
||||
static void TearDownTestCase() {
|
||||
static void TearDownTestSuite() {
|
||||
delete shared_resource_;
|
||||
shared_resource_ = NULL;
|
||||
}
|
||||
@ -1254,7 +1254,7 @@ TEST_F(FooTest, Test2) {
|
||||
}
|
||||
```
|
||||
|
||||
NOTE: Though the above code declares `SetUpTestCase()` protected, it may
|
||||
NOTE: Though the above code declares `SetUpTestSuite()` protected, it may
|
||||
sometimes be necessary to declare it public, such as when using it with
|
||||
`TEST_P`.
|
||||
|
||||
@ -1262,7 +1262,7 @@ sometimes be necessary to declare it public, such as when using it with
|
||||
|
||||
## Global Set-Up and Tear-Down
|
||||
|
||||
Just as you can do set-up and tear-down at the test level and the test case
|
||||
Just as you can do set-up and tear-down at the test level and the test suite
|
||||
level, you can also do it at the test program level. Here's how.
|
||||
|
||||
First, you subclass the `::testing::Environment` class to define a test
|
||||
@ -1341,7 +1341,7 @@ both `::testing::Test` and `::testing::WithParamInterface<T>`. `T` can be any
|
||||
copyable type. If it's a raw pointer, you are responsible for managing the
|
||||
lifespan of the pointed values.
|
||||
|
||||
NOTE: If your test fixture defines `SetUpTestCase()` or `TearDownTestCase()`
|
||||
NOTE: If your test fixture defines `SetUpTestSuite()` or `TearDownTestSuite()`
|
||||
they must be declared **public** rather than **protected** in order to use
|
||||
`TEST_P`.
|
||||
|
||||
@ -1380,7 +1380,7 @@ TEST_P(FooTest, HasBlahBlah) {
|
||||
}
|
||||
```
|
||||
|
||||
Finally, you can use `INSTANTIATE_TEST_CASE_P` to instantiate the test case with
|
||||
Finally, you can use `INSTANTIATE_TEST_SUITE_P` to instantiate the test suite with
|
||||
any set of parameters you want. googletest defines a number of functions for
|
||||
generating test parameters. They return what we call (surprise!) *parameter
|
||||
generators*. Here is a summary of them, which are all in the `testing`
|
||||
@ -1396,11 +1396,11 @@ namespace:
|
||||
|
||||
For more details, see the comments at the definitions of these functions.
|
||||
|
||||
The following statement will instantiate tests from the `FooTest` test case each
|
||||
The following statement will instantiate tests from the `FooTest` test suite each
|
||||
with parameter values `"meeny"`, `"miny"`, and `"moe"`.
|
||||
|
||||
```c++
|
||||
INSTANTIATE_TEST_CASE_P(InstantiationName,
|
||||
INSTANTIATE_TEST_SUITE_P(InstantiationName,
|
||||
FooTest,
|
||||
::testing::Values("meeny", "miny", "moe"));
|
||||
```
|
||||
@ -1409,11 +1409,11 @@ NOTE: The code above must be placed at global or namespace scope, not at
|
||||
function scope.
|
||||
|
||||
NOTE: Don't forget this step! If you do your test will silently pass, but none
|
||||
of its cases will ever run!
|
||||
of its suites will ever run!
|
||||
|
||||
To distinguish different instances of the pattern (yes, you can instantiate it
|
||||
more than once), the first argument to `INSTANTIATE_TEST_CASE_P` is a prefix
|
||||
that will be added to the actual test case name. Remember to pick unique
|
||||
more than once), the first argument to `INSTANTIATE_TEST_SUITE_P` is a prefix
|
||||
that will be added to the actual test suite name. Remember to pick unique
|
||||
prefixes for different instantiations. The tests from the instantiation above
|
||||
will have these names:
|
||||
|
||||
@ -1431,7 +1431,7 @@ parameter values `"cat"` and `"dog"`:
|
||||
|
||||
```c++
|
||||
const char* pets[] = {"cat", "dog"};
|
||||
INSTANTIATE_TEST_CASE_P(AnotherInstantiationName, FooTest,
|
||||
INSTANTIATE_TEST_SUITE_P(AnotherInstantiationName, FooTest,
|
||||
::testing::ValuesIn(pets));
|
||||
```
|
||||
|
||||
@ -1442,9 +1442,9 @@ The tests from the instantiation above will have these names:
|
||||
* `AnotherInstantiationName/FooTest.HasBlahBlah/0` for `"cat"`
|
||||
* `AnotherInstantiationName/FooTest.HasBlahBlah/1` for `"dog"`
|
||||
|
||||
Please note that `INSTANTIATE_TEST_CASE_P` will instantiate *all* tests in the
|
||||
given test case, whether their definitions come before or *after* the
|
||||
`INSTANTIATE_TEST_CASE_P` statement.
|
||||
Please note that `INSTANTIATE_TEST_SUITE_P` will instantiate *all* tests in the
|
||||
given test suite, whether their definitions come before or *after* the
|
||||
`INSTANTIATE_TEST_SUITE_P` statement.
|
||||
|
||||
You can see sample7_unittest.cc and sample8_unittest.cc for more examples.
|
||||
|
||||
@ -1470,13 +1470,13 @@ To define abstract tests, you should organize your code like this:
|
||||
`foo_param_test.h`. Think of this as *implementing* your abstract tests.
|
||||
|
||||
Once they are defined, you can instantiate them by including `foo_param_test.h`,
|
||||
invoking `INSTANTIATE_TEST_CASE_P()`, and depending on the library target that
|
||||
contains `foo_param_test.cc`. You can instantiate the same abstract test case
|
||||
invoking `INSTANTIATE_TEST_SUITE_P()`, and depending on the library target that
|
||||
contains `foo_param_test.cc`. You can instantiate the same abstract test suite
|
||||
multiple times, possibly in different source files.
|
||||
|
||||
### Specifying Names for Value-Parameterized Test Parameters
|
||||
|
||||
The optional last argument to `INSTANTIATE_TEST_CASE_P()` allows the user to
|
||||
The optional last argument to `INSTANTIATE_TEST_SUITE_P()` allows the user to
|
||||
specify a function or functor that generates custom test name suffixes based on
|
||||
the test parameters. The function should accept one argument of type
|
||||
`testing::TestParamInfo<class ParamType>`, and return `std::string`.
|
||||
@ -1487,17 +1487,17 @@ returns the value of `testing::PrintToString(GetParam())`. It does not work for
|
||||
|
||||
NOTE: test names must be non-empty, unique, and may only contain ASCII
|
||||
alphanumeric characters. In particular, they [should not contain
|
||||
underscores](https://github.com/google/googletest/blob/master/googletest/docs/faq.md#why-should-test-case-names-and-test-names-not-contain-underscore).
|
||||
underscores](https://github.com/google/googletest/blob/master/googletest/docs/faq.md#why-should-test-suite-names-and-test-names-not-contain-underscore).
|
||||
|
||||
```c++
|
||||
class MyTestCase : public testing::TestWithParam<int> {};
|
||||
class MyTestsuite : public testing::TestWithParam<int> {};
|
||||
|
||||
TEST_P(MyTestCase, MyTest)
|
||||
TEST_P(MyTestsuite, MyTest)
|
||||
{
|
||||
std::cout << "Example Test Param: " << GetParam() << std::endl;
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(MyGroup, MyTestCase, testing::Range(0, 10),
|
||||
INSTANTIATE_TEST_SUITE_P(MyGroup, MyTestsuite, testing::Range(0, 10),
|
||||
testing::PrintToStringParamName());
|
||||
```
|
||||
|
||||
@ -1532,20 +1532,20 @@ class FooTest : public ::testing::Test {
|
||||
};
|
||||
```
|
||||
|
||||
Next, associate a list of types with the test case, which will be repeated for
|
||||
Next, associate a list of types with the test suite, which will be repeated for
|
||||
each type in the list:
|
||||
|
||||
```c++
|
||||
using MyTypes = ::testing::Types<char, int, unsigned int>;
|
||||
TYPED_TEST_CASE(FooTest, MyTypes);
|
||||
TYPED_TEST_SUITE(FooTest, MyTypes);
|
||||
```
|
||||
|
||||
The type alias (`using` or `typedef`) is necessary for the `TYPED_TEST_CASE`
|
||||
The type alias (`using` or `typedef`) is necessary for the `TYPED_TEST_SUITE`
|
||||
macro to parse correctly. Otherwise the compiler will think that each comma in
|
||||
the type list introduces a new macro argument.
|
||||
|
||||
Then, use `TYPED_TEST()` instead of `TEST_F()` to define a typed test for this
|
||||
test case. You can repeat this as many times as you want:
|
||||
test suite. You can repeat this as many times as you want:
|
||||
|
||||
```c++
|
||||
TYPED_TEST(FooTest, DoesBlah) {
|
||||
@ -1596,10 +1596,10 @@ class FooTest : public ::testing::Test {
|
||||
};
|
||||
```
|
||||
|
||||
Next, declare that you will define a type-parameterized test case:
|
||||
Next, declare that you will define a type-parameterized test suite:
|
||||
|
||||
```c++
|
||||
TYPED_TEST_CASE_P(FooTest);
|
||||
TYPED_TEST_SUITE_P(FooTest);
|
||||
```
|
||||
|
||||
Then, use `TYPED_TEST_P()` to define a type-parameterized test. You can repeat
|
||||
@ -1616,12 +1616,12 @@ TYPED_TEST_P(FooTest, HasPropertyA) { ... }
|
||||
```
|
||||
|
||||
Now the tricky part: you need to register all test patterns using the
|
||||
`REGISTER_TYPED_TEST_CASE_P` macro before you can instantiate them. The first
|
||||
argument of the macro is the test case name; the rest are the names of the tests
|
||||
in this test case:
|
||||
`REGISTER_TYPED_TEST_SUITE_P` macro before you can instantiate them. The first
|
||||
argument of the macro is the test suite name; the rest are the names of the tests
|
||||
in this test suite:
|
||||
|
||||
```c++
|
||||
REGISTER_TYPED_TEST_CASE_P(FooTest,
|
||||
REGISTER_TYPED_TEST_SUITE_P(FooTest,
|
||||
DoesBlah, HasPropertyA);
|
||||
```
|
||||
|
||||
@ -1631,18 +1631,18 @@ source files and instantiate it multiple times.
|
||||
|
||||
```c++
|
||||
typedef ::testing::Types<char, int, unsigned int> MyTypes;
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);
|
||||
INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
|
||||
```
|
||||
|
||||
To distinguish different instances of the pattern, the first argument to the
|
||||
`INSTANTIATE_TYPED_TEST_CASE_P` macro is a prefix that will be added to the
|
||||
actual test case name. Remember to pick unique prefixes for different instances.
|
||||
`INSTANTIATE_TYPED_TEST_SUITE_P` macro is a prefix that will be added to the
|
||||
actual test suite name. Remember to pick unique prefixes for different instances.
|
||||
|
||||
In the special case where the type list contains only one type, you can write
|
||||
that type directly without `::testing::Types<...>`, like this:
|
||||
|
||||
```c++
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, int);
|
||||
INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, int);
|
||||
```
|
||||
|
||||
You can see `sample6_unittest.cc` for a complete example.
|
||||
@ -1704,7 +1704,7 @@ To test them, we use the following special techniques:
|
||||
this line in the class body:
|
||||
|
||||
```c++
|
||||
FRIEND_TEST(TestCaseName, TestName);
|
||||
FRIEND_TEST(TestsuiteName, TestName);
|
||||
```
|
||||
|
||||
For example,
|
||||
@ -1826,11 +1826,11 @@ namespace testing {
|
||||
|
||||
class TestInfo {
|
||||
public:
|
||||
// Returns the test case name and the test name, respectively.
|
||||
// Returns the test suite name and the test name, respectively.
|
||||
//
|
||||
// Do NOT delete or free the return value - it's managed by the
|
||||
// TestInfo class.
|
||||
const char* test_case_name() const;
|
||||
const char* test_suite_name() const;
|
||||
const char* name() const;
|
||||
};
|
||||
|
||||
@ -1848,14 +1848,14 @@ To obtain a `TestInfo` object for the currently running test, call
|
||||
|
||||
|
||||
|
||||
printf("We are in test %s of test case %s.\n",
|
||||
printf("We are in test %s of test suite %s.\n",
|
||||
test_info->name(),
|
||||
test_info->test_case_name());
|
||||
test_info->test_suite_name());
|
||||
```
|
||||
|
||||
`current_test_info()` returns a null pointer if no test is running. In
|
||||
particular, you cannot find the test case name in `TestCaseSetUp()`,
|
||||
`TestCaseTearDown()` (where you know the test case name implicitly), or
|
||||
particular, you cannot find the test suite name in `TestsuiteSetUp()`,
|
||||
`TestsuiteTearDown()` (where you know the test suite name implicitly), or
|
||||
functions called from them.
|
||||
|
||||
**Availability**: Linux, Windows, Mac.
|
||||
@ -1864,7 +1864,7 @@ functions called from them.
|
||||
|
||||
googletest provides an **event listener API** to let you receive notifications
|
||||
about the progress of a test program and test failures. The events you can
|
||||
listen to include the start and end of the test program, a test case, or a test
|
||||
listen to include the start and end of the test program, a test suite, or a test
|
||||
method, among others. You may use this API to augment or replace the standard
|
||||
console output, replace the XML output, or provide a completely different form
|
||||
of output, such as a GUI or a database. You can also use test events as
|
||||
@ -1885,7 +1885,7 @@ When an event is fired, its context is passed to the handler function as an
|
||||
argument. The following argument types are used:
|
||||
|
||||
* UnitTest reflects the state of the entire test program,
|
||||
* TestCase has information about a test case, which can contain one or more
|
||||
* Testsuite has information about a test suite, which can contain one or more
|
||||
tests,
|
||||
* TestInfo contains the state of a test, and
|
||||
* TestPartResult represents the result of a test assertion.
|
||||
@ -1900,7 +1900,7 @@ Here's an example:
|
||||
// Called before a test starts.
|
||||
virtual void OnTestStart(const ::testing::TestInfo& test_info) {
|
||||
printf("*** Test %s.%s starting.\n",
|
||||
test_info.test_case_name(), test_info.name());
|
||||
test_info.test_suite_name(), test_info.name());
|
||||
}
|
||||
|
||||
// Called after a failed assertion or a SUCCESS().
|
||||
@ -1915,7 +1915,7 @@ Here's an example:
|
||||
// Called after a test ends.
|
||||
virtual void OnTestEnd(const ::testing::TestInfo& test_info) {
|
||||
printf("*** Test %s.%s ending.\n",
|
||||
test_info.test_case_name(), test_info.name());
|
||||
test_info.test_suite_name(), test_info.name());
|
||||
}
|
||||
};
|
||||
```
|
||||
@ -2002,10 +2002,10 @@ running them so that a filter may be applied if needed. Including the flag
|
||||
format:
|
||||
|
||||
```none
|
||||
TestCase1.
|
||||
Testsuite1.
|
||||
TestName1
|
||||
TestName2
|
||||
TestCase2.
|
||||
Testsuite2.
|
||||
TestName
|
||||
```
|
||||
|
||||
@ -2020,7 +2020,7 @@ By default, a googletest program runs all tests the user has defined. Sometimes,
|
||||
you want to run only a subset of the tests (e.g. for debugging or quickly
|
||||
verifying a change). If you set the `GTEST_FILTER` environment variable or the
|
||||
`--gtest_filter` flag to a filter string, googletest will only run the tests
|
||||
whose full names (in the form of `TestCaseName.TestName`) match the filter.
|
||||
whose full names (in the form of `TestsuiteName.TestName`) match the filter.
|
||||
|
||||
The format of a filter is a '`:`'-separated list of wildcard patterns (called
|
||||
the *positive patterns*) optionally followed by a '`-`' and another
|
||||
@ -2038,16 +2038,16 @@ For example:
|
||||
* `./foo_test` Has no flag, and thus runs all its tests.
|
||||
* `./foo_test --gtest_filter=*` Also runs everything, due to the single
|
||||
match-everything `*` value.
|
||||
* `./foo_test --gtest_filter=FooTest.*` Runs everything in test case `FooTest`
|
||||
* `./foo_test --gtest_filter=FooTest.*` Runs everything in test suite `FooTest`
|
||||
.
|
||||
* `./foo_test --gtest_filter=*Null*:*Constructor*` Runs any test whose full
|
||||
name contains either `"Null"` or `"Constructor"` .
|
||||
* `./foo_test --gtest_filter=-*DeathTest.*` Runs all non-death tests.
|
||||
* `./foo_test --gtest_filter=FooTest.*-FooTest.Bar` Runs everything in test
|
||||
case `FooTest` except `FooTest.Bar`.
|
||||
suite `FooTest` except `FooTest.Bar`.
|
||||
* `./foo_test --gtest_filter=FooTest.*:BarTest.*-FooTest.Bar:BarTest.Foo` Runs
|
||||
everything in test case `FooTest` except `FooTest.Bar` and everything in
|
||||
test case `BarTest` except `BarTest.Foo`.
|
||||
everything in test suite `FooTest` except `FooTest.Bar` and everything in
|
||||
test suite `BarTest` except `BarTest.Foo`.
|
||||
|
||||
#### Temporarily Disabling Tests
|
||||
|
||||
@ -2056,9 +2056,9 @@ If you have a broken test that you cannot fix right away, you can add the
|
||||
better than commenting out the code or using `#if 0`, as disabled tests are
|
||||
still compiled (and thus won't rot).
|
||||
|
||||
If you need to disable all tests in a test case, you can either add `DISABLED_`
|
||||
If you need to disable all tests in a test suite, you can either add `DISABLED_`
|
||||
to the front of the name of each test, or alternatively add it to the front of
|
||||
the test case name.
|
||||
the test suite name.
|
||||
|
||||
For example, the following tests won't be run by googletest, even though they
|
||||
will still be compiled:
|
||||
@ -2165,7 +2165,7 @@ important information:
|
||||
... some error messages ...<br/>
|
||||
<span style="color:red">[ FAILED ] <span style="color:black">BarTest.ReturnsTrueOnSuccess<br/>
|
||||
...<br/>
|
||||
<span style="color:green">[==========]<span style="color:black"> 30 tests from 14 test cases ran.<br/>
|
||||
<span style="color:green">[==========]<span style="color:black"> 30 tests from 14 test suites ran.<br/>
|
||||
<span style="color:green">[ PASSED ]<span style="color:black"> 28 tests.<br/>
|
||||
<span style="color:red">[ FAILED ]<span style="color:black"> 2 tests, listed below:<br/>
|
||||
<span style="color:red">[ FAILED ]<span style="color:black"> BarTest.ReturnsTrueOnSuccess<br/>
|
||||
@ -2227,7 +2227,7 @@ apply to googletest tests, as shown here:
|
||||
|
||||
```xml
|
||||
<testsuites name="AllTests" ...>
|
||||
<testsuite name="test_case_name" ...>
|
||||
<testsuite name="test_suite_name" ...>
|
||||
<testcase name="test_name" ...>
|
||||
<failure message="..."/>
|
||||
<failure message="..."/>
|
||||
@ -2238,7 +2238,7 @@ apply to googletest tests, as shown here:
|
||||
```
|
||||
|
||||
* The root `<testsuites>` element corresponds to the entire test program.
|
||||
* `<testsuite>` elements correspond to googletest test cases.
|
||||
* `<testsuite>` elements correspond to googletest test suites.
|
||||
* `<testcase>` elements correspond to googletest test functions.
|
||||
|
||||
For instance, the following program
|
||||
@ -2272,10 +2272,10 @@ could generate this report:
|
||||
Things to note:
|
||||
|
||||
* The `tests` attribute of a `<testsuites>` or `<testsuite>` element tells how
|
||||
many test functions the googletest program or test case contains, while the
|
||||
many test functions the googletest program or test suite contains, while the
|
||||
`failures` attribute tells how many of them failed.
|
||||
|
||||
* The `time` attribute expresses the duration of the test, test case, or
|
||||
* The `time` attribute expresses the duration of the test, test suite, or
|
||||
entire test program in seconds.
|
||||
|
||||
* The `timestamp` attribute records the local date and time of the test
|
||||
@ -2302,7 +2302,7 @@ The report format conforms to the following JSON Schema:
|
||||
"$schema": "http://json-schema.org/schema#",
|
||||
"type": "object",
|
||||
"definitions": {
|
||||
"TestCase": {
|
||||
"Testsuite": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": { "type": "string" },
|
||||
@ -2358,7 +2358,7 @@ The report format conforms to the following JSON Schema:
|
||||
"testsuites": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/TestCase"
|
||||
"$ref": "#/definitions/Testsuite"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2384,7 +2384,7 @@ message UnitTest {
|
||||
google.protobuf.Timestamp timestamp = 5;
|
||||
google.protobuf.Duration time = 6;
|
||||
string name = 7;
|
||||
repeated TestCase testsuites = 8;
|
||||
repeated Testsuite testsuites = 8;
|
||||
}
|
||||
|
||||
message TestCase {
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Googletest FAQ
|
||||
|
||||
|
||||
## Why should test case names and test names not contain underscore?
|
||||
## Why should test suite names and test names not contain underscore?
|
||||
|
||||
Underscore (`_`) is special, as C++ reserves the following to be used by the
|
||||
compiler and the standard library:
|
||||
@ -14,26 +14,26 @@ User code is *prohibited* from using such identifiers.
|
||||
|
||||
Now let's look at what this means for `TEST` and `TEST_F`.
|
||||
|
||||
Currently `TEST(TestCaseName, TestName)` generates a class named
|
||||
`TestCaseName_TestName_Test`. What happens if `TestCaseName` or `TestName`
|
||||
Currently `TEST(TestSuiteName, TestName)` generates a class named
|
||||
`TestSuiteName_TestName_Test`. What happens if `TestSuiteName` or `TestName`
|
||||
contains `_`?
|
||||
|
||||
1. If `TestCaseName` starts with an `_` followed by an upper-case letter (say,
|
||||
1. If `TestSuiteName` starts with an `_` followed by an upper-case letter (say,
|
||||
`_Foo`), we end up with `_Foo_TestName_Test`, which is reserved and thus
|
||||
invalid.
|
||||
1. If `TestCaseName` ends with an `_` (say, `Foo_`), we get
|
||||
1. If `TestSuiteName` ends with an `_` (say, `Foo_`), we get
|
||||
`Foo__TestName_Test`, which is invalid.
|
||||
1. If `TestName` starts with an `_` (say, `_Bar`), we get
|
||||
`TestCaseName__Bar_Test`, which is invalid.
|
||||
`TestSuiteName__Bar_Test`, which is invalid.
|
||||
1. If `TestName` ends with an `_` (say, `Bar_`), we get
|
||||
`TestCaseName_Bar__Test`, which is invalid.
|
||||
`TestSuiteName_Bar__Test`, which is invalid.
|
||||
|
||||
So clearly `TestCaseName` and `TestName` cannot start or end with `_` (Actually,
|
||||
`TestCaseName` can start with `_` -- as long as the `_` isn't followed by an
|
||||
So clearly `TestSuiteName` and `TestName` cannot start or end with `_` (Actually,
|
||||
`TestSuiteName` can start with `_` -- as long as the `_` isn't followed by an
|
||||
upper-case letter. But that's getting complicated. So for simplicity we just say
|
||||
that it cannot start with `_`.).
|
||||
|
||||
It may seem fine for `TestCaseName` and `TestName` to contain `_` in the middle.
|
||||
It may seem fine for `TestSuiteName` and `TestName` to contain `_` in the middle.
|
||||
However, consider this:
|
||||
|
||||
```c++
|
||||
@ -44,7 +44,7 @@ TEST(Time_Flies, Like_An_Arrow) { ... }
|
||||
Now, the two `TEST`s will both generate the same class
|
||||
(`Time_Flies_Like_An_Arrow_Test`). That's not good.
|
||||
|
||||
So for simplicity, we just ask the users to avoid `_` in `TestCaseName` and
|
||||
So for simplicity, we just ask the users to avoid `_` in `TestSuiteName` and
|
||||
`TestName`. The rule is more constraining than necessary, but it's simple and
|
||||
easy to remember. It also gives googletest some wiggle room in case its
|
||||
implementation needs to change in the future.
|
||||
@ -472,7 +472,7 @@ switch to `EXPECT_*()` if that works. This
|
||||
|
||||
C++ is case-sensitive. Did you spell it as `Setup()`?
|
||||
|
||||
Similarly, sometimes people spell `SetUpTestCase()` as `SetupTestCase()` and
|
||||
Similarly, sometimes people spell `SetUpTestSuite()` as `SetupTestSuite()` and
|
||||
wonder why it's never called.
|
||||
|
||||
## How do I jump to the line of a failure in Emacs directly?
|
||||
|
@ -61,21 +61,19 @@ The related term _Test_, as it is used in the googletest, is corresponding to
|
||||
the term _[Test Case](http://glossary.istqb.org/search/test%20case)_ of ISTQB
|
||||
and others.
|
||||
|
||||
The term _Test_ is commonly of broad enough sense, including ISTQB's
|
||||
definition of _Test Case_, so it's not much of a problem here. But the
|
||||
term _Test Case_ as used in Google Test is of contradictory sense and thus confusing.
|
||||
The term _Test_ is commonly of broad enough sense, including ISTQB's definition
|
||||
of _Test Case_, so it's not much of a problem here. But the term _Test Case_ as
|
||||
was used in Google Test is of contradictory sense and thus confusing.
|
||||
|
||||
Unfortunately replacing the term _Test Case_ by _Test Suite_ throughout the
|
||||
googletest is not easy without breaking dependent projects, as `TestCase` is
|
||||
part of the public API at various places.
|
||||
googletest recently started replacing the term _Test Case_ by _Test Suite_ The
|
||||
preferred API is TestSuite*. The older TestCase* API is being slowly deprecated
|
||||
and refactored away
|
||||
|
||||
So for the time being, please be aware of the different definitions of
|
||||
the terms:
|
||||
So please be aware of the different definitions of the terms:
|
||||
|
||||
Meaning | googletest Term | [ISTQB](http://www.istqb.org/) Term
|
||||
:----------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------- | :----------------------------------
|
||||
Exercise a particular program path with specific input values and verify the results | [TEST()](#simple-tests) | [Test Case](http://glossary.istqb.org/search/test%20case)
|
||||
A set of several tests related to one component | [TestCase](#basic-concepts) | [TestSuite](http://glossary.istqb.org/search/test%20suite)
|
||||
|
||||
## Basic Concepts
|
||||
|
||||
@ -252,7 +250,7 @@ To create a test:
|
||||
entire test fails. Otherwise, it succeeds.
|
||||
|
||||
```c++
|
||||
TEST(TestCaseName, TestName) {
|
||||
TEST(TestSuiteName, TestName) {
|
||||
... test body ...
|
||||
}
|
||||
```
|
||||
@ -324,7 +322,7 @@ When using a fixture, use `TEST_F()` instead of `TEST()` as it allows you to
|
||||
access objects and subroutines in the test fixture:
|
||||
|
||||
```c++
|
||||
TEST_F(TestCaseName, TestName) {
|
||||
TEST_F(TestSuiteName, TestName) {
|
||||
... test body ...
|
||||
}
|
||||
```
|
||||
|
@ -161,7 +161,6 @@ GTEST_API_ bool InDeathTestChild();
|
||||
// is rarely a problem as people usually don't put the test binary
|
||||
// directory in PATH.
|
||||
//
|
||||
// FIXME: make thread-safe death tests search the PATH.
|
||||
|
||||
// Asserts that a given statement causes the program to exit, with an
|
||||
// integer exit status that satisfies predicate, and emitting error output
|
||||
@ -170,7 +169,7 @@ GTEST_API_ bool InDeathTestChild();
|
||||
GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_FATAL_FAILURE_)
|
||||
|
||||
// Like ASSERT_EXIT, but continues on to successive tests in the
|
||||
// test case, if any:
|
||||
// test suite, if any:
|
||||
# define EXPECT_EXIT(statement, predicate, regex) \
|
||||
GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_NONFATAL_FAILURE_)
|
||||
|
||||
@ -181,7 +180,7 @@ GTEST_API_ bool InDeathTestChild();
|
||||
ASSERT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex)
|
||||
|
||||
// Like ASSERT_DEATH, but continues on to successive tests in the
|
||||
// test case, if any:
|
||||
// test suite, if any:
|
||||
# define EXPECT_DEATH(statement, regex) \
|
||||
EXPECT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex)
|
||||
|
||||
@ -228,7 +227,7 @@ class GTEST_API_ KilledBySignal {
|
||||
// return 12;
|
||||
// }
|
||||
//
|
||||
// TEST(TestCase, TestDieOr12WorksInDgbAndOpt) {
|
||||
// TEST(TestSuite, TestDieOr12WorksInDgbAndOpt) {
|
||||
// int sideeffect = 0;
|
||||
// // Only asserts in dbg.
|
||||
// EXPECT_DEBUG_DEATH(DieInDebugOr12(&sideeffect), "death");
|
||||
|
@ -69,10 +69,6 @@ namespace testing {
|
||||
// MatchResultListener is an abstract class. Its << operator can be
|
||||
// used by a matcher to explain why a value matches or doesn't match.
|
||||
//
|
||||
// FIXME: add method
|
||||
// bool InterestedInWhy(bool result) const;
|
||||
// to indicate whether the listener is interested in why the match
|
||||
// result is 'result'.
|
||||
class MatchResultListener {
|
||||
public:
|
||||
// Creates a listener object with the given underlying ostream. The
|
||||
@ -256,13 +252,12 @@ class MatcherBase {
|
||||
public:
|
||||
// Returns true iff the matcher matches x; also explains the match
|
||||
// result to 'listener'.
|
||||
bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x,
|
||||
MatchResultListener* listener) const {
|
||||
bool MatchAndExplain(const T& x, MatchResultListener* listener) const {
|
||||
return impl_->MatchAndExplain(x, listener);
|
||||
}
|
||||
|
||||
// Returns true iff this matcher matches x.
|
||||
bool Matches(GTEST_REFERENCE_TO_CONST_(T) x) const {
|
||||
bool Matches(const T& x) const {
|
||||
DummyMatchResultListener dummy;
|
||||
return MatchAndExplain(x, &dummy);
|
||||
}
|
||||
@ -276,8 +271,7 @@ class MatcherBase {
|
||||
}
|
||||
|
||||
// Explains why x matches, or doesn't match, the matcher.
|
||||
void ExplainMatchResultTo(GTEST_REFERENCE_TO_CONST_(T) x,
|
||||
::std::ostream* os) const {
|
||||
void ExplainMatchResultTo(const T& x, ::std::ostream* os) const {
|
||||
StreamMatchResultListener listener(os);
|
||||
MatchAndExplain(x, &listener);
|
||||
}
|
||||
@ -293,22 +287,19 @@ class MatcherBase {
|
||||
MatcherBase() {}
|
||||
|
||||
// Constructs a matcher from its implementation.
|
||||
explicit MatcherBase(
|
||||
const MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)>* impl)
|
||||
: impl_(impl) {}
|
||||
explicit MatcherBase(const MatcherInterface<const T&>* impl) : impl_(impl) {}
|
||||
|
||||
template <typename U>
|
||||
explicit MatcherBase(
|
||||
const MatcherInterface<U>* impl,
|
||||
typename internal::EnableIf<
|
||||
!internal::IsSame<U, GTEST_REFERENCE_TO_CONST_(U)>::value>::type* =
|
||||
nullptr)
|
||||
!internal::IsSame<U, const U&>::value>::type* = nullptr)
|
||||
: impl_(new internal::MatcherInterfaceAdapter<U>(impl)) {}
|
||||
|
||||
virtual ~MatcherBase() {}
|
||||
|
||||
private:
|
||||
std::shared_ptr<const MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)>> impl_;
|
||||
std::shared_ptr<const MatcherInterface<const T&>> impl_;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
@ -326,15 +317,13 @@ class Matcher : public internal::MatcherBase<T> {
|
||||
explicit Matcher() {} // NOLINT
|
||||
|
||||
// Constructs a matcher from its implementation.
|
||||
explicit Matcher(const MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)>* impl)
|
||||
explicit Matcher(const MatcherInterface<const T&>* impl)
|
||||
: internal::MatcherBase<T>(impl) {}
|
||||
|
||||
template <typename U>
|
||||
explicit Matcher(
|
||||
const MatcherInterface<U>* impl,
|
||||
explicit Matcher(const MatcherInterface<U>* impl,
|
||||
typename internal::EnableIf<
|
||||
!internal::IsSame<U, GTEST_REFERENCE_TO_CONST_(U)>::value>::type* =
|
||||
nullptr)
|
||||
!internal::IsSame<U, const U&>::value>::type* = nullptr)
|
||||
: internal::MatcherBase<T>(impl) {}
|
||||
|
||||
// Implicit constructor here allows people to write
|
||||
@ -535,7 +524,7 @@ class PolymorphicMatcher {
|
||||
|
||||
template <typename T>
|
||||
operator Matcher<T>() const {
|
||||
return Matcher<T>(new MonomorphicImpl<GTEST_REFERENCE_TO_CONST_(T)>(impl_));
|
||||
return Matcher<T>(new MonomorphicImpl<const T&>(impl_));
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -107,14 +107,6 @@ class GTEST_API_ Message {
|
||||
*ss_ << str;
|
||||
}
|
||||
|
||||
#if GTEST_OS_SYMBIAN
|
||||
// Streams a value (either a pointer or not) to this object.
|
||||
template <typename T>
|
||||
inline Message& operator <<(const T& value) {
|
||||
StreamHelper(typename internal::is_pointer<T>::type(), value);
|
||||
return *this;
|
||||
}
|
||||
#else
|
||||
// Streams a non-pointer value to this object.
|
||||
template <typename T>
|
||||
inline Message& operator <<(const T& val) {
|
||||
@ -159,7 +151,6 @@ class GTEST_API_ Message {
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
#endif // GTEST_OS_SYMBIAN
|
||||
|
||||
// Since the basic IO manipulators are overloaded for both narrow
|
||||
// and wide streams, we have to provide this specialized definition
|
||||
@ -201,29 +192,6 @@ class GTEST_API_ Message {
|
||||
std::string GetString() const;
|
||||
|
||||
private:
|
||||
#if GTEST_OS_SYMBIAN
|
||||
// These are needed as the Nokia Symbian Compiler cannot decide between
|
||||
// const T& and const T* in a function template. The Nokia compiler _can_
|
||||
// decide between class template specializations for T and T*, so a
|
||||
// tr1::type_traits-like is_pointer works, and we can overload on that.
|
||||
template <typename T>
|
||||
inline void StreamHelper(internal::true_type /*is_pointer*/, T* pointer) {
|
||||
if (pointer == nullptr) {
|
||||
*ss_ << "(null)";
|
||||
} else {
|
||||
*ss_ << pointer;
|
||||
}
|
||||
}
|
||||
template <typename T>
|
||||
inline void StreamHelper(internal::false_type /*is_pointer*/,
|
||||
const T& value) {
|
||||
// See the comments in Message& operator <<(const T&) above for why
|
||||
// we need this using statement.
|
||||
using ::operator <<;
|
||||
*ss_ << value;
|
||||
}
|
||||
#endif // GTEST_OS_SYMBIAN
|
||||
|
||||
// We'll hold the text streamed to this object here.
|
||||
const std::unique_ptr< ::std::stringstream> ss_;
|
||||
|
||||
|
@ -75,7 +75,7 @@ TEST_P(FooTest, HasBlahBlah) {
|
||||
...
|
||||
}
|
||||
|
||||
// Finally, you can use INSTANTIATE_TEST_CASE_P to instantiate the test
|
||||
// Finally, you can use INSTANTIATE_TEST_SUITE_P to instantiate the test
|
||||
// case with any set of parameters you want. Google Test defines a number
|
||||
// of functions for generating test parameters. They return what we call
|
||||
// (surprise!) parameter generators. Here is a summary of them, which
|
||||
@ -96,17 +96,17 @@ TEST_P(FooTest, HasBlahBlah) {
|
||||
// For more details, see comments at the definitions of these functions below
|
||||
// in this file.
|
||||
//
|
||||
// The following statement will instantiate tests from the FooTest test case
|
||||
// The following statement will instantiate tests from the FooTest test suite
|
||||
// each with parameter values "meeny", "miny", and "moe".
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(InstantiationName,
|
||||
INSTANTIATE_TEST_SUITE_P(InstantiationName,
|
||||
FooTest,
|
||||
Values("meeny", "miny", "moe"));
|
||||
|
||||
// To distinguish different instances of the pattern, (yes, you
|
||||
// can instantiate it more then once) the first argument to the
|
||||
// INSTANTIATE_TEST_CASE_P macro is a prefix that will be added to the
|
||||
// actual test case name. Remember to pick unique prefixes for different
|
||||
// INSTANTIATE_TEST_SUITE_P macro is a prefix that will be added to the
|
||||
// actual test suite name. Remember to pick unique prefixes for different
|
||||
// instantiations. The tests from the instantiation above will have
|
||||
// these names:
|
||||
//
|
||||
@ -123,7 +123,7 @@ INSTANTIATE_TEST_CASE_P(InstantiationName,
|
||||
// with parameter values "cat" and "dog":
|
||||
|
||||
const char* pets[] = {"cat", "dog"};
|
||||
INSTANTIATE_TEST_CASE_P(AnotherInstantiationName, FooTest, ValuesIn(pets));
|
||||
INSTANTIATE_TEST_SUITE_P(AnotherInstantiationName, FooTest, ValuesIn(pets));
|
||||
|
||||
// The tests from the instantiation above will have these names:
|
||||
//
|
||||
@ -132,9 +132,9 @@ INSTANTIATE_TEST_CASE_P(AnotherInstantiationName, FooTest, ValuesIn(pets));
|
||||
// * AnotherInstantiationName/FooTest.HasBlahBlah/0 for "cat"
|
||||
// * AnotherInstantiationName/FooTest.HasBlahBlah/1 for "dog"
|
||||
//
|
||||
// Please note that INSTANTIATE_TEST_CASE_P will instantiate all tests
|
||||
// in the given test case, whether their definitions come before or
|
||||
// AFTER the INSTANTIATE_TEST_CASE_P statement.
|
||||
// Please note that INSTANTIATE_TEST_SUITE_P will instantiate all tests
|
||||
// in the given test suite, whether their definitions come before or
|
||||
// AFTER the INSTANTIATE_TEST_SUITE_P statement.
|
||||
//
|
||||
// Please also note that generator expressions (including parameters to the
|
||||
// generators) are evaluated in InitGoogleTest(), after main() has started.
|
||||
@ -178,26 +178,23 @@ TEST_P(DerivedTest, DoesBlah) {
|
||||
|
||||
#endif // 0
|
||||
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
#if !GTEST_OS_SYMBIAN
|
||||
# include <utility>
|
||||
#endif
|
||||
#include <utility>
|
||||
|
||||
#include "gtest/internal/gtest-internal.h"
|
||||
#include "gtest/internal/gtest-param-util.h"
|
||||
#include "gtest/internal/gtest-param-util-generated.h"
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
namespace testing {
|
||||
|
||||
// Functions producing parameter generators.
|
||||
//
|
||||
// Google Test uses these generators to produce parameters for value-
|
||||
// parameterized tests. When a parameterized test case is instantiated
|
||||
// parameterized tests. When a parameterized test suite is instantiated
|
||||
// with a particular generator, Google Test creates and runs tests
|
||||
// for each element in the sequence produced by the generator.
|
||||
//
|
||||
// In the following sample, tests from test case FooTest are instantiated
|
||||
// In the following sample, tests from test suite FooTest are instantiated
|
||||
// each three times with parameter values 3, 5, and 8:
|
||||
//
|
||||
// class FooTest : public TestWithParam<int> { ... };
|
||||
@ -206,7 +203,7 @@ namespace testing {
|
||||
// }
|
||||
// TEST_P(FooTest, TestThat) {
|
||||
// }
|
||||
// INSTANTIATE_TEST_CASE_P(TestSequence, FooTest, Values(3, 5, 8));
|
||||
// INSTANTIATE_TEST_SUITE_P(TestSequence, FooTest, Values(3, 5, 8));
|
||||
//
|
||||
|
||||
// Range() returns generators providing sequences of values in a range.
|
||||
@ -263,13 +260,13 @@ internal::ParamGenerator<T> Range(T start, T end) {
|
||||
//
|
||||
// Examples:
|
||||
//
|
||||
// This instantiates tests from test case StringTest
|
||||
// This instantiates tests from test suite StringTest
|
||||
// each with C-string values of "foo", "bar", and "baz":
|
||||
//
|
||||
// const char* strings[] = {"foo", "bar", "baz"};
|
||||
// INSTANTIATE_TEST_CASE_P(StringSequence, StringTest, ValuesIn(strings));
|
||||
// INSTANTIATE_TEST_SUITE_P(StringSequence, StringTest, ValuesIn(strings));
|
||||
//
|
||||
// This instantiates tests from test case StlStringTest
|
||||
// This instantiates tests from test suite StlStringTest
|
||||
// each with STL strings with values "a" and "b":
|
||||
//
|
||||
// ::std::vector< ::std::string> GetParameterStrings() {
|
||||
@ -279,7 +276,7 @@ internal::ParamGenerator<T> Range(T start, T end) {
|
||||
// return v;
|
||||
// }
|
||||
//
|
||||
// INSTANTIATE_TEST_CASE_P(CharSequence,
|
||||
// INSTANTIATE_TEST_SUITE_P(CharSequence,
|
||||
// StlStringTest,
|
||||
// ValuesIn(GetParameterStrings()));
|
||||
//
|
||||
@ -294,7 +291,7 @@ internal::ParamGenerator<T> Range(T start, T end) {
|
||||
// return list;
|
||||
// }
|
||||
// ::std::list<char> l = GetParameterChars();
|
||||
// INSTANTIATE_TEST_CASE_P(CharSequence2,
|
||||
// INSTANTIATE_TEST_SUITE_P(CharSequence2,
|
||||
// CharTest,
|
||||
// ValuesIn(l.begin(), l.end()));
|
||||
//
|
||||
@ -326,15 +323,17 @@ internal::ParamGenerator<typename Container::value_type> ValuesIn(
|
||||
// Values(T v1, T v2, ..., T vN)
|
||||
// - returns a generator producing sequences with elements v1, v2, ..., vN.
|
||||
//
|
||||
// For example, this instantiates tests from test case BarTest each
|
||||
// For example, this instantiates tests from test suite BarTest each
|
||||
// with values "one", "two", and "three":
|
||||
//
|
||||
// INSTANTIATE_TEST_CASE_P(NumSequence, BarTest, Values("one", "two", "three"));
|
||||
// INSTANTIATE_TEST_SUITE_P(NumSequence,
|
||||
// BarTest,
|
||||
// Values("one", "two", "three"));
|
||||
//
|
||||
// This instantiates tests from test case BazTest each with values 1, 2, 3.5.
|
||||
// This instantiates tests from test suite BazTest each with values 1, 2, 3.5.
|
||||
// The exact type of values will depend on the type of parameter in BazTest.
|
||||
//
|
||||
// INSTANTIATE_TEST_CASE_P(FloatingNumbers, BazTest, Values(1, 2, 3.5));
|
||||
// INSTANTIATE_TEST_SUITE_P(FloatingNumbers, BazTest, Values(1, 2, 3.5));
|
||||
//
|
||||
//
|
||||
template <typename... T>
|
||||
@ -352,7 +351,7 @@ internal::ValueArray<T...> Values(T... v) {
|
||||
// of multiple flags can be tested when several Bool()'s are combined using
|
||||
// Combine() function.
|
||||
//
|
||||
// In the following example all tests in the test case FlagDependentTest
|
||||
// In the following example all tests in the test suite FlagDependentTest
|
||||
// will be instantiated twice with parameters false and true.
|
||||
//
|
||||
// class FlagDependentTest : public testing::TestWithParam<bool> {
|
||||
@ -360,7 +359,7 @@ internal::ValueArray<T...> Values(T... v) {
|
||||
// external_flag = GetParam();
|
||||
// }
|
||||
// }
|
||||
// INSTANTIATE_TEST_CASE_P(BoolSequence, FlagDependentTest, Bool());
|
||||
// INSTANTIATE_TEST_SUITE_P(BoolSequence, FlagDependentTest, Bool());
|
||||
//
|
||||
inline internal::ParamGenerator<bool> Bool() {
|
||||
return Values(false, true);
|
||||
@ -381,7 +380,7 @@ inline internal::ParamGenerator<bool> Bool() {
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// This will instantiate tests in test case AnimalTest each one with
|
||||
// This will instantiate tests in test suite AnimalTest each one with
|
||||
// the parameter values tuple("cat", BLACK), tuple("cat", WHITE),
|
||||
// tuple("dog", BLACK), and tuple("dog", WHITE):
|
||||
//
|
||||
@ -391,7 +390,7 @@ inline internal::ParamGenerator<bool> Bool() {
|
||||
//
|
||||
// TEST_P(AnimalTest, AnimalLooksNice) {...}
|
||||
//
|
||||
// INSTANTIATE_TEST_CASE_P(AnimalVariations, AnimalTest,
|
||||
// INSTANTIATE_TEST_SUITE_P(AnimalVariations, AnimalTest,
|
||||
// Combine(Values("cat", "dog"),
|
||||
// Values(BLACK, WHITE)));
|
||||
//
|
||||
@ -409,7 +408,7 @@ inline internal::ParamGenerator<bool> Bool() {
|
||||
// TEST_P(FlagDependentTest, TestFeature1) {
|
||||
// // Test your code using external_flag_1 and external_flag_2 here.
|
||||
// }
|
||||
// INSTANTIATE_TEST_CASE_P(TwoBoolSequence, FlagDependentTest,
|
||||
// INSTANTIATE_TEST_SUITE_P(TwoBoolSequence, FlagDependentTest,
|
||||
// Combine(Bool(), Bool()));
|
||||
//
|
||||
template <typename Generator1, typename Generator2>
|
||||
@ -516,36 +515,36 @@ internal::CartesianProductHolder10<Generator1, Generator2, Generator3,
|
||||
g1, g2, g3, g4, g5, g6, g7, g8, g9, g10);
|
||||
}
|
||||
|
||||
# define TEST_P(test_case_name, test_name) \
|
||||
class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
|
||||
: public test_case_name { \
|
||||
#define TEST_P(test_suite_name, test_name) \
|
||||
class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \
|
||||
: public test_suite_name { \
|
||||
public: \
|
||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {} \
|
||||
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() {} \
|
||||
virtual void TestBody(); \
|
||||
\
|
||||
private: \
|
||||
static int AddToRegistry() { \
|
||||
::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
|
||||
GetTestCasePatternHolder<test_case_name>(\
|
||||
#test_case_name, \
|
||||
::testing::internal::CodeLocation(\
|
||||
__FILE__, __LINE__))->AddTestPattern(\
|
||||
GTEST_STRINGIFY_(test_case_name), \
|
||||
GTEST_STRINGIFY_(test_name), \
|
||||
new ::testing::internal::TestMetaFactory< \
|
||||
GTEST_TEST_CLASS_NAME_(\
|
||||
test_case_name, test_name)>()); \
|
||||
::testing::UnitTest::GetInstance() \
|
||||
->parameterized_test_registry() \
|
||||
.GetTestSuitePatternHolder<test_suite_name>( \
|
||||
#test_suite_name, \
|
||||
::testing::internal::CodeLocation(__FILE__, __LINE__)) \
|
||||
->AddTestPattern( \
|
||||
GTEST_STRINGIFY_(test_suite_name), GTEST_STRINGIFY_(test_name), \
|
||||
new ::testing::internal::TestMetaFactory<GTEST_TEST_CLASS_NAME_( \
|
||||
test_suite_name, test_name)>()); \
|
||||
return 0; \
|
||||
} \
|
||||
static int gtest_registering_dummy_ GTEST_ATTRIBUTE_UNUSED_; \
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(\
|
||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)); \
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(GTEST_TEST_CLASS_NAME_(test_suite_name, \
|
||||
test_name)); \
|
||||
}; \
|
||||
int GTEST_TEST_CLASS_NAME_(test_case_name, \
|
||||
int GTEST_TEST_CLASS_NAME_(test_suite_name, \
|
||||
test_name)::gtest_registering_dummy_ = \
|
||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \
|
||||
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
|
||||
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::AddToRegistry(); \
|
||||
void GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::TestBody()
|
||||
|
||||
// The optional last argument to INSTANTIATE_TEST_CASE_P allows the user
|
||||
// The optional last argument to INSTANTIATE_TEST_SUITE_P allows the user
|
||||
// to specify a function or functor that generates custom test name suffixes
|
||||
// based on the test parameters. The function should accept one argument of
|
||||
// type testing::TestParamInfo<class ParamType>, and return std::string.
|
||||
@ -557,25 +556,33 @@ internal::CartesianProductHolder10<Generator1, Generator2, Generator3,
|
||||
// alphanumeric characters or underscore. Because PrintToString adds quotes
|
||||
// to std::string and C strings, it won't work for these types.
|
||||
|
||||
# define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator, ...) \
|
||||
static ::testing::internal::ParamGenerator<test_case_name::ParamType> \
|
||||
gtest_##prefix##test_case_name##_EvalGenerator_() { return generator; } \
|
||||
static ::std::string gtest_##prefix##test_case_name##_EvalGenerateName_( \
|
||||
const ::testing::TestParamInfo<test_case_name::ParamType>& info) { \
|
||||
return ::testing::internal::GetParamNameGen<test_case_name::ParamType> \
|
||||
(__VA_ARGS__)(info); \
|
||||
#define INSTANTIATE_TEST_SUITE_P(prefix, test_suite_name, generator, ...) \
|
||||
static ::testing::internal::ParamGenerator<test_suite_name::ParamType> \
|
||||
gtest_##prefix##test_suite_name##_EvalGenerator_() { \
|
||||
return generator; \
|
||||
} \
|
||||
static int gtest_##prefix##test_case_name##_dummy_ GTEST_ATTRIBUTE_UNUSED_ = \
|
||||
::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
|
||||
GetTestCasePatternHolder<test_case_name>(\
|
||||
#test_case_name, \
|
||||
::testing::internal::CodeLocation(\
|
||||
__FILE__, __LINE__))->AddTestCaseInstantiation(\
|
||||
#prefix, \
|
||||
>est_##prefix##test_case_name##_EvalGenerator_, \
|
||||
>est_##prefix##test_case_name##_EvalGenerateName_, \
|
||||
static ::std::string gtest_##prefix##test_suite_name##_EvalGenerateName_( \
|
||||
const ::testing::TestParamInfo<test_suite_name::ParamType>& info) { \
|
||||
return ::testing::internal::GetParamNameGen<test_suite_name::ParamType>( \
|
||||
__VA_ARGS__)(info); \
|
||||
} \
|
||||
static int gtest_##prefix##test_suite_name##_dummy_ \
|
||||
GTEST_ATTRIBUTE_UNUSED_ = \
|
||||
::testing::UnitTest::GetInstance() \
|
||||
->parameterized_test_registry() \
|
||||
.GetTestSuitePatternHolder<test_suite_name>( \
|
||||
#test_suite_name, \
|
||||
::testing::internal::CodeLocation(__FILE__, __LINE__)) \
|
||||
->AddTestSuiteInstantiation( \
|
||||
#prefix, >est_##prefix##test_suite_name##_EvalGenerator_, \
|
||||
>est_##prefix##test_suite_name##_EvalGenerateName_, \
|
||||
__FILE__, __LINE__)
|
||||
|
||||
// Legacy API is deprecated but still available
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
#define INSTANTIATE_TEST_CASE_P INSTANTIATE_TEST_SUITE_P
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
} // namespace testing
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
|
||||
|
@ -74,7 +74,7 @@ TEST_P(FooTest, HasBlahBlah) {
|
||||
...
|
||||
}
|
||||
|
||||
// Finally, you can use INSTANTIATE_TEST_CASE_P to instantiate the test
|
||||
// Finally, you can use INSTANTIATE_TEST_SUITE_P to instantiate the test
|
||||
// case with any set of parameters you want. Google Test defines a number
|
||||
// of functions for generating test parameters. They return what we call
|
||||
// (surprise!) parameter generators. Here is a summary of them, which
|
||||
@ -95,17 +95,17 @@ TEST_P(FooTest, HasBlahBlah) {
|
||||
// For more details, see comments at the definitions of these functions below
|
||||
// in this file.
|
||||
//
|
||||
// The following statement will instantiate tests from the FooTest test case
|
||||
// The following statement will instantiate tests from the FooTest test suite
|
||||
// each with parameter values "meeny", "miny", and "moe".
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(InstantiationName,
|
||||
INSTANTIATE_TEST_SUITE_P(InstantiationName,
|
||||
FooTest,
|
||||
Values("meeny", "miny", "moe"));
|
||||
|
||||
// To distinguish different instances of the pattern, (yes, you
|
||||
// can instantiate it more then once) the first argument to the
|
||||
// INSTANTIATE_TEST_CASE_P macro is a prefix that will be added to the
|
||||
// actual test case name. Remember to pick unique prefixes for different
|
||||
// INSTANTIATE_TEST_SUITE_P macro is a prefix that will be added to the
|
||||
// actual test suite name. Remember to pick unique prefixes for different
|
||||
// instantiations. The tests from the instantiation above will have
|
||||
// these names:
|
||||
//
|
||||
@ -122,7 +122,7 @@ INSTANTIATE_TEST_CASE_P(InstantiationName,
|
||||
// with parameter values "cat" and "dog":
|
||||
|
||||
const char* pets[] = {"cat", "dog"};
|
||||
INSTANTIATE_TEST_CASE_P(AnotherInstantiationName, FooTest, ValuesIn(pets));
|
||||
INSTANTIATE_TEST_SUITE_P(AnotherInstantiationName, FooTest, ValuesIn(pets));
|
||||
|
||||
// The tests from the instantiation above will have these names:
|
||||
//
|
||||
@ -131,9 +131,9 @@ INSTANTIATE_TEST_CASE_P(AnotherInstantiationName, FooTest, ValuesIn(pets));
|
||||
// * AnotherInstantiationName/FooTest.HasBlahBlah/0 for "cat"
|
||||
// * AnotherInstantiationName/FooTest.HasBlahBlah/1 for "dog"
|
||||
//
|
||||
// Please note that INSTANTIATE_TEST_CASE_P will instantiate all tests
|
||||
// in the given test case, whether their definitions come before or
|
||||
// AFTER the INSTANTIATE_TEST_CASE_P statement.
|
||||
// Please note that INSTANTIATE_TEST_SUITE_P will instantiate all tests
|
||||
// in the given test suite, whether their definitions come before or
|
||||
// AFTER the INSTANTIATE_TEST_SUITE_P statement.
|
||||
//
|
||||
// Please also note that generator expressions (including parameters to the
|
||||
// generators) are evaluated in InitGoogleTest(), after main() has started.
|
||||
@ -177,26 +177,23 @@ TEST_P(DerivedTest, DoesBlah) {
|
||||
|
||||
#endif // 0
|
||||
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
#if !GTEST_OS_SYMBIAN
|
||||
# include <utility>
|
||||
#endif
|
||||
#include <utility>
|
||||
|
||||
#include "gtest/internal/gtest-internal.h"
|
||||
#include "gtest/internal/gtest-param-util.h"
|
||||
#include "gtest/internal/gtest-param-util-generated.h"
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
namespace testing {
|
||||
|
||||
// Functions producing parameter generators.
|
||||
//
|
||||
// Google Test uses these generators to produce parameters for value-
|
||||
// parameterized tests. When a parameterized test case is instantiated
|
||||
// parameterized tests. When a parameterized test suite is instantiated
|
||||
// with a particular generator, Google Test creates and runs tests
|
||||
// for each element in the sequence produced by the generator.
|
||||
//
|
||||
// In the following sample, tests from test case FooTest are instantiated
|
||||
// In the following sample, tests from test suite FooTest are instantiated
|
||||
// each three times with parameter values 3, 5, and 8:
|
||||
//
|
||||
// class FooTest : public TestWithParam<int> { ... };
|
||||
@ -205,7 +202,7 @@ namespace testing {
|
||||
// }
|
||||
// TEST_P(FooTest, TestThat) {
|
||||
// }
|
||||
// INSTANTIATE_TEST_CASE_P(TestSequence, FooTest, Values(3, 5, 8));
|
||||
// INSTANTIATE_TEST_SUITE_P(TestSequence, FooTest, Values(3, 5, 8));
|
||||
//
|
||||
|
||||
// Range() returns generators providing sequences of values in a range.
|
||||
@ -262,13 +259,13 @@ internal::ParamGenerator<T> Range(T start, T end) {
|
||||
//
|
||||
// Examples:
|
||||
//
|
||||
// This instantiates tests from test case StringTest
|
||||
// This instantiates tests from test suite StringTest
|
||||
// each with C-string values of "foo", "bar", and "baz":
|
||||
//
|
||||
// const char* strings[] = {"foo", "bar", "baz"};
|
||||
// INSTANTIATE_TEST_CASE_P(StringSequence, StringTest, ValuesIn(strings));
|
||||
// INSTANTIATE_TEST_SUITE_P(StringSequence, StringTest, ValuesIn(strings));
|
||||
//
|
||||
// This instantiates tests from test case StlStringTest
|
||||
// This instantiates tests from test suite StlStringTest
|
||||
// each with STL strings with values "a" and "b":
|
||||
//
|
||||
// ::std::vector< ::std::string> GetParameterStrings() {
|
||||
@ -278,7 +275,7 @@ internal::ParamGenerator<T> Range(T start, T end) {
|
||||
// return v;
|
||||
// }
|
||||
//
|
||||
// INSTANTIATE_TEST_CASE_P(CharSequence,
|
||||
// INSTANTIATE_TEST_SUITE_P(CharSequence,
|
||||
// StlStringTest,
|
||||
// ValuesIn(GetParameterStrings()));
|
||||
//
|
||||
@ -293,7 +290,7 @@ internal::ParamGenerator<T> Range(T start, T end) {
|
||||
// return list;
|
||||
// }
|
||||
// ::std::list<char> l = GetParameterChars();
|
||||
// INSTANTIATE_TEST_CASE_P(CharSequence2,
|
||||
// INSTANTIATE_TEST_SUITE_P(CharSequence2,
|
||||
// CharTest,
|
||||
// ValuesIn(l.begin(), l.end()));
|
||||
//
|
||||
@ -325,15 +322,17 @@ internal::ParamGenerator<typename Container::value_type> ValuesIn(
|
||||
// Values(T v1, T v2, ..., T vN)
|
||||
// - returns a generator producing sequences with elements v1, v2, ..., vN.
|
||||
//
|
||||
// For example, this instantiates tests from test case BarTest each
|
||||
// For example, this instantiates tests from test suite BarTest each
|
||||
// with values "one", "two", and "three":
|
||||
//
|
||||
// INSTANTIATE_TEST_CASE_P(NumSequence, BarTest, Values("one", "two", "three"));
|
||||
// INSTANTIATE_TEST_SUITE_P(NumSequence,
|
||||
// BarTest,
|
||||
// Values("one", "two", "three"));
|
||||
//
|
||||
// This instantiates tests from test case BazTest each with values 1, 2, 3.5.
|
||||
// This instantiates tests from test suite BazTest each with values 1, 2, 3.5.
|
||||
// The exact type of values will depend on the type of parameter in BazTest.
|
||||
//
|
||||
// INSTANTIATE_TEST_CASE_P(FloatingNumbers, BazTest, Values(1, 2, 3.5));
|
||||
// INSTANTIATE_TEST_SUITE_P(FloatingNumbers, BazTest, Values(1, 2, 3.5));
|
||||
//
|
||||
//
|
||||
template <typename... T>
|
||||
@ -351,7 +350,7 @@ internal::ValueArray<T...> Values(T... v) {
|
||||
// of multiple flags can be tested when several Bool()'s are combined using
|
||||
// Combine() function.
|
||||
//
|
||||
// In the following example all tests in the test case FlagDependentTest
|
||||
// In the following example all tests in the test suite FlagDependentTest
|
||||
// will be instantiated twice with parameters false and true.
|
||||
//
|
||||
// class FlagDependentTest : public testing::TestWithParam<bool> {
|
||||
@ -359,7 +358,7 @@ internal::ValueArray<T...> Values(T... v) {
|
||||
// external_flag = GetParam();
|
||||
// }
|
||||
// }
|
||||
// INSTANTIATE_TEST_CASE_P(BoolSequence, FlagDependentTest, Bool());
|
||||
// INSTANTIATE_TEST_SUITE_P(BoolSequence, FlagDependentTest, Bool());
|
||||
//
|
||||
inline internal::ParamGenerator<bool> Bool() {
|
||||
return Values(false, true);
|
||||
@ -380,7 +379,7 @@ inline internal::ParamGenerator<bool> Bool() {
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// This will instantiate tests in test case AnimalTest each one with
|
||||
// This will instantiate tests in test suite AnimalTest each one with
|
||||
// the parameter values tuple("cat", BLACK), tuple("cat", WHITE),
|
||||
// tuple("dog", BLACK), and tuple("dog", WHITE):
|
||||
//
|
||||
@ -390,7 +389,7 @@ inline internal::ParamGenerator<bool> Bool() {
|
||||
//
|
||||
// TEST_P(AnimalTest, AnimalLooksNice) {...}
|
||||
//
|
||||
// INSTANTIATE_TEST_CASE_P(AnimalVariations, AnimalTest,
|
||||
// INSTANTIATE_TEST_SUITE_P(AnimalVariations, AnimalTest,
|
||||
// Combine(Values("cat", "dog"),
|
||||
// Values(BLACK, WHITE)));
|
||||
//
|
||||
@ -408,7 +407,7 @@ inline internal::ParamGenerator<bool> Bool() {
|
||||
// TEST_P(FlagDependentTest, TestFeature1) {
|
||||
// // Test your code using external_flag_1 and external_flag_2 here.
|
||||
// }
|
||||
// INSTANTIATE_TEST_CASE_P(TwoBoolSequence, FlagDependentTest,
|
||||
// INSTANTIATE_TEST_SUITE_P(TwoBoolSequence, FlagDependentTest,
|
||||
// Combine(Bool(), Bool()));
|
||||
//
|
||||
$range i 2..maxtuple
|
||||
@ -424,36 +423,36 @@ internal::CartesianProductHolder$i<$for j, [[Generator$j]]> Combine(
|
||||
|
||||
]]
|
||||
|
||||
# define TEST_P(test_case_name, test_name) \
|
||||
class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
|
||||
: public test_case_name { \
|
||||
# define TEST_P(test_suite_name, test_name) \
|
||||
class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \
|
||||
: public test_suite_name { \
|
||||
public: \
|
||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {} \
|
||||
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() {} \
|
||||
virtual void TestBody(); \
|
||||
private: \
|
||||
static int AddToRegistry() { \
|
||||
::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
|
||||
GetTestCasePatternHolder<test_case_name>(\
|
||||
#test_case_name, \
|
||||
GetTestSuitePatternHolder<test_suite_name>(\
|
||||
#test_suite_name, \
|
||||
::testing::internal::CodeLocation(\
|
||||
__FILE__, __LINE__))->AddTestPattern(\
|
||||
GTEST_STRINGIFY_(test_case_name), \
|
||||
GTEST_STRINGIFY_(test_suite_name), \
|
||||
GTEST_STRINGIFY_(test_name), \
|
||||
new ::testing::internal::TestMetaFactory< \
|
||||
GTEST_TEST_CLASS_NAME_(\
|
||||
test_case_name, test_name)>()); \
|
||||
test_suite_name, test_name)>()); \
|
||||
return 0; \
|
||||
} \
|
||||
static int gtest_registering_dummy_ GTEST_ATTRIBUTE_UNUSED_; \
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(\
|
||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)); \
|
||||
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)); \
|
||||
}; \
|
||||
int GTEST_TEST_CLASS_NAME_(test_case_name, \
|
||||
int GTEST_TEST_CLASS_NAME_(test_suite_name, \
|
||||
test_name)::gtest_registering_dummy_ = \
|
||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \
|
||||
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
|
||||
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::AddToRegistry(); \
|
||||
void GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::TestBody()
|
||||
|
||||
// The optional last argument to INSTANTIATE_TEST_CASE_P allows the user
|
||||
// The optional last argument to INSTANTIATE_TEST_SUITE_P allows the user
|
||||
// to specify a function or functor that generates custom test name suffixes
|
||||
// based on the test parameters. The function should accept one argument of
|
||||
// type testing::TestParamInfo<class ParamType>, and return std::string.
|
||||
@ -465,25 +464,30 @@ internal::CartesianProductHolder$i<$for j, [[Generator$j]]> Combine(
|
||||
// alphanumeric characters or underscore. Because PrintToString adds quotes
|
||||
// to std::string and C strings, it won't work for these types.
|
||||
|
||||
# define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator, ...) \
|
||||
static ::testing::internal::ParamGenerator<test_case_name::ParamType> \
|
||||
gtest_##prefix##test_case_name##_EvalGenerator_() { return generator; } \
|
||||
static ::std::string gtest_##prefix##test_case_name##_EvalGenerateName_( \
|
||||
const ::testing::TestParamInfo<test_case_name::ParamType>& info) { \
|
||||
return ::testing::internal::GetParamNameGen<test_case_name::ParamType> \
|
||||
# define INSTANTIATE_TEST_SUITE_P(prefix, test_suite_name, generator, ...) \
|
||||
static ::testing::internal::ParamGenerator<test_suite_name::ParamType> \
|
||||
gtest_##prefix##test_suite_name##_EvalGenerator_() { return generator; } \
|
||||
static ::std::string gtest_##prefix##test_suite_name##_EvalGenerateName_( \
|
||||
const ::testing::TestParamInfo<test_suite_name::ParamType>& info) { \
|
||||
return ::testing::internal::GetParamNameGen<test_suite_name::ParamType> \
|
||||
(__VA_ARGS__)(info); \
|
||||
} \
|
||||
static int gtest_##prefix##test_case_name##_dummy_ GTEST_ATTRIBUTE_UNUSED_ = \
|
||||
static int gtest_##prefix##test_suite_name##_dummy_ GTEST_ATTRIBUTE_UNUSED_ = \
|
||||
::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
|
||||
GetTestCasePatternHolder<test_case_name>(\
|
||||
#test_case_name, \
|
||||
GetTestSuitePatternHolder<test_suite_name>(\
|
||||
#test_suite_name, \
|
||||
::testing::internal::CodeLocation(\
|
||||
__FILE__, __LINE__))->AddTestCaseInstantiation(\
|
||||
__FILE__, __LINE__))->AddTestSuiteInstantiation(\
|
||||
#prefix, \
|
||||
>est_##prefix##test_case_name##_EvalGenerator_, \
|
||||
>est_##prefix##test_case_name##_EvalGenerateName_, \
|
||||
>est_##prefix##test_suite_name##_EvalGenerator_, \
|
||||
>est_##prefix##test_suite_name##_EvalGenerateName_, \
|
||||
__FILE__, __LINE__)
|
||||
|
||||
// Legacy API is deprecated but still available
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
#define INSTANTIATE_TEST_CASE_P INSTANTIATE_TEST_SUITE_P
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
} // namespace testing
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
|
||||
|
@ -514,7 +514,7 @@ void PrintTo(const T& value, ::std::ostream* os) {
|
||||
(sizeof(IsContainerTest<T>(0)) == sizeof(IsContainer)) &&
|
||||
!IsRecursiveContainer<T>::value
|
||||
? kPrintContainer
|
||||
: !is_pointer<T>::value
|
||||
: !std::is_pointer<T>::value
|
||||
? kPrintOther
|
||||
: std::is_function<typename std::remove_pointer<T>::type>::value
|
||||
? kPrintFunctionPointer
|
||||
@ -761,7 +761,6 @@ void UniversalPrintArray(const T* begin, size_t len, ::std::ostream* os) {
|
||||
// If the array has more than kThreshold elements, we'll have to
|
||||
// omit some details by printing only the first and the last
|
||||
// kChunkSize elements.
|
||||
// FIXME: let the user control the threshold using a flag.
|
||||
if (len <= kThreshold) {
|
||||
PrintRawArrayTo(begin, len, os);
|
||||
} else {
|
||||
|
@ -52,18 +52,18 @@ class FooTest : public testing::Test {
|
||||
T value_;
|
||||
};
|
||||
|
||||
// Next, associate a list of types with the test case, which will be
|
||||
// Next, associate a list of types with the test suite, which will be
|
||||
// repeated for each type in the list. The typedef is necessary for
|
||||
// the macro to parse correctly.
|
||||
typedef testing::Types<char, int, unsigned int> MyTypes;
|
||||
TYPED_TEST_CASE(FooTest, MyTypes);
|
||||
TYPED_TEST_SUITE(FooTest, MyTypes);
|
||||
|
||||
// If the type list contains only one type, you can write that type
|
||||
// directly without Types<...>:
|
||||
// TYPED_TEST_CASE(FooTest, int);
|
||||
// TYPED_TEST_SUITE(FooTest, int);
|
||||
|
||||
// Then, use TYPED_TEST() instead of TEST_F() to define as many typed
|
||||
// tests for this test case as you want.
|
||||
// tests for this test suite as you want.
|
||||
TYPED_TEST(FooTest, DoesBlah) {
|
||||
// Inside a test, refer to TypeParam to get the type parameter.
|
||||
// Since we are inside a derived class template, C++ requires use to
|
||||
@ -83,7 +83,7 @@ TYPED_TEST(FooTest, DoesBlah) {
|
||||
|
||||
TYPED_TEST(FooTest, HasPropertyA) { ... }
|
||||
|
||||
// TYPED_TEST_CASE takes an optional third argument which allows to specify a
|
||||
// TYPED_TEST_SUITE takes an optional third argument which allows to specify a
|
||||
// class that generates custom test name suffixes based on the type. This should
|
||||
// be a class which has a static template function GetName(int index) returning
|
||||
// a string for each type. The provided integer index equals the index of the
|
||||
@ -99,7 +99,7 @@ TYPED_TEST(FooTest, HasPropertyA) { ... }
|
||||
// if (std::is_same<T, unsigned int>()) return "unsignedInt";
|
||||
// }
|
||||
// };
|
||||
// TYPED_TEST_CASE(FooTest, MyTypes, MyTypeNames);
|
||||
// TYPED_TEST_SUITE(FooTest, MyTypes, MyTypeNames);
|
||||
|
||||
#endif // 0
|
||||
|
||||
@ -126,13 +126,13 @@ class FooTest : public testing::Test {
|
||||
...
|
||||
};
|
||||
|
||||
// Next, declare that you will define a type-parameterized test case
|
||||
// Next, declare that you will define a type-parameterized test suite
|
||||
// (the _P suffix is for "parameterized" or "pattern", whichever you
|
||||
// prefer):
|
||||
TYPED_TEST_CASE_P(FooTest);
|
||||
TYPED_TEST_SUITE_P(FooTest);
|
||||
|
||||
// Then, use TYPED_TEST_P() to define as many type-parameterized tests
|
||||
// for this type-parameterized test case as you want.
|
||||
// for this type-parameterized test suite as you want.
|
||||
TYPED_TEST_P(FooTest, DoesBlah) {
|
||||
// Inside a test, refer to TypeParam to get the type parameter.
|
||||
TypeParam n = 0;
|
||||
@ -143,9 +143,9 @@ TYPED_TEST_P(FooTest, HasPropertyA) { ... }
|
||||
|
||||
// Now the tricky part: you need to register all test patterns before
|
||||
// you can instantiate them. The first argument of the macro is the
|
||||
// test case name; the rest are the names of the tests in this test
|
||||
// test suite name; the rest are the names of the tests in this test
|
||||
// case.
|
||||
REGISTER_TYPED_TEST_CASE_P(FooTest,
|
||||
REGISTER_TYPED_TEST_SUITE_P(FooTest,
|
||||
DoesBlah, HasPropertyA);
|
||||
|
||||
// Finally, you are free to instantiate the pattern with the types you
|
||||
@ -154,19 +154,19 @@ REGISTER_TYPED_TEST_CASE_P(FooTest,
|
||||
//
|
||||
// To distinguish different instances of the pattern, the first
|
||||
// argument to the INSTANTIATE_* macro is a prefix that will be added
|
||||
// to the actual test case name. Remember to pick unique prefixes for
|
||||
// to the actual test suite name. Remember to pick unique prefixes for
|
||||
// different instances.
|
||||
typedef testing::Types<char, int, unsigned int> MyTypes;
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);
|
||||
INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
|
||||
|
||||
// If the type list contains only one type, you can write that type
|
||||
// directly without Types<...>:
|
||||
// INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, int);
|
||||
// INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, int);
|
||||
//
|
||||
// Similar to the optional argument of TYPED_TEST_CASE above,
|
||||
// INSTANTIATE_TEST_CASE_P takes an optional fourth argument which allows to
|
||||
// Similar to the optional argument of TYPED_TEST_SUITE above,
|
||||
// INSTANTIATE_TEST_SUITE_P takes an optional fourth argument which allows to
|
||||
// generate custom names.
|
||||
// INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes, MyTypeNames);
|
||||
// INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes, MyTypeNames);
|
||||
|
||||
#endif // 0
|
||||
|
||||
@ -180,19 +180,19 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||
//
|
||||
// Expands to the name of the typedef for the type parameters of the
|
||||
// given test case.
|
||||
# define GTEST_TYPE_PARAMS_(TestCaseName) gtest_type_params_##TestCaseName##_
|
||||
// given test suite.
|
||||
#define GTEST_TYPE_PARAMS_(TestSuiteName) gtest_type_params_##TestSuiteName##_
|
||||
|
||||
// Expands to the name of the typedef for the NameGenerator, responsible for
|
||||
// creating the suffixes of the name.
|
||||
#define GTEST_NAME_GENERATOR_(TestCaseName) \
|
||||
gtest_type_params_##TestCaseName##_NameGenerator
|
||||
#define GTEST_NAME_GENERATOR_(TestSuiteName) \
|
||||
gtest_type_params_##TestSuiteName##_NameGenerator
|
||||
|
||||
// The 'Types' template argument below must have spaces around it
|
||||
// since some compilers may choke on '>>' when passing a template
|
||||
// instance (e.g. Types<int>)
|
||||
# define TYPED_TEST_CASE(CaseName, Types, ...) \
|
||||
typedef ::testing::internal::TypeList< Types >::type GTEST_TYPE_PARAMS_( \
|
||||
#define TYPED_TEST_SUITE(CaseName, Types, ...) \
|
||||
typedef ::testing::internal::TypeList<Types>::type GTEST_TYPE_PARAMS_( \
|
||||
CaseName); \
|
||||
typedef ::testing::internal::NameGeneratorSelector<__VA_ARGS__>::type \
|
||||
GTEST_NAME_GENERATOR_(CaseName)
|
||||
@ -224,6 +224,11 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);
|
||||
void GTEST_TEST_CLASS_NAME_(CaseName, \
|
||||
TestName)<gtest_TypeParam_>::TestBody()
|
||||
|
||||
// Legacy API is deprecated but still available
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
#define TYPED_TEST_CASE TYPED_TEST_SUITE
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
#endif // GTEST_HAS_TYPED_TEST
|
||||
|
||||
// Implements type-parameterized tests.
|
||||
@ -233,73 +238,88 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||
//
|
||||
// Expands to the namespace name that the type-parameterized tests for
|
||||
// the given type-parameterized test case are defined in. The exact
|
||||
// the given type-parameterized test suite are defined in. The exact
|
||||
// name of the namespace is subject to change without notice.
|
||||
# define GTEST_CASE_NAMESPACE_(TestCaseName) \
|
||||
gtest_case_##TestCaseName##_
|
||||
#define GTEST_SUITE_NAMESPACE_(TestSuiteName) gtest_suite_##TestSuiteName##_
|
||||
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||
//
|
||||
// Expands to the name of the variable used to remember the names of
|
||||
// the defined tests in the given test case.
|
||||
# define GTEST_TYPED_TEST_CASE_P_STATE_(TestCaseName) \
|
||||
gtest_typed_test_case_p_state_##TestCaseName##_
|
||||
// the defined tests in the given test suite.
|
||||
#define GTEST_TYPED_TEST_SUITE_P_STATE_(TestSuiteName) \
|
||||
gtest_typed_test_suite_p_state_##TestSuiteName##_
|
||||
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE DIRECTLY.
|
||||
//
|
||||
// Expands to the name of the variable used to remember the names of
|
||||
// the registered tests in the given test case.
|
||||
# define GTEST_REGISTERED_TEST_NAMES_(TestCaseName) \
|
||||
gtest_registered_test_names_##TestCaseName##_
|
||||
// the registered tests in the given test suite.
|
||||
#define GTEST_REGISTERED_TEST_NAMES_(TestSuiteName) \
|
||||
gtest_registered_test_names_##TestSuiteName##_
|
||||
|
||||
// The variables defined in the type-parameterized test macros are
|
||||
// static as typically these macros are used in a .h file that can be
|
||||
// #included in multiple translation units linked together.
|
||||
# define TYPED_TEST_CASE_P(CaseName) \
|
||||
static ::testing::internal::TypedTestCasePState \
|
||||
GTEST_TYPED_TEST_CASE_P_STATE_(CaseName)
|
||||
#define TYPED_TEST_SUITE_P(SuiteName) \
|
||||
static ::testing::internal::TypedTestSuitePState \
|
||||
GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName)
|
||||
|
||||
# define TYPED_TEST_P(CaseName, TestName) \
|
||||
namespace GTEST_CASE_NAMESPACE_(CaseName) { \
|
||||
// Legacy API is deprecated but still available
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
#define TYPED_TEST_CASE_P TYPED_TEST_SUITE_P
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
#define TYPED_TEST_P(SuiteName, TestName) \
|
||||
namespace GTEST_SUITE_NAMESPACE_(SuiteName) { \
|
||||
template <typename gtest_TypeParam_> \
|
||||
class TestName : public CaseName<gtest_TypeParam_> { \
|
||||
class TestName : public SuiteName<gtest_TypeParam_> { \
|
||||
private: \
|
||||
typedef CaseName<gtest_TypeParam_> TestFixture; \
|
||||
typedef SuiteName<gtest_TypeParam_> TestFixture; \
|
||||
typedef gtest_TypeParam_ TypeParam; \
|
||||
virtual void TestBody(); \
|
||||
}; \
|
||||
static bool gtest_##TestName##_defined_ GTEST_ATTRIBUTE_UNUSED_ = \
|
||||
GTEST_TYPED_TEST_CASE_P_STATE_(CaseName).AddTestName(\
|
||||
__FILE__, __LINE__, #CaseName, #TestName); \
|
||||
GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName).AddTestName( \
|
||||
__FILE__, __LINE__, #SuiteName, #TestName); \
|
||||
} \
|
||||
template <typename gtest_TypeParam_> \
|
||||
void GTEST_CASE_NAMESPACE_(CaseName)::TestName<gtest_TypeParam_>::TestBody()
|
||||
void GTEST_SUITE_NAMESPACE_( \
|
||||
SuiteName)::TestName<gtest_TypeParam_>::TestBody()
|
||||
|
||||
# define REGISTER_TYPED_TEST_CASE_P(CaseName, ...) \
|
||||
namespace GTEST_CASE_NAMESPACE_(CaseName) { \
|
||||
#define REGISTER_TYPED_TEST_SUITE_P(SuiteName, ...) \
|
||||
namespace GTEST_SUITE_NAMESPACE_(SuiteName) { \
|
||||
typedef ::testing::internal::Templates<__VA_ARGS__>::type gtest_AllTests_; \
|
||||
} \
|
||||
static const char* const GTEST_REGISTERED_TEST_NAMES_(CaseName) \
|
||||
GTEST_ATTRIBUTE_UNUSED_ = \
|
||||
GTEST_TYPED_TEST_CASE_P_STATE_(CaseName).VerifyRegisteredTestNames( \
|
||||
static const char* const GTEST_REGISTERED_TEST_NAMES_( \
|
||||
SuiteName) GTEST_ATTRIBUTE_UNUSED_ = \
|
||||
GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName).VerifyRegisteredTestNames( \
|
||||
__FILE__, __LINE__, #__VA_ARGS__)
|
||||
|
||||
// Legacy API is deprecated but still available
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
#define REGISTER_TYPED_TEST_CASE_P REGISTER_TYPED_TEST_SUITE_P
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
// The 'Types' template argument below must have spaces around it
|
||||
// since some compilers may choke on '>>' when passing a template
|
||||
// instance (e.g. Types<int>)
|
||||
# define INSTANTIATE_TYPED_TEST_CASE_P(Prefix, CaseName, Types, ...) \
|
||||
static bool gtest_##Prefix##_##CaseName GTEST_ATTRIBUTE_UNUSED_ = \
|
||||
::testing::internal::TypeParameterizedTestCase< \
|
||||
CaseName, GTEST_CASE_NAMESPACE_(CaseName)::gtest_AllTests_, \
|
||||
::testing::internal::TypeList< Types >::type>:: \
|
||||
#define INSTANTIATE_TYPED_TEST_SUITE_P(Prefix, SuiteName, Types, ...) \
|
||||
static bool gtest_##Prefix##_##SuiteName GTEST_ATTRIBUTE_UNUSED_ = \
|
||||
::testing::internal::TypeParameterizedTestSuite< \
|
||||
SuiteName, GTEST_SUITE_NAMESPACE_(SuiteName)::gtest_AllTests_, \
|
||||
::testing::internal::TypeList<Types>::type>:: \
|
||||
Register(#Prefix, \
|
||||
::testing::internal::CodeLocation(__FILE__, __LINE__), \
|
||||
>EST_TYPED_TEST_CASE_P_STATE_(CaseName), #CaseName, \
|
||||
GTEST_REGISTERED_TEST_NAMES_(CaseName), \
|
||||
>EST_TYPED_TEST_SUITE_P_STATE_(SuiteName), #SuiteName, \
|
||||
GTEST_REGISTERED_TEST_NAMES_(SuiteName), \
|
||||
::testing::internal::GenerateNames< \
|
||||
::testing::internal::NameGeneratorSelector< \
|
||||
__VA_ARGS__>::type, \
|
||||
::testing::internal::TypeList< Types >::type>())
|
||||
::testing::internal::TypeList<Types>::type>())
|
||||
|
||||
// Legacy API is deprecated but still available
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
#define INSTANTIATE_TYPED_TEST_CASE_P INSTANTIATE_TYPED_TEST_SUITE_P
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
#endif // GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
|
@ -196,7 +196,12 @@ void ReportFailureInUnknownLocation(TestPartResult::Type result_type,
|
||||
// If we don't forward declare them the compiler might confuse the classes
|
||||
// in friendship clauses with same named classes on the scope.
|
||||
class Test;
|
||||
class TestCase;
|
||||
class TestSuite;
|
||||
|
||||
// Old API is still available but deprecated
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
using TestCase = TestSuite;
|
||||
#endif
|
||||
class TestInfo;
|
||||
class UnitTest;
|
||||
|
||||
@ -328,7 +333,6 @@ class GTEST_API_ AssertionResult {
|
||||
const char* message() const {
|
||||
return message_.get() != nullptr ? message_->c_str() : "";
|
||||
}
|
||||
// FIXME: Remove this after making sure no clients use it.
|
||||
// Deprecated; please use message() instead.
|
||||
const char* failure_message() const { return message(); }
|
||||
|
||||
@ -387,8 +391,8 @@ namespace testing {
|
||||
|
||||
// The abstract class that all tests inherit from.
|
||||
//
|
||||
// In Google Test, a unit test program contains one or many TestCases, and
|
||||
// each TestCase contains one or many Tests.
|
||||
// In Google Test, a unit test program contains one or many TestSuites, and
|
||||
// each TestSuite contains one or many Tests.
|
||||
//
|
||||
// When you define a test using the TEST macro, you don't need to
|
||||
// explicitly derive from Test - the TEST macro automatically does
|
||||
@ -412,29 +416,30 @@ class GTEST_API_ Test {
|
||||
public:
|
||||
friend class TestInfo;
|
||||
|
||||
// Defines types for pointers to functions that set up and tear down
|
||||
// a test case.
|
||||
typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc;
|
||||
typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc;
|
||||
|
||||
// The d'tor is virtual as we intend to inherit from Test.
|
||||
virtual ~Test();
|
||||
|
||||
// Sets up the stuff shared by all tests in this test case.
|
||||
//
|
||||
// Google Test will call Foo::SetUpTestCase() before running the first
|
||||
// Google Test will call Foo::SetUpTestSuite() before running the first
|
||||
// test in test case Foo. Hence a sub-class can define its own
|
||||
// SetUpTestCase() method to shadow the one defined in the super
|
||||
// SetUpTestSuite() method to shadow the one defined in the super
|
||||
// class.
|
||||
static void SetUpTestCase() {}
|
||||
static void SetUpTestSuite() {}
|
||||
|
||||
// Tears down the stuff shared by all tests in this test case.
|
||||
//
|
||||
// Google Test will call Foo::TearDownTestCase() after running the last
|
||||
// Google Test will call Foo::TearDownTestSuite() after running the last
|
||||
// test in test case Foo. Hence a sub-class can define its own
|
||||
// TearDownTestCase() method to shadow the one defined in the super
|
||||
// TearDownTestSuite() method to shadow the one defined in the super
|
||||
// class.
|
||||
static void TearDownTestSuite() {}
|
||||
|
||||
// Legacy API is deprecated but still available
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
static void TearDownTestCase() {}
|
||||
static void SetUpTestCase() {}
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
// Returns true iff the current test has a fatal failure.
|
||||
static bool HasFatalFailure();
|
||||
@ -449,15 +454,15 @@ class GTEST_API_ Test {
|
||||
// non-fatal) failure.
|
||||
static bool HasFailure() { return HasFatalFailure() || HasNonfatalFailure(); }
|
||||
|
||||
// Logs a property for the current test, test case, or for the entire
|
||||
// Logs a property for the current test, test suite, or for the entire
|
||||
// invocation of the test program when used outside of the context of a
|
||||
// test case. Only the last value for a given key is remembered. These
|
||||
// test suite. Only the last value for a given key is remembered. These
|
||||
// are public static so they can be called from utility functions that are
|
||||
// not members of the test fixture. Calls to RecordProperty made during
|
||||
// lifespan of the test (from the moment its constructor starts to the
|
||||
// moment its destructor finishes) will be output in XML as attributes of
|
||||
// the <testcase> element. Properties recorded from fixture's
|
||||
// SetUpTestCase or TearDownTestCase are logged as attributes of the
|
||||
// SetUpTestSuite or TearDownTestSuite are logged as attributes of the
|
||||
// corresponding <testsuite> element. Calls to RecordProperty made in the
|
||||
// global context (before or after invocation of RUN_ALL_TESTS and from
|
||||
// SetUp/TearDown method of Environment objects registered with Google
|
||||
@ -477,7 +482,7 @@ class GTEST_API_ Test {
|
||||
|
||||
private:
|
||||
// Returns true iff the current test has the same fixture class as
|
||||
// the first test in the current test case.
|
||||
// the first test in the current test suite.
|
||||
static bool HasSameFixtureClass();
|
||||
|
||||
// Runs the test after the test fixture has been set up.
|
||||
@ -600,7 +605,7 @@ class GTEST_API_ TestResult {
|
||||
|
||||
private:
|
||||
friend class TestInfo;
|
||||
friend class TestCase;
|
||||
friend class TestSuite;
|
||||
friend class UnitTest;
|
||||
friend class internal::DefaultGlobalTestPartResultReporter;
|
||||
friend class internal::ExecDeathTest;
|
||||
@ -632,7 +637,7 @@ class GTEST_API_ TestResult {
|
||||
const TestProperty& test_property);
|
||||
|
||||
// Adds a failure if the key is a reserved attribute of Google Test
|
||||
// testcase tags. Returns true if the property is valid.
|
||||
// testsuite tags. Returns true if the property is valid.
|
||||
// FIXME: Validate attribute names are legal and human readable.
|
||||
static bool ValidateTestProperty(const std::string& xml_element,
|
||||
const TestProperty& test_property);
|
||||
@ -671,7 +676,7 @@ class GTEST_API_ TestResult {
|
||||
|
||||
// A TestInfo object stores the following information about a test:
|
||||
//
|
||||
// Test case name
|
||||
// Test suite name
|
||||
// Test name
|
||||
// Whether the test should be run
|
||||
// A function pointer that creates the test object when invoked
|
||||
@ -686,8 +691,13 @@ class GTEST_API_ TestInfo {
|
||||
// don't inherit from TestInfo.
|
||||
~TestInfo();
|
||||
|
||||
// Returns the test case name.
|
||||
const char* test_case_name() const { return test_case_name_.c_str(); }
|
||||
// Returns the test suite name.
|
||||
const char* test_suite_name() const { return test_suite_name_.c_str(); }
|
||||
|
||||
// Legacy API is deprecated but still available
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
const char* test_case_name() const { return test_suite_name(); }
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
// Returns the test name.
|
||||
const char* name() const { return name_.c_str(); }
|
||||
@ -720,7 +730,7 @@ class GTEST_API_ TestInfo {
|
||||
// been specified) and its full name matches the user-specified filter.
|
||||
//
|
||||
// Google Test allows the user to filter the tests by their full names.
|
||||
// The full name of a test Bar in test case Foo is defined as
|
||||
// The full name of a test Bar in test suite Foo is defined as
|
||||
// "Foo.Bar". Only the tests that match the filter will run.
|
||||
//
|
||||
// A filter is a colon-separated list of glob (not regex) patterns,
|
||||
@ -748,19 +758,19 @@ class GTEST_API_ TestInfo {
|
||||
friend class internal::DefaultDeathTestFactory;
|
||||
#endif // GTEST_HAS_DEATH_TEST
|
||||
friend class Test;
|
||||
friend class TestCase;
|
||||
friend class TestSuite;
|
||||
friend class internal::UnitTestImpl;
|
||||
friend class internal::StreamingListenerTest;
|
||||
friend TestInfo* internal::MakeAndRegisterTestInfo(
|
||||
const char* test_case_name, const char* name, const char* type_param,
|
||||
const char* test_suite_name, const char* name, const char* type_param,
|
||||
const char* value_param, internal::CodeLocation code_location,
|
||||
internal::TypeId fixture_class_id, Test::SetUpTestCaseFunc set_up_tc,
|
||||
Test::TearDownTestCaseFunc tear_down_tc,
|
||||
internal::TypeId fixture_class_id, internal::SetUpTestSuiteFunc set_up_tc,
|
||||
internal::TearDownTestSuiteFunc tear_down_tc,
|
||||
internal::TestFactoryBase* factory);
|
||||
|
||||
// Constructs a TestInfo object. The newly constructed instance assumes
|
||||
// ownership of the factory object.
|
||||
TestInfo(const std::string& test_case_name, const std::string& name,
|
||||
TestInfo(const std::string& test_suite_name, const std::string& name,
|
||||
const char* a_type_param, // NULL if not a type-parameterized test
|
||||
const char* a_value_param, // NULL if not a value-parameterized test
|
||||
internal::CodeLocation a_code_location,
|
||||
@ -782,7 +792,7 @@ class GTEST_API_ TestInfo {
|
||||
}
|
||||
|
||||
// These fields are immutable properties of the test.
|
||||
const std::string test_case_name_; // Test case name
|
||||
const std::string test_suite_name_; // test suite name
|
||||
const std::string name_; // Test name
|
||||
// Name of the parameter type, or NULL if this is not a typed or a
|
||||
// type-parameterized test.
|
||||
@ -807,71 +817,71 @@ class GTEST_API_ TestInfo {
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfo);
|
||||
};
|
||||
|
||||
// A test case, which consists of a vector of TestInfos.
|
||||
// A test suite, which consists of a vector of TestInfos.
|
||||
//
|
||||
// TestCase is not copyable.
|
||||
class GTEST_API_ TestCase {
|
||||
// TestSuite is not copyable.
|
||||
class GTEST_API_ TestSuite {
|
||||
public:
|
||||
// Creates a TestCase with the given name.
|
||||
// Creates a TestSuite with the given name.
|
||||
//
|
||||
// TestCase does NOT have a default constructor. Always use this
|
||||
// constructor to create a TestCase object.
|
||||
// TestSuite does NOT have a default constructor. Always use this
|
||||
// constructor to create a TestSuite object.
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// name: name of the test case
|
||||
// name: name of the test suite
|
||||
// a_type_param: the name of the test's type parameter, or NULL if
|
||||
// this is not a type-parameterized test.
|
||||
// set_up_tc: pointer to the function that sets up the test case
|
||||
// tear_down_tc: pointer to the function that tears down the test case
|
||||
TestCase(const char* name, const char* a_type_param,
|
||||
Test::SetUpTestCaseFunc set_up_tc,
|
||||
Test::TearDownTestCaseFunc tear_down_tc);
|
||||
// set_up_tc: pointer to the function that sets up the test suite
|
||||
// tear_down_tc: pointer to the function that tears down the test suite
|
||||
TestSuite(const char* name, const char* a_type_param,
|
||||
internal::SetUpTestSuiteFunc set_up_tc,
|
||||
internal::TearDownTestSuiteFunc tear_down_tc);
|
||||
|
||||
// Destructor of TestCase.
|
||||
virtual ~TestCase();
|
||||
// Destructor of TestSuite.
|
||||
virtual ~TestSuite();
|
||||
|
||||
// Gets the name of the TestCase.
|
||||
// Gets the name of the TestSuite.
|
||||
const char* name() const { return name_.c_str(); }
|
||||
|
||||
// Returns the name of the parameter type, or NULL if this is not a
|
||||
// type-parameterized test case.
|
||||
// type-parameterized test suite.
|
||||
const char* type_param() const {
|
||||
if (type_param_.get() != nullptr) return type_param_->c_str();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Returns true if any test in this test case should run.
|
||||
// Returns true if any test in this test suite should run.
|
||||
bool should_run() const { return should_run_; }
|
||||
|
||||
// Gets the number of successful tests in this test case.
|
||||
// Gets the number of successful tests in this test suite.
|
||||
int successful_test_count() const;
|
||||
|
||||
// Gets the number of skipped tests in this test case.
|
||||
// Gets the number of skipped tests in this test suite.
|
||||
int skipped_test_count() const;
|
||||
|
||||
// Gets the number of failed tests in this test case.
|
||||
// Gets the number of failed tests in this test suite.
|
||||
int failed_test_count() const;
|
||||
|
||||
// Gets the number of disabled tests that will be reported in the XML report.
|
||||
int reportable_disabled_test_count() const;
|
||||
|
||||
// Gets the number of disabled tests in this test case.
|
||||
// Gets the number of disabled tests in this test suite.
|
||||
int disabled_test_count() const;
|
||||
|
||||
// Gets the number of tests to be printed in the XML report.
|
||||
int reportable_test_count() const;
|
||||
|
||||
// Get the number of tests in this test case that should run.
|
||||
// Get the number of tests in this test suite that should run.
|
||||
int test_to_run_count() const;
|
||||
|
||||
// Gets the number of all tests in this test case.
|
||||
// Gets the number of all tests in this test suite.
|
||||
int total_test_count() const;
|
||||
|
||||
// Returns true iff the test case passed.
|
||||
// Returns true iff the test suite passed.
|
||||
bool Passed() const { return !Failed(); }
|
||||
|
||||
// Returns true iff the test case failed.
|
||||
// Returns true iff the test suite failed.
|
||||
bool Failed() const { return failed_test_count() > 0; }
|
||||
|
||||
// Returns the elapsed time, in milliseconds.
|
||||
@ -882,17 +892,17 @@ class GTEST_API_ TestCase {
|
||||
const TestInfo* GetTestInfo(int i) const;
|
||||
|
||||
// Returns the TestResult that holds test properties recorded during
|
||||
// execution of SetUpTestCase and TearDownTestCase.
|
||||
// execution of SetUpTestSuite and TearDownTestSuite.
|
||||
const TestResult& ad_hoc_test_result() const { return ad_hoc_test_result_; }
|
||||
|
||||
private:
|
||||
friend class Test;
|
||||
friend class internal::UnitTestImpl;
|
||||
|
||||
// Gets the (mutable) vector of TestInfos in this TestCase.
|
||||
// Gets the (mutable) vector of TestInfos in this TestSuite.
|
||||
std::vector<TestInfo*>& test_info_list() { return test_info_list_; }
|
||||
|
||||
// Gets the (immutable) vector of TestInfos in this TestCase.
|
||||
// Gets the (immutable) vector of TestInfos in this TestSuite.
|
||||
const std::vector<TestInfo*>& test_info_list() const {
|
||||
return test_info_list_;
|
||||
}
|
||||
@ -904,28 +914,36 @@ class GTEST_API_ TestCase {
|
||||
// Sets the should_run member.
|
||||
void set_should_run(bool should) { should_run_ = should; }
|
||||
|
||||
// Adds a TestInfo to this test case. Will delete the TestInfo upon
|
||||
// destruction of the TestCase object.
|
||||
void AddTestInfo(TestInfo* test_info);
|
||||
// Adds a TestInfo to this test suite. Will delete the TestInfo upon
|
||||
// destruction of the TestSuite object.
|
||||
void AddTestInfo(TestInfo * test_info);
|
||||
|
||||
// Clears the results of all tests in this test case.
|
||||
// Clears the results of all tests in this test suite.
|
||||
void ClearResult();
|
||||
|
||||
// Clears the results of all tests in the given test case.
|
||||
static void ClearTestCaseResult(TestCase* test_case) {
|
||||
test_case->ClearResult();
|
||||
// Clears the results of all tests in the given test suite.
|
||||
static void ClearTestSuiteResult(TestSuite* test_suite) {
|
||||
test_suite->ClearResult();
|
||||
}
|
||||
|
||||
// Runs every test in this TestCase.
|
||||
// Runs every test in this TestSuite.
|
||||
void Run();
|
||||
|
||||
// Runs SetUpTestCase() for this TestCase. This wrapper is needed
|
||||
// for catching exceptions thrown from SetUpTestCase().
|
||||
void RunSetUpTestCase() { (*set_up_tc_)(); }
|
||||
// Runs SetUpTestSuite() for this TestSuite. This wrapper is needed
|
||||
// for catching exceptions thrown from SetUpTestSuite().
|
||||
void RunSetUpTestSuite() {
|
||||
if (set_up_tc_ != nullptr) {
|
||||
(*set_up_tc_)();
|
||||
}
|
||||
}
|
||||
|
||||
// Runs TearDownTestCase() for this TestCase. This wrapper is
|
||||
// needed for catching exceptions thrown from TearDownTestCase().
|
||||
void RunTearDownTestCase() { (*tear_down_tc_)(); }
|
||||
// Runs TearDownTestSuite() for this TestSuite. This wrapper is
|
||||
// needed for catching exceptions thrown from TearDownTestSuite().
|
||||
void RunTearDownTestSuite() {
|
||||
if (tear_down_tc_ != nullptr) {
|
||||
(*tear_down_tc_)();
|
||||
}
|
||||
}
|
||||
|
||||
// Returns true iff test passed.
|
||||
static bool TestPassed(const TestInfo* test_info) {
|
||||
@ -963,13 +981,13 @@ class GTEST_API_ TestCase {
|
||||
return test_info->should_run();
|
||||
}
|
||||
|
||||
// Shuffles the tests in this test case.
|
||||
// Shuffles the tests in this test suite.
|
||||
void ShuffleTests(internal::Random* random);
|
||||
|
||||
// Restores the test order to before the first shuffle.
|
||||
void UnshuffleTests();
|
||||
|
||||
// Name of the test case.
|
||||
// Name of the test suite.
|
||||
std::string name_;
|
||||
// Name of the parameter type, or NULL if this is not a typed or a
|
||||
// type-parameterized test.
|
||||
@ -981,20 +999,20 @@ class GTEST_API_ TestCase {
|
||||
// shuffling and restoring the test order. The i-th element in this
|
||||
// vector is the index of the i-th test in the shuffled test list.
|
||||
std::vector<int> test_indices_;
|
||||
// Pointer to the function that sets up the test case.
|
||||
Test::SetUpTestCaseFunc set_up_tc_;
|
||||
// Pointer to the function that tears down the test case.
|
||||
Test::TearDownTestCaseFunc tear_down_tc_;
|
||||
// True iff any test in this test case should run.
|
||||
// Pointer to the function that sets up the test suite.
|
||||
internal::SetUpTestSuiteFunc set_up_tc_;
|
||||
// Pointer to the function that tears down the test suite.
|
||||
internal::TearDownTestSuiteFunc tear_down_tc_;
|
||||
// True iff any test in this test suite should run.
|
||||
bool should_run_;
|
||||
// Elapsed time, in milliseconds.
|
||||
TimeInMillis elapsed_time_;
|
||||
// Holds test properties recorded during execution of SetUpTestCase and
|
||||
// TearDownTestCase.
|
||||
// Holds test properties recorded during execution of SetUpTestSuite and
|
||||
// TearDownTestSuite.
|
||||
TestResult ad_hoc_test_result_;
|
||||
|
||||
// We disallow copying TestCases.
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestCase);
|
||||
// We disallow copying TestSuites.
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestSuite);
|
||||
};
|
||||
|
||||
// An Environment object is capable of setting up and tearing down an
|
||||
@ -1062,8 +1080,13 @@ class TestEventListener {
|
||||
// Fired after environment set-up for each iteration of tests ends.
|
||||
virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) = 0;
|
||||
|
||||
// Fired before the test case starts.
|
||||
virtual void OnTestCaseStart(const TestCase& test_case) = 0;
|
||||
// Fired before the test suite starts.
|
||||
virtual void OnTestSuiteStart(const TestSuite& test_suite) {}
|
||||
|
||||
// Legacy API is deprecated but still available
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
virtual void OnTestCaseStart(const TestCase& test_case) {}
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
// Fired before the test starts.
|
||||
virtual void OnTestStart(const TestInfo& test_info) = 0;
|
||||
@ -1076,8 +1099,13 @@ class TestEventListener {
|
||||
// Fired after the test ends.
|
||||
virtual void OnTestEnd(const TestInfo& test_info) = 0;
|
||||
|
||||
// Fired after the test case ends.
|
||||
virtual void OnTestCaseEnd(const TestCase& test_case) = 0;
|
||||
// Fired after the test suite ends.
|
||||
virtual void OnTestSuiteEnd(const TestSuite& test_suite) {}
|
||||
|
||||
// Legacy API is deprecated but still available
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
virtual void OnTestCaseEnd(const TestCase& test_case) {}
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
// Fired before environment tear-down for each iteration of tests starts.
|
||||
virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) = 0;
|
||||
@ -1104,11 +1132,20 @@ class EmptyTestEventListener : public TestEventListener {
|
||||
int /*iteration*/) override {}
|
||||
void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) override {}
|
||||
void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) override {}
|
||||
void OnTestCaseStart(const TestCase& /*test_case*/) override {}
|
||||
void OnTestSuiteStart(const TestSuite& /*test_suite*/) override {}
|
||||
// Legacy API is deprecated but still available
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
void OnTestCaseStart(const TestCase& tc /*test_suite*/) override {}
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
void OnTestStart(const TestInfo& /*test_info*/) override {}
|
||||
void OnTestPartResult(const TestPartResult& /*test_part_result*/) override {}
|
||||
void OnTestEnd(const TestInfo& /*test_info*/) override {}
|
||||
void OnTestCaseEnd(const TestCase& /*test_case*/) override {}
|
||||
void OnTestSuiteEnd(const TestSuite& /*test_suite*/) override {}
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
void OnTestCaseEnd(const TestCase& tc /*test_suite*/) override {}
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) override {}
|
||||
void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) override {}
|
||||
void OnTestIterationEnd(const UnitTest& /*unit_test*/,
|
||||
@ -1153,7 +1190,7 @@ class GTEST_API_ TestEventListeners {
|
||||
}
|
||||
|
||||
private:
|
||||
friend class TestCase;
|
||||
friend class TestSuite;
|
||||
friend class TestInfo;
|
||||
friend class internal::DefaultGlobalTestPartResultReporter;
|
||||
friend class internal::NoExecDeathTest;
|
||||
@ -1194,7 +1231,7 @@ class GTEST_API_ TestEventListeners {
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestEventListeners);
|
||||
};
|
||||
|
||||
// A UnitTest consists of a vector of TestCases.
|
||||
// A UnitTest consists of a vector of TestSuites.
|
||||
//
|
||||
// This is a singleton class. The only instance of UnitTest is
|
||||
// created when UnitTest::GetInstance() is first called. This
|
||||
@ -1223,9 +1260,14 @@ class GTEST_API_ UnitTest {
|
||||
// was executed. The UnitTest object owns the string.
|
||||
const char* original_working_dir() const;
|
||||
|
||||
// Returns the TestCase object for the test that's currently running,
|
||||
// Returns the TestSuite object for the test that's currently running,
|
||||
// or NULL if no test is running.
|
||||
const TestSuite* current_test_suite() const GTEST_LOCK_EXCLUDED_(mutex_);
|
||||
|
||||
// Legacy API is still available but deprecated
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
const TestCase* current_test_case() const GTEST_LOCK_EXCLUDED_(mutex_);
|
||||
#endif
|
||||
|
||||
// Returns the TestInfo object for the test that's currently running,
|
||||
// or NULL if no test is running.
|
||||
@ -1234,25 +1276,33 @@ class GTEST_API_ UnitTest {
|
||||
// Returns the random seed used at the start of the current test run.
|
||||
int random_seed() const;
|
||||
|
||||
// Returns the ParameterizedTestCaseRegistry object used to keep track of
|
||||
// Returns the ParameterizedTestSuiteRegistry object used to keep track of
|
||||
// value-parameterized tests and instantiate and register them.
|
||||
//
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
|
||||
internal::ParameterizedTestCaseRegistry& parameterized_test_registry()
|
||||
internal::ParameterizedTestSuiteRegistry& parameterized_test_registry()
|
||||
GTEST_LOCK_EXCLUDED_(mutex_);
|
||||
|
||||
// Gets the number of successful test cases.
|
||||
int successful_test_case_count() const;
|
||||
// Gets the number of successful test suites.
|
||||
int successful_test_suite_count() const;
|
||||
|
||||
// Gets the number of failed test cases.
|
||||
int failed_test_case_count() const;
|
||||
// Gets the number of failed test suites.
|
||||
int failed_test_suite_count() const;
|
||||
|
||||
// Gets the number of all test cases.
|
||||
int total_test_case_count() const;
|
||||
// Gets the number of all test suites.
|
||||
int total_test_suite_count() const;
|
||||
|
||||
// Gets the number of all test cases that contain at least one test
|
||||
// Gets the number of all test suites that contain at least one test
|
||||
// that should run.
|
||||
int test_suite_to_run_count() const;
|
||||
|
||||
// Legacy API is deprecated but still available
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
int successful_test_case_count() const;
|
||||
int failed_test_case_count() const;
|
||||
int total_test_case_count() const;
|
||||
int test_case_to_run_count() const;
|
||||
#endif // EMOVE_LEGACY_TEST_CASEAPI
|
||||
|
||||
// Gets the number of successful tests.
|
||||
int successful_test_count() const;
|
||||
@ -1285,19 +1335,24 @@ class GTEST_API_ UnitTest {
|
||||
// Gets the elapsed time, in milliseconds.
|
||||
TimeInMillis elapsed_time() const;
|
||||
|
||||
// Returns true iff the unit test passed (i.e. all test cases passed).
|
||||
// Returns true iff the unit test passed (i.e. all test suites passed).
|
||||
bool Passed() const;
|
||||
|
||||
// Returns true iff the unit test failed (i.e. some test case failed
|
||||
// Returns true iff the unit test failed (i.e. some test suite failed
|
||||
// or something outside of all tests failed).
|
||||
bool Failed() const;
|
||||
|
||||
// Gets the i-th test case among all the test cases. i can range from 0 to
|
||||
// total_test_case_count() - 1. If i is not in that range, returns NULL.
|
||||
// Gets the i-th test suite among all the test suites. i can range from 0 to
|
||||
// total_test_suite_count() - 1. If i is not in that range, returns NULL.
|
||||
const TestSuite* GetTestSuite(int i) const;
|
||||
|
||||
// Legacy API is deprecated but still available
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
const TestCase* GetTestCase(int i) const;
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
// Returns the TestResult containing information on test failures and
|
||||
// properties logged outside of individual test cases.
|
||||
// properties logged outside of individual test suites.
|
||||
const TestResult& ad_hoc_test_result() const;
|
||||
|
||||
// Returns the list of event listeners that can be used to track events
|
||||
@ -1327,15 +1382,15 @@ class GTEST_API_ UnitTest {
|
||||
GTEST_LOCK_EXCLUDED_(mutex_);
|
||||
|
||||
// Adds a TestProperty to the current TestResult object when invoked from
|
||||
// inside a test, to current TestCase's ad_hoc_test_result_ when invoked
|
||||
// from SetUpTestCase or TearDownTestCase, or to the global property set
|
||||
// inside a test, to current TestSuite's ad_hoc_test_result_ when invoked
|
||||
// from SetUpTestSuite or TearDownTestSuite, or to the global property set
|
||||
// when invoked elsewhere. If the result already contains a property with
|
||||
// the same key, the value will be updated.
|
||||
void RecordProperty(const std::string& key, const std::string& value);
|
||||
|
||||
// Gets the i-th test case among all the test cases. i can range from 0 to
|
||||
// total_test_case_count() - 1. If i is not in that range, returns NULL.
|
||||
TestCase* GetMutableTestCase(int i);
|
||||
// Gets the i-th test suite among all the test suites. i can range from 0 to
|
||||
// total_test_suite_count() - 1. If i is not in that range, returns NULL.
|
||||
TestSuite* GetMutableTestSuite(int i);
|
||||
|
||||
// Accessors for the implementation object.
|
||||
internal::UnitTestImpl* impl() { return impl_; }
|
||||
@ -1504,7 +1559,7 @@ class EqHelper<true> {
|
||||
// expands to Compare("", "", NULL, my_ptr), which requires a conversion
|
||||
// to match the Secret* in the other overload, which would otherwise make
|
||||
// this template match better.
|
||||
typename EnableIf<!is_pointer<T2>::value>::type* = nullptr) {
|
||||
typename EnableIf<!std::is_pointer<T2>::value>::type* = nullptr) {
|
||||
return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs);
|
||||
}
|
||||
|
||||
@ -1784,7 +1839,7 @@ GTEST_API_ GTEST_ATTRIBUTE_PRINTF_(2, 3) void ColoredPrintf(GTestColor color,
|
||||
// Foo foo;
|
||||
// ASSERT_TRUE(foo.DoesBar(GetParam()));
|
||||
// }
|
||||
// INSTANTIATE_TEST_CASE_P(OneToTenRange, FooTest, ::testing::Range(1, 10));
|
||||
// INSTANTIATE_TEST_SUITE_P(OneToTenRange, FooTest, ::testing::Range(1, 10));
|
||||
|
||||
template <typename T>
|
||||
class WithParamInterface {
|
||||
@ -2246,11 +2301,11 @@ bool StaticAssertTypeEq() {
|
||||
|
||||
// Defines a test.
|
||||
//
|
||||
// The first parameter is the name of the test case, and the second
|
||||
// parameter is the name of the test within the test case.
|
||||
// The first parameter is the name of the test suite, and the second
|
||||
// parameter is the name of the test within the test suite.
|
||||
//
|
||||
// The convention is to end the test case name with "Test". For
|
||||
// example, a test case for the Foo class can be named FooTest.
|
||||
// The convention is to end the test suite name with "Test". For
|
||||
// example, a test suite for the Foo class can be named FooTest.
|
||||
//
|
||||
// Test code should appear between braces after an invocation of
|
||||
// this macro. Example:
|
||||
@ -2269,21 +2324,21 @@ bool StaticAssertTypeEq() {
|
||||
// code. GetTestTypeId() is guaranteed to always return the same
|
||||
// value, as it always calls GetTypeId<>() from the Google Test
|
||||
// framework.
|
||||
#define GTEST_TEST(test_case_name, test_name) \
|
||||
GTEST_TEST_(test_case_name, test_name, ::testing::Test, \
|
||||
#define GTEST_TEST(test_suite_name, test_name) \
|
||||
GTEST_TEST_(test_suite_name, test_name, ::testing::Test, \
|
||||
::testing::internal::GetTestTypeId())
|
||||
|
||||
// Define this macro to 1 to omit the definition of TEST(), which
|
||||
// is a generic name and clashes with some other libraries.
|
||||
#if !GTEST_DONT_DEFINE_TEST
|
||||
#define TEST(test_case_name, test_name) GTEST_TEST(test_case_name, test_name)
|
||||
#define TEST(test_suite_name, test_name) GTEST_TEST(test_suite_name, test_name)
|
||||
#endif
|
||||
|
||||
// Defines a test that uses a test fixture.
|
||||
//
|
||||
// The first parameter is the name of the test fixture class, which
|
||||
// also doubles as the test case name. The second parameter is the
|
||||
// name of the test within the test case.
|
||||
// also doubles as the test suite name. The second parameter is the
|
||||
// name of the test within the test suite.
|
||||
//
|
||||
// A test fixture class must be declared earlier. The user should put
|
||||
// the test code between braces after using this macro. Example:
|
||||
@ -2317,6 +2372,86 @@ GTEST_API_ std::string TempDir();
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
// Dynamically registers a test with the framework.
|
||||
//
|
||||
// This is an advanced API only to be used when the `TEST` macros are
|
||||
// insufficient. The macros should be preferred when possible, as they avoid
|
||||
// most of the complexity of calling this function.
|
||||
//
|
||||
// The `factory` argument is a factory callable (move-constructible) object or
|
||||
// function pointer that creates a new instance of the Test object. It
|
||||
// handles ownership to the caller. The signature of the callable is
|
||||
// `Fixture*()`, where `Fixture` is the test fixture class for the test. All
|
||||
// tests registered with the same `test_suite_name` must return the same
|
||||
// fixture type. This is checked at runtime.
|
||||
//
|
||||
// The framework will infer the fixture class from the factory and will call
|
||||
// the `SetUpTestSuite` and `TearDownTestSuite` for it.
|
||||
//
|
||||
// Must be called before `RUN_ALL_TESTS()` is invoked, otherwise behavior is
|
||||
// undefined.
|
||||
//
|
||||
// Use case example:
|
||||
//
|
||||
// class MyFixture : public ::testing::Test {
|
||||
// public:
|
||||
// // All of these optional, just like in regular macro usage.
|
||||
// static void SetUpTestSuite() { ... }
|
||||
// static void TearDownTestSuite() { ... }
|
||||
// void SetUp() override { ... }
|
||||
// void TearDown() override { ... }
|
||||
// };
|
||||
//
|
||||
// class MyTest : public MyFixture {
|
||||
// public:
|
||||
// explicit MyTest(int data) : data_(data) {}
|
||||
// void TestBody() override { ... }
|
||||
//
|
||||
// private:
|
||||
// int data_;
|
||||
// };
|
||||
//
|
||||
// void RegisterMyTests(const std::vector<int>& values) {
|
||||
// for (int v : values) {
|
||||
// ::testing::RegisterTest(
|
||||
// "MyFixture", ("Test" + std::to_string(v)).c_str(), nullptr,
|
||||
// std::to_string(v).c_str(),
|
||||
// __FILE__, __LINE__,
|
||||
// // Important to use the fixture type as the return type here.
|
||||
// [=]() -> MyFixture* { return new MyTest(v); });
|
||||
// }
|
||||
// }
|
||||
// ...
|
||||
// int main(int argc, char** argv) {
|
||||
// std::vector<int> values_to_test = LoadValuesFromConfig();
|
||||
// RegisterMyTests(values_to_test);
|
||||
// ...
|
||||
// return RUN_ALL_TESTS();
|
||||
// }
|
||||
//
|
||||
template <int&... ExplicitParameterBarrier, typename Factory>
|
||||
TestInfo* RegisterTest(const char* test_suite_name, const char* test_name,
|
||||
const char* type_param, const char* value_param,
|
||||
const char* file, int line, Factory factory) {
|
||||
using TestT = typename std::remove_pointer<decltype(factory())>::type;
|
||||
|
||||
class FactoryImpl : public internal::TestFactoryBase {
|
||||
public:
|
||||
explicit FactoryImpl(Factory f) : factory_(std::move(f)) {}
|
||||
Test* CreateTest() override { return factory_(); }
|
||||
|
||||
private:
|
||||
Factory factory_;
|
||||
};
|
||||
|
||||
return internal::MakeAndRegisterTestInfo(
|
||||
test_suite_name, test_name, type_param, value_param,
|
||||
internal::CodeLocation(file, line), internal::GetTypeId<TestT>(),
|
||||
internal::SuiteApiResolver<TestT>::GetSetUpCaseOrSuite(),
|
||||
internal::SuiteApiResolver<TestT>::GetTearDownCaseOrSuite(),
|
||||
new FactoryImpl{std::move(factory)});
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
|
||||
// Use this function in main() to run all tests. It returns 0 if all
|
||||
|
@ -27,11 +27,10 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This file is AUTOMATICALLY GENERATED on 01/02/2018 by command
|
||||
// This file is AUTOMATICALLY GENERATED on 01/02/2019 by command
|
||||
// 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
|
||||
//
|
||||
// Implements a family of generic predicate assertion macros.
|
||||
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
|
||||
@ -67,6 +66,8 @@ namespace testing {
|
||||
// We also define the EXPECT_* variations.
|
||||
//
|
||||
// For now we only support predicates whose arity is at most 5.
|
||||
// Please email googletestframework@googlegroups.com if you need
|
||||
// support for higher arities.
|
||||
|
||||
// GTEST_ASSERT_ is the basic statement to which all of the assertions
|
||||
// in this file reduce. Don't use this in your code.
|
||||
@ -89,9 +90,10 @@ AssertionResult AssertPred1Helper(const char* pred_text,
|
||||
const T1& v1) {
|
||||
if (pred(v1)) return AssertionSuccess();
|
||||
|
||||
return AssertionFailure() << pred_text << "("
|
||||
<< e1 << ") evaluates to false, where"
|
||||
<< "\n" << e1 << " evaluates to " << v1;
|
||||
return AssertionFailure()
|
||||
<< pred_text << "(" << e1 << ") evaluates to false, where"
|
||||
<< "\n"
|
||||
<< e1 << " evaluates to " << ::testing::PrintToString(v1);
|
||||
}
|
||||
|
||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT1.
|
||||
@ -133,11 +135,12 @@ AssertionResult AssertPred2Helper(const char* pred_text,
|
||||
const T2& v2) {
|
||||
if (pred(v1, v2)) return AssertionSuccess();
|
||||
|
||||
return AssertionFailure() << pred_text << "("
|
||||
<< e1 << ", "
|
||||
<< e2 << ") evaluates to false, where"
|
||||
<< "\n" << e1 << " evaluates to " << v1
|
||||
<< "\n" << e2 << " evaluates to " << v2;
|
||||
return AssertionFailure()
|
||||
<< pred_text << "(" << e1 << ", " << e2
|
||||
<< ") evaluates to false, where"
|
||||
<< "\n"
|
||||
<< e1 << " evaluates to " << ::testing::PrintToString(v1) << "\n"
|
||||
<< e2 << " evaluates to " << ::testing::PrintToString(v2);
|
||||
}
|
||||
|
||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2.
|
||||
@ -184,13 +187,13 @@ AssertionResult AssertPred3Helper(const char* pred_text,
|
||||
const T3& v3) {
|
||||
if (pred(v1, v2, v3)) return AssertionSuccess();
|
||||
|
||||
return AssertionFailure() << pred_text << "("
|
||||
<< e1 << ", "
|
||||
<< e2 << ", "
|
||||
<< e3 << ") evaluates to false, where"
|
||||
<< "\n" << e1 << " evaluates to " << v1
|
||||
<< "\n" << e2 << " evaluates to " << v2
|
||||
<< "\n" << e3 << " evaluates to " << v3;
|
||||
return AssertionFailure()
|
||||
<< pred_text << "(" << e1 << ", " << e2 << ", " << e3
|
||||
<< ") evaluates to false, where"
|
||||
<< "\n"
|
||||
<< e1 << " evaluates to " << ::testing::PrintToString(v1) << "\n"
|
||||
<< e2 << " evaluates to " << ::testing::PrintToString(v2) << "\n"
|
||||
<< e3 << " evaluates to " << ::testing::PrintToString(v3);
|
||||
}
|
||||
|
||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT3.
|
||||
@ -242,15 +245,14 @@ AssertionResult AssertPred4Helper(const char* pred_text,
|
||||
const T4& v4) {
|
||||
if (pred(v1, v2, v3, v4)) return AssertionSuccess();
|
||||
|
||||
return AssertionFailure() << pred_text << "("
|
||||
<< e1 << ", "
|
||||
<< e2 << ", "
|
||||
<< e3 << ", "
|
||||
<< e4 << ") evaluates to false, where"
|
||||
<< "\n" << e1 << " evaluates to " << v1
|
||||
<< "\n" << e2 << " evaluates to " << v2
|
||||
<< "\n" << e3 << " evaluates to " << v3
|
||||
<< "\n" << e4 << " evaluates to " << v4;
|
||||
return AssertionFailure()
|
||||
<< pred_text << "(" << e1 << ", " << e2 << ", " << e3 << ", " << e4
|
||||
<< ") evaluates to false, where"
|
||||
<< "\n"
|
||||
<< e1 << " evaluates to " << ::testing::PrintToString(v1) << "\n"
|
||||
<< e2 << " evaluates to " << ::testing::PrintToString(v2) << "\n"
|
||||
<< e3 << " evaluates to " << ::testing::PrintToString(v3) << "\n"
|
||||
<< e4 << " evaluates to " << ::testing::PrintToString(v4);
|
||||
}
|
||||
|
||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT4.
|
||||
@ -307,17 +309,15 @@ AssertionResult AssertPred5Helper(const char* pred_text,
|
||||
const T5& v5) {
|
||||
if (pred(v1, v2, v3, v4, v5)) return AssertionSuccess();
|
||||
|
||||
return AssertionFailure() << pred_text << "("
|
||||
<< e1 << ", "
|
||||
<< e2 << ", "
|
||||
<< e3 << ", "
|
||||
<< e4 << ", "
|
||||
<< e5 << ") evaluates to false, where"
|
||||
<< "\n" << e1 << " evaluates to " << v1
|
||||
<< "\n" << e2 << " evaluates to " << v2
|
||||
<< "\n" << e3 << " evaluates to " << v3
|
||||
<< "\n" << e4 << " evaluates to " << v4
|
||||
<< "\n" << e5 << " evaluates to " << v5;
|
||||
return AssertionFailure()
|
||||
<< pred_text << "(" << e1 << ", " << e2 << ", " << e3 << ", " << e4
|
||||
<< ", " << e5 << ") evaluates to false, where"
|
||||
<< "\n"
|
||||
<< e1 << " evaluates to " << ::testing::PrintToString(v1) << "\n"
|
||||
<< e2 << " evaluates to " << ::testing::PrintToString(v2) << "\n"
|
||||
<< e3 << " evaluates to " << ::testing::PrintToString(v3) << "\n"
|
||||
<< e4 << " evaluates to " << ::testing::PrintToString(v4) << "\n"
|
||||
<< e5 << " evaluates to " << ::testing::PrintToString(v5);
|
||||
}
|
||||
|
||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT5.
|
||||
|
@ -91,7 +91,7 @@ class Message; // Represents a failure message.
|
||||
class Test; // Represents a test.
|
||||
class TestInfo; // Information about a test.
|
||||
class TestPartResult; // Result of a test part.
|
||||
class UnitTest; // A collection of test cases.
|
||||
class UnitTest; // A collection of test suites.
|
||||
|
||||
template <typename T>
|
||||
::std::string PrintToString(const T& value);
|
||||
@ -106,12 +106,22 @@ class UnitTestImpl; // Opaque implementation of UnitTest
|
||||
// stack trace.
|
||||
GTEST_API_ extern const char kStackTraceMarker[];
|
||||
|
||||
// An IgnoredValue object can be implicitly constructed from ANY value.
|
||||
class IgnoredValue {
|
||||
public:
|
||||
// This constructor template allows any value to be implicitly
|
||||
// converted to IgnoredValue. The object has no data member and
|
||||
// doesn't try to remember anything about the argument. We
|
||||
// deliberately omit the 'explicit' keyword in order to allow the
|
||||
// conversion to be implicit.
|
||||
template <typename T>
|
||||
IgnoredValue(const T& /* ignored */) {} // NOLINT(runtime/explicit)
|
||||
};
|
||||
|
||||
// Two overloaded helpers for checking at compile time whether an
|
||||
// expression is a null pointer literal (i.e. NULL or any 0-valued
|
||||
// compile-time integral constant). Their return values have
|
||||
// different sizes, so we can use sizeof() to test which version is
|
||||
// picked by the compiler. These helpers have no implementations, as
|
||||
// we only need their signatures.
|
||||
// compile-time integral constant). These helpers have no
|
||||
// implementations, as we only need their signatures.
|
||||
//
|
||||
// Given IsNullLiteralHelper(x), the compiler will pick the first
|
||||
// version if x can be implicitly converted to Secret*, and pick the
|
||||
@ -120,20 +130,13 @@ GTEST_API_ extern const char kStackTraceMarker[];
|
||||
// a null pointer literal. Therefore, we know that x is a null
|
||||
// pointer literal if and only if the first version is picked by the
|
||||
// compiler.
|
||||
char IsNullLiteralHelper(Secret* p);
|
||||
char (&IsNullLiteralHelper(...))[2]; // NOLINT
|
||||
std::true_type IsNullLiteralHelper(Secret*);
|
||||
std::false_type IsNullLiteralHelper(IgnoredValue);
|
||||
|
||||
// A compile-time bool constant that is true if and only if x is a
|
||||
// null pointer literal (i.e. NULL or any 0-valued compile-time
|
||||
// integral constant).
|
||||
#ifdef GTEST_ELLIPSIS_NEEDS_POD_
|
||||
// We lose support for NULL detection where the compiler doesn't like
|
||||
// passing non-POD classes through ellipsis (...).
|
||||
# define GTEST_IS_NULL_LITERAL_(x) false
|
||||
#else
|
||||
# define GTEST_IS_NULL_LITERAL_(x) \
|
||||
(sizeof(::testing::internal::IsNullLiteralHelper(x)) == 1)
|
||||
#endif // GTEST_ELLIPSIS_NEEDS_POD_
|
||||
// A compile-time bool constant that is true if and only if x is a null pointer
|
||||
// literal (i.e. nullptr, NULL or any 0-valued compile-time integral constant).
|
||||
#define GTEST_IS_NULL_LITERAL_(x) \
|
||||
decltype(::testing::internal::IsNullLiteralHelper(x))::value
|
||||
|
||||
// Appends the user-supplied message to the Google-Test-generated message.
|
||||
GTEST_API_ std::string AppendUserMessage(
|
||||
@ -409,7 +412,7 @@ typedef FloatingPoint<float> Float;
|
||||
typedef FloatingPoint<double> Double;
|
||||
|
||||
// In order to catch the mistake of putting tests that use different
|
||||
// test fixture classes in the same test case, we need to assign
|
||||
// test fixture classes in the same test suite, we need to assign
|
||||
// unique IDs to fixture classes and compare them. The TypeId type is
|
||||
// used to hold such IDs. The user should treat TypeId as an opaque
|
||||
// type: the only operation allowed on TypeId values is to compare
|
||||
@ -485,9 +488,9 @@ GTEST_API_ AssertionResult IsHRESULTFailure(const char* expr,
|
||||
|
||||
#endif // GTEST_OS_WINDOWS
|
||||
|
||||
// Types of SetUpTestCase() and TearDownTestCase() functions.
|
||||
typedef void (*SetUpTestCaseFunc)();
|
||||
typedef void (*TearDownTestCaseFunc)();
|
||||
// Types of SetUpTestSuite() and TearDownTestSuite() functions.
|
||||
using SetUpTestSuiteFunc = void (*)();
|
||||
using TearDownTestSuiteFunc = void (*)();
|
||||
|
||||
struct CodeLocation {
|
||||
CodeLocation(const std::string& a_file, int a_line)
|
||||
@ -497,12 +500,60 @@ struct CodeLocation {
|
||||
int line;
|
||||
};
|
||||
|
||||
// Helper to identify which setup function for TestCase / TestSuite to call.
|
||||
// Only one function is allowed, either TestCase or TestSute but not both.
|
||||
|
||||
// Utility functions to help SuiteApiResolver
|
||||
using SetUpTearDownSuiteFuncType = void (*)();
|
||||
|
||||
inline SetUpTearDownSuiteFuncType GetNotDefaultOrNull(
|
||||
SetUpTearDownSuiteFuncType a, SetUpTearDownSuiteFuncType def) {
|
||||
return a == def ? nullptr : a;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
// Note that SuiteApiResolver inherits from T because
|
||||
// SetUpTestSuite()/TearDownTestSuite() could be protected. Ths way
|
||||
// SuiteApiResolver can access them.
|
||||
struct SuiteApiResolver : T {
|
||||
// testing::Test is only forward declared at this point. So we make it a
|
||||
// dependend class for the compiler to be OK with it.
|
||||
using Test =
|
||||
typename std::conditional<sizeof(T) != 0, ::testing::Test, void>::type;
|
||||
|
||||
static SetUpTearDownSuiteFuncType GetSetUpCaseOrSuite() {
|
||||
SetUpTearDownSuiteFuncType test_case_fp =
|
||||
GetNotDefaultOrNull(&T::SetUpTestCase, &Test::SetUpTestCase);
|
||||
SetUpTearDownSuiteFuncType test_suite_fp =
|
||||
GetNotDefaultOrNull(&T::SetUpTestSuite, &Test::SetUpTestSuite);
|
||||
|
||||
GTEST_CHECK_(!test_case_fp || !test_suite_fp)
|
||||
<< "Test can not provide both SetUpTestSuite and SetUpTestCase, please "
|
||||
"make sure there is only one present ";
|
||||
|
||||
return test_case_fp != nullptr ? test_case_fp : test_suite_fp;
|
||||
}
|
||||
|
||||
static SetUpTearDownSuiteFuncType GetTearDownCaseOrSuite() {
|
||||
SetUpTearDownSuiteFuncType test_case_fp =
|
||||
GetNotDefaultOrNull(&T::TearDownTestCase, &Test::TearDownTestCase);
|
||||
SetUpTearDownSuiteFuncType test_suite_fp =
|
||||
GetNotDefaultOrNull(&T::TearDownTestSuite, &Test::TearDownTestSuite);
|
||||
|
||||
GTEST_CHECK_(!test_case_fp || !test_suite_fp)
|
||||
<< "Test can not provide both TearDownTestSuite and TearDownTestCase,"
|
||||
" please make sure there is only one present ";
|
||||
|
||||
return test_case_fp != nullptr ? test_case_fp : test_suite_fp;
|
||||
}
|
||||
};
|
||||
|
||||
// Creates a new TestInfo object and registers it with Google Test;
|
||||
// returns the created object.
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// test_case_name: name of the test case
|
||||
// test_suite_name: name of the test suite
|
||||
// name: name of the test
|
||||
// type_param the name of the test's type parameter, or NULL if
|
||||
// this is not a typed or a type-parameterized test.
|
||||
@ -510,21 +561,16 @@ struct CodeLocation {
|
||||
// or NULL if this is not a type-parameterized test.
|
||||
// code_location: code location where the test is defined
|
||||
// fixture_class_id: ID of the test fixture class
|
||||
// set_up_tc: pointer to the function that sets up the test case
|
||||
// tear_down_tc: pointer to the function that tears down the test case
|
||||
// set_up_tc: pointer to the function that sets up the test suite
|
||||
// tear_down_tc: pointer to the function that tears down the test suite
|
||||
// factory: pointer to the factory that creates a test object.
|
||||
// The newly created TestInfo instance will assume
|
||||
// ownership of the factory object.
|
||||
GTEST_API_ TestInfo* MakeAndRegisterTestInfo(
|
||||
const char* test_case_name,
|
||||
const char* name,
|
||||
const char* type_param,
|
||||
const char* value_param,
|
||||
CodeLocation code_location,
|
||||
TypeId fixture_class_id,
|
||||
SetUpTestCaseFunc set_up_tc,
|
||||
TearDownTestCaseFunc tear_down_tc,
|
||||
TestFactoryBase* factory);
|
||||
const char* test_suite_name, const char* name, const char* type_param,
|
||||
const char* value_param, CodeLocation code_location,
|
||||
TypeId fixture_class_id, SetUpTestSuiteFunc set_up_tc,
|
||||
TearDownTestSuiteFunc tear_down_tc, TestFactoryBase* factory);
|
||||
|
||||
// If *pstr starts with the given prefix, modifies *pstr to be right
|
||||
// past the prefix and returns true; otherwise leaves *pstr unchanged
|
||||
@ -536,19 +582,20 @@ GTEST_API_ bool SkipPrefix(const char* prefix, const char** pstr);
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
||||
/* class A needs to have dll-interface to be used by clients of class B */)
|
||||
|
||||
// State of the definition of a type-parameterized test case.
|
||||
class GTEST_API_ TypedTestCasePState {
|
||||
// State of the definition of a type-parameterized test suite.
|
||||
class GTEST_API_ TypedTestSuitePState {
|
||||
public:
|
||||
TypedTestCasePState() : registered_(false) {}
|
||||
TypedTestSuitePState() : registered_(false) {}
|
||||
|
||||
// Adds the given test name to defined_test_names_ and return true
|
||||
// if the test case hasn't been registered; otherwise aborts the
|
||||
// if the test suite hasn't been registered; otherwise aborts the
|
||||
// program.
|
||||
bool AddTestName(const char* file, int line, const char* case_name,
|
||||
const char* test_name) {
|
||||
if (registered_) {
|
||||
fprintf(stderr, "%s Test %s must be defined before "
|
||||
"REGISTER_TYPED_TEST_CASE_P(%s, ...).\n",
|
||||
fprintf(stderr,
|
||||
"%s Test %s must be defined before "
|
||||
"REGISTER_TYPED_TEST_SUITE_P(%s, ...).\n",
|
||||
FormatFileLocation(file, line).c_str(), test_name, case_name);
|
||||
fflush(stderr);
|
||||
posix::Abort();
|
||||
@ -581,6 +628,11 @@ class GTEST_API_ TypedTestCasePState {
|
||||
RegisteredTestsMap registered_tests_;
|
||||
};
|
||||
|
||||
// Legacy API is deprecated but still available
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
using TypedTestCasePState = TypedTestSuitePState;
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
||||
|
||||
// Skips to the first non-space char after the first comma in 'str';
|
||||
@ -648,7 +700,7 @@ template <GTEST_TEMPLATE_ Fixture, class TestSel, typename Types>
|
||||
class TypeParameterizedTest {
|
||||
public:
|
||||
// 'index' is the index of the test in the type list 'Types'
|
||||
// specified in INSTANTIATE_TYPED_TEST_CASE_P(Prefix, TestCase,
|
||||
// specified in INSTANTIATE_TYPED_TEST_SUITE_P(Prefix, TestSuite,
|
||||
// Types). Valid values for 'index' are [0, N - 1] where N is the
|
||||
// length of Types.
|
||||
static bool Register(const char* prefix, const CodeLocation& code_location,
|
||||
@ -668,8 +720,10 @@ class TypeParameterizedTest {
|
||||
StripTrailingSpaces(GetPrefixUntilComma(test_names)).c_str(),
|
||||
GetTypeName<Type>().c_str(),
|
||||
nullptr, // No value parameter.
|
||||
code_location, GetTypeId<FixtureClass>(), TestClass::SetUpTestCase,
|
||||
TestClass::TearDownTestCase, new TestFactoryImpl<TestClass>);
|
||||
code_location, GetTypeId<FixtureClass>(),
|
||||
SuiteApiResolver<TestClass>::GetSetUpCaseOrSuite(),
|
||||
SuiteApiResolver<TestClass>::GetTearDownCaseOrSuite(),
|
||||
new TestFactoryImpl<TestClass>);
|
||||
|
||||
// Next, recurses (at compile time) with the tail of the type list.
|
||||
return TypeParameterizedTest<Fixture, TestSel,
|
||||
@ -695,15 +749,15 @@ class TypeParameterizedTest<Fixture, TestSel, Types0> {
|
||||
}
|
||||
};
|
||||
|
||||
// TypeParameterizedTestCase<Fixture, Tests, Types>::Register()
|
||||
// TypeParameterizedTestSuite<Fixture, Tests, Types>::Register()
|
||||
// registers *all combinations* of 'Tests' and 'Types' with Google
|
||||
// Test. The return value is insignificant - we just need to return
|
||||
// something such that we can call this function in a namespace scope.
|
||||
template <GTEST_TEMPLATE_ Fixture, typename Tests, typename Types>
|
||||
class TypeParameterizedTestCase {
|
||||
class TypeParameterizedTestSuite {
|
||||
public:
|
||||
static bool Register(const char* prefix, CodeLocation code_location,
|
||||
const TypedTestCasePState* state, const char* case_name,
|
||||
const TypedTestSuitePState* state, const char* case_name,
|
||||
const char* test_names,
|
||||
const std::vector<std::string>& type_names =
|
||||
GenerateNames<DefaultNameGenerator, Types>()) {
|
||||
@ -726,7 +780,7 @@ class TypeParameterizedTestCase {
|
||||
prefix, test_location, case_name, test_names, 0, type_names);
|
||||
|
||||
// Next, recurses (at compile time) with the tail of the test list.
|
||||
return TypeParameterizedTestCase<Fixture, typename Tests::Tail,
|
||||
return TypeParameterizedTestSuite<Fixture, typename Tests::Tail,
|
||||
Types>::Register(prefix, code_location,
|
||||
state, case_name,
|
||||
SkipComma(test_names),
|
||||
@ -736,10 +790,10 @@ class TypeParameterizedTestCase {
|
||||
|
||||
// The base case for the compile time recursion.
|
||||
template <GTEST_TEMPLATE_ Fixture, typename Types>
|
||||
class TypeParameterizedTestCase<Fixture, Templates0, Types> {
|
||||
class TypeParameterizedTestSuite<Fixture, Templates0, Types> {
|
||||
public:
|
||||
static bool Register(const char* /*prefix*/, const CodeLocation&,
|
||||
const TypedTestCasePState* /*state*/,
|
||||
const TypedTestSuitePState* /*state*/,
|
||||
const char* /*case_name*/, const char* /*test_names*/,
|
||||
const std::vector<std::string>& =
|
||||
std::vector<std::string>() /*type_names*/) {
|
||||
@ -967,37 +1021,24 @@ struct IsHashTable {
|
||||
template <typename T>
|
||||
const bool IsHashTable<T>::value;
|
||||
|
||||
template<typename T>
|
||||
struct VoidT {
|
||||
typedef void value_type;
|
||||
};
|
||||
|
||||
template <typename T, typename = void>
|
||||
struct HasValueType : false_type {};
|
||||
template <typename T>
|
||||
struct HasValueType<T, VoidT<typename T::value_type> > : true_type {
|
||||
};
|
||||
|
||||
template <typename C,
|
||||
bool = sizeof(IsContainerTest<C>(0)) == sizeof(IsContainer),
|
||||
bool = HasValueType<C>::value>
|
||||
bool = sizeof(IsContainerTest<C>(0)) == sizeof(IsContainer)>
|
||||
struct IsRecursiveContainerImpl;
|
||||
|
||||
template <typename C, bool HV>
|
||||
struct IsRecursiveContainerImpl<C, false, HV> : public false_type {};
|
||||
template <typename C>
|
||||
struct IsRecursiveContainerImpl<C, false> : public false_type {};
|
||||
|
||||
// Since the IsRecursiveContainerImpl depends on the IsContainerTest we need to
|
||||
// obey the same inconsistencies as the IsContainerTest, namely check if
|
||||
// something is a container is relying on only const_iterator in C++11 and
|
||||
// is relying on both const_iterator and iterator otherwise
|
||||
template <typename C>
|
||||
struct IsRecursiveContainerImpl<C, true, false> : public false_type {};
|
||||
|
||||
template <typename C>
|
||||
struct IsRecursiveContainerImpl<C, true, true> {
|
||||
typedef typename IteratorTraits<typename C::const_iterator>::value_type
|
||||
value_type;
|
||||
typedef is_same<value_type, C> type;
|
||||
struct IsRecursiveContainerImpl<C, true> {
|
||||
using value_type = decltype(*std::declval<typename C::const_iterator>());
|
||||
using type =
|
||||
is_same<typename std::remove_const<
|
||||
typename std::remove_reference<value_type>::type>::type,
|
||||
C>;
|
||||
};
|
||||
|
||||
// IsRecursiveContainer<Type> is a unary compile-time predicate that
|
||||
@ -1386,32 +1427,35 @@ class FlatTuple
|
||||
" Actual: it does.")
|
||||
|
||||
// Expands to the name of the class that implements the given test.
|
||||
#define GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
|
||||
test_case_name##_##test_name##_Test
|
||||
#define GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \
|
||||
test_suite_name##_##test_name##_Test
|
||||
|
||||
// Helper macro for defining tests.
|
||||
#define GTEST_TEST_(test_case_name, test_name, parent_class, parent_id) \
|
||||
class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
|
||||
#define GTEST_TEST_(test_suite_name, test_name, parent_class, parent_id) \
|
||||
class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \
|
||||
: public parent_class { \
|
||||
public: \
|
||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {} \
|
||||
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() {} \
|
||||
\
|
||||
private: \
|
||||
virtual void TestBody(); \
|
||||
static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_; \
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(GTEST_TEST_CLASS_NAME_(test_case_name, \
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(GTEST_TEST_CLASS_NAME_(test_suite_name, \
|
||||
test_name)); \
|
||||
}; \
|
||||
\
|
||||
::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, \
|
||||
::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_suite_name, \
|
||||
test_name)::test_info_ = \
|
||||
::testing::internal::MakeAndRegisterTestInfo( \
|
||||
#test_case_name, #test_name, nullptr, nullptr, \
|
||||
#test_suite_name, #test_name, nullptr, nullptr, \
|
||||
::testing::internal::CodeLocation(__FILE__, __LINE__), (parent_id), \
|
||||
parent_class::SetUpTestCase, parent_class::TearDownTestCase, \
|
||||
::testing::internal::SuiteApiResolver< \
|
||||
parent_class>::GetSetUpCaseOrSuite(), \
|
||||
::testing::internal::SuiteApiResolver< \
|
||||
parent_class>::GetTearDownCaseOrSuite(), \
|
||||
new ::testing::internal::TestFactoryImpl<GTEST_TEST_CLASS_NAME_( \
|
||||
test_case_name, test_name)>); \
|
||||
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
|
||||
test_suite_name, test_name)>); \
|
||||
void GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::TestBody()
|
||||
|
||||
// Internal Macro to mark an API deprecated, for googletest usage only
|
||||
// Usage: class GTEST_INTERNAL_DEPRECATED(message) MyClass or
|
||||
|
@ -75,10 +75,10 @@ namespace internal {
|
||||
// Utility Functions
|
||||
|
||||
// Outputs a message explaining invalid registration of different
|
||||
// fixture class for the same test case. This may happen when
|
||||
// fixture class for the same test suite. This may happen when
|
||||
// TEST_P macro is used to define two tests with the same name
|
||||
// but in different namespaces.
|
||||
GTEST_API_ void ReportInvalidTestCaseType(const char* test_case_name,
|
||||
GTEST_API_ void ReportInvalidTestSuiteType(const char* test_suite_name,
|
||||
CodeLocation code_location);
|
||||
|
||||
template <typename> class ParamGeneratorInterface;
|
||||
@ -379,7 +379,7 @@ std::string DefaultParamName(const TestParamInfo<ParamType>& info) {
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||
//
|
||||
// Parameterized test name overload helpers, which help the
|
||||
// INSTANTIATE_TEST_CASE_P macro choose between the default parameterized
|
||||
// INSTANTIATE_TEST_SUITE_P macro choose between the default parameterized
|
||||
// test name generator and user param name generator.
|
||||
template <class ParamType, class ParamNameGenFunctor>
|
||||
ParamNameGenFunctor GetParamNameGen(ParamNameGenFunctor func) {
|
||||
@ -434,19 +434,19 @@ class TestMetaFactoryBase {
|
||||
// TestMetaFactory creates test factories for passing into
|
||||
// MakeAndRegisterTestInfo function. Since MakeAndRegisterTestInfo receives
|
||||
// ownership of test factory pointer, same factory object cannot be passed
|
||||
// into that method twice. But ParameterizedTestCaseInfo is going to call
|
||||
// into that method twice. But ParameterizedTestSuiteInfo is going to call
|
||||
// it for each Test/Parameter value combination. Thus it needs meta factory
|
||||
// creator class.
|
||||
template <class TestCase>
|
||||
template <class TestSuite>
|
||||
class TestMetaFactory
|
||||
: public TestMetaFactoryBase<typename TestCase::ParamType> {
|
||||
: public TestMetaFactoryBase<typename TestSuite::ParamType> {
|
||||
public:
|
||||
typedef typename TestCase::ParamType ParamType;
|
||||
using ParamType = typename TestSuite::ParamType;
|
||||
|
||||
TestMetaFactory() {}
|
||||
|
||||
TestFactoryBase* CreateTestFactory(ParamType parameter) override {
|
||||
return new ParameterizedTestFactory<TestCase>(parameter);
|
||||
return new ParameterizedTestFactory<TestSuite>(parameter);
|
||||
}
|
||||
|
||||
private:
|
||||
@ -455,78 +455,77 @@ class TestMetaFactory
|
||||
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||
//
|
||||
// ParameterizedTestCaseInfoBase is a generic interface
|
||||
// to ParameterizedTestCaseInfo classes. ParameterizedTestCaseInfoBase
|
||||
// ParameterizedTestSuiteInfoBase is a generic interface
|
||||
// to ParameterizedTestSuiteInfo classes. ParameterizedTestSuiteInfoBase
|
||||
// accumulates test information provided by TEST_P macro invocations
|
||||
// and generators provided by INSTANTIATE_TEST_CASE_P macro invocations
|
||||
// and generators provided by INSTANTIATE_TEST_SUITE_P macro invocations
|
||||
// and uses that information to register all resulting test instances
|
||||
// in RegisterTests method. The ParameterizeTestCaseRegistry class holds
|
||||
// a collection of pointers to the ParameterizedTestCaseInfo objects
|
||||
// in RegisterTests method. The ParameterizeTestSuiteRegistry class holds
|
||||
// a collection of pointers to the ParameterizedTestSuiteInfo objects
|
||||
// and calls RegisterTests() on each of them when asked.
|
||||
class ParameterizedTestCaseInfoBase {
|
||||
class ParameterizedTestSuiteInfoBase {
|
||||
public:
|
||||
virtual ~ParameterizedTestCaseInfoBase() {}
|
||||
virtual ~ParameterizedTestSuiteInfoBase() {}
|
||||
|
||||
// Base part of test case name for display purposes.
|
||||
virtual const std::string& GetTestCaseName() const = 0;
|
||||
// Base part of test suite name for display purposes.
|
||||
virtual const std::string& GetTestSuiteName() const = 0;
|
||||
// Test case id to verify identity.
|
||||
virtual TypeId GetTestCaseTypeId() const = 0;
|
||||
virtual TypeId GetTestSuiteTypeId() const = 0;
|
||||
// UnitTest class invokes this method to register tests in this
|
||||
// test case right before running them in RUN_ALL_TESTS macro.
|
||||
// test suite right before running them in RUN_ALL_TESTS macro.
|
||||
// This method should not be called more then once on any single
|
||||
// instance of a ParameterizedTestCaseInfoBase derived class.
|
||||
// instance of a ParameterizedTestSuiteInfoBase derived class.
|
||||
virtual void RegisterTests() = 0;
|
||||
|
||||
protected:
|
||||
ParameterizedTestCaseInfoBase() {}
|
||||
ParameterizedTestSuiteInfoBase() {}
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestCaseInfoBase);
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestSuiteInfoBase);
|
||||
};
|
||||
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||
//
|
||||
// ParameterizedTestCaseInfo accumulates tests obtained from TEST_P
|
||||
// macro invocations for a particular test case and generators
|
||||
// obtained from INSTANTIATE_TEST_CASE_P macro invocations for that
|
||||
// test case. It registers tests with all values generated by all
|
||||
// ParameterizedTestSuiteInfo accumulates tests obtained from TEST_P
|
||||
// macro invocations for a particular test suite and generators
|
||||
// obtained from INSTANTIATE_TEST_SUITE_P macro invocations for that
|
||||
// test suite. It registers tests with all values generated by all
|
||||
// generators when asked.
|
||||
template <class TestCase>
|
||||
class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
|
||||
template <class TestSuite>
|
||||
class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase {
|
||||
public:
|
||||
// ParamType and GeneratorCreationFunc are private types but are required
|
||||
// for declarations of public methods AddTestPattern() and
|
||||
// AddTestCaseInstantiation().
|
||||
typedef typename TestCase::ParamType ParamType;
|
||||
// AddTestSuiteInstantiation().
|
||||
using ParamType = typename TestSuite::ParamType;
|
||||
// A function that returns an instance of appropriate generator type.
|
||||
typedef ParamGenerator<ParamType>(GeneratorCreationFunc)();
|
||||
typedef typename ParamNameGenFunc<ParamType>::Type ParamNameGeneratorFunc;
|
||||
|
||||
explicit ParameterizedTestCaseInfo(
|
||||
const char* name, CodeLocation code_location)
|
||||
: test_case_name_(name), code_location_(code_location) {}
|
||||
explicit ParameterizedTestSuiteInfo(const char* name,
|
||||
CodeLocation code_location)
|
||||
: test_suite_name_(name), code_location_(code_location) {}
|
||||
|
||||
// Test case base name for display purposes.
|
||||
const std::string& GetTestCaseName() const override {
|
||||
return test_case_name_;
|
||||
const std::string& GetTestSuiteName() const override {
|
||||
return test_suite_name_;
|
||||
}
|
||||
// Test case id to verify identity.
|
||||
TypeId GetTestCaseTypeId() const override { return GetTypeId<TestCase>(); }
|
||||
TypeId GetTestSuiteTypeId() const override { return GetTypeId<TestSuite>(); }
|
||||
// TEST_P macro uses AddTestPattern() to record information
|
||||
// about a single test in a LocalTestInfo structure.
|
||||
// test_case_name is the base name of the test case (without invocation
|
||||
// test_suite_name is the base name of the test suite (without invocation
|
||||
// prefix). test_base_name is the name of an individual test without
|
||||
// parameter index. For the test SequenceA/FooTest.DoBar/1 FooTest is
|
||||
// test case base name and DoBar is test base name.
|
||||
void AddTestPattern(const char* test_case_name,
|
||||
const char* test_base_name,
|
||||
// test suite base name and DoBar is test base name.
|
||||
void AddTestPattern(const char* test_suite_name, const char* test_base_name,
|
||||
TestMetaFactoryBase<ParamType>* meta_factory) {
|
||||
tests_.push_back(std::shared_ptr<TestInfo>(
|
||||
new TestInfo(test_case_name, test_base_name, meta_factory)));
|
||||
new TestInfo(test_suite_name, test_base_name, meta_factory)));
|
||||
}
|
||||
// INSTANTIATE_TEST_CASE_P macro uses AddGenerator() to record information
|
||||
// INSTANTIATE_TEST_SUITE_P macro uses AddGenerator() to record information
|
||||
// about a generator.
|
||||
int AddTestCaseInstantiation(const std::string& instantiation_name,
|
||||
int AddTestSuiteInstantiation(const std::string& instantiation_name,
|
||||
GeneratorCreationFunc* func,
|
||||
ParamNameGeneratorFunc* name_func,
|
||||
const char* file, int line) {
|
||||
@ -534,10 +533,10 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
|
||||
InstantiationInfo(instantiation_name, func, name_func, file, line));
|
||||
return 0; // Return value used only to run this method in namespace scope.
|
||||
}
|
||||
// UnitTest class invokes this method to register tests in this test case
|
||||
// test cases right before running tests in RUN_ALL_TESTS macro.
|
||||
// UnitTest class invokes this method to register tests in this test suite
|
||||
// test suites right before running tests in RUN_ALL_TESTS macro.
|
||||
// This method should not be called more then once on any single
|
||||
// instance of a ParameterizedTestCaseInfoBase derived class.
|
||||
// instance of a ParameterizedTestSuiteInfoBase derived class.
|
||||
// UnitTest has a guard to prevent from calling this method more then once.
|
||||
void RegisterTests() override {
|
||||
for (typename TestInfoContainer::iterator test_it = tests_.begin();
|
||||
@ -552,10 +551,10 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
|
||||
const char* file = gen_it->file;
|
||||
int line = gen_it->line;
|
||||
|
||||
std::string test_case_name;
|
||||
std::string test_suite_name;
|
||||
if ( !instantiation_name.empty() )
|
||||
test_case_name = instantiation_name + "/";
|
||||
test_case_name += test_info->test_case_base_name;
|
||||
test_suite_name = instantiation_name + "/";
|
||||
test_suite_name += test_info->test_suite_base_name;
|
||||
|
||||
size_t i = 0;
|
||||
std::set<std::string> test_param_names;
|
||||
@ -580,11 +579,12 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
|
||||
|
||||
test_name_stream << test_info->test_base_name << "/" << param_name;
|
||||
MakeAndRegisterTestInfo(
|
||||
test_case_name.c_str(), test_name_stream.GetString().c_str(),
|
||||
test_suite_name.c_str(), test_name_stream.GetString().c_str(),
|
||||
nullptr, // No type parameter.
|
||||
PrintToString(*param_it).c_str(), code_location_,
|
||||
GetTestCaseTypeId(), TestCase::SetUpTestCase,
|
||||
TestCase::TearDownTestCase,
|
||||
GetTestSuiteTypeId(),
|
||||
SuiteApiResolver<TestSuite>::GetSetUpCaseOrSuite(),
|
||||
SuiteApiResolver<TestSuite>::GetTearDownCaseOrSuite(),
|
||||
test_info->test_meta_factory->CreateTestFactory(*param_it));
|
||||
} // for param_it
|
||||
} // for gen_it
|
||||
@ -595,19 +595,18 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
|
||||
// LocalTestInfo structure keeps information about a single test registered
|
||||
// with TEST_P macro.
|
||||
struct TestInfo {
|
||||
TestInfo(const char* a_test_case_base_name,
|
||||
const char* a_test_base_name,
|
||||
TestMetaFactoryBase<ParamType>* a_test_meta_factory) :
|
||||
test_case_base_name(a_test_case_base_name),
|
||||
TestInfo(const char* a_test_suite_base_name, const char* a_test_base_name,
|
||||
TestMetaFactoryBase<ParamType>* a_test_meta_factory)
|
||||
: test_suite_base_name(a_test_suite_base_name),
|
||||
test_base_name(a_test_base_name),
|
||||
test_meta_factory(a_test_meta_factory) {}
|
||||
|
||||
const std::string test_case_base_name;
|
||||
const std::string test_suite_base_name;
|
||||
const std::string test_base_name;
|
||||
const std::unique_ptr<TestMetaFactoryBase<ParamType> > test_meta_factory;
|
||||
};
|
||||
using TestInfoContainer = ::std::vector<std::shared_ptr<TestInfo> >;
|
||||
// Records data received from INSTANTIATE_TEST_CASE_P macros:
|
||||
// Records data received from INSTANTIATE_TEST_SUITE_P macros:
|
||||
// <Instantiation name, Sequence generator creation function,
|
||||
// Name generator function, Source file, Source line>
|
||||
struct InstantiationInfo {
|
||||
@ -644,76 +643,87 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
|
||||
return true;
|
||||
}
|
||||
|
||||
const std::string test_case_name_;
|
||||
const std::string test_suite_name_;
|
||||
CodeLocation code_location_;
|
||||
TestInfoContainer tests_;
|
||||
InstantiationContainer instantiations_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestCaseInfo);
|
||||
}; // class ParameterizedTestCaseInfo
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestSuiteInfo);
|
||||
}; // class ParameterizedTestSuiteInfo
|
||||
|
||||
// Legacy API is deprecated but still available
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
template <class TestCase>
|
||||
using ParameterizedTestCaseInfo = ParameterizedTestSuiteInfo<TestCase>;
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||
//
|
||||
// ParameterizedTestCaseRegistry contains a map of ParameterizedTestCaseInfoBase
|
||||
// classes accessed by test case names. TEST_P and INSTANTIATE_TEST_CASE_P
|
||||
// macros use it to locate their corresponding ParameterizedTestCaseInfo
|
||||
// descriptors.
|
||||
class ParameterizedTestCaseRegistry {
|
||||
// ParameterizedTestSuiteRegistry contains a map of
|
||||
// ParameterizedTestSuiteInfoBase classes accessed by test suite names. TEST_P
|
||||
// and INSTANTIATE_TEST_SUITE_P macros use it to locate their corresponding
|
||||
// ParameterizedTestSuiteInfo descriptors.
|
||||
class ParameterizedTestSuiteRegistry {
|
||||
public:
|
||||
ParameterizedTestCaseRegistry() {}
|
||||
~ParameterizedTestCaseRegistry() {
|
||||
for (TestCaseInfoContainer::iterator it = test_case_infos_.begin();
|
||||
it != test_case_infos_.end(); ++it) {
|
||||
delete *it;
|
||||
ParameterizedTestSuiteRegistry() {}
|
||||
~ParameterizedTestSuiteRegistry() {
|
||||
for (auto& test_suite_info : test_suite_infos_) {
|
||||
delete test_suite_info;
|
||||
}
|
||||
}
|
||||
|
||||
// Looks up or creates and returns a structure containing information about
|
||||
// tests and instantiations of a particular test case.
|
||||
template <class TestCase>
|
||||
ParameterizedTestCaseInfo<TestCase>* GetTestCasePatternHolder(
|
||||
const char* test_case_name,
|
||||
CodeLocation code_location) {
|
||||
ParameterizedTestCaseInfo<TestCase>* typed_test_info = nullptr;
|
||||
for (TestCaseInfoContainer::iterator it = test_case_infos_.begin();
|
||||
it != test_case_infos_.end(); ++it) {
|
||||
if ((*it)->GetTestCaseName() == test_case_name) {
|
||||
if ((*it)->GetTestCaseTypeId() != GetTypeId<TestCase>()) {
|
||||
// tests and instantiations of a particular test suite.
|
||||
template <class TestSuite>
|
||||
ParameterizedTestSuiteInfo<TestSuite>* GetTestSuitePatternHolder(
|
||||
const char* test_suite_name, CodeLocation code_location) {
|
||||
ParameterizedTestSuiteInfo<TestSuite>* typed_test_info = nullptr;
|
||||
for (auto& test_suite_info : test_suite_infos_) {
|
||||
if (test_suite_info->GetTestSuiteName() == test_suite_name) {
|
||||
if (test_suite_info->GetTestSuiteTypeId() != GetTypeId<TestSuite>()) {
|
||||
// Complain about incorrect usage of Google Test facilities
|
||||
// and terminate the program since we cannot guaranty correct
|
||||
// test case setup and tear-down in this case.
|
||||
ReportInvalidTestCaseType(test_case_name, code_location);
|
||||
// test suite setup and tear-down in this case.
|
||||
ReportInvalidTestSuiteType(test_suite_name, code_location);
|
||||
posix::Abort();
|
||||
} else {
|
||||
// At this point we are sure that the object we found is of the same
|
||||
// type we are looking for, so we downcast it to that type
|
||||
// without further checks.
|
||||
typed_test_info = CheckedDowncastToActualType<
|
||||
ParameterizedTestCaseInfo<TestCase> >(*it);
|
||||
ParameterizedTestSuiteInfo<TestSuite> >(test_suite_info);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (typed_test_info == nullptr) {
|
||||
typed_test_info = new ParameterizedTestCaseInfo<TestCase>(
|
||||
test_case_name, code_location);
|
||||
test_case_infos_.push_back(typed_test_info);
|
||||
typed_test_info = new ParameterizedTestSuiteInfo<TestSuite>(
|
||||
test_suite_name, code_location);
|
||||
test_suite_infos_.push_back(typed_test_info);
|
||||
}
|
||||
return typed_test_info;
|
||||
}
|
||||
void RegisterTests() {
|
||||
for (TestCaseInfoContainer::iterator it = test_case_infos_.begin();
|
||||
it != test_case_infos_.end(); ++it) {
|
||||
(*it)->RegisterTests();
|
||||
for (auto& test_suite_info : test_suite_infos_) {
|
||||
test_suite_info->RegisterTests();
|
||||
}
|
||||
}
|
||||
// Legacy API is deprecated but still available
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
template <class TestCase>
|
||||
ParameterizedTestCaseInfo<TestCase>* GetTestCasePatternHolder(
|
||||
const char* test_case_name, CodeLocation code_location) {
|
||||
return GetTestSuitePatternHolder<TestCase>(test_case_name, code_location);
|
||||
}
|
||||
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
private:
|
||||
typedef ::std::vector<ParameterizedTestCaseInfoBase*> TestCaseInfoContainer;
|
||||
using TestSuiteInfoContainer = ::std::vector<ParameterizedTestSuiteInfoBase*>;
|
||||
|
||||
TestCaseInfoContainer test_case_infos_;
|
||||
TestSuiteInfoContainer test_suite_infos_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestCaseRegistry);
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestSuiteRegistry);
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
@ -41,8 +41,6 @@
|
||||
# elif defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__)
|
||||
# define GTEST_OS_WINDOWS_MINGW 1
|
||||
# define GTEST_OS_WINDOWS 1
|
||||
#elif defined __SYMBIAN32__
|
||||
# define GTEST_OS_SYMBIAN 1
|
||||
#elif defined _WIN32
|
||||
# define GTEST_OS_WINDOWS 1
|
||||
# ifdef _WIN32_WCE
|
||||
|
@ -92,8 +92,6 @@
|
||||
// - Define it to 1/0 to indicate whether the
|
||||
// platform supports I/O stream redirection using
|
||||
// dup() and dup2().
|
||||
// GTEST_LANG_CXX11 - Define it to 1/0 to indicate that Google Test
|
||||
// is building in C++11/C++98 mode.
|
||||
// GTEST_LINKED_AS_SHARED_LIBRARY
|
||||
// - Define to 1 when compiling tests that use
|
||||
// Google Test as a shared library (known as
|
||||
@ -132,7 +130,6 @@
|
||||
// GTEST_OS_OS2 - OS/2
|
||||
// GTEST_OS_QNX - QNX
|
||||
// GTEST_OS_SOLARIS - Sun Solaris
|
||||
// GTEST_OS_SYMBIAN - Symbian
|
||||
// GTEST_OS_WINDOWS - Windows (Desktop, MinGW, or Mobile)
|
||||
// GTEST_OS_WINDOWS_DESKTOP - Windows Desktop
|
||||
// GTEST_OS_WINDOWS_MINGW - MinGW
|
||||
@ -177,7 +174,6 @@
|
||||
// define themselves.
|
||||
// GTEST_USES_SIMPLE_RE - our own simple regex is used;
|
||||
// the above RE\b(s) are mutually exclusive.
|
||||
// GTEST_CAN_COMPARE_NULL - accepts untyped NULL in EXPECT_EQ().
|
||||
|
||||
// Misc public macros
|
||||
// ------------------
|
||||
@ -208,7 +204,6 @@
|
||||
// - synchronization primitives.
|
||||
//
|
||||
// Template meta programming:
|
||||
// is_pointer - as in TR1; needed on Symbian and IBM XL C/C++ only.
|
||||
// IteratorTraits - partial implementation of std::iterator_traits, which
|
||||
// is not available in libCstd when compiled with Sun C++.
|
||||
//
|
||||
@ -255,6 +250,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
#ifndef _WIN32_WCE
|
||||
# include <sys/types.h>
|
||||
@ -332,44 +328,6 @@
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_()
|
||||
#endif
|
||||
|
||||
#define GTEST_LANG_CXX11 1
|
||||
|
||||
// Distinct from C++11 language support, some environments don't provide
|
||||
// proper C++11 library support. Notably, it's possible to build in
|
||||
// C++11 mode when targeting Mac OS X 10.6, which has an old libstdc++
|
||||
// with no C++11 support.
|
||||
//
|
||||
// libstdc++ has sufficient C++11 support as of GCC 4.6.0, __GLIBCXX__
|
||||
// 20110325, but maintenance releases in the 4.4 and 4.5 series followed
|
||||
// this date, so check for those versions by their date stamps.
|
||||
// https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html#abi.versioning
|
||||
#if GTEST_LANG_CXX11 && \
|
||||
(!defined(__GLIBCXX__) || ( \
|
||||
__GLIBCXX__ >= 20110325ul && /* GCC >= 4.6.0 */ \
|
||||
/* Blacklist of patch releases of older branches: */ \
|
||||
__GLIBCXX__ != 20110416ul && /* GCC 4.4.6 */ \
|
||||
__GLIBCXX__ != 20120313ul && /* GCC 4.4.7 */ \
|
||||
__GLIBCXX__ != 20110428ul && /* GCC 4.5.3 */ \
|
||||
__GLIBCXX__ != 20120702ul)) /* GCC 4.5.4 */
|
||||
# define GTEST_STDLIB_CXX11 1
|
||||
#endif
|
||||
|
||||
// Only use C++11 library features if the library provides them.
|
||||
#if GTEST_STDLIB_CXX11
|
||||
# define GTEST_HAS_STD_BEGIN_AND_END_ 1
|
||||
# define GTEST_HAS_STD_FORWARD_LIST_ 1
|
||||
# if !defined(_MSC_VER) || (_MSC_FULL_VER >= 190023824)
|
||||
// works only with VS2015U2 and better
|
||||
# define GTEST_HAS_STD_FUNCTION_ 1
|
||||
# endif
|
||||
# define GTEST_HAS_STD_INITIALIZER_LIST_ 1
|
||||
# define GTEST_HAS_STD_MOVE_ 1
|
||||
# define GTEST_HAS_STD_UNIQUE_PTR_ 1
|
||||
# define GTEST_HAS_STD_SHARED_PTR_ 1
|
||||
# define GTEST_HAS_UNORDERED_MAP_ 1
|
||||
# define GTEST_HAS_UNORDERED_SET_ 1
|
||||
#endif
|
||||
|
||||
// Brings in definitions for functions used in the testing::internal::posix
|
||||
// namespace (read, write, close, chdir, isatty, stat). We do not currently
|
||||
// use them on Windows Mobile.
|
||||
@ -500,9 +458,6 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
|
||||
#ifndef GTEST_HAS_STD_WSTRING
|
||||
// The user didn't tell us whether ::std::wstring is available, so we need
|
||||
// to figure it out.
|
||||
// FIXME: uses autoconf to detect whether ::std::wstring
|
||||
// is available.
|
||||
|
||||
// Cygwin 1.7 and below doesn't support ::std::wstring.
|
||||
// Solaris' libc++ doesn't support it either. Android has
|
||||
// no support for it at least as recent as Froyo (2.2).
|
||||
@ -532,7 +487,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
|
||||
# endif
|
||||
|
||||
// Starting with version 4.3.2, gcc defines __GXX_RTTI iff RTTI is enabled.
|
||||
# elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40302)
|
||||
# elif defined(__GNUC__)
|
||||
|
||||
# ifdef __GXX_RTTI
|
||||
// When building against STLport with the Android NDK and with
|
||||
@ -635,12 +590,11 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
|
||||
#ifndef GTEST_HAS_STREAM_REDIRECTION
|
||||
// By default, we assume that stream redirection is supported on all
|
||||
// platforms except known mobile ones.
|
||||
# if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN || \
|
||||
GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
|
||||
# if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
|
||||
# define GTEST_HAS_STREAM_REDIRECTION 0
|
||||
# else
|
||||
# define GTEST_HAS_STREAM_REDIRECTION 1
|
||||
# endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_SYMBIAN
|
||||
# endif // !GTEST_OS_WINDOWS_MOBILE
|
||||
#endif // GTEST_HAS_STREAM_REDIRECTION
|
||||
|
||||
// Determines whether to support death tests.
|
||||
@ -666,8 +620,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
|
||||
|
||||
// Determines whether the system compiler uses UTF-16 for encoding wide strings.
|
||||
#define GTEST_WIDE_STRING_USES_UTF16_ \
|
||||
(GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_SYMBIAN || \
|
||||
GTEST_OS_AIX || GTEST_OS_OS2)
|
||||
(GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_AIX || GTEST_OS_OS2)
|
||||
|
||||
// Determines whether test results can be streamed to a socket.
|
||||
#if GTEST_OS_LINUX
|
||||
@ -712,12 +665,6 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
|
||||
# define GTEST_ATTRIBUTE_UNUSED_
|
||||
#endif
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
# define GTEST_CXX11_EQUALS_DELETE_ = delete
|
||||
#else // GTEST_LANG_CXX11
|
||||
# define GTEST_CXX11_EQUALS_DELETE_
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
// Use this annotation before a function that takes a printf format string.
|
||||
#if (defined(__GNUC__) || defined(__clang__)) && !defined(COMPILER_ICC)
|
||||
# if defined(__MINGW_PRINTF_FORMAT)
|
||||
@ -739,12 +686,12 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
|
||||
// A macro to disallow operator=
|
||||
// This should be used in the private: declarations for a class.
|
||||
#define GTEST_DISALLOW_ASSIGN_(type) \
|
||||
void operator=(type const &) GTEST_CXX11_EQUALS_DELETE_
|
||||
void operator=(type const &) = delete
|
||||
|
||||
// A macro to disallow copy constructor and operator=
|
||||
// This should be used in the private: declarations for a class.
|
||||
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type) \
|
||||
type(type const &) GTEST_CXX11_EQUALS_DELETE_; \
|
||||
type(type const &) = delete; \
|
||||
GTEST_DISALLOW_ASSIGN_(type)
|
||||
|
||||
// Tell the compiler to warn about unused return values for functions declared
|
||||
@ -752,11 +699,11 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
|
||||
// following the argument list:
|
||||
//
|
||||
// Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_;
|
||||
#if defined(__GNUC__) && (GTEST_GCC_VER_ >= 30400) && !defined(COMPILER_ICC)
|
||||
#if defined(__GNUC__) && !defined(COMPILER_ICC)
|
||||
# define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result))
|
||||
#else
|
||||
# define GTEST_MUST_USE_RESULT_
|
||||
#endif // __GNUC__ && (GTEST_GCC_VER_ >= 30400) && !COMPILER_ICC
|
||||
#endif // __GNUC__ && !COMPILER_ICC
|
||||
|
||||
// MS C++ compiler emits warning when a conditional expression is compile time
|
||||
// constant. In some contexts this warning is false positive and needs to be
|
||||
@ -893,75 +840,16 @@ namespace internal {
|
||||
// Secret object, which is what we want.
|
||||
class Secret;
|
||||
|
||||
// The GTEST_COMPILE_ASSERT_ macro can be used to verify that a compile time
|
||||
// expression is true. For example, you could use it to verify the
|
||||
// size of a static array:
|
||||
// The GTEST_COMPILE_ASSERT_ is a legacy macro used to verify that a compile
|
||||
// time expression is true (in new code, use static_assert instead). For
|
||||
// example, you could use it to verify the size of a static array:
|
||||
//
|
||||
// GTEST_COMPILE_ASSERT_(GTEST_ARRAY_SIZE_(names) == NUM_NAMES,
|
||||
// names_incorrect_size);
|
||||
//
|
||||
// or to make sure a struct is smaller than a certain size:
|
||||
//
|
||||
// GTEST_COMPILE_ASSERT_(sizeof(foo) < 128, foo_too_large);
|
||||
//
|
||||
// The second argument to the macro is the name of the variable. If
|
||||
// the expression is false, most compilers will issue a warning/error
|
||||
// containing the name of the variable.
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
# define GTEST_COMPILE_ASSERT_(expr, msg) static_assert(expr, #msg)
|
||||
#else // !GTEST_LANG_CXX11
|
||||
template <bool>
|
||||
struct CompileAssert {
|
||||
};
|
||||
|
||||
# define GTEST_COMPILE_ASSERT_(expr, msg) \
|
||||
typedef ::testing::internal::CompileAssert<(static_cast<bool>(expr))> \
|
||||
msg[static_cast<bool>(expr) ? 1 : -1] GTEST_ATTRIBUTE_UNUSED_
|
||||
#endif // !GTEST_LANG_CXX11
|
||||
|
||||
// Implementation details of GTEST_COMPILE_ASSERT_:
|
||||
//
|
||||
// (In C++11, we simply use static_assert instead of the following)
|
||||
//
|
||||
// - GTEST_COMPILE_ASSERT_ works by defining an array type that has -1
|
||||
// elements (and thus is invalid) when the expression is false.
|
||||
//
|
||||
// - The simpler definition
|
||||
//
|
||||
// #define GTEST_COMPILE_ASSERT_(expr, msg) typedef char msg[(expr) ? 1 : -1]
|
||||
//
|
||||
// does not work, as gcc supports variable-length arrays whose sizes
|
||||
// are determined at run-time (this is gcc's extension and not part
|
||||
// of the C++ standard). As a result, gcc fails to reject the
|
||||
// following code with the simple definition:
|
||||
//
|
||||
// int foo;
|
||||
// GTEST_COMPILE_ASSERT_(foo, msg); // not supposed to compile as foo is
|
||||
// // not a compile-time constant.
|
||||
//
|
||||
// - By using the type CompileAssert<(bool(expr))>, we ensures that
|
||||
// expr is a compile-time constant. (Template arguments must be
|
||||
// determined at compile-time.)
|
||||
//
|
||||
// - The outter parentheses in CompileAssert<(bool(expr))> are necessary
|
||||
// to work around a bug in gcc 3.4.4 and 4.0.1. If we had written
|
||||
//
|
||||
// CompileAssert<bool(expr)>
|
||||
//
|
||||
// instead, these compilers will refuse to compile
|
||||
//
|
||||
// GTEST_COMPILE_ASSERT_(5 > 0, some_message);
|
||||
//
|
||||
// (They seem to think the ">" in "5 > 0" marks the end of the
|
||||
// template argument list.)
|
||||
//
|
||||
// - The array size is (bool(expr) ? 1 : -1), instead of simply
|
||||
//
|
||||
// ((expr) ? 1 : -1).
|
||||
//
|
||||
// This is to avoid running into a bug in MS VC 7.1, which
|
||||
// causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1.
|
||||
// The second argument to the macro must be a valid C++ identifier. If the
|
||||
// expression is false, compiler will issue an error containing this identifier.
|
||||
#define GTEST_COMPILE_ASSERT_(expr, msg) static_assert(expr, #msg)
|
||||
|
||||
// StaticAssertTypeEqHelper is used by StaticAssertTypeEq defined in gtest.h.
|
||||
//
|
||||
@ -1036,9 +924,6 @@ class GTEST_API_ RE {
|
||||
// the entire str.
|
||||
// PartialMatch(str, re) returns true iff regular expression re
|
||||
// matches a substring of str (including str itself).
|
||||
//
|
||||
// FIXME: make FullMatch() and PartialMatch() work
|
||||
// when str contains NUL characters.
|
||||
static bool FullMatch(const ::std::string& str, const RE& re) {
|
||||
return FullMatch(str.c_str(), re);
|
||||
}
|
||||
@ -1062,10 +947,6 @@ class GTEST_API_ RE {
|
||||
|
||||
private:
|
||||
void Init(const char* regex);
|
||||
|
||||
// We use a const char* instead of an std::string, as Google Test used to be
|
||||
// used where std::string is not available. FIXME: change to
|
||||
// std::string.
|
||||
const char* pattern_;
|
||||
bool is_valid_;
|
||||
|
||||
@ -2065,29 +1946,6 @@ class GTEST_API_ ThreadLocal {
|
||||
// we cannot detect it.
|
||||
GTEST_API_ size_t GetThreadCount();
|
||||
|
||||
// Passing non-POD classes through ellipsis (...) crashes the ARM
|
||||
// compiler and generates a warning in Sun Studio before 12u4. The Nokia Symbian
|
||||
// and the IBM XL C/C++ compiler try to instantiate a copy constructor
|
||||
// for objects passed through ellipsis (...), failing for uncopyable
|
||||
// objects. We define this to ensure that only POD is passed through
|
||||
// ellipsis on these systems.
|
||||
#if defined(__SYMBIAN32__) || defined(__IBMCPP__) || \
|
||||
(defined(__SUNPRO_CC) && __SUNPRO_CC < 0x5130)
|
||||
// We lose support for NULL detection where the compiler doesn't like
|
||||
// passing non-POD classes through ellipsis (...).
|
||||
# define GTEST_ELLIPSIS_NEEDS_POD_ 1
|
||||
#else
|
||||
# define GTEST_CAN_COMPARE_NULL 1
|
||||
#endif
|
||||
|
||||
// The Nokia Symbian and IBM XL C/C++ compilers cannot decide between
|
||||
// const T& and const T* in a function template. These compilers
|
||||
// _can_ decide between class template specializations for T and T*,
|
||||
// so a tr1::type_traits-like is_pointer works.
|
||||
#if defined(__SYMBIAN32__) || defined(__IBMCPP__)
|
||||
# define GTEST_NEEDS_IS_POINTER_ 1
|
||||
#endif
|
||||
|
||||
template <bool bool_value>
|
||||
struct bool_constant {
|
||||
typedef bool_constant<bool_value> type;
|
||||
@ -2104,13 +1962,6 @@ struct is_same : public false_type {};
|
||||
template <typename T>
|
||||
struct is_same<T, T> : public true_type {};
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct is_pointer : public false_type {};
|
||||
|
||||
template <typename T>
|
||||
struct is_pointer<T*> : public true_type {};
|
||||
|
||||
template <typename Iterator>
|
||||
struct IteratorTraits {
|
||||
typedef typename Iterator::value_type value_type;
|
||||
@ -2433,9 +2284,6 @@ typedef TypeWithSize<8>::Int TimeInMillis; // Represents time in milliseconds.
|
||||
// Parses 'str' for a 32-bit signed integer. If successful, writes the result
|
||||
// to *value and returns true; otherwise leaves *value unchanged and returns
|
||||
// false.
|
||||
// FIXME: Find a better way to refactor flag and environment parsing
|
||||
// out of both gtest-port.cc and gtest.cc to avoid exporting this utility
|
||||
// function.
|
||||
bool ParseInt32(const Message& src_text, const char* str, Int32* value);
|
||||
|
||||
// Parses a bool/Int32/string from the environment variable
|
||||
|
@ -31,12 +31,11 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
// Type utilities needed for implementing typed and type-parameterized
|
||||
// tests. This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
|
||||
//
|
||||
// Currently we support at most 50 types in a list, and at most 50
|
||||
// type-parameterized tests in one type-parameterized test case.
|
||||
// type-parameterized tests in one type-parameterized test suite.
|
||||
// Please contact googletestframework@googlegroups.com if you need
|
||||
// more.
|
||||
|
||||
@ -3312,8 +3311,8 @@ struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
|
||||
};
|
||||
|
||||
// The TypeList template makes it possible to use either a single type
|
||||
// or a Types<...> list in TYPED_TEST_CASE() and
|
||||
// INSTANTIATE_TYPED_TEST_CASE_P().
|
||||
// or a Types<...> list in TYPED_TEST_SUITE() and
|
||||
// INSTANTIATE_TYPED_TEST_SUITE_P().
|
||||
|
||||
template <typename T>
|
||||
struct TypeList {
|
||||
|
@ -34,7 +34,7 @@ $var n = 50 $$ Maximum length of type lists we want to support.
|
||||
// tests. This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
|
||||
//
|
||||
// Currently we support at most $n types in a list, and at most $n
|
||||
// type-parameterized tests in one type-parameterized test case.
|
||||
// type-parameterized tests in one type-parameterized test suite.
|
||||
// Please contact googletestframework@googlegroups.com if you need
|
||||
// more.
|
||||
|
||||
@ -291,8 +291,8 @@ struct Templates<$for j, [[T$j]]$for k[[, NoneT]]> {
|
||||
]]
|
||||
|
||||
// The TypeList template makes it possible to use either a single type
|
||||
// or a Types<...> list in TYPED_TEST_CASE() and
|
||||
// INSTANTIATE_TYPED_TEST_CASE_P().
|
||||
// or a Types<...> list in TYPED_TEST_SUITE() and
|
||||
// INSTANTIATE_TYPED_TEST_SUITE_P().
|
||||
|
||||
template <typename T>
|
||||
struct TypeList {
|
||||
|
@ -16,6 +16,9 @@
|
||||
# Remember to tweak this if you move this file.
|
||||
GTEST_DIR = ..
|
||||
|
||||
# Points to the location of the Google Test libraries
|
||||
GTEST_LIB_DIR = .
|
||||
|
||||
# Where to find user code.
|
||||
USER_DIR = ../samples
|
||||
|
||||
@ -27,6 +30,9 @@ CPPFLAGS += -isystem $(GTEST_DIR)/include
|
||||
# Flags passed to the C++ compiler.
|
||||
CXXFLAGS += -g -Wall -Wextra -pthread -std=c++11
|
||||
|
||||
# Google Test libraries
|
||||
GTEST_LIBS = libgtest.a libgtest_main.a
|
||||
|
||||
# All tests produced by this Makefile. Remember to add new tests you
|
||||
# created to the list.
|
||||
TESTS = sample1_unittest
|
||||
@ -38,10 +44,10 @@ GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \
|
||||
|
||||
# House-keeping build targets.
|
||||
|
||||
all : $(TESTS)
|
||||
all : $(GTEST_LIBS) $(TESTS)
|
||||
|
||||
clean :
|
||||
rm -f $(TESTS) gtest.a gtest_main.a *.o
|
||||
rm -f $(GTEST_LIBS) $(TESTS) *.o
|
||||
|
||||
# Builds gtest.a and gtest_main.a.
|
||||
|
||||
@ -61,10 +67,10 @@ gtest_main.o : $(GTEST_SRCS_)
|
||||
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \
|
||||
$(GTEST_DIR)/src/gtest_main.cc
|
||||
|
||||
gtest.a : gtest-all.o
|
||||
libgtest.a : gtest-all.o
|
||||
$(AR) $(ARFLAGS) $@ $^
|
||||
|
||||
gtest_main.a : gtest-all.o gtest_main.o
|
||||
libgtest_main.a : gtest-all.o gtest_main.o
|
||||
$(AR) $(ARFLAGS) $@ $^
|
||||
|
||||
# Builds a sample test. A test should link with either gtest.a or
|
||||
@ -78,5 +84,5 @@ sample1_unittest.o : $(USER_DIR)/sample1_unittest.cc \
|
||||
$(USER_DIR)/sample1.h $(GTEST_HEADERS)
|
||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/sample1_unittest.cc
|
||||
|
||||
sample1_unittest : sample1.o sample1_unittest.o gtest_main.a
|
||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
|
||||
sample1_unittest : sample1.o sample1_unittest.o $(GTEST_LIBS)
|
||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -L$(GTEST_LIB_DIR) -lgtest_main -lpthread $^ -o $@
|
||||
|
@ -274,8 +274,6 @@ static const int kFuchsiaReadPipeFd = 3;
|
||||
// statement, which is not allowed; THREW means that the test statement
|
||||
// returned control by throwing an exception. IN_PROGRESS means the test
|
||||
// has not yet concluded.
|
||||
// FIXME: Unify names and possibly values for
|
||||
// AbortReason, DeathTestOutcome, and flag characters above.
|
||||
enum DeathTestOutcome { IN_PROGRESS, DIED, LIVED, RETURNED, THREW };
|
||||
|
||||
// Routine for aborting the program which is safe to call from an
|
||||
@ -755,9 +753,9 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() {
|
||||
FALSE, // The initial state is non-signalled.
|
||||
nullptr)); // The even is unnamed.
|
||||
GTEST_DEATH_TEST_CHECK_(event_handle_.Get() != nullptr);
|
||||
const std::string filter_flag =
|
||||
std::string("--") + GTEST_FLAG_PREFIX_ + kFilterFlag + "=" +
|
||||
info->test_case_name() + "." + info->name();
|
||||
const std::string filter_flag = std::string("--") + GTEST_FLAG_PREFIX_ +
|
||||
kFilterFlag + "=" + info->test_suite_name() +
|
||||
"." + info->name();
|
||||
const std::string internal_flag =
|
||||
std::string("--") + GTEST_FLAG_PREFIX_ + kInternalRunDeathTestFlag +
|
||||
"=" + file_ + "|" + StreamableToString(line_) + "|" +
|
||||
@ -974,9 +972,9 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() {
|
||||
FlushInfoLog();
|
||||
|
||||
// Build the child process command line.
|
||||
const std::string filter_flag =
|
||||
std::string("--") + GTEST_FLAG_PREFIX_ + kFilterFlag + "="
|
||||
+ info->test_case_name() + "." + info->name();
|
||||
const std::string filter_flag = std::string("--") + GTEST_FLAG_PREFIX_ +
|
||||
kFilterFlag + "=" + info->test_suite_name() +
|
||||
"." + info->name();
|
||||
const std::string internal_flag =
|
||||
std::string("--") + GTEST_FLAG_PREFIX_ + kInternalRunDeathTestFlag + "="
|
||||
+ file_ + "|"
|
||||
@ -1413,9 +1411,9 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() {
|
||||
// it be closed when the child process does an exec:
|
||||
GTEST_DEATH_TEST_CHECK_(fcntl(pipe_fd[1], F_SETFD, 0) != -1);
|
||||
|
||||
const std::string filter_flag =
|
||||
std::string("--") + GTEST_FLAG_PREFIX_ + kFilterFlag + "="
|
||||
+ info->test_case_name() + "." + info->name();
|
||||
const std::string filter_flag = std::string("--") + GTEST_FLAG_PREFIX_ +
|
||||
kFilterFlag + "=" + info->test_suite_name() +
|
||||
"." + info->name();
|
||||
const std::string internal_flag =
|
||||
std::string("--") + GTEST_FLAG_PREFIX_ + kInternalRunDeathTestFlag + "="
|
||||
+ file_ + "|" + StreamableToString(line_) + "|"
|
||||
@ -1523,8 +1521,6 @@ static int GetStatusFileDescriptor(unsigned int parent_process_id,
|
||||
StreamableToString(parent_process_id));
|
||||
}
|
||||
|
||||
// FIXME: Replace the following check with a
|
||||
// compile-time assertion when available.
|
||||
GTEST_CHECK_(sizeof(HANDLE) <= sizeof(size_t));
|
||||
|
||||
const HANDLE write_handle =
|
||||
|
@ -38,9 +38,6 @@
|
||||
#elif GTEST_OS_WINDOWS
|
||||
# include <direct.h>
|
||||
# include <io.h>
|
||||
#elif GTEST_OS_SYMBIAN
|
||||
// Symbian OpenC has PATH_MAX in sys/syslimits.h
|
||||
# include <sys/syslimits.h>
|
||||
#else
|
||||
# include <limits.h>
|
||||
# include <climits> // Some Linux distributions define PATH_MAX here.
|
||||
@ -250,9 +247,6 @@ bool FilePath::DirectoryExists() const {
|
||||
// root directory per disk drive.)
|
||||
bool FilePath::IsRootDirectory() const {
|
||||
#if GTEST_OS_WINDOWS
|
||||
// FIXME: on Windows a network share like
|
||||
// \\server\share can be a root directory, although it cannot be the
|
||||
// current directory. Handle this properly.
|
||||
return pathname_.length() == 3 && IsAbsolutePath();
|
||||
#else
|
||||
return pathname_.length() == 1 && IsPathSeparator(pathname_.c_str()[0]);
|
||||
@ -350,7 +344,6 @@ FilePath FilePath::RemoveTrailingPathSeparator() const {
|
||||
// Removes any redundant separators that might be in the pathname.
|
||||
// For example, "bar///foo" becomes "bar/foo". Does not eliminate other
|
||||
// redundancies that might be in a pathname involving "." or "..".
|
||||
// FIXME: handle Windows network shares (e.g. \\server\share).
|
||||
void FilePath::Normalize() {
|
||||
if (pathname_.c_str() == nullptr) {
|
||||
pathname_ = "";
|
||||
|
@ -231,7 +231,7 @@ GTEST_API_ std::string CodePointToUtf8(UInt32 code_point);
|
||||
|
||||
// Converts a wide string to a narrow string in UTF-8 encoding.
|
||||
// The wide string is assumed to have the following encoding:
|
||||
// UTF-16 if sizeof(wchar_t) == 2 (on Windows, Cygwin, Symbian OS)
|
||||
// UTF-16 if sizeof(wchar_t) == 2 (on Windows, Cygwin)
|
||||
// UTF-32 if sizeof(wchar_t) == 4 (on Linux)
|
||||
// Parameter str points to a null-terminated wide string.
|
||||
// Parameter num_chars may additionally limit the number
|
||||
@ -388,10 +388,10 @@ class GTEST_API_ UnitTestOptions {
|
||||
// works well enough for matching test names, which are short.
|
||||
static bool PatternMatchesString(const char *pattern, const char *str);
|
||||
|
||||
// Returns true iff the user-specified filter matches the test case
|
||||
// Returns true iff the user-specified filter matches the test suite
|
||||
// name and the test name.
|
||||
static bool FilterMatchesTest(const std::string &test_case_name,
|
||||
const std::string &test_name);
|
||||
static bool FilterMatchesTest(const std::string& test_suite_name,
|
||||
const std::string& test_name);
|
||||
|
||||
#if GTEST_OS_WINDOWS
|
||||
// Function for supporting the gtest_catch_exception flag.
|
||||
@ -529,18 +529,18 @@ class GTEST_API_ UnitTestImpl {
|
||||
void SetTestPartResultReporterForCurrentThread(
|
||||
TestPartResultReporterInterface* reporter);
|
||||
|
||||
// Gets the number of successful test cases.
|
||||
int successful_test_case_count() const;
|
||||
// Gets the number of successful test suites.
|
||||
int successful_test_suite_count() const;
|
||||
|
||||
// Gets the number of failed test cases.
|
||||
int failed_test_case_count() const;
|
||||
// Gets the number of failed test suites.
|
||||
int failed_test_suite_count() const;
|
||||
|
||||
// Gets the number of all test cases.
|
||||
int total_test_case_count() const;
|
||||
// Gets the number of all test suites.
|
||||
int total_test_suite_count() const;
|
||||
|
||||
// Gets the number of all test cases that contain at least one test
|
||||
// Gets the number of all test suites that contain at least one test
|
||||
// that should run.
|
||||
int test_case_to_run_count() const;
|
||||
int test_suite_to_run_count() const;
|
||||
|
||||
// Gets the number of successful tests.
|
||||
int successful_test_count() const;
|
||||
@ -573,27 +573,32 @@ class GTEST_API_ UnitTestImpl {
|
||||
// Gets the elapsed time, in milliseconds.
|
||||
TimeInMillis elapsed_time() const { return elapsed_time_; }
|
||||
|
||||
// Returns true iff the unit test passed (i.e. all test cases passed).
|
||||
// Returns true iff the unit test passed (i.e. all test suites passed).
|
||||
bool Passed() const { return !Failed(); }
|
||||
|
||||
// Returns true iff the unit test failed (i.e. some test case failed
|
||||
// Returns true iff the unit test failed (i.e. some test suite failed
|
||||
// or something outside of all tests failed).
|
||||
bool Failed() const {
|
||||
return failed_test_case_count() > 0 || ad_hoc_test_result()->Failed();
|
||||
return failed_test_suite_count() > 0 || ad_hoc_test_result()->Failed();
|
||||
}
|
||||
|
||||
// Gets the i-th test case among all the test cases. i can range from 0 to
|
||||
// total_test_case_count() - 1. If i is not in that range, returns NULL.
|
||||
const TestCase* GetTestCase(int i) const {
|
||||
const int index = GetElementOr(test_case_indices_, i, -1);
|
||||
return index < 0 ? nullptr : test_cases_[i];
|
||||
// Gets the i-th test suite among all the test suites. i can range from 0 to
|
||||
// total_test_suite_count() - 1. If i is not in that range, returns NULL.
|
||||
const TestSuite* GetTestSuite(int i) const {
|
||||
const int index = GetElementOr(test_suite_indices_, i, -1);
|
||||
return index < 0 ? nullptr : test_suites_[i];
|
||||
}
|
||||
|
||||
// Gets the i-th test case among all the test cases. i can range from 0 to
|
||||
// total_test_case_count() - 1. If i is not in that range, returns NULL.
|
||||
TestCase* GetMutableTestCase(int i) {
|
||||
const int index = GetElementOr(test_case_indices_, i, -1);
|
||||
return index < 0 ? nullptr : test_cases_[index];
|
||||
// Legacy API is deprecated but still available
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
const TestCase* GetTestCase(int i) const { return GetTestSuite(i); }
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
// Gets the i-th test suite among all the test suites. i can range from 0 to
|
||||
// total_test_suite_count() - 1. If i is not in that range, returns NULL.
|
||||
TestSuite* GetMutableSuiteCase(int i) {
|
||||
const int index = GetElementOr(test_suite_indices_, i, -1);
|
||||
return index < 0 ? nullptr : test_suites_[index];
|
||||
}
|
||||
|
||||
// Provides access to the event listener list.
|
||||
@ -630,30 +635,38 @@ class GTEST_API_ UnitTestImpl {
|
||||
// trace but Bar() and CurrentOsStackTraceExceptTop() won't.
|
||||
std::string CurrentOsStackTraceExceptTop(int skip_count) GTEST_NO_INLINE_;
|
||||
|
||||
// Finds and returns a TestCase with the given name. If one doesn't
|
||||
// Finds and returns a TestSuite with the given name. If one doesn't
|
||||
// exist, creates one and returns it.
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// test_case_name: name of the test case
|
||||
// test_suite_name: name of the test suite
|
||||
// type_param: the name of the test's type parameter, or NULL if
|
||||
// this is not a typed or a type-parameterized test.
|
||||
// set_up_tc: pointer to the function that sets up the test case
|
||||
// tear_down_tc: pointer to the function that tears down the test case
|
||||
TestCase* GetTestCase(const char* test_case_name,
|
||||
const char* type_param,
|
||||
Test::SetUpTestCaseFunc set_up_tc,
|
||||
Test::TearDownTestCaseFunc tear_down_tc);
|
||||
// set_up_tc: pointer to the function that sets up the test suite
|
||||
// tear_down_tc: pointer to the function that tears down the test suite
|
||||
TestSuite* GetTestSuite(const char* test_suite_name, const char* type_param,
|
||||
internal::SetUpTestSuiteFunc set_up_tc,
|
||||
internal::TearDownTestSuiteFunc tear_down_tc);
|
||||
|
||||
// Legacy API is deprecated but still available
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
TestCase* GetTestCase(const char* test_case_name, const char* type_param,
|
||||
internal::SetUpTestSuiteFunc set_up_tc,
|
||||
internal::TearDownTestSuiteFunc tear_down_tc) {
|
||||
return GetTestSuite(test_case_name, type_param, set_up_tc, tear_down_tc);
|
||||
}
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
// Adds a TestInfo to the unit test.
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// set_up_tc: pointer to the function that sets up the test case
|
||||
// tear_down_tc: pointer to the function that tears down the test case
|
||||
// set_up_tc: pointer to the function that sets up the test suite
|
||||
// tear_down_tc: pointer to the function that tears down the test suite
|
||||
// test_info: the TestInfo object
|
||||
void AddTestInfo(Test::SetUpTestCaseFunc set_up_tc,
|
||||
Test::TearDownTestCaseFunc tear_down_tc,
|
||||
void AddTestInfo(internal::SetUpTestSuiteFunc set_up_tc,
|
||||
internal::TearDownTestSuiteFunc tear_down_tc,
|
||||
TestInfo* test_info) {
|
||||
// In order to support thread-safe death tests, we need to
|
||||
// remember the original working directory when the test program
|
||||
@ -668,21 +681,20 @@ class GTEST_API_ UnitTestImpl {
|
||||
<< "Failed to get the current working directory.";
|
||||
}
|
||||
|
||||
GetTestCase(test_info->test_case_name(),
|
||||
test_info->type_param(),
|
||||
set_up_tc,
|
||||
tear_down_tc)->AddTestInfo(test_info);
|
||||
GetTestSuite(test_info->test_suite_name(), test_info->type_param(),
|
||||
set_up_tc, tear_down_tc)
|
||||
->AddTestInfo(test_info);
|
||||
}
|
||||
|
||||
// Returns ParameterizedTestCaseRegistry object used to keep track of
|
||||
// Returns ParameterizedTestSuiteRegistry object used to keep track of
|
||||
// value-parameterized tests and instantiate and register them.
|
||||
internal::ParameterizedTestCaseRegistry& parameterized_test_registry() {
|
||||
internal::ParameterizedTestSuiteRegistry& parameterized_test_registry() {
|
||||
return parameterized_test_registry_;
|
||||
}
|
||||
|
||||
// Sets the TestCase object for the test that's currently running.
|
||||
void set_current_test_case(TestCase* a_current_test_case) {
|
||||
current_test_case_ = a_current_test_case;
|
||||
// Sets the TestSuite object for the test that's currently running.
|
||||
void set_current_test_suite(TestSuite* a_current_test_suite) {
|
||||
current_test_suite_ = a_current_test_suite;
|
||||
}
|
||||
|
||||
// Sets the TestInfo object for the test that's currently running. If
|
||||
@ -693,7 +705,7 @@ class GTEST_API_ UnitTestImpl {
|
||||
}
|
||||
|
||||
// Registers all parameterized tests defined using TEST_P and
|
||||
// INSTANTIATE_TEST_CASE_P, creating regular tests for each test/parameter
|
||||
// INSTANTIATE_TEST_SUITE_P, creating regular tests for each test/parameter
|
||||
// combination. This method can be called more then once; it has guards
|
||||
// protecting from registering the tests more then once. If
|
||||
// value-parameterized tests are disabled, RegisterParameterizedTests is
|
||||
@ -708,7 +720,7 @@ class GTEST_API_ UnitTestImpl {
|
||||
|
||||
// Clears the results of all tests, except the ad hoc tests.
|
||||
void ClearNonAdHocTestResult() {
|
||||
ForEach(test_cases_, TestCase::ClearTestCaseResult);
|
||||
ForEach(test_suites_, TestSuite::ClearTestSuiteResult);
|
||||
}
|
||||
|
||||
// Clears the results of ad-hoc test assertions.
|
||||
@ -717,7 +729,7 @@ class GTEST_API_ UnitTestImpl {
|
||||
}
|
||||
|
||||
// Adds a TestProperty to the current TestResult object when invoked in a
|
||||
// context of a test or a test case, or to the global property set. If the
|
||||
// context of a test or a test suite, or to the global property set. If the
|
||||
// result already contains a property with the same key, the value will be
|
||||
// updated.
|
||||
void RecordProperty(const TestProperty& test_property);
|
||||
@ -729,7 +741,7 @@ class GTEST_API_ UnitTestImpl {
|
||||
|
||||
// Matches the full name of each test against the user-specified
|
||||
// filter to decide whether the test should run, then records the
|
||||
// result in each TestCase and TestInfo object.
|
||||
// result in each TestSuite and TestInfo object.
|
||||
// If shard_tests == HONOR_SHARDING_PROTOCOL, further filters tests
|
||||
// based on sharding variables in the environment.
|
||||
// Returns the number of tests that should run.
|
||||
@ -738,7 +750,7 @@ class GTEST_API_ UnitTestImpl {
|
||||
// Prints the names of the tests matching the user-specified filter flag.
|
||||
void ListTestsMatchingFilter();
|
||||
|
||||
const TestCase* current_test_case() const { return current_test_case_; }
|
||||
const TestSuite* current_test_suite() const { return current_test_suite_; }
|
||||
TestInfo* current_test_info() { return current_test_info_; }
|
||||
const TestInfo* current_test_info() const { return current_test_info_; }
|
||||
|
||||
@ -799,11 +811,11 @@ class GTEST_API_ UnitTestImpl {
|
||||
// Gets the random number generator.
|
||||
internal::Random* random() { return &random_; }
|
||||
|
||||
// Shuffles all test cases, and the tests within each test case,
|
||||
// Shuffles all test suites, and the tests within each test suite,
|
||||
// making sure that death tests are still run first.
|
||||
void ShuffleTests();
|
||||
|
||||
// Restores the test cases and tests to their order before the first shuffle.
|
||||
// Restores the test suites and tests to their order before the first shuffle.
|
||||
void UnshuffleTests();
|
||||
|
||||
// Returns the value of GTEST_FLAG(catch_exceptions) at the moment
|
||||
@ -843,31 +855,31 @@ class GTEST_API_ UnitTestImpl {
|
||||
// before/after the tests are run.
|
||||
std::vector<Environment*> environments_;
|
||||
|
||||
// The vector of TestCases in their original order. It owns the
|
||||
// The vector of TestSuites in their original order. It owns the
|
||||
// elements in the vector.
|
||||
std::vector<TestCase*> test_cases_;
|
||||
std::vector<TestSuite*> test_suites_;
|
||||
|
||||
// Provides a level of indirection for the test case list to allow
|
||||
// easy shuffling and restoring the test case order. The i-th
|
||||
// element of this vector is the index of the i-th test case in the
|
||||
// Provides a level of indirection for the test suite list to allow
|
||||
// easy shuffling and restoring the test suite order. The i-th
|
||||
// element of this vector is the index of the i-th test suite in the
|
||||
// shuffled order.
|
||||
std::vector<int> test_case_indices_;
|
||||
std::vector<int> test_suite_indices_;
|
||||
|
||||
// ParameterizedTestRegistry object used to register value-parameterized
|
||||
// tests.
|
||||
internal::ParameterizedTestCaseRegistry parameterized_test_registry_;
|
||||
internal::ParameterizedTestSuiteRegistry parameterized_test_registry_;
|
||||
|
||||
// Indicates whether RegisterParameterizedTests() has been called already.
|
||||
bool parameterized_tests_registered_;
|
||||
|
||||
// Index of the last death test case registered. Initially -1.
|
||||
int last_death_test_case_;
|
||||
// Index of the last death test suite registered. Initially -1.
|
||||
int last_death_test_suite_;
|
||||
|
||||
// This points to the TestCase for the currently running test. It
|
||||
// changes as Google Test goes through one test case after another.
|
||||
// This points to the TestSuite for the currently running test. It
|
||||
// changes as Google Test goes through one test suite after another.
|
||||
// When no test is running, this is set to NULL and Google Test
|
||||
// stores assertion results in ad_hoc_test_result_. Initially NULL.
|
||||
TestCase* current_test_case_;
|
||||
TestSuite* current_test_suite_;
|
||||
|
||||
// This points to the TestInfo for the currently running test. It
|
||||
// changes as Google Test goes through one test after another. When
|
||||
@ -998,8 +1010,6 @@ bool ParseNaturalNumber(const ::std::string& str, Integer* number) {
|
||||
|
||||
const bool parse_success = *end == '\0' && errno == 0;
|
||||
|
||||
// FIXME: Convert this to compile time assertion when it is
|
||||
// available.
|
||||
GTEST_CHECK_(sizeof(Integer) <= sizeof(parsed));
|
||||
|
||||
const Integer result = static_cast<Integer>(parsed);
|
||||
@ -1138,14 +1148,18 @@ class StreamingListener : public EmptyTestEventListener {
|
||||
StreamableToString(unit_test.elapsed_time()) + "ms");
|
||||
}
|
||||
|
||||
// Note that "event=TestCaseStart" is a wire format and has to remain
|
||||
// "case" for compatibilty
|
||||
void OnTestCaseStart(const TestCase& test_case) override {
|
||||
SendLn(std::string("event=TestCaseStart&name=") + test_case.name());
|
||||
}
|
||||
|
||||
// Note that "event=TestCaseEnd" is a wire format and has to remain
|
||||
// "case" for compatibilty
|
||||
void OnTestCaseEnd(const TestCase& test_case) override {
|
||||
SendLn("event=TestCaseEnd&passed=" + FormatBool(test_case.Passed())
|
||||
+ "&elapsed_time=" + StreamableToString(test_case.elapsed_time())
|
||||
+ "ms");
|
||||
SendLn("event=TestCaseEnd&passed=" + FormatBool(test_case.Passed()) +
|
||||
"&elapsed_time=" + StreamableToString(test_case.elapsed_time()) +
|
||||
"ms");
|
||||
}
|
||||
|
||||
void OnTestStart(const TestInfo& test_info) override {
|
||||
|
@ -265,9 +265,6 @@ Mutex::Mutex()
|
||||
Mutex::~Mutex() {
|
||||
// Static mutexes are leaked intentionally. It is not thread-safe to try
|
||||
// to clean them up.
|
||||
// FIXME: Switch to Slim Reader/Writer (SRW) Locks, which requires
|
||||
// nothing to clean it up but is available only on Vista and later.
|
||||
// https://docs.microsoft.com/en-us/windows/desktop/Sync/slim-reader-writer--srw--locks
|
||||
if (type_ == kDynamic) {
|
||||
::DeleteCriticalSection(critical_section_);
|
||||
delete critical_section_;
|
||||
@ -388,7 +385,6 @@ class ThreadWithParamSupport : public ThreadWithParamBase {
|
||||
Notification* thread_can_start) {
|
||||
ThreadMainParam* param = new ThreadMainParam(runnable, thread_can_start);
|
||||
DWORD thread_id;
|
||||
// FIXME: Consider to use _beginthreadex instead.
|
||||
HANDLE thread_handle = ::CreateThread(
|
||||
nullptr, // Default security.
|
||||
0, // Default stack size.
|
||||
@ -741,9 +737,6 @@ static std::string FormatRegexSyntaxError(const char* regex, int index) {
|
||||
// otherwise returns true.
|
||||
bool ValidateRegex(const char* regex) {
|
||||
if (regex == nullptr) {
|
||||
// FIXME: fix the source file location in the
|
||||
// assertion failures to match where the regex is used in user
|
||||
// code.
|
||||
ADD_FAILURE() << "NULL is not a valid simple regular expression.";
|
||||
return false;
|
||||
}
|
||||
|
@ -89,7 +89,6 @@ void PrintBytesInObjectToImpl(const unsigned char* obj_bytes, size_t count,
|
||||
// If the object size is bigger than kThreshold, we'll have to omit
|
||||
// some details by printing only the first and the last kChunkSize
|
||||
// bytes.
|
||||
// FIXME: let the user control the threshold using a flag.
|
||||
if (count < kThreshold) {
|
||||
PrintByteSegmentInObjectTo(obj_bytes, 0, count, os);
|
||||
} else {
|
||||
|
@ -57,7 +57,7 @@ static std::vector<std::string> SplitIntoTestNames(const char* src) {
|
||||
// Verifies that registered_tests match the test names in
|
||||
// registered_tests_; returns registered_tests if successful, or
|
||||
// aborts the program otherwise.
|
||||
const char* TypedTestCasePState::VerifyRegisteredTestNames(
|
||||
const char* TypedTestSuitePState::VerifyRegisteredTestNames(
|
||||
const char* file, int line, const char* registered_tests) {
|
||||
typedef RegisteredTestsMap::const_iterator RegisteredTestIter;
|
||||
registered_ = true;
|
||||
@ -89,7 +89,7 @@ const char* TypedTestCasePState::VerifyRegisteredTestNames(
|
||||
tests.insert(name);
|
||||
} else {
|
||||
errors << "No test named " << name
|
||||
<< " can be found in this test case.\n";
|
||||
<< " can be found in this test suite.\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -278,6 +278,13 @@ cc_binary(
|
||||
deps = ["//:gtest"],
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "gtest_skip_test",
|
||||
size = "small",
|
||||
srcs = ["gtest_skip_test.cc"],
|
||||
deps = ["//:gtest_main"],
|
||||
)
|
||||
|
||||
py_test(
|
||||
name = "googletest-list-tests-unittest",
|
||||
size = "small",
|
||||
|
@ -140,8 +140,7 @@ class CatchCxxExceptionsTest(gtest_test_utils.TestCase):
|
||||
|
||||
def testCatchesCxxExceptionsInSetUpTestCase(self):
|
||||
self.assert_('C++ exception with description "Standard C++ exception"'
|
||||
' thrown in SetUpTestCase()'
|
||||
in EX_BINARY_OUTPUT)
|
||||
' thrown in SetUpTestSuite()' in EX_BINARY_OUTPUT)
|
||||
self.assert_('CxxExceptionInConstructorTest::TearDownTestCase() '
|
||||
'called as expected.'
|
||||
in EX_BINARY_OUTPUT)
|
||||
@ -163,8 +162,7 @@ class CatchCxxExceptionsTest(gtest_test_utils.TestCase):
|
||||
|
||||
def testCatchesCxxExceptionsInTearDownTestCase(self):
|
||||
self.assert_('C++ exception with description "Standard C++ exception"'
|
||||
' thrown in TearDownTestCase()'
|
||||
in EX_BINARY_OUTPUT)
|
||||
' thrown in TearDownTestSuite()' in EX_BINARY_OUTPUT)
|
||||
|
||||
def testCatchesCxxExceptionsInSetUp(self):
|
||||
self.assert_('C++ exception with description "Standard C++ exception"'
|
||||
|
@ -1281,9 +1281,6 @@ TEST(ParseNaturalNumberTest, WorksForShorterIntegers) {
|
||||
|
||||
# if GTEST_OS_WINDOWS
|
||||
TEST(EnvironmentTest, HandleFitsIntoSizeT) {
|
||||
// FIXME: Remove this test after this condition is verified
|
||||
// in a static assertion in gtest-death-test.cc in the function
|
||||
// GetStatusFileDescriptor.
|
||||
ASSERT_TRUE(sizeof(HANDLE) <= sizeof(size_t));
|
||||
}
|
||||
# endif // GTEST_OS_WINDOWS
|
||||
|
@ -50,8 +50,6 @@ namespace internal {
|
||||
namespace {
|
||||
|
||||
#if GTEST_OS_WINDOWS_MOBILE
|
||||
// FIXME: Move these to the POSIX adapter section in
|
||||
// gtest-port.h.
|
||||
|
||||
// Windows CE doesn't have the remove C function.
|
||||
int remove(const char* path) {
|
||||
|
@ -136,11 +136,6 @@ class GTestJsonOutFilesTest(gtest_test_utils.TestCase):
|
||||
self.assert_(p.exited)
|
||||
self.assertEquals(0, p.exit_code)
|
||||
|
||||
# FIXME: libtool causes the built test binary to be
|
||||
# named lt-gtest_xml_outfiles_test_ instead of
|
||||
# gtest_xml_outfiles_test_. To account for this possibility, we
|
||||
# allow both names in the following code. We should remove this
|
||||
# when libtool replacement tool is ready.
|
||||
output_file_name1 = test_name + '.json'
|
||||
output_file1 = os.path.join(self.output_dir_, output_file_name1)
|
||||
output_file_name2 = 'lt-' + output_file_name1
|
||||
|
@ -125,6 +125,78 @@ class EventRecordingListener : public TestEventListener {
|
||||
std::string name_;
|
||||
};
|
||||
|
||||
// This listener is using OnTestSuiteStart, OnTestSuiteEnd API
|
||||
class EventRecordingListener2 : public TestEventListener {
|
||||
public:
|
||||
explicit EventRecordingListener2(const char* name) : name_(name) {}
|
||||
|
||||
protected:
|
||||
void OnTestProgramStart(const UnitTest& /*unit_test*/) override {
|
||||
g_events->push_back(GetFullMethodName("OnTestProgramStart"));
|
||||
}
|
||||
|
||||
void OnTestIterationStart(const UnitTest& /*unit_test*/,
|
||||
int iteration) override {
|
||||
Message message;
|
||||
message << GetFullMethodName("OnTestIterationStart") << "(" << iteration
|
||||
<< ")";
|
||||
g_events->push_back(message.GetString());
|
||||
}
|
||||
|
||||
void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) override {
|
||||
g_events->push_back(GetFullMethodName("OnEnvironmentsSetUpStart"));
|
||||
}
|
||||
|
||||
void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) override {
|
||||
g_events->push_back(GetFullMethodName("OnEnvironmentsSetUpEnd"));
|
||||
}
|
||||
|
||||
void OnTestSuiteStart(const TestSuite& /*test_suite*/) override {
|
||||
g_events->push_back(GetFullMethodName("OnTestSuiteStart"));
|
||||
}
|
||||
|
||||
void OnTestStart(const TestInfo& /*test_info*/) override {
|
||||
g_events->push_back(GetFullMethodName("OnTestStart"));
|
||||
}
|
||||
|
||||
void OnTestPartResult(const TestPartResult& /*test_part_result*/) override {
|
||||
g_events->push_back(GetFullMethodName("OnTestPartResult"));
|
||||
}
|
||||
|
||||
void OnTestEnd(const TestInfo& /*test_info*/) override {
|
||||
g_events->push_back(GetFullMethodName("OnTestEnd"));
|
||||
}
|
||||
|
||||
void OnTestSuiteEnd(const TestSuite& /*test_suite*/) override {
|
||||
g_events->push_back(GetFullMethodName("OnTestSuiteEnd"));
|
||||
}
|
||||
|
||||
void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) override {
|
||||
g_events->push_back(GetFullMethodName("OnEnvironmentsTearDownStart"));
|
||||
}
|
||||
|
||||
void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) override {
|
||||
g_events->push_back(GetFullMethodName("OnEnvironmentsTearDownEnd"));
|
||||
}
|
||||
|
||||
void OnTestIterationEnd(const UnitTest& /*unit_test*/,
|
||||
int iteration) override {
|
||||
Message message;
|
||||
message << GetFullMethodName("OnTestIterationEnd") << "(" << iteration
|
||||
<< ")";
|
||||
g_events->push_back(message.GetString());
|
||||
}
|
||||
|
||||
void OnTestProgramEnd(const UnitTest& /*unit_test*/) override {
|
||||
g_events->push_back(GetFullMethodName("OnTestProgramEnd"));
|
||||
}
|
||||
|
||||
private:
|
||||
std::string GetFullMethodName(const char* name) { return name_ + "." + name; }
|
||||
|
||||
std::string name_;
|
||||
};
|
||||
|
||||
class EnvironmentInvocationCatcher : public Environment {
|
||||
protected:
|
||||
void SetUp() override { g_events->push_back("Environment::SetUp"); }
|
||||
@ -165,6 +237,7 @@ TEST_F(ListenerTest, DoesBar) {
|
||||
|
||||
using ::testing::internal::EnvironmentInvocationCatcher;
|
||||
using ::testing::internal::EventRecordingListener;
|
||||
using ::testing::internal::EventRecordingListener2;
|
||||
|
||||
void VerifyResults(const std::vector<std::string>& data,
|
||||
const char* const* expected_data,
|
||||
@ -199,6 +272,8 @@ int main(int argc, char **argv) {
|
||||
new EventRecordingListener("1st"));
|
||||
UnitTest::GetInstance()->listeners().Append(
|
||||
new EventRecordingListener("2nd"));
|
||||
UnitTest::GetInstance()->listeners().Append(
|
||||
new EventRecordingListener2("3rd"));
|
||||
|
||||
AddGlobalTestEnvironment(new EnvironmentInvocationCatcher);
|
||||
|
||||
@ -208,88 +283,117 @@ int main(int argc, char **argv) {
|
||||
::testing::GTEST_FLAG(repeat) = 2;
|
||||
int ret_val = RUN_ALL_TESTS();
|
||||
|
||||
const char* const expected_events[] = {
|
||||
"1st.OnTestProgramStart",
|
||||
const char* const expected_events[] = {"1st.OnTestProgramStart",
|
||||
"2nd.OnTestProgramStart",
|
||||
"3rd.OnTestProgramStart",
|
||||
"1st.OnTestIterationStart(0)",
|
||||
"2nd.OnTestIterationStart(0)",
|
||||
"3rd.OnTestIterationStart(0)",
|
||||
"1st.OnEnvironmentsSetUpStart",
|
||||
"2nd.OnEnvironmentsSetUpStart",
|
||||
"3rd.OnEnvironmentsSetUpStart",
|
||||
"Environment::SetUp",
|
||||
"3rd.OnEnvironmentsSetUpEnd",
|
||||
"2nd.OnEnvironmentsSetUpEnd",
|
||||
"1st.OnEnvironmentsSetUpEnd",
|
||||
"3rd.OnTestSuiteStart",
|
||||
"1st.OnTestCaseStart",
|
||||
"2nd.OnTestCaseStart",
|
||||
"ListenerTest::SetUpTestCase",
|
||||
"1st.OnTestStart",
|
||||
"2nd.OnTestStart",
|
||||
"3rd.OnTestStart",
|
||||
"ListenerTest::SetUp",
|
||||
"ListenerTest::* Test Body",
|
||||
"1st.OnTestPartResult",
|
||||
"2nd.OnTestPartResult",
|
||||
"3rd.OnTestPartResult",
|
||||
"ListenerTest::TearDown",
|
||||
"3rd.OnTestEnd",
|
||||
"2nd.OnTestEnd",
|
||||
"1st.OnTestEnd",
|
||||
"1st.OnTestStart",
|
||||
"2nd.OnTestStart",
|
||||
"3rd.OnTestStart",
|
||||
"ListenerTest::SetUp",
|
||||
"ListenerTest::* Test Body",
|
||||
"1st.OnTestPartResult",
|
||||
"2nd.OnTestPartResult",
|
||||
"3rd.OnTestPartResult",
|
||||
"ListenerTest::TearDown",
|
||||
"3rd.OnTestEnd",
|
||||
"2nd.OnTestEnd",
|
||||
"1st.OnTestEnd",
|
||||
"ListenerTest::TearDownTestCase",
|
||||
"3rd.OnTestSuiteEnd",
|
||||
"2nd.OnTestCaseEnd",
|
||||
"1st.OnTestCaseEnd",
|
||||
"1st.OnEnvironmentsTearDownStart",
|
||||
"2nd.OnEnvironmentsTearDownStart",
|
||||
"3rd.OnEnvironmentsTearDownStart",
|
||||
"Environment::TearDown",
|
||||
"3rd.OnEnvironmentsTearDownEnd",
|
||||
"2nd.OnEnvironmentsTearDownEnd",
|
||||
"1st.OnEnvironmentsTearDownEnd",
|
||||
"3rd.OnTestIterationEnd(0)",
|
||||
"2nd.OnTestIterationEnd(0)",
|
||||
"1st.OnTestIterationEnd(0)",
|
||||
"1st.OnTestIterationStart(1)",
|
||||
"2nd.OnTestIterationStart(1)",
|
||||
"3rd.OnTestIterationStart(1)",
|
||||
"1st.OnEnvironmentsSetUpStart",
|
||||
"2nd.OnEnvironmentsSetUpStart",
|
||||
"3rd.OnEnvironmentsSetUpStart",
|
||||
"Environment::SetUp",
|
||||
"3rd.OnEnvironmentsSetUpEnd",
|
||||
"2nd.OnEnvironmentsSetUpEnd",
|
||||
"1st.OnEnvironmentsSetUpEnd",
|
||||
"3rd.OnTestSuiteStart",
|
||||
"1st.OnTestCaseStart",
|
||||
"2nd.OnTestCaseStart",
|
||||
"ListenerTest::SetUpTestCase",
|
||||
"1st.OnTestStart",
|
||||
"2nd.OnTestStart",
|
||||
"3rd.OnTestStart",
|
||||
"ListenerTest::SetUp",
|
||||
"ListenerTest::* Test Body",
|
||||
"1st.OnTestPartResult",
|
||||
"2nd.OnTestPartResult",
|
||||
"3rd.OnTestPartResult",
|
||||
"ListenerTest::TearDown",
|
||||
"3rd.OnTestEnd",
|
||||
"2nd.OnTestEnd",
|
||||
"1st.OnTestEnd",
|
||||
"1st.OnTestStart",
|
||||
"2nd.OnTestStart",
|
||||
"3rd.OnTestStart",
|
||||
"ListenerTest::SetUp",
|
||||
"ListenerTest::* Test Body",
|
||||
"1st.OnTestPartResult",
|
||||
"2nd.OnTestPartResult",
|
||||
"3rd.OnTestPartResult",
|
||||
"ListenerTest::TearDown",
|
||||
"3rd.OnTestEnd",
|
||||
"2nd.OnTestEnd",
|
||||
"1st.OnTestEnd",
|
||||
"ListenerTest::TearDownTestCase",
|
||||
"3rd.OnTestSuiteEnd",
|
||||
"2nd.OnTestCaseEnd",
|
||||
"1st.OnTestCaseEnd",
|
||||
"1st.OnEnvironmentsTearDownStart",
|
||||
"2nd.OnEnvironmentsTearDownStart",
|
||||
"3rd.OnEnvironmentsTearDownStart",
|
||||
"Environment::TearDown",
|
||||
"3rd.OnEnvironmentsTearDownEnd",
|
||||
"2nd.OnEnvironmentsTearDownEnd",
|
||||
"1st.OnEnvironmentsTearDownEnd",
|
||||
"3rd.OnTestIterationEnd(1)",
|
||||
"2nd.OnTestIterationEnd(1)",
|
||||
"1st.OnTestIterationEnd(1)",
|
||||
"3rd.OnTestProgramEnd",
|
||||
"2nd.OnTestProgramEnd",
|
||||
"1st.OnTestProgramEnd"
|
||||
};
|
||||
"1st.OnTestProgramEnd"};
|
||||
|
||||
VerifyResults(events,
|
||||
expected_events,
|
||||
sizeof(expected_events)/sizeof(expected_events[0]));
|
||||
|
@ -111,7 +111,6 @@ TEST(OutputFileHelpersTest, GetCurrentExecutableName) {
|
||||
#elif GTEST_OS_FUCHSIA
|
||||
const bool success = exe_str == "app";
|
||||
#else
|
||||
// FIXME: remove the hard-coded "lt-" prefix when libtool replacement is ready
|
||||
const bool success =
|
||||
exe_str == "googletest-options-test" ||
|
||||
exe_str == "gtest_all_test" ||
|
||||
|
@ -12,7 +12,7 @@ Expected equality of these values:
|
||||
3
|
||||
Stack trace: (omitted)
|
||||
|
||||
[0;32m[==========] [mRunning 76 tests from 34 test cases.
|
||||
[0;32m[==========] [mRunning 83 tests from 38 test suites.
|
||||
[0;32m[----------] [mGlobal test environment set-up.
|
||||
FooEnvironment::SetUp() called.
|
||||
BarEnvironment::SetUp() called.
|
||||
@ -392,26 +392,26 @@ Stack trace: (omitted)
|
||||
[0;32m[ RUN ] [mMixedUpTestCaseTest.ThisShouldFail
|
||||
gtest.cc:#: Failure
|
||||
Failed
|
||||
All tests in the same test case must use the same test fixture
|
||||
class. However, in test case MixedUpTestCaseTest,
|
||||
All tests in the same test suite must use the same test fixture
|
||||
class. However, in test suite MixedUpTestCaseTest,
|
||||
you defined test FirstTestFromNamespaceFoo and test ThisShouldFail
|
||||
using two different test fixture classes. This can happen if
|
||||
the two classes are from different namespaces or translation
|
||||
units and have the same name. You should probably rename one
|
||||
of the classes to put the tests into different test cases.
|
||||
of the classes to put the tests into different test suites.
|
||||
Stack trace: (omitted)
|
||||
|
||||
[0;31m[ FAILED ] [mMixedUpTestCaseTest.ThisShouldFail
|
||||
[0;32m[ RUN ] [mMixedUpTestCaseTest.ThisShouldFailToo
|
||||
gtest.cc:#: Failure
|
||||
Failed
|
||||
All tests in the same test case must use the same test fixture
|
||||
class. However, in test case MixedUpTestCaseTest,
|
||||
All tests in the same test suite must use the same test fixture
|
||||
class. However, in test suite MixedUpTestCaseTest,
|
||||
you defined test FirstTestFromNamespaceFoo and test ThisShouldFailToo
|
||||
using two different test fixture classes. This can happen if
|
||||
the two classes are from different namespaces or translation
|
||||
units and have the same name. You should probably rename one
|
||||
of the classes to put the tests into different test cases.
|
||||
of the classes to put the tests into different test suites.
|
||||
Stack trace: (omitted)
|
||||
|
||||
[0;31m[ FAILED ] [mMixedUpTestCaseTest.ThisShouldFailToo
|
||||
@ -421,13 +421,13 @@ Stack trace: (omitted)
|
||||
[0;32m[ RUN ] [mMixedUpTestCaseWithSameTestNameTest.TheSecondTestWithThisNameShouldFail
|
||||
gtest.cc:#: Failure
|
||||
Failed
|
||||
All tests in the same test case must use the same test fixture
|
||||
class. However, in test case MixedUpTestCaseWithSameTestNameTest,
|
||||
All tests in the same test suite must use the same test fixture
|
||||
class. However, in test suite MixedUpTestCaseWithSameTestNameTest,
|
||||
you defined test TheSecondTestWithThisNameShouldFail and test TheSecondTestWithThisNameShouldFail
|
||||
using two different test fixture classes. This can happen if
|
||||
the two classes are from different namespaces or translation
|
||||
units and have the same name. You should probably rename one
|
||||
of the classes to put the tests into different test cases.
|
||||
of the classes to put the tests into different test suites.
|
||||
Stack trace: (omitted)
|
||||
|
||||
[0;31m[ FAILED ] [mMixedUpTestCaseWithSameTestNameTest.TheSecondTestWithThisNameShouldFail
|
||||
@ -437,9 +437,9 @@ Stack trace: (omitted)
|
||||
[0;32m[ RUN ] [mTEST_F_before_TEST_in_same_test_case.DefinedUsingTESTAndShouldFail
|
||||
gtest.cc:#: Failure
|
||||
Failed
|
||||
All tests in the same test case must use the same test fixture
|
||||
class, so mixing TEST_F and TEST in the same test case is
|
||||
illegal. In test case TEST_F_before_TEST_in_same_test_case,
|
||||
All tests in the same test suite must use the same test fixture
|
||||
class, so mixing TEST_F and TEST in the same test suite is
|
||||
illegal. In test suite TEST_F_before_TEST_in_same_test_case,
|
||||
test DefinedUsingTEST_F is defined using TEST_F but
|
||||
test DefinedUsingTESTAndShouldFail is defined using TEST. You probably
|
||||
want to change the TEST to TEST_F or move it to another test
|
||||
@ -453,9 +453,9 @@ Stack trace: (omitted)
|
||||
[0;32m[ RUN ] [mTEST_before_TEST_F_in_same_test_case.DefinedUsingTEST_FAndShouldFail
|
||||
gtest.cc:#: Failure
|
||||
Failed
|
||||
All tests in the same test case must use the same test fixture
|
||||
class, so mixing TEST_F and TEST in the same test case is
|
||||
illegal. In test case TEST_before_TEST_F_in_same_test_case,
|
||||
All tests in the same test suite must use the same test fixture
|
||||
class, so mixing TEST_F and TEST in the same test suite is
|
||||
illegal. In test suite TEST_before_TEST_F_in_same_test_case,
|
||||
test DefinedUsingTEST_FAndShouldFail is defined using TEST_F but
|
||||
test DefinedUsingTEST is defined using TEST. You probably
|
||||
want to change the TEST to TEST_F or move it to another test
|
||||
@ -870,6 +870,84 @@ Expected non-fatal failure.
|
||||
Stack trace: (omitted)
|
||||
|
||||
[0;31m[ FAILED ] [mScopedFakeTestPartResultReporterTest.InterceptOnlyCurrentThread
|
||||
[0;32m[----------] [m2 tests from DynamicFixture
|
||||
DynamicFixture::SetUpTestCase
|
||||
[0;32m[ RUN ] [mDynamicFixture.DynamicTestPass
|
||||
DynamicFixture()
|
||||
DynamicFixture::SetUp
|
||||
DynamicFixture::TearDown
|
||||
~DynamicFixture()
|
||||
[0;32m[ OK ] [mDynamicFixture.DynamicTestPass
|
||||
[0;32m[ RUN ] [mDynamicFixture.DynamicTestFail
|
||||
DynamicFixture()
|
||||
DynamicFixture::SetUp
|
||||
googletest-output-test_.cc:#: Failure
|
||||
Value of: Pass
|
||||
Actual: false
|
||||
Expected: true
|
||||
Stack trace: (omitted)
|
||||
|
||||
DynamicFixture::TearDown
|
||||
~DynamicFixture()
|
||||
[0;31m[ FAILED ] [mDynamicFixture.DynamicTestFail
|
||||
DynamicFixture::TearDownTestCase
|
||||
[0;32m[----------] [m1 test from DynamicFixtureAnotherName
|
||||
DynamicFixture::SetUpTestCase
|
||||
[0;32m[ RUN ] [mDynamicFixtureAnotherName.DynamicTestPass
|
||||
DynamicFixture()
|
||||
DynamicFixture::SetUp
|
||||
DynamicFixture::TearDown
|
||||
~DynamicFixture()
|
||||
[0;32m[ OK ] [mDynamicFixtureAnotherName.DynamicTestPass
|
||||
DynamicFixture::TearDownTestCase
|
||||
[0;32m[----------] [m2 tests from BadDynamicFixture1
|
||||
DynamicFixture::SetUpTestCase
|
||||
[0;32m[ RUN ] [mBadDynamicFixture1.FixtureBase
|
||||
DynamicFixture()
|
||||
DynamicFixture::SetUp
|
||||
DynamicFixture::TearDown
|
||||
~DynamicFixture()
|
||||
[0;32m[ OK ] [mBadDynamicFixture1.FixtureBase
|
||||
[0;32m[ RUN ] [mBadDynamicFixture1.TestBase
|
||||
DynamicFixture()
|
||||
gtest.cc:#: Failure
|
||||
Failed
|
||||
All tests in the same test suite must use the same test fixture
|
||||
class, so mixing TEST_F and TEST in the same test suite is
|
||||
illegal. In test suite BadDynamicFixture1,
|
||||
test FixtureBase is defined using TEST_F but
|
||||
test TestBase is defined using TEST. You probably
|
||||
want to change the TEST to TEST_F or move it to another test
|
||||
case.
|
||||
Stack trace: (omitted)
|
||||
|
||||
~DynamicFixture()
|
||||
[0;31m[ FAILED ] [mBadDynamicFixture1.TestBase
|
||||
DynamicFixture::TearDownTestCase
|
||||
[0;32m[----------] [m2 tests from BadDynamicFixture2
|
||||
DynamicFixture::SetUpTestCase
|
||||
[0;32m[ RUN ] [mBadDynamicFixture2.FixtureBase
|
||||
DynamicFixture()
|
||||
DynamicFixture::SetUp
|
||||
DynamicFixture::TearDown
|
||||
~DynamicFixture()
|
||||
[0;32m[ OK ] [mBadDynamicFixture2.FixtureBase
|
||||
[0;32m[ RUN ] [mBadDynamicFixture2.Derived
|
||||
DynamicFixture()
|
||||
gtest.cc:#: Failure
|
||||
Failed
|
||||
All tests in the same test suite must use the same test fixture
|
||||
class. However, in test suite BadDynamicFixture2,
|
||||
you defined test FixtureBase and test Derived
|
||||
using two different test fixture classes. This can happen if
|
||||
the two classes are from different namespaces or translation
|
||||
units and have the same name. You should probably rename one
|
||||
of the classes to put the tests into different test suites.
|
||||
Stack trace: (omitted)
|
||||
|
||||
~DynamicFixture()
|
||||
[0;31m[ FAILED ] [mBadDynamicFixture2.Derived
|
||||
DynamicFixture::TearDownTestCase
|
||||
[0;32m[----------] [m1 test from PrintingFailingParams/FailingParamTest
|
||||
[0;32m[ RUN ] [mPrintingFailingParams/FailingParamTest.Fails/0
|
||||
googletest-output-test_.cc:#: Failure
|
||||
@ -906,9 +984,9 @@ Failed
|
||||
Expected fatal failure.
|
||||
Stack trace: (omitted)
|
||||
|
||||
[0;32m[==========] [m76 tests from 34 test cases ran.
|
||||
[0;32m[ PASSED ] [m26 tests.
|
||||
[0;31m[ FAILED ] [m50 tests, listed below:
|
||||
[0;32m[==========] [m83 tests from 38 test suites ran.
|
||||
[0;32m[ PASSED ] [m30 tests.
|
||||
[0;31m[ FAILED ] [m53 tests, listed below:
|
||||
[0;31m[ FAILED ] [mNonfatalFailureTest.EscapesStringOperands
|
||||
[0;31m[ FAILED ] [mNonfatalFailureTest.DiffForLongStrings
|
||||
[0;31m[ FAILED ] [mFatalFailureTest.FatalFailureInSubroutine
|
||||
@ -957,14 +1035,17 @@ Stack trace: (omitted)
|
||||
[0;31m[ FAILED ] [mExpectFailureWithThreadsTest.ExpectFatalFailure
|
||||
[0;31m[ FAILED ] [mExpectFailureWithThreadsTest.ExpectNonFatalFailure
|
||||
[0;31m[ FAILED ] [mScopedFakeTestPartResultReporterTest.InterceptOnlyCurrentThread
|
||||
[0;31m[ FAILED ] [mDynamicFixture.DynamicTestFail
|
||||
[0;31m[ FAILED ] [mBadDynamicFixture1.TestBase
|
||||
[0;31m[ FAILED ] [mBadDynamicFixture2.Derived
|
||||
[0;31m[ FAILED ] [mPrintingFailingParams/FailingParamTest.Fails/0, where GetParam() = 2
|
||||
[0;31m[ FAILED ] [mPrintingStrings/ParamTest.Failure/a, where GetParam() = "a"
|
||||
|
||||
50 FAILED TESTS
|
||||
53 FAILED TESTS
|
||||
[0;33m YOU HAVE 1 DISABLED TEST
|
||||
|
||||
[mNote: Google Test filter = FatalFailureTest.*:LoggingTest.*
|
||||
[==========] Running 4 tests from 2 test cases.
|
||||
[==========] Running 4 tests from 2 test suites.
|
||||
[----------] Global test environment set-up.
|
||||
[----------] 3 tests from FatalFailureTest
|
||||
[ RUN ] FatalFailureTest.FatalFailureInSubroutine
|
||||
@ -1017,7 +1098,7 @@ Stack trace: (omitted)
|
||||
[----------] 1 test from LoggingTest (? ms total)
|
||||
|
||||
[----------] Global test environment tear-down
|
||||
[==========] 4 tests from 2 test cases ran. (? ms total)
|
||||
[==========] 4 tests from 2 test suites ran. (? ms total)
|
||||
[ PASSED ] 0 tests.
|
||||
[ FAILED ] 4 tests, listed below:
|
||||
[ FAILED ] FatalFailureTest.FatalFailureInSubroutine
|
||||
@ -1027,21 +1108,21 @@ Stack trace: (omitted)
|
||||
|
||||
4 FAILED TESTS
|
||||
Note: Google Test filter = *DISABLED_*
|
||||
[==========] Running 1 test from 1 test case.
|
||||
[==========] Running 1 test from 1 test suite.
|
||||
[----------] Global test environment set-up.
|
||||
[----------] 1 test from DisabledTestsWarningTest
|
||||
[ RUN ] DisabledTestsWarningTest.DISABLED_AlsoRunDisabledTestsFlagSuppressesWarning
|
||||
[ OK ] DisabledTestsWarningTest.DISABLED_AlsoRunDisabledTestsFlagSuppressesWarning
|
||||
[----------] Global test environment tear-down
|
||||
[==========] 1 test from 1 test case ran.
|
||||
[==========] 1 test from 1 test suite ran.
|
||||
[ PASSED ] 1 test.
|
||||
Note: Google Test filter = PassingTest.*
|
||||
Note: This is test shard 2 of 2.
|
||||
[==========] Running 1 test from 1 test case.
|
||||
[==========] Running 1 test from 1 test suite.
|
||||
[----------] Global test environment set-up.
|
||||
[----------] 1 test from PassingTest
|
||||
[ RUN ] PassingTest.PassingTest2
|
||||
[ OK ] PassingTest.PassingTest2
|
||||
[----------] Global test environment tear-down
|
||||
[==========] 1 test from 1 test case ran.
|
||||
[==========] 1 test from 1 test suite ran.
|
||||
[ PASSED ] 1 test.
|
||||
|
@ -55,7 +55,6 @@ NO_STACKTRACE_SUPPORT_FLAG = '--no_stacktrace_support'
|
||||
IS_LINUX = os.name == 'posix' and os.uname()[0] == 'Linux'
|
||||
IS_WINDOWS = os.name == 'nt'
|
||||
|
||||
# FIXME: remove the _lin suffix.
|
||||
GOLDEN_NAME = 'googletest-output-test-golden-lin.txt'
|
||||
|
||||
PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath('googletest-output-test_')
|
||||
|
@ -1024,6 +1024,56 @@ TEST_F(ExpectFailureTest, ExpectNonFatalFailureOnAllThreads) {
|
||||
"Some other non-fatal failure.");
|
||||
}
|
||||
|
||||
class DynamicFixture : public testing::Test {
|
||||
protected:
|
||||
DynamicFixture() { printf("DynamicFixture()\n"); }
|
||||
~DynamicFixture() override { printf("~DynamicFixture()\n"); }
|
||||
void SetUp() override { printf("DynamicFixture::SetUp\n"); }
|
||||
void TearDown() override { printf("DynamicFixture::TearDown\n"); }
|
||||
|
||||
static void SetUpTestCase() { printf("DynamicFixture::SetUpTestCase\n"); }
|
||||
static void TearDownTestCase() {
|
||||
printf("DynamicFixture::TearDownTestCase\n");
|
||||
}
|
||||
};
|
||||
|
||||
template <bool Pass>
|
||||
class DynamicTest : public DynamicFixture {
|
||||
public:
|
||||
void TestBody() override { EXPECT_TRUE(Pass); }
|
||||
};
|
||||
|
||||
auto dynamic_test = (
|
||||
// Register two tests with the same fixture correctly.
|
||||
testing::RegisterTest(
|
||||
"DynamicFixture", "DynamicTestPass", nullptr, nullptr, __FILE__,
|
||||
__LINE__, []() -> DynamicFixture* { return new DynamicTest<true>; }),
|
||||
testing::RegisterTest(
|
||||
"DynamicFixture", "DynamicTestFail", nullptr, nullptr, __FILE__,
|
||||
__LINE__, []() -> DynamicFixture* { return new DynamicTest<false>; }),
|
||||
|
||||
// Register the same fixture with another name. That's fine.
|
||||
testing::RegisterTest(
|
||||
"DynamicFixtureAnotherName", "DynamicTestPass", nullptr, nullptr,
|
||||
__FILE__, __LINE__,
|
||||
[]() -> DynamicFixture* { return new DynamicTest<true>; }),
|
||||
|
||||
// Register two tests with the same fixture incorrectly.
|
||||
testing::RegisterTest(
|
||||
"BadDynamicFixture1", "FixtureBase", nullptr, nullptr, __FILE__,
|
||||
__LINE__, []() -> DynamicFixture* { return new DynamicTest<true>; }),
|
||||
testing::RegisterTest(
|
||||
"BadDynamicFixture1", "TestBase", nullptr, nullptr, __FILE__, __LINE__,
|
||||
[]() -> testing::Test* { return new DynamicTest<true>; }),
|
||||
|
||||
// Register two tests with the same fixture incorrectly by ommiting the
|
||||
// return type.
|
||||
testing::RegisterTest(
|
||||
"BadDynamicFixture2", "FixtureBase", nullptr, nullptr, __FILE__,
|
||||
__LINE__, []() -> DynamicFixture* { return new DynamicTest<true>; }),
|
||||
testing::RegisterTest("BadDynamicFixture2", "Derived", nullptr, nullptr,
|
||||
__FILE__, __LINE__,
|
||||
[]() { return new DynamicTest<true>; }));
|
||||
|
||||
// Two test environments for testing testing::AddGlobalTestEnvironment().
|
||||
|
||||
|
@ -37,29 +37,20 @@
|
||||
#include <string.h>
|
||||
#include <algorithm>
|
||||
#include <deque>
|
||||
#include <forward_list>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "gtest/gtest-printers.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#if GTEST_HAS_UNORDERED_MAP_
|
||||
# include <unordered_map> // NOLINT
|
||||
#endif // GTEST_HAS_UNORDERED_MAP_
|
||||
|
||||
#if GTEST_HAS_UNORDERED_SET_
|
||||
# include <unordered_set> // NOLINT
|
||||
#endif // GTEST_HAS_UNORDERED_SET_
|
||||
|
||||
#if GTEST_HAS_STD_FORWARD_LIST_
|
||||
# include <forward_list> // NOLINT
|
||||
#endif // GTEST_HAS_STD_FORWARD_LIST_
|
||||
|
||||
// Some user-defined types for testing the universal value printer.
|
||||
|
||||
// An anonymous enum type.
|
||||
@ -192,8 +183,14 @@ class PathLike {
|
||||
public:
|
||||
struct iterator {
|
||||
typedef PathLike value_type;
|
||||
|
||||
iterator& operator++();
|
||||
PathLike& operator*();
|
||||
};
|
||||
|
||||
using value_type = char;
|
||||
using const_iterator = iterator;
|
||||
|
||||
PathLike() {}
|
||||
|
||||
iterator begin() const { return iterator(); }
|
||||
@ -814,7 +811,6 @@ TEST(PrintStlContainerTest, NonEmptyDeque) {
|
||||
EXPECT_EQ("{ 1, 3 }", Print(non_empty));
|
||||
}
|
||||
|
||||
#if GTEST_HAS_UNORDERED_MAP_
|
||||
|
||||
TEST(PrintStlContainerTest, OneElementHashMap) {
|
||||
::std::unordered_map<int, char> map1;
|
||||
@ -834,9 +830,7 @@ TEST(PrintStlContainerTest, HashMultiMap) {
|
||||
<< " where Print(map1) returns \"" << result << "\".";
|
||||
}
|
||||
|
||||
#endif // GTEST_HAS_UNORDERED_MAP_
|
||||
|
||||
#if GTEST_HAS_UNORDERED_SET_
|
||||
|
||||
TEST(PrintStlContainerTest, HashSet) {
|
||||
::std::unordered_set<int> set1;
|
||||
@ -873,7 +867,6 @@ TEST(PrintStlContainerTest, HashMultiSet) {
|
||||
EXPECT_TRUE(std::equal(a, a + kSize, numbers.begin()));
|
||||
}
|
||||
|
||||
#endif // GTEST_HAS_UNORDERED_SET_
|
||||
|
||||
TEST(PrintStlContainerTest, List) {
|
||||
const std::string a[] = {"hello", "world"};
|
||||
@ -915,14 +908,12 @@ TEST(PrintStlContainerTest, MultiSet) {
|
||||
EXPECT_EQ("{ 1, 1, 1, 2, 5 }", Print(set1));
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_FORWARD_LIST_
|
||||
|
||||
TEST(PrintStlContainerTest, SinglyLinkedList) {
|
||||
int a[] = { 9, 2, 8 };
|
||||
const std::forward_list<int> ints(a, a + 3);
|
||||
EXPECT_EQ("{ 9, 2, 8 }", Print(ints));
|
||||
}
|
||||
#endif // GTEST_HAS_STD_FORWARD_LIST_
|
||||
|
||||
TEST(PrintStlContainerTest, Pair) {
|
||||
pair<const bool, int> p(true, 5);
|
||||
|
@ -227,6 +227,4 @@ TEST_F(TestPartResultArrayDeathTest, DiesWhenIndexIsOutOfBound) {
|
||||
EXPECT_DEATH_IF_SUPPORTED(results.GetTestPartResult(1), "");
|
||||
}
|
||||
|
||||
// FIXME: Add a test for the class HasNewFatalFailureHelper.
|
||||
|
||||
} // namespace
|
||||
|
@ -73,8 +73,7 @@ def Run(command):
|
||||
return p.exited and p.exit_code == 0
|
||||
|
||||
|
||||
# The tests. FIXME: refactor the class to share common
|
||||
# logic with code in googletest-break-on-failure-unittest.py.
|
||||
# The tests.
|
||||
class ThrowOnFailureTest(gtest_test_utils.TestCase):
|
||||
"""Tests the throw-on-failure mode."""
|
||||
|
||||
|
@ -249,7 +249,7 @@ TEST_F(TypedTestCasePStateDeathTest, DetectsDuplicates) {
|
||||
TEST_F(TypedTestCasePStateDeathTest, DetectsExtraTest) {
|
||||
EXPECT_DEATH_IF_SUPPORTED(
|
||||
state_.VerifyRegisteredTestNames("foo.cc", 1, "A, B, C, D"),
|
||||
"foo\\.cc.1.?: No test named D can be found in this test case\\.");
|
||||
"foo\\.cc.1.?: No test named D can be found in this test suite\\.");
|
||||
}
|
||||
|
||||
TEST_F(TypedTestCasePStateDeathTest, DetectsMissedTest) {
|
||||
@ -264,7 +264,7 @@ TEST_F(TypedTestCasePStateDeathTest, DetectsTestAfterRegistration) {
|
||||
state_.VerifyRegisteredTestNames("foo.cc", 1, "A, B, C");
|
||||
EXPECT_DEATH_IF_SUPPORTED(
|
||||
state_.AddTestName("foo.cc", 2, "FooTest", "D"),
|
||||
"foo\\.cc.2.?: Test D must be defined before REGISTER_TYPED_TEST_CASE_P"
|
||||
"foo\\.cc.2.?: Test D must be defined before REGISTER_TYPED_TEST_SUITE_P"
|
||||
"\\(FooTest, \\.\\.\\.\\)\\.");
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,6 @@ TEST(Test, Test) {
|
||||
int kTestForContinuingTest = 0;
|
||||
|
||||
TEST(Test, Test2) {
|
||||
// FIXME: how to force Test2 to be after Test?
|
||||
kTestForContinuingTest = 1;
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This file is AUTOMATICALLY GENERATED on 01/02/2018 by command
|
||||
// This file is AUTOMATICALLY GENERATED on 01/02/2019 by command
|
||||
// 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
|
||||
|
||||
// Regression test for gtest_pred_impl.h
|
||||
|
@ -117,7 +117,6 @@ const int kNumberOfParamTests = 10;
|
||||
class MyParamTest : public testing::TestWithParam<int> {};
|
||||
|
||||
TEST_P(MyParamTest, ShouldPass) {
|
||||
// FIXME: Make parameter value checking robust WRT order of tests.
|
||||
GTEST_CHECK_INT_EQ_(g_param_test_count % kNumberOfParamTests, GetParam());
|
||||
g_param_test_count++;
|
||||
}
|
||||
|
@ -307,8 +307,6 @@ def Main():
|
||||
_ParseAndStripGTestFlags(sys.argv)
|
||||
# The tested binaries should not be writing XML output files unless the
|
||||
# script explicitly instructs them to.
|
||||
# FIXME: Move this into Subprocess when we implement
|
||||
# passing environment into it as a parameter.
|
||||
if GTEST_OUTPUT_VAR_NAME in os.environ:
|
||||
del os.environ[GTEST_OUTPUT_VAR_NAME]
|
||||
|
||||
|
@ -511,8 +511,6 @@ TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsEpochStart) {
|
||||
EXPECT_EQ("1970-01-01T00:00:00", FormatEpochTimeInMillisAsIso8601(0));
|
||||
}
|
||||
|
||||
#if GTEST_CAN_COMPARE_NULL
|
||||
|
||||
# ifdef __BORLANDC__
|
||||
// Silences warnings: "Condition is always true", "Unreachable code"
|
||||
# pragma option push -w-ccc -w-rch
|
||||
@ -541,7 +539,6 @@ TEST(NullLiteralTest, IsFalseForNonNullLiterals) {
|
||||
# pragma option pop
|
||||
# endif
|
||||
|
||||
#endif // GTEST_CAN_COMPARE_NULL
|
||||
//
|
||||
// Tests CodePointToUtf8().
|
||||
|
||||
@ -586,7 +583,7 @@ TEST(CodePointToUtf8Test, CanEncode12To16Bits) {
|
||||
|
||||
#if !GTEST_WIDE_STRING_USES_UTF16_
|
||||
// Tests in this group require a wchar_t to hold > 16 bits, and thus
|
||||
// are skipped on Windows, Cygwin, and Symbian, where a wchar_t is
|
||||
// are skipped on Windows, and Cygwin, where a wchar_t is
|
||||
// 16-bit wide. This code may not compile on those systems.
|
||||
|
||||
// Tests that Unicode code-points that have 17 to 21 bits are encoded
|
||||
@ -2360,6 +2357,16 @@ TEST(PredTest, SingleEvaluationOnFailure) {
|
||||
EXPECT_EQ(1, n4) << "Argument 4 is not evaluated exactly once.";
|
||||
}
|
||||
|
||||
// Test predicate assertions for sets
|
||||
TEST(PredTest, ExpectPredEvalFailure) {
|
||||
std::set<int> set_a = {2, 1, 3, 4, 5};
|
||||
std::set<int> set_b = {0, 4, 8};
|
||||
const auto compare_sets = [] (std::set<int>, std::set<int>) { return false; };
|
||||
EXPECT_NONFATAL_FAILURE(
|
||||
EXPECT_PRED2(compare_sets, set_a, set_b),
|
||||
"compare_sets(set_a, set_b) evaluates to false, where\nset_a evaluates "
|
||||
"to { 1, 2, 3, 4, 5 }\nset_b evaluates to { 0, 4, 8 }");
|
||||
}
|
||||
|
||||
// Some helper functions for testing using overloaded/template
|
||||
// functions with ASSERT_PREDn and EXPECT_PREDn.
|
||||
@ -2822,8 +2829,6 @@ TEST_F(FloatTest, LargeDiff) {
|
||||
TEST_F(FloatTest, Infinity) {
|
||||
EXPECT_FLOAT_EQ(values_.infinity, values_.close_to_infinity);
|
||||
EXPECT_FLOAT_EQ(-values_.infinity, -values_.close_to_infinity);
|
||||
#if !GTEST_OS_SYMBIAN
|
||||
// Nokia's STLport crashes if we try to output infinity or NaN.
|
||||
EXPECT_NONFATAL_FAILURE(EXPECT_FLOAT_EQ(values_.infinity, -values_.infinity),
|
||||
"-values_.infinity");
|
||||
|
||||
@ -2831,14 +2836,10 @@ TEST_F(FloatTest, Infinity) {
|
||||
// are only 1 DLP apart.
|
||||
EXPECT_NONFATAL_FAILURE(EXPECT_FLOAT_EQ(values_.infinity, values_.nan1),
|
||||
"values_.nan1");
|
||||
#endif // !GTEST_OS_SYMBIAN
|
||||
}
|
||||
|
||||
// Tests that comparing with NAN always returns false.
|
||||
TEST_F(FloatTest, NaN) {
|
||||
#if !GTEST_OS_SYMBIAN
|
||||
// Nokia's STLport crashes if we try to output infinity or NaN.
|
||||
|
||||
// In C++Builder, names within local classes (such as used by
|
||||
// EXPECT_FATAL_FAILURE) cannot be resolved against static members of the
|
||||
// scoping class. Use a static local alias as a workaround.
|
||||
@ -2856,7 +2857,6 @@ TEST_F(FloatTest, NaN) {
|
||||
|
||||
EXPECT_FATAL_FAILURE(ASSERT_FLOAT_EQ(v.nan1, v.infinity),
|
||||
"v.infinity");
|
||||
#endif // !GTEST_OS_SYMBIAN
|
||||
}
|
||||
|
||||
// Tests that *_FLOAT_EQ are reflexive.
|
||||
@ -2918,10 +2918,6 @@ TEST_F(FloatTest, FloatLEFails) {
|
||||
EXPECT_PRED_FORMAT2(FloatLE, values_.further_from_one, 1.0f);
|
||||
}, "(values_.further_from_one) <= (1.0f)");
|
||||
|
||||
#if !GTEST_OS_SYMBIAN && !defined(__BORLANDC__)
|
||||
// Nokia's STLport crashes if we try to output infinity or NaN.
|
||||
// C++Builder gives bad results for ordered comparisons involving NaNs
|
||||
// due to compiler bugs.
|
||||
EXPECT_NONFATAL_FAILURE({ // NOLINT
|
||||
EXPECT_PRED_FORMAT2(FloatLE, values_.nan1, values_.infinity);
|
||||
}, "(values_.nan1) <= (values_.infinity)");
|
||||
@ -2931,7 +2927,6 @@ TEST_F(FloatTest, FloatLEFails) {
|
||||
EXPECT_FATAL_FAILURE({ // NOLINT
|
||||
ASSERT_PRED_FORMAT2(FloatLE, values_.nan1, values_.nan1);
|
||||
}, "(values_.nan1) <= (values_.nan1)");
|
||||
#endif // !GTEST_OS_SYMBIAN && !defined(__BORLANDC__)
|
||||
}
|
||||
|
||||
// Instantiates FloatingPointTest for testing *_DOUBLE_EQ.
|
||||
@ -2995,8 +2990,6 @@ TEST_F(DoubleTest, LargeDiff) {
|
||||
TEST_F(DoubleTest, Infinity) {
|
||||
EXPECT_DOUBLE_EQ(values_.infinity, values_.close_to_infinity);
|
||||
EXPECT_DOUBLE_EQ(-values_.infinity, -values_.close_to_infinity);
|
||||
#if !GTEST_OS_SYMBIAN
|
||||
// Nokia's STLport crashes if we try to output infinity or NaN.
|
||||
EXPECT_NONFATAL_FAILURE(EXPECT_DOUBLE_EQ(values_.infinity, -values_.infinity),
|
||||
"-values_.infinity");
|
||||
|
||||
@ -3004,18 +2997,10 @@ TEST_F(DoubleTest, Infinity) {
|
||||
// are only 1 DLP apart.
|
||||
EXPECT_NONFATAL_FAILURE(EXPECT_DOUBLE_EQ(values_.infinity, values_.nan1),
|
||||
"values_.nan1");
|
||||
#endif // !GTEST_OS_SYMBIAN
|
||||
}
|
||||
|
||||
// Tests that comparing with NAN always returns false.
|
||||
TEST_F(DoubleTest, NaN) {
|
||||
#if !GTEST_OS_SYMBIAN
|
||||
// In C++Builder, names within local classes (such as used by
|
||||
// EXPECT_FATAL_FAILURE) cannot be resolved against static members of the
|
||||
// scoping class. Use a static local alias as a workaround.
|
||||
// We use the assignment syntax since some compilers, like Sun Studio,
|
||||
// don't allow initializing references using construction syntax
|
||||
// (parentheses).
|
||||
static const DoubleTest::TestValues& v = this->values_;
|
||||
|
||||
// Nokia's STLport crashes if we try to output infinity or NaN.
|
||||
@ -3025,17 +3010,13 @@ TEST_F(DoubleTest, NaN) {
|
||||
EXPECT_NONFATAL_FAILURE(EXPECT_DOUBLE_EQ(1.0, v.nan1), "v.nan1");
|
||||
EXPECT_FATAL_FAILURE(ASSERT_DOUBLE_EQ(v.nan1, v.infinity),
|
||||
"v.infinity");
|
||||
#endif // !GTEST_OS_SYMBIAN
|
||||
}
|
||||
|
||||
// Tests that *_DOUBLE_EQ are reflexive.
|
||||
TEST_F(DoubleTest, Reflexive) {
|
||||
EXPECT_DOUBLE_EQ(0.0, 0.0);
|
||||
EXPECT_DOUBLE_EQ(1.0, 1.0);
|
||||
#if !GTEST_OS_SYMBIAN
|
||||
// Nokia's STLport crashes if we try to output infinity or NaN.
|
||||
ASSERT_DOUBLE_EQ(values_.infinity, values_.infinity);
|
||||
#endif // !GTEST_OS_SYMBIAN
|
||||
}
|
||||
|
||||
// Tests that *_DOUBLE_EQ are commutative.
|
||||
@ -3090,10 +3071,6 @@ TEST_F(DoubleTest, DoubleLEFails) {
|
||||
EXPECT_PRED_FORMAT2(DoubleLE, values_.further_from_one, 1.0);
|
||||
}, "(values_.further_from_one) <= (1.0)");
|
||||
|
||||
#if !GTEST_OS_SYMBIAN && !defined(__BORLANDC__)
|
||||
// Nokia's STLport crashes if we try to output infinity or NaN.
|
||||
// C++Builder gives bad results for ordered comparisons involving NaNs
|
||||
// due to compiler bugs.
|
||||
EXPECT_NONFATAL_FAILURE({ // NOLINT
|
||||
EXPECT_PRED_FORMAT2(DoubleLE, values_.nan1, values_.infinity);
|
||||
}, "(values_.nan1) <= (values_.infinity)");
|
||||
@ -3103,7 +3080,6 @@ TEST_F(DoubleTest, DoubleLEFails) {
|
||||
EXPECT_FATAL_FAILURE({ // NOLINT
|
||||
ASSERT_PRED_FORMAT2(DoubleLE, values_.nan1, values_.nan1);
|
||||
}, "(values_.nan1) <= (values_.nan1)");
|
||||
#endif // !GTEST_OS_SYMBIAN && !defined(__BORLANDC__)
|
||||
}
|
||||
|
||||
|
||||
@ -3711,7 +3687,6 @@ TEST(AssertionTest, ASSERT_EQ) {
|
||||
}
|
||||
|
||||
// Tests ASSERT_EQ(NULL, pointer).
|
||||
#if GTEST_CAN_COMPARE_NULL
|
||||
TEST(AssertionTest, ASSERT_EQ_NULL) {
|
||||
// A success.
|
||||
const char* p = nullptr;
|
||||
@ -3725,7 +3700,6 @@ TEST(AssertionTest, ASSERT_EQ_NULL) {
|
||||
static int n = 0;
|
||||
EXPECT_FATAL_FAILURE(ASSERT_EQ(nullptr, &n), " &n\n Which is:");
|
||||
}
|
||||
#endif // GTEST_CAN_COMPARE_NULL
|
||||
|
||||
// Tests ASSERT_EQ(0, non_pointer). Since the literal 0 can be
|
||||
// treated as a null pointer by the compiler, we need to make sure
|
||||
@ -3916,11 +3890,8 @@ TEST(AssertionTest, NamedEnum) {
|
||||
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(kE1, kE2), "Which is: 1");
|
||||
}
|
||||
|
||||
// The version of gcc used in XCode 2.2 has a bug and doesn't allow
|
||||
// anonymous enums in assertions. Therefore the following test is not
|
||||
// done on Mac.
|
||||
// Sun Studio and HP aCC also reject this code.
|
||||
#if !GTEST_OS_MAC && !defined(__SUNPRO_CC) && !defined(__HP_aCC)
|
||||
// Sun Studio and HP aCC2reject this code.
|
||||
#if !defined(__SUNPRO_CC) && !defined(__HP_aCC)
|
||||
|
||||
// Tests using assertions with anonymous enums.
|
||||
enum {
|
||||
@ -4439,7 +4410,6 @@ TEST(ExpectTest, EXPECT_EQ_Double) {
|
||||
"5.1");
|
||||
}
|
||||
|
||||
#if GTEST_CAN_COMPARE_NULL
|
||||
// Tests EXPECT_EQ(NULL, pointer).
|
||||
TEST(ExpectTest, EXPECT_EQ_NULL) {
|
||||
// A success.
|
||||
@ -4454,7 +4424,6 @@ TEST(ExpectTest, EXPECT_EQ_NULL) {
|
||||
int n = 0;
|
||||
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(nullptr, &n), " &n\n Which is:");
|
||||
}
|
||||
#endif // GTEST_CAN_COMPARE_NULL
|
||||
|
||||
// Tests EXPECT_EQ(0, non_pointer). Since the literal 0 can be
|
||||
// treated as a null pointer by the compiler, we need to make sure
|
||||
@ -5472,6 +5441,67 @@ TEST_F(SetUpTestCaseTest, Test2) {
|
||||
EXPECT_STREQ("123", shared_resource_);
|
||||
}
|
||||
|
||||
// Tests SetupTestSuite/TearDown TestSuite API
|
||||
class SetUpTestSuiteTest : public Test {
|
||||
protected:
|
||||
// This will be called once before the first test in this test case
|
||||
// is run.
|
||||
static void SetUpTestSuite() {
|
||||
printf("Setting up the test suite . . .\n");
|
||||
|
||||
// Initializes some shared resource. In this simple example, we
|
||||
// just create a C string. More complex stuff can be done if
|
||||
// desired.
|
||||
shared_resource_ = "123";
|
||||
|
||||
// Increments the number of test cases that have been set up.
|
||||
counter_++;
|
||||
|
||||
// SetUpTestSuite() should be called only once.
|
||||
EXPECT_EQ(1, counter_);
|
||||
}
|
||||
|
||||
// This will be called once after the last test in this test case is
|
||||
// run.
|
||||
static void TearDownTestSuite() {
|
||||
printf("Tearing down the test suite . . .\n");
|
||||
|
||||
// Decrements the number of test suites that have been set up.
|
||||
counter_--;
|
||||
|
||||
// TearDownTestSuite() should be called only once.
|
||||
EXPECT_EQ(0, counter_);
|
||||
|
||||
// Cleans up the shared resource.
|
||||
shared_resource_ = nullptr;
|
||||
}
|
||||
|
||||
// This will be called before each test in this test case.
|
||||
void SetUp() override {
|
||||
// SetUpTestSuite() should be called only once, so counter_ should
|
||||
// always be 1.
|
||||
EXPECT_EQ(1, counter_);
|
||||
}
|
||||
|
||||
// Number of test suites that have been set up.
|
||||
static int counter_;
|
||||
|
||||
// Some resource to be shared by all tests in this test case.
|
||||
static const char* shared_resource_;
|
||||
};
|
||||
|
||||
int SetUpTestSuiteTest::counter_ = 0;
|
||||
const char* SetUpTestSuiteTest::shared_resource_ = nullptr;
|
||||
|
||||
// A test that uses the shared resource.
|
||||
TEST_F(SetUpTestSuiteTest, TestSetupTestSuite1) {
|
||||
EXPECT_STRNE(nullptr, shared_resource_);
|
||||
}
|
||||
|
||||
// Another test that uses the shared resource.
|
||||
TEST_F(SetUpTestSuiteTest, TestSetupTestSuite2) {
|
||||
EXPECT_STREQ("123", shared_resource_);
|
||||
}
|
||||
|
||||
// The ParseFlagsTest test case tests ParseGoogleTestFlagsOnly.
|
||||
|
||||
@ -7054,7 +7084,6 @@ GTEST_TEST(AlternativeNameTest, Works) { // GTEST_TEST is the same as TEST.
|
||||
|
||||
// Tests for internal utilities necessary for implementation of the universal
|
||||
// printing.
|
||||
// FIXME: Find a better home for them.
|
||||
|
||||
class ConversionHelperBase {};
|
||||
class ConversionHelperDerived : public ConversionHelperBase {};
|
||||
@ -7547,3 +7576,30 @@ TEST_F(AdHocTestResultTest, AdHocTestResultTestForUnitTestDoesNotShowFailure) {
|
||||
testing::UnitTest::GetInstance()->ad_hoc_test_result();
|
||||
EXPECT_FALSE(test_result.Failed());
|
||||
}
|
||||
|
||||
class DynamicUnitTestFixture : public testing::Test {};
|
||||
|
||||
class DynamicTest : public DynamicUnitTestFixture {
|
||||
void TestBody() override { EXPECT_TRUE(true); }
|
||||
};
|
||||
|
||||
auto* dynamic_test = testing::RegisterTest(
|
||||
"DynamicUnitTestFixture", "DynamicTest", "TYPE", "VALUE", __FILE__,
|
||||
__LINE__, []() -> DynamicUnitTestFixture* { return new DynamicTest; });
|
||||
|
||||
TEST(RegisterTest, WasRegistered) {
|
||||
auto* unittest = testing::UnitTest::GetInstance();
|
||||
for (int i = 0; i < unittest->total_test_case_count(); ++i) {
|
||||
auto* tests = unittest->GetTestCase(i);
|
||||
if (tests->name() != std::string("DynamicUnitTestFixture")) continue;
|
||||
for (int j = 0; j < tests->total_test_count(); ++j) {
|
||||
if (tests->GetTestInfo(j)->name() != std::string("DynamicTest")) continue;
|
||||
// Found it.
|
||||
EXPECT_STREQ(tests->GetTestInfo(j)->value_param(), "VALUE");
|
||||
EXPECT_STREQ(tests->GetTestInfo(j)->type_param(), "TYPE");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
FAIL() << "Didn't find the test!";
|
||||
}
|
||||
|
@ -111,11 +111,6 @@ class GTestXMLOutFilesTest(gtest_xml_test_utils.GTestXMLTestCase):
|
||||
self.assert_(p.exited)
|
||||
self.assertEquals(0, p.exit_code)
|
||||
|
||||
# FIXME: libtool causes the built test binary to be
|
||||
# named lt-gtest_xml_outfiles_test_ instead of
|
||||
# gtest_xml_outfiles_test_. To account for this possibility, we
|
||||
# allow both names in the following code. We should remove this
|
||||
# when libtool replacement tool is ready.
|
||||
output_file_name1 = test_name + ".xml"
|
||||
output_file1 = os.path.join(self.output_dir_, output_file_name1)
|
||||
output_file_name2 = 'lt-' + output_file_name1
|
||||
|
Loading…
Reference in New Issue
Block a user