Merge pull request #2388 from kuzkry:remove-gtest-type-util.pump
PiperOrigin-RevId: 276944601
This commit is contained in:
		@@ -133,10 +133,10 @@ All tests should pass.
 | 
			
		||||
 | 
			
		||||
Some of Google Test's source files are generated from templates (not in the C++
 | 
			
		||||
sense) using a script. For example, the file
 | 
			
		||||
include/gtest/internal/gtest-type-util.h.pump is used to generate
 | 
			
		||||
gtest-type-util.h in the same directory.
 | 
			
		||||
*googlemock/include/gmock/gmock-generated-actions.h.pump* is used to generate
 | 
			
		||||
*gmock-generated-actions.h* in the same directory.
 | 
			
		||||
 | 
			
		||||
You don't need to worry about regenerating the source files unless you need to
 | 
			
		||||
modify them. You would then modify the corresponding `.pump` files and run the
 | 
			
		||||
'[pump.py](googletest/scripts/pump.py)' generator script. See the
 | 
			
		||||
[Pump Manual](googletest/docs/pump_manual.md).
 | 
			
		||||
'[pump.py](googlemock/scripts/pump.py)' generator script. See the
 | 
			
		||||
[Pump Manual](googlemock/docs/pump_manual.md).
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										182
									
								
								googlemock/test/pump_test.py
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										182
									
								
								googlemock/test/pump_test.py
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,182 @@
 | 
			
		||||
#!/usr/bin/env python
 | 
			
		||||
#
 | 
			
		||||
# Copyright 2010, Google Inc.
 | 
			
		||||
# All rights reserved.
 | 
			
		||||
#
 | 
			
		||||
# Redistribution and use in source and binary forms, with or without
 | 
			
		||||
# modification, are permitted provided that the following conditions are
 | 
			
		||||
# met:
 | 
			
		||||
#
 | 
			
		||||
#     * Redistributions of source code must retain the above copyright
 | 
			
		||||
# notice, this list of conditions and the following disclaimer.
 | 
			
		||||
#     * Redistributions in binary form must reproduce the above
 | 
			
		||||
# copyright notice, this list of conditions and the following disclaimer
 | 
			
		||||
# in the documentation and/or other materials provided with the
 | 
			
		||||
# distribution.
 | 
			
		||||
#     * Neither the name of Google Inc. nor the names of its
 | 
			
		||||
# contributors may be used to endorse or promote products derived from
 | 
			
		||||
# this software without specific prior written permission.
 | 
			
		||||
#
 | 
			
		||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 | 
			
		||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 | 
			
		||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 | 
			
		||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 | 
			
		||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 | 
			
		||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 | 
			
		||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 | 
			
		||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 | 
			
		||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 | 
			
		||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
 | 
			
		||||
"""Tests for the Pump meta-programming tool."""
 | 
			
		||||
 | 
			
		||||
from google3.testing.pybase import googletest
 | 
			
		||||
import google3.third_party.googletest.googlemock.scripts.pump
 | 
			
		||||
 | 
			
		||||
pump = google3.third_party.googletest.googlemock.scripts.pump
 | 
			
		||||
Convert = pump.ConvertFromPumpSource
 | 
			
		||||
StripMetaComments = pump.StripMetaComments
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class PumpTest(googletest.TestCase):
 | 
			
		||||
 | 
			
		||||
  def testConvertsEmptyToEmpty(self):
 | 
			
		||||
    self.assertEquals('', Convert('').strip())
 | 
			
		||||
 | 
			
		||||
  def testConvertsPlainCodeToSame(self):
 | 
			
		||||
    self.assertEquals('#include <stdio.h>\n',
 | 
			
		||||
                      Convert('#include <stdio.h>\n'))
 | 
			
		||||
 | 
			
		||||
  def testConvertsLongIWYUPragmaToSame(self):
 | 
			
		||||
    long_line = '// IWYU pragma: private, include "' + (80*'a') + '.h"\n'
 | 
			
		||||
    self.assertEquals(long_line, Convert(long_line))
 | 
			
		||||
 | 
			
		||||
  def testConvertsIWYUPragmaWithLeadingSpaceToSame(self):
 | 
			
		||||
    long_line = ' // IWYU pragma: private, include "' + (80*'a') + '.h"\n'
 | 
			
		||||
    self.assertEquals(long_line, Convert(long_line))
 | 
			
		||||
 | 
			
		||||
  def testConvertsIWYUPragmaWithSlashStarLeaderToSame(self):
 | 
			
		||||
    long_line = '/* IWYU pragma: private, include "' + (80*'a') + '.h"\n'
 | 
			
		||||
    self.assertEquals(long_line, Convert(long_line))
 | 
			
		||||
 | 
			
		||||
  def testConvertsIWYUPragmaWithSlashStarAndSpacesToSame(self):
 | 
			
		||||
    long_line = ' /* IWYU pragma: private, include "' + (80*'a') + '.h"\n'
 | 
			
		||||
    self.assertEquals(long_line, Convert(long_line))
 | 
			
		||||
 | 
			
		||||
  def testIgnoresMetaComment(self):
 | 
			
		||||
    self.assertEquals('',
 | 
			
		||||
                      Convert('$$ This is a Pump meta comment.\n').strip())
 | 
			
		||||
 | 
			
		||||
  def testSimpleVarDeclarationWorks(self):
 | 
			
		||||
    self.assertEquals('3\n',
 | 
			
		||||
                      Convert('$var m = 3\n'
 | 
			
		||||
                              '$m\n'))
 | 
			
		||||
 | 
			
		||||
  def testVarDeclarationCanReferenceEarlierVar(self):
 | 
			
		||||
    self.assertEquals('43 != 3;\n',
 | 
			
		||||
                      Convert('$var a = 42\n'
 | 
			
		||||
                              '$var b = a + 1\n'
 | 
			
		||||
                              '$var c = (b - a)*3\n'
 | 
			
		||||
                              '$b != $c;\n'))
 | 
			
		||||
 | 
			
		||||
  def testSimpleLoopWorks(self):
 | 
			
		||||
    self.assertEquals('1, 2, 3, 4, 5\n',
 | 
			
		||||
                      Convert('$var n = 5\n'
 | 
			
		||||
                              '$range i 1..n\n'
 | 
			
		||||
                              '$for i, [[$i]]\n'))
 | 
			
		||||
 | 
			
		||||
  def testSimpleLoopWithCommentWorks(self):
 | 
			
		||||
    self.assertEquals('1, 2, 3, 4, 5\n',
 | 
			
		||||
                      Convert('$var n = 5    $$ This is comment 1.\n'
 | 
			
		||||
                              '$range i 1..n $$ This is comment 2.\n'
 | 
			
		||||
                              '$for i, [[$i]]\n'))
 | 
			
		||||
 | 
			
		||||
  def testNonTrivialRangeExpressionsWork(self):
 | 
			
		||||
    self.assertEquals('1, 2, 3, 4\n',
 | 
			
		||||
                      Convert('$var n = 5\n'
 | 
			
		||||
                              '$range i (n/n)..(n - 1)\n'
 | 
			
		||||
                              '$for i, [[$i]]\n'))
 | 
			
		||||
 | 
			
		||||
  def testLoopWithoutSeparatorWorks(self):
 | 
			
		||||
    self.assertEquals('a + 1 + 2 + 3;\n',
 | 
			
		||||
                      Convert('$range i 1..3\n'
 | 
			
		||||
                              'a$for i [[ + $i]];\n'))
 | 
			
		||||
 | 
			
		||||
  def testCanGenerateDollarSign(self):
 | 
			
		||||
    self.assertEquals('$\n', Convert('$($)\n'))
 | 
			
		||||
 | 
			
		||||
  def testCanIterpolateExpressions(self):
 | 
			
		||||
    self.assertEquals('a[2] = 3;\n',
 | 
			
		||||
                      Convert('$var i = 1\n'
 | 
			
		||||
                              'a[$(i + 1)] = $(i*4 - 1);\n'))
 | 
			
		||||
 | 
			
		||||
  def testConditionalWithoutElseBranchWorks(self):
 | 
			
		||||
    self.assertEquals('true\n',
 | 
			
		||||
                      Convert('$var n = 5\n'
 | 
			
		||||
                              '$if n > 0 [[true]]\n'))
 | 
			
		||||
 | 
			
		||||
  def testConditionalWithElseBranchWorks(self):
 | 
			
		||||
    self.assertEquals('true -- really false\n',
 | 
			
		||||
                      Convert('$var n = 5\n'
 | 
			
		||||
                              '$if n > 0 [[true]]\n'
 | 
			
		||||
                              '$else [[false]] -- \n'
 | 
			
		||||
                              '$if n > 10 [[really true]]\n'
 | 
			
		||||
                              '$else [[really false]]\n'))
 | 
			
		||||
 | 
			
		||||
  def testConditionalWithCascadingElseBranchWorks(self):
 | 
			
		||||
    self.assertEquals('a\n',
 | 
			
		||||
                      Convert('$var n = 5\n'
 | 
			
		||||
                              '$if n > 0 [[a]]\n'
 | 
			
		||||
                              '$elif n > 10 [[b]]\n'
 | 
			
		||||
                              '$else [[c]]\n'))
 | 
			
		||||
    self.assertEquals('b\n',
 | 
			
		||||
                      Convert('$var n = 5\n'
 | 
			
		||||
                              '$if n > 10 [[a]]\n'
 | 
			
		||||
                              '$elif n > 0 [[b]]\n'
 | 
			
		||||
                              '$else [[c]]\n'))
 | 
			
		||||
    self.assertEquals('c\n',
 | 
			
		||||
                      Convert('$var n = 5\n'
 | 
			
		||||
                              '$if n > 10 [[a]]\n'
 | 
			
		||||
                              '$elif n > 8 [[b]]\n'
 | 
			
		||||
                              '$else [[c]]\n'))
 | 
			
		||||
 | 
			
		||||
  def testNestedLexicalBlocksWork(self):
 | 
			
		||||
    self.assertEquals('a = 5;\n',
 | 
			
		||||
                      Convert('$var n = 5\n'
 | 
			
		||||
                              'a = [[$if n > 0 [[$n]]]];\n'))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class StripMetaCommentsTest(googletest.TestCase):
 | 
			
		||||
 | 
			
		||||
  def testReturnsSameStringIfItContainsNoComment(self):
 | 
			
		||||
    self.assertEquals('', StripMetaComments(''))
 | 
			
		||||
    self.assertEquals(' blah ', StripMetaComments(' blah '))
 | 
			
		||||
    self.assertEquals('A single $ is fine.',
 | 
			
		||||
                      StripMetaComments('A single $ is fine.'))
 | 
			
		||||
    self.assertEquals('multiple\nlines',
 | 
			
		||||
                      StripMetaComments('multiple\nlines'))
 | 
			
		||||
 | 
			
		||||
  def testStripsSimpleComment(self):
 | 
			
		||||
    self.assertEquals('yes\n', StripMetaComments('yes $$ or no?\n'))
 | 
			
		||||
 | 
			
		||||
  def testStripsSimpleCommentWithMissingNewline(self):
 | 
			
		||||
    self.assertEquals('yes', StripMetaComments('yes $$ or no?'))
 | 
			
		||||
 | 
			
		||||
  def testStripsPureCommentLinesEntirely(self):
 | 
			
		||||
    self.assertEquals('yes\n',
 | 
			
		||||
                      StripMetaComments('$$ a pure comment line.\n'
 | 
			
		||||
                                        'yes $$ or no?\n'
 | 
			
		||||
                                        '    $$ another comment line.\n'))
 | 
			
		||||
 | 
			
		||||
  def testStripsCommentsFromMultiLineText(self):
 | 
			
		||||
    self.assertEquals('multi-\n'
 | 
			
		||||
                      'line\n'
 | 
			
		||||
                      'text is fine.',
 | 
			
		||||
                      StripMetaComments('multi- $$ comment 1\n'
 | 
			
		||||
                                        'line\n'
 | 
			
		||||
                                        'text is fine. $$ comment 2'))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
  googletest.main()
 | 
			
		||||
@@ -17,6 +17,7 @@ Jói Sigurðsson <joi@google.com>
 | 
			
		||||
Keir Mierle <mierle@gmail.com>
 | 
			
		||||
Keith Ray <keith.ray@gmail.com>
 | 
			
		||||
Kenton Varda <kenton@google.com>
 | 
			
		||||
Krystian Kuzniarek <krystian.kuzniarek@gmail.com>
 | 
			
		||||
Manuel Klimek <klimek@google.com>
 | 
			
		||||
Markus Heule <markus.heule@gmail.com>
 | 
			
		||||
Mika Raento <mikie@iki.fi>
 | 
			
		||||
 
 | 
			
		||||
@@ -27,7 +27,6 @@
 | 
			
		||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 | 
			
		||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// GOOGLETEST_CM0001 DO NOT DELETE
 | 
			
		||||
 | 
			
		||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_
 | 
			
		||||
@@ -189,12 +188,12 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
 | 
			
		||||
  gtest_type_params_##TestSuiteName##_NameGenerator
 | 
			
		||||
 | 
			
		||||
#define TYPED_TEST_SUITE(CaseName, Types, ...)                          \
 | 
			
		||||
  typedef ::testing::internal::TypeList<Types>::type GTEST_TYPE_PARAMS_( \
 | 
			
		||||
      CaseName);                                                         \
 | 
			
		||||
  typedef ::testing::internal::GenerateTypeList<Types>::type            \
 | 
			
		||||
      GTEST_TYPE_PARAMS_(CaseName);                                     \
 | 
			
		||||
  typedef ::testing::internal::NameGeneratorSelector<__VA_ARGS__>::type \
 | 
			
		||||
      GTEST_NAME_GENERATOR_(CaseName)
 | 
			
		||||
 | 
			
		||||
# define TYPED_TEST(CaseName, TestName)                                       \
 | 
			
		||||
#define TYPED_TEST(CaseName, TestName)                                        \
 | 
			
		||||
  template <typename gtest_TypeParam_>                                        \
 | 
			
		||||
  class GTEST_TEST_CLASS_NAME_(CaseName, TestName)                            \
 | 
			
		||||
      : public CaseName<gtest_TypeParam_> {                                   \
 | 
			
		||||
@@ -204,8 +203,7 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
 | 
			
		||||
    void TestBody() override;                                                 \
 | 
			
		||||
  };                                                                          \
 | 
			
		||||
  static bool gtest_##CaseName##_##TestName##_registered_                     \
 | 
			
		||||
        GTEST_ATTRIBUTE_UNUSED_ =                                             \
 | 
			
		||||
      ::testing::internal::TypeParameterizedTest<                             \
 | 
			
		||||
      GTEST_ATTRIBUTE_UNUSED_ = ::testing::internal::TypeParameterizedTest<   \
 | 
			
		||||
          CaseName,                                                           \
 | 
			
		||||
          ::testing::internal::TemplateSel<GTEST_TEST_CLASS_NAME_(CaseName,   \
 | 
			
		||||
                                                                  TestName)>, \
 | 
			
		||||
@@ -288,7 +286,7 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
 | 
			
		||||
 | 
			
		||||
#define REGISTER_TYPED_TEST_SUITE_P(SuiteName, ...)                         \
 | 
			
		||||
  namespace GTEST_SUITE_NAMESPACE_(SuiteName) {                             \
 | 
			
		||||
    typedef ::testing::internal::Templates<__VA_ARGS__>::type gtest_AllTests_; \
 | 
			
		||||
    typedef ::testing::internal::Templates<__VA_ARGS__> gtest_AllTests_;    \
 | 
			
		||||
  }                                                                         \
 | 
			
		||||
  static const char* const GTEST_REGISTERED_TEST_NAMES_(                    \
 | 
			
		||||
      SuiteName) GTEST_ATTRIBUTE_UNUSED_ =                                  \
 | 
			
		||||
@@ -307,7 +305,7 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
 | 
			
		||||
  static bool gtest_##Prefix##_##SuiteName GTEST_ATTRIBUTE_UNUSED_ =        \
 | 
			
		||||
      ::testing::internal::TypeParameterizedTestSuite<                      \
 | 
			
		||||
          SuiteName, GTEST_SUITE_NAMESPACE_(SuiteName)::gtest_AllTests_,    \
 | 
			
		||||
          ::testing::internal::TypeList<Types>::type>::                     \
 | 
			
		||||
          ::testing::internal::GenerateTypeList<Types>::type>::             \
 | 
			
		||||
          Register(#Prefix,                                                 \
 | 
			
		||||
                   ::testing::internal::CodeLocation(__FILE__, __LINE__),   \
 | 
			
		||||
                   >EST_TYPED_TEST_SUITE_P_STATE_(SuiteName), #SuiteName, \
 | 
			
		||||
@@ -315,7 +313,7 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
 | 
			
		||||
                   ::testing::internal::GenerateNames<                      \
 | 
			
		||||
                       ::testing::internal::NameGeneratorSelector<          \
 | 
			
		||||
                           __VA_ARGS__>::type,                              \
 | 
			
		||||
                       ::testing::internal::TypeList<Types>::type>())
 | 
			
		||||
                       ::testing::internal::GenerateTypeList<Types>::type>())
 | 
			
		||||
 | 
			
		||||
// Legacy API is deprecated but still available
 | 
			
		||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
 | 
			
		||||
 
 | 
			
		||||
@@ -662,7 +662,7 @@ struct NameGeneratorSelector {
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename NameGenerator>
 | 
			
		||||
void GenerateNamesRecursively(Types0, std::vector<std::string>*, int) {}
 | 
			
		||||
void GenerateNamesRecursively(internal::None, std::vector<std::string>*, int) {}
 | 
			
		||||
 | 
			
		||||
template <typename NameGenerator, typename Types>
 | 
			
		||||
void GenerateNamesRecursively(Types, std::vector<std::string>* result, int i) {
 | 
			
		||||
@@ -729,7 +729,7 @@ class TypeParameterizedTest {
 | 
			
		||||
 | 
			
		||||
// The base case for the compile time recursion.
 | 
			
		||||
template <GTEST_TEMPLATE_ Fixture, class TestSel>
 | 
			
		||||
class TypeParameterizedTest<Fixture, TestSel, Types0> {
 | 
			
		||||
class TypeParameterizedTest<Fixture, TestSel, internal::None> {
 | 
			
		||||
 public:
 | 
			
		||||
  static bool Register(const char* /*prefix*/, const CodeLocation&,
 | 
			
		||||
                       const char* /*case_name*/, const char* /*test_names*/,
 | 
			
		||||
@@ -781,7 +781,7 @@ class TypeParameterizedTestSuite {
 | 
			
		||||
 | 
			
		||||
// The base case for the compile time recursion.
 | 
			
		||||
template <GTEST_TEMPLATE_ Fixture, typename Types>
 | 
			
		||||
class TypeParameterizedTestSuite<Fixture, Templates0, Types> {
 | 
			
		||||
class TypeParameterizedTestSuite<Fixture, internal::None, Types> {
 | 
			
		||||
 public:
 | 
			
		||||
  static bool Register(const char* /*prefix*/, const CodeLocation&,
 | 
			
		||||
                       const TypedTestSuitePState* /*state*/,
 | 
			
		||||
 
 | 
			
		||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -1,302 +0,0 @@
 | 
			
		||||
$$ -*- mode: c++; -*-
 | 
			
		||||
$var n = 50  $$ Maximum length of type lists we want to support.
 | 
			
		||||
// Copyright 2008 Google Inc.
 | 
			
		||||
// All Rights Reserved.
 | 
			
		||||
//
 | 
			
		||||
// Redistribution and use in source and binary forms, with or without
 | 
			
		||||
// modification, are permitted provided that the following conditions are
 | 
			
		||||
// met:
 | 
			
		||||
//
 | 
			
		||||
//     * Redistributions of source code must retain the above copyright
 | 
			
		||||
// notice, this list of conditions and the following disclaimer.
 | 
			
		||||
//     * Redistributions in binary form must reproduce the above
 | 
			
		||||
// copyright notice, this list of conditions and the following disclaimer
 | 
			
		||||
// in the documentation and/or other materials provided with the
 | 
			
		||||
// distribution.
 | 
			
		||||
//     * Neither the name of Google Inc. nor the names of its
 | 
			
		||||
// contributors may be used to endorse or promote products derived from
 | 
			
		||||
// this software without specific prior written permission.
 | 
			
		||||
//
 | 
			
		||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 | 
			
		||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 | 
			
		||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 | 
			
		||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 | 
			
		||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 | 
			
		||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 | 
			
		||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 | 
			
		||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 | 
			
		||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 | 
			
		||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Type utilities needed for implementing typed and type-parameterized
 | 
			
		||||
// tests.  This file is generated by a SCRIPT.  DO NOT EDIT BY HAND!
 | 
			
		||||
//
 | 
			
		||||
// Currently we support at most $n types in a list, and at most $n
 | 
			
		||||
// type-parameterized tests in one type-parameterized test suite.
 | 
			
		||||
// Please contact googletestframework@googlegroups.com if you need
 | 
			
		||||
// more.
 | 
			
		||||
 | 
			
		||||
// GOOGLETEST_CM0001 DO NOT DELETE
 | 
			
		||||
 | 
			
		||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
 | 
			
		||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
 | 
			
		||||
 | 
			
		||||
#include "gtest/internal/gtest-port.h"
 | 
			
		||||
 | 
			
		||||
// #ifdef __GNUC__ is too general here.  It is possible to use gcc without using
 | 
			
		||||
// libstdc++ (which is where cxxabi.h comes from).
 | 
			
		||||
# if GTEST_HAS_CXXABI_H_
 | 
			
		||||
#  include <cxxabi.h>
 | 
			
		||||
# elif defined(__HP_aCC)
 | 
			
		||||
#  include <acxx_demangle.h>
 | 
			
		||||
# endif  // GTEST_HASH_CXXABI_H_
 | 
			
		||||
 | 
			
		||||
namespace testing {
 | 
			
		||||
namespace internal {
 | 
			
		||||
 | 
			
		||||
// Canonicalizes a given name with respect to the Standard C++ Library.
 | 
			
		||||
// This handles removing the inline namespace within `std` that is
 | 
			
		||||
// used by various standard libraries (e.g., `std::__1`).  Names outside
 | 
			
		||||
// of namespace std are returned unmodified.
 | 
			
		||||
inline std::string CanonicalizeForStdLibVersioning(std::string s) {
 | 
			
		||||
  static const char prefix[] = "std::__";
 | 
			
		||||
  if (s.compare(0, strlen(prefix), prefix) == 0) {
 | 
			
		||||
    std::string::size_type end = s.find("::", strlen(prefix));
 | 
			
		||||
    if (end != s.npos) {
 | 
			
		||||
      // Erase everything between the initial `std` and the second `::`.
 | 
			
		||||
      s.erase(strlen("std"), end - strlen("std"));
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  return s;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetTypeName<T>() returns a human-readable name of type T.
 | 
			
		||||
// NB: This function is also used in Google Mock, so don't move it inside of
 | 
			
		||||
// the typed-test-only section below.
 | 
			
		||||
template <typename T>
 | 
			
		||||
std::string GetTypeName() {
 | 
			
		||||
# if GTEST_HAS_RTTI
 | 
			
		||||
 | 
			
		||||
  const char* const name = typeid(T).name();
 | 
			
		||||
#  if GTEST_HAS_CXXABI_H_ || defined(__HP_aCC)
 | 
			
		||||
  int status = 0;
 | 
			
		||||
  // gcc's implementation of typeid(T).name() mangles the type name,
 | 
			
		||||
  // so we have to demangle it.
 | 
			
		||||
#   if GTEST_HAS_CXXABI_H_
 | 
			
		||||
  using abi::__cxa_demangle;
 | 
			
		||||
#   endif  // GTEST_HAS_CXXABI_H_
 | 
			
		||||
  char* const readable_name = __cxa_demangle(name, nullptr, nullptr, &status);
 | 
			
		||||
  const std::string name_str(status == 0 ? readable_name : name);
 | 
			
		||||
  free(readable_name);
 | 
			
		||||
  return CanonicalizeForStdLibVersioning(name_str);
 | 
			
		||||
#  else
 | 
			
		||||
  return name;
 | 
			
		||||
#  endif  // GTEST_HAS_CXXABI_H_ || __HP_aCC
 | 
			
		||||
 | 
			
		||||
# else
 | 
			
		||||
 | 
			
		||||
  return "<type>";
 | 
			
		||||
 | 
			
		||||
# endif  // GTEST_HAS_RTTI
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
 | 
			
		||||
 | 
			
		||||
// A unique type used as the default value for the arguments of class
 | 
			
		||||
// template Types.  This allows us to simulate variadic templates
 | 
			
		||||
// (e.g. Types<int>, Type<int, double>, and etc), which C++ doesn't
 | 
			
		||||
// support directly.
 | 
			
		||||
struct None {};
 | 
			
		||||
 | 
			
		||||
// The following family of struct and struct templates are used to
 | 
			
		||||
// represent type lists.  In particular, TypesN<T1, T2, ..., TN>
 | 
			
		||||
// represents a type list with N types (T1, T2, ..., and TN) in it.
 | 
			
		||||
// Except for Types0, every struct in the family has two member types:
 | 
			
		||||
// Head for the first type in the list, and Tail for the rest of the
 | 
			
		||||
// list.
 | 
			
		||||
 | 
			
		||||
// The empty type list.
 | 
			
		||||
struct Types0 {};
 | 
			
		||||
 | 
			
		||||
// Type lists of length 1, 2, 3, and so on.
 | 
			
		||||
 | 
			
		||||
template <typename T1>
 | 
			
		||||
struct Types1 {
 | 
			
		||||
  typedef T1 Head;
 | 
			
		||||
  typedef Types0 Tail;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
$range i 2..n
 | 
			
		||||
 | 
			
		||||
$for i [[
 | 
			
		||||
$range j 1..i
 | 
			
		||||
$range k 2..i
 | 
			
		||||
template <$for j, [[typename T$j]]>
 | 
			
		||||
struct Types$i {
 | 
			
		||||
  typedef T1 Head;
 | 
			
		||||
  typedef Types$(i-1)<$for k, [[T$k]]> Tail;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
]]
 | 
			
		||||
 | 
			
		||||
}  // namespace internal
 | 
			
		||||
 | 
			
		||||
// We don't want to require the users to write TypesN<...> directly,
 | 
			
		||||
// as that would require them to count the length.  Types<...> is much
 | 
			
		||||
// easier to write, but generates horrible messages when there is a
 | 
			
		||||
// compiler error, as gcc insists on printing out each template
 | 
			
		||||
// argument, even if it has the default value (this means Types<int>
 | 
			
		||||
// will appear as Types<int, None, None, ..., None> in the compiler
 | 
			
		||||
// errors).
 | 
			
		||||
//
 | 
			
		||||
// Our solution is to combine the best part of the two approaches: a
 | 
			
		||||
// user would write Types<T1, ..., TN>, and Google Test will translate
 | 
			
		||||
// that to TypesN<T1, ..., TN> internally to make error messages
 | 
			
		||||
// readable.  The translation is done by the 'type' member of the
 | 
			
		||||
// Types template.
 | 
			
		||||
 | 
			
		||||
$range i 1..n
 | 
			
		||||
template <$for i, [[typename T$i = internal::None]]>
 | 
			
		||||
struct Types {
 | 
			
		||||
  typedef internal::Types$n<$for i, [[T$i]]> type;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <>
 | 
			
		||||
struct Types<$for i, [[internal::None]]> {
 | 
			
		||||
  typedef internal::Types0 type;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
$range i 1..n-1
 | 
			
		||||
$for i [[
 | 
			
		||||
$range j 1..i
 | 
			
		||||
$range k i+1..n
 | 
			
		||||
template <$for j, [[typename T$j]]>
 | 
			
		||||
struct Types<$for j, [[T$j]]$for k[[, internal::None]]> {
 | 
			
		||||
  typedef internal::Types$i<$for j, [[T$j]]> type;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
]]
 | 
			
		||||
 | 
			
		||||
namespace internal {
 | 
			
		||||
 | 
			
		||||
# define GTEST_TEMPLATE_ template <typename T> class
 | 
			
		||||
 | 
			
		||||
// The template "selector" struct TemplateSel<Tmpl> is used to
 | 
			
		||||
// represent Tmpl, which must be a class template with one type
 | 
			
		||||
// parameter, as a type.  TemplateSel<Tmpl>::Bind<T>::type is defined
 | 
			
		||||
// as the type Tmpl<T>.  This allows us to actually instantiate the
 | 
			
		||||
// template "selected" by TemplateSel<Tmpl>.
 | 
			
		||||
//
 | 
			
		||||
// This trick is necessary for simulating typedef for class templates,
 | 
			
		||||
// which C++ doesn't support directly.
 | 
			
		||||
template <GTEST_TEMPLATE_ Tmpl>
 | 
			
		||||
struct TemplateSel {
 | 
			
		||||
  template <typename T>
 | 
			
		||||
  struct Bind {
 | 
			
		||||
    typedef Tmpl<T> type;
 | 
			
		||||
  };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
# define GTEST_BIND_(TmplSel, T) \
 | 
			
		||||
  TmplSel::template Bind<T>::type
 | 
			
		||||
 | 
			
		||||
// A unique struct template used as the default value for the
 | 
			
		||||
// arguments of class template Templates.  This allows us to simulate
 | 
			
		||||
// variadic templates (e.g. Templates<int>, Templates<int, double>,
 | 
			
		||||
// and etc), which C++ doesn't support directly.
 | 
			
		||||
template <typename T>
 | 
			
		||||
struct NoneT {};
 | 
			
		||||
 | 
			
		||||
// The following family of struct and struct templates are used to
 | 
			
		||||
// represent template lists.  In particular, TemplatesN<T1, T2, ...,
 | 
			
		||||
// TN> represents a list of N templates (T1, T2, ..., and TN).  Except
 | 
			
		||||
// for Templates0, every struct in the family has two member types:
 | 
			
		||||
// Head for the selector of the first template in the list, and Tail
 | 
			
		||||
// for the rest of the list.
 | 
			
		||||
 | 
			
		||||
// The empty template list.
 | 
			
		||||
struct Templates0 {};
 | 
			
		||||
 | 
			
		||||
// Template lists of length 1, 2, 3, and so on.
 | 
			
		||||
 | 
			
		||||
template <GTEST_TEMPLATE_ T1>
 | 
			
		||||
struct Templates1 {
 | 
			
		||||
  typedef TemplateSel<T1> Head;
 | 
			
		||||
  typedef Templates0 Tail;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
$range i 2..n
 | 
			
		||||
 | 
			
		||||
$for i [[
 | 
			
		||||
$range j 1..i
 | 
			
		||||
$range k 2..i
 | 
			
		||||
template <$for j, [[GTEST_TEMPLATE_ T$j]]>
 | 
			
		||||
struct Templates$i {
 | 
			
		||||
  typedef TemplateSel<T1> Head;
 | 
			
		||||
  typedef Templates$(i-1)<$for k, [[T$k]]> Tail;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
]]
 | 
			
		||||
 | 
			
		||||
// We don't want to require the users to write TemplatesN<...> directly,
 | 
			
		||||
// as that would require them to count the length.  Templates<...> is much
 | 
			
		||||
// easier to write, but generates horrible messages when there is a
 | 
			
		||||
// compiler error, as gcc insists on printing out each template
 | 
			
		||||
// argument, even if it has the default value (this means Templates<list>
 | 
			
		||||
// will appear as Templates<list, NoneT, NoneT, ..., NoneT> in the compiler
 | 
			
		||||
// errors).
 | 
			
		||||
//
 | 
			
		||||
// Our solution is to combine the best part of the two approaches: a
 | 
			
		||||
// user would write Templates<T1, ..., TN>, and Google Test will translate
 | 
			
		||||
// that to TemplatesN<T1, ..., TN> internally to make error messages
 | 
			
		||||
// readable.  The translation is done by the 'type' member of the
 | 
			
		||||
// Templates template.
 | 
			
		||||
 | 
			
		||||
$range i 1..n
 | 
			
		||||
template <$for i, [[GTEST_TEMPLATE_ T$i = NoneT]]>
 | 
			
		||||
struct Templates {
 | 
			
		||||
  typedef Templates$n<$for i, [[T$i]]> type;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <>
 | 
			
		||||
struct Templates<$for i, [[NoneT]]> {
 | 
			
		||||
  typedef Templates0 type;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
$range i 1..n-1
 | 
			
		||||
$for i [[
 | 
			
		||||
$range j 1..i
 | 
			
		||||
$range k i+1..n
 | 
			
		||||
template <$for j, [[GTEST_TEMPLATE_ T$j]]>
 | 
			
		||||
struct Templates<$for j, [[T$j]]$for k[[, NoneT]]> {
 | 
			
		||||
  typedef Templates$i<$for j, [[T$j]]> type;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
]]
 | 
			
		||||
 | 
			
		||||
// The TypeList template makes it possible to use either a single type
 | 
			
		||||
// or a Types<...> list in TYPED_TEST_SUITE() and
 | 
			
		||||
// INSTANTIATE_TYPED_TEST_SUITE_P().
 | 
			
		||||
 | 
			
		||||
template <typename T>
 | 
			
		||||
struct TypeList {
 | 
			
		||||
  typedef Types1<T> type;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
$range i 1..n
 | 
			
		||||
template <$for i, [[typename T$i]]>
 | 
			
		||||
struct TypeList<Types<$for i, [[T$i]]> > {
 | 
			
		||||
  typedef typename Types<$for i, [[T$i]]>::type type;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif  // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
 | 
			
		||||
 | 
			
		||||
}  // namespace internal
 | 
			
		||||
}  // namespace testing
 | 
			
		||||
 | 
			
		||||
#endif  // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
 | 
			
		||||
@@ -188,7 +188,7 @@ TEST(ApiTest, TestSuiteImmutableAccessorsWork) {
 | 
			
		||||
  ASSERT_TRUE(test_suite != nullptr);
 | 
			
		||||
 | 
			
		||||
  EXPECT_STREQ("TestSuiteWithCommentTest/0", test_suite->name());
 | 
			
		||||
  EXPECT_STREQ(GetTypeName<int>().c_str(), test_suite->type_param());
 | 
			
		||||
  EXPECT_STREQ(GetTypeName<Types<int>>().c_str(), test_suite->type_param());
 | 
			
		||||
  EXPECT_TRUE(test_suite->should_run());
 | 
			
		||||
  EXPECT_EQ(0, test_suite->disabled_test_count());
 | 
			
		||||
  EXPECT_EQ(1, test_suite->test_to_run_count());
 | 
			
		||||
@@ -199,7 +199,7 @@ TEST(ApiTest, TestSuiteImmutableAccessorsWork) {
 | 
			
		||||
  EXPECT_STREQ("Dummy", tests[0]->name());
 | 
			
		||||
  EXPECT_STREQ("TestSuiteWithCommentTest/0", tests[0]->test_suite_name());
 | 
			
		||||
  EXPECT_TRUE(IsNull(tests[0]->value_param()));
 | 
			
		||||
  EXPECT_STREQ(GetTypeName<int>().c_str(), tests[0]->type_param());
 | 
			
		||||
  EXPECT_STREQ(GetTypeName<Types<int>>().c_str(), tests[0]->type_param());
 | 
			
		||||
  EXPECT_TRUE(tests[0]->should_run());
 | 
			
		||||
 | 
			
		||||
  delete[] tests;
 | 
			
		||||
@@ -265,7 +265,8 @@ class FinalSuccessChecker : public Environment {
 | 
			
		||||
 | 
			
		||||
#if GTEST_HAS_TYPED_TEST
 | 
			
		||||
    EXPECT_STREQ("TestSuiteWithCommentTest/0", test_suites[2]->name());
 | 
			
		||||
    EXPECT_STREQ(GetTypeName<int>().c_str(), test_suites[2]->type_param());
 | 
			
		||||
    EXPECT_STREQ(GetTypeName<Types<int>>().c_str(),
 | 
			
		||||
                 test_suites[2]->type_param());
 | 
			
		||||
    EXPECT_TRUE(test_suites[2]->should_run());
 | 
			
		||||
    EXPECT_EQ(0, test_suites[2]->disabled_test_count());
 | 
			
		||||
    ASSERT_EQ(1, test_suites[2]->total_test_count());
 | 
			
		||||
@@ -317,7 +318,7 @@ class FinalSuccessChecker : public Environment {
 | 
			
		||||
    EXPECT_STREQ("Dummy", tests[0]->name());
 | 
			
		||||
    EXPECT_STREQ("TestSuiteWithCommentTest/0", tests[0]->test_suite_name());
 | 
			
		||||
    EXPECT_TRUE(IsNull(tests[0]->value_param()));
 | 
			
		||||
    EXPECT_STREQ(GetTypeName<int>().c_str(), tests[0]->type_param());
 | 
			
		||||
    EXPECT_STREQ(GetTypeName<Types<int>>().c_str(), tests[0]->type_param());
 | 
			
		||||
    EXPECT_TRUE(tests[0]->should_run());
 | 
			
		||||
    EXPECT_TRUE(tests[0]->result()->Passed());
 | 
			
		||||
    EXPECT_EQ(0, tests[0]->result()->test_property_count());
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user