Flutter Engine
Loading...
Searching...
No Matches
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
12
namespace
flutter::testing
{
13
14
// Temporarily replaces the specified stream's output buffer to capture output.
15
//
16
// Example:
17
// StreamCapture captured_stdout(&std::cout);
18
// ... code that writest to std::cout ...
19
// std::string output = captured_stdout.GetCapturedOutput();
20
class
StreamCapture
{
21
public
:
22
// Begins capturing output to the specified stream.
23
explicit
StreamCapture
(std::ostream* ostream);
24
25
// Stops capturing output to the specified stream, and restores the original
26
// output buffer, if |Stop| has not already been called.
27
~StreamCapture
();
28
29
// Stops capturing output to the specified stream, and restores the original
30
// output buffer.
31
void
Stop
();
32
33
// Returns any output written to the captured stream between construction and
34
// the first call to |Stop|, if any, or now.
35
std::string
GetOutput
()
const
;
36
37
private
:
38
std::ostream* ostream_;
39
std::stringstream buffer_;
40
std::streambuf* old_buffer_;
41
};
42
43
}
// namespace flutter::testing
44
45
#endif
// FLUTTER_TESTING_STREAM_CAPTURE_H_
flutter::testing::StreamCapture
Definition
stream_capture.h:20
flutter::testing::StreamCapture::~StreamCapture
~StreamCapture()
Definition
stream_capture.cc:14
flutter::testing::StreamCapture::Stop
void Stop()
Definition
stream_capture.cc:18
flutter::testing::StreamCapture::GetOutput
std::string GetOutput() const
Definition
stream_capture.cc:25
flutter::testing
Definition
native_assets_unittests.cc:10
testing
stream_capture.h
Generated on Thu Nov 6 2025 16:11:29 for Flutter Engine by
1.9.8