Flutter Engine
The Flutter Engine
stream_capture.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_TESTING_STREAM_CAPTURE_H_
6#define FLUTTER_TESTING_STREAM_CAPTURE_H_
7
8#include <ostream>
9#include <sstream>
10#include <string>
11
12namespace flutter {
13namespace testing {
14
15// Temporarily replaces the specified stream's output buffer to capture output.
16//
17// Example:
18// StreamCapture captured_stdout(&std::cout);
19// ... code that writest to std::cout ...
20// std::string output = captured_stdout.GetCapturedOutput();
22 public:
23 // Begins capturing output to the specified stream.
24 explicit StreamCapture(std::ostream* ostream);
25
26 // Stops capturing output to the specified stream, and restores the original
27 // output buffer, if |Stop| has not already been called.
29
30 // Stops capturing output to the specified stream, and restores the original
31 // output buffer.
32 void Stop();
33
34 // Returns any output written to the captured stream between construction and
35 // the first call to |Stop|, if any, or now.
36 std::string GetOutput() const;
37
38 private:
39 std::ostream* ostream_;
40 std::stringstream buffer_;
41 std::streambuf* old_buffer_;
42};
43
44} // namespace testing
45} // namespace flutter
46
47#endif // FLUTTER_TESTING_STREAM_CAPTURE_H_
StreamCapture(std::ostream *ostream)