chromium/third_party/googletest/custom/gtest/internal/custom/gtest_port_wrapper.cc

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// TODO(crbug.com/1009553): Remove this wrapper after finding a way to plumb a
// workable temporary path into googletest on Android.

// This wrapper lets us compile gtest-port.cc without its stream redirection
// code. We replace this code with a variant that works on all Chrome platforms.
// This is a temporary workaround until we get good code upstream.
//
// Stream redirection requires the ability to create files in a temporary
// directory. Traditionally, this directory has been /sdcard on Android.
// Commit bf0fe874a27bd6c9a4a35b98e662d2d02f8879a2 changed the Android
// directory to /data/local/tmp, which is not writable in Chrome's testing
// setup. We work around this problem by using the old code for now.
//
// It is tempting to consider disabling the stream redirection code altogether,
// by setting GTEST_HAS_STREAM_REDIRECTION to 0 in googletest's BUILD.gn.
// This breaks gtest-death-test.cc, which assumes the existence of
// testing::internal::{GetCapturedStderr,CaptureStderr} without any macro
// checking.

#define GTEST_HAS_STREAM_REDIRECTION
#include "third_party/googletest/src/googletest/src/gtest-port.cc"

namespace testing {
namespace internal {

// Verbatim copy from gtest-port.cc, since it only provides these constants when
// GTEST_HAS_STREAM_REDIRECTION is true.
#if defined(_MSC_VER) || defined(__BORLANDC__)
// MSVC and C++Builder do not provide a definition of STDERR_FILENO.
const int kStdOutFileno = 1;
const int kStdErrFileno = 2;
#else
const int kStdOutFileno =;
const int kStdErrFileno =;
#endif  // defined(_MSC_VER) || defined(__BORLANDC__)

// Object that captures an output stream (stdout/stderr).
class CapturedStream {};

static CapturedStream* g_captured_stderr =;
static CapturedStream* g_captured_stdout =;

// Starts capturing an output stream (stdout/stderr).
static void CaptureStream(int fd,
                          const char* stream_name,
                          CapturedStream** stream) {}

// Stops capturing the output stream and returns the captured string.
static std::string GetCapturedStream(CapturedStream** captured_stream) {}

// Starts capturing stdout.
void CaptureStdout() {}

// Starts capturing stderr.
void CaptureStderr() {}

// Stops capturing stdout and returns the captured string.
std::string GetCapturedStdout() {}

// Stops capturing stderr and returns the captured string.
std::string GetCapturedStderr() {}

}  // namespace internal
}  // namespace testing