gtest-param-util-generated.h.pump revision 2079:65f446a2bdd7
11590Srgrimes$$ -*- mode: c++; -*- 21590Srgrimes$var n = 50 $$ Maximum length of Values arguments we want to support. 31590Srgrimes$var maxtuple = 10 $$ Maximum number of Combine arguments we want to support. 41590Srgrimes// Copyright 2008 Google Inc. 51590Srgrimes// All Rights Reserved. 61590Srgrimes// 71590Srgrimes// Redistribution and use in source and binary forms, with or without 81590Srgrimes// modification, are permitted provided that the following conditions are 91590Srgrimes// met: 101590Srgrimes// 111590Srgrimes// * Redistributions of source code must retain the above copyright 121590Srgrimes// notice, this list of conditions and the following disclaimer. 131590Srgrimes// * Redistributions in binary form must reproduce the above 141590Srgrimes// copyright notice, this list of conditions and the following disclaimer 151590Srgrimes// in the documentation and/or other materials provided with the 161590Srgrimes// distribution. 171590Srgrimes// * Neither the name of Google Inc. nor the names of its 181590Srgrimes// contributors may be used to endorse or promote products derived from 191590Srgrimes// this software without specific prior written permission. 201590Srgrimes// 211590Srgrimes// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 221590Srgrimes// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 231590Srgrimes// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 241590Srgrimes// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 251590Srgrimes// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 261590Srgrimes// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 271590Srgrimes// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 281590Srgrimes// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 291590Srgrimes// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 301590Srgrimes// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 311590Srgrimes// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 321590Srgrimes// 3387628Sdwmalone// Author: vladl@google.com (Vlad Losev) 3487628Sdwmalone 3587628Sdwmalone// Type and function utilities for implementing parameterized tests. 3687628Sdwmalone// This file is generated by a SCRIPT. DO NOT EDIT BY HAND! 3787628Sdwmalone// 3887628Sdwmalone// Currently Google Test supports at most $n arguments in Values, 3987231Smarkm// and at most $maxtuple arguments in Combine. Please contact 4087231Smarkm// googletestframework@googlegroups.com if you need more. 4187231Smarkm// Please note that the number of arguments to Combine is limited 4267189Sbrian// by the maximum arity of the implementation of tr1::tuple which is 43204761Sjh// currently set at $maxtuple. 441590Srgrimes 451590Srgrimes#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_ 461590Srgrimes#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_ 471590Srgrimes 48204761Sjh// scripts/fuse_gtest.py depends on gtest's own header being #included 491590Srgrimes// *unconditionally*. Therefore these #includes cannot be moved 501590Srgrimes// inside #if GTEST_HAS_PARAM_TEST. 511590Srgrimes#include "gtest/internal/gtest-param-util.h" 521590Srgrimes#include "gtest/internal/gtest-port.h" 531590Srgrimes 541590Srgrimes#if GTEST_HAS_PARAM_TEST 551590Srgrimes 5671326Swillnamespace testing { 571590Srgrimes 58245048Sdelphij// Forward declarations of ValuesIn(), which is implemented in 5971326Swill// include/gtest/gtest-param-test.h. 6070692Swilltemplate <typename ForwardIterator> 611590Srgrimesinternal::ParamGenerator< 62204761Sjh typename ::testing::internal::IteratorTraits<ForwardIterator>::value_type> 63204761SjhValuesIn(ForwardIterator begin, ForwardIterator end); 64204761Sjh 65204761Sjhtemplate <typename T, size_t N> 6671326Swillinternal::ParamGenerator<T> ValuesIn(const T (&array)[N]); 67204761Sjh 68204761Sjhtemplate <class Container> 691590Srgrimesinternal::ParamGenerator<typename Container::value_type> ValuesIn( 701590Srgrimes const Container& container); 711590Srgrimes 721590Srgrimesnamespace internal { 7370672Swill 741590Srgrimes// Used in the Values() function to provide polymorphic capabilities. 751590Srgrimestemplate <typename T1> 761590Srgrimesclass ValueArray1 { 771590Srgrimes public: 7854157Scharnier explicit ValueArray1(T1 v1) : v1_(v1) {} 791590Srgrimes 801590Srgrimes template <typename T> 811590Srgrimes operator ParamGenerator<T>() const { return ValuesIn(&v1_, &v1_ + 1); } 821590Srgrimes 831590Srgrimes private: 841590Srgrimes // No implementation - assignment is unsupported. 851590Srgrimes void operator=(const ValueArray1& other); 861590Srgrimes 871590Srgrimes const T1 v1_; 8854157Scharnier}; 891590Srgrimes 901590Srgrimes$range i 2..n 911590Srgrimes$for i [[ 921590Srgrimes$range j 1..i 931590Srgrimes 941590Srgrimestemplate <$for j, [[typename T$j]]> 951590Srgrimesclass ValueArray$i { 961590Srgrimes public: 971590Srgrimes ValueArray$i($for j, [[T$j v$j]]) : $for j, [[v$(j)_(v$j)]] {} 981590Srgrimes 991590Srgrimes template <typename T> 1001590Srgrimes operator ParamGenerator<T>() const { 1011590Srgrimes const T array[] = {$for j, [[static_cast<T>(v$(j)_)]]}; 1021590Srgrimes return ValuesIn(array); 1031590Srgrimes } 1041590Srgrimes 1051590Srgrimes private: 1061590Srgrimes // No implementation - assignment is unsupported. 1071590Srgrimes void operator=(const ValueArray$i& other); 1081590Srgrimes 1091590Srgrimes$for j [[ 1101590Srgrimes 1111590Srgrimes const T$j v$(j)_; 1121590Srgrimes]] 11370692Swill 11470692Swill}; 11570692Swill 11670692Swill]] 11770692Swill 11870692Swill# if GTEST_HAS_COMBINE 11970692Swill// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. 12070692Swill// 12170692Swill// Generates values from the Cartesian product of values produced 12270692Swill// by the argument generators. 12370692Swill// 12470692Swill$range i 2..maxtuple 12570692Swill$for i [[ 12670692Swill$range j 1..i 12770692Swill$range k 2..i 12870692Swill 1291590Srgrimestemplate <$for j, [[typename T$j]]> 1301590Srgrimesclass CartesianProductGenerator$i 1311590Srgrimes : public ParamGeneratorInterface< ::std::tr1::tuple<$for j, [[T$j]]> > { 13270692Swill public: 13370692Swill typedef ::std::tr1::tuple<$for j, [[T$j]]> ParamType; 1341590Srgrimes 13571326Swill CartesianProductGenerator$i($for j, [[const ParamGenerator<T$j>& g$j]]) 13671326Swill : $for j, [[g$(j)_(g$j)]] {} 13770692Swill virtual ~CartesianProductGenerator$i() {} 1381590Srgrimes 1398874Srgrimes virtual ParamIteratorInterface<ParamType>* Begin() const { 1401590Srgrimes return new Iterator(this, $for j, [[g$(j)_, g$(j)_.begin()]]); 1411590Srgrimes } 1421590Srgrimes virtual ParamIteratorInterface<ParamType>* End() const { 1431590Srgrimes return new Iterator(this, $for j, [[g$(j)_, g$(j)_.end()]]); 1441590Srgrimes } 1451590Srgrimes 14670692Swill private: 14782057Sbrian class Iterator : public ParamIteratorInterface<ParamType> { 148204761Sjh public: 14970692Swill Iterator(const ParamGeneratorInterface<ParamType>* base, $for j, [[ 15071615Swill 15170692Swill const ParamGenerator<T$j>& g$j, 15270692Swill const typename ParamGenerator<T$j>::iterator& current$(j)]]) 15382057Sbrian : base_(base), 154204761Sjh$for j, [[ 15570692Swill 15671615Swill begin$(j)_(g$j.begin()), end$(j)_(g$j.end()), current$(j)_(current$j) 15770692Swill]] { 1581590Srgrimes ComputeCurrentValue(); 1591590Srgrimes } 1601590Srgrimes virtual ~Iterator() {} 1611590Srgrimes 1621590Srgrimes virtual const ParamGeneratorInterface<ParamType>* BaseGenerator() const { 1631590Srgrimes return base_; 1641590Srgrimes } 1651590Srgrimes // Advance should not be called on beyond-of-range iterators 16670692Swill // so no component iterators must be beyond end of range, either. 16782057Sbrian virtual void Advance() { 168204761Sjh assert(!AtEnd()); 1691590Srgrimes ++current$(i)_; 1701590Srgrimes 1711590Srgrimes$for k [[ 172204761Sjh if (current$(i+2-k)_ == end$(i+2-k)_) { 173204761Sjh current$(i+2-k)_ = begin$(i+2-k)_; 1741590Srgrimes ++current$(i+2-k-1)_; 1751590Srgrimes } 176204761Sjh 177204761Sjh]] 1781590Srgrimes ComputeCurrentValue(); 1791590Srgrimes } 1801590Srgrimes virtual ParamIteratorInterface<ParamType>* Clone() const { 1811590Srgrimes return new Iterator(*this); 1821590Srgrimes } 1831590Srgrimes virtual const ParamType* Current() const { return ¤t_value_; } 184204761Sjh virtual bool Equals(const ParamIteratorInterface<ParamType>& other) const { 1851590Srgrimes // Having the same base generator guarantees that the other 186204761Sjh // iterator is of the same type and we can downcast. 18770692Swill GTEST_CHECK_(BaseGenerator() == other.BaseGenerator()) 188204761Sjh << "The program attempted to compare iterators " 189204761Sjh << "from different generators." << std::endl; 190204761Sjh const Iterator* typed_other = 191204761Sjh CheckedDowncastToActualType<const Iterator>(&other); 192204761Sjh // We must report iterators equal if they both point beyond their 193204761Sjh // respective ranges. That can happen in a variety of fashions, 194204761Sjh // so we have to consult AtEnd(). 195204761Sjh return (AtEnd() && typed_other->AtEnd()) || 196204761Sjh ($for j && [[ 197204761Sjh 1981590Srgrimes current$(j)_ == typed_other->current$(j)_ 1991590Srgrimes]]); 200204761Sjh } 2011590Srgrimes 2021590Srgrimes private: 2031590Srgrimes Iterator(const Iterator& other) 204204761Sjh : base_(other.base_), $for j, [[ 2051590Srgrimes 206204761Sjh begin$(j)_(other.begin$(j)_), 2071590Srgrimes end$(j)_(other.end$(j)_), 2081590Srgrimes current$(j)_(other.current$(j)_) 2091590Srgrimes]] { 2101590Srgrimes ComputeCurrentValue(); 2111590Srgrimes } 212204761Sjh 21370692Swill void ComputeCurrentValue() { 214204761Sjh if (!AtEnd()) 21570692Swill current_value_ = ParamType($for j, [[*current$(j)_]]); 2161590Srgrimes } 2171590Srgrimes bool AtEnd() const { 2181590Srgrimes // We must report iterator past the end of the range when either of the 2191590Srgrimes // component iterators has reached the end of its range. 22070692Swill return 22170692Swill$for j || [[ 22270692Swill 2231590Srgrimes current$(j)_ == end$(j)_ 22470692Swill]]; 225245048Sdelphij } 2261590Srgrimes 2271590Srgrimes // No implementation - assignment is unsupported. 22843928Seivind void operator=(const Iterator& other); 2291590Srgrimes 2301590Srgrimes const ParamGeneratorInterface<ParamType>* const base_; 23170672Swill // begin[i]_ and end[i]_ define the i-th range that Iterator traverses. 2321590Srgrimes // current[i]_ is the actual traversing iterator. 2331590Srgrimes$for j [[ 2341590Srgrimes 23560706Skris const typename ParamGenerator<T$j>::iterator begin$(j)_; 2361590Srgrimes const typename ParamGenerator<T$j>::iterator end$(j)_; 23760706Skris typename ParamGenerator<T$j>::iterator current$(j)_; 2381590Srgrimes]] 2391590Srgrimes 24079452Sbrian ParamType current_value_; 24170692Swill }; // class CartesianProductGenerator$i::Iterator 24260706Skris 2431590Srgrimes // No implementation - assignment is unsupported. 2441590Srgrimes void operator=(const CartesianProductGenerator$i& other); 2451590Srgrimes 24643928Seivind 2471590Srgrimes$for j [[ 2481590Srgrimes const ParamGenerator<T$j> g$(j)_; 2491590Srgrimes 25043928Seivind]] 2511590Srgrimes}; // class CartesianProductGenerator$i 2521590Srgrimes 253245048Sdelphij 25499984Salfred]] 2551590Srgrimes 2561590Srgrimes// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. 2571590Srgrimes// 25870672Swill// Helper classes providing Combine() with polymorphic features. They allow 2591590Srgrimes// casting CartesianProductGeneratorN<T> to ParamGenerator<U> if T is 2601590Srgrimes// convertible to U. 261// 262$range i 2..maxtuple 263$for i [[ 264$range j 1..i 265 266template <$for j, [[class Generator$j]]> 267class CartesianProductHolder$i { 268 public: 269CartesianProductHolder$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]]>( 275$for j,[[ 276 277 static_cast<ParamGenerator<T$j> >(g$(j)_) 278]])); 279 } 280 281 private: 282 // No implementation - assignment is unsupported. 283 void operator=(const CartesianProductHolder$i& other); 284 285 286$for j [[ 287 const Generator$j g$(j)_; 288 289]] 290}; // class CartesianProductHolder$i 291 292]] 293 294# endif // GTEST_HAS_COMBINE 295 296} // namespace internal 297} // namespace testing 298 299#endif // GTEST_HAS_PARAM_TEST 300 301#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_ 302