diff options
22 files changed, 235 insertions, 492 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7e8b479..30c8d89 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -90,32 +90,40 @@ and their own tests from a git checkout, which has further requirements: * [Python](https://www.python.org/) v2.3 or newer (for running some of the tests and re-generating certain source files from templates) * [CMake](https://cmake.org/) v2.6.4 or newer -* [GNU Build System](https://en.wikipedia.org/wiki/GNU_Build_System) including - automake (>= 1.9), autoconf (>= 2.59), and libtool / libtoolize. -## Developing Google Test +## Developing Google Test and Google Mock -This section discusses how to make your own changes to Google Test. +This section discusses how to make your own changes to the Google Test project. -### Testing Google Test Itself +### Testing Google Test and Google Mock Themselves To make sure your changes work as intended and don't break existing -functionality, you'll want to compile and run Google Test's own tests. For that -you can use CMake: +functionality, you'll want to compile and run Google Test and GoogleMock's own +tests. For that you can use CMake: mkdir mybuild cd mybuild - cmake -Dgtest_build_tests=ON ${GTEST_DIR} + cmake -Dgtest_build_tests=ON -Dgmock_build_tests=ON ${GTEST_REPO_DIR} + +To choose between building only Google Test or Google Mock, you may modify your +cmake command to be one of each + + cmake -Dgtest_build_tests=ON ${GTEST_DIR} # sets up Google Test tests + cmake -Dgmock_build_tests=ON ${GMOCK_DIR} # sets up Google Mock tests Make sure you have Python installed, as some of Google Test's tests are written in Python. If the cmake command complains about not being able to find Python (`Could NOT find PythonInterp (missing: PYTHON_EXECUTABLE)`), try telling it explicitly where your Python executable can be found: - cmake -DPYTHON_EXECUTABLE=path/to/python -Dgtest_build_tests=ON ${GTEST_DIR} + cmake -DPYTHON_EXECUTABLE=path/to/python ... + +Next, you can build Google Test and / or Google Mock and all desired tests. On +\*nix, this is usually done by + + make -Next, you can build Google Test and all of its own tests. On \*nix, this is -usually done by 'make'. To run the tests, do +To run the tests, do make test @@ -132,27 +140,3 @@ You don't need to worry about regenerating the source files unless you need to modify them. You would then modify the corresponding `.pump` files and run the '[pump.py](googletest/scripts/pump.py)' generator script. See the [Pump Manual](googletest/docs/pump_manual.md). - -## Developing Google Mock - -This section discusses how to make your own changes to Google Mock. - -#### Testing Google Mock Itself - -To make sure your changes work as intended and don't break existing -functionality, you'll want to compile and run Google Test's own tests. For that -you'll need Autotools. First, make sure you have followed the instructions above -to configure Google Mock. Then, create a build output directory and enter it. -Next, - - ${GMOCK_DIR}/configure # try --help for more info - -Once you have successfully configured Google Mock, the build steps are standard -for GNU-style OSS packages. - - make # Standard makefile following GNU conventions - make check # Builds and runs all tests - all should pass. - -Note that when building your project against Google Mock, you are building -against Google Test as well. There is no need to configure Google Test -separately. diff --git a/googlemock/docs/cheat_sheet.md b/googlemock/docs/cheat_sheet.md index 2040056..850963a 100644 --- a/googlemock/docs/cheat_sheet.md +++ b/googlemock/docs/cheat_sheet.md @@ -202,6 +202,15 @@ EXPECT_CALL(mock-object, method (matchers)?) .RetiresOnSaturation(); ? ``` +For each item above, `?` means it can be used at most once, while `*` means it +can be used any number of times. + +In order to pass, `EXPECT_CALL` must be used before the calls are actually made. + +The `(matchers)` is a comma-separated list of matchers that correspond to each +of the arguments of `method`, and sets the expectation only for calls of +`method` that matches all of the matchers. + If `(matchers)` is omitted, the expectation is the same as if the matchers were set to anything matchers (for example, `(_, _, _, _)` for a four-arg method). @@ -221,17 +230,19 @@ and the default action will be taken each time. <!-- GOOGLETEST_CM0020 DO NOT DELETE --> A **matcher** matches a *single* argument. You can use it inside `ON_CALL()` or -`EXPECT_CALL()`, or use it to validate a value directly: +`EXPECT_CALL()`, or use it to validate a value directly using two macros: <!-- mdformat off(github rendering does not support multiline tables) --> -| Matcher | Description | +| Macro | Description | | :----------------------------------- | :------------------------------------ | | `EXPECT_THAT(actual_value, matcher)` | Asserts that `actual_value` matches `matcher`. | | `ASSERT_THAT(actual_value, matcher)` | The same as `EXPECT_THAT(actual_value, matcher)`, except that it generates a **fatal** failure. | <!-- mdformat on --> -Built-in matchers (where `argument` is the function argument) are divided into -several categories: +Built-in matchers (where `argument` is the function argument, e.g. +`actual_value` in the example above, or when used in the context of +`EXPECT_CALL(mock_object, method(matchers))`, the arguments of `method`) are +divided into several categories: #### Wildcard @@ -251,6 +262,8 @@ Matcher | Description | `Le(value)` | `argument <= value` | | `Lt(value)` | `argument < value` | | `Ne(value)` | `argument != value` | +| `IsFalse()` | `argument` evaluates to `false` in a Boolean context. | +| `IsTrue()` | `argument` evaluates to `true` in a Boolean context. | | `IsNull()` | `argument` is a `NULL` pointer (raw or smart). | | `NotNull()` | `argument` is a non-null pointer (raw or smart). | | `Optional(m)` | `argument` is `optional<>` that contains a value matching `m`. | @@ -333,10 +346,8 @@ messages, you can use: | `ElementsAre(e0, e1, ..., en)` | `argument` has `n + 1` elements, where the *i*-th element matches `ei`, which can be a value or a matcher. | | `ElementsAreArray({e0, e1, ..., en})`, `ElementsAreArray(a_container)`, `ElementsAreArray(begin, end)`, `ElementsAreArray(array)`, or `ElementsAreArray(array, count)` | The same as `ElementsAre()` except that the expected element values/matchers come from an initializer list, STL-style container, iterator range, or C-style array. | | `IsEmpty()` | `argument` is an empty container (`container.empty()`). | -| `IsFalse()` | `argument` evaluates to `false` in a Boolean context. | | `IsSubsetOf({e0, e1, ..., en})`, `IsSubsetOf(a_container)`, `IsSubsetOf(begin, end)`, `IsSubsetOf(array)`, or `IsSubsetOf(array, count)` | `argument` matches `UnorderedElementsAre(x0, x1, ..., xk)` for some subset `{x0, x1, ..., xk}` of the expected matchers. | | `IsSupersetOf({e0, e1, ..., en})`, `IsSupersetOf(a_container)`, `IsSupersetOf(begin, end)`, `IsSupersetOf(array)`, or `IsSupersetOf(array, count)` | Some subset of `argument` matches `UnorderedElementsAre(`expected matchers`)`. | -| `IsTrue()` | `argument` evaluates to `true` in a Boolean context. | | `Pointwise(m, container)`, `Pointwise(m, {e0, e1, ..., en})` | `argument` contains the same number of elements as in `container`, and for all i, (the i-th element in `argument`, the i-th element in `container`) match `m`, which is a matcher on 2-tuples. E.g. `Pointwise(Le(), upper_bounds)` verifies that each element in `argument` doesn't exceed the corresponding element in `upper_bounds`. See more detail below. | | `SizeIs(m)` | `argument` is a container whose size matches `m`. E.g. `SizeIs(2)` or `SizeIs(Lt(2))`. | | `UnorderedElementsAre(e0, e1, ..., en)` | `argument` has `n + 1` elements, and under *some* permutation of the elements, each element matches an `ei` (for a different `i`), which can be a value or a matcher. | diff --git a/googlemock/docs/cook_book.md b/googlemock/docs/cook_book.md index 43bc41a..3a3308e 100644 --- a/googlemock/docs/cook_book.md +++ b/googlemock/docs/cook_book.md @@ -1271,8 +1271,7 @@ the pointer itself, has a certain property? Well, you can use the `Pointee(m)` matcher. `Pointee(m)` matches a pointer if and only if `m` matches the value the pointer -points to. -For example: +points to. For example: ```cpp using ::testing::Ge; diff --git a/googlemock/docs/for_dummies.md b/googlemock/docs/for_dummies.md index 0e7db8d..e11c18d 100644 --- a/googlemock/docs/for_dummies.md +++ b/googlemock/docs/for_dummies.md @@ -483,7 +483,7 @@ the *default* action for the function every time (unless, of course, you have a What can we do inside `WillOnce()` besides `Return()`? You can return a reference using `ReturnRef(*variable*)`, or invoke a pre-defined function, among -[others](#ActionList). +[others](cook_book.md#using-actions). **Important note:** The `EXPECT_CALL()` statement evaluates the action clause only once, even though the action may be performed many times. Therefore you @@ -561,7 +561,7 @@ overloaded). This makes any calls to the method expected. This is not necessary for methods that are not mentioned at all (these are "uninteresting"), but is useful for methods that have some expectations, but for which other calls are ok. See -[Understanding Uninteresting vs Unexpected Calls](#uninteresting-vs-unexpected). +[Understanding Uninteresting vs Unexpected Calls](cook_book.md#uninteresting-vs-unexpected). #### Ordered vs Unordered Calls {#OrderedCalls} diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index c946271..f12d39b 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -620,7 +620,7 @@ class ReturnVoidAction { // Allows Return() to be used in any void-returning function. template <typename Result, typename ArgumentTuple> static void Perform(const ArgumentTuple&) { - CompileAssertTypesEqual<void, Result>(); + static_assert(std::is_void<Result>::value, "Result should be void."); } }; @@ -843,7 +843,7 @@ class IgnoreResultAction { typedef typename internal::Function<F>::Result Result; // Asserts at compile time that F returns void. - CompileAssertTypesEqual<void, Result>(); + static_assert(std::is_void<Result>::value, "Result type should be void."); return Action<F>(new Impl<F>(action_)); } diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index a6a63f1..ad16687 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -132,19 +132,16 @@ class MatcherCastImpl { // polymorphic_matcher_or_value to Matcher<T> because it won't trigger // a user-defined conversion from M to T if one exists (assuming M is // a value). - return CastImpl( - polymorphic_matcher_or_value, - BooleanConstant< - std::is_convertible<M, Matcher<T> >::value>(), - BooleanConstant< - std::is_convertible<M, T>::value>()); + return CastImpl(polymorphic_matcher_or_value, + std::is_convertible<M, Matcher<T>>{}, + std::is_convertible<M, T>{}); } private: template <bool Ignore> static Matcher<T> CastImpl(const M& polymorphic_matcher_or_value, - BooleanConstant<true> /* convertible_to_matcher */, - BooleanConstant<Ignore>) { + std::true_type /* convertible_to_matcher */, + bool_constant<Ignore>) { // M is implicitly convertible to Matcher<T>, which means that either // M is a polymorphic matcher or Matcher<T> has an implicit constructor // from M. In both cases using the implicit conversion will produce a @@ -159,9 +156,9 @@ class MatcherCastImpl { // M can't be implicitly converted to Matcher<T>, so M isn't a polymorphic // matcher. It's a value of a type implicitly convertible to T. Use direct // initialization to create a matcher. - static Matcher<T> CastImpl( - const M& value, BooleanConstant<false> /* convertible_to_matcher */, - BooleanConstant<true> /* convertible_to_T */) { + static Matcher<T> CastImpl(const M& value, + std::false_type /* convertible_to_matcher */, + std::true_type /* convertible_to_T */) { return Matcher<T>(ImplicitCast_<T>(value)); } @@ -175,9 +172,9 @@ class MatcherCastImpl { // (e.g. std::pair<const int, int> vs. std::pair<int, int>). // // We don't define this method inline as we need the declaration of Eq(). - static Matcher<T> CastImpl( - const M& value, BooleanConstant<false> /* convertible_to_matcher */, - BooleanConstant<false> /* convertible_to_T */); + static Matcher<T> CastImpl(const M& value, + std::false_type /* convertible_to_matcher */, + std::false_type /* convertible_to_T */); }; // This more specialized version is used when MatcherCast()'s argument @@ -1610,8 +1607,8 @@ class PointeeMatcher { template <typename Pointer> class Impl : public MatcherInterface<Pointer> { public: - typedef typename PointeeOf<GTEST_REMOVE_CONST_( // NOLINT - GTEST_REMOVE_REFERENCE_(Pointer))>::type Pointee; + typedef typename PointeeOf<typename std::remove_const< + typename std::remove_reference<Pointer>::type>::type>::type Pointee; explicit Impl(const InnerMatcher& matcher) : matcher_(MatcherCast<const Pointee&>(matcher)) {} @@ -1749,8 +1746,8 @@ class FieldMatcher { // FIXME: The dispatch on std::is_pointer was introduced as a workaround for // a compiler bug, and can now be removed. return MatchAndExplainImpl( - typename std::is_pointer<GTEST_REMOVE_CONST_(T)>::type(), value, - listener); + typename std::is_pointer<typename std::remove_const<T>::type>::type(), + value, listener); } private: @@ -1816,8 +1813,8 @@ class PropertyMatcher { template <typename T> bool MatchAndExplain(const T&value, MatchResultListener* listener) const { return MatchAndExplainImpl( - typename std::is_pointer<GTEST_REMOVE_CONST_(T)>::type(), value, - listener); + typename std::is_pointer<typename std::remove_const<T>::type>::type(), + value, listener); } private: @@ -2093,9 +2090,8 @@ class ContainerEqMatcher { template <typename LhsContainer> bool MatchAndExplain(const LhsContainer& lhs, MatchResultListener* listener) const { - // GTEST_REMOVE_CONST_() is needed to work around an MSVC 8.0 bug - // that causes LhsContainer to be a const type sometimes. - typedef internal::StlContainerView<GTEST_REMOVE_CONST_(LhsContainer)> + typedef internal::StlContainerView< + typename std::remove_const<LhsContainer>::type> LhsView; typedef typename LhsView::type LhsStlContainer; StlContainerReference lhs_stl_container = LhsView::ConstReference(lhs); @@ -3604,9 +3600,8 @@ inline Matcher<T> An() { return A<T>(); } template <typename T, typename M> Matcher<T> internal::MatcherCastImpl<T, M>::CastImpl( - const M& value, - internal::BooleanConstant<false> /* convertible_to_matcher */, - internal::BooleanConstant<false> /* convertible_to_T */) { + const M& value, std::false_type /* convertible_to_matcher */, + std::false_type /* convertible_to_T */) { return Eq(value); } @@ -4034,12 +4029,12 @@ BeginEndDistanceIs(const DistanceMatcher& distance_matcher) { // values that are included in one container but not the other. (Duplicate // values and order differences are not explained.) template <typename Container> -inline PolymorphicMatcher<internal::ContainerEqMatcher< // NOLINT - GTEST_REMOVE_CONST_(Container)> > - ContainerEq(const Container& rhs) { +inline PolymorphicMatcher<internal::ContainerEqMatcher< + typename std::remove_const<Container>::type>> +ContainerEq(const Container& rhs) { // This following line is for working around a bug in MSVC 8.0, // which causes Container to be a const type sometimes. - typedef GTEST_REMOVE_CONST_(Container) RawContainer; + typedef typename std::remove_const<Container>::type RawContainer; return MakePolymorphicMatcher( internal::ContainerEqMatcher<RawContainer>(rhs)); } @@ -4072,12 +4067,12 @@ WhenSorted(const ContainerMatcher& container_matcher) { // LHS container and the RHS container respectively. template <typename TupleMatcher, typename Container> inline internal::PointwiseMatcher<TupleMatcher, - GTEST_REMOVE_CONST_(Container)> + typename std::remove_const<Container>::type> Pointwise(const TupleMatcher& tuple_matcher, const Container& rhs) { // This following line is for working around a bug in MSVC 8.0, // which causes Container to be a const type sometimes (e.g. when // rhs is a const int[]).. - typedef GTEST_REMOVE_CONST_(Container) RawContainer; + typedef typename std::remove_const<Container>::type RawContainer; return internal::PointwiseMatcher<TupleMatcher, RawContainer>( tuple_matcher, rhs); } @@ -4105,14 +4100,15 @@ inline internal::PointwiseMatcher<TupleMatcher, std::vector<T> > Pointwise( template <typename Tuple2Matcher, typename RhsContainer> inline internal::UnorderedElementsAreArrayMatcher< typename internal::BoundSecondMatcher< - Tuple2Matcher, typename internal::StlContainerView<GTEST_REMOVE_CONST_( - RhsContainer)>::type::value_type> > + Tuple2Matcher, + typename internal::StlContainerView< + typename std::remove_const<RhsContainer>::type>::type::value_type>> UnorderedPointwise(const Tuple2Matcher& tuple2_matcher, const RhsContainer& rhs_container) { // This following line is for working around a bug in MSVC 8.0, // which causes RhsContainer to be a const type sometimes (e.g. when // rhs_container is a const int[]). - typedef GTEST_REMOVE_CONST_(RhsContainer) RawRhsContainer; + typedef typename std::remove_const<RhsContainer>::type RawRhsContainer; // RhsView allows the same code to handle RhsContainer being a // STL-style container and it being a native C-style array. diff --git a/googlemock/include/gmock/gmock-spec-builders.h b/googlemock/include/gmock/gmock-spec-builders.h index 0a56d6d..80c13b5 100644 --- a/googlemock/include/gmock/gmock-spec-builders.h +++ b/googlemock/include/gmock/gmock-spec-builders.h @@ -1323,8 +1323,8 @@ class ReferenceOrValueWrapper { // Provides nondestructive access to the underlying value/reference. // Always returns a const reference (more precisely, - // const RemoveReference<T>&). The behavior of calling this after - // calling Unwrap on the same object is unspecified. + // const std::add_lvalue_reference<T>::type). The behavior of calling this + // after calling Unwrap on the same object is unspecified. const T& Peek() const { return value_; } diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index d187f08..e05b883 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -170,27 +170,27 @@ GMOCK_DECLARE_KIND_(long double, kFloatingPoint); // From, and kToKind is the kind of To; the value is // implementation-defined when the above pre-condition is violated. template <TypeKind kFromKind, typename From, TypeKind kToKind, typename To> -struct LosslessArithmeticConvertibleImpl : public false_type {}; +struct LosslessArithmeticConvertibleImpl : public std::false_type {}; // Converting bool to bool is lossless. template <> struct LosslessArithmeticConvertibleImpl<kBool, bool, kBool, bool> - : public true_type {}; // NOLINT + : public std::true_type {}; // Converting bool to any integer type is lossless. template <typename To> struct LosslessArithmeticConvertibleImpl<kBool, bool, kInteger, To> - : public true_type {}; // NOLINT + : public std::true_type {}; // Converting bool to any floating-point type is lossless. template <typename To> struct LosslessArithmeticConvertibleImpl<kBool, bool, kFloatingPoint, To> - : public true_type {}; // NOLINT + : public std::true_type {}; // Converting an integer to bool is lossy. template <typename From> struct LosslessArithmeticConvertibleImpl<kInteger, From, kBool, bool> - : public false_type {}; // NOLINT + : public std::false_type {}; // Converting an integer to another non-bool integer is lossless // if and only if the target type's range encloses the source type's range. @@ -211,17 +211,17 @@ struct LosslessArithmeticConvertibleImpl<kInteger, From, kInteger, To> // the format of a floating-point number is implementation-defined. template <typename From, typename To> struct LosslessArithmeticConvertibleImpl<kInteger, From, kFloatingPoint, To> - : public false_type {}; // NOLINT + : public std::false_type {}; // Converting a floating-point to bool is lossy. template <typename From> struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kBool, bool> - : public false_type {}; // NOLINT + : public std::false_type {}; // Converting a floating-point to an integer is lossy. template <typename From, typename To> struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kInteger, To> - : public false_type {}; // NOLINT + : public std::false_type {}; // Converting a floating-point to another floating-point is lossless // if and only if the target type is at least as big as the source type. @@ -336,23 +336,6 @@ GTEST_API_ WithoutMatchers GetWithoutMatchers(); // Type traits. -// remove_reference<T>::type removes the reference from type T, if any. -template <typename T> struct remove_reference { typedef T type; }; // NOLINT -template <typename T> struct remove_reference<T&> { typedef T type; }; // NOLINT - -// DecayArray<T>::type turns an array type U[N] to const U* and preserves -// other types. Useful for saving a copy of a function argument. -template <typename T> struct DecayArray { typedef T type; }; // NOLINT -template <typename T, size_t N> struct DecayArray<T[N]> { - typedef const T* type; -}; -// Sometimes people use arrays whose size is not available at the use site -// (e.g. extern const char kNamePrefix[]). This specialization covers that -// case. -template <typename T> struct DecayArray<T[]> { - typedef const T* type; -}; - // Disable MSVC warnings for infinite recursion, since in this case the // the recursion is unreachable. #ifdef _MSC_VER @@ -402,8 +385,8 @@ class StlContainerView { static const_reference ConstReference(const RawContainer& container) { // Ensures that RawContainer is not a const type. - testing::StaticAssertTypeEq<RawContainer, - GTEST_REMOVE_CONST_(RawContainer)>(); + testing::StaticAssertTypeEq< + RawContainer, typename std::remove_const<RawContainer>::type>(); return container; } static type Copy(const RawContainer& container) { return container; } @@ -413,7 +396,7 @@ class StlContainerView { template <typename Element, size_t N> class StlContainerView<Element[N]> { public: - typedef GTEST_REMOVE_CONST_(Element) RawElement; + typedef typename std::remove_const<Element>::type RawElement; typedef internal::NativeArray<RawElement> type; // NativeArray<T> can represent a native array either by value or by // reference (selected by a constructor argument), so 'const type' @@ -437,8 +420,8 @@ class StlContainerView<Element[N]> { template <typename ElementPointer, typename Size> class StlContainerView< ::std::tuple<ElementPointer, Size> > { public: - typedef GTEST_REMOVE_CONST_( - typename internal::PointeeOf<ElementPointer>::type) RawElement; + typedef typename std::remove_const< + typename internal::PointeeOf<ElementPointer>::type>::type RawElement; typedef internal::NativeArray<RawElement> type; typedef const type const_reference; @@ -470,28 +453,12 @@ struct RemoveConstFromKey<std::pair<const K, V> > { typedef std::pair<K, V> type; }; -// Mapping from booleans to types. Similar to boost::bool_<kValue> and -// std::integral_constant<bool, kValue>. -template <bool kValue> -struct BooleanConstant {}; - // Emit an assertion failure due to incorrect DoDefault() usage. Out-of-lined to // reduce code size. GTEST_API_ void IllegalDoDefault(const char* file, int line); -// Helper types for Apply() below. -template <size_t... Is> struct int_pack { typedef int_pack type; }; - -template <class Pack, size_t I> struct append; -template <size_t... Is, size_t I> -struct append<int_pack<Is...>, I> : int_pack<Is..., I> {}; - -template <size_t C> -struct make_int_pack : append<typename make_int_pack<C - 1>::type, C - 1> {}; -template <> struct make_int_pack<0> : int_pack<> {}; - template <typename F, typename Tuple, size_t... Idx> -auto ApplyImpl(F&& f, Tuple&& args, int_pack<Idx...>) -> decltype( +auto ApplyImpl(F&& f, Tuple&& args, IndexSequence<Idx...>) -> decltype( std::forward<F>(f)(std::get<Idx>(std::forward<Tuple>(args))...)) { return std::forward<F>(f)(std::get<Idx>(std::forward<Tuple>(args))...); } @@ -500,9 +467,9 @@ auto ApplyImpl(F&& f, Tuple&& args, int_pack<Idx...>) -> decltype( template <typename F, typename Tuple> auto Apply(F&& f, Tuple&& args) -> decltype(ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args), - make_int_pack<std::tuple_size<Tuple>::value>())) { + MakeIndexSequence<std::tuple_size<Tuple>::value>())) { return ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args), - make_int_pack<std::tuple_size<Tuple>::value>()); + MakeIndexSequence<std::tuple_size<Tuple>::value>()); } // Template struct Function<F>, where F must be a function type, contains diff --git a/googlemock/test/gmock-internal-utils_test.cc b/googlemock/test/gmock-internal-utils_test.cc index 67865c2..d000e69 100644 --- a/googlemock/test/gmock-internal-utils_test.cc +++ b/googlemock/test/gmock-internal-utils_test.cc @@ -33,17 +33,20 @@ // This file tests the internal utilities. #include "gmock/internal/gmock-internal-utils.h" + #include <stdlib.h> + #include <map> #include <memory> -#include <string> #include <sstream> +#include <string> #include <type_traits> #include <vector> + #include "gmock/gmock.h" #include "gmock/internal/gmock-port.h" -#include "gtest/gtest.h" #include "gtest/gtest-spi.h" +#include "gtest/gtest.h" // Indicates that this translation unit is part of Google Test's // implementation. It must come before gtest-internal-inl.h is @@ -122,15 +125,17 @@ TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameIsMixture) { } TEST(PointeeOfTest, WorksForSmartPointers) { - CompileAssertTypesEqual<int, PointeeOf<std::unique_ptr<int> >::type>(); - CompileAssertTypesEqual<std::string, - PointeeOf<std::shared_ptr<std::string> >::type>(); + EXPECT_TRUE( + (std::is_same<int, PointeeOf<std::unique_ptr<int>>::type>::value)); + EXPECT_TRUE( + (std::is_same<std::string, + PointeeOf<std::shared_ptr<std::string>>::type>::value)); } TEST(PointeeOfTest, WorksForRawPointers) { - CompileAssertTypesEqual<int, PointeeOf<int*>::type>(); - CompileAssertTypesEqual<const char, PointeeOf<const char*>::type>(); - CompileAssertTypesEqual<void, PointeeOf<void*>::type>(); + EXPECT_TRUE((std::is_same<int, PointeeOf<int*>::type>::value)); + EXPECT_TRUE((std::is_same<const char, PointeeOf<const char*>::type>::value)); + EXPECT_TRUE((std::is_void<PointeeOf<void*>::type>::value)); } TEST(GetRawPointerTest, WorksForSmartPointers) { @@ -503,26 +508,6 @@ TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) { TestLogWithSeverity("invalid", kWarning, true); } -#endif // GTEST_HAS_STREAM_REDIRECTION - -TEST(TypeTraitsTest, true_type) { - EXPECT_TRUE(true_type::value); -} - -TEST(TypeTraitsTest, false_type) { - EXPECT_FALSE(false_type::value); -} - -TEST(TypeTraitsTest, remove_reference) { - EXPECT_TRUE((std::is_same<char, remove_reference<char&>::type>::value)); - EXPECT_TRUE( - (std::is_same<const int, remove_reference<const int&>::type>::value)); - EXPECT_TRUE((std::is_same<int, remove_reference<int>::type>::value)); - EXPECT_TRUE((std::is_same<double*, remove_reference<double*>::type>::value)); -} - -#if GTEST_HAS_STREAM_REDIRECTION - // Verifies that Log() behaves correctly for the given verbosity level // and log severity. std::string GrabOutput(void(*logger)(), const char* verbosity) { @@ -681,63 +666,66 @@ TEST(StlContainerViewTest, WorksForDynamicNativeArray) { TEST(FunctionTest, Nullary) { typedef Function<int()> F; // NOLINT EXPECT_EQ(0u, F::ArgumentCount); - CompileAssertTypesEqual<int, F::Result>(); - CompileAssertTypesEqual<std::tuple<>, F::ArgumentTuple>(); - CompileAssertTypesEqual<std::tuple<>, F::ArgumentMatcherTuple>(); - CompileAssertTypesEqual<void(), F::MakeResultVoid>(); - CompileAssertTypesEqual<IgnoredValue(), F::MakeResultIgnoredValue>(); + EXPECT_TRUE((std::is_same<int, F::Result>::value)); + EXPECT_TRUE((std::is_same<std::tuple<>, F::ArgumentTuple>::value)); + EXPECT_TRUE((std::is_same<std::tuple<>, F::ArgumentMatcherTuple>::value)); + EXPECT_TRUE((std::is_same<void(), F::MakeResultVoid>::value)); + EXPECT_TRUE((std::is_same<IgnoredValue(), F::MakeResultIgnoredValue>::value)); } TEST(FunctionTest, Unary) { typedef Function<int(bool)> F; // NOLINT EXPECT_EQ(1u, F::ArgumentCount); - CompileAssertTypesEqual<int, F::Result>(); - CompileAssertTypesEqual<bool, F::Arg<0>::type>(); - CompileAssertTypesEqual<std::tuple<bool>, F::ArgumentTuple>(); - CompileAssertTypesEqual<std::tuple<Matcher<bool> >, - F::ArgumentMatcherTuple>(); - CompileAssertTypesEqual<void(bool), F::MakeResultVoid>(); // NOLINT - CompileAssertTypesEqual<IgnoredValue(bool), // NOLINT - F::MakeResultIgnoredValue>(); + EXPECT_TRUE((std::is_same<int, F::Result>::value)); + EXPECT_TRUE((std::is_same<bool, F::Arg<0>::type>::value)); + EXPECT_TRUE((std::is_same<std::tuple<bool>, F::ArgumentTuple>::value)); + EXPECT_TRUE(( + std::is_same<std::tuple<Matcher<bool>>, F::ArgumentMatcherTuple>::value)); + EXPECT_TRUE((std::is_same<void(bool), F::MakeResultVoid>::value)); // NOLINT + EXPECT_TRUE((std::is_same<IgnoredValue(bool), // NOLINT + F::MakeResultIgnoredValue>::value)); } TEST(FunctionTest, Binary) { typedef Function<int(bool, const long&)> F; // NOLINT EXPECT_EQ(2u, F::ArgumentCount); - CompileAssertTypesEqual<int, F::Result>(); - CompileAssertTypesEqual<bool, F::Arg<0>::type>(); - CompileAssertTypesEqual<const long&, F::Arg<1>::type>(); // NOLINT - CompileAssertTypesEqual<std::tuple<bool, const long&>, // NOLINT - F::ArgumentTuple>(); - CompileAssertTypesEqual< - std::tuple<Matcher<bool>, Matcher<const long&> >, // NOLINT - F::ArgumentMatcherTuple>(); - CompileAssertTypesEqual<void(bool, const long&), F::MakeResultVoid>(); // NOLINT - CompileAssertTypesEqual<IgnoredValue(bool, const long&), // NOLINT - F::MakeResultIgnoredValue>(); + EXPECT_TRUE((std::is_same<int, F::Result>::value)); + EXPECT_TRUE((std::is_same<bool, F::Arg<0>::type>::value)); + EXPECT_TRUE((std::is_same<const long&, F::Arg<1>::type>::value)); // NOLINT + EXPECT_TRUE((std::is_same<std::tuple<bool, const long&>, // NOLINT + F::ArgumentTuple>::value)); + EXPECT_TRUE( + (std::is_same<std::tuple<Matcher<bool>, Matcher<const long&>>, // NOLINT + F::ArgumentMatcherTuple>::value)); + EXPECT_TRUE((std::is_same<void(bool, const long&), // NOLINT + F::MakeResultVoid>::value)); + EXPECT_TRUE((std::is_same<IgnoredValue(bool, const long&), // NOLINT + F::MakeResultIgnoredValue>::value)); } TEST(FunctionTest, LongArgumentList) { typedef Function<char(bool, int, char*, int&, const long&)> F; // NOLINT EXPECT_EQ(5u, F::ArgumentCount); - CompileAssertTypesEqual<char, F::Result>(); - CompileAssertTypesEqual<bool, F::Arg<0>::type>(); - CompileAssertTypesEqual<int, F::Arg<1>::type>(); - CompileAssertTypesEqual<char*, F::Arg<2>::type>(); - CompileAssertTypesEqual<int&, F::Arg<3>::type>(); - CompileAssertTypesEqual<const long&, F::Arg<4>::type>(); // NOLINT - CompileAssertTypesEqual< - std::tuple<bool, int, char*, int&, const long&>, // NOLINT - F::ArgumentTuple>(); - CompileAssertTypesEqual< - std::tuple<Matcher<bool>, Matcher<int>, Matcher<char*>, Matcher<int&>, - Matcher<const long&> >, // NOLINT - F::ArgumentMatcherTuple>(); - CompileAssertTypesEqual<void(bool, int, char*, int&, const long&), // NOLINT - F::MakeResultVoid>(); - CompileAssertTypesEqual< - IgnoredValue(bool, int, char*, int&, const long&), // NOLINT - F::MakeResultIgnoredValue>(); + EXPECT_TRUE((std::is_same<char, F::Result>::value)); + EXPECT_TRUE((std::is_same<bool, F::Arg<0>::type>::value)); + EXPECT_TRUE((std::is_same<int, F::Arg<1>::type>::value)); + EXPECT_TRUE((std::is_same<char*, F::Arg<2>::type>::value)); + EXPECT_TRUE((std::is_same<int&, F::Arg<3>::type>::value)); + EXPECT_TRUE((std::is_same<const long&, F::Arg<4>::type>::value)); // NOLINT + EXPECT_TRUE( + (std::is_same<std::tuple<bool, int, char*, int&, const long&>, // NOLINT + F::ArgumentTuple>::value)); + EXPECT_TRUE( + (std::is_same< + std::tuple<Matcher<bool>, Matcher<int>, Matcher<char*>, Matcher<int&>, + Matcher<const long&>>, // NOLINT + F::ArgumentMatcherTuple>::value)); + EXPECT_TRUE( + (std::is_same<void(bool, int, char*, int&, const long&), // NOLINT + F::MakeResultVoid>::value)); + EXPECT_TRUE(( + std::is_same<IgnoredValue(bool, int, char*, int&, const long&), // NOLINT + F::MakeResultIgnoredValue>::value)); } } // namespace diff --git a/googletest/docs/faq.md b/googletest/docs/faq.md index 9949fec..960a827 100644 --- a/googletest/docs/faq.md +++ b/googletest/docs/faq.md @@ -298,7 +298,7 @@ In the end, this boils down to good concurrent programming. You have to make sure that there is no race conditions or dead locks in your program. No silver bullet - sorry! -## Should I use the constructor/destructor of the test fixture or SetUp()/TearDown()? +## Should I use the constructor/destructor of the test fixture or SetUp()/TearDown()? {#CtorVsSetUp} The first thing to remember is that googletest does **not** reuse the same test fixture object across multiple tests. For each `TEST_F`, googletest will create diff --git a/googletest/docs/pkgconfig.md b/googletest/docs/pkgconfig.md index b775873..6dc0673 100644 --- a/googletest/docs/pkgconfig.md +++ b/googletest/docs/pkgconfig.md @@ -98,7 +98,7 @@ test('first_and_only_test', testapp) Since `pkg-config` is a small Unix command-line utility, it can be used in handwritten `Makefile`s too: -```Makefile +```makefile GTEST_CFLAGS = `pkg-config --cflags gtest_main` GTEST_LIBS = `pkg-config --libs gtest_main` diff --git a/googletest/docs/primer.md b/googletest/docs/primer.md index caf9c43..0317692 100644 --- a/googletest/docs/primer.md +++ b/googletest/docs/primer.md @@ -5,9 +5,9 @@ *googletest* helps you write better C++ tests. googletest is a testing framework developed by the Testing Technology team with -Google's specific requirements and constraints in mind. No matter whether you -work on Linux, Windows, or a Mac, if you write C++ code, googletest can help -you. And it supports *any* kind of tests, not just unit tests. +Google's specific requirements and constraints in mind. Whether you work on +Linux, Windows, or a Mac, if you write C++ code, googletest can help you. And it +supports *any* kind of tests, not just unit tests. So what makes a good test, and how does googletest fit in? We believe: @@ -21,7 +21,7 @@ So what makes a good test, and how does googletest fit in? We believe: easy to maintain. Such consistency is especially helpful when people switch projects and start to work on a new code base. 3. Tests should be *portable* and *reusable*. Google has a lot of code that is - platform-neutral, its tests should also be platform-neutral. googletest + platform-neutral; its tests should also be platform-neutral. googletest works on different OSes, with different compilers, with or without exceptions, so googletest tests can work with a variety of configurations. 4. When tests fail, they should provide as much *information* about the problem @@ -44,18 +44,17 @@ minutes to learn the basics and get started. So let's go! ## Beware of the nomenclature -_Note:_ There might be some confusion of idea due to different -definitions of the terms _Test_, _Test Case_ and _Test Suite_, so beware -of misunderstanding these. +_Note:_ There might be some confusion arising from different definitions of the +terms _Test_, _Test Case_ and _Test Suite_, so beware of misunderstanding these. Historically, googletest started to use the term _Test Case_ for grouping -related tests, whereas current publications including the International Software -Testing Qualifications Board ([ISTQB](http://www.istqb.org/)) and various -textbooks on Software Quality use the term _[Test Suite][istqb test suite]_ for -this. +related tests, whereas current publications, including International Software +Testing Qualifications Board ([ISTQB](http://www.istqb.org/)) materials and +various textbooks on software quality, use the term +_[Test Suite][istqb test suite]_ for this. -The related term _Test_, as it is used in the googletest, is corresponding to -the term _[Test Case][istqb test case]_ of ISTQB and others. +The related term _Test_, as it is used in googletest, corresponds to the term +_[Test Case][istqb test case]_ 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 @@ -120,7 +119,7 @@ Depending on the nature of the leak, it may or may not be worth fixing - so keep this in mind if you get a heap checker error in addition to assertion errors. To provide a custom failure message, simply stream it into the macro using the -`<<` operator, or a sequence of such operators. An example: +`<<` operator or a sequence of such operators. An example: ```c++ ASSERT_EQ(x.size(), y.size()) << "Vectors x and y are of unequal length"; @@ -166,16 +165,16 @@ Fatal assertion | Nonfatal assertion | Verifies Value arguments must be comparable by the assertion's comparison operator or you'll get a compiler error. We used to require the arguments to support the -`<<` operator for streaming to an `ostream`, but it's no longer necessary. If +`<<` operator for streaming to an `ostream`, but this is no longer necessary. If `<<` is supported, it will be called to print the arguments when the assertion fails; otherwise googletest will attempt to print them in the best way it can. -For more details and how to customize the printing of the arguments, see -[documentation](../../googlemock/docs/cook_book.md#teaching-gmock-how-to-print-your-values) +For more details and how to customize the printing of the arguments, see the +[documentation](../../googlemock/docs/cook_book.md#teaching-gmock-how-to-print-your-values). These assertions can work with a user-defined type, but only if you define the -corresponding comparison operator (e.g. `==`, `<`, etc). Since this is -discouraged by the Google [C++ Style -Guide](https://google.github.io/styleguide/cppguide.html#Operator_Overloading), +corresponding comparison operator (e.g., `==` or `<`). Since this is discouraged +by the Google +[C++ Style Guide](https://google.github.io/styleguide/cppguide.html#Operator_Overloading), you may need to use `ASSERT_TRUE()` or `EXPECT_TRUE()` to assert the equality of two objects of a user-defined type. @@ -185,8 +184,8 @@ values on failure. Arguments are always evaluated exactly once. Therefore, it's OK for the arguments to have side effects. However, as with any ordinary C/C++ function, -the arguments' evaluation order is undefined (i.e. the compiler is free to -choose any order) and your code should not depend on any particular argument +the arguments' evaluation order is undefined (i.e., the compiler is free to +choose any order), and your code should not depend on any particular argument evaluation order. `ASSERT_EQ()` does pointer equality on pointers. If used on two C strings, it @@ -199,7 +198,7 @@ objects, you should use `ASSERT_EQ`. When doing pointer comparisons use `*_EQ(ptr, nullptr)` and `*_NE(ptr, nullptr)` instead of `*_EQ(ptr, NULL)` and `*_NE(ptr, NULL)`. This is because `nullptr` is -typed while `NULL` is not. See [FAQ](faq.md) for more details. +typed, while `NULL` is not. See the [FAQ](faq.md) for more details. If you're working with floating point numbers, you may want to use the floating point variations of some of these macros in order to avoid problems caused by @@ -246,7 +245,7 @@ Advanced googletest Guide. To create a test: -1. Use the `TEST()` macro to define and name a test function, These are +1. Use the `TEST()` macro to define and name a test function. These are ordinary C++ functions that don't return a value. 2. In this function, along with any valid C++ statements you want to include, use the various googletest assertions to check values. @@ -263,7 +262,7 @@ TEST(TestSuiteName, TestName) { `TEST()` arguments go from general to specific. The *first* argument is the name of the test suite, and the *second* argument is the test's name within the test case. Both names must be valid C++ identifiers, and they should not contain -underscore (`_`). A test's *full name* consists of its containing test suite and +any underscores (`_`). A test's *full name* consists of its containing test suite and its individual name. Tests from different test suites can have the same individual name. @@ -290,7 +289,7 @@ TEST(FactorialTest, HandlesPositiveInput) { } ``` -googletest groups the test results by test suites, so logically-related tests +googletest groups the test results by test suites, so logically related tests should be in the same test suite; in other words, the first argument to their `TEST()` should be the same. In the above example, we have two tests, `HandlesZeroInput` and `HandlesPositiveInput`, that belong to the same test @@ -302,25 +301,25 @@ for **Availability**: Linux, Windows, Mac. -## Test Fixtures: Using the Same Data Configuration for Multiple Tests +## Test Fixtures: Using the Same Data Configuration for Multiple Tests {#same-data-multiple-tests} If you find yourself writing two or more tests that operate on similar data, you -can use a *test fixture*. It allows you to reuse the same configuration of +can use a *test fixture*. This allows you to reuse the same configuration of objects for several different tests. To create a fixture: -1. Derive a class from `::testing::Test` . Start its body with `protected:` as +1. Derive a class from `::testing::Test` . Start its body with `protected:`, as we'll want to access fixture members from sub-classes. 2. Inside the class, declare any objects you plan to use. 3. If necessary, write a default constructor or `SetUp()` function to prepare the objects for each test. A common mistake is to spell `SetUp()` as **`Setup()`** with a small `u` - Use `override` in C++11 to make sure you - spelled it correctly + spelled it correctly. 4. If necessary, write a destructor or `TearDown()` function to release any resources you allocated in `SetUp()` . To learn when you should use the constructor/destructor and when you should use `SetUp()/TearDown()`, read - the [FAQ](faq.md). + the [FAQ](faq.md#CtorVsSetUp). 5. If needed, define subroutines for your tests to share. When using a fixture, use `TEST_F()` instead of `TEST()` as it allows you to @@ -344,9 +343,9 @@ Also, you must first define a test fixture class before using it in a `TEST_F()`, or you'll get the compiler error "`virtual outside class declaration`". -For each test defined with `TEST_F()` , googletest will create a *fresh* test -fixture at runtime, immediately initialize it via `SetUp()` , run the test, -clean up by calling `TearDown()` , and then delete the test fixture. Note that +For each test defined with `TEST_F()`, googletest will create a *fresh* test +fixture at runtime, immediately initialize it via `SetUp()`, run the test, +clean up by calling `TearDown()`, and then delete the test fixture. Note that different tests in the same test suite have different test fixture objects, and googletest always deletes a test fixture before it creates the next one. googletest does **not** reuse the same test fixture for multiple tests. Any @@ -424,9 +423,9 @@ would lead to a segfault when `n` is `NULL`. When these tests run, the following happens: -1. googletest constructs a `QueueTest` object (let's call it `t1` ). -2. `t1.SetUp()` initializes `t1` . -3. The first test ( `IsEmptyInitially` ) runs on `t1` . +1. googletest constructs a `QueueTest` object (let's call it `t1`). +2. `t1.SetUp()` initializes `t1`. +3. The first test (`IsEmptyInitially`) runs on `t1`. 4. `t1.TearDown()` cleans up after the test finishes. 5. `t1` is destructed. 6. The above steps are repeated on another `QueueTest` object, this time @@ -440,14 +439,14 @@ When these tests run, the following happens: unlike with many other C++ testing frameworks, you don't have to re-list all your defined tests in order to run them. -After defining your tests, you can run them with `RUN_ALL_TESTS()` , which +After defining your tests, you can run them with `RUN_ALL_TESTS()`, which returns `0` if all the tests are successful, or `1` otherwise. Note that -`RUN_ALL_TESTS()` runs *all tests* in your link unit -- they can be from +`RUN_ALL_TESTS()` runs *all tests* in your link unit--they can be from different test suites, or even different source files. When invoked, the `RUN_ALL_TESTS()` macro: -* Saves the state of all googletest flags +* Saves the state of all googletest flags. * Creates a test fixture object for the first test. @@ -459,7 +458,7 @@ When invoked, the `RUN_ALL_TESTS()` macro: * Deletes the fixture. -* Restores the state of all googletest flags +* Restores the state of all googletest flags. * Repeats the above steps for the next test, until all tests have run. @@ -472,7 +471,7 @@ If a fatal failure happens the subsequent steps will be skipped. > return the value of `RUN_ALL_TESTS()`. > > Also, you should call `RUN_ALL_TESTS()` only **once**. Calling it more than -> once conflicts with some advanced googletest features (e.g. thread-safe +> once conflicts with some advanced googletest features (e.g., thread-safe > [death tests](advanced.md#death-tests)) and thus is not supported. **Availability**: Linux, Windows, Mac. @@ -480,7 +479,7 @@ If a fatal failure happens the subsequent steps will be skipped. ## Writing the main() Function Write your own main() function, which should return the value of -`RUN_ALL_TESTS()` +`RUN_ALL_TESTS()`. You can start from this boilerplate: @@ -544,14 +543,14 @@ int main(int argc, char **argv) { The `::testing::InitGoogleTest()` function parses the command line for googletest flags, and removes all recognized flags. This allows the user to control a test program's behavior via various flags, which we'll cover in -[AdvancedGuide](advanced.md). You **must** call this function before calling +the [AdvancedGuide](advanced.md). You **must** call this function before calling `RUN_ALL_TESTS()`, or the flags won't be properly initialized. On Windows, `InitGoogleTest()` also works with wide strings, so it can be used in programs compiled in `UNICODE` mode as well. But maybe you think that writing all those main() functions is too much work? We -agree with you completely and that's why Google Test provides a basic +agree with you completely, and that's why Google Test provides a basic implementation of main(). If it fits your needs, then just link your test with gtest\_main library and you are good to go. diff --git a/googletest/include/gtest/gtest-matchers.h b/googletest/include/gtest/gtest-matchers.h index 187c290..9de6c2e 100644 --- a/googletest/include/gtest/gtest-matchers.h +++ b/googletest/include/gtest/gtest-matchers.h @@ -300,7 +300,7 @@ class MatcherBase { template <typename U> explicit MatcherBase( const MatcherInterface<U>* impl, - typename internal::EnableIf<!std::is_same<U, const U&>::value>::type* = + typename std::enable_if<!std::is_same<U, const U&>::value>::type* = nullptr) : impl_(new internal::MatcherInterfaceAdapter<U>(impl)) {} @@ -336,7 +336,7 @@ class Matcher : public internal::MatcherBase<T> { template <typename U> explicit Matcher( const MatcherInterface<U>* impl, - typename internal::EnableIf<!std::is_same<U, const U&>::value>::type* = + typename std::enable_if<!std::is_same<U, const U&>::value>::type* = nullptr) : internal::MatcherBase<T>(impl) {} diff --git a/googletest/include/gtest/gtest-param-test.h b/googletest/include/gtest/gtest-param-test.h index d7c9dd8..c2e6eae 100644 --- a/googletest/include/gtest/gtest-param-test.h +++ b/googletest/include/gtest/gtest-param-test.h @@ -174,6 +174,7 @@ TEST_P(DerivedTest, DoesBlah) { #endif // 0 +#include <iterator> #include <utility> #include "gtest/internal/gtest-internal.h" @@ -292,10 +293,9 @@ internal::ParamGenerator<T> Range(T start, T end) { // template <typename ForwardIterator> internal::ParamGenerator< - typename ::testing::internal::IteratorTraits<ForwardIterator>::value_type> + typename std::iterator_traits<ForwardIterator>::value_type> ValuesIn(ForwardIterator begin, ForwardIterator end) { - typedef typename ::testing::internal::IteratorTraits<ForwardIterator> - ::value_type ParamType; + typedef typename std::iterator_traits<ForwardIterator>::value_type ParamType; return internal::ParamGenerator<ParamType>( new internal::ValuesInIteratorRangeGenerator<ParamType>(begin, end)); } diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index 98c1949..8e125a4 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -292,7 +292,7 @@ class GTEST_API_ AssertionResult { template <typename T> explicit AssertionResult( const T& success, - typename internal::EnableIf< + typename std::enable_if< !std::is_convertible<T, AssertionResult>::value>::type* /*enabler*/ = nullptr) @@ -2266,7 +2266,6 @@ class GTEST_API_ ScopedTrace { ::testing::ScopedTrace GTEST_CONCAT_TOKEN_(gtest_trace_, __LINE__)(\ __FILE__, __LINE__, (message)) - // Compile-time assertion for type equality. // StaticAssertTypeEq<type1, type2>() compiles if and only if type1 and type2 // are the same type. The value it returns is not interesting. diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index c3cf727..22127c7 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -847,60 +847,16 @@ class GTEST_API_ Random { GTEST_DISALLOW_COPY_AND_ASSIGN_(Random); }; -// Defining a variable of type CompileAssertTypesEqual<T1, T2> will cause a -// compiler error if and only if T1 and T2 are different types. -template <typename T1, typename T2> -struct CompileAssertTypesEqual; - -template <typename T> -struct CompileAssertTypesEqual<T, T> { -}; - -// Removes the reference from a type if it is a reference type, -// otherwise leaves it unchanged. This is the same as -// tr1::remove_reference, which is not widely available yet. -template <typename T> -struct RemoveReference { typedef T type; }; // NOLINT -template <typename T> -struct RemoveReference<T&> { typedef T type; }; // NOLINT - -// A handy wrapper around RemoveReference that works when the argument -// T depends on template parameters. -#define GTEST_REMOVE_REFERENCE_(T) \ - typename ::testing::internal::RemoveReference<T>::type - -// Removes const from a type if it is a const type, otherwise leaves -// it unchanged. This is the same as tr1::remove_const, which is not -// widely available yet. -template <typename T> -struct RemoveConst { typedef T type; }; // NOLINT -template <typename T> -struct RemoveConst<const T> { typedef T type; }; // NOLINT - -// MSVC 8.0, Sun C++, and IBM XL C++ have a bug which causes the above -// definition to fail to remove the const in 'const int[3]' and 'const -// char[3][4]'. The following specialization works around the bug. -template <typename T, size_t N> -struct RemoveConst<const T[N]> { - typedef typename RemoveConst<T>::type type[N]; -}; - -// A handy wrapper around RemoveConst that works when the argument -// T depends on template parameters. -#define GTEST_REMOVE_CONST_(T) \ - typename ::testing::internal::RemoveConst<T>::type - // Turns const U&, U&, const U, and U all into U. #define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \ - GTEST_REMOVE_CONST_(GTEST_REMOVE_REFERENCE_(T)) + typename std::remove_const<typename std::remove_reference<T>::type>::type // IsAProtocolMessage<T>::value is a compile-time bool constant that's // true if and only if T is type proto2::Message or a subclass of it. template <typename T> struct IsAProtocolMessage : public bool_constant< - std::is_convertible<const T*, const ::proto2::Message*>::value> { -}; + std::is_convertible<const T*, const ::proto2::Message*>::value> {}; // When the compiler sees expression IsContainerTest<C>(0), if C is an // STL-style container class, the first overload of IsContainerTest @@ -967,7 +923,7 @@ template <typename C, struct IsRecursiveContainerImpl; template <typename C> -struct IsRecursiveContainerImpl<C, false> : public false_type {}; +struct IsRecursiveContainerImpl<C, false> : public std::false_type {}; // Since the IsRecursiveContainerImpl depends on the IsContainerTest we need to // obey the same inconsistencies as the IsContainerTest, namely check if @@ -991,13 +947,6 @@ struct IsRecursiveContainerImpl<C, true> { template <typename C> struct IsRecursiveContainer : public IsRecursiveContainerImpl<C>::type {}; -// EnableIf<condition>::type is void when 'Cond' is true, and -// undefined when 'Cond' is false. To use SFINAE to make a function -// overload only apply when a particular expression is true, add -// "typename EnableIf<expression>::type* = 0" as the last parameter. -template<bool> struct EnableIf; -template<> struct EnableIf<true> { typedef void type; }; // NOLINT - // Utilities for native arrays. // ArrayEq() compares two k-dimensional native arrays using the diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 18dd637..0813adc 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -202,11 +202,6 @@ // Mutex, MutexLock, ThreadLocal, GetThreadCount() // - synchronization primitives. // -// Template meta programming: -// IteratorTraits - partial implementation of std::iterator_traits, which -// is not available in libCstd when compiled with Sun C++. -// -// // Regular expressions: // RE - a simple regular expression class using the POSIX // Extended Regular Expression syntax on UNIX-like platforms @@ -474,7 +469,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; # ifdef _MSC_VER -# ifdef _CPPRTTI // MSVC defines this macro if and only if RTTI is enabled. +#ifdef _CPPRTTI // MSVC defines this macro if and only if RTTI is enabled. # define GTEST_HAS_RTTI 1 # else # define GTEST_HAS_RTTI 0 @@ -1022,19 +1017,6 @@ inline void FlushInfoLog() { fflush(nullptr); } GTEST_LOG_(FATAL) << #posix_call << "failed with error " \ << gtest_error -// Adds reference to a type if it is not a reference type, -// otherwise leaves it unchanged. This is the same as -// tr1::add_reference, which is not widely available yet. -template <typename T> -struct AddReference { typedef T& type; }; // NOLINT -template <typename T> -struct AddReference<T&> { typedef T& type; }; // NOLINT - -// A handy wrapper around AddReference that works when the argument T -// depends on template parameters. -#define GTEST_ADD_REFERENCE_(T) \ - typename ::testing::internal::AddReference<T>::type - // Transforms "T" into "const T&" according to standard reference collapsing // rules (this is only needed as a backport for C++98 compilers that do not // support reference collapsing). Specifically, it transforms: @@ -1916,31 +1898,8 @@ class GTEST_API_ ThreadLocal { // we cannot detect it. GTEST_API_ size_t GetThreadCount(); -template <bool bool_value> -struct bool_constant { - typedef bool_constant<bool_value> type; - static const bool value = bool_value; -}; -template <bool bool_value> const bool bool_constant<bool_value>::value; - -typedef bool_constant<false> false_type; -typedef bool_constant<true> true_type; - -template <typename Iterator> -struct IteratorTraits { - typedef typename Iterator::value_type value_type; -}; - - -template <typename T> -struct IteratorTraits<T*> { - typedef T value_type; -}; - -template <typename T> -struct IteratorTraits<const T*> { - typedef T value_type; -}; +template <bool B> +using bool_constant = std::integral_constant<bool, B>; #if GTEST_OS_WINDOWS # define GTEST_PATH_SEP_ "\\" diff --git a/googletest/src/gtest-filepath.cc b/googletest/src/gtest-filepath.cc index 322fbb1..bd7b99f 100644 --- a/googletest/src/gtest-filepath.cc +++ b/googletest/src/gtest-filepath.cc @@ -93,8 +93,8 @@ static bool IsPathSeparator(char c) { // Returns the current working directory, or "" if unsuccessful. FilePath FilePath::GetCurrentDir() { #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \ - GTEST_OS_WINDOWS_RT || ARDUINO - // Windows CE and Arduino don't have a current directory, so we just return + GTEST_OS_WINDOWS_RT || ARDUINO || defined(ESP_PLATFORM) + // These platforms do not have a current directory, so we just return // something reasonable. return FilePath(kCurrentDirectoryString); #elif GTEST_OS_WINDOWS diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index bd4ee42..a5b4e5a 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -215,16 +215,14 @@ GTEST_DEFINE_bool_( "Run disabled tests too, in addition to the tests normally being run."); GTEST_DEFINE_bool_( - break_on_failure, - internal::BoolFromGTestEnv("break_on_failure", false), + break_on_failure, internal::BoolFromGTestEnv("break_on_failure", false), "True if and only if a failed assertion should be a debugger " "break-point."); -GTEST_DEFINE_bool_( - catch_exceptions, - internal::BoolFromGTestEnv("catch_exceptions", true), - "True if and only if " GTEST_NAME_ - " should catch exceptions and treat them as test failures."); +GTEST_DEFINE_bool_(catch_exceptions, + internal::BoolFromGTestEnv("catch_exceptions", true), + "True if and only if " GTEST_NAME_ + " should catch exceptions and treat them as test failures."); GTEST_DEFINE_string_( color, @@ -271,17 +269,13 @@ GTEST_DEFINE_string_( "executable's name and, if necessary, made unique by adding " "digits."); -GTEST_DEFINE_bool_( - print_time, - internal::BoolFromGTestEnv("print_time", true), - "True if and only if " GTEST_NAME_ - " should display elapsed time in text output."); +GTEST_DEFINE_bool_(print_time, internal::BoolFromGTestEnv("print_time", true), + "True if and only if " GTEST_NAME_ + " should display elapsed time in text output."); -GTEST_DEFINE_bool_( - print_utf8, - internal::BoolFromGTestEnv("print_utf8", true), - "True if and only if " GTEST_NAME_ - " prints UTF8 characters as text."); +GTEST_DEFINE_bool_(print_utf8, internal::BoolFromGTestEnv("print_utf8", true), + "True if and only if " GTEST_NAME_ + " prints UTF8 characters as text."); GTEST_DEFINE_int32_( random_seed, @@ -295,16 +289,14 @@ GTEST_DEFINE_int32_( "How many times to repeat each test. Specify a negative number " "for repeating forever. Useful for shaking out flaky tests."); -GTEST_DEFINE_bool_( - show_internal_stack_frames, false, - "True if and only if " GTEST_NAME_ " should include internal stack frames when " - "printing test failure stack traces."); +GTEST_DEFINE_bool_(show_internal_stack_frames, false, + "True if and only if " GTEST_NAME_ + " should include internal stack frames when " + "printing test failure stack traces."); -GTEST_DEFINE_bool_( - shuffle, - internal::BoolFromGTestEnv("shuffle", false), - "True if and only if " GTEST_NAME_ - " should randomize tests' order on every run."); +GTEST_DEFINE_bool_(shuffle, internal::BoolFromGTestEnv("shuffle", false), + "True if and only if " GTEST_NAME_ + " should randomize tests' order on every run."); GTEST_DEFINE_int32_( stack_trace_depth, @@ -3040,7 +3032,7 @@ void ColoredPrintf(GTestColor color, const char* fmt, ...) { va_start(args, fmt); #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_ZOS || GTEST_OS_IOS || \ - GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT + GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT || defined(ESP_PLATFORM) const bool use_color = AlwaysFalse(); #else static const bool in_color_mode = diff --git a/googletest/test/googletest-port-test.cc b/googletest/test/googletest-port-test.cc index 42035cc..60d637c 100644 --- a/googletest/test/googletest-port-test.cc +++ b/googletest/test/googletest-port-test.cc @@ -201,24 +201,6 @@ TEST(ImplicitCastTest, CanUseImplicitConstructor) { EXPECT_TRUE(converted); } -TEST(IteratorTraitsTest, WorksForSTLContainerIterators) { - StaticAssertTypeEq<int, - IteratorTraits< ::std::vector<int>::const_iterator>::value_type>(); - StaticAssertTypeEq<bool, - IteratorTraits< ::std::list<bool>::iterator>::value_type>(); -} - -TEST(IteratorTraitsTest, WorksForPointerToNonConst) { - StaticAssertTypeEq<char, IteratorTraits<char*>::value_type>(); - StaticAssertTypeEq<const void*, IteratorTraits<const void**>::value_type>(); -} - -TEST(IteratorTraitsTest, WorksForPointerToConst) { - StaticAssertTypeEq<char, IteratorTraits<const char*>::value_type>(); - StaticAssertTypeEq<const void*, - IteratorTraits<const void* const*>::value_type>(); -} - TEST(GtestCheckSyntaxTest, BehavesLikeASingleStatement) { if (AlwaysFalse()) GTEST_CHECK_(false) << "This should never be executed; " diff --git a/googletest/test/gtest_test_utils.py b/googletest/test/gtest_test_utils.py index 3db665e..ef9363c 100755 --- a/googletest/test/gtest_test_utils.py +++ b/googletest/test/gtest_test_utils.py @@ -218,7 +218,8 @@ class Subprocess: terminated_by_signal True if and only if the child process has been terminated by a signal. signal Sygnal that terminated the child process. - exited True if and only if the child process exited normally. + exited True if and only if the child process exited + normally. exit_code The code with which the child process exited. output Child process's stdout and stderr output combined in a string. diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 220ceba..39749b7 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -61,9 +61,10 @@ TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) { #include <time.h> #include <map> -#include <vector> #include <ostream> +#include <type_traits> #include <unordered_set> +#include <vector> #include "gtest/gtest-spi.h" #include "src/gtest-internal-inl.h" @@ -226,14 +227,12 @@ using testing::TestProperty; using testing::TestResult; using testing::TimeInMillis; using testing::UnitTest; -using testing::internal::AddReference; using testing::internal::AlwaysFalse; using testing::internal::AlwaysTrue; using testing::internal::AppendUserMessage; using testing::internal::ArrayAwareFind; using testing::internal::ArrayEq; using testing::internal::CodePointToUtf8; -using testing::internal::CompileAssertTypesEqual; using testing::internal::CopyArray; using testing::internal::CountIf; using testing::internal::EqFailure; @@ -262,8 +261,6 @@ using testing::internal::OsStackTraceGetterInterface; using testing::internal::ParseInt32Flag; using testing::internal::RelationToSourceCopy; using testing::internal::RelationToSourceReference; -using testing::internal::RemoveConst; -using testing::internal::RemoveReference; using testing::internal::ShouldRunTestOnShard; using testing::internal::ShouldShard; using testing::internal::ShouldUseColor; @@ -7104,69 +7101,12 @@ TEST(IsAProtocolMessageTest, ValueIsFalseWhenTypeIsNotAProtocolMessage) { EXPECT_FALSE(IsAProtocolMessage<const ConversionHelperBase>::value); } -// Tests that CompileAssertTypesEqual compiles when the type arguments are -// equal. -TEST(CompileAssertTypesEqual, CompilesWhenTypesAreEqual) { - CompileAssertTypesEqual<void, void>(); - CompileAssertTypesEqual<int*, int*>(); -} - -// Tests that RemoveReference does not affect non-reference types. -TEST(RemoveReferenceTest, DoesNotAffectNonReferenceType) { - CompileAssertTypesEqual<int, RemoveReference<int>::type>(); - CompileAssertTypesEqual<const char, RemoveReference<const char>::type>(); -} - -// Tests that RemoveReference removes reference from reference types. -TEST(RemoveReferenceTest, RemovesReference) { - CompileAssertTypesEqual<int, RemoveReference<int&>::type>(); - CompileAssertTypesEqual<const char, RemoveReference<const char&>::type>(); -} - -// Tests GTEST_REMOVE_REFERENCE_. - -template <typename T1, typename T2> -void TestGTestRemoveReference() { - CompileAssertTypesEqual<T1, GTEST_REMOVE_REFERENCE_(T2)>(); -} - -TEST(RemoveReferenceTest, MacroVersion) { - TestGTestRemoveReference<int, int>(); - TestGTestRemoveReference<const char, const char&>(); -} - - -// Tests that RemoveConst does not affect non-const types. -TEST(RemoveConstTest, DoesNotAffectNonConstType) { - CompileAssertTypesEqual<int, RemoveConst<int>::type>(); - CompileAssertTypesEqual<char&, RemoveConst<char&>::type>(); -} - -// Tests that RemoveConst removes const from const types. -TEST(RemoveConstTest, RemovesConst) { - CompileAssertTypesEqual<int, RemoveConst<const int>::type>(); - CompileAssertTypesEqual<char[2], RemoveConst<const char[2]>::type>(); - CompileAssertTypesEqual<char[2][3], RemoveConst<const char[2][3]>::type>(); -} - -// Tests GTEST_REMOVE_CONST_. - -template <typename T1, typename T2> -void TestGTestRemoveConst() { - CompileAssertTypesEqual<T1, GTEST_REMOVE_CONST_(T2)>(); -} - -TEST(RemoveConstTest, MacroVersion) { - TestGTestRemoveConst<int, int>(); - TestGTestRemoveConst<double&, double&>(); - TestGTestRemoveConst<char, const char>(); -} - // Tests GTEST_REMOVE_REFERENCE_AND_CONST_. template <typename T1, typename T2> void TestGTestRemoveReferenceAndConst() { - CompileAssertTypesEqual<T1, GTEST_REMOVE_REFERENCE_AND_CONST_(T2)>(); + static_assert(std::is_same<T1, GTEST_REMOVE_REFERENCE_AND_CONST_(T2)>::value, + "GTEST_REMOVE_REFERENCE_AND_CONST_ failed."); } TEST(RemoveReferenceToConstTest, Works) { @@ -7177,35 +7117,12 @@ TEST(RemoveReferenceToConstTest, Works) { TestGTestRemoveReferenceAndConst<const char*, const char*>(); } -// Tests that AddReference does not affect reference types. -TEST(AddReferenceTest, DoesNotAffectReferenceType) { - CompileAssertTypesEqual<int&, AddReference<int&>::type>(); - CompileAssertTypesEqual<const char&, AddReference<const char&>::type>(); -} - -// Tests that AddReference adds reference to non-reference types. -TEST(AddReferenceTest, AddsReference) { - CompileAssertTypesEqual<int&, AddReference<int>::type>(); - CompileAssertTypesEqual<const char&, AddReference<const char>::type>(); -} - -// Tests GTEST_ADD_REFERENCE_. - -template <typename T1, typename T2> -void TestGTestAddReference() { - CompileAssertTypesEqual<T1, GTEST_ADD_REFERENCE_(T2)>(); -} - -TEST(AddReferenceTest, MacroVersion) { - TestGTestAddReference<int&, int>(); - TestGTestAddReference<const char&, const char&>(); -} - // Tests GTEST_REFERENCE_TO_CONST_. template <typename T1, typename T2> void TestGTestReferenceToConst() { - CompileAssertTypesEqual<T1, GTEST_REFERENCE_TO_CONST_(T2)>(); + static_assert(std::is_same<T1, GTEST_REFERENCE_TO_CONST_(T2)>::value, + "GTEST_REFERENCE_TO_CONST_ failed."); } TEST(GTestReferenceToConstTest, Works) { |