ci_base
gtest-param-util.h
1 // Copyright 2008 Google Inc.
2 // All Rights Reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30 
31 // Type and function utilities for implementing parameterized tests.
32 
33 // GOOGLETEST_CM0001 DO NOT DELETE
34 
35 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_
36 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_
37 
38 #include <ctype.h>
39 
40 #include <iterator>
41 #include <memory>
42 #include <set>
43 #include <tuple>
44 #include <utility>
45 #include <vector>
46 
47 #include "gtest/internal/gtest-internal.h"
48 #include "gtest/internal/gtest-port.h"
49 #include "gtest/gtest-printers.h"
50 
51 namespace testing {
52 // Input to a parameterized test name generator, describing a test parameter.
53 // Consists of the parameter value and the integer parameter index.
54 template <class ParamType>
55 struct TestParamInfo {
56  TestParamInfo(const ParamType& a_param, size_t an_index) :
57  param(a_param),
58  index(an_index) {}
59  ParamType param;
60  size_t index;
61 };
62 
63 // A builtin parameterized test name generator which returns the result of
64 // testing::PrintToString.
66  template <class ParamType>
67  std::string operator()(const TestParamInfo<ParamType>& info) const {
68  return PrintToString(info.param);
69  }
70 };
71 
72 namespace internal {
73 
74 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
75 // Utility Functions
76 
77 // Outputs a message explaining invalid registration of different
78 // fixture class for the same test suite. This may happen when
79 // TEST_P macro is used to define two tests with the same name
80 // but in different namespaces.
81 GTEST_API_ void ReportInvalidTestSuiteType(const char* test_suite_name,
82  CodeLocation code_location);
83 
84 template <typename> class ParamGeneratorInterface;
85 template <typename> class ParamGenerator;
86 
87 // Interface for iterating over elements provided by an implementation
88 // of ParamGeneratorInterface<T>.
89 template <typename T>
91  public:
92  virtual ~ParamIteratorInterface() {}
93  // A pointer to the base generator instance.
94  // Used only for the purposes of iterator comparison
95  // to make sure that two iterators belong to the same generator.
96  virtual const ParamGeneratorInterface<T>* BaseGenerator() const = 0;
97  // Advances iterator to point to the next element
98  // provided by the generator. The caller is responsible
99  // for not calling Advance() on an iterator equal to
100  // BaseGenerator()->End().
101  virtual void Advance() = 0;
102  // Clones the iterator object. Used for implementing copy semantics
103  // of ParamIterator<T>.
104  virtual ParamIteratorInterface* Clone() const = 0;
105  // Dereferences the current iterator and provides (read-only) access
106  // to the pointed value. It is the caller's responsibility not to call
107  // Current() on an iterator equal to BaseGenerator()->End().
108  // Used for implementing ParamGenerator<T>::operator*().
109  virtual const T* Current() const = 0;
110  // Determines whether the given iterator and other point to the same
111  // element in the sequence generated by the generator.
112  // Used for implementing ParamGenerator<T>::operator==().
113  virtual bool Equals(const ParamIteratorInterface& other) const = 0;
114 };
115 
116 // Class iterating over elements provided by an implementation of
117 // ParamGeneratorInterface<T>. It wraps ParamIteratorInterface<T>
118 // and implements the const forward iterator concept.
119 template <typename T>
121  public:
122  typedef T value_type;
123  typedef const T& reference;
124  typedef ptrdiff_t difference_type;
125 
126  // ParamIterator assumes ownership of the impl_ pointer.
127  ParamIterator(const ParamIterator& other) : impl_(other.impl_->Clone()) {}
128  ParamIterator& operator=(const ParamIterator& other) {
129  if (this != &other)
130  impl_.reset(other.impl_->Clone());
131  return *this;
132  }
133 
134  const T& operator*() const { return *impl_->Current(); }
135  const T* operator->() const { return impl_->Current(); }
136  // Prefix version of operator++.
137  ParamIterator& operator++() {
138  impl_->Advance();
139  return *this;
140  }
141  // Postfix version of operator++.
142  ParamIterator operator++(int /*unused*/) {
143  ParamIteratorInterface<T>* clone = impl_->Clone();
144  impl_->Advance();
145  return ParamIterator(clone);
146  }
147  bool operator==(const ParamIterator& other) const {
148  return impl_.get() == other.impl_.get() || impl_->Equals(*other.impl_);
149  }
150  bool operator!=(const ParamIterator& other) const {
151  return !(*this == other);
152  }
153 
154  private:
155  friend class ParamGenerator<T>;
156  explicit ParamIterator(ParamIteratorInterface<T>* impl) : impl_(impl) {}
157  std::unique_ptr<ParamIteratorInterface<T> > impl_;
158 };
159 
160 // ParamGeneratorInterface<T> is the binary interface to access generators
161 // defined in other translation units.
162 template <typename T>
164  public:
165  typedef T ParamType;
166 
167  virtual ~ParamGeneratorInterface() {}
168 
169  // Generator interface definition
170  virtual ParamIteratorInterface<T>* Begin() const = 0;
171  virtual ParamIteratorInterface<T>* End() const = 0;
172 };
173 
174 // Wraps ParamGeneratorInterface<T> and provides general generator syntax
175 // compatible with the STL Container concept.
176 // This class implements copy initialization semantics and the contained
177 // ParamGeneratorInterface<T> instance is shared among all copies
178 // of the original object. This is possible because that instance is immutable.
179 template<typename T>
180 class ParamGenerator {
181  public:
182  typedef ParamIterator<T> iterator;
183 
184  explicit ParamGenerator(ParamGeneratorInterface<T>* impl) : impl_(impl) {}
185  ParamGenerator(const ParamGenerator& other) : impl_(other.impl_) {}
186 
187  ParamGenerator& operator=(const ParamGenerator& other) {
188  impl_ = other.impl_;
189  return *this;
190  }
191 
192  iterator begin() const { return iterator(impl_->Begin()); }
193  iterator end() const { return iterator(impl_->End()); }
194 
195  private:
196  std::shared_ptr<const ParamGeneratorInterface<T> > impl_;
197 };
198 
199 // Generates values from a range of two comparable values. Can be used to
200 // generate sequences of user-defined types that implement operator+() and
201 // operator<().
202 // This class is used in the Range() function.
203 template <typename T, typename IncrementT>
205  public:
206  RangeGenerator(T begin, T end, IncrementT step)
207  : begin_(begin), end_(end),
208  step_(step), end_index_(CalculateEndIndex(begin, end, step)) {}
209  ~RangeGenerator() override {}
210 
211  ParamIteratorInterface<T>* Begin() const override {
212  return new Iterator(this, begin_, 0, step_);
213  }
214  ParamIteratorInterface<T>* End() const override {
215  return new Iterator(this, end_, end_index_, step_);
216  }
217 
218  private:
219  class Iterator : public ParamIteratorInterface<T> {
220  public:
221  Iterator(const ParamGeneratorInterface<T>* base, T value, int index,
222  IncrementT step)
223  : base_(base), value_(value), index_(index), step_(step) {}
224  ~Iterator() override {}
225 
226  const ParamGeneratorInterface<T>* BaseGenerator() const override {
227  return base_;
228  }
229  void Advance() override {
230  value_ = static_cast<T>(value_ + step_);
231  index_++;
232  }
233  ParamIteratorInterface<T>* Clone() const override {
234  return new Iterator(*this);
235  }
236  const T* Current() const override { return &value_; }
237  bool Equals(const ParamIteratorInterface<T>& other) const override {
238  // Having the same base generator guarantees that the other
239  // iterator is of the same type and we can downcast.
240  GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
241  << "The program attempted to compare iterators "
242  << "from different generators." << std::endl;
243  const int other_index =
244  CheckedDowncastToActualType<const Iterator>(&other)->index_;
245  return index_ == other_index;
246  }
247 
248  private:
249  Iterator(const Iterator& other)
251  base_(other.base_), value_(other.value_), index_(other.index_),
252  step_(other.step_) {}
253 
254  // No implementation - assignment is unsupported.
255  void operator=(const Iterator& other);
256 
257  const ParamGeneratorInterface<T>* const base_;
258  T value_;
259  int index_;
260  const IncrementT step_;
261  }; // class RangeGenerator::Iterator
262 
263  static int CalculateEndIndex(const T& begin,
264  const T& end,
265  const IncrementT& step) {
266  int end_index = 0;
267  for (T i = begin; i < end; i = static_cast<T>(i + step))
268  end_index++;
269  return end_index;
270  }
271 
272  // No implementation - assignment is unsupported.
273  void operator=(const RangeGenerator& other);
274 
275  const T begin_;
276  const T end_;
277  const IncrementT step_;
278  // The index for the end() iterator. All the elements in the generated
279  // sequence are indexed (0-based) to aid iterator comparison.
280  const int end_index_;
281 }; // class RangeGenerator
282 
283 
284 // Generates values from a pair of STL-style iterators. Used in the
285 // ValuesIn() function. The elements are copied from the source range
286 // since the source can be located on the stack, and the generator
287 // is likely to persist beyond that stack frame.
288 template <typename T>
290  public:
291  template <typename ForwardIterator>
292  ValuesInIteratorRangeGenerator(ForwardIterator begin, ForwardIterator end)
293  : container_(begin, end) {}
294  ~ValuesInIteratorRangeGenerator() override {}
295 
296  ParamIteratorInterface<T>* Begin() const override {
297  return new Iterator(this, container_.begin());
298  }
299  ParamIteratorInterface<T>* End() const override {
300  return new Iterator(this, container_.end());
301  }
302 
303  private:
304  typedef typename ::std::vector<T> ContainerType;
305 
306  class Iterator : public ParamIteratorInterface<T> {
307  public:
308  Iterator(const ParamGeneratorInterface<T>* base,
309  typename ContainerType::const_iterator iterator)
310  : base_(base), iterator_(iterator) {}
311  ~Iterator() override {}
312 
313  const ParamGeneratorInterface<T>* BaseGenerator() const override {
314  return base_;
315  }
316  void Advance() override {
317  ++iterator_;
318  value_.reset();
319  }
320  ParamIteratorInterface<T>* Clone() const override {
321  return new Iterator(*this);
322  }
323  // We need to use cached value referenced by iterator_ because *iterator_
324  // can return a temporary object (and of type other then T), so just
325  // having "return &*iterator_;" doesn't work.
326  // value_ is updated here and not in Advance() because Advance()
327  // can advance iterator_ beyond the end of the range, and we cannot
328  // detect that fact. The client code, on the other hand, is
329  // responsible for not calling Current() on an out-of-range iterator.
330  const T* Current() const override {
331  if (value_.get() == nullptr) value_.reset(new T(*iterator_));
332  return value_.get();
333  }
334  bool Equals(const ParamIteratorInterface<T>& other) const override {
335  // Having the same base generator guarantees that the other
336  // iterator is of the same type and we can downcast.
337  GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
338  << "The program attempted to compare iterators "
339  << "from different generators." << std::endl;
340  return iterator_ ==
341  CheckedDowncastToActualType<const Iterator>(&other)->iterator_;
342  }
343 
344  private:
345  Iterator(const Iterator& other)
346  // The explicit constructor call suppresses a false warning
347  // emitted by gcc when supplied with the -Wextra option.
349  base_(other.base_),
350  iterator_(other.iterator_) {}
351 
352  const ParamGeneratorInterface<T>* const base_;
353  typename ContainerType::const_iterator iterator_;
354  // A cached value of *iterator_. We keep it here to allow access by
355  // pointer in the wrapping iterator's operator->().
356  // value_ needs to be mutable to be accessed in Current().
357  // Use of std::unique_ptr helps manage cached value's lifetime,
358  // which is bound by the lifespan of the iterator itself.
359  mutable std::unique_ptr<const T> value_;
360  }; // class ValuesInIteratorRangeGenerator::Iterator
361 
362  // No implementation - assignment is unsupported.
363  void operator=(const ValuesInIteratorRangeGenerator& other);
364 
365  const ContainerType container_;
366 }; // class ValuesInIteratorRangeGenerator
367 
368 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
369 //
370 // Default parameterized test name generator, returns a string containing the
371 // integer test parameter index.
372 template <class ParamType>
373 std::string DefaultParamName(const TestParamInfo<ParamType>& info) {
374  Message name_stream;
375  name_stream << info.index;
376  return name_stream.GetString();
377 }
378 
379 template <typename T = int>
380 void TestNotEmpty() {
381  static_assert(sizeof(T) == 0, "Empty arguments are not allowed.");
382 }
383 template <typename T = int>
384 void TestNotEmpty(const T&) {}
385 
386 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
387 //
388 // Stores a parameter value and later creates tests parameterized with that
389 // value.
390 template <class TestClass>
392  public:
393  typedef typename TestClass::ParamType ParamType;
394  explicit ParameterizedTestFactory(ParamType parameter) :
395  parameter_(parameter) {}
396  Test* CreateTest() override {
397  TestClass::SetParam(&parameter_);
398  return new TestClass();
399  }
400 
401  private:
402  const ParamType parameter_;
403 
404  GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestFactory);
405 };
406 
407 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
408 //
409 // TestMetaFactoryBase is a base class for meta-factories that create
410 // test factories for passing into MakeAndRegisterTestInfo function.
411 template <class ParamType>
413  public:
414  virtual ~TestMetaFactoryBase() {}
415 
416  virtual TestFactoryBase* CreateTestFactory(ParamType parameter) = 0;
417 };
418 
419 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
420 //
421 // TestMetaFactory creates test factories for passing into
422 // MakeAndRegisterTestInfo function. Since MakeAndRegisterTestInfo receives
423 // ownership of test factory pointer, same factory object cannot be passed
424 // into that method twice. But ParameterizedTestSuiteInfo is going to call
425 // it for each Test/Parameter value combination. Thus it needs meta factory
426 // creator class.
427 template <class TestSuite>
429  : public TestMetaFactoryBase<typename TestSuite::ParamType> {
430  public:
431  using ParamType = typename TestSuite::ParamType;
432 
433  TestMetaFactory() {}
434 
435  TestFactoryBase* CreateTestFactory(ParamType parameter) override {
436  return new ParameterizedTestFactory<TestSuite>(parameter);
437  }
438 
439  private:
440  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestMetaFactory);
441 };
442 
443 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
444 //
445 // ParameterizedTestSuiteInfoBase is a generic interface
446 // to ParameterizedTestSuiteInfo classes. ParameterizedTestSuiteInfoBase
447 // accumulates test information provided by TEST_P macro invocations
448 // and generators provided by INSTANTIATE_TEST_SUITE_P macro invocations
449 // and uses that information to register all resulting test instances
450 // in RegisterTests method. The ParameterizeTestSuiteRegistry class holds
451 // a collection of pointers to the ParameterizedTestSuiteInfo objects
452 // and calls RegisterTests() on each of them when asked.
454  public:
455  virtual ~ParameterizedTestSuiteInfoBase() {}
456 
457  // Base part of test suite name for display purposes.
458  virtual const std::string& GetTestSuiteName() const = 0;
459  // Test case id to verify identity.
460  virtual TypeId GetTestSuiteTypeId() const = 0;
461  // UnitTest class invokes this method to register tests in this
462  // test suite right before running them in RUN_ALL_TESTS macro.
463  // This method should not be called more then once on any single
464  // instance of a ParameterizedTestSuiteInfoBase derived class.
465  virtual void RegisterTests() = 0;
466 
467  protected:
469 
470  private:
471  GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestSuiteInfoBase);
472 };
473 
474 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
475 //
476 // ParameterizedTestSuiteInfo accumulates tests obtained from TEST_P
477 // macro invocations for a particular test suite and generators
478 // obtained from INSTANTIATE_TEST_SUITE_P macro invocations for that
479 // test suite. It registers tests with all values generated by all
480 // generators when asked.
481 template <class TestSuite>
483  public:
484  // ParamType and GeneratorCreationFunc are private types but are required
485  // for declarations of public methods AddTestPattern() and
486  // AddTestSuiteInstantiation().
487  using ParamType = typename TestSuite::ParamType;
488  // A function that returns an instance of appropriate generator type.
489  typedef ParamGenerator<ParamType>(GeneratorCreationFunc)();
490  using ParamNameGeneratorFunc = std::string(const TestParamInfo<ParamType>&);
491 
492  explicit ParameterizedTestSuiteInfo(const char* name,
493  CodeLocation code_location)
494  : test_suite_name_(name), code_location_(code_location) {}
495 
496  // Test case base name for display purposes.
497  const std::string& GetTestSuiteName() const override {
498  return test_suite_name_;
499  }
500  // Test case id to verify identity.
501  TypeId GetTestSuiteTypeId() const override { return GetTypeId<TestSuite>(); }
502  // TEST_P macro uses AddTestPattern() to record information
503  // about a single test in a LocalTestInfo structure.
504  // test_suite_name is the base name of the test suite (without invocation
505  // prefix). test_base_name is the name of an individual test without
506  // parameter index. For the test SequenceA/FooTest.DoBar/1 FooTest is
507  // test suite base name and DoBar is test base name.
508  void AddTestPattern(const char* test_suite_name, const char* test_base_name,
509  TestMetaFactoryBase<ParamType>* meta_factory) {
510  tests_.push_back(std::shared_ptr<TestInfo>(
511  new TestInfo(test_suite_name, test_base_name, meta_factory)));
512  }
513  // INSTANTIATE_TEST_SUITE_P macro uses AddGenerator() to record information
514  // about a generator.
515  int AddTestSuiteInstantiation(const std::string& instantiation_name,
516  GeneratorCreationFunc* func,
517  ParamNameGeneratorFunc* name_func,
518  const char* file, int line) {
519  instantiations_.push_back(
520  InstantiationInfo(instantiation_name, func, name_func, file, line));
521  return 0; // Return value used only to run this method in namespace scope.
522  }
523  // UnitTest class invokes this method to register tests in this test suite
524  // test suites right before running tests in RUN_ALL_TESTS macro.
525  // This method should not be called more then once on any single
526  // instance of a ParameterizedTestSuiteInfoBase derived class.
527  // UnitTest has a guard to prevent from calling this method more then once.
528  void RegisterTests() override {
529  for (typename TestInfoContainer::iterator test_it = tests_.begin();
530  test_it != tests_.end(); ++test_it) {
531  std::shared_ptr<TestInfo> test_info = *test_it;
532  for (typename InstantiationContainer::iterator gen_it =
533  instantiations_.begin(); gen_it != instantiations_.end();
534  ++gen_it) {
535  const std::string& instantiation_name = gen_it->name;
536  ParamGenerator<ParamType> generator((*gen_it->generator)());
537  ParamNameGeneratorFunc* name_func = gen_it->name_func;
538  const char* file = gen_it->file;
539  int line = gen_it->line;
540 
541  std::string test_suite_name;
542  if ( !instantiation_name.empty() )
543  test_suite_name = instantiation_name + "/";
544  test_suite_name += test_info->test_suite_base_name;
545 
546  size_t i = 0;
547  std::set<std::string> test_param_names;
548  for (typename ParamGenerator<ParamType>::iterator param_it =
549  generator.begin();
550  param_it != generator.end(); ++param_it, ++i) {
551  Message test_name_stream;
552 
553  std::string param_name = name_func(
554  TestParamInfo<ParamType>(*param_it, i));
555 
556  GTEST_CHECK_(IsValidParamName(param_name))
557  << "Parameterized test name '" << param_name
558  << "' is invalid, in " << file
559  << " line " << line << std::endl;
560 
561  GTEST_CHECK_(test_param_names.count(param_name) == 0)
562  << "Duplicate parameterized test name '" << param_name
563  << "', in " << file << " line " << line << std::endl;
564 
565  test_param_names.insert(param_name);
566 
567  test_name_stream << test_info->test_base_name << "/" << param_name;
568  MakeAndRegisterTestInfo(
569  test_suite_name.c_str(), test_name_stream.GetString().c_str(),
570  nullptr, // No type parameter.
571  PrintToString(*param_it).c_str(), code_location_,
572  GetTestSuiteTypeId(),
575  test_info->test_meta_factory->CreateTestFactory(*param_it));
576  } // for param_it
577  } // for gen_it
578  } // for test_it
579  } // RegisterTests
580 
581  private:
582  // LocalTestInfo structure keeps information about a single test registered
583  // with TEST_P macro.
584  struct TestInfo {
585  TestInfo(const char* a_test_suite_base_name, const char* a_test_base_name,
586  TestMetaFactoryBase<ParamType>* a_test_meta_factory)
587  : test_suite_base_name(a_test_suite_base_name),
588  test_base_name(a_test_base_name),
589  test_meta_factory(a_test_meta_factory) {}
590 
591  const std::string test_suite_base_name;
592  const std::string test_base_name;
593  const std::unique_ptr<TestMetaFactoryBase<ParamType> > test_meta_factory;
594  };
595  using TestInfoContainer = ::std::vector<std::shared_ptr<TestInfo> >;
596  // Records data received from INSTANTIATE_TEST_SUITE_P macros:
597  // <Instantiation name, Sequence generator creation function,
598  // Name generator function, Source file, Source line>
599  struct InstantiationInfo {
600  InstantiationInfo(const std::string &name_in,
601  GeneratorCreationFunc* generator_in,
602  ParamNameGeneratorFunc* name_func_in,
603  const char* file_in,
604  int line_in)
605  : name(name_in),
606  generator(generator_in),
607  name_func(name_func_in),
608  file(file_in),
609  line(line_in) {}
610 
611  std::string name;
612  GeneratorCreationFunc* generator;
613  ParamNameGeneratorFunc* name_func;
614  const char* file;
615  int line;
616  };
617  typedef ::std::vector<InstantiationInfo> InstantiationContainer;
618 
619  static bool IsValidParamName(const std::string& name) {
620  // Check for empty string
621  if (name.empty())
622  return false;
623 
624  // Check for invalid characters
625  for (std::string::size_type index = 0; index < name.size(); ++index) {
626  if (!isalnum(name[index]) && name[index] != '_')
627  return false;
628  }
629 
630  return true;
631  }
632 
633  const std::string test_suite_name_;
634  CodeLocation code_location_;
635  TestInfoContainer tests_;
636  InstantiationContainer instantiations_;
637 
638  GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestSuiteInfo);
639 }; // class ParameterizedTestSuiteInfo
640 
641 // Legacy API is deprecated but still available
642 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
643 template <class TestCase>
645 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
646 
647 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
648 //
649 // ParameterizedTestSuiteRegistry contains a map of
650 // ParameterizedTestSuiteInfoBase classes accessed by test suite names. TEST_P
651 // and INSTANTIATE_TEST_SUITE_P macros use it to locate their corresponding
652 // ParameterizedTestSuiteInfo descriptors.
654  public:
657  for (auto& test_suite_info : test_suite_infos_) {
658  delete test_suite_info;
659  }
660  }
661 
662  // Looks up or creates and returns a structure containing information about
663  // tests and instantiations of a particular test suite.
664  template <class TestSuite>
665  ParameterizedTestSuiteInfo<TestSuite>* GetTestSuitePatternHolder(
666  const char* test_suite_name, CodeLocation code_location) {
667  ParameterizedTestSuiteInfo<TestSuite>* typed_test_info = nullptr;
668  for (auto& test_suite_info : test_suite_infos_) {
669  if (test_suite_info->GetTestSuiteName() == test_suite_name) {
670  if (test_suite_info->GetTestSuiteTypeId() != GetTypeId<TestSuite>()) {
671  // Complain about incorrect usage of Google Test facilities
672  // and terminate the program since we cannot guaranty correct
673  // test suite setup and tear-down in this case.
674  ReportInvalidTestSuiteType(test_suite_name, code_location);
675  posix::Abort();
676  } else {
677  // At this point we are sure that the object we found is of the same
678  // type we are looking for, so we downcast it to that type
679  // without further checks.
680  typed_test_info = CheckedDowncastToActualType<
681  ParameterizedTestSuiteInfo<TestSuite> >(test_suite_info);
682  }
683  break;
684  }
685  }
686  if (typed_test_info == nullptr) {
687  typed_test_info = new ParameterizedTestSuiteInfo<TestSuite>(
688  test_suite_name, code_location);
689  test_suite_infos_.push_back(typed_test_info);
690  }
691  return typed_test_info;
692  }
693  void RegisterTests() {
694  for (auto& test_suite_info : test_suite_infos_) {
695  test_suite_info->RegisterTests();
696  }
697  }
698 // Legacy API is deprecated but still available
699 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
700  template <class TestCase>
701  ParameterizedTestCaseInfo<TestCase>* GetTestCasePatternHolder(
702  const char* test_case_name, CodeLocation code_location) {
703  return GetTestSuitePatternHolder<TestCase>(test_case_name, code_location);
704  }
705 
706 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
707 
708  private:
709  using TestSuiteInfoContainer = ::std::vector<ParameterizedTestSuiteInfoBase*>;
710 
711  TestSuiteInfoContainer test_suite_infos_;
712 
713  GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestSuiteRegistry);
714 };
715 
716 } // namespace internal
717 
718 // Forward declarations of ValuesIn(), which is implemented in
719 // include/gtest/gtest-param-test.h.
720 template <class Container>
722  const Container& container);
723 
724 namespace internal {
725 // Used in the Values() function to provide polymorphic capabilities.
726 
727 template <typename... Ts>
728 class ValueArray {
729  public:
730  ValueArray(Ts... v) : v_{std::move(v)...} {}
731 
732  template <typename T>
733  operator ParamGenerator<T>() const { // NOLINT
734  return ValuesIn(MakeVector<T>(MakeIndexSequence<sizeof...(Ts)>()));
735  }
736 
737  private:
738  template <typename T, size_t... I>
739  std::vector<T> MakeVector(IndexSequence<I...>) const {
740  return std::vector<T>{static_cast<T>(v_.template Get<I>())...};
741  }
742 
743  FlatTuple<Ts...> v_;
744 };
745 
746 } // namespace internal
747 } // namespace testing
748 
749 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_
Definition: gtest-param-util.h:428
Definition: gmock-actions.h:59
Definition: gtest-param-util.h:412
Definition: gtest-param-util.h:204
Definition: gtest-internal.h:535
Definition: gtest-param-util.h:289
Definition: gtest-param-util.h:55
Definition: gtest-message.h:90
Definition: gtest-internal.h:472
Definition: gtest-internal.h:512
Definition: gtest.h:415
Definition: gtest-param-util.h:482
Definition: gtest-param-util.h:391
Definition: gtest-param-util.h:653
Definition: gtest-internal.h:1200
Definition: gtest-internal.h:1181
Definition: gtest-param-util.h:453
Definition: gtest-param-util.h:728
Definition: gtest-param-util.h:90
Definition: gtest-param-util.h:120
Definition: gtest-param-util.h:84
Definition: gtest-internal.h:1228
Definition: gtest-param-util.h:85
Definition: gtest-param-util.h:65