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