summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorbillydonahue@google.com <billydonahue@google.com@861a406c-534a-0410-8894-cb66d6ee9925>2014-05-15 19:42:15 +0000
committerbillydonahue@google.com <billydonahue@google.com@861a406c-534a-0410-8894-cb66d6ee9925>2014-05-15 19:42:15 +0000
commitf0d7f455d0ba1b1da1891c3ee54961a162e8fbc4 (patch)
treec7d7f91871f2078acc77b8b41dd5dd8313765a24 /test
parente735d74bc537869af877dfc90c171dc140495c11 (diff)
downloadgoogletest-f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4.tar.gz
Push upstream to SVN.
git-svn-id: http://googletest.googlecode.com/svn/trunk@686 861a406c-534a-0410-8894-cb66d6ee9925
Diffstat (limited to 'test')
-rw-r--r--test/gtest-death-test_test.cc70
-rw-r--r--test/gtest-printers_test.cc7
-rw-r--r--test/gtest_premature_exit_test.cc4
-rw-r--r--test/gtest_unittest.cc66
4 files changed, 77 insertions, 70 deletions
diff --git a/test/gtest-death-test_test.cc b/test/gtest-death-test_test.cc
index da0b84d..b25bc22 100644
--- a/test/gtest-death-test_test.cc
+++ b/test/gtest-death-test_test.cc
@@ -326,12 +326,9 @@ TEST_F(TestForDeathTest, EmbeddedNulInMessage) {
// Tests that death test macros expand to code which interacts well with switch
// statements.
TEST_F(TestForDeathTest, SwitchStatement) {
-// Microsoft compiler usually complains about switch statements without
-// case labels. We suppress that warning for this test.
-# ifdef _MSC_VER
-# pragma warning(push)
-# pragma warning(disable: 4065)
-# endif // _MSC_VER
+ // Microsoft compiler usually complains about switch statements without
+ // case labels. We suppress that warning for this test.
+ GTEST_DISABLE_MSC_WARNINGS_PUSH_(4065)
switch (0)
default:
@@ -341,9 +338,7 @@ TEST_F(TestForDeathTest, SwitchStatement) {
case 0:
EXPECT_DEATH(_exit(1), "") << "exit in switch case";
-# ifdef _MSC_VER
-# pragma warning(pop)
-# endif // _MSC_VER
+ GTEST_DISABLE_MSC_WARNINGS_POP_()
}
// Tests that a static member function can be used in a "fast" style
@@ -1304,7 +1299,27 @@ TEST(ConditionalDeathMacrosDeathTest, ExpectsDeathWhenDeathTestsAvailable) {
EXPECT_FATAL_FAILURE(ASSERT_DEATH_IF_SUPPORTED(;, ""), "");
}
-#else
+TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInFastStyle) {
+ testing::GTEST_FLAG(death_test_style) = "fast";
+ EXPECT_FALSE(InDeathTestChild());
+ EXPECT_DEATH({
+ fprintf(stderr, InDeathTestChild() ? "Inside" : "Outside");
+ fflush(stderr);
+ _exit(1);
+ }, "Inside");
+}
+
+TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInThreadSafeStyle) {
+ testing::GTEST_FLAG(death_test_style) = "threadsafe";
+ EXPECT_FALSE(InDeathTestChild());
+ EXPECT_DEATH({
+ fprintf(stderr, InDeathTestChild() ? "Inside" : "Outside");
+ fflush(stderr);
+ _exit(1);
+ }, "Inside");
+}
+
+#else // !GTEST_HAS_DEATH_TEST follows
using testing::internal::CaptureStderr;
using testing::internal::GetCapturedStderr;
@@ -1354,27 +1369,7 @@ TEST(ConditionalDeathMacrosTest, AssertDeatDoesNotReturnhIfUnsupported) {
EXPECT_EQ(1, n);
}
-TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInFastStyle) {
- testing::GTEST_FLAG(death_test_style) = "fast";
- EXPECT_FALSE(InDeathTestChild());
- EXPECT_DEATH({
- fprintf(stderr, InDeathTestChild() ? "Inside" : "Outside");
- fflush(stderr);
- _exit(1);
- }, "Inside");
-}
-
-TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInThreadSafeStyle) {
- testing::GTEST_FLAG(death_test_style) = "threadsafe";
- EXPECT_FALSE(InDeathTestChild());
- EXPECT_DEATH({
- fprintf(stderr, InDeathTestChild() ? "Inside" : "Outside");
- fflush(stderr);
- _exit(1);
- }, "Inside");
-}
-
-#endif // GTEST_HAS_DEATH_TEST
+#endif // !GTEST_HAS_DEATH_TEST
// Tests that the death test macros expand to code which may or may not
// be followed by operator<<, and that in either case the complete text
@@ -1405,12 +1400,9 @@ TEST(ConditionalDeathMacrosSyntaxDeathTest, SingleStatement) {
// Tests that conditional death test macros expand to code which interacts
// well with switch statements.
TEST(ConditionalDeathMacrosSyntaxDeathTest, SwitchStatement) {
-// Microsoft compiler usually complains about switch statements without
-// case labels. We suppress that warning for this test.
-#ifdef _MSC_VER
-# pragma warning(push)
-# pragma warning(disable: 4065)
-#endif // _MSC_VER
+ // Microsoft compiler usually complains about switch statements without
+ // case labels. We suppress that warning for this test.
+ GTEST_DISABLE_MSC_WARNINGS_PUSH_(4065)
switch (0)
default:
@@ -1421,9 +1413,7 @@ TEST(ConditionalDeathMacrosSyntaxDeathTest, SwitchStatement) {
case 0:
EXPECT_DEATH_IF_SUPPORTED(_exit(1), "") << "exit in switch case";
-#ifdef _MSC_VER
-# pragma warning(pop)
-#endif // _MSC_VER
+ GTEST_DISABLE_MSC_WARNINGS_POP_()
}
// Tests that a test case whose name ends with "DeathTest" works fine
diff --git a/test/gtest-printers_test.cc b/test/gtest-printers_test.cc
index 9481290..7b07fd1 100644
--- a/test/gtest-printers_test.cc
+++ b/test/gtest-printers_test.cc
@@ -202,12 +202,12 @@ using ::testing::internal::FormatForComparisonFailureMessage;
using ::testing::internal::ImplicitCast_;
using ::testing::internal::NativeArray;
using ::testing::internal::RE;
+using ::testing::internal::RelationToSourceReference;
using ::testing::internal::Strings;
using ::testing::internal::UniversalPrint;
using ::testing::internal::UniversalPrinter;
using ::testing::internal::UniversalTersePrint;
using ::testing::internal::UniversalTersePrintTupleFieldsToStrings;
-using ::testing::internal::kReference;
using ::testing::internal::string;
// The hash_* classes are not part of the C++ standard. STLport
@@ -946,13 +946,13 @@ TEST(PrintStlContainerTest, NestedContainer) {
TEST(PrintStlContainerTest, OneDimensionalNativeArray) {
const int a[3] = { 1, 2, 3 };
- NativeArray<int> b(a, 3, kReference);
+ NativeArray<int> b(a, 3, RelationToSourceReference());
EXPECT_EQ("{ 1, 2, 3 }", Print(b));
}
TEST(PrintStlContainerTest, TwoDimensionalNativeArray) {
const int a[2][3] = { { 1, 2, 3 }, { 4, 5, 6 } };
- NativeArray<int[3]> b(a, 2, kReference);
+ NativeArray<int[3]> b(a, 2, RelationToSourceReference());
EXPECT_EQ("{ { 1, 2, 3 }, { 4, 5, 6 } }", Print(b));
}
@@ -1648,3 +1648,4 @@ TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTersely) {
} // namespace gtest_printers_test
} // namespace testing
+
diff --git a/test/gtest_premature_exit_test.cc b/test/gtest_premature_exit_test.cc
index fcfc623..c1ed968 100644
--- a/test/gtest_premature_exit_test.cc
+++ b/test/gtest_premature_exit_test.cc
@@ -100,9 +100,9 @@ TEST_F(PrematureExitDeathTest, FileExistsDuringExecutionOfDeathTest) {
// Tests that TEST_PREMATURE_EXIT_FILE is set where it's expected to
// be set.
TEST_F(PrematureExitTest, TestPrematureExitFileEnvVarIsSet) {
- GTEST_INTENTIONAL_CONST_COND_PUSH_
+ GTEST_INTENTIONAL_CONST_COND_PUSH_()
if (kTestPrematureExitFileEnvVarShouldBeSet) {
- GTEST_INTENTIONAL_CONST_COND_POP_
+ GTEST_INTENTIONAL_CONST_COND_POP_()
const char* const filepath = GetEnv("TEST_PREMATURE_EXIT_FILE");
ASSERT_TRUE(filepath != NULL);
ASSERT_NE(*filepath, '\0');
diff --git a/test/gtest_unittest.cc b/test/gtest_unittest.cc
index 0cab07d..6cccd01 100644
--- a/test/gtest_unittest.cc
+++ b/test/gtest_unittest.cc
@@ -233,7 +233,6 @@ using testing::TestProperty;
using testing::TestResult;
using testing::TimeInMillis;
using testing::UnitTest;
-using testing::kMaxStackTraceDepth;
using testing::internal::AddReference;
using testing::internal::AlwaysFalse;
using testing::internal::AlwaysTrue;
@@ -267,6 +266,8 @@ using testing::internal::IsContainerTest;
using testing::internal::IsNotContainer;
using testing::internal::NativeArray;
using testing::internal::ParseInt32Flag;
+using testing::internal::RelationToSourceCopy;
+using testing::internal::RelationToSourceReference;
using testing::internal::RemoveConst;
using testing::internal::RemoveReference;
using testing::internal::ShouldRunTestOnShard;
@@ -281,11 +282,10 @@ using testing::internal::TestEventListenersAccessor;
using testing::internal::TestResultAccessor;
using testing::internal::UInt32;
using testing::internal::WideStringToUtf8;
-using testing::internal::kCopy;
using testing::internal::kMaxRandomSeed;
-using testing::internal::kReference;
using testing::internal::kTestTypeIdInGoogleTest;
using testing::internal::scoped_ptr;
+using testing::kMaxStackTraceDepth;
#if GTEST_HAS_STREAM_REDIRECTION
using testing::internal::CaptureStdout;
@@ -417,19 +417,11 @@ class FormatEpochTimeInMillisAsIso8601Test : public Test {
private:
virtual void SetUp() {
saved_tz_ = NULL;
-#if _MSC_VER
-# pragma warning(push) // Saves the current warning state.
-# pragma warning(disable:4996) // Temporarily disables warning 4996
- // (function or variable may be unsafe
- // for getenv, function is deprecated for
- // strdup).
- if (getenv("TZ"))
- saved_tz_ = strdup(getenv("TZ"));
-# pragma warning(pop) // Restores the warning state again.
-#else
+
+ GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996 /* getenv, strdup: deprecated */)
if (getenv("TZ"))
saved_tz_ = strdup(getenv("TZ"));
-#endif
+ GTEST_DISABLE_MSC_WARNINGS_POP_()
// Set up the time zone for FormatEpochTimeInMillisAsIso8601 to use. We
// cannot use the local time zone because the function's output depends
@@ -453,11 +445,9 @@ class FormatEpochTimeInMillisAsIso8601Test : public Test {
const std::string env_var =
std::string("TZ=") + (time_zone ? time_zone : "");
_putenv(env_var.c_str());
-# pragma warning(push) // Saves the current warning state.
-# pragma warning(disable:4996) // Temporarily disables warning 4996
- // (function is deprecated).
+ GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996 /* deprecated function */)
tzset();
-# pragma warning(pop) // Restores the warning state again.
+ GTEST_DISABLE_MSC_WARNINGS_POP_()
#else
if (time_zone) {
setenv(("TZ"), time_zone, 1);
@@ -5026,6 +5016,31 @@ 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
+
+TEST(AssertionResultTest, ConstructibleFromContextuallyConvertibleToBool) {
+ struct ExplicitlyConvertibleToBool {
+ explicit operator bool() const { return value; }
+ bool value;
+ };
+ ExplicitlyConvertibleToBool v1 = {false};
+ ExplicitlyConvertibleToBool v2 = {true};
+ EXPECT_FALSE(v1);
+ EXPECT_TRUE(v2);
+}
+
+#endif // GTEST_LANG_CXX11
+
+struct ConvertibleToAssertionResult {
+ operator AssertionResult() const { return AssertionResult(true); }
+};
+
+TEST(AssertionResultTest, ConstructibleFromImplicitlyConvertible) {
+ ConvertibleToAssertionResult obj;
+ EXPECT_TRUE(obj);
+}
+
// Tests streaming a user type whose definition and operator << are
// both in the global namespace.
class Base {
@@ -7327,7 +7342,7 @@ TEST(CopyArrayTest, WorksForTwoDimensionalArrays) {
TEST(NativeArrayTest, ConstructorFromArrayWorks) {
const int a[3] = { 0, 1, 2 };
- NativeArray<int> na(a, 3, kReference);
+ NativeArray<int> na(a, 3, RelationToSourceReference());
EXPECT_EQ(3U, na.size());
EXPECT_EQ(a, na.begin());
}
@@ -7337,7 +7352,7 @@ TEST(NativeArrayTest, CreatesAndDeletesCopyOfArrayWhenAskedTo) {
Array* a = new Array[1];
(*a)[0] = 0;
(*a)[1] = 1;
- NativeArray<int> na(*a, 2, kCopy);
+ NativeArray<int> na(*a, 2, RelationToSourceCopy());
EXPECT_NE(*a, na.begin());
delete[] a;
EXPECT_EQ(0, na.begin()[0]);
@@ -7357,7 +7372,7 @@ TEST(NativeArrayTest, TypeMembersAreCorrect) {
TEST(NativeArrayTest, MethodsWork) {
const int a[3] = { 0, 1, 2 };
- NativeArray<int> na(a, 3, kCopy);
+ NativeArray<int> na(a, 3, RelationToSourceCopy());
ASSERT_EQ(3U, na.size());
EXPECT_EQ(3, na.end() - na.begin());
@@ -7372,18 +7387,18 @@ TEST(NativeArrayTest, MethodsWork) {
EXPECT_TRUE(na == na);
- NativeArray<int> na2(a, 3, kReference);
+ NativeArray<int> na2(a, 3, RelationToSourceReference());
EXPECT_TRUE(na == na2);
const int b1[3] = { 0, 1, 1 };
const int b2[4] = { 0, 1, 2, 3 };
- EXPECT_FALSE(na == NativeArray<int>(b1, 3, kReference));
- EXPECT_FALSE(na == NativeArray<int>(b2, 4, kCopy));
+ EXPECT_FALSE(na == NativeArray<int>(b1, 3, RelationToSourceReference()));
+ EXPECT_FALSE(na == NativeArray<int>(b2, 4, RelationToSourceCopy()));
}
TEST(NativeArrayTest, WorksForTwoDimensionalArray) {
const char a[2][3] = { "hi", "lo" };
- NativeArray<char[3]> na(a, 2, kReference);
+ NativeArray<char[3]> na(a, 2, RelationToSourceReference());
ASSERT_EQ(2U, na.size());
EXPECT_EQ(a, na.begin());
}
@@ -7413,3 +7428,4 @@ TEST(SkipPrefixTest, DoesNotSkipWhenPrefixDoesNotMatch) {
EXPECT_FALSE(SkipPrefix("world!", &p));
EXPECT_EQ(str, p);
}
+