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

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