/thirdparty/breakpad/third_party/protobuf/protobuf/gtest/include/gtest/gtest-param-test.h.pump

http://github.com/tomahawk-player/tomahawk · Unknown · 457 lines · 418 code · 39 blank · 0 comment · 0 complexity · 0adde26a49fe611ac248eea233aaa16d 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. // Authors: vladl@google.com (Vlad Losev)
  34. //
  35. // Macros and functions for implementing parameterized tests
  36. // in Google C++ Testing Framework (Google Test)
  37. //
  38. // This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
  39. //
  40. #ifndef GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
  41. #define GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
  42. // Value-parameterized tests allow you to test your code with different
  43. // parameters without writing multiple copies of the same test.
  44. //
  45. // Here is how you use value-parameterized tests:
  46. #if 0
  47. // To write value-parameterized tests, first you should define a fixture
  48. // class. It must be derived from testing::TestWithParam<T>, where T is
  49. // the type of your parameter values. TestWithParam<T> is itself derived
  50. // from testing::Test. T can be any copyable type. If it's a raw pointer,
  51. // you are responsible for managing the lifespan of the pointed values.
  52. class FooTest : public ::testing::TestWithParam<const char*> {
  53. // You can implement all the usual class fixture members here.
  54. };
  55. // Then, use the TEST_P macro to define as many parameterized tests
  56. // for this fixture as you want. The _P suffix is for "parameterized"
  57. // or "pattern", whichever you prefer to think.
  58. TEST_P(FooTest, DoesBlah) {
  59. // Inside a test, access the test parameter with the GetParam() method
  60. // of the TestWithParam<T> class:
  61. EXPECT_TRUE(foo.Blah(GetParam()));
  62. ...
  63. }
  64. TEST_P(FooTest, HasBlahBlah) {
  65. ...
  66. }
  67. // Finally, you can use INSTANTIATE_TEST_CASE_P to instantiate the test
  68. // case with any set of parameters you want. Google Test defines a number
  69. // of functions for generating test parameters. They return what we call
  70. // (surprise!) parameter generators. Here is a summary of them, which
  71. // are all in the testing namespace:
  72. //
  73. //
  74. // Range(begin, end [, step]) - Yields values {begin, begin+step,
  75. // begin+step+step, ...}. The values do not
  76. // include end. step defaults to 1.
  77. // Values(v1, v2, ..., vN) - Yields values {v1, v2, ..., vN}.
  78. // ValuesIn(container) - Yields values from a C-style array, an STL
  79. // ValuesIn(begin,end) container, or an iterator range [begin, end).
  80. // Bool() - Yields sequence {false, true}.
  81. // Combine(g1, g2, ..., gN) - Yields all combinations (the Cartesian product
  82. // for the math savvy) of the values generated
  83. // by the N generators.
  84. //
  85. // For more details, see comments at the definitions of these functions below
  86. // in this file.
  87. //
  88. // The following statement will instantiate tests from the FooTest test case
  89. // each with parameter values "meeny", "miny", and "moe".
  90. INSTANTIATE_TEST_CASE_P(InstantiationName,
  91. FooTest,
  92. Values("meeny", "miny", "moe"));
  93. // To distinguish different instances of the pattern, (yes, you
  94. // can instantiate it more then once) the first argument to the
  95. // INSTANTIATE_TEST_CASE_P macro is a prefix that will be added to the
  96. // actual test case name. Remember to pick unique prefixes for different
  97. // instantiations. The tests from the instantiation above will have
  98. // these names:
  99. //
  100. // * InstantiationName/FooTest.DoesBlah/0 for "meeny"
  101. // * InstantiationName/FooTest.DoesBlah/1 for "miny"
  102. // * InstantiationName/FooTest.DoesBlah/2 for "moe"
  103. // * InstantiationName/FooTest.HasBlahBlah/0 for "meeny"
  104. // * InstantiationName/FooTest.HasBlahBlah/1 for "miny"
  105. // * InstantiationName/FooTest.HasBlahBlah/2 for "moe"
  106. //
  107. // You can use these names in --gtest_filter.
  108. //
  109. // This statement will instantiate all tests from FooTest again, each
  110. // with parameter values "cat" and "dog":
  111. const char* pets[] = {"cat", "dog"};
  112. INSTANTIATE_TEST_CASE_P(AnotherInstantiationName, FooTest, ValuesIn(pets));
  113. // The tests from the instantiation above will have these names:
  114. //
  115. // * AnotherInstantiationName/FooTest.DoesBlah/0 for "cat"
  116. // * AnotherInstantiationName/FooTest.DoesBlah/1 for "dog"
  117. // * AnotherInstantiationName/FooTest.HasBlahBlah/0 for "cat"
  118. // * AnotherInstantiationName/FooTest.HasBlahBlah/1 for "dog"
  119. //
  120. // Please note that INSTANTIATE_TEST_CASE_P will instantiate all tests
  121. // in the given test case, whether their definitions come before or
  122. // AFTER the INSTANTIATE_TEST_CASE_P statement.
  123. //
  124. // Please also note that generator expressions are evaluated in
  125. // RUN_ALL_TESTS(), after main() has started. This allows evaluation of
  126. // parameter list based on command line parameters.
  127. //
  128. // You can see samples/sample7_unittest.cc and samples/sample8_unittest.cc
  129. // for more examples.
  130. //
  131. // In the future, we plan to publish the API for defining new parameter
  132. // generators. But for now this interface remains part of the internal
  133. // implementation and is subject to change.
  134. #endif // 0
  135. #include <gtest/internal/gtest-port.h>
  136. #if !GTEST_OS_SYMBIAN
  137. #include <utility>
  138. #endif
  139. // scripts/fuse_gtest.py depends on gtest's own header being #included
  140. // *unconditionally*. Therefore these #includes cannot be moved
  141. // inside #if GTEST_HAS_PARAM_TEST.
  142. #include <gtest/internal/gtest-internal.h>
  143. #include <gtest/internal/gtest-param-util.h>
  144. #include <gtest/internal/gtest-param-util-generated.h>
  145. #if GTEST_HAS_PARAM_TEST
  146. namespace testing {
  147. // Functions producing parameter generators.
  148. //
  149. // Google Test uses these generators to produce parameters for value-
  150. // parameterized tests. When a parameterized test case is instantiated
  151. // with a particular generator, Google Test creates and runs tests
  152. // for each element in the sequence produced by the generator.
  153. //
  154. // In the following sample, tests from test case FooTest are instantiated
  155. // each three times with parameter values 3, 5, and 8:
  156. //
  157. // class FooTest : public TestWithParam<int> { ... };
  158. //
  159. // TEST_P(FooTest, TestThis) {
  160. // }
  161. // TEST_P(FooTest, TestThat) {
  162. // }
  163. // INSTANTIATE_TEST_CASE_P(TestSequence, FooTest, Values(3, 5, 8));
  164. //
  165. // Range() returns generators providing sequences of values in a range.
  166. //
  167. // Synopsis:
  168. // Range(start, end)
  169. // - returns a generator producing a sequence of values {start, start+1,
  170. // start+2, ..., }.
  171. // Range(start, end, step)
  172. // - returns a generator producing a sequence of values {start, start+step,
  173. // start+step+step, ..., }.
  174. // Notes:
  175. // * The generated sequences never include end. For example, Range(1, 5)
  176. // returns a generator producing a sequence {1, 2, 3, 4}. Range(1, 9, 2)
  177. // returns a generator producing {1, 3, 5, 7}.
  178. // * start and end must have the same type. That type may be any integral or
  179. // floating-point type or a user defined type satisfying these conditions:
  180. // * It must be assignable (have operator=() defined).
  181. // * It must have operator+() (operator+(int-compatible type) for
  182. // two-operand version).
  183. // * It must have operator<() defined.
  184. // Elements in the resulting sequences will also have that type.
  185. // * Condition start < end must be satisfied in order for resulting sequences
  186. // to contain any elements.
  187. //
  188. template <typename T, typename IncrementT>
  189. internal::ParamGenerator<T> Range(T start, T end, IncrementT step) {
  190. return internal::ParamGenerator<T>(
  191. new internal::RangeGenerator<T, IncrementT>(start, end, step));
  192. }
  193. template <typename T>
  194. internal::ParamGenerator<T> Range(T start, T end) {
  195. return Range(start, end, 1);
  196. }
  197. // ValuesIn() function allows generation of tests with parameters coming from
  198. // a container.
  199. //
  200. // Synopsis:
  201. // ValuesIn(const T (&array)[N])
  202. // - returns a generator producing sequences with elements from
  203. // a C-style array.
  204. // ValuesIn(const Container& container)
  205. // - returns a generator producing sequences with elements from
  206. // an STL-style container.
  207. // ValuesIn(Iterator begin, Iterator end)
  208. // - returns a generator producing sequences with elements from
  209. // a range [begin, end) defined by a pair of STL-style iterators. These
  210. // iterators can also be plain C pointers.
  211. //
  212. // Please note that ValuesIn copies the values from the containers
  213. // passed in and keeps them to generate tests in RUN_ALL_TESTS().
  214. //
  215. // Examples:
  216. //
  217. // This instantiates tests from test case StringTest
  218. // each with C-string values of "foo", "bar", and "baz":
  219. //
  220. // const char* strings[] = {"foo", "bar", "baz"};
  221. // INSTANTIATE_TEST_CASE_P(StringSequence, SrtingTest, ValuesIn(strings));
  222. //
  223. // This instantiates tests from test case StlStringTest
  224. // each with STL strings with values "a" and "b":
  225. //
  226. // ::std::vector< ::std::string> GetParameterStrings() {
  227. // ::std::vector< ::std::string> v;
  228. // v.push_back("a");
  229. // v.push_back("b");
  230. // return v;
  231. // }
  232. //
  233. // INSTANTIATE_TEST_CASE_P(CharSequence,
  234. // StlStringTest,
  235. // ValuesIn(GetParameterStrings()));
  236. //
  237. //
  238. // This will also instantiate tests from CharTest
  239. // each with parameter values 'a' and 'b':
  240. //
  241. // ::std::list<char> GetParameterChars() {
  242. // ::std::list<char> list;
  243. // list.push_back('a');
  244. // list.push_back('b');
  245. // return list;
  246. // }
  247. // ::std::list<char> l = GetParameterChars();
  248. // INSTANTIATE_TEST_CASE_P(CharSequence2,
  249. // CharTest,
  250. // ValuesIn(l.begin(), l.end()));
  251. //
  252. template <typename ForwardIterator>
  253. internal::ParamGenerator<
  254. typename ::std::iterator_traits<ForwardIterator>::value_type> ValuesIn(
  255. ForwardIterator begin,
  256. ForwardIterator end) {
  257. typedef typename ::std::iterator_traits<ForwardIterator>::value_type
  258. ParamType;
  259. return internal::ParamGenerator<ParamType>(
  260. new internal::ValuesInIteratorRangeGenerator<ParamType>(begin, end));
  261. }
  262. template <typename T, size_t N>
  263. internal::ParamGenerator<T> ValuesIn(const T (&array)[N]) {
  264. return ValuesIn(array, array + N);
  265. }
  266. template <class Container>
  267. internal::ParamGenerator<typename Container::value_type> ValuesIn(
  268. const Container& container) {
  269. return ValuesIn(container.begin(), container.end());
  270. }
  271. // Values() allows generating tests from explicitly specified list of
  272. // parameters.
  273. //
  274. // Synopsis:
  275. // Values(T v1, T v2, ..., T vN)
  276. // - returns a generator producing sequences with elements v1, v2, ..., vN.
  277. //
  278. // For example, this instantiates tests from test case BarTest each
  279. // with values "one", "two", and "three":
  280. //
  281. // INSTANTIATE_TEST_CASE_P(NumSequence, BarTest, Values("one", "two", "three"));
  282. //
  283. // This instantiates tests from test case BazTest each with values 1, 2, 3.5.
  284. // The exact type of values will depend on the type of parameter in BazTest.
  285. //
  286. // INSTANTIATE_TEST_CASE_P(FloatingNumbers, BazTest, Values(1, 2, 3.5));
  287. //
  288. // Currently, Values() supports from 1 to $n parameters.
  289. //
  290. $range i 1..n
  291. $for i [[
  292. $range j 1..i
  293. template <$for j, [[typename T$j]]>
  294. internal::ValueArray$i<$for j, [[T$j]]> Values($for j, [[T$j v$j]]) {
  295. return internal::ValueArray$i<$for j, [[T$j]]>($for j, [[v$j]]);
  296. }
  297. ]]
  298. // Bool() allows generating tests with parameters in a set of (false, true).
  299. //
  300. // Synopsis:
  301. // Bool()
  302. // - returns a generator producing sequences with elements {false, true}.
  303. //
  304. // It is useful when testing code that depends on Boolean flags. Combinations
  305. // of multiple flags can be tested when several Bool()'s are combined using
  306. // Combine() function.
  307. //
  308. // In the following example all tests in the test case FlagDependentTest
  309. // will be instantiated twice with parameters false and true.
  310. //
  311. // class FlagDependentTest : public testing::TestWithParam<bool> {
  312. // virtual void SetUp() {
  313. // external_flag = GetParam();
  314. // }
  315. // }
  316. // INSTANTIATE_TEST_CASE_P(BoolSequence, FlagDependentTest, Bool());
  317. //
  318. inline internal::ParamGenerator<bool> Bool() {
  319. return Values(false, true);
  320. }
  321. #if GTEST_HAS_COMBINE
  322. // Combine() allows the user to combine two or more sequences to produce
  323. // values of a Cartesian product of those sequences' elements.
  324. //
  325. // Synopsis:
  326. // Combine(gen1, gen2, ..., genN)
  327. // - returns a generator producing sequences with elements coming from
  328. // the Cartesian product of elements from the sequences generated by
  329. // gen1, gen2, ..., genN. The sequence elements will have a type of
  330. // tuple<T1, T2, ..., TN> where T1, T2, ..., TN are the types
  331. // of elements from sequences produces by gen1, gen2, ..., genN.
  332. //
  333. // Combine can have up to $maxtuple arguments. This number is currently limited
  334. // by the maximum number of elements in the tuple implementation used by Google
  335. // Test.
  336. //
  337. // Example:
  338. //
  339. // This will instantiate tests in test case AnimalTest each one with
  340. // the parameter values tuple("cat", BLACK), tuple("cat", WHITE),
  341. // tuple("dog", BLACK), and tuple("dog", WHITE):
  342. //
  343. // enum Color { BLACK, GRAY, WHITE };
  344. // class AnimalTest
  345. // : public testing::TestWithParam<tuple<const char*, Color> > {...};
  346. //
  347. // TEST_P(AnimalTest, AnimalLooksNice) {...}
  348. //
  349. // INSTANTIATE_TEST_CASE_P(AnimalVariations, AnimalTest,
  350. // Combine(Values("cat", "dog"),
  351. // Values(BLACK, WHITE)));
  352. //
  353. // This will instantiate tests in FlagDependentTest with all variations of two
  354. // Boolean flags:
  355. //
  356. // class FlagDependentTest
  357. // : public testing::TestWithParam<tuple(bool, bool)> > {
  358. // virtual void SetUp() {
  359. // // Assigns external_flag_1 and external_flag_2 values from the tuple.
  360. // tie(external_flag_1, external_flag_2) = GetParam();
  361. // }
  362. // };
  363. //
  364. // TEST_P(FlagDependentTest, TestFeature1) {
  365. // // Test your code using external_flag_1 and external_flag_2 here.
  366. // }
  367. // INSTANTIATE_TEST_CASE_P(TwoBoolSequence, FlagDependentTest,
  368. // Combine(Bool(), Bool()));
  369. //
  370. $range i 2..maxtuple
  371. $for i [[
  372. $range j 1..i
  373. template <$for j, [[typename Generator$j]]>
  374. internal::CartesianProductHolder$i<$for j, [[Generator$j]]> Combine(
  375. $for j, [[const Generator$j& g$j]]) {
  376. return internal::CartesianProductHolder$i<$for j, [[Generator$j]]>(
  377. $for j, [[g$j]]);
  378. }
  379. ]]
  380. #endif // GTEST_HAS_COMBINE
  381. #define TEST_P(test_case_name, test_name) \
  382. class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
  383. : public test_case_name { \
  384. public: \
  385. GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {} \
  386. virtual void TestBody(); \
  387. private: \
  388. static int AddToRegistry() { \
  389. ::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
  390. GetTestCasePatternHolder<test_case_name>(\
  391. #test_case_name, __FILE__, __LINE__)->AddTestPattern(\
  392. #test_case_name, \
  393. #test_name, \
  394. new ::testing::internal::TestMetaFactory< \
  395. GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>()); \
  396. return 0; \
  397. } \
  398. static int gtest_registering_dummy_; \
  399. GTEST_DISALLOW_COPY_AND_ASSIGN_(\
  400. GTEST_TEST_CLASS_NAME_(test_case_name, test_name)); \
  401. }; \
  402. int GTEST_TEST_CLASS_NAME_(test_case_name, \
  403. test_name)::gtest_registering_dummy_ = \
  404. GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \
  405. void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
  406. #define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator) \
  407. ::testing::internal::ParamGenerator<test_case_name::ParamType> \
  408. gtest_##prefix##test_case_name##_EvalGenerator_() { return generator; } \
  409. int gtest_##prefix##test_case_name##_dummy_ = \
  410. ::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
  411. GetTestCasePatternHolder<test_case_name>(\
  412. #test_case_name, __FILE__, __LINE__)->AddTestCaseInstantiation(\
  413. #prefix, \
  414. &gtest_##prefix##test_case_name##_EvalGenerator_, \
  415. __FILE__, __LINE__)
  416. } // namespace testing
  417. #endif // GTEST_HAS_PARAM_TEST
  418. #endif // GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_