PageRenderTime 63ms CodeModel.GetById 54ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/firmware/tests/gtest-1.4.0/include/gtest/internal/gtest-param-util-generated.h.pump

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