Towerism / googletest

Automatically exported from code.google.com/p/googletest
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

How to fix the Input parameter value when using typed_parameter test #376

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
when I used  the sample code from advanceguide Type-Parameterized Tests,
I found that it just had set the type,but not any input paramter.
Did it a wrong sample,or gtest couldn't support that functional.
If yes,the Type-Parameterized Tests maybe wasn't useful.
-------------------------------

Original issue reported on code.google.com by charming...@gmail.com on 15 Aug 2011 at 7:29

GoogleCodeExporter commented 9 years ago
Type parameterized tests are for verifying how your template code works when 
instantiated with different types. If you want to verify your code with 
different values of the same type, use value parameterized tests.

If you want different types _and_ specific parameters for each type, define and 
specialize a template like this and then use it in your type parameterized 
tests:

template <typename T> class ValueForType;

template <> class ValueForType<int> {
  public:
    static const int value = 5;
};
template <> class ValueForType<int>::value;

template <> class ValueForType<char> {
  public:
    static const char value = 'a';
};
template <> class ValueForType<char>::value;

You can write a macro to make defining such mappings easier.

Original comment by vladlosev on 18 Aug 2011 at 7:28