Blame googletest/include/gtest/gtest-param-test.h.pump

Packit bd1cd8
$$ -*- mode: c++; -*-
Packit bd1cd8
$var n = 50  $$ Maximum length of Values arguments we want to support.
Packit bd1cd8
$var maxtuple = 10  $$ Maximum number of Combine arguments we want to support.
Packit bd1cd8
// Copyright 2008, Google Inc.
Packit bd1cd8
// All rights reserved.
Packit bd1cd8
//
Packit bd1cd8
// Redistribution and use in source and binary forms, with or without
Packit bd1cd8
// modification, are permitted provided that the following conditions are
Packit bd1cd8
// met:
Packit bd1cd8
//
Packit bd1cd8
//     * Redistributions of source code must retain the above copyright
Packit bd1cd8
// notice, this list of conditions and the following disclaimer.
Packit bd1cd8
//     * Redistributions in binary form must reproduce the above
Packit bd1cd8
// copyright notice, this list of conditions and the following disclaimer
Packit bd1cd8
// in the documentation and/or other materials provided with the
Packit bd1cd8
// distribution.
Packit bd1cd8
//     * Neither the name of Google Inc. nor the names of its
Packit bd1cd8
// contributors may be used to endorse or promote products derived from
Packit bd1cd8
// this software without specific prior written permission.
Packit bd1cd8
//
Packit bd1cd8
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit bd1cd8
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit bd1cd8
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Packit bd1cd8
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
Packit bd1cd8
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Packit bd1cd8
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Packit bd1cd8
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Packit bd1cd8
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Packit bd1cd8
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Packit bd1cd8
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit bd1cd8
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit bd1cd8
//
Packit bd1cd8
// Authors: vladl@google.com (Vlad Losev)
Packit bd1cd8
//
Packit bd1cd8
// Macros and functions for implementing parameterized tests
Packit bd1cd8
// in Google C++ Testing Framework (Google Test)
Packit bd1cd8
//
Packit bd1cd8
// This file is generated by a SCRIPT.  DO NOT EDIT BY HAND!
Packit bd1cd8
//
Packit bd1cd8
#ifndef GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
Packit bd1cd8
#define GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
Packit bd1cd8
Packit bd1cd8
Packit bd1cd8
// Value-parameterized tests allow you to test your code with different
Packit bd1cd8
// parameters without writing multiple copies of the same test.
Packit bd1cd8
//
Packit bd1cd8
// Here is how you use value-parameterized tests:
Packit bd1cd8
Packit bd1cd8
#if 0
Packit bd1cd8
Packit bd1cd8
// To write value-parameterized tests, first you should define a fixture
Packit bd1cd8
// class. It is usually derived from testing::TestWithParam<T> (see below for
Packit bd1cd8
// another inheritance scheme that's sometimes useful in more complicated
Packit bd1cd8
// class hierarchies), where the type of your parameter values.
Packit bd1cd8
// TestWithParam<T> is itself derived from testing::Test. T can be any
Packit bd1cd8
// copyable type. If it's a raw pointer, you are responsible for managing the
Packit bd1cd8
// lifespan of the pointed values.
Packit bd1cd8
Packit bd1cd8
class FooTest : public ::testing::TestWithParam<const char*> {
Packit bd1cd8
  // You can implement all the usual class fixture members here.
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
// Then, use the TEST_P macro to define as many parameterized tests
Packit bd1cd8
// for this fixture as you want. The _P suffix is for "parameterized"
Packit bd1cd8
// or "pattern", whichever you prefer to think.
Packit bd1cd8
Packit bd1cd8
TEST_P(FooTest, DoesBlah) {
Packit bd1cd8
  // Inside a test, access the test parameter with the GetParam() method
Packit bd1cd8
  // of the TestWithParam<T> class:
Packit bd1cd8
  EXPECT_TRUE(foo.Blah(GetParam()));
Packit bd1cd8
  ...
Packit bd1cd8
}
Packit bd1cd8
Packit bd1cd8
TEST_P(FooTest, HasBlahBlah) {
Packit bd1cd8
  ...
Packit bd1cd8
}
Packit bd1cd8
Packit bd1cd8
// Finally, you can use INSTANTIATE_TEST_CASE_P to instantiate the test
Packit bd1cd8
// case with any set of parameters you want. Google Test defines a number
Packit bd1cd8
// of functions for generating test parameters. They return what we call
Packit bd1cd8
// (surprise!) parameter generators. Here is a  summary of them, which
Packit bd1cd8
// are all in the testing namespace:
Packit bd1cd8
//
Packit bd1cd8
//
Packit bd1cd8
//  Range(begin, end [, step]) - Yields values {begin, begin+step,
Packit bd1cd8
//                               begin+step+step, ...}. The values do not
Packit bd1cd8
//                               include end. step defaults to 1.
Packit bd1cd8
//  Values(v1, v2, ..., vN)    - Yields values {v1, v2, ..., vN}.
Packit bd1cd8
//  ValuesIn(container)        - Yields values from a C-style array, an STL
Packit bd1cd8
//  ValuesIn(begin,end)          container, or an iterator range [begin, end).
Packit bd1cd8
//  Bool()                     - Yields sequence {false, true}.
Packit bd1cd8
//  Combine(g1, g2, ..., gN)   - Yields all combinations (the Cartesian product
Packit bd1cd8
//                               for the math savvy) of the values generated
Packit bd1cd8
//                               by the N generators.
Packit bd1cd8
//
Packit bd1cd8
// For more details, see comments at the definitions of these functions below
Packit bd1cd8
// in this file.
Packit bd1cd8
//
Packit bd1cd8
// The following statement will instantiate tests from the FooTest test case
Packit bd1cd8
// each with parameter values "meeny", "miny", and "moe".
Packit bd1cd8
Packit bd1cd8
INSTANTIATE_TEST_CASE_P(InstantiationName,
Packit bd1cd8
                        FooTest,
Packit bd1cd8
                        Values("meeny", "miny", "moe"));
Packit bd1cd8
Packit bd1cd8
// To distinguish different instances of the pattern, (yes, you
Packit bd1cd8
// can instantiate it more then once) the first argument to the
Packit bd1cd8
// INSTANTIATE_TEST_CASE_P macro is a prefix that will be added to the
Packit bd1cd8
// actual test case name. Remember to pick unique prefixes for different
Packit bd1cd8
// instantiations. The tests from the instantiation above will have
Packit bd1cd8
// these names:
Packit bd1cd8
//
Packit bd1cd8
//    * InstantiationName/FooTest.DoesBlah/0 for "meeny"
Packit bd1cd8
//    * InstantiationName/FooTest.DoesBlah/1 for "miny"
Packit bd1cd8
//    * InstantiationName/FooTest.DoesBlah/2 for "moe"
Packit bd1cd8
//    * InstantiationName/FooTest.HasBlahBlah/0 for "meeny"
Packit bd1cd8
//    * InstantiationName/FooTest.HasBlahBlah/1 for "miny"
Packit bd1cd8
//    * InstantiationName/FooTest.HasBlahBlah/2 for "moe"
Packit bd1cd8
//
Packit bd1cd8
// You can use these names in --gtest_filter.
Packit bd1cd8
//
Packit bd1cd8
// This statement will instantiate all tests from FooTest again, each
Packit bd1cd8
// with parameter values "cat" and "dog":
Packit bd1cd8
Packit bd1cd8
const char* pets[] = {"cat", "dog"};
Packit bd1cd8
INSTANTIATE_TEST_CASE_P(AnotherInstantiationName, FooTest, ValuesIn(pets));
Packit bd1cd8
Packit bd1cd8
// The tests from the instantiation above will have these names:
Packit bd1cd8
//
Packit bd1cd8
//    * AnotherInstantiationName/FooTest.DoesBlah/0 for "cat"
Packit bd1cd8
//    * AnotherInstantiationName/FooTest.DoesBlah/1 for "dog"
Packit bd1cd8
//    * AnotherInstantiationName/FooTest.HasBlahBlah/0 for "cat"
Packit bd1cd8
//    * AnotherInstantiationName/FooTest.HasBlahBlah/1 for "dog"
Packit bd1cd8
//
Packit bd1cd8
// Please note that INSTANTIATE_TEST_CASE_P will instantiate all tests
Packit bd1cd8
// in the given test case, whether their definitions come before or
Packit bd1cd8
// AFTER the INSTANTIATE_TEST_CASE_P statement.
Packit bd1cd8
//
Packit bd1cd8
// Please also note that generator expressions (including parameters to the
Packit bd1cd8
// generators) are evaluated in InitGoogleTest(), after main() has started.
Packit bd1cd8
// This allows the user on one hand, to adjust generator parameters in order
Packit bd1cd8
// to dynamically determine a set of tests to run and on the other hand,
Packit bd1cd8
// give the user a chance to inspect the generated tests with Google Test
Packit bd1cd8
// reflection API before RUN_ALL_TESTS() is executed.
Packit bd1cd8
//
Packit bd1cd8
// You can see samples/sample7_unittest.cc and samples/sample8_unittest.cc
Packit bd1cd8
// for more examples.
Packit bd1cd8
//
Packit bd1cd8
// In the future, we plan to publish the API for defining new parameter
Packit bd1cd8
// generators. But for now this interface remains part of the internal
Packit bd1cd8
// implementation and is subject to change.
Packit bd1cd8
//
Packit bd1cd8
//
Packit bd1cd8
// A parameterized test fixture must be derived from testing::Test and from
Packit bd1cd8
// testing::WithParamInterface<T>, where T is the type of the parameter
Packit bd1cd8
// values. Inheriting from TestWithParam<T> satisfies that requirement because
Packit bd1cd8
// TestWithParam<T> inherits from both Test and WithParamInterface. In more
Packit bd1cd8
// complicated hierarchies, however, it is occasionally useful to inherit
Packit bd1cd8
// separately from Test and WithParamInterface. For example:
Packit bd1cd8
Packit bd1cd8
class BaseTest : public ::testing::Test {
Packit bd1cd8
  // You can inherit all the usual members for a non-parameterized test
Packit bd1cd8
  // fixture here.
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
class DerivedTest : public BaseTest, public ::testing::WithParamInterface<int> {
Packit bd1cd8
  // The usual test fixture members go here too.
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
TEST_F(BaseTest, HasFoo) {
Packit bd1cd8
  // This is an ordinary non-parameterized test.
Packit bd1cd8
}
Packit bd1cd8
Packit bd1cd8
TEST_P(DerivedTest, DoesBlah) {
Packit bd1cd8
  // GetParam works just the same here as if you inherit from TestWithParam.
Packit bd1cd8
  EXPECT_TRUE(foo.Blah(GetParam()));
Packit bd1cd8
}
Packit bd1cd8
Packit bd1cd8
#endif  // 0
Packit bd1cd8
Packit bd1cd8
#include "gtest/internal/gtest-port.h"
Packit bd1cd8
Packit bd1cd8
#if !GTEST_OS_SYMBIAN
Packit bd1cd8
# include <utility>
Packit bd1cd8
#endif
Packit bd1cd8
Packit bd1cd8
// scripts/fuse_gtest.py depends on gtest's own header being #included
Packit bd1cd8
// *unconditionally*.  Therefore these #includes cannot be moved
Packit bd1cd8
// inside #if GTEST_HAS_PARAM_TEST.
Packit bd1cd8
#include "gtest/internal/gtest-internal.h"
Packit bd1cd8
#include "gtest/internal/gtest-param-util.h"
Packit bd1cd8
#include "gtest/internal/gtest-param-util-generated.h"
Packit bd1cd8
Packit bd1cd8
#if GTEST_HAS_PARAM_TEST
Packit bd1cd8
Packit bd1cd8
namespace testing {
Packit bd1cd8
Packit bd1cd8
// Functions producing parameter generators.
Packit bd1cd8
//
Packit bd1cd8
// Google Test uses these generators to produce parameters for value-
Packit bd1cd8
// parameterized tests. When a parameterized test case is instantiated
Packit bd1cd8
// with a particular generator, Google Test creates and runs tests
Packit bd1cd8
// for each element in the sequence produced by the generator.
Packit bd1cd8
//
Packit bd1cd8
// In the following sample, tests from test case FooTest are instantiated
Packit bd1cd8
// each three times with parameter values 3, 5, and 8:
Packit bd1cd8
//
Packit bd1cd8
// class FooTest : public TestWithParam<int> { ... };
Packit bd1cd8
//
Packit bd1cd8
// TEST_P(FooTest, TestThis) {
Packit bd1cd8
// }
Packit bd1cd8
// TEST_P(FooTest, TestThat) {
Packit bd1cd8
// }
Packit bd1cd8
// INSTANTIATE_TEST_CASE_P(TestSequence, FooTest, Values(3, 5, 8));
Packit bd1cd8
//
Packit bd1cd8
Packit bd1cd8
// Range() returns generators providing sequences of values in a range.
Packit bd1cd8
//
Packit bd1cd8
// Synopsis:
Packit bd1cd8
// Range(start, end)
Packit bd1cd8
//   - returns a generator producing a sequence of values {start, start+1,
Packit bd1cd8
//     start+2, ..., }.
Packit bd1cd8
// Range(start, end, step)
Packit bd1cd8
//   - returns a generator producing a sequence of values {start, start+step,
Packit bd1cd8
//     start+step+step, ..., }.
Packit bd1cd8
// Notes:
Packit bd1cd8
//   * The generated sequences never include end. For example, Range(1, 5)
Packit bd1cd8
//     returns a generator producing a sequence {1, 2, 3, 4}. Range(1, 9, 2)
Packit bd1cd8
//     returns a generator producing {1, 3, 5, 7}.
Packit bd1cd8
//   * start and end must have the same type. That type may be any integral or
Packit bd1cd8
//     floating-point type or a user defined type satisfying these conditions:
Packit bd1cd8
//     * It must be assignable (have operator=() defined).
Packit bd1cd8
//     * It must have operator+() (operator+(int-compatible type) for
Packit bd1cd8
//       two-operand version).
Packit bd1cd8
//     * It must have operator<() defined.
Packit bd1cd8
//     Elements in the resulting sequences will also have that type.
Packit bd1cd8
//   * Condition start < end must be satisfied in order for resulting sequences
Packit bd1cd8
//     to contain any elements.
Packit bd1cd8
//
Packit bd1cd8
template <typename T, typename IncrementT>
Packit bd1cd8
internal::ParamGenerator<T> Range(T start, T end, IncrementT step) {
Packit bd1cd8
  return internal::ParamGenerator<T>(
Packit bd1cd8
      new internal::RangeGenerator<T, IncrementT>(start, end, step));
Packit bd1cd8
}
Packit bd1cd8
Packit bd1cd8
template <typename T>
Packit bd1cd8
internal::ParamGenerator<T> Range(T start, T end) {
Packit bd1cd8
  return Range(start, end, 1);
Packit bd1cd8
}
Packit bd1cd8
Packit bd1cd8
// ValuesIn() function allows generation of tests with parameters coming from
Packit bd1cd8
// a container.
Packit bd1cd8
//
Packit bd1cd8
// Synopsis:
Packit bd1cd8
// ValuesIn(const T (&array)[N])
Packit bd1cd8
//   - returns a generator producing sequences with elements from
Packit bd1cd8
//     a C-style array.
Packit bd1cd8
// ValuesIn(const Container& container)
Packit bd1cd8
//   - returns a generator producing sequences with elements from
Packit bd1cd8
//     an STL-style container.
Packit bd1cd8
// ValuesIn(Iterator begin, Iterator end)
Packit bd1cd8
//   - returns a generator producing sequences with elements from
Packit bd1cd8
//     a range [begin, end) defined by a pair of STL-style iterators. These
Packit bd1cd8
//     iterators can also be plain C pointers.
Packit bd1cd8
//
Packit bd1cd8
// Please note that ValuesIn copies the values from the containers
Packit bd1cd8
// passed in and keeps them to generate tests in RUN_ALL_TESTS().
Packit bd1cd8
//
Packit bd1cd8
// Examples:
Packit bd1cd8
//
Packit bd1cd8
// This instantiates tests from test case StringTest
Packit bd1cd8
// each with C-string values of "foo", "bar", and "baz":
Packit bd1cd8
//
Packit bd1cd8
// const char* strings[] = {"foo", "bar", "baz"};
Packit bd1cd8
// INSTANTIATE_TEST_CASE_P(StringSequence, SrtingTest, ValuesIn(strings));
Packit bd1cd8
//
Packit bd1cd8
// This instantiates tests from test case StlStringTest
Packit bd1cd8
// each with STL strings with values "a" and "b":
Packit bd1cd8
//
Packit bd1cd8
// ::std::vector< ::std::string> GetParameterStrings() {
Packit bd1cd8
//   ::std::vector< ::std::string> v;
Packit bd1cd8
//   v.push_back("a");
Packit bd1cd8
//   v.push_back("b");
Packit bd1cd8
//   return v;
Packit bd1cd8
// }
Packit bd1cd8
//
Packit bd1cd8
// INSTANTIATE_TEST_CASE_P(CharSequence,
Packit bd1cd8
//                         StlStringTest,
Packit bd1cd8
//                         ValuesIn(GetParameterStrings()));
Packit bd1cd8
//
Packit bd1cd8
//
Packit bd1cd8
// This will also instantiate tests from CharTest
Packit bd1cd8
// each with parameter values 'a' and 'b':
Packit bd1cd8
//
Packit bd1cd8
// ::std::list<char> GetParameterChars() {
Packit bd1cd8
//   ::std::list<char> list;
Packit bd1cd8
//   list.push_back('a');
Packit bd1cd8
//   list.push_back('b');
Packit bd1cd8
//   return list;
Packit bd1cd8
// }
Packit bd1cd8
// ::std::list<char> l = GetParameterChars();
Packit bd1cd8
// INSTANTIATE_TEST_CASE_P(CharSequence2,
Packit bd1cd8
//                         CharTest,
Packit bd1cd8
//                         ValuesIn(l.begin(), l.end()));
Packit bd1cd8
//
Packit bd1cd8
template <typename ForwardIterator>
Packit bd1cd8
internal::ParamGenerator<
Packit bd1cd8
  typename ::testing::internal::IteratorTraits<ForwardIterator>::value_type>
Packit bd1cd8
ValuesIn(ForwardIterator begin, ForwardIterator end) {
Packit bd1cd8
  typedef typename ::testing::internal::IteratorTraits<ForwardIterator>
Packit bd1cd8
      ::value_type ParamType;
Packit bd1cd8
  return internal::ParamGenerator<ParamType>(
Packit bd1cd8
      new internal::ValuesInIteratorRangeGenerator<ParamType>(begin, end));
Packit bd1cd8
}
Packit bd1cd8
Packit bd1cd8
template <typename T, size_t N>
Packit bd1cd8
internal::ParamGenerator<T> ValuesIn(const T (&array)[N]) {
Packit bd1cd8
  return ValuesIn(array, array + N);
Packit bd1cd8
}
Packit bd1cd8
Packit bd1cd8
template <class Container>
Packit bd1cd8
internal::ParamGenerator<typename Container::value_type> ValuesIn(
Packit bd1cd8
    const Container& container) {
Packit bd1cd8
  return ValuesIn(container.begin(), container.end());
Packit bd1cd8
}
Packit bd1cd8
Packit bd1cd8
// Values() allows generating tests from explicitly specified list of
Packit bd1cd8
// parameters.
Packit bd1cd8
//
Packit bd1cd8
// Synopsis:
Packit bd1cd8
// Values(T v1, T v2, ..., T vN)
Packit bd1cd8
//   - returns a generator producing sequences with elements v1, v2, ..., vN.
Packit bd1cd8
//
Packit bd1cd8
// For example, this instantiates tests from test case BarTest each
Packit bd1cd8
// with values "one", "two", and "three":
Packit bd1cd8
//
Packit bd1cd8
// INSTANTIATE_TEST_CASE_P(NumSequence, BarTest, Values("one", "two", "three"));
Packit bd1cd8
//
Packit bd1cd8
// This instantiates tests from test case BazTest each with values 1, 2, 3.5.
Packit bd1cd8
// The exact type of values will depend on the type of parameter in BazTest.
Packit bd1cd8
//
Packit bd1cd8
// INSTANTIATE_TEST_CASE_P(FloatingNumbers, BazTest, Values(1, 2, 3.5));
Packit bd1cd8
//
Packit bd1cd8
// Currently, Values() supports from 1 to $n parameters.
Packit bd1cd8
//
Packit bd1cd8
$range i 1..n
Packit bd1cd8
$for i [[
Packit bd1cd8
$range j 1..i
Packit bd1cd8
Packit bd1cd8
template <$for j, [[typename T$j]]>
Packit bd1cd8
internal::ValueArray$i<$for j, [[T$j]]> Values($for j, [[T$j v$j]]) {
Packit bd1cd8
  return internal::ValueArray$i<$for j, [[T$j]]>($for j, [[v$j]]);
Packit bd1cd8
}
Packit bd1cd8
Packit bd1cd8
]]
Packit bd1cd8
Packit bd1cd8
// Bool() allows generating tests with parameters in a set of (false, true).
Packit bd1cd8
//
Packit bd1cd8
// Synopsis:
Packit bd1cd8
// Bool()
Packit bd1cd8
//   - returns a generator producing sequences with elements {false, true}.
Packit bd1cd8
//
Packit bd1cd8
// It is useful when testing code that depends on Boolean flags. Combinations
Packit bd1cd8
// of multiple flags can be tested when several Bool()'s are combined using
Packit bd1cd8
// Combine() function.
Packit bd1cd8
//
Packit bd1cd8
// In the following example all tests in the test case FlagDependentTest
Packit bd1cd8
// will be instantiated twice with parameters false and true.
Packit bd1cd8
//
Packit bd1cd8
// class FlagDependentTest : public testing::TestWithParam<bool> {
Packit bd1cd8
//   virtual void SetUp() {
Packit bd1cd8
//     external_flag = GetParam();
Packit bd1cd8
//   }
Packit bd1cd8
// }
Packit bd1cd8
// INSTANTIATE_TEST_CASE_P(BoolSequence, FlagDependentTest, Bool());
Packit bd1cd8
//
Packit bd1cd8
inline internal::ParamGenerator<bool> Bool() {
Packit bd1cd8
  return Values(false, true);
Packit bd1cd8
}
Packit bd1cd8
Packit bd1cd8
# if GTEST_HAS_COMBINE
Packit bd1cd8
// Combine() allows the user to combine two or more sequences to produce
Packit bd1cd8
// values of a Cartesian product of those sequences' elements.
Packit bd1cd8
//
Packit bd1cd8
// Synopsis:
Packit bd1cd8
// Combine(gen1, gen2, ..., genN)
Packit bd1cd8
//   - returns a generator producing sequences with elements coming from
Packit bd1cd8
//     the Cartesian product of elements from the sequences generated by
Packit bd1cd8
//     gen1, gen2, ..., genN. The sequence elements will have a type of
Packit bd1cd8
//     tuple<T1, T2, ..., TN> where T1, T2, ..., TN are the types
Packit bd1cd8
//     of elements from sequences produces by gen1, gen2, ..., genN.
Packit bd1cd8
//
Packit bd1cd8
// Combine can have up to $maxtuple arguments. This number is currently limited
Packit bd1cd8
// by the maximum number of elements in the tuple implementation used by Google
Packit bd1cd8
// Test.
Packit bd1cd8
//
Packit bd1cd8
// Example:
Packit bd1cd8
//
Packit bd1cd8
// This will instantiate tests in test case AnimalTest each one with
Packit bd1cd8
// the parameter values tuple("cat", BLACK), tuple("cat", WHITE),
Packit bd1cd8
// tuple("dog", BLACK), and tuple("dog", WHITE):
Packit bd1cd8
//
Packit bd1cd8
// enum Color { BLACK, GRAY, WHITE };
Packit bd1cd8
// class AnimalTest
Packit bd1cd8
//     : public testing::TestWithParam<tuple<const char*, Color> > {...};
Packit bd1cd8
//
Packit bd1cd8
// TEST_P(AnimalTest, AnimalLooksNice) {...}
Packit bd1cd8
//
Packit bd1cd8
// INSTANTIATE_TEST_CASE_P(AnimalVariations, AnimalTest,
Packit bd1cd8
//                         Combine(Values("cat", "dog"),
Packit bd1cd8
//                                 Values(BLACK, WHITE)));
Packit bd1cd8
//
Packit bd1cd8
// This will instantiate tests in FlagDependentTest with all variations of two
Packit bd1cd8
// Boolean flags:
Packit bd1cd8
//
Packit bd1cd8
// class FlagDependentTest
Packit bd1cd8
//     : public testing::TestWithParam<tuple<bool, bool> > {
Packit bd1cd8
//   virtual void SetUp() {
Packit bd1cd8
//     // Assigns external_flag_1 and external_flag_2 values from the tuple.
Packit bd1cd8
//     tie(external_flag_1, external_flag_2) = GetParam();
Packit bd1cd8
//   }
Packit bd1cd8
// };
Packit bd1cd8
//
Packit bd1cd8
// TEST_P(FlagDependentTest, TestFeature1) {
Packit bd1cd8
//   // Test your code using external_flag_1 and external_flag_2 here.
Packit bd1cd8
// }
Packit bd1cd8
// INSTANTIATE_TEST_CASE_P(TwoBoolSequence, FlagDependentTest,
Packit bd1cd8
//                         Combine(Bool(), Bool()));
Packit bd1cd8
//
Packit bd1cd8
$range i 2..maxtuple
Packit bd1cd8
$for i [[
Packit bd1cd8
$range j 1..i
Packit bd1cd8
Packit bd1cd8
template <$for j, [[typename Generator$j]]>
Packit bd1cd8
internal::CartesianProductHolder$i<$for j, [[Generator$j]]> Combine(
Packit bd1cd8
    $for j, [[const Generator$j& g$j]]) {
Packit bd1cd8
  return internal::CartesianProductHolder$i<$for j, [[Generator$j]]>(
Packit bd1cd8
      $for j, [[g$j]]);
Packit bd1cd8
}
Packit bd1cd8
Packit bd1cd8
]]
Packit bd1cd8
# endif  // GTEST_HAS_COMBINE
Packit bd1cd8
Packit bd1cd8
Packit bd1cd8
Packit bd1cd8
# define TEST_P(test_case_name, test_name) \
Packit bd1cd8
  class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
Packit bd1cd8
      : public test_case_name { \
Packit bd1cd8
   public: \
Packit bd1cd8
    GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {} \
Packit bd1cd8
    virtual void TestBody(); \
Packit bd1cd8
   private: \
Packit bd1cd8
    static int AddToRegistry() { \
Packit bd1cd8
      ::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
Packit bd1cd8
          GetTestCasePatternHolder<test_case_name>(\
Packit bd1cd8
              #test_case_name, \
Packit bd1cd8
              ::testing::internal::CodeLocation(\
Packit bd1cd8
                  __FILE__, __LINE__))->AddTestPattern(\
Packit bd1cd8
                      #test_case_name, \
Packit bd1cd8
                      #test_name, \
Packit bd1cd8
                      new ::testing::internal::TestMetaFactory< \
Packit bd1cd8
                          GTEST_TEST_CLASS_NAME_(\
Packit bd1cd8
                              test_case_name, test_name)>()); \
Packit bd1cd8
      return 0; \
Packit bd1cd8
    } \
Packit bd1cd8
    static int gtest_registering_dummy_ GTEST_ATTRIBUTE_UNUSED_; \
Packit bd1cd8
    GTEST_DISALLOW_COPY_AND_ASSIGN_(\
Packit bd1cd8
        GTEST_TEST_CLASS_NAME_(test_case_name, test_name)); \
Packit bd1cd8
  }; \
Packit bd1cd8
  int GTEST_TEST_CLASS_NAME_(test_case_name, \
Packit bd1cd8
                             test_name)::gtest_registering_dummy_ = \
Packit bd1cd8
      GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \
Packit bd1cd8
  void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
Packit bd1cd8
Packit bd1cd8
// The optional last argument to INSTANTIATE_TEST_CASE_P allows the user
Packit bd1cd8
// to specify a function or functor that generates custom test name suffixes
Packit bd1cd8
// based on the test parameters. The function should accept one argument of
Packit bd1cd8
// type testing::TestParamInfo<class ParamType>, and return std::string.
Packit bd1cd8
//
Packit bd1cd8
// testing::PrintToStringParamName is a builtin test suffix generator that
Packit bd1cd8
// returns the value of testing::PrintToString(GetParam()).
Packit bd1cd8
//
Packit bd1cd8
// Note: test names must be non-empty, unique, and may only contain ASCII
Packit bd1cd8
// alphanumeric characters or underscore. Because PrintToString adds quotes
Packit bd1cd8
// to std::string and C strings, it won't work for these types.
Packit bd1cd8
Packit bd1cd8
# define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator, ...) \
Packit bd1cd8
  ::testing::internal::ParamGenerator<test_case_name::ParamType> \
Packit bd1cd8
      gtest_##prefix##test_case_name##_EvalGenerator_() { return generator; } \
Packit bd1cd8
  ::std::string gtest_##prefix##test_case_name##_EvalGenerateName_( \
Packit bd1cd8
      const ::testing::TestParamInfo<test_case_name::ParamType>& info) { \
Packit bd1cd8
    return ::testing::internal::GetParamNameGen<test_case_name::ParamType> \
Packit bd1cd8
        (__VA_ARGS__)(info); \
Packit bd1cd8
  } \
Packit bd1cd8
  int gtest_##prefix##test_case_name##_dummy_ GTEST_ATTRIBUTE_UNUSED_ = \
Packit bd1cd8
      ::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
Packit bd1cd8
          GetTestCasePatternHolder<test_case_name>(\
Packit bd1cd8
              #test_case_name, \
Packit bd1cd8
              ::testing::internal::CodeLocation(\
Packit bd1cd8
                  __FILE__, __LINE__))->AddTestCaseInstantiation(\
Packit bd1cd8
                      #prefix, \
Packit bd1cd8
                      &gtest_##prefix##test_case_name##_EvalGenerator_, \
Packit bd1cd8
                      &gtest_##prefix##test_case_name##_EvalGenerateName_, \
Packit bd1cd8
                      __FILE__, __LINE__)
Packit bd1cd8
Packit bd1cd8
}  // namespace testing
Packit bd1cd8
Packit bd1cd8
#endif  // GTEST_HAS_PARAM_TEST
Packit bd1cd8
Packit bd1cd8
#endif  // GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_