Gazebo Common

API Reference

6.0.0~pre2
RedirectConsoleStream.hh
Go to the documentation of this file.
1/*
2* Copyright (C) 2022 Open Source Robotics Foundation
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*
16*/
17#ifndef GZ_COMMON_TESTING_REDIRECTCONSOLE_STREAM_HH
18#define GZ_COMMON_TESTING_REDIRECTCONSOLE_STREAM_HH
19
20#include <string>
21
22#include <gz/utils/ImplPtr.hh>
24
25#include "gz/common/testing/Export.hh"
26
27namespace gz::common::testing
28{
29
30enum class StreamSource
31{
32 STDOUT,
33 STDERR,
34};
35
36class GZ_COMMON_TESTING_VISIBLE RedirectConsoleStream
37{
47 public: RedirectConsoleStream(const StreamSource &_source,
48 const std::string &_destination);
49
53
56 public: bool Active() const;
57
59 GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr)
60};
61
64{
65 auto path = gz::common::testing::TempPath("stdout.out");
66 return RedirectConsoleStream(StreamSource::STDOUT, path);
67}
68
71{
72 auto path = gz::common::testing::TempPath("stderr.out");
73 return RedirectConsoleStream(StreamSource::STDERR, path);
74}
75} // namespace gz::common::testing
76#endif // GZ_COMMON_TESTING_REDIRECTCONSOLE_STREAM_HH