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 #include "gtest/internal/gtest-param-util.h"
49 #include "gtest/internal/gtest-port.h"
53 // Forward declarations of ValuesIn(), which is implemented in
54 // include/gtest/gtest-param-test.h.
55 template <typename ForwardIterator>
56 internal::ParamGenerator<
57 typename ::testing::internal::IteratorTraits<ForwardIterator>::value_type>
58 ValuesIn(ForwardIterator begin, ForwardIterator end);
60 template <typename T, size_t N>
61 internal::ParamGenerator<T> ValuesIn(const T (&array)[N]);
63 template <class Container>
64 internal::ParamGenerator<typename Container::value_type> ValuesIn(
65 const Container& container);
69 // Used in the Values() function to provide polymorphic capabilities.
74 template <$for j, [[typename T$j]]>
77 $if i==1 [[explicit ]]ValueArray$i($for j, [[T$j v$j]]) : $for j, [[v$(j)_(v$j)]] {}
80 operator ParamGenerator<T>() const {
81 const T array[] = {$for j, [[static_cast<T>(v$(j)_)]]};
82 return ValuesIn(array);
86 // No implementation - assignment is unsupported.
87 void operator=(const ValueArray$i& other);
98 # if GTEST_HAS_COMBINE
99 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
101 // Generates values from the Cartesian product of values produced
102 // by the argument generators.
109 template <$for j, [[typename T$j]]>
110 class CartesianProductGenerator$i
111 : public ParamGeneratorInterface< ::testing::tuple<$for j, [[T$j]]> > {
113 typedef ::testing::tuple<$for j, [[T$j]]> ParamType;
115 CartesianProductGenerator$i($for j, [[const ParamGenerator<T$j>& g$j]])
116 : $for j, [[g$(j)_(g$j)]] {}
117 virtual ~CartesianProductGenerator$i() {}
119 virtual ParamIteratorInterface<ParamType>* Begin() const {
120 return new Iterator(this, $for j, [[g$(j)_, g$(j)_.begin()]]);
122 virtual ParamIteratorInterface<ParamType>* End() const {
123 return new Iterator(this, $for j, [[g$(j)_, g$(j)_.end()]]);
127 class Iterator : public ParamIteratorInterface<ParamType> {
129 Iterator(const ParamGeneratorInterface<ParamType>* base, $for j, [[
131 const ParamGenerator<T$j>& g$j,
132 const typename ParamGenerator<T$j>::iterator& current$(j)]])
136 begin$(j)_(g$j.begin()), end$(j)_(g$j.end()), current$(j)_(current$j)
138 ComputeCurrentValue();
140 virtual ~Iterator() {}
142 virtual const ParamGeneratorInterface<ParamType>* BaseGenerator() const {
145 // Advance should not be called on beyond-of-range iterators
146 // so no component iterators must be beyond end of range, either.
147 virtual void Advance() {
152 if (current$(i+2-k)_ == end$(i+2-k)_) {
153 current$(i+2-k)_ = begin$(i+2-k)_;
154 ++current$(i+2-k-1)_;
158 ComputeCurrentValue();
160 virtual ParamIteratorInterface<ParamType>* Clone() const {
161 return new Iterator(*this);
163 virtual const ParamType* Current() const { return current_value_.get(); }
164 virtual bool Equals(const ParamIteratorInterface<ParamType>& other) const {
165 // Having the same base generator guarantees that the other
166 // iterator is of the same type and we can downcast.
167 GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
168 << "The program attempted to compare iterators "
169 << "from different generators." << std::endl;
170 const Iterator* typed_other =
171 CheckedDowncastToActualType<const Iterator>(&other);
172 // We must report iterators equal if they both point beyond their
173 // respective ranges. That can happen in a variety of fashions,
174 // so we have to consult AtEnd().
175 return (AtEnd() && typed_other->AtEnd()) ||
178 current$(j)_ == typed_other->current$(j)_
183 Iterator(const Iterator& other)
184 : base_(other.base_), $for j, [[
186 begin$(j)_(other.begin$(j)_),
187 end$(j)_(other.end$(j)_),
188 current$(j)_(other.current$(j)_)
190 ComputeCurrentValue();
193 void ComputeCurrentValue() {
195 current_value_.reset(new ParamType($for j, [[*current$(j)_]]));
198 // We must report iterator past the end of the range when either of the
199 // component iterators has reached the end of its range.
203 current$(j)_ == end$(j)_
207 // No implementation - assignment is unsupported.
208 void operator=(const Iterator& other);
210 const ParamGeneratorInterface<ParamType>* const base_;
211 // begin[i]_ and end[i]_ define the i-th range that Iterator traverses.
212 // current[i]_ is the actual traversing iterator.
215 const typename ParamGenerator<T$j>::iterator begin$(j)_;
216 const typename ParamGenerator<T$j>::iterator end$(j)_;
217 typename ParamGenerator<T$j>::iterator current$(j)_;
220 linked_ptr<ParamType> current_value_;
221 }; // class CartesianProductGenerator$i::Iterator
223 // No implementation - assignment is unsupported.
224 void operator=(const CartesianProductGenerator$i& other);
228 const ParamGenerator<T$j> g$(j)_;
231 }; // class CartesianProductGenerator$i
236 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
238 // Helper classes providing Combine() with polymorphic features. They allow
239 // casting CartesianProductGeneratorN<T> to ParamGenerator<U> if T is
246 template <$for j, [[class Generator$j]]>
247 class CartesianProductHolder$i {
249 CartesianProductHolder$i($for j, [[const Generator$j& g$j]])
250 : $for j, [[g$(j)_(g$j)]] {}
251 template <$for j, [[typename T$j]]>
252 operator ParamGenerator< ::testing::tuple<$for j, [[T$j]]> >() const {
253 return ParamGenerator< ::testing::tuple<$for j, [[T$j]]> >(
254 new CartesianProductGenerator$i<$for j, [[T$j]]>(
257 static_cast<ParamGenerator<T$j> >(g$(j)_)
262 // No implementation - assignment is unsupported.
263 void operator=(const CartesianProductHolder$i& other);
267 const Generator$j g$(j)_;
270 }; // class CartesianProductHolder$i
274 # endif // GTEST_HAS_COMBINE
276 } // namespace internal
277 } // namespace testing
279 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_