}
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));
}
// 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
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);
// 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.
// 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)]);
}
}
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_;
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;
}
// 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.
}
// 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)
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);
}
}
}
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(
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) {
// 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;
}
}