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 tr1::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.
75 template <typename T1>
78 explicit ValueArray1(T1 v1) : v1_(v1) {}
81 operator ParamGenerator<T>() const { return ValuesIn(&v1_, &v1_ + 1); }
84 // No implementation - assignment is unsupported.
85 void operator=(const ValueArray1& other);
94 template <$for j, [[typename T$j]]>
97 ValueArray$i($for j, [[T$j v$j]]) : $for j, [[v$(j)_(v$j)]] {}
100 operator ParamGenerator<T>() const {
101 const T array[] = {$for j, [[v$(j)_]]};
102 return ValuesIn(array);
106 // No implementation - assignment is unsupported.
107 void operator=(const ValueArray$i& other);
118 # if GTEST_HAS_COMBINE
119 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
121 // Generates values from the Cartesian product of values produced
122 // by the argument generators.
129 template <$for j, [[typename T$j]]>
130 class CartesianProductGenerator$i
131 : public ParamGeneratorInterface< ::std::tr1::tuple<$for j, [[T$j]]> > {
133 typedef ::std::tr1::tuple<$for j, [[T$j]]> ParamType;
135 CartesianProductGenerator$i($for j, [[const ParamGenerator<T$j>& g$j]])
136 : $for j, [[g$(j)_(g$j)]] {}
137 virtual ~CartesianProductGenerator$i() {}
139 virtual ParamIteratorInterface<ParamType>* Begin() const {
140 return new Iterator(this, $for j, [[g$(j)_, g$(j)_.begin()]]);
142 virtual ParamIteratorInterface<ParamType>* End() const {
143 return new Iterator(this, $for j, [[g$(j)_, g$(j)_.end()]]);
147 class Iterator : public ParamIteratorInterface<ParamType> {
149 Iterator(const ParamGeneratorInterface<ParamType>* base, $for j, [[
151 const ParamGenerator<T$j>& g$j,
152 const typename ParamGenerator<T$j>::iterator& current$(j)]])
156 begin$(j)_(g$j.begin()), end$(j)_(g$j.end()), current$(j)_(current$j)
158 ComputeCurrentValue();
160 virtual ~Iterator() {}
162 virtual const ParamGeneratorInterface<ParamType>* BaseGenerator() const {
165 // Advance should not be called on beyond-of-range iterators
166 // so no component iterators must be beyond end of range, either.
167 virtual void Advance() {
172 if (current$(i+2-k)_ == end$(i+2-k)_) {
173 current$(i+2-k)_ = begin$(i+2-k)_;
174 ++current$(i+2-k-1)_;
178 ComputeCurrentValue();
180 virtual ParamIteratorInterface<ParamType>* Clone() const {
181 return new Iterator(*this);
183 virtual const ParamType* Current() const { return ¤t_value_; }
184 virtual bool Equals(const ParamIteratorInterface<ParamType>& other) const {
185 // Having the same base generator guarantees that the other
186 // iterator is of the same type and we can downcast.
187 GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
188 << "The program attempted to compare iterators "
189 << "from different generators." << std::endl;
190 const Iterator* typed_other =
191 CheckedDowncastToActualType<const Iterator>(&other);
192 // We must report iterators equal if they both point beyond their
193 // respective ranges. That can happen in a variety of fashions,
194 // so we have to consult AtEnd().
195 return (AtEnd() && typed_other->AtEnd()) ||
198 current$(j)_ == typed_other->current$(j)_
203 Iterator(const Iterator& other)
204 : base_(other.base_), $for j, [[
206 begin$(j)_(other.begin$(j)_),
207 end$(j)_(other.end$(j)_),
208 current$(j)_(other.current$(j)_)
210 ComputeCurrentValue();
213 void ComputeCurrentValue() {
215 current_value_ = ParamType($for j, [[*current$(j)_]]);
218 // We must report iterator past the end of the range when either of the
219 // component iterators has reached the end of its range.
223 current$(j)_ == end$(j)_
227 // No implementation - assignment is unsupported.
228 void operator=(const Iterator& other);
230 const ParamGeneratorInterface<ParamType>* const base_;
231 // begin[i]_ and end[i]_ define the i-th range that Iterator traverses.
232 // current[i]_ is the actual traversing iterator.
235 const typename ParamGenerator<T$j>::iterator begin$(j)_;
236 const typename ParamGenerator<T$j>::iterator end$(j)_;
237 typename ParamGenerator<T$j>::iterator current$(j)_;
240 ParamType current_value_;
241 }; // class CartesianProductGenerator$i::Iterator
243 // No implementation - assignment is unsupported.
244 void operator=(const CartesianProductGenerator$i& other);
248 const ParamGenerator<T$j> g$(j)_;
251 }; // class CartesianProductGenerator$i
256 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
258 // Helper classes providing Combine() with polymorphic features. They allow
259 // casting CartesianProductGeneratorN<T> to ParamGenerator<U> if T is
266 template <$for j, [[class Generator$j]]>
267 class CartesianProductHolder$i {
269 CartesianProductHolder$i($for j, [[const Generator$j& g$j]])
270 : $for j, [[g$(j)_(g$j)]] {}
271 template <$for j, [[typename T$j]]>
272 operator ParamGenerator< ::std::tr1::tuple<$for j, [[T$j]]> >() const {
273 return ParamGenerator< ::std::tr1::tuple<$for j, [[T$j]]> >(
274 new CartesianProductGenerator$i<$for j, [[T$j]]>(
277 static_cast<ParamGenerator<T$j> >(g$(j)_)
282 // No implementation - assignment is unsupported.
283 void operator=(const CartesianProductHolder$i& other);
287 const Generator$j g$(j)_;
290 }; // class CartesianProductHolder$i
294 # endif // GTEST_HAS_COMBINE
296 } // namespace internal
297 } // namespace testing
299 #endif // GTEST_HAS_PARAM_TEST
301 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_