gtest-param-util-generated.h.pump revision fbaaef999ba563838ebd00874ed8a1c01fbf286d
1$$ -*- 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 tr1::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#include <gtest/internal/gtest-port.h> 49 50#if GTEST_HAS_PARAM_TEST 51 52#include <gtest/internal/gtest-param-util.h> 53 54namespace testing { 55namespace internal { 56 57// Used in the Values() function to provide polymorphic capabilities. 58template <typename T1> 59class ValueArray1 { 60 public: 61 explicit ValueArray1(T1 v1) : v1_(v1) {} 62 63 template <typename T> 64 operator ParamGenerator<T>() const { return ValuesIn(&v1_, &v1_ + 1); } 65 66 private: 67 const T1 v1_; 68}; 69 70$range i 2..n 71$for i [[ 72$range j 1..i 73 74template <$for j, [[typename T$j]]> 75class ValueArray$i { 76 public: 77 ValueArray$i($for j, [[T$j v$j]]) : $for j, [[v$(j)_(v$j)]] {} 78 79 template <typename T> 80 operator ParamGenerator<T>() const { 81 const T array[] = {$for j, [[v$(j)_]]}; 82 return ValuesIn(array); 83 } 84 85 private: 86$for j [[ 87 88 const T$j v$(j)_; 89]] 90 91}; 92 93]] 94 95#if GTEST_HAS_COMBINE 96// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. 97// 98// Generates values from the Cartesian product of values produced 99// by the argument generators. 100// 101$range i 2..maxtuple 102$for i [[ 103$range j 1..i 104$range k 2..i 105 106template <$for j, [[typename T$j]]> 107class CartesianProductGenerator$i 108 : public ParamGeneratorInterface< ::std::tr1::tuple<$for j, [[T$j]]> > { 109 public: 110 typedef ::std::tr1::tuple<$for j, [[T$j]]> ParamType; 111 112 CartesianProductGenerator$i($for j, [[const ParamGenerator<T$j>& g$j]]) 113 : $for j, [[g$(j)_(g$j)]] {} 114 virtual ~CartesianProductGenerator$i() {} 115 116 virtual ParamIteratorInterface<ParamType>* Begin() const { 117 return new Iterator(this, $for j, [[g$(j)_, g$(j)_.begin()]]); 118 } 119 virtual ParamIteratorInterface<ParamType>* End() const { 120 return new Iterator(this, $for j, [[g$(j)_, g$(j)_.end()]]); 121 } 122 123 private: 124 class Iterator : public ParamIteratorInterface<ParamType> { 125 public: 126 Iterator(const ParamGeneratorInterface<ParamType>* base, $for j, [[ 127 128 const ParamGenerator<T$j>& g$j, 129 const typename ParamGenerator<T$j>::iterator& current$(j)]]) 130 : base_(base), 131$for j, [[ 132 133 begin$(j)_(g$j.begin()), end$(j)_(g$j.end()), current$(j)_(current$j) 134]] { 135 ComputeCurrentValue(); 136 } 137 virtual ~Iterator() {} 138 139 virtual const ParamGeneratorInterface<ParamType>* BaseGenerator() const { 140 return base_; 141 } 142 // Advance should not be called on beyond-of-range iterators 143 // so no component iterators must be beyond end of range, either. 144 virtual void Advance() { 145 assert(!AtEnd()); 146 ++current$(i)_; 147 148$for k [[ 149 if (current$(i+2-k)_ == end$(i+2-k)_) { 150 current$(i+2-k)_ = begin$(i+2-k)_; 151 ++current$(i+2-k-1)_; 152 } 153 154]] 155 ComputeCurrentValue(); 156 } 157 virtual ParamIteratorInterface<ParamType>* Clone() const { 158 return new Iterator(*this); 159 } 160 virtual const ParamType* Current() const { return ¤t_value_; } 161 virtual bool Equals(const ParamIteratorInterface<ParamType>& other) const { 162 // Having the same base generator guarantees that the other 163 // iterator is of the same type and we can downcast. 164 GTEST_CHECK_(BaseGenerator() == other.BaseGenerator()) 165 << "The program attempted to compare iterators " 166 << "from different generators." << std::endl; 167 const Iterator* typed_other = 168 CheckedDowncastToActualType<const Iterator>(&other); 169 // We must report iterators equal if they both point beyond their 170 // respective ranges. That can happen in a variety of fashions, 171 // so we have to consult AtEnd(). 172 return (AtEnd() && typed_other->AtEnd()) || 173 ($for j && [[ 174 175 current$(j)_ == typed_other->current$(j)_ 176]]); 177 } 178 179 private: 180 Iterator(const Iterator& other) 181 : base_(other.base_), $for j, [[ 182 183 begin$(j)_(other.begin$(j)_), 184 end$(j)_(other.end$(j)_), 185 current$(j)_(other.current$(j)_) 186]] { 187 ComputeCurrentValue(); 188 } 189 190 void ComputeCurrentValue() { 191 if (!AtEnd()) 192 current_value_ = ParamType($for j, [[*current$(j)_]]); 193 } 194 bool AtEnd() const { 195 // We must report iterator past the end of the range when either of the 196 // component iterators has reached the end of its range. 197 return 198$for j || [[ 199 200 current$(j)_ == end$(j)_ 201]]; 202 } 203 204 const ParamGeneratorInterface<ParamType>* const base_; 205 // begin[i]_ and end[i]_ define the i-th range that Iterator traverses. 206 // current[i]_ is the actual traversing iterator. 207$for j [[ 208 209 const typename ParamGenerator<T$j>::iterator begin$(j)_; 210 const typename ParamGenerator<T$j>::iterator end$(j)_; 211 typename ParamGenerator<T$j>::iterator current$(j)_; 212]] 213 214 ParamType current_value_; 215 }; 216 217 218$for j [[ 219 const ParamGenerator<T$j> g$(j)_; 220 221]] 222}; 223 224 225]] 226 227// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. 228// 229// Helper classes providing Combine() with polymorphic features. They allow 230// casting CartesianProductGeneratorN<T> to ParamGenerator<U> if T is 231// convertible to U. 232// 233$range i 2..maxtuple 234$for i [[ 235$range j 1..i 236 237template <$for j, [[class Generator$j]]> 238class CartesianProductHolder$i { 239 public: 240CartesianProductHolder$i($for j, [[const Generator$j& g$j]]) 241 : $for j, [[g$(j)_(g$j)]] {} 242 template <$for j, [[typename T$j]]> 243 operator ParamGenerator< ::std::tr1::tuple<$for j, [[T$j]]> >() const { 244 return ParamGenerator< ::std::tr1::tuple<$for j, [[T$j]]> >( 245 new CartesianProductGenerator$i<$for j, [[T$j]]>( 246$for j,[[ 247 248 static_cast<ParamGenerator<T$j> >(g$(j)_) 249]])); 250 } 251 252 private: 253 254$for j [[ 255 const Generator$j g$(j)_; 256 257]] 258}; 259 260]] 261 262#endif // GTEST_HAS_COMBINE 263 264} // namespace internal 265} // namespace testing 266 267#endif // GTEST_HAS_PARAM_TEST 268 269#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_ 270