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

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