gtest-param-util-generated.h.pump 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. // Type and function utilities for implementing parameterized tests.
  35. // This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
  36. //
  37. // Currently Google Test supports at most $n arguments in Values,
  38. // and at most $maxtuple arguments in Combine. Please contact
  39. // googletestframework@googlegroups.com if you need more.
  40. // Please note that the number of arguments to Combine is limited
  41. // by the maximum arity of the implementation of tr1::tuple which is
  42. // currently set at $maxtuple.
  43. #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_
  44. #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_
  45. // scripts/fuse_gtest.py depends on gtest's own header being #included
  46. // *unconditionally*. Therefore these #includes cannot be moved
  47. // inside #if GTEST_HAS_PARAM_TEST.
  48. #include "gtest/internal/gtest-param-util.h"
  49. #include "gtest/internal/gtest-port.h"
  50. #if GTEST_HAS_PARAM_TEST
  51. namespace testing {
  52. // Forward declarations of ValuesIn(), which is implemented in
  53. // include/gtest/gtest-param-test.h.
  54. template <typename ForwardIterator>
  55. internal::ParamGenerator<
  56. typename ::testing::internal::IteratorTraits<ForwardIterator>::value_type>
  57. ValuesIn(ForwardIterator begin, ForwardIterator end);
  58. template <typename T, size_t N>
  59. internal::ParamGenerator<T> ValuesIn(const T (&array)[N]);
  60. template <class Container>
  61. internal::ParamGenerator<typename Container::value_type> ValuesIn(
  62. const Container& container);
  63. namespace internal {
  64. // Used in the Values() function to provide polymorphic capabilities.
  65. template <typename T1>
  66. class ValueArray1 {
  67. public:
  68. explicit ValueArray1(T1 v1) : v1_(v1) {}
  69. template <typename T>
  70. operator ParamGenerator<T>() const { return ValuesIn(&v1_, &v1_ + 1); }
  71. private:
  72. // No implementation - assignment is unsupported.
  73. void operator=(const ValueArray1& other);
  74. const T1 v1_;
  75. };
  76. $range i 2..n
  77. $for i [[
  78. $range j 1..i
  79. template <$for j, [[typename T$j]]>
  80. class ValueArray$i {
  81. public:
  82. ValueArray$i($for j, [[T$j v$j]]) : $for j, [[v$(j)_(v$j)]] {}
  83. template <typename T>
  84. operator ParamGenerator<T>() const {
  85. const T array[] = {$for j, [[static_cast<T>(v$(j)_)]]};
  86. return ValuesIn(array);
  87. }
  88. private:
  89. // No implementation - assignment is unsupported.
  90. void operator=(const ValueArray$i& other);
  91. $for j [[
  92. const T$j v$(j)_;
  93. ]]
  94. };
  95. ]]
  96. # if GTEST_HAS_COMBINE
  97. // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
  98. //
  99. // Generates values from the Cartesian product of values produced
  100. // by the argument generators.
  101. //
  102. $range i 2..maxtuple
  103. $for i [[
  104. $range j 1..i
  105. $range k 2..i
  106. template <$for j, [[typename T$j]]>
  107. class 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. CartesianProductGenerator$i($for j, [[const ParamGenerator<T$j>& g$j]])
  112. : $for j, [[g$(j)_(g$j)]] {}
  113. virtual ~CartesianProductGenerator$i() {}
  114. virtual ParamIteratorInterface<ParamType>* Begin() const {
  115. return new Iterator(this, $for j, [[g$(j)_, g$(j)_.begin()]]);
  116. }
  117. virtual ParamIteratorInterface<ParamType>* End() const {
  118. return new Iterator(this, $for j, [[g$(j)_, g$(j)_.end()]]);
  119. }
  120. private:
  121. class Iterator : public ParamIteratorInterface<ParamType> {
  122. public:
  123. Iterator(const ParamGeneratorInterface<ParamType>* base, $for j, [[
  124. const ParamGenerator<T$j>& g$j,
  125. const typename ParamGenerator<T$j>::iterator& current$(j)]])
  126. : base_(base),
  127. $for j, [[
  128. begin$(j)_(g$j.begin()), end$(j)_(g$j.end()), current$(j)_(current$j)
  129. ]] {
  130. ComputeCurrentValue();
  131. }
  132. virtual ~Iterator() {}
  133. virtual const ParamGeneratorInterface<ParamType>* BaseGenerator() const {
  134. return base_;
  135. }
  136. // Advance should not be called on beyond-of-range iterators
  137. // so no component iterators must be beyond end of range, either.
  138. virtual void Advance() {
  139. assert(!AtEnd());
  140. ++current$(i)_;
  141. $for k [[
  142. if (current$(i+2-k)_ == end$(i+2-k)_) {
  143. current$(i+2-k)_ = begin$(i+2-k)_;
  144. ++current$(i+2-k-1)_;
  145. }
  146. ]]
  147. ComputeCurrentValue();
  148. }
  149. virtual ParamIteratorInterface<ParamType>* Clone() const {
  150. return new Iterator(*this);
  151. }
  152. virtual const ParamType* Current() const { return &current_value_; }
  153. virtual bool Equals(const ParamIteratorInterface<ParamType>& other) const {
  154. // Having the same base generator guarantees that the other
  155. // iterator is of the same type and we can downcast.
  156. GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
  157. << "The program attempted to compare iterators "
  158. << "from different generators." << std::endl;
  159. const Iterator* typed_other =
  160. CheckedDowncastToActualType<const Iterator>(&other);
  161. // We must report iterators equal if they both point beyond their
  162. // respective ranges. That can happen in a variety of fashions,
  163. // so we have to consult AtEnd().
  164. return (AtEnd() && typed_other->AtEnd()) ||
  165. ($for j && [[
  166. current$(j)_ == typed_other->current$(j)_
  167. ]]);
  168. }
  169. private:
  170. Iterator(const Iterator& other)
  171. : base_(other.base_), $for j, [[
  172. begin$(j)_(other.begin$(j)_),
  173. end$(j)_(other.end$(j)_),
  174. current$(j)_(other.current$(j)_)
  175. ]] {
  176. ComputeCurrentValue();
  177. }
  178. void ComputeCurrentValue() {
  179. if (!AtEnd())
  180. current_value_ = ParamType($for j, [[*current$(j)_]]);
  181. }
  182. bool AtEnd() const {
  183. // We must report iterator past the end of the range when either of the
  184. // component iterators has reached the end of its range.
  185. return
  186. $for j || [[
  187. current$(j)_ == end$(j)_
  188. ]];
  189. }
  190. // No implementation - assignment is unsupported.
  191. void operator=(const Iterator& other);
  192. const ParamGeneratorInterface<ParamType>* const base_;
  193. // begin[i]_ and end[i]_ define the i-th range that Iterator traverses.
  194. // current[i]_ is the actual traversing iterator.
  195. $for j [[
  196. const typename ParamGenerator<T$j>::iterator begin$(j)_;
  197. const typename ParamGenerator<T$j>::iterator end$(j)_;
  198. typename ParamGenerator<T$j>::iterator current$(j)_;
  199. ]]
  200. ParamType current_value_;
  201. }; // class CartesianProductGenerator$i::Iterator
  202. // No implementation - assignment is unsupported.
  203. void operator=(const CartesianProductGenerator$i& other);
  204. $for j [[
  205. const ParamGenerator<T$j> g$(j)_;
  206. ]]
  207. }; // class CartesianProductGenerator$i
  208. ]]
  209. // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
  210. //
  211. // Helper classes providing Combine() with polymorphic features. They allow
  212. // casting CartesianProductGeneratorN<T> to ParamGenerator<U> if T is
  213. // convertible to U.
  214. //
  215. $range i 2..maxtuple
  216. $for i [[
  217. $range j 1..i
  218. template <$for j, [[class Generator$j]]>
  219. class CartesianProductHolder$i {
  220. public:
  221. CartesianProductHolder$i($for j, [[const Generator$j& g$j]])
  222. : $for j, [[g$(j)_(g$j)]] {}
  223. template <$for j, [[typename T$j]]>
  224. operator ParamGenerator< ::std::tr1::tuple<$for j, [[T$j]]> >() const {
  225. return ParamGenerator< ::std::tr1::tuple<$for j, [[T$j]]> >(
  226. new CartesianProductGenerator$i<$for j, [[T$j]]>(
  227. $for j,[[
  228. static_cast<ParamGenerator<T$j> >(g$(j)_)
  229. ]]));
  230. }
  231. private:
  232. // No implementation - assignment is unsupported.
  233. void operator=(const CartesianProductHolder$i& other);
  234. $for j [[
  235. const Generator$j g$(j)_;
  236. ]]
  237. }; // class CartesianProductHolder$i
  238. ]]
  239. # endif // GTEST_HAS_COMBINE
  240. } // namespace internal
  241. } // namespace testing
  242. #endif // GTEST_HAS_PARAM_TEST
  243. #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_