2 $var n = 50 $$ Maximum length of Values arguments we want to support.
3 $var maxtuple = 10 $$ Maximum number of Combine arguments we want to support.
4 // Copyright 2008 Google Inc.
5 // All Rights Reserved.
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
17 // * Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 // Type and function utilities for implementing parameterized tests.
35 // This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
37 // Currently Google Test supports at most $n arguments in Values,
38 // and at most $maxtuple arguments in Combine. Please contact
39 // googletestframework@googlegroups.com if you need more.
40 // Please note that the number of arguments to Combine is limited
41 // by the maximum arity of the implementation of tuple which is
42 // currently set at $maxtuple.
44 // GOOGLETEST_CM0001 DO NOT DELETE
46 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_
47 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_
49 #include "gtest/internal/gtest-param-util.h"
50 #include "gtest/internal/gtest-port.h"
54 // Forward declarations of ValuesIn(), which is implemented in
55 // include/gtest/gtest-param-test.h.
56 template <typename ForwardIterator>
57 internal::ParamGenerator<
58 typename ::testing::internal::IteratorTraits<ForwardIterator>::value_type>
59 ValuesIn(ForwardIterator begin, ForwardIterator end);
61 template <typename T, size_t N>
62 internal::ParamGenerator<T> ValuesIn(const T (&array)[N]);
64 template <class Container>
65 internal::ParamGenerator<typename Container::value_type> ValuesIn(
66 const Container& container);
70 // Used in the Values() function to provide polymorphic capabilities.
75 template <$for j, [[typename T$j]]>
78 $if i==1 [[explicit ]]ValueArray$i($for j, [[T$j v$j]]) : $for j, [[v$(j)_(v$j)]] {}
81 operator ParamGenerator<T>() const {
82 const T array[] = {$for j, [[static_cast<T>(v$(j)_)]]};
83 return ValuesIn(array);
86 ValueArray$i(const ValueArray$i& other) : $for j, [[v$(j)_(other.v$(j)_)]] {}
89 // No implementation - assignment is unsupported.
90 void operator=(const ValueArray$i& other);
101 # if GTEST_HAS_COMBINE
102 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
104 // Generates values from the Cartesian product of values produced
105 // by the argument generators.
112 template <$for j, [[typename T$j]]>
113 class CartesianProductGenerator$i
114 : public ParamGeneratorInterface< ::testing::tuple<$for j, [[T$j]]> > {
116 typedef ::testing::tuple<$for j, [[T$j]]> ParamType;
118 CartesianProductGenerator$i($for j, [[const ParamGenerator<T$j>& g$j]])
119 : $for j, [[g$(j)_(g$j)]] {}
120 virtual ~CartesianProductGenerator$i() {}
122 virtual ParamIteratorInterface<ParamType>* Begin() const {
123 return new Iterator(this, $for j, [[g$(j)_, g$(j)_.begin()]]);
125 virtual ParamIteratorInterface<ParamType>* End() const {
126 return new Iterator(this, $for j, [[g$(j)_, g$(j)_.end()]]);
130 class Iterator : public ParamIteratorInterface<ParamType> {
132 Iterator(const ParamGeneratorInterface<ParamType>* base, $for j, [[
134 const ParamGenerator<T$j>& g$j,
135 const typename ParamGenerator<T$j>::iterator& current$(j)]])
139 begin$(j)_(g$j.begin()), end$(j)_(g$j.end()), current$(j)_(current$j)
141 ComputeCurrentValue();
143 virtual ~Iterator() {}
145 virtual const ParamGeneratorInterface<ParamType>* BaseGenerator() const {
148 // Advance should not be called on beyond-of-range iterators
149 // so no component iterators must be beyond end of range, either.
150 virtual void Advance() {
155 if (current$(i+2-k)_ == end$(i+2-k)_) {
156 current$(i+2-k)_ = begin$(i+2-k)_;
157 ++current$(i+2-k-1)_;
161 ComputeCurrentValue();
163 virtual ParamIteratorInterface<ParamType>* Clone() const {
164 return new Iterator(*this);
166 virtual const ParamType* Current() const { return current_value_.get(); }
167 virtual bool Equals(const ParamIteratorInterface<ParamType>& other) const {
168 // Having the same base generator guarantees that the other
169 // iterator is of the same type and we can downcast.
170 GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
171 << "The program attempted to compare iterators "
172 << "from different generators." << std::endl;
173 const Iterator* typed_other =
174 CheckedDowncastToActualType<const Iterator>(&other);
175 // We must report iterators equal if they both point beyond their
176 // respective ranges. That can happen in a variety of fashions,
177 // so we have to consult AtEnd().
178 return (AtEnd() && typed_other->AtEnd()) ||
181 current$(j)_ == typed_other->current$(j)_
186 Iterator(const Iterator& other)
187 : base_(other.base_), $for j, [[
189 begin$(j)_(other.begin$(j)_),
190 end$(j)_(other.end$(j)_),
191 current$(j)_(other.current$(j)_)
193 ComputeCurrentValue();
196 void ComputeCurrentValue() {
198 current_value_.reset(new ParamType($for j, [[*current$(j)_]]));
201 // We must report iterator past the end of the range when either of the
202 // component iterators has reached the end of its range.
206 current$(j)_ == end$(j)_
210 // No implementation - assignment is unsupported.
211 void operator=(const Iterator& other);
213 const ParamGeneratorInterface<ParamType>* const base_;
214 // begin[i]_ and end[i]_ define the i-th range that Iterator traverses.
215 // current[i]_ is the actual traversing iterator.
218 const typename ParamGenerator<T$j>::iterator begin$(j)_;
219 const typename ParamGenerator<T$j>::iterator end$(j)_;
220 typename ParamGenerator<T$j>::iterator current$(j)_;
223 linked_ptr<ParamType> current_value_;
224 }; // class CartesianProductGenerator$i::Iterator
226 // No implementation - assignment is unsupported.
227 void operator=(const CartesianProductGenerator$i& other);
231 const ParamGenerator<T$j> g$(j)_;
234 }; // class CartesianProductGenerator$i
239 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
241 // Helper classes providing Combine() with polymorphic features. They allow
242 // casting CartesianProductGeneratorN<T> to ParamGenerator<U> if T is
249 template <$for j, [[class Generator$j]]>
250 class CartesianProductHolder$i {
252 CartesianProductHolder$i($for j, [[const Generator$j& g$j]])
253 : $for j, [[g$(j)_(g$j)]] {}
254 template <$for j, [[typename T$j]]>
255 operator ParamGenerator< ::testing::tuple<$for j, [[T$j]]> >() const {
256 return ParamGenerator< ::testing::tuple<$for j, [[T$j]]> >(
257 new CartesianProductGenerator$i<$for j, [[T$j]]>(
260 static_cast<ParamGenerator<T$j> >(g$(j)_)
265 // No implementation - assignment is unsupported.
266 void operator=(const CartesianProductHolder$i& other);
270 const Generator$j g$(j)_;
273 }; // class CartesianProductHolder$i
277 # endif // GTEST_HAS_COMBINE
279 } // namespace internal
280 } // namespace testing
282 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_