gmock/gtest/include/gtest/internal/gtest-param-util.h
Go to the documentation of this file.
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 // Author: vladl@google.com (Vlad Losev)
31 
32 // Type and function utilities for implementing parameterized tests.
33 
34 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_
35 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_
36 
37 #include <iterator>
38 #include <utility>
39 #include <vector>
40 
41 // scripts/fuse_gtest.py depends on gtest's own header being #included
42 // *unconditionally*. Therefore these #includes cannot be moved
43 // inside #if GTEST_HAS_PARAM_TEST.
44 #include "gtest/internal/gtest-internal.h"
45 #include "gtest/internal/gtest-linked_ptr.h"
46 #include "gtest/internal/gtest-port.h"
47 #include "gtest/gtest-printers.h"
48 
49 #if GTEST_HAS_PARAM_TEST
50 
51 namespace testing
52 {
53 namespace internal
54 {
55 
56 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
57 //
58 // Outputs a message explaining invalid registration of different
59 // fixture class for the same test case. This may happen when
60 // TEST_P macro is used to define two tests with the same name
61 // but in different namespaces.
62 GTEST_API_ void ReportInvalidTestCaseType(const char * test_case_name,
63  const char * file, int line);
64 
65 template <typename> class ParamGeneratorInterface;
66 template <typename> class ParamGenerator;
67 
68 // Interface for iterating over elements provided by an implementation
69 // of ParamGeneratorInterface<T>.
70 template <typename T>
71 class ParamIteratorInterface
72 {
73 public:
74  virtual ~ParamIteratorInterface() {}
75  // A pointer to the base generator instance.
76  // Used only for the purposes of iterator comparison
77  // to make sure that two iterators belong to the same generator.
78  virtual const ParamGeneratorInterface<T> * BaseGenerator() const = 0;
79  // Advances iterator to point to the next element
80  // provided by the generator. The caller is responsible
81  // for not calling Advance() on an iterator equal to
82  // BaseGenerator()->End().
83  virtual void Advance() = 0;
84  // Clones the iterator object. Used for implementing copy semantics
85  // of ParamIterator<T>.
86  virtual ParamIteratorInterface * Clone() const = 0;
87  // Dereferences the current iterator and provides (read-only) access
88  // to the pointed value. It is the caller's responsibility not to call
89  // Current() on an iterator equal to BaseGenerator()->End().
90  // Used for implementing ParamGenerator<T>::operator*().
91  virtual const T * Current() const = 0;
92  // Determines whether the given iterator and other point to the same
93  // element in the sequence generated by the generator.
94  // Used for implementing ParamGenerator<T>::operator==().
95  virtual bool Equals(const ParamIteratorInterface & other) const = 0;
96 };
97 
98 // Class iterating over elements provided by an implementation of
99 // ParamGeneratorInterface<T>. It wraps ParamIteratorInterface<T>
100 // and implements the const forward iterator concept.
101 template <typename T>
102 class ParamIterator
103 {
104 public:
105  typedef T value_type;
106  typedef const T & reference;
107  typedef ptrdiff_t difference_type;
108 
109  // ParamIterator assumes ownership of the impl_ pointer.
110  ParamIterator(const ParamIterator & other) : impl_(other.impl_->Clone()) {}
111  ParamIterator & operator=(const ParamIterator & other)
112  {
113  if (this != &other)
114  { impl_.reset(other.impl_->Clone()); }
115 
116  return *this;
117  }
118 
119  const T & operator*() const { return *impl_->Current(); }
120  const T * operator->() const { return impl_->Current(); }
121  // Prefix version of operator++.
122  ParamIterator & operator++()
123  {
124  impl_->Advance();
125  return *this;
126  }
127  // Postfix version of operator++.
128  ParamIterator operator++(int /*unused*/)
129  {
130  ParamIteratorInterface<T> * clone = impl_->Clone();
131  impl_->Advance();
132  return ParamIterator(clone);
133  }
134  bool operator==(const ParamIterator & other) const
135  {
136  return impl_.get() == other.impl_.get() || impl_->Equals(*other.impl_);
137  }
138  bool operator!=(const ParamIterator & other) const
139  {
140  return !(*this == other);
141  }
142 
143 private:
144  friend class ParamGenerator<T>;
145  explicit ParamIterator(ParamIteratorInterface<T> * impl) : impl_(impl) {}
146  scoped_ptr<ParamIteratorInterface<T> > impl_;
147 };
148 
149 // ParamGeneratorInterface<T> is the binary interface to access generators
150 // defined in other translation units.
151 template <typename T>
152 class ParamGeneratorInterface
153 {
154 public:
155  typedef T ParamType;
156 
157  virtual ~ParamGeneratorInterface() {}
158 
159  // Generator interface definition
160  virtual ParamIteratorInterface<T> * Begin() const = 0;
161  virtual ParamIteratorInterface<T> * End() const = 0;
162 };
163 
164 // Wraps ParamGeneratorInterface<T> and provides general generator syntax
165 // compatible with the STL Container concept.
166 // This class implements copy initialization semantics and the contained
167 // ParamGeneratorInterface<T> instance is shared among all copies
168 // of the original object. This is possible because that instance is immutable.
169 template<typename T>
170 class ParamGenerator
171 {
172 public:
173  typedef ParamIterator<T> iterator;
174 
175  explicit ParamGenerator(ParamGeneratorInterface<T> * impl) : impl_(impl) {}
176  ParamGenerator(const ParamGenerator & other) : impl_(other.impl_) {}
177 
178  ParamGenerator & operator=(const ParamGenerator & other)
179  {
180  impl_ = other.impl_;
181  return *this;
182  }
183 
184  iterator begin() const { return iterator(impl_->Begin()); }
185  iterator end() const { return iterator(impl_->End()); }
186 
187 private:
188  linked_ptr<const ParamGeneratorInterface<T> > impl_;
189 };
190 
191 // Generates values from a range of two comparable values. Can be used to
192 // generate sequences of user-defined types that implement operator+() and
193 // operator<().
194 // This class is used in the Range() function.
195 template <typename T, typename IncrementT>
196 class RangeGenerator : public ParamGeneratorInterface<T>
197 {
198 public:
199  RangeGenerator(T begin, T end, IncrementT step)
200  : begin_(begin), end_(end),
201  step_(step), end_index_(CalculateEndIndex(begin, end, step)) {}
202  virtual ~RangeGenerator() {}
203 
204  virtual ParamIteratorInterface<T> * Begin() const
205  {
206  return new Iterator(this, begin_, 0, step_);
207  }
208  virtual ParamIteratorInterface<T> * End() const
209  {
210  return new Iterator(this, end_, end_index_, step_);
211  }
212 
213 private:
214  class Iterator : public ParamIteratorInterface<T>
215  {
216  public:
217  Iterator(const ParamGeneratorInterface<T> * base, T value, int index,
218  IncrementT step)
219  : base_(base), value_(value), index_(index), step_(step) {}
220  virtual ~Iterator() {}
221 
222  virtual const ParamGeneratorInterface<T> * BaseGenerator() const
223  {
224  return base_;
225  }
226  virtual void Advance()
227  {
228  value_ = value_ + step_;
229  index_++;
230  }
231  virtual ParamIteratorInterface<T> * Clone() const
232  {
233  return new Iterator(*this);
234  }
235  virtual const T * Current() const { return &value_; }
236  virtual bool Equals(const ParamIteratorInterface<T> & other) const
237  {
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)
250  : ParamIteratorInterface<T>(),
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  {
267  int end_index = 0;
268 
269  for (T i = begin; i < end; i = i + step)
270  { end_index++; }
271 
272  return end_index;
273  }
274 
275  // No implementation - assignment is unsupported.
276  void operator=(const RangeGenerator & other);
277 
278  const T begin_;
279  const T end_;
280  const IncrementT step_;
281  // The index for the end() iterator. All the elements in the generated
282  // sequence are indexed (0-based) to aid iterator comparison.
283  const int end_index_;
284 }; // class RangeGenerator
285 
286 
287 // Generates values from a pair of STL-style iterators. Used in the
288 // ValuesIn() function. The elements are copied from the source range
289 // since the source can be located on the stack, and the generator
290 // is likely to persist beyond that stack frame.
291 template <typename T>
292 class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface<T>
293 {
294 public:
295  template <typename ForwardIterator>
296  ValuesInIteratorRangeGenerator(ForwardIterator begin, ForwardIterator end)
297  : container_(begin, end) {}
298  virtual ~ValuesInIteratorRangeGenerator() {}
299 
300  virtual ParamIteratorInterface<T> * Begin() const
301  {
302  return new Iterator(this, container_.begin());
303  }
304  virtual ParamIteratorInterface<T> * End() const
305  {
306  return new Iterator(this, container_.end());
307  }
308 
309 private:
310  typedef typename ::std::vector<T> ContainerType;
311 
312  class Iterator : public ParamIteratorInterface<T>
313  {
314  public:
315  Iterator(const ParamGeneratorInterface<T> * base,
316  typename ContainerType::const_iterator iterator)
317  : base_(base), iterator_(iterator) {}
318  virtual ~Iterator() {}
319 
320  virtual const ParamGeneratorInterface<T> * BaseGenerator() const
321  {
322  return base_;
323  }
324  virtual void Advance()
325  {
326  ++iterator_;
327  value_.reset();
328  }
329  virtual ParamIteratorInterface<T> * Clone() const
330  {
331  return new Iterator(*this);
332  }
333  // We need to use cached value referenced by iterator_ because *iterator_
334  // can return a temporary object (and of type other then T), so just
335  // having "return &*iterator_;" doesn't work.
336  // value_ is updated here and not in Advance() because Advance()
337  // can advance iterator_ beyond the end of the range, and we cannot
338  // detect that fact. The client code, on the other hand, is
339  // responsible for not calling Current() on an out-of-range iterator.
340  virtual const T * Current() const
341  {
342  if (value_.get() == NULL)
343  { value_.reset(new T(*iterator_)); }
344 
345  return value_.get();
346  }
347  virtual bool Equals(const ParamIteratorInterface<T> & other) const
348  {
349  // Having the same base generator guarantees that the other
350  // iterator is of the same type and we can downcast.
351  GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
352  << "The program attempted to compare iterators "
353  << "from different generators." << std::endl;
354  return iterator_ ==
355  CheckedDowncastToActualType<const Iterator>(&other)->iterator_;
356  }
357 
358  private:
359  Iterator(const Iterator & other)
360  // The explicit constructor call suppresses a false warning
361  // emitted by gcc when supplied with the -Wextra option.
362  : ParamIteratorInterface<T>(),
363  base_(other.base_),
364  iterator_(other.iterator_) {}
365 
366  const ParamGeneratorInterface<T> * const base_;
367  typename ContainerType::const_iterator iterator_;
368  // A cached value of *iterator_. We keep it here to allow access by
369  // pointer in the wrapping iterator's operator->().
370  // value_ needs to be mutable to be accessed in Current().
371  // Use of scoped_ptr helps manage cached value's lifetime,
372  // which is bound by the lifespan of the iterator itself.
373  mutable scoped_ptr<const T> value_;
374  }; // class ValuesInIteratorRangeGenerator::Iterator
375 
376  // No implementation - assignment is unsupported.
377  void operator=(const ValuesInIteratorRangeGenerator & other);
378 
379  const ContainerType container_;
380 }; // class ValuesInIteratorRangeGenerator
381 
382 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
383 //
384 // Stores a parameter value and later creates tests parameterized with that
385 // value.
386 template <class TestClass>
387 class ParameterizedTestFactory : public TestFactoryBase
388 {
389 public:
390  typedef typename TestClass::ParamType ParamType;
391  explicit ParameterizedTestFactory(ParamType parameter) :
392  parameter_(parameter) {}
393  virtual Test * CreateTest()
394  {
395  TestClass::SetParam(&parameter_);
396  return new TestClass();
397  }
398 
399 private:
400  const ParamType parameter_;
401 
402  GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestFactory);
403 };
404 
405 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
406 //
407 // TestMetaFactoryBase is a base class for meta-factories that create
408 // test factories for passing into MakeAndRegisterTestInfo function.
409 template <class ParamType>
410 class TestMetaFactoryBase
411 {
412 public:
413  virtual ~TestMetaFactoryBase() {}
414 
415  virtual TestFactoryBase * CreateTestFactory(ParamType parameter) = 0;
416 };
417 
418 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
419 //
420 // TestMetaFactory creates test factories for passing into
421 // MakeAndRegisterTestInfo function. Since MakeAndRegisterTestInfo receives
422 // ownership of test factory pointer, same factory object cannot be passed
423 // into that method twice. But ParameterizedTestCaseInfo is going to call
424 // it for each Test/Parameter value combination. Thus it needs meta factory
425 // creator class.
426 template <class TestCase>
427 class TestMetaFactory
428  : public TestMetaFactoryBase<typename TestCase::ParamType>
429 {
430 public:
431  typedef typename TestCase::ParamType ParamType;
432 
433  TestMetaFactory() {}
434 
435  virtual TestFactoryBase * CreateTestFactory(ParamType parameter)
436  {
437  return new ParameterizedTestFactory<TestCase>(parameter);
438  }
439 
440 private:
441  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestMetaFactory);
442 };
443 
444 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
445 //
446 // ParameterizedTestCaseInfoBase is a generic interface
447 // to ParameterizedTestCaseInfo classes. ParameterizedTestCaseInfoBase
448 // accumulates test information provided by TEST_P macro invocations
449 // and generators provided by INSTANTIATE_TEST_CASE_P macro invocations
450 // and uses that information to register all resulting test instances
451 // in RegisterTests method. The ParameterizeTestCaseRegistry class holds
452 // a collection of pointers to the ParameterizedTestCaseInfo objects
453 // and calls RegisterTests() on each of them when asked.
454 class ParameterizedTestCaseInfoBase
455 {
456 public:
457  virtual ~ParameterizedTestCaseInfoBase() {}
458 
459  // Base part of test case name for display purposes.
460  virtual const string & GetTestCaseName() const = 0;
461  // Test case id to verify identity.
462  virtual TypeId GetTestCaseTypeId() const = 0;
463  // UnitTest class invokes this method to register tests in this
464  // test case right before running them in RUN_ALL_TESTS macro.
465  // This method should not be called more then once on any single
466  // instance of a ParameterizedTestCaseInfoBase derived class.
467  virtual void RegisterTests() = 0;
468 
469 protected:
470  ParameterizedTestCaseInfoBase() {}
471 
472 private:
473  GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestCaseInfoBase);
474 };
475 
476 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
477 //
478 // ParameterizedTestCaseInfo accumulates tests obtained from TEST_P
479 // macro invocations for a particular test case and generators
480 // obtained from INSTANTIATE_TEST_CASE_P macro invocations for that
481 // test case. It registers tests with all values generated by all
482 // generators when asked.
483 template <class TestCase>
484 class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase
485 {
486 public:
487  // ParamType and GeneratorCreationFunc are private types but are required
488  // for declarations of public methods AddTestPattern() and
489  // AddTestCaseInstantiation().
490  typedef typename TestCase::ParamType ParamType;
491  // A function that returns an instance of appropriate generator type.
492  typedef ParamGenerator<ParamType>(GeneratorCreationFunc)();
493 
494  explicit ParameterizedTestCaseInfo(const char * name)
495  : test_case_name_(name) {}
496 
497  // Test case base name for display purposes.
498  virtual const string & GetTestCaseName() const { return test_case_name_; }
499  // Test case id to verify identity.
500  virtual TypeId GetTestCaseTypeId() const { return GetTypeId<TestCase>(); }
501  // TEST_P macro uses AddTestPattern() to record information
502  // about a single test in a LocalTestInfo structure.
503  // test_case_name is the base name of the test case (without invocation
504  // prefix). test_base_name is the name of an individual test without
505  // parameter index. For the test SequenceA/FooTest.DoBar/1 FooTest is
506  // test case base name and DoBar is test base name.
507  void AddTestPattern(const char * test_case_name,
508  const char * test_base_name,
509  TestMetaFactoryBase<ParamType> * meta_factory)
510  {
511  tests_.push_back(linked_ptr<TestInfo>(new TestInfo(test_case_name,
512  test_base_name,
513  meta_factory)));
514  }
515  // INSTANTIATE_TEST_CASE_P macro uses AddGenerator() to record information
516  // about a generator.
517  int AddTestCaseInstantiation(const string & instantiation_name,
518  GeneratorCreationFunc * func,
519  const char * /* file */,
520  int /* line */)
521  {
522  instantiations_.push_back(::std::make_pair(instantiation_name, func));
523  return 0; // Return value used only to run this method in namespace scope.
524  }
525  // UnitTest class invokes this method to register tests in this test case
526  // test cases right before running tests in RUN_ALL_TESTS macro.
527  // This method should not be called more then once on any single
528  // instance of a ParameterizedTestCaseInfoBase derived class.
529  // UnitTest has a guard to prevent from calling this method more then once.
530  virtual void RegisterTests()
531  {
532  for (typename TestInfoContainer::iterator test_it = tests_.begin();
533  test_it != tests_.end(); ++test_it)
534  {
535  linked_ptr<TestInfo> test_info = *test_it;
536 
537  for (typename InstantiationContainer::iterator gen_it =
538  instantiations_.begin(); gen_it != instantiations_.end();
539  ++gen_it)
540  {
541  const string & instantiation_name = gen_it->first;
542  ParamGenerator<ParamType> generator((*gen_it->second)());
543 
544  string test_case_name;
545 
546  if (!instantiation_name.empty())
547  { test_case_name = instantiation_name + "/"; }
548 
549  test_case_name += test_info->test_case_base_name;
550 
551  int i = 0;
552 
553  for (typename ParamGenerator<ParamType>::iterator param_it =
554  generator.begin();
555  param_it != generator.end(); ++param_it, ++i)
556  {
557  Message test_name_stream;
558  test_name_stream << test_info->test_base_name << "/" << i;
560  test_case_name.c_str(),
561  test_name_stream.GetString().c_str(),
562  NULL, // No type parameter.
563  PrintToString(*param_it).c_str(),
564  GetTestCaseTypeId(),
565  TestCase::SetUpTestCase,
566  TestCase::TearDownTestCase,
567  test_info->test_meta_factory->CreateTestFactory(*param_it));
568  } // for param_it
569  } // for gen_it
570  } // for test_it
571  } // RegisterTests
572 
573 private:
574  // LocalTestInfo structure keeps information about a single test registered
575  // with TEST_P macro.
576  struct TestInfo
577  {
578  TestInfo(const char * a_test_case_base_name,
579  const char * a_test_base_name,
580  TestMetaFactoryBase<ParamType> * a_test_meta_factory) :
581  test_case_base_name(a_test_case_base_name),
582  test_base_name(a_test_base_name),
583  test_meta_factory(a_test_meta_factory) {}
584 
585  const string test_case_base_name;
586  const string test_base_name;
587  const scoped_ptr<TestMetaFactoryBase<ParamType> > test_meta_factory;
588  };
589  typedef ::std::vector<linked_ptr<TestInfo> > TestInfoContainer;
590  // Keeps pairs of <Instantiation name, Sequence generator creation function>
591  // received from INSTANTIATE_TEST_CASE_P macros.
592  typedef ::std::vector<std::pair<string, GeneratorCreationFunc *> >
593  InstantiationContainer;
594 
595  const string test_case_name_;
596  TestInfoContainer tests_;
597  InstantiationContainer instantiations_;
598 
599  GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestCaseInfo);
600 }; // class ParameterizedTestCaseInfo
601 
602 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
603 //
604 // ParameterizedTestCaseRegistry contains a map of ParameterizedTestCaseInfoBase
605 // classes accessed by test case names. TEST_P and INSTANTIATE_TEST_CASE_P
606 // macros use it to locate their corresponding ParameterizedTestCaseInfo
607 // descriptors.
608 class ParameterizedTestCaseRegistry
609 {
610 public:
611  ParameterizedTestCaseRegistry() {}
612  ~ParameterizedTestCaseRegistry()
613  {
614  for (TestCaseInfoContainer::iterator it = test_case_infos_.begin();
615  it != test_case_infos_.end(); ++it)
616  {
617  delete *it;
618  }
619  }
620 
621  // Looks up or creates and returns a structure containing information about
622  // tests and instantiations of a particular test case.
623  template <class TestCase>
624  ParameterizedTestCaseInfo<TestCase> * GetTestCasePatternHolder(
625  const char * test_case_name,
626  const char * file,
627  int line)
628  {
629  ParameterizedTestCaseInfo<TestCase> * typed_test_info = NULL;
630 
631  for (TestCaseInfoContainer::iterator it = test_case_infos_.begin();
632  it != test_case_infos_.end(); ++it)
633  {
634  if ((*it)->GetTestCaseName() == test_case_name)
635  {
636  if ((*it)->GetTestCaseTypeId() != GetTypeId<TestCase>())
637  {
638  // Complain about incorrect usage of Google Test facilities
639  // and terminate the program since we cannot guaranty correct
640  // test case setup and tear-down in this case.
641  ReportInvalidTestCaseType(test_case_name, file, line);
642  posix::Abort();
643  }
644 
645  else
646  {
647  // At this point we are sure that the object we found is of the same
648  // type we are looking for, so we downcast it to that type
649  // without further checks.
650  typed_test_info = CheckedDowncastToActualType <
651  ParameterizedTestCaseInfo<TestCase> > (*it);
652  }
653 
654  break;
655  }
656  }
657 
658  if (typed_test_info == NULL)
659  {
660  typed_test_info = new ParameterizedTestCaseInfo<TestCase>(test_case_name);
661  test_case_infos_.push_back(typed_test_info);
662  }
663 
664  return typed_test_info;
665  }
666  void RegisterTests()
667  {
668  for (TestCaseInfoContainer::iterator it = test_case_infos_.begin();
669  it != test_case_infos_.end(); ++it)
670  {
671  (*it)->RegisterTests();
672  }
673  }
674 
675 private:
676  typedef ::std::vector<ParameterizedTestCaseInfoBase *> TestCaseInfoContainer;
677 
678  TestCaseInfoContainer test_case_infos_;
679 
680  GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestCaseRegistry);
681 };
682 
683 } // namespace internal
684 } // namespace testing
685 
686 #endif // GTEST_HAS_PARAM_TEST
687 
688 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
#define GTEST_API_
::std::string PrintToString(const T &value)
const char Message[]
Definition: strings.h:102
Derived * CheckedDowncastToActualType(Base *base)
virtual bool Equals(const ParamIteratorInterface &other) const =0
bool operator==(T *ptr, const linked_ptr< T > &x)
TestInfo * MakeAndRegisterTestInfo(const char *test_case_name, const char *name, const char *type_param, const char *value_param, TypeId fixture_class_id, SetUpTestCaseFunc set_up_tc, TearDownTestCaseFunc tear_down_tc, TestFactoryBase *factory)
name
Definition: setup.py:38
void ReportInvalidTestCaseType(const char *test_case_name, const char *file, int line)
virtual const T * Current() const =0
virtual const ParamGeneratorInterface< T > * BaseGenerator() const =0
virtual ParamIteratorInterface * Clone() const =0
bool operator!=(T *ptr, const linked_ptr< T > &x)
#define GTEST_CHECK_(condition)


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Tue Jan 19 2021 03:06:20