mirror of
https://github.com/google/googletest.git
synced 2025-12-06 16:57:00 +08:00
Refactor Values() generator function to resolve more complicated type transformations
This commit is contained in:
parent
1b96fa13f5
commit
ceeca5fcea
@ -332,9 +332,10 @@ internal::ParamGenerator<typename Container::value_type> ValuesIn(
|
|||||||
// INSTANTIATE_TEST_SUITE_P(FloatingNumbers, BazTest, Values(1, 2, 3.5));
|
// INSTANTIATE_TEST_SUITE_P(FloatingNumbers, BazTest, Values(1, 2, 3.5));
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
template <typename... T>
|
template <typename... Ts>
|
||||||
internal::ValueArray<T...> Values(T... v) {
|
internal::ParamGenerator<std::common_type_t<Ts...>> Values(Ts... vs) {
|
||||||
return internal::ValueArray<T...>(std::move(v)...);
|
return ValuesIn(
|
||||||
|
std::array<std::common_type_t<Ts...>, sizeof...(Ts)>{std::move(vs)...});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bool() allows generating tests with parameters in a set of (false, true).
|
// Bool() allows generating tests with parameters in a set of (false, true).
|
||||||
|
|||||||
@ -180,6 +180,11 @@ class ParamGeneratorInterface {
|
|||||||
virtual ParamIteratorInterface<T>* End() const = 0;
|
virtual ParamIteratorInterface<T>* End() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <class GeneratedT,
|
||||||
|
typename StdFunction =
|
||||||
|
std::function<const GeneratedT&(const GeneratedT&)>>
|
||||||
|
class ParamConverterGenerator;
|
||||||
|
|
||||||
// Wraps ParamGeneratorInterface<T> and provides general generator syntax
|
// Wraps ParamGeneratorInterface<T> and provides general generator syntax
|
||||||
// compatible with the STL Container concept.
|
// compatible with the STL Container concept.
|
||||||
// This class implements copy initialization semantics and the contained
|
// This class implements copy initialization semantics and the contained
|
||||||
@ -201,6 +206,11 @@ class ParamGenerator {
|
|||||||
iterator begin() const { return iterator(impl_->Begin()); }
|
iterator begin() const { return iterator(impl_->Begin()); }
|
||||||
iterator end() const { return iterator(impl_->End()); }
|
iterator end() const { return iterator(impl_->End()); }
|
||||||
|
|
||||||
|
template <typename R>
|
||||||
|
operator ParamGenerator<R>() {
|
||||||
|
return ParamConverterGenerator<T>(*this);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<const ParamGeneratorInterface<T>> impl_;
|
std::shared_ptr<const ParamGeneratorInterface<T>> impl_;
|
||||||
};
|
};
|
||||||
@ -796,30 +806,6 @@ internal::ParamGenerator<typename Container::value_type> ValuesIn(
|
|||||||
const Container& container);
|
const Container& container);
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
// Used in the Values() function to provide polymorphic capabilities.
|
|
||||||
|
|
||||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100)
|
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
class ValueArray {
|
|
||||||
public:
|
|
||||||
explicit ValueArray(Ts... v) : v_(FlatTupleConstructTag{}, std::move(v)...) {}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
operator ParamGenerator<T>() const { // NOLINT
|
|
||||||
return ValuesIn(MakeVector<T>(std::make_index_sequence<sizeof...(Ts)>()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
template <typename T, size_t... I>
|
|
||||||
std::vector<T> MakeVector(std::index_sequence<I...>) const {
|
|
||||||
return std::vector<T>{static_cast<T>(v_.template Get<I>())...};
|
|
||||||
}
|
|
||||||
|
|
||||||
FlatTuple<Ts...> v_;
|
|
||||||
};
|
|
||||||
|
|
||||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100
|
|
||||||
|
|
||||||
template <typename... T>
|
template <typename... T>
|
||||||
class CartesianProductGenerator
|
class CartesianProductGenerator
|
||||||
@ -1020,9 +1006,7 @@ class ParamGeneratorConverter : public ParamGeneratorInterface<To> {
|
|||||||
Func converter_;
|
Func converter_;
|
||||||
}; // class ParamGeneratorConverter
|
}; // class ParamGeneratorConverter
|
||||||
|
|
||||||
template <class GeneratedT,
|
template <class GeneratedT, typename StdFunction>
|
||||||
typename StdFunction =
|
|
||||||
std::function<const GeneratedT&(const GeneratedT&)>>
|
|
||||||
class ParamConverterGenerator {
|
class ParamConverterGenerator {
|
||||||
public:
|
public:
|
||||||
ParamConverterGenerator(ParamGenerator<GeneratedT> g) // NOLINT
|
ParamConverterGenerator(ParamGenerator<GeneratedT> g) // NOLINT
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user