summaryrefslogtreecommitdiffstats
path: root/googletest/test/gtest_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'googletest/test/gtest_unittest.cc')
-rw-r--r--googletest/test/gtest_unittest.cc1097
1 files changed, 445 insertions, 652 deletions
diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc
index 97fcd5a..c6280ca 100644
--- a/googletest/test/gtest_unittest.cc
+++ b/googletest/test/gtest_unittest.cc
@@ -26,17 +26,16 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-// Author: wan@google.com (Zhanyong Wan)
+
//
// Tests for Google Test itself. This verifies that the basic constructs of
// Google Test work.
#include "gtest/gtest.h"
-// Verifies that the command line flag variables can be accessed
-// in code once <gtest/gtest.h> has been #included.
-// Do not move it after other #includes.
+// 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.
TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) {
bool dummy = testing::GTEST_FLAG(also_run_disabled_tests)
|| testing::GTEST_FLAG(break_on_failure)
@@ -64,17 +63,10 @@ TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) {
#include <map>
#include <vector>
#include <ostream>
+#include <unordered_set>
#include "gtest/gtest-spi.h"
-
-// Indicates that this translation unit is part of Google Test's
-// implementation. It must come before gtest-internal-inl.h is
-// included, or there will be a compiler error. This trick is to
-// prevent a user from accidentally including gtest-internal-inl.h in
-// his code.
-#define GTEST_IMPLEMENTATION_ 1
#include "src/gtest-internal-inl.h"
-#undef GTEST_IMPLEMENTATION_
namespace testing {
namespace internal {
@@ -86,19 +78,19 @@ class StreamingListenerTest : public Test {
class FakeSocketWriter : public StreamingListener::AbstractSocketWriter {
public:
// Sends a string to the socket.
- virtual void Send(const string& message) { output_ += message; }
+ virtual void Send(const std::string& message) { output_ += message; }
- string output_;
+ std::string output_;
};
StreamingListenerTest()
: fake_sock_writer_(new FakeSocketWriter),
streamer_(fake_sock_writer_),
- test_info_obj_("FooTest", "Bar", NULL, NULL,
- CodeLocation(__FILE__, __LINE__), 0, NULL) {}
+ test_info_obj_("FooTest", "Bar", nullptr, nullptr,
+ CodeLocation(__FILE__, __LINE__), nullptr, nullptr) {}
protected:
- string* output() { return &(fake_sock_writer_->output_); }
+ std::string* output() { return &(fake_sock_writer_->output_); }
FakeSocketWriter* const fake_sock_writer_;
StreamingListener streamer_;
@@ -120,13 +112,13 @@ TEST_F(StreamingListenerTest, OnTestIterationEnd) {
TEST_F(StreamingListenerTest, OnTestCaseStart) {
*output() = "";
- streamer_.OnTestCaseStart(TestCase("FooTest", "Bar", NULL, NULL));
+ streamer_.OnTestCaseStart(TestCase("FooTest", "Bar", nullptr, nullptr));
EXPECT_EQ("event=TestCaseStart&name=FooTest\n", *output());
}
TEST_F(StreamingListenerTest, OnTestCaseEnd) {
*output() = "";
- streamer_.OnTestCaseEnd(TestCase("FooTest", "Bar", NULL, NULL));
+ streamer_.OnTestCaseEnd(TestCase("FooTest", "Bar", nullptr, nullptr));
EXPECT_EQ("event=TestCaseEnd&passed=1&elapsed_time=0ms\n", *output());
}
@@ -266,6 +258,8 @@ using testing::internal::IsContainer;
using testing::internal::IsContainerTest;
using testing::internal::IsNotContainer;
using testing::internal::NativeArray;
+using testing::internal::OsStackTraceGetter;
+using testing::internal::OsStackTraceGetterInterface;
using testing::internal::ParseInt32Flag;
using testing::internal::RelationToSourceCopy;
using testing::internal::RelationToSourceReference;
@@ -282,6 +276,7 @@ using testing::internal::String;
using testing::internal::TestEventListenersAccessor;
using testing::internal::TestResultAccessor;
using testing::internal::UInt32;
+using testing::internal::UnitTestImpl;
using testing::internal::WideStringToUtf8;
using testing::internal::edit_distance::CalculateOptimalEdits;
using testing::internal::edit_distance::CreateUnifiedDiff;
@@ -382,6 +377,31 @@ TEST(GetTestTypeIdTest, ReturnsTheSameValueInsideOrOutsideOfGoogleTest) {
EXPECT_EQ(kTestTypeIdInGoogleTest, GetTestTypeId());
}
+// Tests CanonicalizeForStdLibVersioning.
+
+using ::testing::internal::CanonicalizeForStdLibVersioning;
+
+TEST(CanonicalizeForStdLibVersioning, LeavesUnversionedNamesUnchanged) {
+ EXPECT_EQ("std::bind", CanonicalizeForStdLibVersioning("std::bind"));
+ EXPECT_EQ("std::_", CanonicalizeForStdLibVersioning("std::_"));
+ EXPECT_EQ("std::__foo", CanonicalizeForStdLibVersioning("std::__foo"));
+ EXPECT_EQ("gtl::__1::x", CanonicalizeForStdLibVersioning("gtl::__1::x"));
+ EXPECT_EQ("__1::x", CanonicalizeForStdLibVersioning("__1::x"));
+ EXPECT_EQ("::__1::x", CanonicalizeForStdLibVersioning("::__1::x"));
+}
+
+TEST(CanonicalizeForStdLibVersioning, ElidesDoubleUnderNames) {
+ EXPECT_EQ("std::bind", CanonicalizeForStdLibVersioning("std::__1::bind"));
+ EXPECT_EQ("std::_", CanonicalizeForStdLibVersioning("std::__1::_"));
+
+ EXPECT_EQ("std::bind", CanonicalizeForStdLibVersioning("std::__g::bind"));
+ EXPECT_EQ("std::_", CanonicalizeForStdLibVersioning("std::__g::_"));
+
+ EXPECT_EQ("std::bind",
+ CanonicalizeForStdLibVersioning("std::__google::bind"));
+ EXPECT_EQ("std::_", CanonicalizeForStdLibVersioning("std::__google::_"));
+}
+
// Tests FormatTimeInMillisAsSeconds().
TEST(FormatTimeInMillisAsSecondsTest, FormatsZero) {
@@ -419,12 +439,12 @@ class FormatEpochTimeInMillisAsIso8601Test : public Test {
private:
virtual void SetUp() {
- saved_tz_ = NULL;
+ saved_tz_ = nullptr;
- GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996 /* getenv, strdup: deprecated */)
+ GTEST_DISABLE_MSC_DEPRECATED_PUSH_(/* getenv, strdup: deprecated */)
if (getenv("TZ"))
saved_tz_ = strdup(getenv("TZ"));
- GTEST_DISABLE_MSC_WARNINGS_POP_()
+ GTEST_DISABLE_MSC_DEPRECATED_POP_()
// Set up the time zone for FormatEpochTimeInMillisAsIso8601 to use. We
// cannot use the local time zone because the function's output depends
@@ -435,7 +455,7 @@ class FormatEpochTimeInMillisAsIso8601Test : public Test {
virtual void TearDown() {
SetTimeZone(saved_tz_);
free(const_cast<char*>(saved_tz_));
- saved_tz_ = NULL;
+ saved_tz_ = nullptr;
}
static void SetTimeZone(const char* time_zone) {
@@ -501,10 +521,10 @@ TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsEpochStart) {
// Tests that GTEST_IS_NULL_LITERAL_(x) is true when x is a null
// pointer literal.
TEST(NullLiteralTest, IsTrueForNullLiterals) {
- EXPECT_TRUE(GTEST_IS_NULL_LITERAL_(NULL));
- EXPECT_TRUE(GTEST_IS_NULL_LITERAL_(0));
- EXPECT_TRUE(GTEST_IS_NULL_LITERAL_(0U));
- EXPECT_TRUE(GTEST_IS_NULL_LITERAL_(0L));
+ EXPECT_TRUE(GTEST_IS_NULL_LITERAL_(nullptr));
+ EXPECT_TRUE(GTEST_IS_NULL_LITERAL_(nullptr));
+ EXPECT_TRUE(GTEST_IS_NULL_LITERAL_(nullptr));
+ EXPECT_TRUE(GTEST_IS_NULL_LITERAL_(nullptr));
}
// Tests that GTEST_IS_NULL_LITERAL_(x) is false when x is not a null
@@ -513,7 +533,7 @@ TEST(NullLiteralTest, IsFalseForNonNullLiterals) {
EXPECT_FALSE(GTEST_IS_NULL_LITERAL_(1));
EXPECT_FALSE(GTEST_IS_NULL_LITERAL_(0.0));
EXPECT_FALSE(GTEST_IS_NULL_LITERAL_('a'));
- EXPECT_FALSE(GTEST_IS_NULL_LITERAL_(static_cast<void*>(NULL)));
+ EXPECT_FALSE(GTEST_IS_NULL_LITERAL_(static_cast<void*>(nullptr)));
}
# ifdef __BORLANDC__
@@ -546,7 +566,7 @@ TEST(CodePointToUtf8Test, CanEncode8To11Bits) {
// 101 0111 0110 => 110-10101 10-110110
// Some compilers (e.g., GCC on MinGW) cannot handle non-ASCII codepoints
- // in wide strings and wide chars. In order to accomodate them, we have to
+ // in wide strings and wide chars. In order to accommodate them, we have to
// introduce such character constants as integers.
EXPECT_EQ("\xD5\xB6",
CodePointToUtf8(static_cast<wchar_t>(0x576)));
@@ -1012,11 +1032,11 @@ TEST(StringTest, EndsWithCaseInsensitive) {
// C++Builder's preprocessor is buggy; it fails to expand macros that
// appear in macro parameters after wide char literals. Provide an alias
// for NULL as a workaround.
-static const wchar_t* const kNull = NULL;
+static const wchar_t* const kNull = nullptr;
// Tests String::CaseInsensitiveWideCStringEquals
TEST(StringTest, CaseInsensitiveWideCStringEquals) {
- EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(NULL, NULL));
+ EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(nullptr, nullptr));
EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(kNull, L""));
EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(L"", kNull));
EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(kNull, L"foobar"));
@@ -1137,7 +1157,7 @@ class ScopedFakeTestPartResultReporterWithThreadsTest
: public ScopedFakeTestPartResultReporterTest {
protected:
static void AddFailureInOtherThread(FailureMode failure) {
- ThreadWithParam<FailureMode> thread(&AddFailure, failure, NULL);
+ ThreadWithParam<FailureMode> thread(&AddFailure, failure, nullptr);
thread.Join();
}
};
@@ -1362,8 +1382,7 @@ class TestResultTest : public Test {
// In order to test TestResult, we need to modify its internal
// state, in particular the TestPartResult vector it holds.
// test_part_results() returns a const reference to this vector.
- // We cast it to a non-const object s.t. it can be modified (yes,
- // this is a hack).
+ // We cast it to a non-const object s.t. it can be modified
TPRVector* results1 = const_cast<TPRVector*>(
&TestResultAccessor::test_part_results(*r1));
TPRVector* results2 = const_cast<TPRVector*>(
@@ -1388,7 +1407,7 @@ class TestResultTest : public Test {
delete r2;
}
- // Helper that compares two two TestPartResults.
+ // Helper that compares two TestPartResults.
static void CompareTestPartResult(const TestPartResult& expected,
const TestPartResult& actual) {
EXPECT_EQ(expected.type(), actual.type());
@@ -1559,7 +1578,7 @@ class GTestFlagSaverTest : public Test {
// be called after the last test in this test case is run.
static void TearDownTestCase() {
delete saver_;
- saver_ = NULL;
+ saver_ = nullptr;
}
// Verifies that the Google Test flags have their default values, and then
@@ -1603,7 +1622,7 @@ class GTestFlagSaverTest : public Test {
static GTestFlagSaver* saver_;
};
-GTestFlagSaver* GTestFlagSaverTest::saver_ = NULL;
+GTestFlagSaver* GTestFlagSaverTest::saver_ = nullptr;
// Google Test doesn't guarantee the order of tests. The following two
// tests are designed to work regardless of their order.
@@ -1787,7 +1806,7 @@ TEST(Int32FromEnvOrDieDeathTest, AbortsOnFailure) {
}
// Tests that Int32FromEnvOrDie() aborts with an error message
-// if the variable cannot be represnted by an Int32.
+// if the variable cannot be represented by an Int32.
TEST(Int32FromEnvOrDieDeathTest, AbortsOnInt32Overflow) {
SetEnv(GTEST_FLAG_PREFIX_UPPER_ "VAR", "1234567891234567891234");
EXPECT_DEATH_IF_SUPPORTED(
@@ -1928,7 +1947,7 @@ TEST(ShouldRunTestOnShardTest, IsPartitionWhenThereAreFiveShards) {
// TEST, TEST_F, RUN_ALL_TESTS
TEST(UnitTestTest, CanGetOriginalWorkingDir) {
- ASSERT_TRUE(UnitTest::GetInstance()->original_working_dir() != NULL);
+ ASSERT_TRUE(UnitTest::GetInstance()->original_working_dir() != nullptr);
EXPECT_STRNE(UnitTest::GetInstance()->original_working_dir(), "");
}
@@ -1950,7 +1969,7 @@ void ExpectNonFatalFailureRecordingPropertyWithReservedKey(
void ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
const char* key) {
const TestInfo* test_info = UnitTest::GetInstance()->current_test_info();
- ASSERT_TRUE(test_info != NULL);
+ ASSERT_TRUE(test_info != nullptr);
ExpectNonFatalFailureRecordingPropertyWithReservedKey(*test_info->result(),
key);
}
@@ -1958,7 +1977,7 @@ void ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
void ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestCase(
const char* key) {
const TestCase* test_case = UnitTest::GetInstance()->current_test_case();
- ASSERT_TRUE(test_case != NULL);
+ ASSERT_TRUE(test_case != nullptr);
ExpectNonFatalFailureRecordingPropertyWithReservedKey(
test_case->ad_hoc_test_result(), key);
}
@@ -1991,7 +2010,7 @@ class UnitTestRecordPropertyTest :
Test::RecordProperty("test_case_key_1", "1");
const TestCase* test_case = UnitTest::GetInstance()->current_test_case();
- ASSERT_TRUE(test_case != NULL);
+ ASSERT_TRUE(test_case != nullptr);
ASSERT_EQ(1, test_case->ad_hoc_test_result().test_property_count());
EXPECT_STREQ("test_case_key_1",
@@ -2069,8 +2088,8 @@ TEST_F(UnitTestRecordPropertyTest,
AddRecordWithReservedKeysGeneratesCorrectPropertyList) {
EXPECT_NONFATAL_FAILURE(
Test::RecordProperty("name", "1"),
- "'classname', 'name', 'status', 'time', 'type_param', and 'value_param'"
- " are reserved");
+ "'classname', 'name', 'status', 'time', 'type_param', 'value_param',"
+ " 'file', and 'line' are reserved");
}
class UnitTestRecordPropertyTestEnvironment : public Environment {
@@ -2096,7 +2115,7 @@ class UnitTestRecordPropertyTestEnvironment : public Environment {
};
// This will test property recording outside of any test or test case.
-static Environment* record_property_env =
+static Environment* record_property_env GTEST_ATTRIBUTE_UNUSED_ =
AddGlobalTestEnvironment(new UnitTestRecordPropertyTestEnvironment);
// This group of tests is for predicate assertions (ASSERT_PRED*, etc)
@@ -2430,29 +2449,27 @@ TEST(StringAssertionTest, ASSERT_STREQ) {
ASSERT_STREQ(p1, p2);
EXPECT_FATAL_FAILURE(ASSERT_STREQ("bad", "good"),
- "Expected: \"bad\"");
+ " \"bad\"\n \"good\"");
}
// Tests ASSERT_STREQ with NULL arguments.
TEST(StringAssertionTest, ASSERT_STREQ_Null) {
- ASSERT_STREQ(static_cast<const char *>(NULL), NULL);
- EXPECT_FATAL_FAILURE(ASSERT_STREQ(NULL, "non-null"),
- "non-null");
+ ASSERT_STREQ(static_cast<const char*>(nullptr), nullptr);
+ EXPECT_FATAL_FAILURE(ASSERT_STREQ(nullptr, "non-null"), "non-null");
}
// Tests ASSERT_STREQ with NULL arguments.
TEST(StringAssertionTest, ASSERT_STREQ_Null2) {
- EXPECT_FATAL_FAILURE(ASSERT_STREQ("non-null", NULL),
- "non-null");
+ EXPECT_FATAL_FAILURE(ASSERT_STREQ("non-null", nullptr), "non-null");
}
// Tests ASSERT_STRNE.
TEST(StringAssertionTest, ASSERT_STRNE) {
ASSERT_STRNE("hi", "Hi");
- ASSERT_STRNE("Hi", NULL);
- ASSERT_STRNE(NULL, "Hi");
- ASSERT_STRNE("", NULL);
- ASSERT_STRNE(NULL, "");
+ ASSERT_STRNE("Hi", nullptr);
+ ASSERT_STRNE(nullptr, "Hi");
+ ASSERT_STRNE("", nullptr);
+ ASSERT_STRNE(nullptr, "");
ASSERT_STRNE("", "Hi");
ASSERT_STRNE("Hi", "");
EXPECT_FATAL_FAILURE(ASSERT_STRNE("Hi", "Hi"),
@@ -2462,7 +2479,7 @@ TEST(StringAssertionTest, ASSERT_STRNE) {
// Tests ASSERT_STRCASEEQ.
TEST(StringAssertionTest, ASSERT_STRCASEEQ) {
ASSERT_STRCASEEQ("hi", "Hi");
- ASSERT_STRCASEEQ(static_cast<const char *>(NULL), NULL);
+ ASSERT_STRCASEEQ(static_cast<const char*>(nullptr), nullptr);
ASSERT_STRCASEEQ("", "");
EXPECT_FATAL_FAILURE(ASSERT_STRCASEEQ("Hi", "hi2"),
@@ -2472,10 +2489,10 @@ TEST(StringAssertionTest, ASSERT_STRCASEEQ) {
// Tests ASSERT_STRCASENE.
TEST(StringAssertionTest, ASSERT_STRCASENE) {
ASSERT_STRCASENE("hi1", "Hi2");
- ASSERT_STRCASENE("Hi", NULL);
- ASSERT_STRCASENE(NULL, "Hi");
- ASSERT_STRCASENE("", NULL);
- ASSERT_STRCASENE(NULL, "");
+ ASSERT_STRCASENE("Hi", nullptr);
+ ASSERT_STRCASENE(nullptr, "Hi");
+ ASSERT_STRCASENE("", nullptr);
+ ASSERT_STRCASENE(nullptr, "");
ASSERT_STRCASENE("", "Hi");
ASSERT_STRCASENE("Hi", "");
EXPECT_FATAL_FAILURE(ASSERT_STRCASENE("Hi", "hi"),
@@ -2485,14 +2502,13 @@ TEST(StringAssertionTest, ASSERT_STRCASENE) {
// Tests *_STREQ on wide strings.
TEST(StringAssertionTest, STREQ_Wide) {
// NULL strings.
- ASSERT_STREQ(static_cast<const wchar_t *>(NULL), NULL);
+ ASSERT_STREQ(static_cast<const wchar_t*>(nullptr), nullptr);
// Empty strings.
ASSERT_STREQ(L"", L"");
// Non-null vs NULL.
- EXPECT_NONFATAL_FAILURE(EXPECT_STREQ(L"non-null", NULL),
- "non-null");
+ EXPECT_NONFATAL_FAILURE(EXPECT_STREQ(L"non-null", nullptr), "non-null");
// Equal strings.
EXPECT_STREQ(L"Hi", L"Hi");
@@ -2514,16 +2530,18 @@ TEST(StringAssertionTest, STREQ_Wide) {
// Tests *_STRNE on wide strings.
TEST(StringAssertionTest, STRNE_Wide) {
// NULL strings.
- EXPECT_NONFATAL_FAILURE({ // NOLINT
- EXPECT_STRNE(static_cast<const wchar_t *>(NULL), NULL);
- }, "");
+ EXPECT_NONFATAL_FAILURE(
+ { // NOLINT
+ EXPECT_STRNE(static_cast<const wchar_t*>(nullptr), nullptr);
+ },
+ "");
// Empty strings.
EXPECT_NONFATAL_FAILURE(EXPECT_STRNE(L"", L""),
"L\"\"");
// Non-null vs NULL.
- ASSERT_STRNE(L"non-null", NULL);
+ ASSERT_STRNE(L"non-null", nullptr);
// Equal strings.
EXPECT_NONFATAL_FAILURE(EXPECT_STRNE(L"Hi", L"Hi"),
@@ -2545,11 +2563,11 @@ TEST(StringAssertionTest, STRNE_Wide) {
// Tests that IsSubstring() returns the correct result when the input
// argument type is const char*.
TEST(IsSubstringTest, ReturnsCorrectResultForCString) {
- EXPECT_FALSE(IsSubstring("", "", NULL, "a"));
- EXPECT_FALSE(IsSubstring("", "", "b", NULL));
+ EXPECT_FALSE(IsSubstring("", "", nullptr, "a"));
+ EXPECT_FALSE(IsSubstring("", "", "b", nullptr));
EXPECT_FALSE(IsSubstring("", "", "needle", "haystack"));
- EXPECT_TRUE(IsSubstring("", "", static_cast<const char*>(NULL), NULL));
+ EXPECT_TRUE(IsSubstring("", "", static_cast<const char*>(nullptr), nullptr));
EXPECT_TRUE(IsSubstring("", "", "needle", "two needles"));
}
@@ -2560,7 +2578,8 @@ TEST(IsSubstringTest, ReturnsCorrectResultForWideCString) {
EXPECT_FALSE(IsSubstring("", "", L"b", kNull));
EXPECT_FALSE(IsSubstring("", "", L"needle", L"haystack"));
- EXPECT_TRUE(IsSubstring("", "", static_cast<const wchar_t*>(NULL), NULL));
+ EXPECT_TRUE(
+ IsSubstring("", "", static_cast<const wchar_t*>(nullptr), nullptr));
EXPECT_TRUE(IsSubstring("", "", L"needle", L"two needles"));
}
@@ -3115,13 +3134,13 @@ TEST(DISABLED_TestCase, DISABLED_TestShouldNotRun) {
FAIL() << "Unexpected failure: Test in disabled test case should not be run.";
}
-// Check that when all tests in a test case are disabled, SetupTestCase() and
+// Check that when all tests in a test case are disabled, SetUpTestCase() and
// TearDownTestCase() are not called.
class DisabledTestsTest : public Test {
protected:
static void SetUpTestCase() {
FAIL() << "Unexpected failure: All tests disabled in test case. "
- "SetupTestCase() should not be called.";
+ "SetUpTestCase() should not be called.";
}
static void TearDownTestCase() {
@@ -3368,7 +3387,7 @@ class NoFatalFailureTest : public Test {
void DoAssertNoFatalFailureOnFails() {
ASSERT_NO_FATAL_FAILURE(Fails());
- ADD_FAILURE() << "shold not reach here.";
+ ADD_FAILURE() << "should not reach here.";
}
void DoExpectNoFatalFailureOnFails() {
@@ -3528,35 +3547,39 @@ TEST(AssertionTest, EqFailure) {
EqFailure("foo", "bar", foo_val, bar_val, false)
.failure_message());
EXPECT_STREQ(
- " Expected: foo\n"
- " Which is: 5\n"
- "To be equal to: bar\n"
- " Which is: 6",
+ "Expected equality of these values:\n"
+ " foo\n"
+ " Which is: 5\n"
+ " bar\n"
+ " Which is: 6",
msg1.c_str());
const std::string msg2(
EqFailure("foo", "6", foo_val, bar_val, false)
.failure_message());
EXPECT_STREQ(
- " Expected: foo\n"
- " Which is: 5\n"
- "To be equal to: 6",
+ "Expected equality of these values:\n"
+ " foo\n"
+ " Which is: 5\n"
+ " 6",
msg2.c_str());
const std::string msg3(
EqFailure("5", "bar", foo_val, bar_val, false)
.failure_message());
EXPECT_STREQ(
- " Expected: 5\n"
- "To be equal to: bar\n"
- " Which is: 6",
+ "Expected equality of these values:\n"
+ " 5\n"
+ " bar\n"
+ " Which is: 6",
msg3.c_str());
const std::string msg4(
EqFailure("5", "6", foo_val, bar_val, false).failure_message());
EXPECT_STREQ(
- " Expected: 5\n"
- "To be equal to: 6",
+ "Expected equality of these values:\n"
+ " 5\n"
+ " 6",
msg4.c_str());
const std::string msg5(
@@ -3564,10 +3587,11 @@ TEST(AssertionTest, EqFailure) {
std::string("\"x\""), std::string("\"y\""),
true).failure_message());
EXPECT_STREQ(
- " Expected: foo\n"
- " Which is: \"x\"\n"
- "To be equal to: bar\n"
- " Which is: \"y\"\n"
+ "Expected equality of these values:\n"
+ " foo\n"
+ " Which is: \"x\"\n"
+ " bar\n"
+ " Which is: \"y\"\n"
"Ignoring case",
msg5.c_str());
}
@@ -3580,11 +3604,12 @@ TEST(AssertionTest, EqFailureWithDiff) {
const std::string msg1(
EqFailure("left", "right", left, right, false).failure_message());
EXPECT_STREQ(
- " Expected: left\n"
- " Which is: "
+ "Expected equality of these values:\n"
+ " left\n"
+ " Which is: "
"1\\n2XXX\\n3\\n5\\n6\\n7\\n8\\n9\\n10\\n11\\n12XXX\\n13\\n14\\n15\n"
- "To be equal to: right\n"
- " Which is: 1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n11\\n12\\n13\\n14\n"
+ " right\n"
+ " Which is: 1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n11\\n12\\n13\\n14\n"
"With diff:\n@@ -1,5 +1,6 @@\n 1\n-2XXX\n+2\n 3\n+4\n 5\n 6\n"
"@@ -7,8 +8,6 @@\n 8\n 9\n-10\n 11\n-12XXX\n+12\n 13\n 14\n-15\n",
msg1.c_str());
@@ -3659,7 +3684,7 @@ TEST(AssertionTest, AssertFalseWithAssertionResult) {
}
#ifdef __BORLANDC__
-// Restores warnings after previous "#pragma option push" supressed them
+// Restores warnings after previous "#pragma option push" suppressed them
# pragma option pop
#endif
@@ -3679,26 +3704,26 @@ TEST(ExpectTest, ASSERT_EQ_Double) {
TEST(AssertionTest, ASSERT_EQ) {
ASSERT_EQ(5, 2 + 3);
EXPECT_FATAL_FAILURE(ASSERT_EQ(5, 2*3),
- " Expected: 5\n"
- "To be equal to: 2*3\n"
- " Which is: 6");
+ "Expected equality of these values:\n"
+ " 5\n"
+ " 2*3\n"
+ " Which is: 6");
}
// Tests ASSERT_EQ(NULL, pointer).
#if GTEST_CAN_COMPARE_NULL
TEST(AssertionTest, ASSERT_EQ_NULL) {
// A success.
- const char* p = NULL;
- // Some older GCC versions may issue a spurious waring in this or the next
+ const char* p = nullptr;
+ // Some older GCC versions may issue a spurious warning in this or the next
// assertion statement. This warning should not be suppressed with
// static_cast since the test verifies the ability to use bare NULL as the
// expected parameter to the macro.
- ASSERT_EQ(NULL, p);
+ ASSERT_EQ(nullptr, p);
// A failure.
static int n = 0;
- EXPECT_FATAL_FAILURE(ASSERT_EQ(NULL, &n),
- "To be equal to: &n\n");
+ EXPECT_FATAL_FAILURE(ASSERT_EQ(nullptr, &n), " &n\n Which is:");
}
#endif // GTEST_CAN_COMPARE_NULL
@@ -3714,7 +3739,7 @@ TEST(ExpectTest, ASSERT_EQ_0) {
// A failure.
EXPECT_FATAL_FAILURE(ASSERT_EQ(0, 5.6),
- "Expected: 0");
+ " 0\n 5.6");
}
// Tests ASSERT_NE.
@@ -3813,7 +3838,7 @@ void TestEq1(int x) {
// Tests calling a test subroutine that's not part of a fixture.
TEST(AssertionTest, NonFixtureSubroutine) {
EXPECT_FATAL_FAILURE(TestEq1(2),
- "To be equal to: x");
+ " x\n Which is: 2");
}
// An uncopyable class.
@@ -3862,7 +3887,8 @@ TEST(AssertionTest, AssertWorksWithUncopyableObject) {
EXPECT_FATAL_FAILURE(TestAssertNonPositive(),
"IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1");
EXPECT_FATAL_FAILURE(TestAssertEqualsUncopyable(),
- "Expected: x\n Which is: 5\nTo be equal to: y\n Which is: -1");
+ "Expected equality of these values:\n"
+ " x\n Which is: 5\n y\n Which is: -1");
}
// Tests that uncopyable objects can be used in expects.
@@ -3874,7 +3900,8 @@ TEST(AssertionTest, ExpectWorksWithUncopyableObject) {
"IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1");
EXPECT_EQ(x, x);
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(x, y),
- "Expected: x\n Which is: 5\nTo be equal to: y\n Which is: -1");
+ "Expected equality of these values:\n"
+ " x\n Which is: 5\n y\n Which is: -1");
}
enum NamedEnum {
@@ -3950,13 +3977,13 @@ TEST(AssertionTest, AnonymousEnum) {
// ICE's in C++Builder.
EXPECT_FATAL_FAILURE(ASSERT_EQ(kCaseA, kCaseB),
- "To be equal to: kCaseB");
+ " kCaseB\n Which is: ");
EXPECT_FATAL_FAILURE(ASSERT_EQ(kCaseA, kCaseC),
- "Which is: 42");
+ "\n Which is: 42");
# endif
EXPECT_FATAL_FAILURE(ASSERT_EQ(kCaseA, kCaseC),
- "Which is: -1");
+ "\n Which is: -1");
}
#endif // !GTEST_OS_MAC && !defined(__SUNPRO_CC)
@@ -4302,10 +4329,12 @@ TEST(AssertionWithMessageTest, SUCCEED) {
TEST(AssertionWithMessageTest, ASSERT_TRUE) {
ASSERT_TRUE(true) << "This should succeed.";
ASSERT_TRUE(true) << true;
- EXPECT_FATAL_FAILURE({ // NOLINT
- ASSERT_TRUE(false) << static_cast<const char *>(NULL)
- << static_cast<char *>(NULL);
- }, "(null)(null)");
+ EXPECT_FATAL_FAILURE(
+ { // NOLINT
+ ASSERT_TRUE(false) << static_cast<const char*>(nullptr)
+ << static_cast<char*>(nullptr);
+ },
+ "(null)(null)");
}
#if GTEST_OS_WINDOWS
@@ -4382,7 +4411,7 @@ TEST(ExpectTest, ExpectFalseWithAssertionResult) {
}
#ifdef __BORLANDC__
-// Restores warnings after previous "#pragma option push" supressed them
+// Restores warnings after previous "#pragma option push" suppressed them
# pragma option pop
#endif
@@ -4390,9 +4419,10 @@ TEST(ExpectTest, ExpectFalseWithAssertionResult) {
TEST(ExpectTest, EXPECT_EQ) {
EXPECT_EQ(5, 2 + 3);
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(5, 2*3),
- " Expected: 5\n"
- "To be equal to: 2*3\n"
- " Which is: 6");
+ "Expected equality of these values:\n"
+ " 5\n"
+ " 2*3\n"
+ " Which is: 6");
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(5, 2 - 3),
"2 - 3");
}
@@ -4413,17 +4443,16 @@ TEST(ExpectTest, EXPECT_EQ_Double) {
// Tests EXPECT_EQ(NULL, pointer).
TEST(ExpectTest, EXPECT_EQ_NULL) {
// A success.
- const char* p = NULL;
+ const char* p = nullptr;
// Some older GCC versions may issue a spurious warning in this or the next
// assertion statement. This warning should not be suppressed with
// static_cast since the test verifies the ability to use bare NULL as the
// expected parameter to the macro.
- EXPECT_EQ(NULL, p);
+ EXPECT_EQ(nullptr, p);
// A failure.
int n = 0;
- EXPECT_NONFATAL_FAILURE(EXPECT_EQ(NULL, &n),
- "To be equal to: &n\n");
+ EXPECT_NONFATAL_FAILURE(EXPECT_EQ(nullptr, &n), " &n\n Which is:");
}
#endif // GTEST_CAN_COMPARE_NULL
@@ -4439,7 +4468,7 @@ TEST(ExpectTest, EXPECT_EQ_0) {
// A failure.
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(0, 5.6),
- "Expected: 0");
+ " 0\n 5.6");
}
// Tests EXPECT_NE.
@@ -4451,7 +4480,7 @@ TEST(ExpectTest, EXPECT_NE) {
"actual: 'a' (97, 0x61) vs 'a' (97, 0x61)");
EXPECT_NONFATAL_FAILURE(EXPECT_NE(2, 2),
"2");
- char* const p0 = NULL;
+ char* const p0 = nullptr;
EXPECT_NONFATAL_FAILURE(EXPECT_NE(p0, p0),
"p0");
// Only way to get the Nokia compiler to compile the cast
@@ -4539,7 +4568,7 @@ TEST(ExpectTest, EXPECT_ANY_THROW) {
TEST(ExpectTest, ExpectPrecedence) {
EXPECT_EQ(1 < 2, true);
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(true, true && false),
- "To be equal to: true && false");
+ " true && false\n Which is: false");
}
@@ -4559,7 +4588,7 @@ TEST(StreamableToStringTest, Pointer) {
// Tests using StreamableToString() on a NULL non-char pointer.
TEST(StreamableToStringTest, NullPointer) {
- int* p = NULL;
+ int* p = nullptr;
EXPECT_STREQ("(null)", StreamableToString(p).c_str());
}
@@ -4570,7 +4599,7 @@ TEST(StreamableToStringTest, CString) {
// Tests using StreamableToString() on a NULL C string.
TEST(StreamableToStringTest, NullCString) {
- char* p = NULL;
+ char* p = nullptr;
EXPECT_STREQ("(null)", StreamableToString(p).c_str());
}
@@ -4615,8 +4644,7 @@ TEST(StreamableTest, int) {
// implemented a workaround (substituting "(null)" for NULL). This
// tests whether the workaround works.
TEST(StreamableTest, NullCharPtr) {
- EXPECT_FATAL_FAILURE(FAIL() << static_cast<const char*>(NULL),
- "(null)");
+ EXPECT_FATAL_FAILURE(FAIL() << static_cast<const char*>(nullptr), "(null)");
}
// Tests that basic IO manipulators (endl, ends, and flush) can be
@@ -4656,7 +4684,7 @@ TEST(MacroTest, ADD_FAILURE_AT) {
// Unfortunately, we cannot verify that the failure message contains
// the right file path and line number the same way, as
// EXPECT_NONFATAL_FAILURE() doesn't get to see the file path and
- // line number. Instead, we do that in gtest_output_test_.cc.
+ // line number. Instead, we do that in googletest-output-test_.cc.
}
// Tests FAIL.
@@ -4686,14 +4714,14 @@ TEST(EqAssertionTest, Bool) {
EXPECT_FATAL_FAILURE({
bool false_value = false;
ASSERT_EQ(false_value, true);
- }, "To be equal to: true");
+ }, " false_value\n Which is: false\n true");
}
// Tests using int values in {EXPECT|ASSERT}_EQ.
TEST(EqAssertionTest, Int) {
ASSERT_EQ(32, 32);
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(32, 33),
- "33");
+ " 32\n 33");
}
// Tests using time_t values in {EXPECT|ASSERT}_EQ.
@@ -4710,9 +4738,9 @@ TEST(EqAssertionTest, Char) {
ASSERT_EQ('z', 'z');
const char ch = 'b';
EXPECT_NONFATAL_FAILURE(EXPECT_EQ('\0', ch),
- "ch");
+ " ch\n Which is: 'b'");
EXPECT_NONFATAL_FAILURE(EXPECT_EQ('a', ch),
- "ch");
+ " ch\n Which is: 'b'");
}
// Tests using wchar_t values in {EXPECT|ASSERT}_EQ.
@@ -4720,10 +4748,11 @@ TEST(EqAssertionTest, WideChar) {
EXPECT_EQ(L'b', L'b');
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(L'\0', L'x'),
- " Expected: L'\0'\n"
- " Which is: L'\0' (0, 0x0)\n"
- "To be equal to: L'x'\n"
- " Which is: L'x' (120, 0x78)");
+ "Expected equality of these values:\n"
+ " L'\0'\n"
+ " Which is: L'\0' (0, 0x0)\n"
+ " L'x'\n"
+ " Which is: L'x' (120, 0x78)");
static wchar_t wchar;
wchar = L'b';
@@ -4731,7 +4760,7 @@ TEST(EqAssertionTest, WideChar) {
"wchar");
wchar = 0x8119;
EXPECT_FATAL_FAILURE(ASSERT_EQ(static_cast<wchar_t>(0x8120), wchar),
- "To be equal to: wchar");
+ " wchar\n Which is: L'");
}
// Tests using ::std::string values in {EXPECT|ASSERT}_EQ.
@@ -4760,8 +4789,7 @@ TEST(EqAssertionTest, StdString) {
static ::std::string str3(str1);
str3.at(2) = '\0';
EXPECT_FATAL_FAILURE(ASSERT_EQ(str1, str3),
- "To be equal to: str3\n"
- " Which is: \"A \\0 in the middle\"");
+ " str3\n Which is: \"A \\0 in the middle\"");
}
#if GTEST_HAS_STD_WSTRING
@@ -4869,7 +4897,7 @@ TEST(EqAssertionTest, GlobalWideString) {
// Tests using char pointers in {EXPECT|ASSERT}_EQ.
TEST(EqAssertionTest, CharPointer) {
- char* const p0 = NULL;
+ char* const p0 = nullptr;
// Only way to get the Nokia compiler to compile the cast
// is to have a separate void* variable first. Putting
// the two casts on the same line doesn't work, neither does
@@ -4881,9 +4909,9 @@ TEST(EqAssertionTest, CharPointer) {
ASSERT_EQ(p1, p1);
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p0, p2),
- "To be equal to: p2");
+ " p2\n Which is:");
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p1, p2),
- "p2");
+ " p2\n Which is:");
EXPECT_FATAL_FAILURE(ASSERT_EQ(reinterpret_cast<char*>(0x1234),
reinterpret_cast<char*>(0xABC0)),
"ABC0");
@@ -4891,7 +4919,7 @@ TEST(EqAssertionTest, CharPointer) {
// Tests using wchar_t pointers in {EXPECT|ASSERT}_EQ.
TEST(EqAssertionTest, WideCharPointer) {
- wchar_t* const p0 = NULL;
+ wchar_t* const p0 = nullptr;
// Only way to get the Nokia compiler to compile the cast
// is to have a separate void* variable first. Putting
// the two casts on the same line doesn't work, neither does
@@ -4903,9 +4931,9 @@ TEST(EqAssertionTest, WideCharPointer) {
EXPECT_EQ(p0, p0);
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p0, p2),
- "To be equal to: p2");
+ " p2\n Which is:");
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p1, p2),
- "p2");
+ " p2\n Which is:");
void* pv3 = (void*)0x1234; // NOLINT
void* pv4 = (void*)0xABC0; // NOLINT
const wchar_t* p3 = reinterpret_cast<const wchar_t*>(pv3);
@@ -4916,9 +4944,8 @@ TEST(EqAssertionTest, WideCharPointer) {
// Tests using other types of pointers in {EXPECT|ASSERT}_EQ.
TEST(EqAssertionTest, OtherPointer) {
- ASSERT_EQ(static_cast<const int*>(NULL),
- static_cast<const int*>(NULL));
- EXPECT_FATAL_FAILURE(ASSERT_EQ(static_cast<const int*>(NULL),
+ ASSERT_EQ(static_cast<const int*>(nullptr), static_cast<const int*>(nullptr));
+ EXPECT_FATAL_FAILURE(ASSERT_EQ(static_cast<const int*>(nullptr),
reinterpret_cast<const int*>(0x1234)),
"0x1234");
}
@@ -5125,8 +5152,7 @@ TEST(AssertionResultTest, CanStreamOstreamManipulators) {
EXPECT_STREQ("Data\n\\0Will be visible", r.message());
}
-// The next test uses explicit conversion operators -- a C++11 feature.
-#if GTEST_LANG_CXX11
+// The next test uses explicit conversion operators
TEST(AssertionResultTest, ConstructibleFromContextuallyConvertibleToBool) {
struct ExplicitlyConvertibleToBool {
@@ -5139,8 +5165,6 @@ TEST(AssertionResultTest, ConstructibleFromContextuallyConvertibleToBool) {
EXPECT_TRUE(v2);
}
-#endif // GTEST_LANG_CXX11
-
struct ConvertibleToAssertionResult {
operator AssertionResult() const { return AssertionResult(true); }
};
@@ -5254,12 +5278,12 @@ TEST(MessageTest, CanStreamUserTypeInUserNameSpaceWithStreamOperatorInGlobal) {
// Tests streaming NULL pointers to testing::Message.
TEST(MessageTest, NullPointers) {
Message msg;
- char* const p1 = NULL;
- unsigned char* const p2 = NULL;
- int* p3 = NULL;
- double* p4 = NULL;
- bool* p5 = NULL;
- Message* p6 = NULL;
+ char* const p1 = nullptr;
+ unsigned char* const p2 = nullptr;
+ int* p3 = nullptr;
+ double* p4 = nullptr;
+ bool* p5 = nullptr;
+ Message* p6 = nullptr;
msg << p1 << p2 << p3 << p4 << p5 << p6;
ASSERT_STREQ("(null)(null)(null)(null)(null)(null)",
@@ -5269,12 +5293,12 @@ TEST(MessageTest, NullPointers) {
// Tests streaming wide strings to testing::Message.
TEST(MessageTest, WideStrings) {
// Streams a NULL of type const wchar_t*.
- const wchar_t* const_wstr = NULL;
+ const wchar_t* const_wstr = nullptr;
EXPECT_STREQ("(null)",
(Message() << const_wstr).GetString().c_str());
// Streams a NULL of type wchar_t*.
- wchar_t* wstr = NULL;
+ wchar_t* wstr = nullptr;
EXPECT_STREQ("(null)",
(Message() << wstr).GetString().c_str());
@@ -5298,15 +5322,15 @@ namespace testing {
class TestInfoTest : public Test {
protected:
static const TestInfo* GetTestInfo(const char* test_name) {
- const TestCase* const test_case = GetUnitTestImpl()->
- GetTestCase("TestInfoTest", "", NULL, NULL);
+ const TestCase* const test_case =
+ GetUnitTestImpl()->GetTestCase("TestInfoTest", "", nullptr, nullptr);
for (int i = 0; i < test_case->total_test_count(); ++i) {
const TestInfo* const test_info = test_case->GetTestInfo(i);
if (strcmp(test_name, test_info->name()) == 0)
return test_info;
}
- return NULL;
+ return nullptr;
}
static const TestResult* GetTestResult(
@@ -5420,7 +5444,7 @@ class SetUpTestCaseTest : public Test {
EXPECT_EQ(0, counter_);
// Cleans up the shared resource.
- shared_resource_ = NULL;
+ shared_resource_ = nullptr;
}
// This will be called before each test in this test case.
@@ -5438,19 +5462,18 @@ class SetUpTestCaseTest : public Test {
};
int SetUpTestCaseTest::counter_ = 0;
-const char* SetUpTestCaseTest::shared_resource_ = NULL;
+const char* SetUpTestCaseTest::shared_resource_ = nullptr;
// A test that uses the shared resource.
-TEST_F(SetUpTestCaseTest, Test1) {
- EXPECT_STRNE(NULL, shared_resource_);
-}
+TEST_F(SetUpTestCaseTest, Test1) { EXPECT_STRNE(nullptr, shared_resource_); }
// Another test that uses the shared resource.
TEST_F(SetUpTestCaseTest, Test2) {
EXPECT_STREQ("123", shared_resource_);
}
-// The InitGoogleTestTest test case tests testing::InitGoogleTest().
+
+// The ParseFlagsTest test case tests ParseGoogleTestFlagsOnly.
// The Flags struct stores a copy of all Google Test flags.
struct Flags {
@@ -5536,8 +5559,8 @@ struct Flags {
return flags;
}
- // Creates a Flags struct where the gtest_random_seed flag has
- // the given value.
+ // Creates a Flags struct where the gtest_random_seed flag has the given
+ // value.
static Flags RandomSeed(Int32 random_seed) {
Flags flags;
flags.random_seed = random_seed;
@@ -5552,8 +5575,8 @@ struct Flags {
return flags;
}
- // Creates a Flags struct where the gtest_shuffle flag has
- // the given value.
+ // Creates a Flags struct where the gtest_shuffle flag has the given
+ // value.
static Flags Shuffle(bool shuffle) {
Flags flags;
flags.shuffle = shuffle;
@@ -5601,8 +5624,8 @@ struct Flags {
bool throw_on_failure;
};
-// Fixture for testing InitGoogleTest().
-class InitGoogleTestTest : public Test {
+// Fixture for testing ParseGoogleTestFlagsOnly().
+class ParseFlagsTest : public Test {
protected:
// Clears the flags before each test.
virtual void SetUp() {
@@ -5663,16 +5686,16 @@ class InitGoogleTestTest : public Test {
const bool saved_help_flag = ::testing::internal::g_help_flag;
::testing::internal::g_help_flag = false;
-#if GTEST_HAS_STREAM_REDIRECTION
+# if GTEST_HAS_STREAM_REDIRECTION
CaptureStdout();
-#endif
+# endif
// Parses the command line.
internal::ParseGoogleTestFlagsOnly(&argc1, const_cast<CharType**>(argv1));
-#if GTEST_HAS_STREAM_REDIRECTION
+# if GTEST_HAS_STREAM_REDIRECTION
const std::string captured_stdout = GetCapturedStdout();
-#endif
+# endif
// Verifies the flag values.
CheckFlags(expected);
@@ -5685,7 +5708,7 @@ class InitGoogleTestTest : public Test {
// help message for the flags it recognizes.
EXPECT_EQ(should_print_help, ::testing::internal::g_help_flag);
-#if GTEST_HAS_STREAM_REDIRECTION
+# if GTEST_HAS_STREAM_REDIRECTION
const char* const expected_help_fragment =
"This program contains tests written using";
if (should_print_help) {
@@ -5694,7 +5717,7 @@ class InitGoogleTestTest : public Test {
EXPECT_PRED_FORMAT2(IsNotSubstring,
expected_help_fragment, captured_stdout);
}
-#endif // GTEST_HAS_STREAM_REDIRECTION
+# endif // GTEST_HAS_STREAM_REDIRECTION
::testing::internal::g_help_flag = saved_help_flag;
}
@@ -5702,235 +5725,139 @@ class InitGoogleTestTest : public Test {
// This macro wraps TestParsingFlags s.t. the user doesn't need
// to specify the array sizes.
-#define GTEST_TEST_PARSING_FLAGS_(argv1, argv2, expected, should_print_help) \
+# 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)
};
// Tests parsing an empty command line.
-TEST_F(InitGoogleTestTest, Empty) {
- const char* argv[] = {
- NULL
- };
+TEST_F(ParseFlagsTest, Empty) {
+ const char* argv[] = {nullptr};
- const char* argv2[] = {
- NULL
- };
+ const char* argv2[] = {nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags(), false);
}
// Tests parsing a command line that has no flag.
-TEST_F(InitGoogleTestTest, NoFlag) {
- const char* argv[] = {
- "foo.exe",
- NULL
- };
+TEST_F(ParseFlagsTest, NoFlag) {
+ const char* argv[] = {"foo.exe", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags(), false);
}
// Tests parsing a bad --gtest_filter flag.
-TEST_F(InitGoogleTestTest, FilterBad) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_filter",
- NULL
- };
+TEST_F(ParseFlagsTest, FilterBad) {
+ const char* argv[] = {"foo.exe", "--gtest_filter", nullptr};
- const char* argv2[] = {
- "foo.exe",
- "--gtest_filter",
- NULL
- };
+ const char* argv2[] = {"foo.exe", "--gtest_filter", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Filter(""), true);
}
// Tests parsing an empty --gtest_filter flag.
-TEST_F(InitGoogleTestTest, FilterEmpty) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_filter=",
- NULL
- };
+TEST_F(ParseFlagsTest, FilterEmpty) {
+ const char* argv[] = {"foo.exe", "--gtest_filter=", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Filter(""), false);
}
// Tests parsing a non-empty --gtest_filter flag.
-TEST_F(InitGoogleTestTest, FilterNonEmpty) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_filter=abc",
- NULL
- };
+TEST_F(ParseFlagsTest, FilterNonEmpty) {
+ const char* argv[] = {"foo.exe", "--gtest_filter=abc", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Filter("abc"), false);
}
// Tests parsing --gtest_break_on_failure.
-TEST_F(InitGoogleTestTest, BreakOnFailureWithoutValue) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_break_on_failure",
- NULL
-};
+TEST_F(ParseFlagsTest, BreakOnFailureWithoutValue) {
+ const char* argv[] = {"foo.exe", "--gtest_break_on_failure", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::BreakOnFailure(true), false);
}
// Tests parsing --gtest_break_on_failure=0.
-TEST_F(InitGoogleTestTest, BreakOnFailureFalse_0) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_break_on_failure=0",
- NULL
- };
+TEST_F(ParseFlagsTest, BreakOnFailureFalse_0) {
+ const char* argv[] = {"foo.exe", "--gtest_break_on_failure=0", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::BreakOnFailure(false), false);
}
// Tests parsing --gtest_break_on_failure=f.
-TEST_F(InitGoogleTestTest, BreakOnFailureFalse_f) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_break_on_failure=f",
- NULL
- };
+TEST_F(ParseFlagsTest, BreakOnFailureFalse_f) {
+ const char* argv[] = {"foo.exe", "--gtest_break_on_failure=f", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::BreakOnFailure(false), false);
}
// Tests parsing --gtest_break_on_failure=F.
-TEST_F(InitGoogleTestTest, BreakOnFailureFalse_F) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_break_on_failure=F",
- NULL
- };
+TEST_F(ParseFlagsTest, BreakOnFailureFalse_F) {
+ const char* argv[] = {"foo.exe", "--gtest_break_on_failure=F", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::BreakOnFailure(false), false);
}
// Tests parsing a --gtest_break_on_failure flag that has a "true"
// definition.
-TEST_F(InitGoogleTestTest, BreakOnFailureTrue) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_break_on_failure=1",
- NULL
- };
+TEST_F(ParseFlagsTest, BreakOnFailureTrue) {
+ const char* argv[] = {"foo.exe", "--gtest_break_on_failure=1", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::BreakOnFailure(true), false);
}
// Tests parsing --gtest_catch_exceptions.
-TEST_F(InitGoogleTestTest, CatchExceptions) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_catch_exceptions",
- NULL
- };
+TEST_F(ParseFlagsTest, CatchExceptions) {
+ const char* argv[] = {"foo.exe", "--gtest_catch_exceptions", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::CatchExceptions(true), false);
}
// Tests parsing --gtest_death_test_use_fork.
-TEST_F(InitGoogleTestTest, DeathTestUseFork) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_death_test_use_fork",
- NULL
- };
+TEST_F(ParseFlagsTest, DeathTestUseFork) {
+ const char* argv[] = {"foo.exe", "--gtest_death_test_use_fork", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::DeathTestUseFork(true), false);
}
// Tests having the same flag twice with different values. The
// expected behavior is that the one coming last takes precedence.
-TEST_F(InitGoogleTestTest, DuplicatedFlags) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_filter=a",
- "--gtest_filter=b",
- NULL
- };
+TEST_F(ParseFlagsTest, DuplicatedFlags) {
+ const char* argv[] = {"foo.exe", "--gtest_filter=a", "--gtest_filter=b",
+ nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Filter("b"), false);
}
// Tests having an unrecognized flag on the command line.
-TEST_F(InitGoogleTestTest, UnrecognizedFlag) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_break_on_failure",
- "bar", // Unrecognized by Google Test.
- "--gtest_filter=b",
- NULL
- };
+TEST_F(ParseFlagsTest, UnrecognizedFlag) {
+ const char* argv[] = {"foo.exe", "--gtest_break_on_failure",
+ "bar", // Unrecognized by Google Test.
+ "--gtest_filter=b", nullptr};
- const char* argv2[] = {
- "foo.exe",
- "bar",
- NULL
- };
+ const char* argv2[] = {"foo.exe", "bar", nullptr};
Flags flags;
flags.break_on_failure = true;
@@ -5939,447 +5866,260 @@ TEST_F(InitGoogleTestTest, UnrecognizedFlag) {
}
// Tests having a --gtest_list_tests flag
-TEST_F(InitGoogleTestTest, ListTestsFlag) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_list_tests",
- NULL
- };
+TEST_F(ParseFlagsTest, ListTestsFlag) {
+ const char* argv[] = {"foo.exe", "--gtest_list_tests", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
- GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ListTests(true), false);
+ GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ListTests(true), false);
}
// Tests having a --gtest_list_tests flag with a "true" value
-TEST_F(InitGoogleTestTest, ListTestsTrue) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_list_tests=1",
- NULL
- };
+TEST_F(ParseFlagsTest, ListTestsTrue) {
+ const char* argv[] = {"foo.exe", "--gtest_list_tests=1", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
- GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ListTests(true), false);
+ GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ListTests(true), false);
}
// Tests having a --gtest_list_tests flag with a "false" value
-TEST_F(InitGoogleTestTest, ListTestsFalse) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_list_tests=0",
- NULL
- };
+TEST_F(ParseFlagsTest, ListTestsFalse) {
+ const char* argv[] = {"foo.exe", "--gtest_list_tests=0", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
- GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ListTests(false), false);
+ GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ListTests(false), false);
}
// Tests parsing --gtest_list_tests=f.
-TEST_F(InitGoogleTestTest, ListTestsFalse_f) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_list_tests=f",
- NULL
- };
+TEST_F(ParseFlagsTest, ListTestsFalse_f) {
+ const char* argv[] = {"foo.exe", "--gtest_list_tests=f", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ListTests(false), false);
}
// Tests parsing --gtest_list_tests=F.
-TEST_F(InitGoogleTestTest, ListTestsFalse_F) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_list_tests=F",
- NULL
- };
+TEST_F(ParseFlagsTest, ListTestsFalse_F) {
+ const char* argv[] = {"foo.exe", "--gtest_list_tests=F", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ListTests(false), false);
}
// Tests parsing --gtest_output (invalid).
-TEST_F(InitGoogleTestTest, OutputEmpty) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_output",
- NULL
- };
+TEST_F(ParseFlagsTest, OutputEmpty) {
+ const char* argv[] = {"foo.exe", "--gtest_output", nullptr};
- const char* argv2[] = {
- "foo.exe",
- "--gtest_output",
- NULL
- };
+ const char* argv2[] = {"foo.exe", "--gtest_output", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags(), true);
}
// Tests parsing --gtest_output=xml
-TEST_F(InitGoogleTestTest, OutputXml) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_output=xml",
- NULL
- };
+TEST_F(ParseFlagsTest, OutputXml) {
+ const char* argv[] = {"foo.exe", "--gtest_output=xml", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Output("xml"), false);
}
// Tests parsing --gtest_output=xml:file
-TEST_F(InitGoogleTestTest, OutputXmlFile) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_output=xml:file",
- NULL
- };
+TEST_F(ParseFlagsTest, OutputXmlFile) {
+ const char* argv[] = {"foo.exe", "--gtest_output=xml:file", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Output("xml:file"), false);
}
// Tests parsing --gtest_output=xml:directory/path/
-TEST_F(InitGoogleTestTest, OutputXmlDirectory) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_output=xml:directory/path/",
- NULL
- };
+TEST_F(ParseFlagsTest, OutputXmlDirectory) {
+ const char* argv[] = {"foo.exe", "--gtest_output=xml:directory/path/",
+ nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2,
Flags::Output("xml:directory/path/"), false);
}
// Tests having a --gtest_print_time flag
-TEST_F(InitGoogleTestTest, PrintTimeFlag) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_print_time",
- NULL
- };
+TEST_F(ParseFlagsTest, PrintTimeFlag) {
+ const char* argv[] = {"foo.exe", "--gtest_print_time", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
- GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::PrintTime(true), false);
+ GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::PrintTime(true), false);
}
// Tests having a --gtest_print_time flag with a "true" value
-TEST_F(InitGoogleTestTest, PrintTimeTrue) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_print_time=1",
- NULL
- };
+TEST_F(ParseFlagsTest, PrintTimeTrue) {
+ const char* argv[] = {"foo.exe", "--gtest_print_time=1", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
- GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::PrintTime(true), false);
+ GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::PrintTime(true), false);
}
// Tests having a --gtest_print_time flag with a "false" value
-TEST_F(InitGoogleTestTest, PrintTimeFalse) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_print_time=0",
- NULL
- };
+TEST_F(ParseFlagsTest, PrintTimeFalse) {
+ const char* argv[] = {"foo.exe", "--gtest_print_time=0", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
- GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::PrintTime(false), false);
+ GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::PrintTime(false), false);
}
// Tests parsing --gtest_print_time=f.
-TEST_F(InitGoogleTestTest, PrintTimeFalse_f) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_print_time=f",
- NULL
- };
+TEST_F(ParseFlagsTest, PrintTimeFalse_f) {
+ const char* argv[] = {"foo.exe", "--gtest_print_time=f", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::PrintTime(false), false);
}
// Tests parsing --gtest_print_time=F.
-TEST_F(InitGoogleTestTest, PrintTimeFalse_F) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_print_time=F",
- NULL
- };
+TEST_F(ParseFlagsTest, PrintTimeFalse_F) {
+ const char* argv[] = {"foo.exe", "--gtest_print_time=F", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::PrintTime(false), false);
}
// Tests parsing --gtest_random_seed=number
-TEST_F(InitGoogleTestTest, RandomSeed) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_random_seed=1000",
- NULL
- };
+TEST_F(ParseFlagsTest, RandomSeed) {
+ const char* argv[] = {"foo.exe", "--gtest_random_seed=1000", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::RandomSeed(1000), false);
}
// Tests parsing --gtest_repeat=number
-TEST_F(InitGoogleTestTest, Repeat) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_repeat=1000",
- NULL
- };
+TEST_F(ParseFlagsTest, Repeat) {
+ const char* argv[] = {"foo.exe", "--gtest_repeat=1000", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Repeat(1000), false);
}
// Tests having a --gtest_also_run_disabled_tests flag
-TEST_F(InitGoogleTestTest, AlsoRunDisabledTestsFlag) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_also_run_disabled_tests",
- NULL
- };
+TEST_F(ParseFlagsTest, AlsoRunDisabledTestsFlag) {
+ const char* argv[] = {"foo.exe", "--gtest_also_run_disabled_tests", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
- GTEST_TEST_PARSING_FLAGS_(argv, argv2,
- Flags::AlsoRunDisabledTests(true), false);
+ GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::AlsoRunDisabledTests(true),
+ false);
}
// Tests having a --gtest_also_run_disabled_tests flag with a "true" value
-TEST_F(InitGoogleTestTest, AlsoRunDisabledTestsTrue) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_also_run_disabled_tests=1",
- NULL
- };
+TEST_F(ParseFlagsTest, AlsoRunDisabledTestsTrue) {
+ const char* argv[] = {"foo.exe", "--gtest_also_run_disabled_tests=1",
+ nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
- GTEST_TEST_PARSING_FLAGS_(argv, argv2,
- Flags::AlsoRunDisabledTests(true), false);
+ GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::AlsoRunDisabledTests(true),
+ false);
}
// Tests having a --gtest_also_run_disabled_tests flag with a "false" value
-TEST_F(InitGoogleTestTest, AlsoRunDisabledTestsFalse) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_also_run_disabled_tests=0",
- NULL
- };
+TEST_F(ParseFlagsTest, AlsoRunDisabledTestsFalse) {
+ const char* argv[] = {"foo.exe", "--gtest_also_run_disabled_tests=0",
+ nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
- GTEST_TEST_PARSING_FLAGS_(argv, argv2,
- Flags::AlsoRunDisabledTests(false), false);
+ GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::AlsoRunDisabledTests(false),
+ false);
}
// Tests parsing --gtest_shuffle.
-TEST_F(InitGoogleTestTest, ShuffleWithoutValue) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_shuffle",
- NULL
-};
+TEST_F(ParseFlagsTest, ShuffleWithoutValue) {
+ const char* argv[] = {"foo.exe", "--gtest_shuffle", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Shuffle(true), false);
}
// Tests parsing --gtest_shuffle=0.
-TEST_F(InitGoogleTestTest, ShuffleFalse_0) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_shuffle=0",
- NULL
- };
+TEST_F(ParseFlagsTest, ShuffleFalse_0) {
+ const char* argv[] = {"foo.exe", "--gtest_shuffle=0", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Shuffle(false), false);
}
-// Tests parsing a --gtest_shuffle flag that has a "true"
-// definition.
-TEST_F(InitGoogleTestTest, ShuffleTrue) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_shuffle=1",
- NULL
- };
+// Tests parsing a --gtest_shuffle flag that has a "true" definition.
+TEST_F(ParseFlagsTest, ShuffleTrue) {
+ const char* argv[] = {"foo.exe", "--gtest_shuffle=1", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Shuffle(true), false);
}
// Tests parsing --gtest_stack_trace_depth=number.
-TEST_F(InitGoogleTestTest, StackTraceDepth) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_stack_trace_depth=5",
- NULL
- };
+TEST_F(ParseFlagsTest, StackTraceDepth) {
+ const char* argv[] = {"foo.exe", "--gtest_stack_trace_depth=5", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::StackTraceDepth(5), false);
}
-TEST_F(InitGoogleTestTest, StreamResultTo) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_stream_result_to=localhost:1234",
- NULL
- };
+TEST_F(ParseFlagsTest, StreamResultTo) {
+ const char* argv[] = {"foo.exe", "--gtest_stream_result_to=localhost:1234",
+ nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(
argv, argv2, Flags::StreamResultTo("localhost:1234"), false);
}
// Tests parsing --gtest_throw_on_failure.
-TEST_F(InitGoogleTestTest, ThrowOnFailureWithoutValue) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_throw_on_failure",
- NULL
-};
+TEST_F(ParseFlagsTest, ThrowOnFailureWithoutValue) {
+ const char* argv[] = {"foo.exe", "--gtest_throw_on_failure", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ThrowOnFailure(true), false);
}
// Tests parsing --gtest_throw_on_failure=0.
-TEST_F(InitGoogleTestTest, ThrowOnFailureFalse_0) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_throw_on_failure=0",
- NULL
- };
+TEST_F(ParseFlagsTest, ThrowOnFailureFalse_0) {
+ const char* argv[] = {"foo.exe", "--gtest_throw_on_failure=0", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ThrowOnFailure(false), false);
}
// Tests parsing a --gtest_throw_on_failure flag that has a "true"
// definition.
-TEST_F(InitGoogleTestTest, ThrowOnFailureTrue) {
- const char* argv[] = {
- "foo.exe",
- "--gtest_throw_on_failure=1",
- NULL
- };
+TEST_F(ParseFlagsTest, ThrowOnFailureTrue) {
+ const char* argv[] = {"foo.exe", "--gtest_throw_on_failure=1", nullptr};
- const char* argv2[] = {
- "foo.exe",
- NULL
- };
+ const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ThrowOnFailure(true), false);
}
-#if GTEST_OS_WINDOWS
+# if GTEST_OS_WINDOWS
// Tests parsing wide strings.
-TEST_F(InitGoogleTestTest, WideStrings) {
+TEST_F(ParseFlagsTest, WideStrings) {
const wchar_t* argv[] = {
L"foo.exe",
L"--gtest_filter=Foo*",
@@ -6405,13 +6145,13 @@ TEST_F(InitGoogleTestTest, WideStrings) {
# endif // GTEST_OS_WINDOWS
#if GTEST_USE_OWN_FLAGFILE_FLAG_
-class FlagfileTest : public InitGoogleTestTest {
+class FlagfileTest : public ParseFlagsTest {
public:
virtual void SetUp() {
- InitGoogleTestTest::SetUp();
+ ParseFlagsTest::SetUp();
testdata_path_.Set(internal::FilePath(
- internal::TempDir() + internal::GetCurrentExecutableName().string() +
+ testing::TempDir() + internal::GetCurrentExecutableName().string() +
"_flagfile_test"));
testing::internal::posix::RmDir(testdata_path_.c_str());
EXPECT_TRUE(testdata_path_.CreateFolder());
@@ -6419,7 +6159,7 @@ class FlagfileTest : public InitGoogleTestTest {
virtual void TearDown() {
testing::internal::posix::RmDir(testdata_path_.c_str());
- InitGoogleTestTest::TearDown();
+ ParseFlagsTest::TearDown();
}
internal::FilePath CreateFlagfile(const char* contents) {
@@ -6514,7 +6254,7 @@ class CurrentTestInfoTest : public Test {
// There should be no tests running at this point.
const TestInfo* test_info =
UnitTest::GetInstance()->current_test_info();
- EXPECT_TRUE(test_info == NULL)
+ EXPECT_TRUE(test_info == nullptr)
<< "There should be no tests running at this point.";
}
@@ -6523,7 +6263,7 @@ class CurrentTestInfoTest : public Test {
static void TearDownTestCase() {
const TestInfo* test_info =
UnitTest::GetInstance()->current_test_info();
- EXPECT_TRUE(test_info == NULL)
+ EXPECT_TRUE(test_info == nullptr)
<< "There should be no tests running at this point.";
}
};
@@ -6533,7 +6273,7 @@ class CurrentTestInfoTest : public Test {
TEST_F(CurrentTestInfoTest, WorksForFirstTestInATestCase) {
const TestInfo* test_info =
UnitTest::GetInstance()->current_test_info();
- ASSERT_TRUE(NULL != test_info)
+ ASSERT_TRUE(nullptr != test_info)
<< "There is a test running so we should have a valid TestInfo.";
EXPECT_STREQ("CurrentTestInfoTest", test_info->test_case_name())
<< "Expected the name of the currently running test case.";
@@ -6548,7 +6288,7 @@ TEST_F(CurrentTestInfoTest, WorksForFirstTestInATestCase) {
TEST_F(CurrentTestInfoTest, WorksForSecondTestInATestCase) {
const TestInfo* test_info =
UnitTest::GetInstance()->current_test_info();
- ASSERT_TRUE(NULL != test_info)
+ ASSERT_TRUE(nullptr != test_info)
<< "There is a test running so we should have a valid TestInfo.";
EXPECT_STREQ("CurrentTestInfoTest", test_info->test_case_name())
<< "Expected the name of the currently running test case.";
@@ -6558,6 +6298,7 @@ TEST_F(CurrentTestInfoTest, WorksForSecondTestInATestCase) {
} // namespace testing
+
// These two lines test that we can define tests in a namespace that
// has the name "testing" and is nested in another namespace.
namespace my_namespace {
@@ -6638,7 +6379,7 @@ TEST(StreamingAssertionsTest, Truth2) {
}
#ifdef __BORLANDC__
-// Restores warnings after previous "#pragma option push" supressed them
+// Restores warnings after previous "#pragma option push" suppressed them
# pragma option pop
#endif
@@ -6799,7 +6540,7 @@ TEST(ColoredOutputTest, UsesColorsWhenStdoutIsTty) {
TEST(ColoredOutputTest, UsesColorsWhenTermSupportsColors) {
GTEST_FLAG(color) = "auto";
-#if GTEST_OS_WINDOWS
+#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW
// On Windows, we ignore the TERM variable as it's usually not set.
SetEnv("TERM", "dumb");
@@ -6888,14 +6629,6 @@ TEST(StaticAssertTypeEqTest, CompilesForEqualTypes) {
StaticAssertTypeEq<int*, IntAlias*>();
}
-TEST(GetCurrentOsStackTraceExceptTopTest, ReturnsTheStackTrace) {
- testing::UnitTest* const unit_test = testing::UnitTest::GetInstance();
-
- // We don't have a stack walker in Google Test yet.
- EXPECT_STREQ("", GetCurrentOsStackTraceExceptTop(unit_test, 0).c_str());
- EXPECT_STREQ("", GetCurrentOsStackTraceExceptTop(unit_test, 1).c_str());
-}
-
TEST(HasNonfatalFailureTest, ReturnsFalseWhenThereIsNoFailure) {
EXPECT_FALSE(HasNonfatalFailure());
}
@@ -6982,7 +6715,7 @@ TEST(HasFailureTest, WorksOutsideOfTestBody2) {
class TestListener : public EmptyTestEventListener {
public:
- TestListener() : on_start_counter_(NULL), is_destroyed_(NULL) {}
+ TestListener() : on_start_counter_(nullptr), is_destroyed_(nullptr) {}
TestListener(int* on_start_counter, bool* is_destroyed)
: on_start_counter_(on_start_counter),
is_destroyed_(is_destroyed) {}
@@ -6994,8 +6727,7 @@ class TestListener : public EmptyTestEventListener {
protected:
virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) {
- if (on_start_counter_ != NULL)
- (*on_start_counter_)++;
+ if (on_start_counter_ != nullptr) (*on_start_counter_)++;
}
private:
@@ -7007,9 +6739,9 @@ class TestListener : public EmptyTestEventListener {
TEST(TestEventListenersTest, ConstructionWorks) {
TestEventListeners listeners;
- EXPECT_TRUE(TestEventListenersAccessor::GetRepeater(&listeners) != NULL);
- EXPECT_TRUE(listeners.default_result_printer() == NULL);
- EXPECT_TRUE(listeners.default_xml_generator() == NULL);
+ EXPECT_TRUE(TestEventListenersAccessor::GetRepeater(&listeners) != nullptr);
+ EXPECT_TRUE(listeners.default_result_printer() == nullptr);
+ EXPECT_TRUE(listeners.default_xml_generator() == nullptr);
}
// Tests that the TestEventListeners destructor deletes all the listeners it
@@ -7018,12 +6750,12 @@ TEST(TestEventListenersTest, DestructionWorks) {
bool default_result_printer_is_destroyed = false;
bool default_xml_printer_is_destroyed = false;
bool extra_listener_is_destroyed = false;
- TestListener* default_result_printer = new TestListener(
- NULL, &default_result_printer_is_destroyed);
- TestListener* default_xml_printer = new TestListener(
- NULL, &default_xml_printer_is_destroyed);
- TestListener* extra_listener = new TestListener(
- NULL, &extra_listener_is_destroyed);
+ TestListener* default_result_printer =
+ new TestListener(nullptr, &default_result_printer_is_destroyed);
+ TestListener* default_xml_printer =
+ new TestListener(nullptr, &default_xml_printer_is_destroyed);
+ TestListener* extra_listener =
+ new TestListener(nullptr, &extra_listener_is_destroyed);
{
TestEventListeners listeners;
@@ -7148,7 +6880,7 @@ TEST(TestEventListenersTest, Release) {
EXPECT_EQ(listener, listeners.Release(listener));
TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
*UnitTest::GetInstance());
- EXPECT_TRUE(listeners.Release(listener) == NULL);
+ EXPECT_TRUE(listeners.Release(listener) == nullptr);
}
EXPECT_EQ(0, on_start_counter);
EXPECT_FALSE(is_destroyed);
@@ -7158,7 +6890,7 @@ TEST(TestEventListenersTest, Release) {
// Tests that no events are forwarded when event forwarding is disabled.
TEST(EventListenerTest, SuppressEventForwarding) {
int on_start_counter = 0;
- TestListener* listener = new TestListener(&on_start_counter, NULL);
+ TestListener* listener = new TestListener(&on_start_counter, nullptr);
TestEventListeners listeners;
listeners.Append(listener);
@@ -7199,9 +6931,9 @@ TEST(EventListenerTest, default_result_printer) {
// Replacing default_result_printer with something else should remove it
// from the list and destroy it.
- TestEventListenersAccessor::SetDefaultResultPrinter(&listeners, NULL);
+ TestEventListenersAccessor::SetDefaultResultPrinter(&listeners, nullptr);
- EXPECT_TRUE(listeners.default_result_printer() == NULL);
+ EXPECT_TRUE(listeners.default_result_printer() == nullptr);
EXPECT_TRUE(is_destroyed);
// After broadcasting an event the counter is still the same, indicating
@@ -7225,7 +6957,7 @@ TEST(EventListenerTest, RemovingDefaultResultPrinterWorks) {
TestEventListenersAccessor::SetDefaultResultPrinter(&listeners, listener);
EXPECT_EQ(listener, listeners.Release(listener));
- EXPECT_TRUE(listeners.default_result_printer() == NULL);
+ EXPECT_TRUE(listeners.default_result_printer() == nullptr);
EXPECT_FALSE(is_destroyed);
// Broadcasting events now should not affect default_result_printer.
@@ -7258,9 +6990,9 @@ TEST(EventListenerTest, default_xml_generator) {
// Replacing default_xml_generator with something else should remove it
// from the list and destroy it.
- TestEventListenersAccessor::SetDefaultXmlGenerator(&listeners, NULL);
+ TestEventListenersAccessor::SetDefaultXmlGenerator(&listeners, nullptr);
- EXPECT_TRUE(listeners.default_xml_generator() == NULL);
+ EXPECT_TRUE(listeners.default_xml_generator() == nullptr);
EXPECT_TRUE(is_destroyed);
// After broadcasting an event the counter is still the same, indicating
@@ -7284,7 +7016,7 @@ TEST(EventListenerTest, RemovingDefaultXmlGeneratorWorks) {
TestEventListenersAccessor::SetDefaultXmlGenerator(&listeners, listener);
EXPECT_EQ(listener, listeners.Release(listener));
- EXPECT_TRUE(listeners.default_xml_generator() == NULL);
+ EXPECT_TRUE(listeners.default_xml_generator() == nullptr);
EXPECT_FALSE(is_destroyed);
// Broadcasting events now should not affect default_xml_generator.
@@ -7347,7 +7079,7 @@ GTEST_TEST(AlternativeNameTest, Works) { // GTEST_TEST is the same as TEST.
// Tests for internal utilities necessary for implementation of the universal
// printing.
-// TODO(vladl@google.com): Find a better home for them.
+// FIXME: Find a better home for them.
class ConversionHelperBase {};
class ConversionHelperDerived : public ConversionHelperBase {};
@@ -7531,6 +7263,46 @@ TEST(IsContainerTestTest, WorksForContainer) {
sizeof(IsContainerTest<std::map<int, double> >(0)));
}
+struct ConstOnlyContainerWithPointerIterator {
+ using const_iterator = int*;
+ const_iterator begin() const;
+ const_iterator end() const;
+};
+
+struct ConstOnlyContainerWithClassIterator {
+ struct const_iterator {
+ const int& operator*() const;
+ const_iterator& operator++(/* pre-increment */);
+ };
+ const_iterator begin() const;
+ const_iterator end() const;
+};
+
+TEST(IsContainerTestTest, ConstOnlyContainer) {
+ EXPECT_EQ(sizeof(IsContainer),
+ sizeof(IsContainerTest<ConstOnlyContainerWithPointerIterator>(0)));
+ EXPECT_EQ(sizeof(IsContainer),
+ sizeof(IsContainerTest<ConstOnlyContainerWithClassIterator>(0)));
+}
+
+// Tests IsHashTable.
+struct AHashTable {
+ typedef void hasher;
+};
+struct NotReallyAHashTable {
+ typedef void hasher;
+ typedef void reverse_iterator;
+};
+TEST(IsHashTable, Basic) {
+ EXPECT_TRUE(testing::internal::IsHashTable<AHashTable>::value);
+ EXPECT_FALSE(testing::internal::IsHashTable<NotReallyAHashTable>::value);
+ EXPECT_FALSE(testing::internal::IsHashTable<std::vector<int>>::value);
+ EXPECT_TRUE(testing::internal::IsHashTable<std::unordered_set<int>>::value);
+#if GTEST_HAS_HASH_SET_
+ EXPECT_TRUE(testing::internal::IsHashTable<__gnu_cxx::hash_set<int>>::value);
+#endif // GTEST_HAS_HASH_SET_
+}
+
// Tests ArrayEq().
TEST(ArrayEqTest, WorksForDegeneratedArrays) {
@@ -7704,3 +7476,24 @@ TEST(SkipPrefixTest, DoesNotSkipWhenPrefixDoesNotMatch) {
EXPECT_EQ(str, p);
}
+// Tests ad_hoc_test_result().
+
+class AdHocTestResultTest : public testing::Test {
+ protected:
+ static void SetUpTestCase() {
+ FAIL() << "A failure happened inside SetUpTestCase().";
+ }
+};
+
+TEST_F(AdHocTestResultTest, AdHocTestResultForTestCaseShowsFailure) {
+ const testing::TestResult& test_result = testing::UnitTest::GetInstance()
+ ->current_test_case()
+ ->ad_hoc_test_result();
+ EXPECT_TRUE(test_result.Failed());
+}
+
+TEST_F(AdHocTestResultTest, AdHocTestResultTestForUnitTestDoesNotShowFailure) {
+ const testing::TestResult& test_result =
+ testing::UnitTest::GetInstance()->ad_hoc_test_result();
+ EXPECT_FALSE(test_result.Failed());
+}