mirror of
https://github.com/google/googletest.git
synced 2026-07-30 16:26:24 +08:00
Compare commits
12 Commits
b56019e8fe
...
155f03ad77
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
155f03ad77 | ||
|
|
3ff51c3e80 | ||
|
|
c6f04243ed | ||
|
|
af4c3cfcb3 | ||
|
|
ecb18f0b03 | ||
|
|
b78aa5ee64 | ||
|
|
56cf341d9c | ||
|
|
1269db9643 | ||
|
|
18258591c9 | ||
|
|
b992f283ea | ||
|
|
52138d0373 | ||
|
|
157ee5a197 |
@ -3774,7 +3774,9 @@ class [[nodiscard]] ElementsAreMatcherImpl
|
||||
// prints the empty container. Otherwise we just need to show
|
||||
// how many elements there actually are.
|
||||
if (listener_interested && (actual_count != 0)) {
|
||||
*listener << "which has " << Elements(actual_count);
|
||||
*listener << "size mismatch:\n"
|
||||
<< " Expected size: " << count() << "\n"
|
||||
<< " Actual size: " << actual_count;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -3797,8 +3799,11 @@ class [[nodiscard]] ElementsAreMatcherImpl
|
||||
// corresponding matcher description. Therefore we print the index, the
|
||||
// value of the mismatched element, and the corresponding matcher
|
||||
// description to ease debugging.
|
||||
*listener << "whose element #" << exam_pos << " ("
|
||||
<< PrintToString(*unmatched_it) << ") ";
|
||||
*listener << "element mismatch at index " << exam_pos << ":\n";
|
||||
*listener << " Actual: " << PrintToString(*unmatched_it) << "\n";
|
||||
*listener << " Expected: ";
|
||||
matchers_[exam_pos].DescribeTo(listener->stream());
|
||||
*listener << "\n Detail: ";
|
||||
matchers_[exam_pos].DescribeNegationTo(listener->stream());
|
||||
PrintIfNotEmpty(explanations[exam_pos], listener->stream());
|
||||
}
|
||||
@ -3815,7 +3820,7 @@ class [[nodiscard]] ElementsAreMatcherImpl
|
||||
if (reason_printed) {
|
||||
*listener << ",\nand ";
|
||||
}
|
||||
*listener << "whose element #" << i << " matches, " << s;
|
||||
*listener << "element #" << i << " matches: " << s;
|
||||
reason_printed = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -243,6 +243,19 @@ static void LogElementMatcherPairVec(const ElementMatcherPairs& pairs,
|
||||
os << "\n}";
|
||||
}
|
||||
|
||||
static void LogActualExpectedPairVec(const ElementMatcherPairs& pairs,
|
||||
::std::ostream* stream) {
|
||||
// Keep pairings in Actual/Expected order for quick visual diffing.
|
||||
typedef ElementMatcherPairs::const_iterator Iter;
|
||||
::std::ostream& os = *stream;
|
||||
const char* sep = "";
|
||||
for (Iter it = pairs.begin(); it != pairs.end(); ++it) {
|
||||
os << sep << " - Actual #" << it->first << " <-> Expected #"
|
||||
<< it->second;
|
||||
sep = "\n";
|
||||
}
|
||||
}
|
||||
|
||||
bool MatchMatrix::NextGraph() {
|
||||
for (size_t ilhs = 0; ilhs < LhsSize(); ++ilhs) {
|
||||
for (size_t irhs = 0; irhs < RhsSize(); ++irhs) {
|
||||
@ -399,33 +412,43 @@ bool UnorderedElementsAreMatcherImplBase::VerifyMatchMatrix(
|
||||
}
|
||||
|
||||
if (match_flags() & UnorderedMatcherRequire::Superset) {
|
||||
const char* sep =
|
||||
"where the following matchers don't match any elements:\n";
|
||||
const char* sep = "";
|
||||
bool header_printed = false;
|
||||
for (size_t mi = 0; mi < matcher_matched.size(); ++mi) {
|
||||
if (matcher_matched[mi]) continue;
|
||||
result = false;
|
||||
if (listener->IsInterested()) {
|
||||
*listener << sep << "matcher #" << mi << ": ";
|
||||
if (!header_printed) {
|
||||
*listener << "UnorderedElementsAre mismatch:\n"
|
||||
<< "Expected entries with no matching actual value:\n";
|
||||
header_printed = true;
|
||||
}
|
||||
*listener << sep << " - Expected #" << mi << ": ";
|
||||
matcher_describers_[mi]->DescribeTo(listener->stream());
|
||||
sep = ",\n";
|
||||
sep = "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (match_flags() & UnorderedMatcherRequire::Subset) {
|
||||
const char* sep =
|
||||
"where the following elements don't match any matchers:\n";
|
||||
const char* sep = "";
|
||||
const char* outer_sep = "";
|
||||
if (!result) {
|
||||
outer_sep = "\nand ";
|
||||
outer_sep = "\n";
|
||||
}
|
||||
bool header_printed = false;
|
||||
for (size_t ei = 0; ei < element_matched.size(); ++ei) {
|
||||
if (element_matched[ei]) continue;
|
||||
result = false;
|
||||
if (listener->IsInterested()) {
|
||||
*listener << outer_sep << sep << "element #" << ei << ": "
|
||||
if (!header_printed) {
|
||||
*listener << outer_sep
|
||||
<< "Actual entries with no matching expected value:\n";
|
||||
header_printed = true;
|
||||
}
|
||||
*listener << sep << " - Actual #" << ei << ": "
|
||||
<< element_printouts[ei];
|
||||
sep = ",\n";
|
||||
sep = "\n";
|
||||
outer_sep = "";
|
||||
}
|
||||
}
|
||||
@ -441,22 +464,22 @@ bool UnorderedElementsAreMatcherImplBase::FindPairing(
|
||||
if ((match_flags() & UnorderedMatcherRequire::Superset) &&
|
||||
max_flow < matrix.RhsSize()) {
|
||||
if (listener->IsInterested()) {
|
||||
*listener << "where no permutation of the elements can satisfy all "
|
||||
"matchers, and the closest match is "
|
||||
<< max_flow << " of " << matrix.RhsSize()
|
||||
<< " matchers with the pairings:\n";
|
||||
LogElementMatcherPairVec(matches, listener->stream());
|
||||
*listener << "UnorderedElementsAre pairing mismatch:\n"
|
||||
<< " Matched " << max_flow << " of " << matrix.RhsSize()
|
||||
<< " expected entries.\n"
|
||||
<< "Pairings (Actual <-> Expected):\n";
|
||||
LogActualExpectedPairVec(matches, listener->stream());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if ((match_flags() & UnorderedMatcherRequire::Subset) &&
|
||||
max_flow < matrix.LhsSize()) {
|
||||
if (listener->IsInterested()) {
|
||||
*listener
|
||||
<< "where not all elements can be matched, and the closest match is "
|
||||
<< max_flow << " of " << matrix.RhsSize()
|
||||
<< " matchers with the pairings:\n";
|
||||
LogElementMatcherPairVec(matches, listener->stream());
|
||||
*listener << "UnorderedElementsAre pairing mismatch:\n"
|
||||
<< " Matched " << max_flow << " of " << matrix.LhsSize()
|
||||
<< " actual entries.\n"
|
||||
<< "Pairings (Actual <-> Expected):\n";
|
||||
LogActualExpectedPairVec(matches, listener->stream());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -465,8 +488,8 @@ bool UnorderedElementsAreMatcherImplBase::FindPairing(
|
||||
if (listener->IsInterested()) {
|
||||
const char* sep = "where:\n";
|
||||
for (size_t mi = 0; mi < matches.size(); ++mi) {
|
||||
*listener << sep << " - element #" << matches[mi].first
|
||||
<< " is matched by matcher #" << matches[mi].second;
|
||||
*listener << sep << " - Actual #" << matches[mi].first
|
||||
<< " is matched by Expected #" << matches[mi].second;
|
||||
sep = ",\n";
|
||||
}
|
||||
}
|
||||
|
||||
@ -1243,16 +1243,16 @@ TEST(InvokeWithoutArgsTest, Function) {
|
||||
TEST(InvokeWithoutArgsTest, Functor) {
|
||||
GTEST_DISABLE_DEPRECATED_PUSH_()
|
||||
// As an action that takes no argument.
|
||||
Action<int()> a = InvokeWithoutArgs(NullaryFunctor()); // NOLINT
|
||||
Action<int()> a = NullaryFunctor(); // NOLINT
|
||||
EXPECT_EQ(2, a.Perform(std::make_tuple()));
|
||||
|
||||
// As an action that takes three arguments.
|
||||
Action<int(int, double, char)> a2 = // NOLINT
|
||||
InvokeWithoutArgs(NullaryFunctor());
|
||||
NullaryFunctor();
|
||||
EXPECT_EQ(2, a2.Perform(std::make_tuple(3, 3.5, 'a')));
|
||||
|
||||
// As an action that returns void.
|
||||
Action<void()> a3 = InvokeWithoutArgs(VoidNullaryFunctor());
|
||||
Action<void()> a3 = VoidNullaryFunctor();
|
||||
g_done = false;
|
||||
a3.Perform(std::make_tuple());
|
||||
EXPECT_TRUE(g_done);
|
||||
|
||||
@ -1274,7 +1274,10 @@ TEST(WhenSortedByTest, ExplainsMatchResult) {
|
||||
const int a[] = {2, 1};
|
||||
EXPECT_EQ(
|
||||
Explain(WhenSortedBy(less<int>(), ElementsAre(2, 3)), a),
|
||||
"which is { 1, 2 } when sorted, whose element #0 (1) isn't equal to 2");
|
||||
"which is { 1, 2 } when sorted, element mismatch at index 0:\n"
|
||||
" Actual: 1\n"
|
||||
" Expected: is equal to 2\n"
|
||||
" Detail: isn't equal to 2");
|
||||
EXPECT_EQ(Explain(WhenSortedBy(less<int>(), ElementsAre(1, 2)), a),
|
||||
"which is { 1, 2 } when sorted");
|
||||
}
|
||||
@ -1623,16 +1626,17 @@ TEST(IsSupersetOfTest, MatchAndExplain) {
|
||||
ASSERT_FALSE(ExplainMatchResult(IsSupersetOf(expected), v, &listener))
|
||||
<< listener.str();
|
||||
EXPECT_THAT(listener.str(),
|
||||
Eq("where the following matchers don't match any elements:\n"
|
||||
"matcher #0: is equal to 1"));
|
||||
Eq("UnorderedElementsAre mismatch:\n"
|
||||
"Expected entries with no matching actual value:\n"
|
||||
" - Expected #0: is equal to 1"));
|
||||
|
||||
v.push_back(1);
|
||||
listener.Clear();
|
||||
ASSERT_TRUE(ExplainMatchResult(IsSupersetOf(expected), v, &listener))
|
||||
<< listener.str();
|
||||
EXPECT_THAT(listener.str(), Eq("where:\n"
|
||||
" - element #0 is matched by matcher #1,\n"
|
||||
" - element #2 is matched by matcher #0"));
|
||||
" - Actual #0 is matched by Expected #1,\n"
|
||||
" - Actual #2 is matched by Expected #0"));
|
||||
}
|
||||
|
||||
TEST(IsSupersetOfTest, WorksForRhsInitializerList) {
|
||||
@ -1751,16 +1755,16 @@ TEST(IsSubsetOfTest, MatchAndExplain) {
|
||||
ASSERT_FALSE(ExplainMatchResult(IsSubsetOf(expected), v, &listener))
|
||||
<< listener.str();
|
||||
EXPECT_THAT(listener.str(),
|
||||
Eq("where the following elements don't match any matchers:\n"
|
||||
"element #1: 3"));
|
||||
Eq("Actual entries with no matching expected value:\n"
|
||||
" - Actual #1: 3"));
|
||||
|
||||
expected.push_back(3);
|
||||
listener.Clear();
|
||||
ASSERT_TRUE(ExplainMatchResult(IsSubsetOf(expected), v, &listener))
|
||||
<< listener.str();
|
||||
EXPECT_THAT(listener.str(), Eq("where:\n"
|
||||
" - element #0 is matched by matcher #1,\n"
|
||||
" - element #1 is matched by matcher #2"));
|
||||
" - Actual #0 is matched by Expected #1,\n"
|
||||
" - Actual #1 is matched by Expected #2"));
|
||||
}
|
||||
|
||||
TEST(IsSubsetOfTest, WorksForRhsInitializerList) {
|
||||
@ -2314,12 +2318,13 @@ TEST_F(UnorderedElementsAreTest, FailMessageCountWrong) {
|
||||
<< listener.str();
|
||||
EXPECT_THAT(listener.str(),
|
||||
Eq("which has 1 element\n"
|
||||
"where the following matchers don't match any elements:\n"
|
||||
"matcher #0: is equal to 1,\n"
|
||||
"matcher #1: is equal to 2,\n"
|
||||
"matcher #2: is equal to 3\n"
|
||||
"and where the following elements don't match any matchers:\n"
|
||||
"element #0: 4"));
|
||||
"UnorderedElementsAre mismatch:\n"
|
||||
"Expected entries with no matching actual value:\n"
|
||||
" - Expected #0: is equal to 1\n"
|
||||
" - Expected #1: is equal to 2\n"
|
||||
" - Expected #2: is equal to 3\n"
|
||||
"Actual entries with no matching expected value:\n"
|
||||
" - Actual #0: 4"));
|
||||
}
|
||||
|
||||
TEST_F(UnorderedElementsAreTest, FailMessageCountWrongZero) {
|
||||
@ -2328,10 +2333,11 @@ TEST_F(UnorderedElementsAreTest, FailMessageCountWrongZero) {
|
||||
EXPECT_FALSE(ExplainMatchResult(UnorderedElementsAre(1, 2, 3), v, &listener))
|
||||
<< listener.str();
|
||||
EXPECT_THAT(listener.str(),
|
||||
Eq("where the following matchers don't match any elements:\n"
|
||||
"matcher #0: is equal to 1,\n"
|
||||
"matcher #1: is equal to 2,\n"
|
||||
"matcher #2: is equal to 3"));
|
||||
Eq("UnorderedElementsAre mismatch:\n"
|
||||
"Expected entries with no matching actual value:\n"
|
||||
" - Expected #0: is equal to 1\n"
|
||||
" - Expected #1: is equal to 2\n"
|
||||
" - Expected #2: is equal to 3"));
|
||||
}
|
||||
|
||||
TEST_F(UnorderedElementsAreTest, FailMessageUnmatchedMatchers) {
|
||||
@ -2342,8 +2348,9 @@ TEST_F(UnorderedElementsAreTest, FailMessageUnmatchedMatchers) {
|
||||
EXPECT_FALSE(ExplainMatchResult(UnorderedElementsAre(1, 2), v, &listener))
|
||||
<< listener.str();
|
||||
EXPECT_THAT(listener.str(),
|
||||
Eq("where the following matchers don't match any elements:\n"
|
||||
"matcher #1: is equal to 2"));
|
||||
Eq("UnorderedElementsAre mismatch:\n"
|
||||
"Expected entries with no matching actual value:\n"
|
||||
" - Expected #1: is equal to 2"));
|
||||
}
|
||||
|
||||
TEST_F(UnorderedElementsAreTest, FailMessageUnmatchedElements) {
|
||||
@ -2353,9 +2360,9 @@ TEST_F(UnorderedElementsAreTest, FailMessageUnmatchedElements) {
|
||||
StringMatchResultListener listener;
|
||||
EXPECT_FALSE(ExplainMatchResult(UnorderedElementsAre(1, 1), v, &listener))
|
||||
<< listener.str();
|
||||
EXPECT_THAT(listener.str(),
|
||||
Eq("where the following elements don't match any matchers:\n"
|
||||
"element #1: 2"));
|
||||
EXPECT_THAT(listener.str(), Eq("Actual entries with no matching expected "
|
||||
"value:\n"
|
||||
" - Actual #1: 2"));
|
||||
}
|
||||
|
||||
TEST_F(UnorderedElementsAreTest, FailMessageUnmatchedMatcherAndElement) {
|
||||
@ -2366,20 +2373,11 @@ TEST_F(UnorderedElementsAreTest, FailMessageUnmatchedMatcherAndElement) {
|
||||
EXPECT_FALSE(ExplainMatchResult(UnorderedElementsAre(1, 2), v, &listener))
|
||||
<< listener.str();
|
||||
EXPECT_THAT(listener.str(),
|
||||
Eq("where"
|
||||
" the following matchers don't match any elements:\n"
|
||||
"matcher #0: is equal to 1\n"
|
||||
"and"
|
||||
" where"
|
||||
" the following elements don't match any matchers:\n"
|
||||
"element #1: 3"));
|
||||
}
|
||||
|
||||
// Test helper for formatting element, matcher index pairs in expectations.
|
||||
static std::string EMString(int element, int matcher) {
|
||||
stringstream ss;
|
||||
ss << "(element #" << element << ", matcher #" << matcher << ")";
|
||||
return ss.str();
|
||||
Eq("UnorderedElementsAre mismatch:\n"
|
||||
"Expected entries with no matching actual value:\n"
|
||||
" - Expected #0: is equal to 1\n"
|
||||
"Actual entries with no matching expected value:\n"
|
||||
" - Actual #1: 3"));
|
||||
}
|
||||
|
||||
TEST_F(UnorderedElementsAreTest, FailMessageImperfectMatchOnly) {
|
||||
@ -2394,20 +2392,22 @@ TEST_F(UnorderedElementsAreTest, FailMessageImperfectMatchOnly) {
|
||||
UnorderedElementsAre("a", "a", AnyOf("b", "c")), v, &listener))
|
||||
<< listener.str();
|
||||
|
||||
std::string prefix =
|
||||
"where no permutation of the elements can satisfy all matchers, "
|
||||
"and the closest match is 2 of 3 matchers with the "
|
||||
"pairings:\n";
|
||||
std::string prefix = "UnorderedElementsAre pairing mismatch:\n"
|
||||
" Matched 2 of 3 expected entries.\n"
|
||||
"Pairings (Actual <-> Expected):\n";
|
||||
|
||||
// We have to be a bit loose here, because there are 4 valid max matches.
|
||||
EXPECT_THAT(
|
||||
listener.str(),
|
||||
AnyOf(
|
||||
prefix + "{\n " + EMString(0, 0) + ",\n " + EMString(1, 2) + "\n}",
|
||||
prefix + "{\n " + EMString(0, 1) + ",\n " + EMString(1, 2) + "\n}",
|
||||
prefix + "{\n " + EMString(0, 0) + ",\n " + EMString(2, 2) + "\n}",
|
||||
prefix + "{\n " + EMString(0, 1) + ",\n " + EMString(2, 2) +
|
||||
"\n}"));
|
||||
prefix + " - Actual #0 <-> Expected #0\n"
|
||||
" - Actual #1 <-> Expected #2",
|
||||
prefix + " - Actual #0 <-> Expected #1\n"
|
||||
" - Actual #1 <-> Expected #2",
|
||||
prefix + " - Actual #0 <-> Expected #0\n"
|
||||
" - Actual #2 <-> Expected #2",
|
||||
prefix + " - Actual #0 <-> Expected #1\n"
|
||||
" - Actual #2 <-> Expected #2"));
|
||||
}
|
||||
|
||||
TEST_F(UnorderedElementsAreTest, Describe) {
|
||||
@ -2759,8 +2759,8 @@ TEST(UnorderedPointwiseTest, RejectsWrongContent) {
|
||||
const int rhs[3] = {2, 6, 6};
|
||||
EXPECT_THAT(lhs, Not(UnorderedPointwise(IsHalfOf(), rhs)));
|
||||
EXPECT_EQ(
|
||||
"where the following elements don't match any matchers:\n"
|
||||
"element #1: 2",
|
||||
"Actual entries with no matching expected value:\n"
|
||||
" - Actual #1: 2",
|
||||
Explain(UnorderedPointwise(IsHalfOf(), rhs), lhs));
|
||||
}
|
||||
|
||||
@ -2938,8 +2938,8 @@ TEST_P(ElementsAreTestP, ExplainsNonTrivialMatch) {
|
||||
const int a[] = {10, 0, 100};
|
||||
vector<int> test_vector(std::begin(a), std::end(a));
|
||||
EXPECT_EQ(
|
||||
"whose element #0 matches, which is 9 more than 1,\n"
|
||||
"and whose element #2 matches, which is 98 more than 2",
|
||||
"element #0 matches: which is 9 more than 1,\n"
|
||||
"and element #2 matches: which is 98 more than 2",
|
||||
Explain(m, test_vector));
|
||||
}
|
||||
|
||||
@ -2951,7 +2951,8 @@ TEST(ElementsAreTest, CanExplainMismatchWrongSize) {
|
||||
EXPECT_EQ("", Explain(m, test_list));
|
||||
|
||||
test_list.push_back(1);
|
||||
EXPECT_EQ("which has 1 element", Explain(m, test_list));
|
||||
EXPECT_EQ("size mismatch:\n Expected size: 2\n Actual size: 1",
|
||||
Explain(m, test_list));
|
||||
}
|
||||
|
||||
TEST_P(ElementsAreTestP, CanExplainMismatchRightSize) {
|
||||
@ -2960,11 +2961,18 @@ TEST_P(ElementsAreTestP, CanExplainMismatchRightSize) {
|
||||
vector<int> v;
|
||||
v.push_back(2);
|
||||
v.push_back(1);
|
||||
EXPECT_EQ(Explain(m, v), "whose element #0 (2) isn't equal to 1");
|
||||
EXPECT_EQ(Explain(m, v),
|
||||
"element mismatch at index 0:\n"
|
||||
" Actual: 2\n"
|
||||
" Expected: is equal to 1\n"
|
||||
" Detail: isn't equal to 1");
|
||||
|
||||
v[0] = 1;
|
||||
EXPECT_EQ(Explain(m, v),
|
||||
"whose element #1 (1) is <= 5, which is 4 less than 5");
|
||||
"element mismatch at index 1:\n"
|
||||
" Actual: 1\n"
|
||||
" Expected: is > 5\n"
|
||||
" Detail: is <= 5, which is 4 less than 5");
|
||||
}
|
||||
|
||||
TEST(ElementsAreTest, MatchesOneElementVector) {
|
||||
|
||||
@ -340,7 +340,7 @@ TEST(LinkTest, TestInvokeWithoutArgs) {
|
||||
|
||||
GTEST_DISABLE_DEPRECATED_PUSH_()
|
||||
EXPECT_CALL(mock, VoidFromString(_))
|
||||
.WillOnce(InvokeWithoutArgs(&InvokeHelper::StaticVoidFromVoid))
|
||||
.WillOnce(&InvokeHelper::StaticVoidFromVoid)
|
||||
.WillOnce(
|
||||
InvokeWithoutArgs(&test_invoke_helper, &InvokeHelper::VoidFromVoid));
|
||||
GTEST_DISABLE_DEPRECATED_POP_()
|
||||
|
||||
@ -30,6 +30,8 @@
|
||||
// Tests that Google Mock constructs can be used in a large number of
|
||||
// threads concurrently.
|
||||
|
||||
#include <iterator>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
@ -188,7 +190,7 @@ TEST(StressTest, CanUseGMockWithThreads) {
|
||||
&TestPartiallyOrderedExpectationsWithThreads,
|
||||
};
|
||||
|
||||
const int kRoutines = sizeof(test_routines) / sizeof(test_routines[0]);
|
||||
const int kRoutines = std::size(test_routines);
|
||||
const int kCopiesOfEachRoutine = kMaxTestThreads / kRoutines;
|
||||
const int kTestThreads = kCopiesOfEachRoutine * kRoutines;
|
||||
ThreadWithParam<Dummy>* threads[kTestThreads] = {};
|
||||
|
||||
@ -39,6 +39,8 @@
|
||||
|
||||
#include "sample2.h"
|
||||
|
||||
#include <iterator>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
namespace {
|
||||
// In this example, we test the MyString class (a simple string).
|
||||
@ -78,7 +80,7 @@ const char kHelloString[] = "Hello, world!";
|
||||
TEST(MyString, ConstructorFromCString) {
|
||||
const MyString s(kHelloString);
|
||||
EXPECT_EQ(0, strcmp(s.c_string(), kHelloString));
|
||||
EXPECT_EQ(sizeof(kHelloString) / sizeof(kHelloString[0]) - 1, s.Length());
|
||||
EXPECT_EQ(std::size(kHelloString) - 1, s.Length());
|
||||
}
|
||||
|
||||
// Tests the copy c'tor.
|
||||
|
||||
@ -587,7 +587,7 @@ class GTEST_API_ UnitTestImpl {
|
||||
// total_test_suite_count() - 1. If i is not in that range, returns NULL.
|
||||
const TestSuite* GetTestSuite(int i) const {
|
||||
const int index = GetElementOr(test_suite_indices_, i, -1);
|
||||
return index < 0 ? nullptr : test_suites_[static_cast<size_t>(i)];
|
||||
return index < 0 ? nullptr : test_suites_[static_cast<size_t>(index)];
|
||||
}
|
||||
|
||||
// Legacy API is deprecated but still available
|
||||
@ -1106,7 +1106,7 @@ class StreamingListener : public EmptyTestEventListener {
|
||||
GTEST_CHECK_(sockfd_ != -1)
|
||||
<< "Send() can be called only when there is a connection.";
|
||||
|
||||
const auto len = static_cast<size_t>(message.length());
|
||||
const size_t len = 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_;
|
||||
|
||||
@ -1209,7 +1209,7 @@ int UnitTestImpl::test_to_run_count() const {
|
||||
// trace but Bar() and CurrentOsStackTraceExceptTop() won't.
|
||||
std::string UnitTestImpl::CurrentOsStackTraceExceptTop(int skip_count) {
|
||||
return os_stack_trace_getter()->CurrentStackTrace(
|
||||
static_cast<int>(GTEST_FLAG_GET(stack_trace_depth)), skip_count + 1
|
||||
GTEST_FLAG_GET(stack_trace_depth), skip_count + 1
|
||||
// Skips the user-specified number of frames plus this function
|
||||
// itself.
|
||||
); // NOLINT
|
||||
@ -4239,8 +4239,7 @@ void XmlUnitTestResultPrinter::OutputXmlCDataSection(::std::ostream* stream,
|
||||
for (;;) {
|
||||
const char* const next_segment = strstr(segment, "]]>");
|
||||
if (next_segment != nullptr) {
|
||||
stream->write(segment,
|
||||
static_cast<std::streamsize>(next_segment - segment));
|
||||
stream->write(segment, next_segment - segment);
|
||||
*stream << "]]>]]><![CDATA[";
|
||||
segment = next_segment + strlen("]]>");
|
||||
} else {
|
||||
|
||||
@ -32,6 +32,7 @@
|
||||
// This file verifies Google Test event listeners receive events at the
|
||||
// right times.
|
||||
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -498,8 +499,7 @@ int main(int argc, char** argv) {
|
||||
"1st.OnTestProgramEnd"};
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
VerifyResults(events, expected_events,
|
||||
sizeof(expected_events) / sizeof(expected_events[0]));
|
||||
VerifyResults(events, expected_events, std::size(expected_events));
|
||||
|
||||
// We need to check manually for ad hoc test failures that happen after
|
||||
// RUN_ALL_TESTS finishes.
|
||||
|
||||
@ -36,6 +36,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
|
||||
#include "gtest/gtest-spi.h"
|
||||
@ -149,7 +150,7 @@ TEST(LoggingTest, InterleavingLoggingAndAssertions) {
|
||||
static const int a[4] = {3, 9, 2, 6};
|
||||
|
||||
printf("(expecting 2 failures on (3) >= (a[i]))\n");
|
||||
for (int i = 0; i < static_cast<int>(sizeof(a) / sizeof(*a)); i++) {
|
||||
for (int i = 0; i < static_cast<int>(std::size(a)); i++) {
|
||||
printf("i == %d\n", i);
|
||||
EXPECT_GE(3, a[i]);
|
||||
}
|
||||
|
||||
@ -39,6 +39,7 @@
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
@ -737,10 +738,7 @@ const int test_generation_params[] = {36, 42, 72};
|
||||
|
||||
class TestGenerationTest : public TestWithParam<int> {
|
||||
public:
|
||||
enum {
|
||||
PARAMETER_COUNT =
|
||||
sizeof(test_generation_params) / sizeof(test_generation_params[0])
|
||||
};
|
||||
enum { PARAMETER_COUNT = std::size(test_generation_params) };
|
||||
|
||||
typedef TestGenerationEnvironment<PARAMETER_COUNT> Environment;
|
||||
|
||||
|
||||
@ -39,6 +39,7 @@
|
||||
#include <deque>
|
||||
#include <forward_list>
|
||||
#include <functional>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <list>
|
||||
#include <map>
|
||||
@ -1784,7 +1785,7 @@ TEST(IsValidUTF8Test, IllFormedUTF8) {
|
||||
// too.
|
||||
{"\xEE\x80\x80", "\"\\xEE\\x80\\x80\"\n As Text: \"\""}};
|
||||
|
||||
for (int i = 0; i < int(sizeof(kTestdata) / sizeof(kTestdata[0])); ++i) {
|
||||
for (int i = 0; i < int(std::size(kTestdata)); ++i) {
|
||||
EXPECT_PRINT_TO_STRING_(kTestdata[i][0], kTestdata[i][1]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,6 +33,8 @@
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <iterator>
|
||||
|
||||
// Verifies that the command line flag variables can be accessed in
|
||||
// code once "gtest.h" has been #included.
|
||||
// Do not move it after other gtest #includes.
|
||||
@ -5853,9 +5855,8 @@ class ParseFlagsTest : public Test {
|
||||
// to specify the array sizes.
|
||||
|
||||
#define GTEST_TEST_PARSING_FLAGS_(argv1, argv2, expected, should_print_help) \
|
||||
TestParsingFlags(sizeof(argv1) / sizeof(*argv1) - 1, argv1, \
|
||||
sizeof(argv2) / sizeof(*argv2) - 1, argv2, expected, \
|
||||
should_print_help)
|
||||
TestParsingFlags(std::size(argv1) - 1, argv1, std::size(argv2) - 1, argv2, \
|
||||
expected, should_print_help)
|
||||
};
|
||||
|
||||
// Tests parsing an empty command line.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user