Commit 96f7ba83 authored by Gennadiy Civil's avatar Gennadiy Civil Committed by GitHub
Browse files

Merge branch 'master' into wrong-version-reported

parents b74070cf 675686a1
......@@ -57,7 +57,6 @@
namespace testing {
namespace gmock_generated_function_mockers_test {
using testing::internal::string;
using testing::_;
using testing::A;
using testing::An;
......@@ -82,11 +81,11 @@ class FooInterface {
virtual bool Unary(int x) = 0;
virtual long Binary(short x, int y) = 0; // NOLINT
virtual int Decimal(bool b, char c, short d, int e, long f, // NOLINT
float g, double h, unsigned i, char* j, const string& k)
= 0;
float g, double h, unsigned i, char* j,
const std::string& k) = 0;
virtual bool TakesNonConstReference(int& n) = 0; // NOLINT
virtual string TakesConstReference(const int& n) = 0;
virtual std::string TakesConstReference(const int& n) = 0;
#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
virtual bool TakesConst(const int x) = 0;
#endif // GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
......@@ -101,13 +100,14 @@ class FooInterface {
virtual char OverloadedOnConstness() const = 0;
virtual int TypeWithHole(int (*func)()) = 0;
virtual int TypeWithComma(const std::map<int, string>& a_map) = 0;
virtual int TypeWithComma(const std::map<int, std::string>& a_map) = 0;
#if GTEST_OS_WINDOWS
STDMETHOD_(int, CTNullary)() = 0;
STDMETHOD_(bool, CTUnary)(int x) = 0;
STDMETHOD_(int, CTDecimal)(bool b, char c, short d, int e, long f, // NOLINT
float g, double h, unsigned i, char* j, const string& k) = 0;
STDMETHOD_(int, CTDecimal)
(bool b, char c, short d, int e, long f, // NOLINT
float g, double h, unsigned i, char* j, const std::string& k) = 0;
STDMETHOD_(char, CTConst)(int x) const = 0;
#endif // GTEST_OS_WINDOWS
};
......@@ -133,19 +133,19 @@ class MockFoo : public FooInterface {
MOCK_METHOD1(Unary, bool(int)); // NOLINT
MOCK_METHOD2(Binary, long(short, int)); // NOLINT
MOCK_METHOD10(Decimal, int(bool, char, short, int, long, float, // NOLINT
double, unsigned, char*, const string& str));
double, unsigned, char*, const std::string& str));
MOCK_METHOD1(TakesNonConstReference, bool(int&)); // NOLINT
MOCK_METHOD1(TakesConstReference, string(const int&));
MOCK_METHOD1(TakesConstReference, std::string(const int&));
#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
MOCK_METHOD1(TakesConst, bool(const int)); // NOLINT
#endif
// Tests that the function return type can contain unprotected comma.
MOCK_METHOD0(ReturnTypeWithComma, std::map<int, string>());
MOCK_METHOD0(ReturnTypeWithComma, std::map<int, std::string>());
MOCK_CONST_METHOD1(ReturnTypeWithComma,
std::map<int, string>(int)); // NOLINT
std::map<int, std::string>(int)); // NOLINT
MOCK_METHOD0(OverloadedOnArgumentNumber, int()); // NOLINT
MOCK_METHOD1(OverloadedOnArgumentNumber, int(int)); // NOLINT
......@@ -157,19 +157,21 @@ class MockFoo : public FooInterface {
MOCK_CONST_METHOD0(OverloadedOnConstness, char()); // NOLINT
MOCK_METHOD1(TypeWithHole, int(int (*)())); // NOLINT
MOCK_METHOD1(TypeWithComma, int(const std::map<int, string>&)); // NOLINT
MOCK_METHOD1(TypeWithComma,
int(const std::map<int, std::string>&)); // NOLINT
#if GTEST_OS_WINDOWS
MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, CTNullary, int());
MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, CTUnary, bool(int));
MOCK_METHOD10_WITH_CALLTYPE(STDMETHODCALLTYPE, CTDecimal, int(bool b, char c,
short d, int e, long f, float g, double h, unsigned i, char* j,
const string& k));
MOCK_METHOD10_WITH_CALLTYPE(STDMETHODCALLTYPE, CTDecimal,
int(bool b, char c, short d, int e, long f,
float g, double h, unsigned i, char* j,
const std::string& k));
MOCK_CONST_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, CTConst, char(int));
// Tests that the function return type can contain unprotected comma.
MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, CTReturnTypeWithComma,
std::map<int, string>());
std::map<int, std::string>());
#endif // GTEST_OS_WINDOWS
private:
......@@ -291,7 +293,7 @@ TEST_F(FunctionMockerTest, MocksFunctionsOverloadedOnConstnessOfThis) {
}
TEST_F(FunctionMockerTest, MocksReturnTypeWithComma) {
const std::map<int, string> a_map;
const std::map<int, std::string> a_map;
EXPECT_CALL(mock_foo_, ReturnTypeWithComma())
.WillOnce(Return(a_map));
EXPECT_CALL(mock_foo_, ReturnTypeWithComma(42))
......@@ -341,7 +343,7 @@ TEST_F(FunctionMockerTest, MocksFunctionsConstFunctionWithCallType) {
}
TEST_F(FunctionMockerTest, MocksReturnTypeWithCommaAndCallType) {
const std::map<int, string> a_map;
const std::map<int, std::string> a_map;
EXPECT_CALL(mock_foo_, CTReturnTypeWithComma())
.WillOnce(Return(a_map));
......
......@@ -79,11 +79,10 @@ using testing::StaticAssertTypeEq;
using testing::StrEq;
using testing::Value;
using testing::internal::ElementsAreArrayMatcher;
using testing::internal::string;
// Returns the description of the given matcher.
template <typename T>
string Describe(const Matcher<T>& m) {
std::string Describe(const Matcher<T>& m) {
stringstream ss;
m.DescribeTo(&ss);
return ss.str();
......@@ -91,7 +90,7 @@ string Describe(const Matcher<T>& m) {
// Returns the description of the negation of the given matcher.
template <typename T>
string DescribeNegation(const Matcher<T>& m) {
std::string DescribeNegation(const Matcher<T>& m) {
stringstream ss;
m.DescribeNegationTo(&ss);
return ss.str();
......@@ -99,7 +98,7 @@ string DescribeNegation(const Matcher<T>& m) {
// Returns the reason why x matches, or doesn't match, m.
template <typename MatcherType, typename Value>
string Explain(const MatcherType& m, const Value& x) {
std::string Explain(const MatcherType& m, const Value& x) {
stringstream ss;
m.ExplainMatchResultTo(x, &ss);
return ss.str();
......@@ -296,7 +295,7 @@ TEST(ElementsAreTest, CanDescribeExpectingOneElement) {
}
TEST(ElementsAreTest, CanDescribeExpectingManyElements) {
Matcher<list<string> > m = ElementsAre(StrEq("one"), "two");
Matcher<list<std::string> > m = ElementsAre(StrEq("one"), "two");
EXPECT_EQ("has 2 elements where\n"
"element #0 is equal to \"one\",\n"
"element #1 is equal to \"two\"", Describe(m));
......@@ -314,7 +313,7 @@ TEST(ElementsAreTest, CanDescribeNegationOfExpectingOneElment) {
}
TEST(ElementsAreTest, CanDescribeNegationOfExpectingManyElements) {
Matcher<const list<string>& > m = ElementsAre("one", "two");
Matcher<const list<std::string>&> m = ElementsAre("one", "two");
EXPECT_EQ("doesn't have 2 elements, or\n"
"element #0 isn't equal to \"one\", or\n"
"element #1 isn't equal to \"two\"", DescribeNegation(m));
......@@ -365,21 +364,21 @@ TEST(ElementsAreTest, CanExplainMismatchRightSize) {
}
TEST(ElementsAreTest, MatchesOneElementVector) {
vector<string> test_vector;
vector<std::string> test_vector;
test_vector.push_back("test string");
EXPECT_THAT(test_vector, ElementsAre(StrEq("test string")));
}
TEST(ElementsAreTest, MatchesOneElementList) {
list<string> test_list;
list<std::string> test_list;
test_list.push_back("test string");
EXPECT_THAT(test_list, ElementsAre("test string"));
}
TEST(ElementsAreTest, MatchesThreeElementVector) {
vector<string> test_vector;
vector<std::string> test_vector;
test_vector.push_back("one");
test_vector.push_back("two");
test_vector.push_back("three");
......@@ -428,30 +427,30 @@ TEST(ElementsAreTest, MatchesTenElementVector) {
}
TEST(ElementsAreTest, DoesNotMatchWrongSize) {
vector<string> test_vector;
vector<std::string> test_vector;
test_vector.push_back("test string");
test_vector.push_back("test string");
Matcher<vector<string> > m = ElementsAre(StrEq("test string"));
Matcher<vector<std::string> > m = ElementsAre(StrEq("test string"));
EXPECT_FALSE(m.Matches(test_vector));
}
TEST(ElementsAreTest, DoesNotMatchWrongValue) {
vector<string> test_vector;
vector<std::string> test_vector;
test_vector.push_back("other string");
Matcher<vector<string> > m = ElementsAre(StrEq("test string"));
Matcher<vector<std::string> > m = ElementsAre(StrEq("test string"));
EXPECT_FALSE(m.Matches(test_vector));
}
TEST(ElementsAreTest, DoesNotMatchWrongOrder) {
vector<string> test_vector;
vector<std::string> test_vector;
test_vector.push_back("one");
test_vector.push_back("three");
test_vector.push_back("two");
Matcher<vector<string> > m = ElementsAre(
StrEq("one"), StrEq("two"), StrEq("three"));
Matcher<vector<std::string> > m =
ElementsAre(StrEq("one"), StrEq("two"), StrEq("three"));
EXPECT_FALSE(m.Matches(test_vector));
}
......@@ -527,7 +526,7 @@ TEST(ElementsAreTest, WorksWithTwoDimensionalNativeArray) {
}
TEST(ElementsAreTest, AcceptsStringLiteral) {
string array[] = { "hi", "one", "two" };
std::string array[] = {"hi", "one", "two"};
EXPECT_THAT(array, ElementsAre("hi", "one", "two"));
EXPECT_THAT(array, Not(ElementsAre("hi", "one", "too")));
}
......@@ -546,10 +545,10 @@ TEST(ElementsAreTest, AcceptsArrayWithUnknownSize) {
// The size of kHi is not known in this test, but ElementsAre() should
// still accept it.
string array1[] = { "hi" };
std::string array1[] = {"hi"};
EXPECT_THAT(array1, ElementsAre(kHi));
string array2[] = { "ho" };
std::string array2[] = {"ho"};
EXPECT_THAT(array2, Not(ElementsAre(kHi)));
}
......@@ -589,7 +588,7 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithValueArray) {
TEST(ElementsAreArrayTest, CanBeCreatedWithArraySize) {
const char* a[] = { "one", "two", "three" };
vector<string> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
vector<std::string> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
EXPECT_THAT(test_vector, ElementsAreArray(a, GTEST_ARRAY_SIZE_(a)));
const char** p = a;
......@@ -600,7 +599,7 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithArraySize) {
TEST(ElementsAreArrayTest, CanBeCreatedWithoutArraySize) {
const char* a[] = { "one", "two", "three" };
vector<string> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
vector<std::string> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
EXPECT_THAT(test_vector, ElementsAreArray(a));
test_vector[0] = "1";
......@@ -608,10 +607,10 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithoutArraySize) {
}
TEST(ElementsAreArrayTest, CanBeCreatedWithMatcherArray) {
const Matcher<string> kMatcherArray[] =
{ StrEq("one"), StrEq("two"), StrEq("three") };
const Matcher<std::string> kMatcherArray[] = {StrEq("one"), StrEq("two"),
StrEq("three")};
vector<string> test_vector;
vector<std::string> test_vector;
test_vector.push_back("one");
test_vector.push_back("two");
test_vector.push_back("three");
......@@ -640,7 +639,7 @@ TEST(ElementsAreArrayTest, TakesInitializerList) {
}
TEST(ElementsAreArrayTest, TakesInitializerListOfCStrings) {
const string a[5] = { "a", "b", "c", "d", "e" };
const std::string a[5] = {"a", "b", "c", "d", "e"};
EXPECT_THAT(a, ElementsAreArray({ "a", "b", "c", "d", "e" }));
EXPECT_THAT(a, Not(ElementsAreArray({ "a", "b", "c", "e", "d" })));
EXPECT_THAT(a, Not(ElementsAreArray({ "a", "b", "c", "d", "ef" })));
......@@ -751,9 +750,9 @@ MATCHER(IsEven2, negation ? "is odd" : "is even") {
// This also tests that the description string can reference matcher
// parameters.
MATCHER_P2(EqSumOf, x, y,
string(negation ? "doesn't equal" : "equals") + " the sum of " +
PrintToString(x) + " and " + PrintToString(y)) {
MATCHER_P2(EqSumOf, x, y, std::string(negation ? "doesn't equal" : "equals") +
" the sum of " + PrintToString(x) + " and " +
PrintToString(y)) {
if (arg == (x + y)) {
*result_listener << "OK";
return true;
......@@ -1117,12 +1116,12 @@ TEST(ContainsTest, ListMatchesWhenElementIsInContainer) {
EXPECT_THAT(some_list, Contains(Gt(2.5)));
EXPECT_THAT(some_list, Contains(Eq(2.0f)));
list<string> another_list;
list<std::string> another_list;
another_list.push_back("fee");
another_list.push_back("fie");
another_list.push_back("foe");
another_list.push_back("fum");
EXPECT_THAT(another_list, Contains(string("fee")));
EXPECT_THAT(another_list, Contains(std::string("fee")));
}
TEST(ContainsTest, ListDoesNotMatchWhenElementIsNotInContainer) {
......@@ -1146,7 +1145,7 @@ TEST(ContainsTest, SetMatchesWhenElementIsInContainer) {
another_set.insert("fie");
another_set.insert("foe");
another_set.insert("fum");
EXPECT_THAT(another_set, Contains(Eq(string("fum"))));
EXPECT_THAT(another_set, Contains(Eq(std::string("fum"))));
}
TEST(ContainsTest, SetDoesNotMatchWhenElementIsNotInContainer) {
......@@ -1157,7 +1156,7 @@ TEST(ContainsTest, SetDoesNotMatchWhenElementIsNotInContainer) {
set<const char*> c_string_set;
c_string_set.insert("hello");
EXPECT_THAT(c_string_set, Not(Contains(string("hello").c_str())));
EXPECT_THAT(c_string_set, Not(Contains(std::string("hello").c_str())));
}
TEST(ContainsTest, ExplainsMatchResultCorrectly) {
......@@ -1189,13 +1188,14 @@ TEST(ContainsTest, MapMatchesWhenElementIsInContainer) {
my_map[bar] = 2;
EXPECT_THAT(my_map, Contains(pair<const char* const, int>(bar, 2)));
map<string, int> another_map;
map<std::string, int> another_map;
another_map["fee"] = 1;
another_map["fie"] = 2;
another_map["foe"] = 3;
another_map["fum"] = 4;
EXPECT_THAT(another_map, Contains(pair<const string, int>(string("fee"), 1)));
EXPECT_THAT(another_map, Contains(pair<const string, int>("fie", 2)));
EXPECT_THAT(another_map,
Contains(pair<const std::string, int>(std::string("fee"), 1)));
EXPECT_THAT(another_map, Contains(pair<const std::string, int>("fie", 2)));
}
TEST(ContainsTest, MapDoesNotMatchWhenElementIsNotInContainer) {
......@@ -1207,7 +1207,7 @@ TEST(ContainsTest, MapDoesNotMatchWhenElementIsNotInContainer) {
TEST(ContainsTest, ArrayMatchesWhenElementIsInContainer) {
const char* string_array[] = { "fee", "fie", "foe", "fum" };
EXPECT_THAT(string_array, Contains(Eq(string("fum"))));
EXPECT_THAT(string_array, Contains(Eq(std::string("fum"))));
}
TEST(ContainsTest, ArrayDoesNotMatchWhenElementIsNotInContainer) {
......
......@@ -319,11 +319,10 @@ TEST(TupleMatchesTest, WorksForSize2) {
TEST(TupleMatchesTest, WorksForSize5) {
tuple<Matcher<int>, Matcher<char>, Matcher<bool>, Matcher<long>, // NOLINT
Matcher<string> >
Matcher<std::string> >
matchers(Eq(1), Eq('a'), Eq(true), Eq(2L), Eq("hi"));
tuple<int, char, bool, long, string> // NOLINT
values1(1, 'a', true, 2L, "hi"),
values2(1, 'a', true, 2L, "hello"),
tuple<int, char, bool, long, std::string> // NOLINT
values1(1, 'a', true, 2L, "hi"), values2(1, 'a', true, 2L, "hello"),
values3(2, 'a', true, 2L, "hi");
EXPECT_TRUE(TupleMatches(matchers, values1));
......@@ -375,7 +374,7 @@ class LogIsVisibleTest : public ::testing::Test {
virtual void TearDown() { GMOCK_FLAG(verbose) = original_verbose_; }
string original_verbose_;
std::string original_verbose_;
};
TEST_F(LogIsVisibleTest, AlwaysReturnsTrueIfVerbosityIsInfo) {
......@@ -402,9 +401,9 @@ TEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) {
// Verifies that Log() behaves correctly for the given verbosity level
// and log severity.
void TestLogWithSeverity(const string& verbosity, LogSeverity severity,
void TestLogWithSeverity(const std::string& verbosity, LogSeverity severity,
bool should_print) {
const string old_flag = GMOCK_FLAG(verbose);
const std::string old_flag = GMOCK_FLAG(verbose);
GMOCK_FLAG(verbose) = verbosity;
CaptureStdout();
Log(severity, "Test log.\n", 0);
......@@ -423,7 +422,7 @@ void TestLogWithSeverity(const string& verbosity, LogSeverity severity,
// Tests that when the stack_frames_to_skip parameter is negative,
// Log() doesn't include the stack trace in the output.
TEST(LogTest, NoStackTraceWhenStackFramesToSkipIsNegative) {
const string saved_flag = GMOCK_FLAG(verbose);
const std::string saved_flag = GMOCK_FLAG(verbose);
GMOCK_FLAG(verbose) = kInfoVerbosity;
CaptureStdout();
Log(kInfo, "Test log.\n", -1);
......@@ -432,7 +431,7 @@ TEST(LogTest, NoStackTraceWhenStackFramesToSkipIsNegative) {
}
struct MockStackTraceGetter : testing::internal::OsStackTraceGetterInterface {
virtual string CurrentStackTrace(int max_depth, int skip_count) {
virtual std::string CurrentStackTrace(int max_depth, int skip_count) {
return (testing::Message() << max_depth << "::" << skip_count << "\n")
.GetString();
}
......@@ -447,11 +446,11 @@ TEST(LogTest, NoSkippingStackFrameInOptMode) {
CaptureStdout();
Log(kWarning, "Test log.\n", 100);
const string log = GetCapturedStdout();
const std::string log = GetCapturedStdout();
string expected_trace =
std::string expected_trace =
(testing::Message() << GTEST_FLAG(stack_trace_depth) << "::").GetString();
string expected_message =
std::string expected_message =
"\nGMOCK WARNING:\n"
"Test log.\n"
"Stack trace:\n" +
......@@ -547,7 +546,7 @@ TEST(TypeTraitsTest, remove_reference) {
// Verifies that Log() behaves correctly for the given verbosity level
// and log severity.
std::string GrabOutput(void(*logger)(), const char* verbosity) {
const string saved_flag = GMOCK_FLAG(verbose);
const std::string saved_flag = GMOCK_FLAG(verbose);
GMOCK_FLAG(verbose) = verbosity;
CaptureStdout();
logger();
......
......@@ -189,7 +189,7 @@ Matcher<int> GreaterThan(int n) {
return MakeMatcher(new GreaterThanMatcher(n));
}
string OfType(const string& type_name) {
std::string OfType(const std::string& type_name) {
#if GTEST_HAS_RTTI
return " (of type " + type_name + ")";
#else
......@@ -199,7 +199,7 @@ string OfType(const string& type_name) {
// Returns the description of the given matcher.
template <typename T>
string Describe(const Matcher<T>& m) {
std::string Describe(const Matcher<T>& m) {
stringstream ss;
m.DescribeTo(&ss);
return ss.str();
......@@ -207,7 +207,7 @@ string Describe(const Matcher<T>& m) {
// Returns the description of the negation of the given matcher.
template <typename T>
string DescribeNegation(const Matcher<T>& m) {
std::string DescribeNegation(const Matcher<T>& m) {
stringstream ss;
m.DescribeNegationTo(&ss);
return ss.str();
......@@ -215,7 +215,7 @@ string DescribeNegation(const Matcher<T>& m) {
// Returns the reason why x matches, or doesn't match, m.
template <typename MatcherType, typename Value>
string Explain(const MatcherType& m, const Value& x) {
std::string Explain(const MatcherType& m, const Value& x) {
StringMatchResultListener listener;
ExplainMatchResult(m, x, &listener);
return listener.str();
......@@ -973,7 +973,7 @@ TEST(LeTest, CanDescribeSelf) {
// Tests that Lt(v) matches anything < v.
TEST(LtTest, ImplementsLessThan) {
Matcher<const string&> m1 = Lt("Hello");
Matcher<const std::string&> m1 = Lt("Hello");
EXPECT_TRUE(m1.Matches("Abc"));
EXPECT_FALSE(m1.Matches("Hello"));
EXPECT_FALSE(m1.Matches("Hello, world!"));
......@@ -1125,7 +1125,7 @@ TEST(RefTest, CanDescribeSelf) {
Matcher<int&> m = Ref(n);
stringstream ss;
ss << "references the variable @" << &n << " 5";
EXPECT_EQ(string(ss.str()), Describe(m));
EXPECT_EQ(ss.str(), Describe(m));
}
// Test that Ref(non_const_varialbe) can be used as a matcher for a
......@@ -1169,27 +1169,27 @@ TEST(RefTest, ExplainsResult) {
// Tests string comparison matchers.
TEST(StrEqTest, MatchesEqualString) {
Matcher<const char*> m = StrEq(string("Hello"));
Matcher<const char*> m = StrEq(std::string("Hello"));
EXPECT_TRUE(m.Matches("Hello"));
EXPECT_FALSE(m.Matches("hello"));
EXPECT_FALSE(m.Matches(NULL));
Matcher<const string&> m2 = StrEq("Hello");
Matcher<const std::string&> m2 = StrEq("Hello");
EXPECT_TRUE(m2.Matches("Hello"));
EXPECT_FALSE(m2.Matches("Hi"));
}
TEST(StrEqTest, CanDescribeSelf) {
Matcher<string> m = StrEq("Hi-\'\"?\\\a\b\f\n\r\t\v\xD3");
Matcher<std::string> m = StrEq("Hi-\'\"?\\\a\b\f\n\r\t\v\xD3");
EXPECT_EQ("is equal to \"Hi-\'\\\"?\\\\\\a\\b\\f\\n\\r\\t\\v\\xD3\"",
Describe(m));
string str("01204500800");
std::string str("01204500800");
str[3] = '\0';
Matcher<string> m2 = StrEq(str);
Matcher<std::string> m2 = StrEq(str);
EXPECT_EQ("is equal to \"012\\04500800\"", Describe(m2));
str[0] = str[6] = str[7] = str[9] = str[10] = '\0';
Matcher<string> m3 = StrEq(str);
Matcher<std::string> m3 = StrEq(str);
EXPECT_EQ("is equal to \"\\012\\045\\0\\08\\0\\0\"", Describe(m3));
}
......@@ -1199,7 +1199,7 @@ TEST(StrNeTest, MatchesUnequalString) {
EXPECT_TRUE(m.Matches(NULL));
EXPECT_FALSE(m.Matches("Hello"));
Matcher<string> m2 = StrNe(string("Hello"));
Matcher<std::string> m2 = StrNe(std::string("Hello"));
EXPECT_TRUE(m2.Matches("hello"));
EXPECT_FALSE(m2.Matches("Hello"));
}
......@@ -1222,32 +1222,32 @@ TEST(StrCaseEqTest, MatchesEqualStringIgnoringCase) {
}
TEST(StrCaseEqTest, MatchesEqualStringWith0IgnoringCase) {
string str1("oabocdooeoo");
string str2("OABOCDOOEOO");
Matcher<const string&> m0 = StrCaseEq(str1);
EXPECT_FALSE(m0.Matches(str2 + string(1, '\0')));
std::string str1("oabocdooeoo");
std::string str2("OABOCDOOEOO");
Matcher<const std::string&> m0 = StrCaseEq(str1);
EXPECT_FALSE(m0.Matches(str2 + std::string(1, '\0')));
str1[3] = str2[3] = '\0';
Matcher<const string&> m1 = StrCaseEq(str1);
Matcher<const std::string&> m1 = StrCaseEq(str1);
EXPECT_TRUE(m1.Matches(str2));
str1[0] = str1[6] = str1[7] = str1[10] = '\0';
str2[0] = str2[6] = str2[7] = str2[10] = '\0';
Matcher<const string&> m2 = StrCaseEq(str1);
Matcher<const std::string&> m2 = StrCaseEq(str1);
str1[9] = str2[9] = '\0';
EXPECT_FALSE(m2.Matches(str2));
Matcher<const string&> m3 = StrCaseEq(str1);
Matcher<const std::string&> m3 = StrCaseEq(str1);
EXPECT_TRUE(m3.Matches(str2));
EXPECT_FALSE(m3.Matches(str2 + "x"));
str2.append(1, '\0');
EXPECT_FALSE(m3.Matches(str2));
EXPECT_FALSE(m3.Matches(string(str2, 0, 9)));
EXPECT_FALSE(m3.Matches(std::string(str2, 0, 9)));
}
TEST(StrCaseEqTest, CanDescribeSelf) {
Matcher<string> m = StrCaseEq("Hi");
Matcher<std::string> m = StrCaseEq("Hi");
EXPECT_EQ("is equal to (ignoring case) \"Hi\"", Describe(m));
}
......@@ -1258,7 +1258,7 @@ TEST(StrCaseNeTest, MatchesUnequalStringIgnoringCase) {
EXPECT_FALSE(m.Matches("Hello"));
EXPECT_FALSE(m.Matches("hello"));
Matcher<string> m2 = StrCaseNe(string("Hello"));
Matcher<std::string> m2 = StrCaseNe(std::string("Hello"));
EXPECT_TRUE(m2.Matches(""));
EXPECT_FALSE(m2.Matches("Hello"));
}
......@@ -1270,9 +1270,9 @@ TEST(StrCaseNeTest, CanDescribeSelf) {
// Tests that HasSubstr() works for matching string-typed values.
TEST(HasSubstrTest, WorksForStringClasses) {
const Matcher<string> m1 = HasSubstr("foo");
EXPECT_TRUE(m1.Matches(string("I love food.")));
EXPECT_FALSE(m1.Matches(string("tofo")));
const Matcher<std::string> m1 = HasSubstr("foo");
EXPECT_TRUE(m1.Matches(std::string("I love food.")));
EXPECT_FALSE(m1.Matches(std::string("tofo")));
const Matcher<const std::string&> m2 = HasSubstr("foo");
EXPECT_TRUE(m2.Matches(std::string("I love food.")));
......@@ -1294,7 +1294,7 @@ TEST(HasSubstrTest, WorksForCStrings) {
// Tests that HasSubstr(s) describes itself properly.
TEST(HasSubstrTest, CanDescribeSelf) {
Matcher<string> m = HasSubstr("foo\n\"");
Matcher<std::string> m = HasSubstr("foo\n\"");
EXPECT_EQ("has substring \"foo\\n\\\"\"", Describe(m));
}
......@@ -1460,12 +1460,12 @@ TEST(PairTest, InsideContainsUsingMap) {
// Tests StartsWith(s).
TEST(StartsWithTest, MatchesStringWithGivenPrefix) {
const Matcher<const char*> m1 = StartsWith(string(""));
const Matcher<const char*> m1 = StartsWith(std::string(""));
EXPECT_TRUE(m1.Matches("Hi"));
EXPECT_TRUE(m1.Matches(""));
EXPECT_FALSE(m1.Matches(NULL));
const Matcher<const string&> m2 = StartsWith("Hi");
const Matcher<const std::string&> m2 = StartsWith("Hi");
EXPECT_TRUE(m2.Matches("Hi"));
EXPECT_TRUE(m2.Matches("Hi Hi!"));
EXPECT_TRUE(m2.Matches("High"));
......@@ -1507,14 +1507,14 @@ TEST(MatchesRegexTest, MatchesStringMatchingGivenRegex) {
EXPECT_TRUE(m1.Matches("abcz"));
EXPECT_FALSE(m1.Matches(NULL));
const Matcher<const string&> m2 = MatchesRegex(new RE("a.*z"));
const Matcher<const std::string&> m2 = MatchesRegex(new RE("a.*z"));
EXPECT_TRUE(m2.Matches("azbz"));
EXPECT_FALSE(m2.Matches("az1"));
EXPECT_FALSE(m2.Matches("1az"));
}
TEST(MatchesRegexTest, CanDescribeSelf) {
Matcher<const std::string> m1 = MatchesRegex(string("Hi.*"));
Matcher<const std::string> m1 = MatchesRegex(std::string("Hi.*"));
EXPECT_EQ("matches regular expression \"Hi.*\"", Describe(m1));
Matcher<const char*> m2 = MatchesRegex(new RE("a.*"));
......@@ -1524,12 +1524,12 @@ TEST(MatchesRegexTest, CanDescribeSelf) {
// Tests ContainsRegex().
TEST(ContainsRegexTest, MatchesStringContainingGivenRegex) {
const Matcher<const char*> m1 = ContainsRegex(string("a.*z"));
const Matcher<const char*> m1 = ContainsRegex(std::string("a.*z"));
EXPECT_TRUE(m1.Matches("az"));
EXPECT_TRUE(m1.Matches("0abcz1"));
EXPECT_FALSE(m1.Matches(NULL));
const Matcher<const string&> m2 = ContainsRegex(new RE("a.*z"));
const Matcher<const std::string&> m2 = ContainsRegex(new RE("a.*z"));
EXPECT_TRUE(m2.Matches("azbz"));
EXPECT_TRUE(m2.Matches("az1"));
EXPECT_FALSE(m2.Matches("1a"));
......@@ -2685,9 +2685,9 @@ TEST(MatcherAssertionTest, WorksForMonomorphicMatcher) {
Matcher<const char*> starts_with_he = StartsWith("he");
ASSERT_THAT("hello", starts_with_he);
Matcher<const string&> ends_with_ok = EndsWith("ok");
Matcher<const std::string&> ends_with_ok = EndsWith("ok");
ASSERT_THAT("book", ends_with_ok);
const string bad = "bad";
const std::string bad = "bad";
EXPECT_NONFATAL_FAILURE(EXPECT_THAT(bad, ends_with_ok),
"Value of: bad\n"
"Expected: ends with \"ok\"\n"
......@@ -3099,7 +3099,8 @@ TEST_F(DoubleNearTest, ExplainsResultWhenMatchFails) {
EXPECT_EQ("which is 0.2 from 2", Explain(DoubleNear(2.0, 0.1), 2.2));
EXPECT_EQ("which is -0.3 from 2", Explain(DoubleNear(2.0, 0.1), 1.7));
const string explanation = Explain(DoubleNear(2.1, 1e-10), 2.1 + 1.2e-10);
const std::string explanation =
Explain(DoubleNear(2.1, 1e-10), 2.1 + 1.2e-10);
// Different C++ implementations may print floating-point numbers
// slightly differently.
EXPECT_TRUE(explanation == "which is 1.2e-10 from 2.1" || // GCC
......@@ -3337,9 +3338,9 @@ TEST(PointeeTest, CanDescribeSelf) {
}
TEST(PointeeTest, CanExplainMatchResult) {
const Matcher<const string*> m = Pointee(StartsWith("Hi"));
const Matcher<const std::string*> m = Pointee(StartsWith("Hi"));
EXPECT_EQ("", Explain(m, static_cast<const string*>(NULL)));
EXPECT_EQ("", Explain(m, static_cast<const std::string*>(NULL)));
const Matcher<long*> m2 = Pointee(GreaterThan(1)); // NOLINT
long n = 3; // NOLINT
......@@ -3585,15 +3586,15 @@ class AClass {
void set_n(int new_n) { n_ = new_n; }
// A getter that returns a reference to const.
const string& s() const { return s_; }
const std::string& s() const { return s_; }
void set_s(const string& new_s) { s_ = new_s; }
void set_s(const std::string& new_s) { s_ = new_s; }
// A getter that returns a reference to non-const.
double& x() const { return x_; }
private:
int n_;
string s_;
std::string s_;
static double x_;
};
......@@ -3799,10 +3800,12 @@ TEST(PropertyForPointerTest, CanExplainMatchResult) {
// Tests that ResultOf(f, ...) compiles and works as expected when f is a
// function pointer.
string IntToStringFunction(int input) { return input == 1 ? "foo" : "bar"; }
std::string IntToStringFunction(int input) {
return input == 1 ? "foo" : "bar";
}
TEST(ResultOfTest, WorksForFunctionPointers) {
Matcher<int> matcher = ResultOf(&IntToStringFunction, Eq(string("foo")));
Matcher<int> matcher = ResultOf(&IntToStringFunction, Eq(std::string("foo")));
EXPECT_TRUE(matcher.Matches(1));
EXPECT_FALSE(matcher.Matches(2));
......@@ -3868,12 +3871,12 @@ TEST(ResultOfTest, WorksForReferenceToNonConstResults) {
// Tests that ResultOf(f, ...) compiles and works as expected when f(x)
// returns a reference to const.
const string& StringFunction(const string& input) { return input; }
const std::string& StringFunction(const std::string& input) { return input; }
TEST(ResultOfTest, WorksForReferenceToConstResults) {
string s = "foo";
string s2 = s;
Matcher<const string&> matcher = ResultOf(&StringFunction, Ref(s));
std::string s = "foo";
std::string s2 = s;
Matcher<const std::string&> matcher = ResultOf(&StringFunction, Ref(s));
EXPECT_TRUE(matcher.Matches(s));
EXPECT_FALSE(matcher.Matches(s2));
......@@ -3893,8 +3896,9 @@ TEST(ResultOfTest, WorksForCompatibleMatcherTypes) {
// a NULL function pointer.
TEST(ResultOfDeathTest, DiesOnNullFunctionPointers) {
EXPECT_DEATH_IF_SUPPORTED(
ResultOf(static_cast<string(*)(int dummy)>(NULL), Eq(string("foo"))),
"NULL function pointer is passed into ResultOf\\(\\)\\.");
ResultOf(static_cast<std::string (*)(int dummy)>(NULL),
Eq(std::string("foo"))),
"NULL function pointer is passed into ResultOf\\(\\)\\.");
}
// Tests that ResultOf(f, ...) compiles and works as expected when f is a
......@@ -3907,14 +3911,14 @@ TEST(ResultOfTest, WorksForFunctionReferences) {
// Tests that ResultOf(f, ...) compiles and works as expected when f is a
// function object.
struct Functor : public ::std::unary_function<int, string> {
struct Functor : public ::std::unary_function<int, std::string> {
result_type operator()(argument_type input) const {
return IntToStringFunction(input);
}
};
TEST(ResultOfTest, WorksForFunctors) {
Matcher<int> matcher = ResultOf(Functor(), Eq(string("foo")));
Matcher<int> matcher = ResultOf(Functor(), Eq(std::string("foo")));
EXPECT_TRUE(matcher.Matches(1));
EXPECT_FALSE(matcher.Matches(2));
......@@ -4080,11 +4084,11 @@ TEST(IsEmptyTest, ImplementsIsEmpty) {
}
TEST(IsEmptyTest, WorksWithString) {
string text;
std::string text;
EXPECT_THAT(text, IsEmpty());
text = "foo";
EXPECT_THAT(text, Not(IsEmpty()));
text = string("\0", 1);
text = std::string("\0", 1);
EXPECT_THAT(text, Not(IsEmpty()));
}
......@@ -4115,7 +4119,7 @@ TEST(SizeIsTest, ImplementsSizeIs) {
}
TEST(SizeIsTest, WorksWithMap) {
map<string, int> container;
map<std::string, int> container;
EXPECT_THAT(container, SizeIs(0));
EXPECT_THAT(container, Not(SizeIs(1)));
container.insert(make_pair("foo", 1));
......@@ -4380,13 +4384,13 @@ TEST(WhenSortedByTest, WorksForNonEmptyContainer) {
}
TEST(WhenSortedByTest, WorksForNonVectorContainer) {
list<string> words;
list<std::string> words;
words.push_back("say");
words.push_back("hello");
words.push_back("world");
EXPECT_THAT(words, WhenSortedBy(less<string>(),
EXPECT_THAT(words, WhenSortedBy(less<std::string>(),
ElementsAre("hello", "say", "world")));
EXPECT_THAT(words, Not(WhenSortedBy(less<string>(),
EXPECT_THAT(words, Not(WhenSortedBy(less<std::string>(),
ElementsAre("say", "hello", "world"))));
}
......@@ -4429,7 +4433,7 @@ TEST(WhenSortedTest, WorksForEmptyContainer) {
}
TEST(WhenSortedTest, WorksForNonEmptyContainer) {
list<string> words;
list<std::string> words;
words.push_back("3");
words.push_back("1");
words.push_back("2");
......@@ -4439,14 +4443,16 @@ TEST(WhenSortedTest, WorksForNonEmptyContainer) {
}
TEST(WhenSortedTest, WorksForMapTypes) {
map<string, int> word_counts;
word_counts["and"] = 1;
word_counts["the"] = 1;
word_counts["buffalo"] = 2;
EXPECT_THAT(word_counts, WhenSorted(ElementsAre(
Pair("and", 1), Pair("buffalo", 2), Pair("the", 1))));
EXPECT_THAT(word_counts, Not(WhenSorted(ElementsAre(
Pair("and", 1), Pair("the", 1), Pair("buffalo", 2)))));
map<std::string, int> word_counts;
word_counts["and"] = 1;
word_counts["the"] = 1;
word_counts["buffalo"] = 2;
EXPECT_THAT(word_counts,
WhenSorted(ElementsAre(Pair("and", 1), Pair("buffalo", 2),
Pair("the", 1))));
EXPECT_THAT(word_counts,
Not(WhenSorted(ElementsAre(Pair("and", 1), Pair("the", 1),
Pair("buffalo", 2)))));
}
TEST(WhenSortedTest, WorksForMultiMapTypes) {
......@@ -4763,7 +4769,7 @@ TEST(UnorderedElementsAreArrayTest, TakesInitializerList) {
}
TEST(UnorderedElementsAreArrayTest, TakesInitializerListOfCStrings) {
const string a[5] = {"a", "b", "c", "d", "e"};
const std::string a[5] = {"a", "b", "c", "d", "e"};
EXPECT_THAT(a, UnorderedElementsAreArray({"a", "b", "c", "d", "e"}));
EXPECT_THAT(a, Not(UnorderedElementsAreArray({"a", "b", "c", "d", "ef"})));
}
......@@ -4937,7 +4943,7 @@ TEST_F(UnorderedElementsAreTest, FailMessageUnmatchedMatcherAndElement) {
}
// Test helper for formatting element, matcher index pairs in expectations.
static string EMString(int element, int matcher) {
static std::string EMString(int element, int matcher) {
stringstream ss;
ss << "(element #" << element << ", matcher #" << matcher << ")";
return ss.str();
......@@ -4946,7 +4952,7 @@ static string EMString(int element, int matcher) {
TEST_F(UnorderedElementsAreTest, FailMessageImperfectMatchOnly) {
// A situation where all elements and matchers have a match
// associated with them, but the max matching is not perfect.
std::vector<string> v;
std::vector<std::string> v;
v.push_back("a");
v.push_back("b");
v.push_back("c");
......@@ -4955,7 +4961,7 @@ TEST_F(UnorderedElementsAreTest, FailMessageImperfectMatchOnly) {
UnorderedElementsAre("a", "a", AnyOf("b", "c")), v, &listener))
<< listener.str();
string prefix =
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";
......@@ -5366,13 +5372,13 @@ TEST(EachTest, MatchesVectorWhenAllElementsMatch) {
EXPECT_THAT(some_vector, Not(Each(3)));
EXPECT_THAT(some_vector, Each(Lt(3.5)));
vector<string> another_vector;
vector<std::string> another_vector;
another_vector.push_back("fee");
EXPECT_THAT(another_vector, Each(string("fee")));
EXPECT_THAT(another_vector, Each(std::string("fee")));
another_vector.push_back("fie");
another_vector.push_back("foe");
another_vector.push_back("fum");
EXPECT_THAT(another_vector, Not(Each(string("fee"))));
EXPECT_THAT(another_vector, Not(Each(std::string("fee"))));
}
TEST(EachTest, MatchesMapWhenAllElementsMatch) {
......@@ -5381,15 +5387,15 @@ TEST(EachTest, MatchesMapWhenAllElementsMatch) {
my_map[bar] = 2;
EXPECT_THAT(my_map, Each(make_pair(bar, 2)));
map<string, int> another_map;
EXPECT_THAT(another_map, Each(make_pair(string("fee"), 1)));
map<std::string, int> another_map;
EXPECT_THAT(another_map, Each(make_pair(std::string("fee"), 1)));
another_map["fee"] = 1;
EXPECT_THAT(another_map, Each(make_pair(string("fee"), 1)));
EXPECT_THAT(another_map, Each(make_pair(std::string("fee"), 1)));
another_map["fie"] = 2;
another_map["foe"] = 3;
another_map["fum"] = 4;
EXPECT_THAT(another_map, Not(Each(make_pair(string("fee"), 1))));
EXPECT_THAT(another_map, Not(Each(make_pair(string("fum"), 1))));
EXPECT_THAT(another_map, Not(Each(make_pair(std::string("fee"), 1))));
EXPECT_THAT(another_map, Not(Each(make_pair(std::string("fum"), 1))));
EXPECT_THAT(another_map, Each(Pair(_, Gt(0))));
}
......
......@@ -94,12 +94,12 @@ const char* Plus1(const char* s) { return s + 1; }
void VoidUnary(int /* n */) { g_done = true; }
bool ByConstRef(const string& s) { return s == "Hi"; }
bool ByConstRef(const std::string& s) { return s == "Hi"; }
const double g_double = 0;
bool ReferencesGlobalDouble(const double& x) { return &x == &g_double; }
string ByNonConstRef(string& s) { return s += "+"; } // NOLINT
std::string ByNonConstRef(std::string& s) { return s += "+"; } // NOLINT
struct UnaryFunctor {
int operator()(bool x) { return x ? 1 : -1; }
......@@ -119,9 +119,9 @@ int SumOfFirst2(int a, int b, Unused, Unused) { return a + b; }
void VoidFunctionWithFourArguments(char, int, float, double) { g_done = true; }
string Concat4(const char* s1, const char* s2, const char* s3,
const char* s4) {
return string(s1) + s2 + s3 + s4;
std::string Concat4(const char* s1, const char* s2, const char* s3,
const char* s4) {
return std::string(s1) + s2 + s3 + s4;
}
int SumOf5(int a, int b, int c, int d, int e) { return a + b + c + d + e; }
......@@ -132,9 +132,9 @@ struct SumOf5Functor {
}
};
string Concat5(const char* s1, const char* s2, const char* s3,
const char* s4, const char* s5) {
return string(s1) + s2 + s3 + s4 + s5;
std::string Concat5(const char* s1, const char* s2, const char* s3,
const char* s4, const char* s5) {
return std::string(s1) + s2 + s3 + s4 + s5;
}
int SumOf6(int a, int b, int c, int d, int e, int f) {
......@@ -147,34 +147,34 @@ struct SumOf6Functor {
}
};
string Concat6(const char* s1, const char* s2, const char* s3,
const char* s4, const char* s5, const char* s6) {
return string(s1) + s2 + s3 + s4 + s5 + s6;
std::string Concat6(const char* s1, const char* s2, const char* s3,
const char* s4, const char* s5, const char* s6) {
return std::string(s1) + s2 + s3 + s4 + s5 + s6;
}
string Concat7(const char* s1, const char* s2, const char* s3,
const char* s4, const char* s5, const char* s6,
const char* s7) {
return string(s1) + s2 + s3 + s4 + s5 + s6 + s7;
std::string Concat7(const char* s1, const char* s2, const char* s3,
const char* s4, const char* s5, const char* s6,
const char* s7) {
return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7;
}
string Concat8(const char* s1, const char* s2, const char* s3,
const char* s4, const char* s5, const char* s6,
const char* s7, const char* s8) {
return string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8;
std::string Concat8(const char* s1, const char* s2, const char* s3,
const char* s4, const char* s5, const char* s6,
const char* s7, const char* s8) {
return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8;
}
string Concat9(const char* s1, const char* s2, const char* s3,
const char* s4, const char* s5, const char* s6,
const char* s7, const char* s8, const char* s9) {
return string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9;
std::string Concat9(const char* s1, const char* s2, const char* s3,
const char* s4, const char* s5, const char* s6,
const char* s7, const char* s8, const char* s9) {
return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9;
}
string Concat10(const char* s1, const char* s2, const char* s3,
const char* s4, const char* s5, const char* s6,
const char* s7, const char* s8, const char* s9,
const char* s10) {
return string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10;
std::string Concat10(const char* s1, const char* s2, const char* s3,
const char* s4, const char* s5, const char* s6,
const char* s7, const char* s8, const char* s9,
const char* s10) {
return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10;
}
class Foo {
......@@ -185,7 +185,7 @@ class Foo {
short Unary(long x) { return static_cast<short>(value_ + x); } // NOLINT
string Binary(const string& str, char c) const { return str + c; }
std::string Binary(const std::string& str, char c) const { return str + c; }
int Ternary(int x, bool y, char z) { return value_ + x + y*z; }
......@@ -201,29 +201,29 @@ class Foo {
return a + b + c + d + e + f;
}
string Concat7(const char* s1, const char* s2, const char* s3,
const char* s4, const char* s5, const char* s6,
const char* s7) {
return string(s1) + s2 + s3 + s4 + s5 + s6 + s7;
std::string Concat7(const char* s1, const char* s2, const char* s3,
const char* s4, const char* s5, const char* s6,
const char* s7) {
return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7;
}
string Concat8(const char* s1, const char* s2, const char* s3,
const char* s4, const char* s5, const char* s6,
const char* s7, const char* s8) {
return string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8;
std::string Concat8(const char* s1, const char* s2, const char* s3,
const char* s4, const char* s5, const char* s6,
const char* s7, const char* s8) {
return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8;
}
string Concat9(const char* s1, const char* s2, const char* s3,
const char* s4, const char* s5, const char* s6,
const char* s7, const char* s8, const char* s9) {
return string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9;
std::string Concat9(const char* s1, const char* s2, const char* s3,
const char* s4, const char* s5, const char* s6,
const char* s7, const char* s8, const char* s9) {
return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9;
}
string Concat10(const char* s1, const char* s2, const char* s3,
const char* s4, const char* s5, const char* s6,
const char* s7, const char* s8, const char* s9,
const char* s10) {
return string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10;
std::string Concat10(const char* s1, const char* s2, const char* s3,
const char* s4, const char* s5, const char* s6,
const char* s7, const char* s8, const char* s9,
const char* s10) {
return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10;
}
private:
......@@ -280,9 +280,9 @@ inline const char* CharPtr(const char* s) { return s; }
// Tests using Invoke() with a 7-argument function.
TEST(InvokeTest, FunctionThatTakes7Arguments) {
Action<string(const char*, const char*, const char*, const char*,
const char*, const char*, const char*)> a =
Invoke(Concat7);
Action<std::string(const char*, const char*, const char*, const char*,
const char*, const char*, const char*)>
a = Invoke(Concat7);
EXPECT_EQ("1234567",
a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"),
CharPtr("4"), CharPtr("5"), CharPtr("6"),
......@@ -291,9 +291,9 @@ TEST(InvokeTest, FunctionThatTakes7Arguments) {
// Tests using Invoke() with a 8-argument function.
TEST(InvokeTest, FunctionThatTakes8Arguments) {
Action<string(const char*, const char*, const char*, const char*,
const char*, const char*, const char*, const char*)> a =
Invoke(Concat8);
Action<std::string(const char*, const char*, const char*, const char*,
const char*, const char*, const char*, const char*)>
a = Invoke(Concat8);
EXPECT_EQ("12345678",
a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"),
CharPtr("4"), CharPtr("5"), CharPtr("6"),
......@@ -302,9 +302,10 @@ TEST(InvokeTest, FunctionThatTakes8Arguments) {
// Tests using Invoke() with a 9-argument function.
TEST(InvokeTest, FunctionThatTakes9Arguments) {
Action<string(const char*, const char*, const char*, const char*,
const char*, const char*, const char*, const char*,
const char*)> a = Invoke(Concat9);
Action<std::string(const char*, const char*, const char*, const char*,
const char*, const char*, const char*, const char*,
const char*)>
a = Invoke(Concat9);
EXPECT_EQ("123456789",
a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"),
CharPtr("4"), CharPtr("5"), CharPtr("6"),
......@@ -313,9 +314,10 @@ TEST(InvokeTest, FunctionThatTakes9Arguments) {
// Tests using Invoke() with a 10-argument function.
TEST(InvokeTest, FunctionThatTakes10Arguments) {
Action<string(const char*, const char*, const char*, const char*,
const char*, const char*, const char*, const char*,
const char*, const char*)> a = Invoke(Concat10);
Action<std::string(const char*, const char*, const char*, const char*,
const char*, const char*, const char*, const char*,
const char*, const char*)>
a = Invoke(Concat10);
EXPECT_EQ("1234567890",
a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"),
CharPtr("4"), CharPtr("5"), CharPtr("6"),
......@@ -339,8 +341,7 @@ TEST(InvokeTest, FunctionWithUnusedParameters) {
// Tests using Invoke() with methods with parameters declared as Unused.
TEST(InvokeTest, MethodWithUnusedParameters) {
Foo foo;
Action<int(string, bool, int, int)> a1 =
Invoke(&foo, &Foo::SumOfLast2);
Action<int(std::string, bool, int, int)> a1 = Invoke(&foo, &Foo::SumOfLast2);
EXPECT_EQ(12, a1.Perform(make_tuple(CharPtr("hi"), true, 10, 2)));
Action<int(char, double, int, int)> a2 =
......@@ -417,9 +418,9 @@ TEST(InvokeMethodTest, MethodThatTakes6Arguments) {
// Tests using Invoke() with a 7-argument method.
TEST(InvokeMethodTest, MethodThatTakes7Arguments) {
Foo foo;
Action<string(const char*, const char*, const char*, const char*,
const char*, const char*, const char*)> a =
Invoke(&foo, &Foo::Concat7);
Action<std::string(const char*, const char*, const char*, const char*,
const char*, const char*, const char*)>
a = Invoke(&foo, &Foo::Concat7);
EXPECT_EQ("1234567",
a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"),
CharPtr("4"), CharPtr("5"), CharPtr("6"),
......@@ -429,9 +430,9 @@ TEST(InvokeMethodTest, MethodThatTakes7Arguments) {
// Tests using Invoke() with a 8-argument method.
TEST(InvokeMethodTest, MethodThatTakes8Arguments) {
Foo foo;
Action<string(const char*, const char*, const char*, const char*,
const char*, const char*, const char*, const char*)> a =
Invoke(&foo, &Foo::Concat8);
Action<std::string(const char*, const char*, const char*, const char*,
const char*, const char*, const char*, const char*)>
a = Invoke(&foo, &Foo::Concat8);
EXPECT_EQ("12345678",
a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"),
CharPtr("4"), CharPtr("5"), CharPtr("6"),
......@@ -441,9 +442,10 @@ TEST(InvokeMethodTest, MethodThatTakes8Arguments) {
// Tests using Invoke() with a 9-argument method.
TEST(InvokeMethodTest, MethodThatTakes9Arguments) {
Foo foo;
Action<string(const char*, const char*, const char*, const char*,
const char*, const char*, const char*, const char*,
const char*)> a = Invoke(&foo, &Foo::Concat9);
Action<std::string(const char*, const char*, const char*, const char*,
const char*, const char*, const char*, const char*,
const char*)>
a = Invoke(&foo, &Foo::Concat9);
EXPECT_EQ("123456789",
a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"),
CharPtr("4"), CharPtr("5"), CharPtr("6"),
......@@ -453,9 +455,10 @@ TEST(InvokeMethodTest, MethodThatTakes9Arguments) {
// Tests using Invoke() with a 10-argument method.
TEST(InvokeMethodTest, MethodThatTakes10Arguments) {
Foo foo;
Action<string(const char*, const char*, const char*, const char*,
const char*, const char*, const char*, const char*,
const char*, const char*)> a = Invoke(&foo, &Foo::Concat10);
Action<std::string(const char*, const char*, const char*, const char*,
const char*, const char*, const char*, const char*,
const char*, const char*)>
a = Invoke(&foo, &Foo::Concat10);
EXPECT_EQ("1234567890",
a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"),
CharPtr("4"), CharPtr("5"), CharPtr("6"),
......@@ -495,8 +498,8 @@ TEST(ReturnArgActionTest, WorksForMultiArgBoolArg0) {
}
TEST(ReturnArgActionTest, WorksForMultiArgStringArg2) {
const Action<string(int, int, string, int)> a = ReturnArg<2>();
EXPECT_EQ("seven", a.Perform(make_tuple(5, 6, string("seven"), 8)));
const Action<std::string(int, int, std::string, int)> a = ReturnArg<2>();
EXPECT_EQ("seven", a.Perform(make_tuple(5, 6, std::string("seven"), 8)));
}
TEST(SaveArgActionTest, WorksForSameType) {
......
......@@ -51,7 +51,6 @@ class Mock {
namespace testing {
namespace gmock_nice_strict_test {
using testing::internal::string;
using testing::GMOCK_FLAG(verbose);
using testing::HasSubstr;
using testing::NaggyMock;
......@@ -63,6 +62,12 @@ using testing::internal::CaptureStdout;
using testing::internal::GetCapturedStdout;
#endif
// Class without default constructor.
class NotDefaultConstructible {
public:
explicit NotDefaultConstructible(int) {}
};
// Defines some mock classes needed by the tests.
class Foo {
......@@ -80,6 +85,7 @@ class MockFoo : public Foo {
MOCK_METHOD0(DoThis, void());
MOCK_METHOD1(DoThat, int(bool flag));
MOCK_METHOD0(ReturnNonDefaultConstructible, NotDefaultConstructible());
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo);
......@@ -87,23 +93,23 @@ class MockFoo : public Foo {
class MockBar {
public:
explicit MockBar(const string& s) : str_(s) {}
explicit MockBar(const std::string& s) : str_(s) {}
MockBar(char a1, char a2, string a3, string a4, int a5, int a6,
const string& a7, const string& a8, bool a9, bool a10) {
str_ = string() + a1 + a2 + a3 + a4 + static_cast<char>(a5) +
MockBar(char a1, char a2, std::string a3, std::string a4, int a5, int a6,
const std::string& a7, const std::string& a8, bool a9, bool a10) {
str_ = std::string() + a1 + a2 + a3 + a4 + static_cast<char>(a5) +
static_cast<char>(a6) + a7 + a8 + (a9 ? 'T' : 'F') + (a10 ? 'T' : 'F');
}
virtual ~MockBar() {}
const string& str() const { return str_; }
const std::string& str() const { return str_; }
MOCK_METHOD0(This, int());
MOCK_METHOD2(That, string(int, bool));
MOCK_METHOD2(That, std::string(int, bool));
private:
string str_;
std::string str_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockBar);
};
......@@ -112,7 +118,7 @@ class MockBar {
// Tests that a raw mock generates warnings for uninteresting calls.
TEST(RawMockTest, WarningForUninterestingCall) {
const string saved_flag = GMOCK_FLAG(verbose);
const std::string saved_flag = GMOCK_FLAG(verbose);
GMOCK_FLAG(verbose) = "warning";
MockFoo raw_foo;
......@@ -129,7 +135,7 @@ TEST(RawMockTest, WarningForUninterestingCall) {
// Tests that a raw mock generates warnings for uninteresting calls
// that delete the mock object.
TEST(RawMockTest, WarningForUninterestingCallAfterDeath) {
const string saved_flag = GMOCK_FLAG(verbose);
const std::string saved_flag = GMOCK_FLAG(verbose);
GMOCK_FLAG(verbose) = "warning";
MockFoo* const raw_foo = new MockFoo;
......@@ -150,7 +156,7 @@ TEST(RawMockTest, WarningForUninterestingCallAfterDeath) {
TEST(RawMockTest, InfoForUninterestingCall) {
MockFoo raw_foo;
const string saved_flag = GMOCK_FLAG(verbose);
const std::string saved_flag = GMOCK_FLAG(verbose);
GMOCK_FLAG(verbose) = "info";
CaptureStdout();
raw_foo.DoThis();
......@@ -188,7 +194,7 @@ TEST(NiceMockTest, NoWarningForUninterestingCallAfterDeath) {
TEST(NiceMockTest, InfoForUninterestingCall) {
NiceMock<MockFoo> nice_foo;
const string saved_flag = GMOCK_FLAG(verbose);
const std::string saved_flag = GMOCK_FLAG(verbose);
GMOCK_FLAG(verbose) = "info";
CaptureStdout();
nice_foo.DoThis();
......@@ -208,6 +214,22 @@ TEST(NiceMockTest, AllowsExpectedCall) {
nice_foo.DoThis();
}
// Tests that an unexpected call on a nice mock which returns a not-default-constructible
// type throws an exception and the exception contains the method's name.
TEST(NiceMockTest, ThrowsExceptionForUnknownReturnTypes) {
NiceMock<MockFoo> nice_foo;
#if GTEST_HAS_EXCEPTIONS
try {
nice_foo.ReturnNonDefaultConstructible();
FAIL();
} catch (const std::runtime_error& ex) {
EXPECT_THAT(ex.what(), HasSubstr("ReturnNonDefaultConstructible"));
}
#else
EXPECT_DEATH_IF_SUPPORTED({ nice_foo.ReturnNonDefaultConstructible(); }, "");
#endif
}
// Tests that an unexpected call on a nice mock fails.
TEST(NiceMockTest, UnexpectedCallFails) {
NiceMock<MockFoo> nice_foo;
......@@ -257,7 +279,7 @@ TEST(NiceMockTest, AcceptsClassNamedMock) {
// Tests that a naggy mock generates warnings for uninteresting calls.
TEST(NaggyMockTest, WarningForUninterestingCall) {
const string saved_flag = GMOCK_FLAG(verbose);
const std::string saved_flag = GMOCK_FLAG(verbose);
GMOCK_FLAG(verbose) = "warning";
NaggyMock<MockFoo> naggy_foo;
......@@ -274,7 +296,7 @@ TEST(NaggyMockTest, WarningForUninterestingCall) {
// Tests that a naggy mock generates a warning for an uninteresting call
// that deletes the mock object.
TEST(NaggyMockTest, WarningForUninterestingCallAfterDeath) {
const string saved_flag = GMOCK_FLAG(verbose);
const std::string saved_flag = GMOCK_FLAG(verbose);
GMOCK_FLAG(verbose) = "warning";
NaggyMock<MockFoo>* const naggy_foo = new NaggyMock<MockFoo>;
......
......@@ -97,7 +97,6 @@ using testing::internal::kErrorVerbosity;
using testing::internal::kInfoVerbosity;
using testing::internal::kWarningVerbosity;
using testing::internal::linked_ptr;
using testing::internal::string;
#if GTEST_HAS_STREAM_REDIRECTION
using testing::HasSubstr;
......@@ -1954,7 +1953,7 @@ class MockC {
public:
MockC() {}
MOCK_METHOD6(VoidMethod, void(bool cond, int n, string s, void* p,
MOCK_METHOD6(VoidMethod, void(bool cond, int n, std::string s, void* p,
const Printable& x, Unprintable y));
MOCK_METHOD0(NonVoidMethod, int()); // NOLINT
......@@ -1970,7 +1969,7 @@ class VerboseFlagPreservingFixture : public testing::Test {
~VerboseFlagPreservingFixture() { GMOCK_FLAG(verbose) = saved_verbose_flag_; }
private:
const string saved_verbose_flag_;
const std::string saved_verbose_flag_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(VerboseFlagPreservingFixture);
};
......@@ -2062,8 +2061,8 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture {
// contain the given function name in the stack trace. When it's
// false, the output should be empty.)
void VerifyOutput(const std::string& output, bool should_print,
const string& expected_substring,
const string& function_name) {
const std::string& expected_substring,
const std::string& function_name) {
if (should_print) {
EXPECT_THAT(output.c_str(), HasSubstr(expected_substring));
# ifndef NDEBUG
......@@ -2113,7 +2112,7 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture {
// Tests how the flag affects uninteresting calls on a naggy mock.
void TestUninterestingCallOnNaggyMock(bool should_print) {
NaggyMock<MockA> a;
const string note =
const std::string note =
"NOTE: You can safely ignore the above warning unless this "
"call should not happen. Do not suppress it by blindly adding "
"an EXPECT_CALL() if you don't mean to enforce the call. "
......
......@@ -51,7 +51,7 @@ const int kRepeat = 50;
class MockFoo {
public:
MOCK_METHOD1(Bar, int(int n)); // NOLINT
MOCK_METHOD2(Baz, char(const char* s1, const internal::string& s2)); // NOLINT
MOCK_METHOD2(Baz, char(const char* s1, const std::string& s2)); // NOLINT
};
// Helper for waiting for the given thread to finish and then deleting it.
......
......@@ -44,9 +44,18 @@ endif()
# as ${gtest_SOURCE_DIR} and to the root binary directory as
# ${gtest_BINARY_DIR}.
# Language "C" is required for find_package(Threads).
project(gtest CXX C)
if (CMAKE_VERSION VERSION_LESS 3.0)
project(gtest CXX C)
else()
cmake_policy(SET CMP0048 NEW)
project(gtest VERSION 1.9.0 LANGUAGES CXX C)
endif()
cmake_minimum_required(VERSION 2.6.4)
if (POLICY CMP0063) # Visibility
cmake_policy(SET CMP0063 NEW)
endif (POLICY CMP0063)
if (COMMAND set_up_hermetic_build)
set_up_hermetic_build()
endif()
......@@ -102,10 +111,26 @@ endif()
########################################################################
#
# Install rules
install(TARGETS gtest gtest_main
DESTINATION lib)
install(DIRECTORY ${gtest_SOURCE_DIR}/include/gtest
DESTINATION include)
if(INSTALL_GTEST)
install(TARGETS gtest gtest_main
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(DIRECTORY ${gtest_SOURCE_DIR}/include/gtest
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# configure and install pkgconfig files
configure_file(
cmake/gtest.pc.in
"${CMAKE_BINARY_DIR}/gtest.pc"
@ONLY)
configure_file(
cmake/gtest_main.pc.in
"${CMAKE_BINARY_DIR}/gtest_main.pc"
@ONLY)
install(FILES "${CMAKE_BINARY_DIR}/gtest.pc" "${CMAKE_BINARY_DIR}/gtest_main.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
endif()
########################################################################
#
......
......@@ -216,7 +216,7 @@ pkginclude_internal_HEADERS = \
lib_libgtest_main_la_SOURCES = src/gtest_main.cc
lib_libgtest_main_la_LIBADD = lib/libgtest.la
# Bulid rules for samples and tests. Automake's naming for some of
# Build rules for samples and tests. Automake's naming for some of
# these variables isn't terribly obvious, so this is a brief
# reference:
#
......
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
Name: gtest
Description: GoogleTest (without main() function)
Version: @PROJECT_VERSION@
URL: https://github.com/google/googletest
Libs: -L${libdir} -lgtest @CMAKE_THREAD_LIBS_INIT@
Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ @CMAKE_THREAD_LIBS_INIT@
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
Name: gtest_main
Description: GoogleTest (with main() function)
Version: @PROJECT_VERSION@
URL: https://github.com/google/googletest
Requires: gtest
Libs: -L${libdir} -lgtest_main @CMAKE_THREAD_LIBS_INIT@
Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ @CMAKE_THREAD_LIBS_INIT@
......@@ -50,6 +50,7 @@ macro(config_compiler_and_linker)
# instead, we use windows threading primitives
if (NOT gtest_disable_pthreads AND NOT MINGW)
# Defines CMAKE_USE_PTHREADS_INIT and CMAKE_THREAD_LIBS_INIT.
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads)
endif()
......@@ -126,10 +127,11 @@ macro(config_compiler_and_linker)
endif()
if (CMAKE_USE_PTHREADS_INIT) # The pthreads library is available and allowed.
set(cxx_base_flags "${cxx_base_flags} -DGTEST_HAS_PTHREAD=1")
set(GTEST_HAS_PTHREAD_MACRO "-DGTEST_HAS_PTHREAD=1")
else()
set(cxx_base_flags "${cxx_base_flags} -DGTEST_HAS_PTHREAD=0")
set(GTEST_HAS_PTHREAD_MACRO "-DGTEST_HAS_PTHREAD=0")
endif()
set(cxx_base_flags "${cxx_base_flags} ${GTEST_HAS_PTHREAD_MACRO}")
# For building gtest's own tests and samples.
set(cxx_exception "${CMAKE_CXX_FLAGS} ${cxx_base_flags} ${cxx_exception_flags}")
......
......@@ -15,7 +15,7 @@ assertions.
These three assertions do not actually test a value or expression. Instead,
they generate a success or failure directly. Like the macros that actually
perform a test, you may stream a custom failure message into the them.
perform a test, you may stream a custom failure message into them.
| `SUCCEED();` |
|:-------------|
......@@ -32,7 +32,7 @@ output in the future.
`FAIL()` generates a fatal failure, while `ADD_FAILURE()` and `ADD_FAILURE_AT()` generate a nonfatal
failure. These are useful when control flow, rather than a Boolean expression,
deteremines the test's success or failure. For example, you might want to write
determines the test's success or failure. For example, you might want to write
something like:
```
......@@ -128,7 +128,7 @@ c is 10<br>
1. If you see a compiler error "no matching function to call" when using `ASSERT_PRED*` or `EXPECT_PRED*`, please see [this FAQ](FAQ.md#the-compiler-complains-no-matching-function-to-call-when-i-use-assert_predn-how-do-i-fix-it) for how to resolve it.
1. Currently we only provide predicate assertions of arity <= 5. If you need a higher-arity assertion, let us know.
_Availability_: Linux, Windows, Mac
_Availability_: Linux, Windows, Mac.
### Using a Function That Returns an AssertionResult ###
......@@ -306,7 +306,7 @@ carefully choose the error bound. If they don't want or care to, comparing in
terms of Units in the Last Place (ULPs) is a good default, and Google Test
provides assertions to do this. Full details about ULPs are quite long; if you
want to learn more, see
[this article on float comparison](http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm).
[this article on float comparison](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/).
### Floating-Point Macros ###
......@@ -675,7 +675,7 @@ syntax only.
## How It Works ##
Under the hood, `ASSERT_EXIT()` spawns a new process and executes the
death test statement in that process. The details of of how precisely
death test statement in that process. The details of how precisely
that happens depend on the platform and the variable
`::testing::GTEST_FLAG(death_test_style)` (which is initialized from the
command-line flag `--gtest_death_test_style`).
......@@ -1344,7 +1344,7 @@ TYPED_TEST(FooTest, DoesBlah) {
TYPED_TEST(FooTest, HasPropertyA) { ... }
```
You can see `samples/sample6_unittest.cc` for a complete example.
You can see [`samples/sample6_unittest.cc`](../samples/sample6_unittest.cc) for a complete example.
_Availability:_ Linux, Windows (requires MSVC 8.0 or above), Mac;
since version 1.1.0.
......@@ -1444,7 +1444,7 @@ absolutely have to test non-public interface code though, you can. There are
two cases to consider:
* Static functions (_not_ the same as static member functions!) or unnamed namespaces, and
* Private or protected class members
* Private or protected class members.
## Static Functions ##
......@@ -1551,7 +1551,7 @@ exception, you could catch the exception and assert on it. But Google
Test doesn't use exceptions, so how do we test that a piece of code
generates an expected failure?
`"gtest/gtest-spi.h"` contains some constructs to do this. After
`"gtest/gtest-spi.h"` contains some constructs to do this. After
`#include`ing this header, you can use
| `EXPECT_FATAL_FAILURE(`_statement, substring_`);` |
......
......@@ -80,8 +80,8 @@ instructions for how to sign and return it.
## Coding Style ##
To keep the source consistent, readable, diffable and easy to merge,
we use a fairly rigid coding style, as defined by the [google-styleguide](http://code.google.com/p/google-styleguide/) project. All patches will be expected
to conform to the style outlined [here](http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml).
we use a fairly rigid coding style, as defined by the [google-styleguide](https://github.com/google/styleguide) project. All patches will be expected
to conform to the style outlined [here](https://google.github.io/styleguide/cppguide.html).
## Updating Generated Code ##
......
This page lists all documentation wiki pages for Google Test **(the SVN trunk version)**
-- **if you use a released version of Google Test, please read the
documentation for that specific version instead.**
This page lists all documentation markdown files for Google Test **(the
current git version)**
-- **if you use a former version of Google Test, please read the
documentation for that specific version instead (e.g. by checking out
the respective git branch/tag).**
* [Primer](Primer.md) -- start here if you are new to Google Test.
* [Samples](Samples.md) -- learn from examples.
......@@ -11,4 +13,4 @@ documentation for that specific version instead.**
To contribute code to Google Test, read:
* [DevGuide](DevGuide.md) -- read this _before_ writing your first patch.
* [PumpManual](PumpManual.md) -- how we generate some of Google Test's source files.
\ No newline at end of file
* [PumpManual](PumpManual.md) -- how we generate some of Google Test's source files.
......@@ -54,7 +54,7 @@ Underscore (`_`) is special, as C++ reserves the following to be used by
the compiler and the standard library:
1. any identifier that starts with an `_` followed by an upper-case letter, and
1. any identifier that containers two consecutive underscores (i.e. `__`) _anywhere_ in its name.
1. any identifier that contains two consecutive underscores (i.e. `__`) _anywhere_ in its name.
User code is _prohibited_ from using such identifiers.
......@@ -960,12 +960,11 @@ Have you read a
the Google Test Primer page?
## I want to use Google Test with Visual Studio but don't know where to start. ##
Many people are in your position and one of the posted his solution to
our mailing list.
Many people are in your position and one of them posted his solution to our mailing list.
## I am seeing compile errors mentioning std::type\_traits when I try to use Google Test on Solaris. ##
Google Test uses parts of the standard C++ library that SunStudio does not support.
Our users reported success using alternative implementations. Try running the build after runing this commad:
Our users reported success using alternative implementations. Try running the build after running this command:
`export CC=cc CXX=CC CXXFLAGS='-library=stlport4'`
......@@ -1015,7 +1014,7 @@ instead of
```
in order to define a test.
Currently, the following `TEST`, `FAIL`, `SUCCEED`, and the basic comparison assertion macros can have alternative names. You can see the full list of covered macros [here](http://www.google.com/codesearch?q=if+!GTEST_DONT_DEFINE_\w%2B+package:http://googletest\.googlecode\.com+file:/include/gtest/gtest.h). More information can be found in the "Avoiding Macro Name Clashes" section of the README file.
Currently, the following `TEST`, `FAIL`, `SUCCEED`, and the basic comparison assertion macros can have . You can see the full list of covered macros [here](../include/gtest/gtest.h). More information can be found in the "Avoiding Macro Name Clashes" section of the README file.
## Is it OK if I have two separate `TEST(Foo, Bar)` test methods defined in different namespaces? ##
......@@ -1061,6 +1060,12 @@ TEST_F(CoolTest, DoSomething) {
If you try to build Google Test's Xcode project with Xcode 4.0 or later, you may encounter an error message that looks like
"Missing SDK in target gtest\_framework: /Developer/SDKs/MacOSX10.4u.sdk". That means that Xcode does not support the SDK the project is targeting. See the Xcode section in the [README](../README.md) file on how to resolve this.
## How do I easily discover the flags needed for GoogleTest? ##
GoogleTest (and GoogleMock) now support discovering all necessary flags using pkg-config.
See the [pkg-config guide](Pkgconfig.md) on how you can easily discover all compiler and
linker flags using pkg-config.
## My question is not covered in your FAQ! ##
If you cannot find the answer to your question in this FAQ, there are
......
## Using GoogleTest from various build systems ##
GoogleTest comes with pkg-config files that can be used to determine all
necessary flags for compiling and linking to GoogleTest (and GoogleMock).
Pkg-config is a standardised plain-text format containing
* the includedir (-I) path
* necessary macro (-D) definitions
* further required flags (-pthread)
* the library (-L) path
* the library (-l) to link to
All current build systems support pkg-config in one way or another. For
all examples here we assume you want to compile the sample
`samples/sample3_unittest.cc`.
### CMake ###
Using `pkg-config` in CMake is fairly easy:
```
cmake_minimum_required(VERSION 3.0)
cmake_policy(SET CMP0048 NEW)
project(my_gtest_pkgconfig VERSION 0.0.1 LANGUAGES CXX)
find_package(PkgConfig)
pkg_search_module(GTEST REQUIRED gtest_main)
add_executable(testapp samples/sample3_unittest.cc)
target_link_libraries(testapp ${GTEST_LDFLAGS})
target_compile_options(testapp PUBLIC ${GTEST_CFLAGS})
include(CTest)
add_test(first_and_only_test testapp)
```
It is generally recommended that you use `target_compile_options` + `_CFLAGS`
over `target_include_directories` + `_INCLUDE_DIRS` as the former includes not
just -I flags (GoogleTest might require a macro indicating to internal headers
that all libraries have been compiled with threading enabled. In addition,
GoogleTest might also require `-pthread` in the compiling step, and as such
splitting the pkg-config `Cflags` variable into include dirs and macros for
`target_compile_definitions()` might still miss this). The same recommendation
goes for using `_LDFLAGS` over the more commonplace `_LIBRARIES`, which
happens to discard `-L` flags and `-pthread`.
### Autotools ###
Finding GoogleTest in Autoconf and using it from Automake is also fairly easy:
In your `configure.ac`:
```
AC_PREREQ([2.69])
AC_INIT([my_gtest_pkgconfig], [0.0.1])
AC_CONFIG_SRCDIR([samples/sample3_unittest.cc])
AC_PROG_CXX
PKG_CHECK_MODULES([GTEST], [gtest_main])
AM_INIT_AUTOMAKE([foreign subdir-objects])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
```
and in your `Makefile.am`:
```
check_PROGRAMS = testapp
TESTS = $(check_PROGRAMS)
testapp_SOURCES = samples/sample3_unittest.cc
testapp_CXXFLAGS = $(GTEST_CFLAGS)
testapp_LDADD = $(GTEST_LIBS)
```
### Meson ###
Meson natively uses pkgconfig to query dependencies:
```
project('my_gtest_pkgconfig', 'cpp', version : '0.0.1')
gtest_dep = dependency('gtest_main')
testapp = executable(
'testapp',
files(['samples/sample3_unittest.cc']),
dependencies : gtest_dep,
install : false)
test('first_and_only_test', testapp)
```
### Plain Makefiles ###
Since `pkg-config` is a small Unix command-line utility, it can be used
in handwritten `Makefile`s too:
```
GTEST_CFLAGS = `pkg-config --cflags gtest_main`
GTEST_LIBS = `pkg-config --libs gtest_main`
.PHONY: tests all
tests: all
./testapp
all: testapp
testapp: testapp.o
$(CXX) $(CXXFLAGS) $(LDFLAGS) $< -o $@ $(GTEST_LIBS)
testapp.o: samples/sample3_unittest.cc
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $< -c -o $@ $(GTEST_CFLAGS)
```
### Help! pkg-config can't find GoogleTest! ###
Let's say you have a `CMakeLists.txt` along the lines of the one in this
tutorial and you try to run `cmake`. It is very possible that you get a
failure along the lines of:
```
-- Checking for one of the modules 'gtest_main'
CMake Error at /usr/share/cmake/Modules/FindPkgConfig.cmake:640 (message):
None of the required 'gtest_main' found
```
These failures are common if you installed GoogleTest yourself and have not
sourced it from a distro or other package manager. If so, you need to tell
pkg-config where it can find the `.pc` files containing the information.
Say you installed GoogleTest to `/usr/local`, then it might be that the
`.pc` files are installed under `/usr/local/lib64/pkgconfig`. If you set
```
export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig
```
pkg-config will also try to look in `PKG_CONFIG_PATH` to find `gtest_main.pc`.
......@@ -23,6 +23,40 @@ So let's go!
_Note:_ We sometimes refer to Google C++ Testing Framework informally
as _Google Test_.
# Beware of the nomenclature #
_Note:_ There might be some confusion of idea due to different
definitions of the terms _Test_, _Test Case_ and _Test Suite_, so beware
of misunderstanding these.
Historically, the Google C++ Testing Framework started to use the term
_Test Case_ for grouping related tests, whereas current publications
including the International Software Testing Qualifications Board
([ISTQB](http://www.istqb.org/)) and various textbooks on Software
Quality use the term _[Test
Suite](http://glossary.istqb.org/search/test%20suite)_ for this.
The related term _Test_, as it is used in the Google C++ Testing
Framework, is corresponding to the term _[Test
Case](http://glossary.istqb.org/search/test%20case)_ of ISTQB and
others.
The term _Test_ is commonly of broad enough sense, including ISTQB's
definition of _Test Case_, so it's not much of a problem here. But the
term _Test Case_ as used in Google Test is of contradictory sense and thus confusing.
Unfortunately replacing the term _Test Case_ by _Test Suite_ throughout
the Google C++ Testing Framework is not easy without breaking dependent
projects, as `TestCase` is part of the public API at various places.
So for the time being, please be aware of the different definitions of
the terms:
Meaning | Google Test Term | [ISTQB](http://www.istqb.org/) Term
------- | ---------------- | -----------------------------------
Exercise a particular program path with specific input values and verify the results | [TEST()](#simple-tests) | [Test Case](http://glossary.istqb.org/search/test%20case)
A set of several tests related to one component | [Test Case](#basic-concepts) | [Test Suite](http://glossary.istqb.org/search/test%20suite)
# Setting up a New Test Project #
To write a test program using Google Test, you need to compile Google
......@@ -179,7 +213,7 @@ two `string` objects, use `EXPECT_EQ`, `EXPECT_NE`, and etc instead.
| **Fatal assertion** | **Nonfatal assertion** | **Verifies** |
|:--------------------|:-----------------------|:-------------|
| `ASSERT_STREQ(`_str1_`, `_str2_`);` | `EXPECT_STREQ(`_str1_`, `_str_2`);` | the two C strings have the same content |
| `ASSERT_STREQ(`_str1_`, `_str2_`);` | `EXPECT_STREQ(`_str1_`, `_str2_`);` | the two C strings have the same content |
| `ASSERT_STRNE(`_str1_`, `_str2_`);` | `EXPECT_STRNE(`_str1_`, `_str2_`);` | the two C strings have different content |
| `ASSERT_STRCASEEQ(`_str1_`, `_str2_`);`| `EXPECT_STRCASEEQ(`_str1_`, `_str2_`);` | the two C strings have the same content, ignoring case |
| `ASSERT_STRCASENE(`_str1_`, `_str2_`);`| `EXPECT_STRCASENE(`_str1_`, `_str2_`);` | the two C strings have different content, ignoring case |
......@@ -281,7 +315,7 @@ declaration`".
For each test defined with `TEST_F()`, Google Test will:
1. Create a _fresh_ test fixture at runtime
1. Immediately initialize it via `SetUp()` ,
1. Immediately initialize it via `SetUp()`
1. Run the test
1. Clean up by calling `TearDown()`
1. Delete the test fixture. Note that different tests in the same test case have different test fixture objects, and Google Test always deletes a test fixture before it creates the next one. Google Test does not reuse the same test fixture for multiple tests. Any changes one test makes to the fixture do not affect other tests.
......@@ -382,7 +416,7 @@ When invoked, the `RUN_ALL_TESTS()` macro:
1. Restores the state of all Google Test flags.
1. Repeats the above steps for the next test, until all tests have run.
In addition, if the text fixture's constructor generates a fatal failure in
In addition, if the test fixture's constructor generates a fatal failure in
step 2, there is no point for step 3 - 5 and they are thus skipped. Similarly,
if step 3 generates a fatal failure, step 4 will be skipped.
......
......@@ -169,7 +169,7 @@ improving Pump.
## Real Examples ##
You can find real-world applications of Pump in [Google Test](http://www.google.com/codesearch?q=file%3A\.pump%24+package%3Ahttp%3A%2F%2Fgoogletest\.googlecode\.com) and [Google Mock](http://www.google.com/codesearch?q=file%3A\.pump%24+package%3Ahttp%3A%2F%2Fgooglemock\.googlecode\.com). The source file `foo.h.pump` generates `foo.h`.
You can find real-world applications of Pump in [Google Test](https://github.com/google/googletest/tree/master/googletest) and [Google Mock](https://github.com/google/googletest/tree/master/googlemock). The source file `foo.h.pump` generates `foo.h`.
## Tips ##
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment