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.
33 // Author: vladl@google.com (Vlad Losev)
35 // Type and function utilities for implementing parameterized tests.
36 // This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
38 // Currently Google Test supports at most $n arguments in Values,
39 // and at most $maxtuple arguments in Combine. Please contact
40 // googletestframework@googlegroups.com if you need more.
41 // Please note that the number of arguments to Combine is limited
42 // by the maximum arity of the implementation of tuple which is
43 // currently set at $maxtuple.
45 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_
46 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_
48 // scripts/fuse_gtest.py depends on gtest's own header being #included
49 // *unconditionally*. Therefore these #includes cannot be moved
50 // inside #if GTEST_HAS_PARAM_TEST.
51 #include "gtest/internal/gtest-param-util.h"
52 #include "gtest/internal/gtest-port.h"
54 #if GTEST_HAS_PARAM_TEST
58 // Forward declarations of ValuesIn(), which is implemented in
59 // include/gtest/gtest-param-test.h.
60 template <typename ForwardIterator>
61 internal::ParamGenerator<
62 typename ::testing::internal::IteratorTraits<ForwardIterator>::value_type>
63 ValuesIn(ForwardIterator begin, ForwardIterator end);
65 template <typename T, size_t N>
66 internal::ParamGenerator<T> ValuesIn(const T (&array)[N]);
68 template <class Container>
69 internal::ParamGenerator<typename Container::value_type> ValuesIn(
70 const Container& container);
74 // Used in the Values() function to provide polymorphic capabilities.
79 template <$for j, [[typename T$j]]>
82 $if i==1 [[explicit ]]ValueArray$i($for j, [[T$j v$j]]) : $for j, [[v$(j)_(v$j)]] {}
85 operator ParamGenerator<T>() const {
86 const T array[] = {$for j, [[static_cast<T>(v$(j)_)]]};
87 return ValuesIn(array);
91 // No implementation - assignment is unsupported.
92 void operator=(const ValueArray$i& other);
103 # if GTEST_HAS_COMBINE
104 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
106 // Generates values from the Cartesian product of values produced
107 // by the argument generators.
114 template <$for j, [[typename T$j]]>
115 class CartesianProductGenerator$i
116 : public ParamGeneratorInterface< ::testing::tuple<$for j, [[T$j]]> > {
118 typedef ::testing::tuple<$for j, [[T$j]]> ParamType;
120 CartesianProductGenerator$i($for j, [[const ParamGenerator<T$j>& g$j]])
121 : $for j, [[g$(j)_(g$j)]] {}
122 virtual ~CartesianProductGenerator$i() {}
124 virtual ParamIteratorInterface<ParamType>* Begin() const {
125 return new Iterator(this, $for j, [[g$(j)_, g$(j)_.begin()]]);
127 virtual ParamIteratorInterface<ParamType>* End() const {
128 return new Iterator(this, $for j, [[g$(j)_, g$(j)_.end()]]);
132 class Iterator : public ParamIteratorInterface<ParamType> {
134 Iterator(const ParamGeneratorInterface<ParamType>* base, $for j, [[
136 const ParamGenerator<T$j>& g$j,
137 const typename ParamGenerator<T$j>::iterator& current$(j)]])
141 begin$(j)_(g$j.begin()), end$(j)_(g$j.end()), current$(j)_(current$j)
143 ComputeCurrentValue();
145 virtual ~Iterator() {}
147 virtual const ParamGeneratorInterface<ParamType>* BaseGenerator() const {
150 // Advance should not be called on beyond-of-range iterators
151 // so no component iterators must be beyond end of range, either.
152 virtual void Advance() {
157 if (current$(i+2-k)_ == end$(i+2-k)_) {
158 current$(i+2-k)_ = begin$(i+2-k)_;
159 ++current$(i+2-k-1)_;
163 ComputeCurrentValue();
165 virtual ParamIteratorInterface<ParamType>* Clone() const {
166 return new Iterator(*this);
168 virtual const ParamType* Current() const { return ¤t_value_; }
169 virtual bool Equals(const ParamIteratorInterface<ParamType>& other) const {
170 // Having the same base generator guarantees that the other
171 // iterator is of the same type and we can downcast.
172 GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
173 << "The program attempted to compare iterators "
174 << "from different generators." << std::endl;
175 const Iterator* typed_other =
176 CheckedDowncastToActualType<const Iterator>(&other);
177 // We must report iterators equal if they both point beyond their
178 // respective ranges. That can happen in a variety of fashions,
179 // so we have to consult AtEnd().
180 return (AtEnd() && typed_other->AtEnd()) ||
183 current$(j)_ == typed_other->current$(j)_
188 Iterator(const Iterator& other)
189 : base_(other.base_), $for j, [[
191 begin$(j)_(other.begin$(j)_),
192 end$(j)_(other.end$(j)_),
193 current$(j)_(other.current$(j)_)
195 ComputeCurrentValue();
198 void ComputeCurrentValue() {
200 current_value_ = ParamType($for j, [[*current$(j)_]]);
203 // We must report iterator past the end of the range when either of the
204 // component iterators has reached the end of its range.
208 current$(j)_ == end$(j)_
212 // No implementation - assignment is unsupported.
213 void operator=(const Iterator& other);
215 const ParamGeneratorInterface<ParamType>* const base_;
216 // begin[i]_ and end[i]_ define the i-th range that Iterator traverses.
217 // current[i]_ is the actual traversing iterator.
220 const typename ParamGenerator<T$j>::iterator begin$(j)_;
221 const typename ParamGenerator<T$j>::iterator end$(j)_;
222 typename ParamGenerator<T$j>::iterator current$(j)_;
225 ParamType current_value_;
226 }; // class CartesianProductGenerator$i::Iterator
228 // No implementation - assignment is unsupported.
229 void operator=(const CartesianProductGenerator$i& other);
233 const ParamGenerator<T$j> g$(j)_;
236 }; // class CartesianProductGenerator$i
241 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
243 // Helper classes providing Combine() with polymorphic features. They allow
244 // casting CartesianProductGeneratorN<T> to ParamGenerator<U> if T is
251 template <$for j, [[class Generator$j]]>
252 class CartesianProductHolder$i {
254 CartesianProductHolder$i($for j, [[const Generator$j& g$j]])
255 : $for j, [[g$(j)_(g$j)]] {}
256 template <$for j, [[typename T$j]]>
257 operator ParamGenerator< ::testing::tuple<$for j, [[T$j]]> >() const {
258 return ParamGenerator< ::testing::tuple<$for j, [[T$j]]> >(
259 new CartesianProductGenerator$i<$for j, [[T$j]]>(
262 static_cast<ParamGenerator<T$j> >(g$(j)_)
267 // No implementation - assignment is unsupported.
268 void operator=(const CartesianProductHolder$i& other);
272 const Generator$j g$(j)_;
275 }; // class CartesianProductHolder$i
279 # endif // GTEST_HAS_COMBINE
281 } // namespace internal
282 } // namespace testing
284 #endif // GTEST_HAS_PARAM_TEST
286 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_