]> git-server-git.apps.pok.os.sepia.ceph.com Git - googletest.git/commitdiff
Merge pull request #2170 from ngie-eign:issue-2146-ver2
authorGennadiy Civil <misterg@google.com>
Thu, 18 Apr 2019 13:44:23 +0000 (09:44 -0400)
committerGennadiy Civil <misterg@google.com>
Thu, 18 Apr 2019 13:44:24 +0000 (09:44 -0400)
PiperOrigin-RevId: 244069956

1  2 
googlemock/test/gmock-matchers_test.cc
googletest/src/gtest-death-test.cc
googletest/src/gtest-internal-inl.h
googletest/src/gtest.cc
googletest/test/gtest_unittest.cc

index 8bdad637d89c74e8cf65fc5a82f9addae08a5fe4,5a5a78630aae1c839aceaa3dc41fd2c704dc564a..eb0a0506ab1b33a45e5b575a61d4f83b4883bbf4
@@@ -4310,8 -4310,9 +4310,11 @@@ TEST(ResultOfTest, WorksForPolymorphicF
  }
  
  TEST(ResultOfTest, WorksForLambdas) {
--  Matcher<int> matcher =
-       ResultOf([](int str_len) { return std::string(str_len, 'x'); }, "xxx");
 -      ResultOf([](int str_len) {
 -          return std::string(static_cast<size_t>(str_len), 'x'); }, "xxx");
++  Matcher<int> matcher = ResultOf(
++      [](int str_len) {
++        return std::string(static_cast<size_t>(str_len), 'x');
++      },
++      "xxx");
    EXPECT_TRUE(matcher.Matches(3));
    EXPECT_FALSE(matcher.Matches(1));
  }
@@@ -5812,7 -5813,7 +5815,7 @@@ class BacktrackingBPMTest : public ::te
  
  // Tests the MaxBipartiteMatching algorithm with square matrices.
  // The single int param is the # of nodes on each of the left and right sides.
- class BipartiteTest : public ::testing::TestWithParam<int> { };
 -class BipartiteTest : public ::testing::TestWithParam<size_t> { };
++class BipartiteTest : public ::testing::TestWithParam<size_t> {};
  
  // Verify all match graphs up to some moderate number of edges.
  TEST_P(BipartiteTest, Exhaustive) {
  }
  
  INSTANTIATE_TEST_SUITE_P(AllGraphs, BipartiteTest,
-                         ::testing::Range(0, 5));
 -                        ::testing::Range(static_cast<size_t>(0),
 -                                         static_cast<size_t>(5)));
++                         ::testing::Range(size_t{0}, size_t{5}));
  
  // Parameterized by a pair interpreted as (LhsSize, RhsSize).
  class BipartiteNonSquareTest
index 76b87a11fc9fa1e5e5941c1802cb8e13e692a8cb,52031f391a020abb164f213c949e4c597f845e38..9bfe315344df8d73818c1805045910e33cef6e46
@@@ -1354,7 -1350,7 +1354,7 @@@ static pid_t ExecDeathTestSpawnChild(ch
  
    if (!use_fork) {
      static const bool stack_grows_down = StackGrowsDown();
-     const size_t stack_size = getpagesize();
 -    const size_t stack_size = static_cast<size_t>(getpagesize());
++    const auto stack_size = static_cast<size_t>(getpagesize());
      // MMAP_ANONYMOUS is not defined on Mac, so we use MAP_ANON instead.
      void* const stack = mmap(nullptr, stack_size, PROT_READ | PROT_WRITE,
                               MAP_ANON | MAP_PRIVATE, -1, 0);
index 29dc6820df9d40978b36bd34d54fcf9adbf40a6a,b3e2724b334a02b00f7ded47ac7958cd849700ef..53cd22b0faf4a12cc1966c953c5dcd00164ab204
@@@ -298,7 -298,8 +298,8 @@@ void ForEach(const Container& c, Functo
  // in range [0, v.size()).
  template <typename E>
  inline E GetElementOr(const std::vector<E>& v, int i, E default_value) {
-   return (i < 0 || i >= static_cast<int>(v.size())) ? default_value : v[i];
 -  return (i < 0 || i >= static_cast<int>(v.size())) ? default_value :
 -        v[static_cast<size_t>(i)];
++  return (i < 0 || i >= static_cast<int>(v.size())) ? default_value
++                                                    : v[static_cast<size_t>(i)];
  }
  
  // Performs an in-place shuffle of a range of the vector's elements.
@@@ -320,8 -321,10 +321,11 @@@ void ShuffleRange(internal::Random* ran
    // http://en.wikipedia.org/wiki/Fisher-Yates_shuffle
    for (int range_width = end - begin; range_width >= 2; range_width--) {
      const int last_in_range = begin + range_width - 1;
-     const int selected = begin + random->Generate(range_width);
-     std::swap((*v)[selected], (*v)[last_in_range]);
 -    const int selected = begin +
 -      static_cast<int>(random->Generate(static_cast<UInt32>(range_width)));
++    const int selected =
++        begin +
++        static_cast<int>(random->Generate(static_cast<UInt32>(range_width)));
+     std::swap((*v)[static_cast<size_t>(selected)],
+               (*v)[static_cast<size_t>(last_in_range)]);
    }
  }
  
@@@ -1083,8 -1086,8 +1087,8 @@@ class StreamingListener : public EmptyT
        GTEST_CHECK_(sockfd_ != -1)
            << "Send() can be called only when there is a connection.";
  
-       const int len = static_cast<int>(message.length());
-       if (write(sockfd_, message.c_str(), len) != len) {
 -      const size_t len = static_cast<size_t>(message.length());
++      const auto len = static_cast<size_t>(message.length());
+       if (write(sockfd_, message.c_str(), len) != static_cast<ssize_t>(len)) {
          GTEST_LOG_(WARNING)
              << "stream_result_to: failed to stream to "
              << host_name_ << ":" << port_num_;
index d4d3d035cd060f53b9a20b375f1f9a3b718c3ad1,320f7cf65207d36b82a94908d9cdb17e122623bd..36210c6eb41e0b91654b813a3775b43a01c880e5
@@@ -1240,9 -1241,11 +1241,10 @@@ std::string CreateUnifiedDiff(const std
      for (; edit_i < edits.size(); ++edit_i) {
        if (n_suffix >= context) {
          // Continue only if the next hunk is very close.
-         std::vector<EditType>::const_iterator it = edits.begin() + edit_i;
 -        std::vector<EditType>::const_iterator it = edits.begin() +
 -                                                   static_cast<int>(edit_i);
++        auto it = edits.begin() + static_cast<int>(edit_i);
          while (it != edits.end() && *it == kMatch) ++it;
-         if (it == edits.end() || (it - edits.begin()) - edit_i >= context) {
+         if (it == edits.end() ||
+             static_cast<size_t>(it - edits.begin()) - edit_i >= context) {
            // There is no next edit or it is too far away.
            break;
          }
@@@ -1808,12 -1811,14 +1810,15 @@@ inline bool IsUtf16SurrogatePair(wchar_
  // Creates a Unicode code point from UTF16 surrogate pair.
  inline UInt32 CreateCodePointFromUtf16SurrogatePair(wchar_t first,
                                                      wchar_t second) {
 -  const UInt32 first_u = static_cast<UInt32>(first);
 -  const UInt32 second_u = static_cast<UInt32>(second);
++  const auto first_u = static_cast<UInt32>(first);
++  const auto second_u = static_cast<UInt32>(second);
    const UInt32 mask = (1 << 10) - 1;
--  return (sizeof(wchar_t) == 2) ?
-       (((first & mask) << 10) | (second & mask)) + 0x10000 :
 -      (((first_u & mask) << 10) | (second_u & mask)) + 0x10000 :
--      // This function should not be called when the condition is
--      // false, but we provide a sensible default in case it is.
-       static_cast<UInt32>(first);
 -      first_u;
++  return (sizeof(wchar_t) == 2)
++             ? (((first_u & mask) << 10) | (second_u & mask)) + 0x10000
++             :
++             // This function should not be called when the condition is
++             // false, but we provide a sensible default in case it is.
++             first_u;
  }
  
  // Converts a wide string to a narrow string in UTF-8 encoding.
@@@ -3421,14 -3431,14 +3431,14 @@@ void TestEventRepeater::Name(const Type
  }
  // This defines a member that forwards the call to all listeners in reverse
  // order.
--#define GTEST_REVERSE_REPEATER_METHOD_(Name, Type) \
--void TestEventRepeater::Name(const Type& parameter) { \
--  if (forwarding_enabled_) { \
-     for (int i = static_cast<int>(listeners_.size()) - 1; i >= 0; i--) { \
-       listeners_[i]->Name(parameter); \
 -    for (size_t i = listeners_.size(); i != 0; i--) { \
 -      listeners_[i-1]->Name(parameter); \
--    } \
--  } \
--}
++#define GTEST_REVERSE_REPEATER_METHOD_(Name, Type)      \
++  void TestEventRepeater::Name(const Type& parameter) { \
++    if (forwarding_enabled_) {                          \
++      for (size_t i = listeners_.size(); i != 0; i--) { \
++        listeners_[i - 1]->Name(parameter);             \
++      }                                                 \
++    }                                                   \
++  }
  
  GTEST_REPEATER_METHOD_(OnTestProgramStart, UnitTest)
  GTEST_REPEATER_METHOD_(OnEnvironmentsSetUpStart, UnitTest)
@@@ -3465,8 -3475,8 +3475,8 @@@ void TestEventRepeater::OnTestIteration
  void TestEventRepeater::OnTestIterationEnd(const UnitTest& unit_test,
                                             int iteration) {
    if (forwarding_enabled_) {
-     for (int i = static_cast<int>(listeners_.size()) - 1; i >= 0; i--) {
-       listeners_[i]->OnTestIterationEnd(unit_test, iteration);
+     for (size_t i = listeners_.size(); i > 0; i--) {
 -      listeners_[i-1]->OnTestIterationEnd(unit_test, iteration);
++      listeners_[i - 1]->OnTestIterationEnd(unit_test, iteration);
      }
    }
  }
@@@ -4069,8 -4079,8 +4079,8 @@@ static std::string FormatEpochTimeInMil
        String::FormatIntWidth2(time_struct.tm_sec) + "Z";
  }
  
- static inline std::string Indent(int width) {
+ static inline std::string Indent(size_t width) {
 -  return std::string(static_cast<size_t>(width), ' ');
 +  return std::string(width, ' ');
  }
  
  void JsonUnitTestResultPrinter::OutputJsonKey(
index 9c1827d44890d42ac657148a507b288036d9aecd,0c8bf99c46dec36d431c3c1e0994673edc465fab..28ced73888fed7a8f73c70dbc73ed5063450af25
@@@ -1018,7 -1018,7 +1018,8 @@@ TEST_F(VectorShuffleTest, ShufflesStart
  
    ASSERT_PRED1(VectorIsNotCorrupt, vector_);
    EXPECT_PRED3(RangeIsShuffled, vector_, 0, kRangeSize);
-   EXPECT_PRED3(RangeIsUnshuffled, vector_, kRangeSize, kVectorSize);
 -  EXPECT_PRED3(RangeIsUnshuffled, vector_, kRangeSize, static_cast<int>(kVectorSize));
++  EXPECT_PRED3(RangeIsUnshuffled, vector_, kRangeSize,
++               static_cast<int>(kVectorSize));
  }
  
  TEST_F(VectorShuffleTest, ShufflesEndOfVector) {
  
    ASSERT_PRED1(VectorIsNotCorrupt, vector_);
    EXPECT_PRED3(RangeIsUnshuffled, vector_, 0, kRangeSize);
-   EXPECT_PRED3(RangeIsShuffled, vector_, kRangeSize, kVectorSize);
 -  EXPECT_PRED3(RangeIsShuffled, vector_, kRangeSize, static_cast<int>(kVectorSize));
++  EXPECT_PRED3(RangeIsShuffled, vector_, kRangeSize,
++               static_cast<int>(kVectorSize));
  }
  
  TEST_F(VectorShuffleTest, ShufflesMiddleOfVector) {
-   int kRangeSize = kVectorSize/3;
 -  int kRangeSize = static_cast<int>(kVectorSize)/3;
++  const int kRangeSize = static_cast<int>(kVectorSize) / 3;
    ShuffleRange(&random_, kRangeSize, 2*kRangeSize, &vector_);
  
    ASSERT_PRED1(VectorIsNotCorrupt, vector_);
    EXPECT_PRED3(RangeIsUnshuffled, vector_, 0, kRangeSize);
    EXPECT_PRED3(RangeIsShuffled, vector_, kRangeSize, 2*kRangeSize);
-   EXPECT_PRED3(RangeIsUnshuffled, vector_, 2*kRangeSize, kVectorSize);
 -  EXPECT_PRED3(RangeIsUnshuffled, vector_, 2*kRangeSize, static_cast<int>(kVectorSize));
++  EXPECT_PRED3(RangeIsUnshuffled, vector_, 2 * kRangeSize,
++               static_cast<int>(kVectorSize));
  }
  
  TEST_F(VectorShuffleTest, ShufflesRepeatably) {
@@@ -5654,11 -5654,11 +5657,11 @@@ class ParseFlagsTest : public Test 
  
    // Asserts that two narrow or wide string arrays are equal.
    template <typename CharType>
-   static void AssertStringArrayEq(size_t size1, CharType** array1,
-                                   size_t size2, CharType** array2) {
 -  static void AssertStringArrayEq(int size1, CharType** array1,
 -                                  int size2, CharType** array2) {
++  static void AssertStringArrayEq(int size1, CharType** array1, int size2,
++                                  CharType** array2) {
      ASSERT_EQ(size1, size2) << " Array sizes different.";
  
-     for (size_t i = 0; i != size1; i++) {
+     for (int i = 0; i != size1; i++) {
        ASSERT_STREQ(array1[i], array2[i]) << " where i == " << i;
      }
    }