From: Gennadiy Civil Date: Thu, 18 Apr 2019 13:44:23 +0000 (-0400) Subject: Merge pull request #2170 from ngie-eign:issue-2146-ver2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a0d60bed4d0ea17c7130cda16776b9bc8a929d7b;p=googletest.git Merge pull request #2170 from ngie-eign:issue-2146-ver2 PiperOrigin-RevId: 244069956 --- a0d60bed4d0ea17c7130cda16776b9bc8a929d7b diff --cc googlemock/test/gmock-matchers_test.cc index 8bdad63,5a5a786..eb0a050 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@@ -4310,8 -4310,9 +4310,11 @@@ TEST(ResultOfTest, WorksForPolymorphicF } TEST(ResultOfTest, WorksForLambdas) { -- Matcher matcher = - ResultOf([](int str_len) { return std::string(str_len, 'x'); }, "xxx"); - ResultOf([](int str_len) { - return std::string(static_cast(str_len), 'x'); }, "xxx"); ++ Matcher matcher = ResultOf( ++ [](int str_len) { ++ return std::string(static_cast(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 { }; -class BipartiteTest : public ::testing::TestWithParam { }; ++class BipartiteTest : public ::testing::TestWithParam {}; // Verify all match graphs up to some moderate number of edges. TEST_P(BipartiteTest, Exhaustive) { @@@ -5841,7 -5842,8 +5844,7 @@@ } INSTANTIATE_TEST_SUITE_P(AllGraphs, BipartiteTest, - ::testing::Range(0, 5)); - ::testing::Range(static_cast(0), - static_cast(5))); ++ ::testing::Range(size_t{0}, size_t{5})); // Parameterized by a pair interpreted as (LhsSize, RhsSize). class BipartiteNonSquareTest diff --cc googletest/src/gtest-death-test.cc index 76b87a1,52031f3..9bfe315 --- a/googletest/src/gtest-death-test.cc +++ b/googletest/src/gtest-death-test.cc @@@ -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(getpagesize()); ++ const auto stack_size = static_cast(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); diff --cc googletest/src/gtest-internal-inl.h index 29dc682,b3e2724..53cd22b --- a/googletest/src/gtest-internal-inl.h +++ b/googletest/src/gtest-internal-inl.h @@@ -298,7 -298,8 +298,8 @@@ void ForEach(const Container& c, Functo // in range [0, v.size()). template inline E GetElementOr(const std::vector& v, int i, E default_value) { - return (i < 0 || i >= static_cast(v.size())) ? default_value : v[i]; - return (i < 0 || i >= static_cast(v.size())) ? default_value : - v[static_cast(i)]; ++ return (i < 0 || i >= static_cast(v.size())) ? default_value ++ : v[static_cast(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(random->Generate(static_cast(range_width))); ++ const int selected = ++ begin + ++ static_cast(random->Generate(static_cast(range_width))); + std::swap((*v)[static_cast(selected)], + (*v)[static_cast(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(message.length()); - if (write(sockfd_, message.c_str(), len) != len) { - const size_t len = static_cast(message.length()); ++ const auto len = static_cast(message.length()); + if (write(sockfd_, message.c_str(), len) != static_cast(len)) { GTEST_LOG_(WARNING) << "stream_result_to: failed to stream to " << host_name_ << ":" << port_num_; diff --cc googletest/src/gtest.cc index d4d3d03,320f7cf..36210c6 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@@ -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::const_iterator it = edits.begin() + edit_i; - std::vector::const_iterator it = edits.begin() + - static_cast(edit_i); ++ auto it = edits.begin() + static_cast(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(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(first); - const UInt32 second_u = static_cast(second); ++ const auto first_u = static_cast(first); ++ const auto second_u = static_cast(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(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(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(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(width), ' '); + return std::string(width, ' '); } void JsonUnitTestResultPrinter::OutputJsonKey( diff --cc googletest/test/gtest_unittest.cc index 9c1827d,0c8bf99..28ced73 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@@ -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(kVectorSize)); ++ EXPECT_PRED3(RangeIsUnshuffled, vector_, kRangeSize, ++ static_cast(kVectorSize)); } TEST_F(VectorShuffleTest, ShufflesEndOfVector) { @@@ -1027,17 -1027,17 +1028,19 @@@ ASSERT_PRED1(VectorIsNotCorrupt, vector_); EXPECT_PRED3(RangeIsUnshuffled, vector_, 0, kRangeSize); - EXPECT_PRED3(RangeIsShuffled, vector_, kRangeSize, kVectorSize); - EXPECT_PRED3(RangeIsShuffled, vector_, kRangeSize, static_cast(kVectorSize)); ++ EXPECT_PRED3(RangeIsShuffled, vector_, kRangeSize, ++ static_cast(kVectorSize)); } TEST_F(VectorShuffleTest, ShufflesMiddleOfVector) { - int kRangeSize = kVectorSize/3; - int kRangeSize = static_cast(kVectorSize)/3; ++ const int kRangeSize = static_cast(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(kVectorSize)); ++ EXPECT_PRED3(RangeIsUnshuffled, vector_, 2 * kRangeSize, ++ static_cast(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 - 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; } }