blob: 5c7c47af0bb1e8898492e05425e40397a4d12f6a [file] [log] [blame]
Austin Schuh0cbef622015-09-06 17:34:52 -07001$$ -*- mode: c++; -*-
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.
6//
7// Redistribution and use in source and binary forms, with or without
8// modification, are permitted provided that the following conditions are
9// met:
10//
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
16// distribution.
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.
20//
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.
32//
33// Author: vladl@google.com (Vlad Losev)
34
35// Type and function utilities for implementing parameterized tests.
36// This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
37//
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.
44
45#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_
46#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_
47
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"
53
54#if GTEST_HAS_PARAM_TEST
55
56namespace testing {
57
58// Forward declarations of ValuesIn(), which is implemented in
59// include/gtest/gtest-param-test.h.
60template <typename ForwardIterator>
61internal::ParamGenerator<
62 typename ::testing::internal::IteratorTraits<ForwardIterator>::value_type>
63ValuesIn(ForwardIterator begin, ForwardIterator end);
64
65template <typename T, size_t N>
66internal::ParamGenerator<T> ValuesIn(const T (&array)[N]);
67
68template <class Container>
69internal::ParamGenerator<typename Container::value_type> ValuesIn(
70 const Container& container);
71
72namespace internal {
73
74// Used in the Values() function to provide polymorphic capabilities.
75$range i 1..n
76$for i [[
77$range j 1..i
78
79template <$for j, [[typename T$j]]>
80class ValueArray$i {
81 public:
82 $if i==1 [[explicit ]]ValueArray$i($for j, [[T$j v$j]]) : $for j, [[v$(j)_(v$j)]] {}
83
84 template <typename T>
85 operator ParamGenerator<T>() const {
86 const T array[] = {$for j, [[static_cast<T>(v$(j)_)]]};
87 return ValuesIn(array);
88 }
89
90 private:
91 // No implementation - assignment is unsupported.
92 void operator=(const ValueArray$i& other);
93
94$for j [[
95
96 const T$j v$(j)_;
97]]
98
99};
100
101]]
102
103# if GTEST_HAS_COMBINE
104// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
105//
106// Generates values from the Cartesian product of values produced
107// by the argument generators.
108//
109$range i 2..maxtuple
110$for i [[
111$range j 1..i
112$range k 2..i
113
114template <$for j, [[typename T$j]]>
115class CartesianProductGenerator$i
116 : public ParamGeneratorInterface< ::testing::tuple<$for j, [[T$j]]> > {
117 public:
118 typedef ::testing::tuple<$for j, [[T$j]]> ParamType;
119
120 CartesianProductGenerator$i($for j, [[const ParamGenerator<T$j>& g$j]])
121 : $for j, [[g$(j)_(g$j)]] {}
122 virtual ~CartesianProductGenerator$i() {}
123
124 virtual ParamIteratorInterface<ParamType>* Begin() const {
125 return new Iterator(this, $for j, [[g$(j)_, g$(j)_.begin()]]);
126 }
127 virtual ParamIteratorInterface<ParamType>* End() const {
128 return new Iterator(this, $for j, [[g$(j)_, g$(j)_.end()]]);
129 }
130
131 private:
132 class Iterator : public ParamIteratorInterface<ParamType> {
133 public:
134 Iterator(const ParamGeneratorInterface<ParamType>* base, $for j, [[
135
136 const ParamGenerator<T$j>& g$j,
137 const typename ParamGenerator<T$j>::iterator& current$(j)]])
138 : base_(base),
139$for j, [[
140
141 begin$(j)_(g$j.begin()), end$(j)_(g$j.end()), current$(j)_(current$j)
142]] {
143 ComputeCurrentValue();
144 }
145 virtual ~Iterator() {}
146
147 virtual const ParamGeneratorInterface<ParamType>* BaseGenerator() const {
148 return base_;
149 }
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() {
153 assert(!AtEnd());
154 ++current$(i)_;
155
156$for k [[
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)_;
160 }
161
162]]
163 ComputeCurrentValue();
164 }
165 virtual ParamIteratorInterface<ParamType>* Clone() const {
166 return new Iterator(*this);
167 }
168 virtual const ParamType* Current() const { return &current_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()) ||
181 ($for j && [[
182
183 current$(j)_ == typed_other->current$(j)_
184]]);
185 }
186
187 private:
188 Iterator(const Iterator& other)
189 : base_(other.base_), $for j, [[
190
191 begin$(j)_(other.begin$(j)_),
192 end$(j)_(other.end$(j)_),
193 current$(j)_(other.current$(j)_)
194]] {
195 ComputeCurrentValue();
196 }
197
198 void ComputeCurrentValue() {
199 if (!AtEnd())
200 current_value_ = ParamType($for j, [[*current$(j)_]]);
201 }
202 bool AtEnd() const {
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.
205 return
206$for j || [[
207
208 current$(j)_ == end$(j)_
209]];
210 }
211
212 // No implementation - assignment is unsupported.
213 void operator=(const Iterator& other);
214
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.
218$for j [[
219
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)_;
223]]
224
225 ParamType current_value_;
226 }; // class CartesianProductGenerator$i::Iterator
227
228 // No implementation - assignment is unsupported.
229 void operator=(const CartesianProductGenerator$i& other);
230
231
232$for j [[
233 const ParamGenerator<T$j> g$(j)_;
234
235]]
236}; // class CartesianProductGenerator$i
237
238
239]]
240
241// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
242//
243// Helper classes providing Combine() with polymorphic features. They allow
244// casting CartesianProductGeneratorN<T> to ParamGenerator<U> if T is
245// convertible to U.
246//
247$range i 2..maxtuple
248$for i [[
249$range j 1..i
250
251template <$for j, [[class Generator$j]]>
252class CartesianProductHolder$i {
253 public:
254CartesianProductHolder$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]]>(
260$for j,[[
261
262 static_cast<ParamGenerator<T$j> >(g$(j)_)
263]]));
264 }
265
266 private:
267 // No implementation - assignment is unsupported.
268 void operator=(const CartesianProductHolder$i& other);
269
270
271$for j [[
272 const Generator$j g$(j)_;
273
274]]
275}; // class CartesianProductHolder$i
276
277]]
278
279# endif // GTEST_HAS_COMBINE
280
281} // namespace internal
282} // namespace testing
283
284#endif // GTEST_HAS_PARAM_TEST
285
286#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_