diff options
author | temporal <temporal@630680e5-0e50-0410-840e-4b1c322b438d> | 2008-08-13 03:15:00 +0000 |
---|---|---|
committer | temporal <temporal@630680e5-0e50-0410-840e-4b1c322b438d> | 2008-08-13 03:15:00 +0000 |
commit | 779f61c6a3ce02a119e28e802f229e61b69b9046 (patch) | |
tree | 9131ef5f0acdc3d708a795fc6703488674741ee0 /src/google/protobuf/testing/googletest.cc | |
parent | a0f27fcd96c5bf2509ca88cca54f00b78f7b8bc5 (diff) | |
download | protobuf-779f61c6a3ce02a119e28e802f229e61b69b9046.tar.gz protobuf-779f61c6a3ce02a119e28e802f229e61b69b9046.tar.bz2 protobuf-779f61c6a3ce02a119e28e802f229e61b69b9046.zip |
Integrate recent changes from google3.
protoc
- New flags --encode and --decode can be used to convert between protobuf text
format and binary format from the command-line.
- New flag --descriptor_set_out can be used to write FileDescriptorProtos for
all parsed files directly into a single output file. This is particularly
useful if you wish to parse .proto files from programs written in languages
other than C++: just run protoc as a background process and have it output
a FileDescriptorList, then parse that natively.
C++
- Reflection objects are now per-class rather than per-instance. To make this
possible, the Reflection interface had to be changed such that all methods
take the Message instance as a parameter. This change improves performance
significantly in memory-bandwidth-limited use cases, since it makes the
message objects smaller. Note that source-incompatible interface changes
like this will not be made again after the library leaves beta.
Python
- MergeFrom(message) and CopyFrom(message) are now implemented.
- SerializeToString() raises an exception if the message is missing required
fields.
- Code organization improvements.
- Fixed doc comments for RpcController and RpcChannel, which had somehow been
swapped.
Diffstat (limited to 'src/google/protobuf/testing/googletest.cc')
-rw-r--r-- | src/google/protobuf/testing/googletest.cc | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/google/protobuf/testing/googletest.cc b/src/google/protobuf/testing/googletest.cc index aabc657f..65c1154f 100644 --- a/src/google/protobuf/testing/googletest.cc +++ b/src/google/protobuf/testing/googletest.cc @@ -126,9 +126,28 @@ string TestTempDir() { return temp_dir_deleter_.GetTempDir(); } +// TODO(kenton): Share duplicated code below. Too busy/lazy for now. + +static string stdout_capture_filename_; static string stderr_capture_filename_; +static int original_stdout_ = -1; static int original_stderr_ = -1; +void CaptureTestStdout() { + GOOGLE_CHECK_EQ(original_stdout_, -1) << "Already capturing."; + + stdout_capture_filename_ = TestTempDir() + "/captured_stdout"; + + int fd = open(stdout_capture_filename_.c_str(), + O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0777); + GOOGLE_CHECK(fd >= 0) << "open: " << strerror(errno); + + original_stdout_ = dup(1); + close(1); + dup2(fd, 1); + close(fd); +} + void CaptureTestStderr() { GOOGLE_CHECK_EQ(original_stderr_, -1) << "Already capturing."; @@ -144,6 +163,21 @@ void CaptureTestStderr() { close(fd); } +string GetCapturedTestStdout() { + GOOGLE_CHECK_NE(original_stdout_, -1) << "Not capturing."; + + close(1); + dup2(original_stdout_, 1); + original_stdout_ = -1; + + string result; + File::ReadFileToStringOrDie(stdout_capture_filename_, &result); + + remove(stdout_capture_filename_.c_str()); + + return result; +} + string GetCapturedTestStderr() { GOOGLE_CHECK_NE(original_stderr_, -1) << "Not capturing."; |