diff options
author | zhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925> | 2010-01-27 22:27:30 (GMT) |
---|---|---|
committer | zhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925> | 2010-01-27 22:27:30 (GMT) |
commit | fd6f2a8a4b3fe8beb31f26b774b460727c410b66 (patch) | |
tree | 3425e1293b03fd10bf46272484c6abc2753308ae /test | |
parent | 27a65a9d67db865e9fba8224780fd2b7a71fe7d1 (diff) | |
download | googletest-fd6f2a8a4b3fe8beb31f26b774b460727c410b66.zip googletest-fd6f2a8a4b3fe8beb31f26b774b460727c410b66.tar.gz googletest-fd6f2a8a4b3fe8beb31f26b774b460727c410b66.tar.bz2 |
Implements stdout capturing (by Vlad Losev); fixes compiler error on NVCC (by Zhanyong Wan).
Diffstat (limited to 'test')
-rw-r--r-- | test/gtest-port_test.cc | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/test/gtest-port_test.cc b/test/gtest-port_test.cc index 551c98b..3576c2b 100644 --- a/test/gtest-port_test.cc +++ b/test/gtest-port_test.cc @@ -33,6 +33,8 @@ #include <gtest/internal/gtest-port.h> +#include <stdio.h> + #if GTEST_OS_MAC #include <pthread.h> #include <time.h> @@ -699,11 +701,49 @@ TEST(RETest, PartialMatchWorks) { #endif // GTEST_USES_POSIX_RE -TEST(CaptureStderrTest, CapturesStdErr) { +#if !GTEST_OS_WINDOWS_MOBILE + +TEST(CaptureTest, CapturesStdout) { + CaptureStdout(); + fprintf(stdout, "abc"); + EXPECT_STREQ("abc", GetCapturedStdout().c_str()); + + CaptureStdout(); + fprintf(stdout, "def%cghi", '\0'); + EXPECT_EQ(::std::string("def\0ghi", 7), ::std::string(GetCapturedStdout())); +} + +TEST(CaptureTest, CapturesStderr) { + CaptureStderr(); + fprintf(stderr, "jkl"); + EXPECT_STREQ("jkl", GetCapturedStderr().c_str()); + CaptureStderr(); - fprintf(stderr, "abc"); - ASSERT_STREQ("abc", GetCapturedStderr().c_str()); + fprintf(stderr, "jkl%cmno", '\0'); + EXPECT_EQ(::std::string("jkl\0mno", 7), ::std::string(GetCapturedStderr())); } +// Tests that stdout and stderr capture don't interfere with each other. +TEST(CaptureTest, CapturesStdoutAndStderr) { + CaptureStdout(); + CaptureStderr(); + fprintf(stdout, "pqr"); + fprintf(stderr, "stu"); + EXPECT_STREQ("pqr", GetCapturedStdout().c_str()); + EXPECT_STREQ("stu", GetCapturedStderr().c_str()); +} + +TEST(CaptureDeathTest, CannotReenterStdoutCapture) { + CaptureStdout(); + EXPECT_DEATH_IF_SUPPORTED(CaptureStdout();, + "Only one stdout capturer can exist at a time"); + GetCapturedStdout(); + + // We cannot test stderr capturing using death tests as they use it + // themselves. +} + +#endif // !GTEST_OS_WINDOWS_MOBILE + } // namespace internal } // namespace testing |