diff options
Diffstat (limited to 'googletest/test/gtest_unittest.cc')
-rw-r--r-- | googletest/test/gtest_unittest.cc | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 9c1827d..28ced73 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -899,23 +899,23 @@ TEST(ContainerUtilityDeathTest, ShuffleRange) { class VectorShuffleTest : public Test { protected: - static const int kVectorSize = 20; + static const size_t kVectorSize = 20; VectorShuffleTest() : random_(1) { - for (int i = 0; i < kVectorSize; i++) { + for (int i = 0; i < static_cast<int>(kVectorSize); i++) { vector_.push_back(i); } } static bool VectorIsCorrupt(const TestingVector& vector) { - if (kVectorSize != static_cast<int>(vector.size())) { + if (kVectorSize != vector.size()) { return true; } bool found_in_vector[kVectorSize] = { false }; for (size_t i = 0; i < vector.size(); i++) { const int e = vector[i]; - if (e < 0 || e >= kVectorSize || found_in_vector[e]) { + if (e < 0 || e >= static_cast<int>(kVectorSize) || found_in_vector[e]) { return true; } found_in_vector[e] = true; @@ -932,7 +932,7 @@ class VectorShuffleTest : public Test { static bool RangeIsShuffled(const TestingVector& vector, int begin, int end) { for (int i = begin; i < end; i++) { - if (i != vector[i]) { + if (i != vector[static_cast<size_t>(i)]) { return true; } } @@ -956,7 +956,7 @@ class VectorShuffleTest : public Test { TestingVector vector_; }; // class VectorShuffleTest -const int VectorShuffleTest::kVectorSize; +const size_t VectorShuffleTest::kVectorSize; TEST_F(VectorShuffleTest, HandlesEmptyRange) { // Tests an empty range at the beginning... @@ -1008,7 +1008,7 @@ TEST_F(VectorShuffleTest, ShufflesEntireVector) { // Tests the first and last elements in particular to ensure that // there are no off-by-one problems in our shuffle algorithm. EXPECT_NE(0, vector_[0]); - EXPECT_NE(kVectorSize - 1, vector_[kVectorSize - 1]); + EXPECT_NE(static_cast<int>(kVectorSize - 1), vector_[kVectorSize - 1]); } TEST_F(VectorShuffleTest, ShufflesStartOfVector) { @@ -1018,7 +1018,8 @@ TEST_F(VectorShuffleTest, ShufflesStartOfVector) { 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)); } TEST_F(VectorShuffleTest, ShufflesEndOfVector) { @@ -1027,23 +1028,25 @@ 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)); } TEST_F(VectorShuffleTest, ShufflesMiddleOfVector) { - int kRangeSize = 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)); } TEST_F(VectorShuffleTest, ShufflesRepeatably) { TestingVector vector2; - for (int i = 0; i < kVectorSize; i++) { - vector2.push_back(i); + for (size_t i = 0; i < kVectorSize; i++) { + vector2.push_back(static_cast<int>(i)); } random_.Reseed(1234); @@ -1054,7 +1057,7 @@ TEST_F(VectorShuffleTest, ShufflesRepeatably) { ASSERT_PRED1(VectorIsNotCorrupt, vector_); ASSERT_PRED1(VectorIsNotCorrupt, vector2); - for (int i = 0; i < kVectorSize; i++) { + for (size_t i = 0; i < kVectorSize; i++) { EXPECT_EQ(vector_[i], vector2[i]) << " where i is " << i; } } @@ -3496,7 +3499,7 @@ std::string EditsToString(const std::vector<EditType>& edits) { std::vector<size_t> CharsToIndices(const std::string& str) { std::vector<size_t> out; for (size_t i = 0; i < str.size(); ++i) { - out.push_back(str[i]); + out.push_back(static_cast<size_t>(str[i])); } return out; } @@ -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) { 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; } } |